blob: e54217cebb3bd65b0549cb3bb70e2207e21ff6d4 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.11 Management
Dmitry Shmidt29333592017-01-09 12:27:11 -08003 * Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#ifndef CONFIG_NATIVE_WINDOWS
12
13#include "utils/common.h"
14#include "utils/eloop.h"
15#include "crypto/crypto.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080016#include "crypto/sha256.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070017#include "crypto/sha384.h"
18#include "crypto/sha512.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080019#include "crypto/random.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070020#include "common/ieee802_11_defs.h"
21#include "common/ieee802_11_common.h"
22#include "common/wpa_ctrl.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080023#include "common/sae.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070024#include "common/dpp.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080025#include "common/ocv.h"
Hai Shalom81f62d82019-07-22 12:10:00 -070026#include "common/wpa_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "radius/radius.h"
28#include "radius/radius_client.h"
29#include "p2p/p2p.h"
30#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080031#include "fst/fst.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070032#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"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080038#include "pmksa_cache_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070039#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"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080046#include "wnm_ap.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080047#include "hw_features.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048#include "ieee802_11.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080049#include "dfs.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080050#include "mbo_ap.h"
Dmitry Shmidt849734c2016-05-27 09:59:01 -070051#include "rrm.h"
Dmitry Shmidtaca489e2016-09-28 15:44:14 -070052#include "taxonomy.h"
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080053#include "fils_hlp.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070054#include "dpp_hostapd.h"
55#include "gas_query_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070056
57
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070058#ifdef CONFIG_FILS
59static struct wpabuf *
60prepare_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 */
Hai Shalom021b0b52019-04-10 11:17:58 -070067static void handle_auth(struct hostapd_data *hapd,
68 const struct ieee80211_mgmt *mgmt, size_t len,
69 int rssi, int from_queue);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070070
Hai Shalom74f70d42019-02-11 14:42:39 -080071
72u8 * 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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
88{
89 u8 *pos = eid;
90 int i, num, count;
Hai Shalomfdcde762020-04-02 11:19:20 -070091 int h2e_required;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070092
93 if (hapd->iface->current_rates == NULL)
94 return eid;
95
96 *pos++ = WLAN_EID_SUPP_RATES;
97 num = hapd->iface->num_rates;
98 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
99 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800100 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
101 num++;
Hai Shalomfdcde762020-04-02 11:19:20 -0700102 h2e_required = (hapd->conf->sae_pwe == 1 ||
103 hostapd_sae_pw_id_in_use(hapd->conf) == 2) &&
104 hapd->conf->sae_pwe != 3 &&
105 wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt);
106 if (h2e_required)
Hai Shalomc3565922019-10-28 11:58:20 -0700107 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700108 if (num > 8) {
109 /* rest of the rates are encoded in Extended supported
110 * rates element */
111 num = 8;
112 }
113
114 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700115 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
116 i++) {
117 count++;
118 *pos = hapd->iface->current_rates[i].rate / 5;
119 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
120 *pos |= 0x80;
121 pos++;
122 }
123
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800124 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
125 count++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700126 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800127 }
128
129 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
130 count++;
131 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
132 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700133
Hai Shalomfdcde762020-04-02 11:19:20 -0700134 if (h2e_required && count < 8) {
Hai Shalomc3565922019-10-28 11:58:20 -0700135 count++;
136 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY;
137 }
138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700139 return pos;
140}
141
142
143u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
144{
145 u8 *pos = eid;
146 int i, num, count;
Hai Shalomfdcde762020-04-02 11:19:20 -0700147 int h2e_required;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700148
149 if (hapd->iface->current_rates == NULL)
150 return eid;
151
152 num = hapd->iface->num_rates;
153 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
154 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800155 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
156 num++;
Hai Shalomfdcde762020-04-02 11:19:20 -0700157 h2e_required = (hapd->conf->sae_pwe == 1 ||
158 hostapd_sae_pw_id_in_use(hapd->conf) == 2) &&
159 hapd->conf->sae_pwe != 3 &&
160 wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt);
161 if (h2e_required)
Hai Shalomc3565922019-10-28 11:58:20 -0700162 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700163 if (num <= 8)
164 return eid;
165 num -= 8;
166
167 *pos++ = WLAN_EID_EXT_SUPP_RATES;
168 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700169 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
170 i++) {
171 count++;
172 if (count <= 8)
173 continue; /* already in SuppRates IE */
174 *pos = hapd->iface->current_rates[i].rate / 5;
175 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
176 *pos |= 0x80;
177 pos++;
178 }
179
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800180 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
181 count++;
182 if (count > 8)
183 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
184 }
185
186 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
187 count++;
188 if (count > 8)
189 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
190 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191
Hai Shalomfdcde762020-04-02 11:19:20 -0700192 if (h2e_required) {
Hai Shalomc3565922019-10-28 11:58:20 -0700193 count++;
194 if (count > 8)
195 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY;
196 }
197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 return pos;
199}
200
201
Hai Shalomfdcde762020-04-02 11:19:20 -0700202u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
203 size_t len)
204{
205 size_t i;
206
207 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
208 if (hapd->conf->radio_measurements[i])
209 break;
210 }
211
212 if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN)
213 return eid;
214
215 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
216 *eid++ = RRM_CAPABILITIES_IE_LEN;
217 os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN);
218
219 return eid + RRM_CAPABILITIES_IE_LEN;
220}
221
222
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700223u16 hostapd_own_capab_info(struct hostapd_data *hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224{
225 int capab = WLAN_CAPABILITY_ESS;
Hai Shalomfdcde762020-04-02 11:19:20 -0700226 int privacy = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800227 int dfs;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700228 int i;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800229
230 /* Check if any of configured channels require DFS */
231 dfs = hostapd_is_dfs_required(hapd->iface);
232 if (dfs < 0) {
233 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
234 dfs);
235 dfs = 0;
236 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237
238 if (hapd->iface->num_sta_no_short_preamble == 0 &&
239 hapd->iconf->preamble == SHORT_PREAMBLE)
240 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
241
Hai Shalomfdcde762020-04-02 11:19:20 -0700242#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243 privacy = hapd->conf->ssid.wep.keys_set;
244
245 if (hapd->conf->ieee802_1x &&
246 (hapd->conf->default_wep_key_len ||
247 hapd->conf->individual_wep_key_len))
248 privacy = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700249#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700250
251 if (hapd->conf->wpa)
252 privacy = 1;
253
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800254#ifdef CONFIG_HS20
255 if (hapd->conf->osen)
256 privacy = 1;
257#endif /* CONFIG_HS20 */
258
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700259 if (privacy)
260 capab |= WLAN_CAPABILITY_PRIVACY;
261
262 if (hapd->iface->current_mode &&
263 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
264 hapd->iface->num_sta_no_short_slot_time == 0)
265 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
266
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800267 /*
268 * Currently, Spectrum Management capability bit is set when directly
269 * requested in configuration by spectrum_mgmt_required or when AP is
270 * running on DFS channel.
271 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
272 */
273 if (hapd->iface->current_mode &&
274 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
275 (hapd->iconf->spectrum_mgmt_required || dfs))
276 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
277
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700278 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
279 if (hapd->conf->radio_measurements[i]) {
280 capab |= IEEE80211_CAP_RRM;
281 break;
282 }
283 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800284
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700285 return capab;
286}
287
288
Hai Shalomfdcde762020-04-02 11:19:20 -0700289#ifdef CONFIG_WEP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800290#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
292 u16 auth_transaction, const u8 *challenge,
293 int iswep)
294{
295 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
296 HOSTAPD_LEVEL_DEBUG,
297 "authentication (shared key, transaction %d)",
298 auth_transaction);
299
300 if (auth_transaction == 1) {
301 if (!sta->challenge) {
302 /* Generate a pseudo-random challenge */
303 u8 key[8];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
306 if (sta->challenge == NULL)
307 return WLAN_STATUS_UNSPECIFIED_FAILURE;
308
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800309 if (os_get_random(key, sizeof(key)) < 0) {
310 os_free(sta->challenge);
311 sta->challenge = NULL;
312 return WLAN_STATUS_UNSPECIFIED_FAILURE;
313 }
314
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 rc4_skip(key, sizeof(key), 0,
316 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
317 }
318 return 0;
319 }
320
321 if (auth_transaction != 3)
322 return WLAN_STATUS_UNSPECIFIED_FAILURE;
323
324 /* Transaction 3 */
325 if (!iswep || !sta->challenge || !challenge ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700326 os_memcmp_const(sta->challenge, challenge,
327 WLAN_AUTH_CHALLENGE_LEN)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
329 HOSTAPD_LEVEL_INFO,
330 "shared key authentication - invalid "
331 "challenge-response");
332 return WLAN_STATUS_CHALLENGE_FAIL;
333 }
334
335 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
336 HOSTAPD_LEVEL_DEBUG,
337 "authentication OK (shared key)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338 sta->flags |= WLAN_STA_AUTH;
339 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340 os_free(sta->challenge);
341 sta->challenge = NULL;
342
343 return 0;
344}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800345#endif /* CONFIG_NO_RC4 */
Hai Shalomfdcde762020-04-02 11:19:20 -0700346#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347
348
Hai Shalomfdcde762020-04-02 11:19:20 -0700349static int send_auth_reply(struct hostapd_data *hapd, struct sta_info *sta,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800350 const u8 *dst, const u8 *bssid,
351 u16 auth_alg, u16 auth_transaction, u16 resp,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700352 const u8 *ies, size_t ies_len, const char *dbg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700353{
354 struct ieee80211_mgmt *reply;
355 u8 *buf;
356 size_t rlen;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800357 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700358
359 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
360 buf = os_zalloc(rlen);
361 if (buf == NULL)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800362 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363
364 reply = (struct ieee80211_mgmt *) buf;
365 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
366 WLAN_FC_STYPE_AUTH);
367 os_memcpy(reply->da, dst, ETH_ALEN);
368 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
369 os_memcpy(reply->bssid, bssid, ETH_ALEN);
370
371 reply->u.auth.auth_alg = host_to_le16(auth_alg);
372 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
373 reply->u.auth.status_code = host_to_le16(resp);
374
375 if (ies && ies_len)
376 os_memcpy(reply->u.auth.variable, ies, ies_len);
377
378 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700379 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu) (dbg=%s)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380 MAC2STR(dst), auth_alg, auth_transaction,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700381 resp, (unsigned long) ies_len, dbg);
Hai Shalomfdcde762020-04-02 11:19:20 -0700382#ifdef CONFIG_TESTING_OPTIONS
383#ifdef CONFIG_SAE
384 if (hapd->conf->sae_confirm_immediate == 2 &&
385 auth_alg == WLAN_AUTH_SAE) {
386 if (auth_transaction == 1 && sta &&
387 (resp == WLAN_STATUS_SUCCESS ||
388 resp == WLAN_STATUS_SAE_HASH_TO_ELEMENT)) {
389 wpa_printf(MSG_DEBUG,
390 "TESTING: Postpone SAE Commit transmission until Confirm is ready");
391 os_free(sta->sae_postponed_commit);
392 sta->sae_postponed_commit = buf;
393 sta->sae_postponed_commit_len = rlen;
394 return WLAN_STATUS_SUCCESS;
395 }
396
397 if (auth_transaction == 2 && sta && sta->sae_postponed_commit) {
398 wpa_printf(MSG_DEBUG,
399 "TESTING: Send postponed SAE Commit first, immediately followed by SAE Confirm");
400 if (hostapd_drv_send_mlme(hapd,
401 sta->sae_postponed_commit,
402 sta->sae_postponed_commit_len,
403 0, NULL, 0, 0) < 0)
404 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
405 os_free(sta->sae_postponed_commit);
406 sta->sae_postponed_commit = NULL;
407 sta->sae_postponed_commit_len = 0;
408 }
409 }
410#endif /* CONFIG_SAE */
411#endif /* CONFIG_TESTING_OPTIONS */
412 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0, NULL, 0, 0) < 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800413 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
414 else
415 reply_res = WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416
417 os_free(buf);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800418
419 return reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700420}
421
422
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800423#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700424static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
425 u16 auth_transaction, u16 status,
426 const u8 *ies, size_t ies_len)
427{
428 struct hostapd_data *hapd = ctx;
429 struct sta_info *sta;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800430 int reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431
Hai Shalomfdcde762020-04-02 11:19:20 -0700432 reply_res = send_auth_reply(hapd, NULL, dst, bssid, WLAN_AUTH_FT,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700433 auth_transaction, status, ies, ies_len,
434 "auth-ft-finish");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700435
436 sta = ap_get_sta(hapd, dst);
437 if (sta == NULL)
438 return;
439
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800440 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
441 status != WLAN_STATUS_SUCCESS)) {
442 hostapd_drv_sta_remove(hapd, sta->addr);
443 sta->added_unassoc = 0;
444 return;
445 }
446
447 if (status != WLAN_STATUS_SUCCESS)
448 return;
449
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700450 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
451 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
452 sta->flags |= WLAN_STA_AUTH;
453 mlme_authenticate_indication(hapd, sta);
454}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800455#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700456
457
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800458#ifdef CONFIG_SAE
459
Roshan Pius3a1667e2018-07-03 15:17:14 -0700460static void sae_set_state(struct sta_info *sta, enum sae_state state,
461 const char *reason)
462{
463 wpa_printf(MSG_DEBUG, "SAE: State %s -> %s for peer " MACSTR " (%s)",
464 sae_state_txt(sta->sae->state), sae_state_txt(state),
465 MAC2STR(sta->addr), reason);
466 sta->sae->state = state;
467}
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800468
469
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800470static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
Hai Shalomc3565922019-10-28 11:58:20 -0700471 struct sta_info *sta, int update,
472 int status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800473{
474 struct wpabuf *buf;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700475 const char *password = NULL;
476 struct sae_password_entry *pw;
477 const char *rx_id = NULL;
Hai Shalomc3565922019-10-28 11:58:20 -0700478 int use_pt = 0;
479 struct sae_pt *pt = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800480
Hai Shalomc3565922019-10-28 11:58:20 -0700481 if (sta->sae->tmp) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700482 rx_id = sta->sae->tmp->pw_id;
Hai Shalomc3565922019-10-28 11:58:20 -0700483 use_pt = sta->sae->tmp->h2e;
484 }
485
Hai Shalomfdcde762020-04-02 11:19:20 -0700486 if (rx_id && hapd->conf->sae_pwe != 3)
487 use_pt = 1;
488 else if (status_code == WLAN_STATUS_SUCCESS)
Hai Shalomc3565922019-10-28 11:58:20 -0700489 use_pt = 0;
490 else if (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT)
491 use_pt = 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700492
493 for (pw = hapd->conf->sae_passwords; pw; pw = pw->next) {
494 if (!is_broadcast_ether_addr(pw->peer_addr) &&
495 os_memcmp(pw->peer_addr, sta->addr, ETH_ALEN) != 0)
496 continue;
497 if ((rx_id && !pw->identifier) || (!rx_id && pw->identifier))
498 continue;
499 if (rx_id && pw->identifier &&
500 os_strcmp(rx_id, pw->identifier) != 0)
501 continue;
502 password = pw->password;
Hai Shalomc3565922019-10-28 11:58:20 -0700503 pt = pw->pt;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700504 break;
505 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700506 if (!password) {
Hai Shalomc3565922019-10-28 11:58:20 -0700507 password = hapd->conf->ssid.wpa_passphrase;
508 pt = hapd->conf->ssid.pt;
509 }
510 if (!password || (use_pt && !pt)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800511 wpa_printf(MSG_DEBUG, "SAE: No password available");
512 return NULL;
513 }
514
Hai Shalomc3565922019-10-28 11:58:20 -0700515 if (update && use_pt &&
516 sae_prepare_commit_pt(sta->sae, pt, hapd->own_addr, sta->addr,
517 NULL) < 0)
518 return NULL;
519
520 if (update && !use_pt &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800521 sae_prepare_commit(hapd->own_addr, sta->addr,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700522 (u8 *) password, os_strlen(password), rx_id,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800523 sta->sae) < 0) {
524 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
525 return NULL;
526 }
527
Hai Shalom021b0b52019-04-10 11:17:58 -0700528 if (pw && pw->vlan_id) {
529 if (!sta->sae->tmp) {
530 wpa_printf(MSG_INFO,
531 "SAE: No temporary data allocated - cannot store VLAN ID");
532 return NULL;
533 }
534 sta->sae->tmp->vlan_id = pw->vlan_id;
535 }
536
Roshan Pius3a1667e2018-07-03 15:17:14 -0700537 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN +
538 (rx_id ? 3 + os_strlen(rx_id) : 0));
Hai Shalomfdcde762020-04-02 11:19:20 -0700539 if (buf &&
540 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
541 sta->sae->tmp->anti_clogging_token : NULL,
542 rx_id) < 0) {
543 wpabuf_free(buf);
544 buf = NULL;
545 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800546
547 return buf;
548}
549
550
551static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
552 struct sta_info *sta)
553{
554 struct wpabuf *buf;
555
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800556 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800557 if (buf == NULL)
558 return NULL;
559
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800560 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800561
562 return buf;
563}
564
565
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800566static int auth_sae_send_commit(struct hostapd_data *hapd,
567 struct sta_info *sta,
Hai Shalomc3565922019-10-28 11:58:20 -0700568 const u8 *bssid, int update, int status_code)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800569{
570 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800571 int reply_res;
Hai Shalomc3565922019-10-28 11:58:20 -0700572 u16 status;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800573
Hai Shalomc3565922019-10-28 11:58:20 -0700574 data = auth_build_sae_commit(hapd, sta, update, status_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700575 if (!data && sta->sae->tmp && sta->sae->tmp->pw_id)
576 return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800577 if (data == NULL)
578 return WLAN_STATUS_UNSPECIFIED_FAILURE;
579
Hai Shalomc3565922019-10-28 11:58:20 -0700580 status = (sta->sae->tmp && sta->sae->tmp->h2e) ?
581 WLAN_STATUS_SAE_HASH_TO_ELEMENT : WLAN_STATUS_SUCCESS;
Hai Shalomfdcde762020-04-02 11:19:20 -0700582 reply_res = send_auth_reply(hapd, sta, sta->addr, bssid,
583 WLAN_AUTH_SAE, 1,
Hai Shalomc3565922019-10-28 11:58:20 -0700584 status, wpabuf_head(data),
Roshan Pius3a1667e2018-07-03 15:17:14 -0700585 wpabuf_len(data), "sae-send-commit");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800586
587 wpabuf_free(data);
588
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800589 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800590}
591
592
593static int auth_sae_send_confirm(struct hostapd_data *hapd,
594 struct sta_info *sta,
595 const u8 *bssid)
596{
597 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800598 int reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800599
600 data = auth_build_sae_confirm(hapd, sta);
601 if (data == NULL)
602 return WLAN_STATUS_UNSPECIFIED_FAILURE;
603
Hai Shalomfdcde762020-04-02 11:19:20 -0700604 reply_res = send_auth_reply(hapd, sta, sta->addr, bssid,
605 WLAN_AUTH_SAE, 2,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800606 WLAN_STATUS_SUCCESS, wpabuf_head(data),
Roshan Pius3a1667e2018-07-03 15:17:14 -0700607 wpabuf_len(data), "sae-send-confirm");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800608
609 wpabuf_free(data);
610
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800611 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800612}
613
614
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800615static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800616{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800617 struct sta_info *sta;
618 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800619
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800620 if (hapd->conf->sae_anti_clogging_threshold == 0)
621 return 1;
622
623 for (sta = hapd->sta_list; sta; sta = sta->next) {
624 if (!sta->sae)
625 continue;
626 if (sta->sae->state != SAE_COMMITTED &&
627 sta->sae->state != SAE_CONFIRMED)
628 continue;
629 open++;
630 if (open >= hapd->conf->sae_anti_clogging_threshold)
631 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800632 }
633
Hai Shalom021b0b52019-04-10 11:17:58 -0700634 /* In addition to already existing open SAE sessions, check whether
635 * there are enough pending commit messages in the processing queue to
636 * potentially result in too many open sessions. */
637 if (open + dl_list_len(&hapd->sae_commit_queue) >=
638 hapd->conf->sae_anti_clogging_threshold)
639 return 1;
640
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800641 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800642}
643
644
Hai Shalomfdcde762020-04-02 11:19:20 -0700645static int sae_token_hash(struct hostapd_data *hapd, const u8 *addr, u8 *idx)
Hai Shalom021b0b52019-04-10 11:17:58 -0700646{
647 u8 hash[SHA256_MAC_LEN];
648
Hai Shalomfdcde762020-04-02 11:19:20 -0700649 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
650 addr, ETH_ALEN, hash) < 0)
651 return -1;
652 *idx = hash[0];
653 return 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700654}
655
656
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800657static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
658 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800659{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800660 u8 mac[SHA256_MAC_LEN];
Hai Shalom021b0b52019-04-10 11:17:58 -0700661 const u8 *addrs[2];
662 size_t len[2];
663 u16 token_idx;
664 u8 idx;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800665
Hai Shalomfdcde762020-04-02 11:19:20 -0700666 if (token_len != SHA256_MAC_LEN || sae_token_hash(hapd, addr, &idx) < 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800667 return -1;
Hai Shalom021b0b52019-04-10 11:17:58 -0700668 token_idx = hapd->sae_pending_token_idx[idx];
669 if (token_idx == 0 || token_idx != WPA_GET_BE16(token)) {
670 wpa_printf(MSG_DEBUG, "SAE: Invalid anti-clogging token from "
671 MACSTR " - token_idx 0x%04x, expected 0x%04x",
672 MAC2STR(addr), WPA_GET_BE16(token), token_idx);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800673 return -1;
Hai Shalom021b0b52019-04-10 11:17:58 -0700674 }
675
676 addrs[0] = addr;
677 len[0] = ETH_ALEN;
678 addrs[1] = token;
679 len[1] = 2;
680 if (hmac_sha256_vector(hapd->sae_token_key, sizeof(hapd->sae_token_key),
681 2, addrs, len, mac) < 0 ||
682 os_memcmp_const(token + 2, &mac[2], SHA256_MAC_LEN - 2) != 0)
683 return -1;
684
685 hapd->sae_pending_token_idx[idx] = 0; /* invalidate used token */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800686
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800687 return 0;
688}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800689
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800690
691static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
Hai Shalomfdcde762020-04-02 11:19:20 -0700692 int group, const u8 *addr, int h2e)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800693{
694 struct wpabuf *buf;
695 u8 *token;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800696 struct os_reltime now;
Hai Shalom021b0b52019-04-10 11:17:58 -0700697 u8 idx[2];
698 const u8 *addrs[2];
699 size_t len[2];
700 u8 p_idx;
701 u16 token_idx;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800702
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800703 os_get_reltime(&now);
704 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
Hai Shalom021b0b52019-04-10 11:17:58 -0700705 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60) ||
706 hapd->sae_token_idx == 0xffff) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800707 if (random_get_bytes(hapd->sae_token_key,
708 sizeof(hapd->sae_token_key)) < 0)
709 return NULL;
710 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
711 hapd->sae_token_key, sizeof(hapd->sae_token_key));
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800712 hapd->last_sae_token_key_update = now;
Hai Shalom021b0b52019-04-10 11:17:58 -0700713 hapd->sae_token_idx = 0;
714 os_memset(hapd->sae_pending_token_idx, 0,
715 sizeof(hapd->sae_pending_token_idx));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800716 }
717
Hai Shalomfdcde762020-04-02 11:19:20 -0700718 buf = wpabuf_alloc(sizeof(le16) + 3 + SHA256_MAC_LEN);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800719 if (buf == NULL)
720 return NULL;
721
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800722 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
723
Hai Shalomfdcde762020-04-02 11:19:20 -0700724 if (h2e) {
725 /* Encapsulate Anti-clogging Token field in a container IE */
726 wpabuf_put_u8(buf, WLAN_EID_EXTENSION);
727 wpabuf_put_u8(buf, 1 + SHA256_MAC_LEN);
728 wpabuf_put_u8(buf, WLAN_EID_EXT_ANTI_CLOGGING_TOKEN);
729 }
730
731 if (sae_token_hash(hapd, addr, &p_idx) < 0) {
732 wpabuf_free(buf);
733 return NULL;
734 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700735 token_idx = hapd->sae_pending_token_idx[p_idx];
736 if (!token_idx) {
737 hapd->sae_token_idx++;
738 token_idx = hapd->sae_token_idx;
739 hapd->sae_pending_token_idx[p_idx] = token_idx;
740 }
741 WPA_PUT_BE16(idx, token_idx);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800742 token = wpabuf_put(buf, SHA256_MAC_LEN);
Hai Shalom021b0b52019-04-10 11:17:58 -0700743 addrs[0] = addr;
744 len[0] = ETH_ALEN;
745 addrs[1] = idx;
746 len[1] = sizeof(idx);
747 if (hmac_sha256_vector(hapd->sae_token_key, sizeof(hapd->sae_token_key),
748 2, addrs, len, token) < 0) {
749 wpabuf_free(buf);
750 return NULL;
751 }
752 WPA_PUT_BE16(token, token_idx);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800753
754 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800755}
756
757
Roshan Pius3a1667e2018-07-03 15:17:14 -0700758static int sae_check_big_sync(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800759{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700760 if (sta->sae->sync > hapd->conf->sae_sync) {
761 sae_set_state(sta, SAE_NOTHING, "Sync > dot11RSNASAESync");
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800762 sta->sae->sync = 0;
763 return -1;
764 }
765 return 0;
766}
767
768
769static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
770{
771 struct hostapd_data *hapd = eloop_ctx;
772 struct sta_info *sta = eloop_data;
773 int ret;
774
Roshan Pius3a1667e2018-07-03 15:17:14 -0700775 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800776 return;
777 sta->sae->sync++;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700778 wpa_printf(MSG_DEBUG, "SAE: Auth SAE retransmit timer for " MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700779 " (sync=%d state=%s)",
780 MAC2STR(sta->addr), sta->sae->sync,
781 sae_state_txt(sta->sae->state));
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800782
783 switch (sta->sae->state) {
784 case SAE_COMMITTED:
Hai Shalomc3565922019-10-28 11:58:20 -0700785 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0, -1);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800786 eloop_register_timeout(0,
787 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800788 auth_sae_retransmit_timer, hapd, sta);
789 break;
790 case SAE_CONFIRMED:
791 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800792 eloop_register_timeout(0,
793 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800794 auth_sae_retransmit_timer, hapd, sta);
795 break;
796 default:
797 ret = -1;
798 break;
799 }
800
801 if (ret != WLAN_STATUS_SUCCESS)
802 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
803}
804
805
806void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
807{
808 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
809}
810
811
812static void sae_set_retransmit_timer(struct hostapd_data *hapd,
813 struct sta_info *sta)
814{
815 if (!(hapd->conf->mesh & MESH_ENABLED))
816 return;
817
818 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800819 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800820 auth_sae_retransmit_timer, hapd, sta);
821}
822
823
Hai Shalom5f92bc92019-04-18 11:54:11 -0700824static void sae_sme_send_external_auth_status(struct hostapd_data *hapd,
825 struct sta_info *sta, u16 status)
826{
827 struct external_auth params;
828
829 os_memset(&params, 0, sizeof(params));
830 params.status = status;
831 params.bssid = sta->addr;
Hai Shalom81f62d82019-07-22 12:10:00 -0700832 if (status == WLAN_STATUS_SUCCESS && sta->sae &&
833 !hapd->conf->disable_pmksa_caching)
Hai Shalom5f92bc92019-04-18 11:54:11 -0700834 params.pmkid = sta->sae->pmkid;
835
836 hostapd_drv_send_external_auth_status(hapd, &params);
837}
838
839
Dmitry Shmidte4663042016-04-04 10:07:49 -0700840void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
841{
Hai Shalom021b0b52019-04-10 11:17:58 -0700842#ifndef CONFIG_NO_VLAN
843 struct vlan_description vlan_desc;
844
845 if (sta->sae->tmp && sta->sae->tmp->vlan_id > 0) {
846 wpa_printf(MSG_DEBUG, "SAE: Assign STA " MACSTR
847 " to VLAN ID %d",
848 MAC2STR(sta->addr), sta->sae->tmp->vlan_id);
849
850 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
851 vlan_desc.notempty = 1;
852 vlan_desc.untagged = sta->sae->tmp->vlan_id;
853 if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
854 wpa_printf(MSG_INFO,
855 "Invalid VLAN ID %d in sae_password",
856 sta->sae->tmp->vlan_id);
857 return;
858 }
859
860 if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0 ||
861 ap_sta_bind_vlan(hapd, sta) < 0) {
862 wpa_printf(MSG_INFO,
863 "Failed to assign VLAN ID %d from sae_password to "
864 MACSTR, sta->sae->tmp->vlan_id,
865 MAC2STR(sta->addr));
866 return;
867 }
868 }
869#endif /* CONFIG_NO_VLAN */
870
Dmitry Shmidte4663042016-04-04 10:07:49 -0700871 sta->flags |= WLAN_STA_AUTH;
872 sta->auth_alg = WLAN_AUTH_SAE;
873 mlme_authenticate_indication(hapd, sta);
874 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700875 sae_set_state(sta, SAE_ACCEPTED, "Accept Confirm");
Hai Shalomfdcde762020-04-02 11:19:20 -0700876 crypto_bignum_deinit(sta->sae->peer_commit_scalar_accepted, 0);
877 sta->sae->peer_commit_scalar_accepted = sta->sae->peer_commit_scalar;
878 sta->sae->peer_commit_scalar = NULL;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700879 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
880 sta->sae->pmk, sta->sae->pmkid);
Hai Shalom5f92bc92019-04-18 11:54:11 -0700881 sae_sme_send_external_auth_status(hapd, sta, WLAN_STATUS_SUCCESS);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700882}
883
884
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800885static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
Hai Shalomc3565922019-10-28 11:58:20 -0700886 const u8 *bssid, u16 auth_transaction, u16 status_code,
887 int allow_reuse, int *sta_removed)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800888{
889 int ret;
890
Hai Shalom5f92bc92019-04-18 11:54:11 -0700891 *sta_removed = 0;
892
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800893 if (auth_transaction != 1 && auth_transaction != 2)
894 return WLAN_STATUS_UNSPECIFIED_FAILURE;
895
Roshan Pius3a1667e2018-07-03 15:17:14 -0700896 wpa_printf(MSG_DEBUG, "SAE: Peer " MACSTR " state=%s auth_trans=%u",
897 MAC2STR(sta->addr), sae_state_txt(sta->sae->state),
898 auth_transaction);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800899 switch (sta->sae->state) {
900 case SAE_NOTHING:
901 if (auth_transaction == 1) {
Hai Shalomc3565922019-10-28 11:58:20 -0700902 if (sta->sae->tmp)
903 sta->sae->tmp->h2e = status_code ==
904 WLAN_STATUS_SAE_HASH_TO_ELEMENT;
Hai Shalom021b0b52019-04-10 11:17:58 -0700905 ret = auth_sae_send_commit(hapd, sta, bssid,
Hai Shalomc3565922019-10-28 11:58:20 -0700906 !allow_reuse, status_code);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800907 if (ret)
908 return ret;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700909 sae_set_state(sta, SAE_COMMITTED, "Sent Commit");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800910
911 if (sae_process_commit(sta->sae) < 0)
912 return WLAN_STATUS_UNSPECIFIED_FAILURE;
913
914 /*
Hai Shalomc3565922019-10-28 11:58:20 -0700915 * In mesh case, both Commit and Confirm are sent
916 * immediately. In infrastructure BSS, by default, only
917 * a single Authentication frame (Commit) is expected
918 * from the AP here and the second one (Confirm) will
919 * be sent once the STA has sent its second
920 * Authentication frame (Confirm). This behavior can be
921 * overridden with explicit configuration so that the
922 * infrastructure BSS case sends both frames together.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800923 */
Hai Shalomc3565922019-10-28 11:58:20 -0700924 if ((hapd->conf->mesh & MESH_ENABLED) ||
925 hapd->conf->sae_confirm_immediate) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800926 /*
927 * Send both Commit and Confirm immediately
928 * based on SAE finite state machine
929 * Nothing -> Confirm transition.
930 */
931 ret = auth_sae_send_confirm(hapd, sta, bssid);
932 if (ret)
933 return ret;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700934 sae_set_state(sta, SAE_CONFIRMED,
935 "Sent Confirm (mesh)");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800936 } else {
937 /*
938 * For infrastructure BSS, send only the Commit
939 * message now to get alternating sequence of
940 * Authentication frames between the AP and STA.
941 * Confirm will be sent in
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800942 * Committed -> Confirmed/Accepted transition
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800943 * when receiving Confirm from STA.
944 */
945 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800946 sta->sae->sync = 0;
947 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800948 } else {
949 hostapd_logger(hapd, sta->addr,
950 HOSTAPD_MODULE_IEEE80211,
951 HOSTAPD_LEVEL_DEBUG,
952 "SAE confirm before commit");
953 }
954 break;
955 case SAE_COMMITTED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800956 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800957 if (auth_transaction == 1) {
958 if (sae_process_commit(sta->sae) < 0)
959 return WLAN_STATUS_UNSPECIFIED_FAILURE;
960
961 ret = auth_sae_send_confirm(hapd, sta, bssid);
962 if (ret)
963 return ret;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700964 sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm");
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800965 sta->sae->sync = 0;
966 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800967 } else if (hapd->conf->mesh & MESH_ENABLED) {
968 /*
969 * In mesh case, follow SAE finite state machine and
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800970 * send Commit now, if sync count allows.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800971 */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700972 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800973 return WLAN_STATUS_SUCCESS;
974 sta->sae->sync++;
975
Hai Shalomc3565922019-10-28 11:58:20 -0700976 ret = auth_sae_send_commit(hapd, sta, bssid, 0,
977 status_code);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800978 if (ret)
979 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800980
981 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800982 } else {
983 /*
984 * For instructure BSS, send the postponed Confirm from
985 * Nothing -> Confirmed transition that was reduced to
986 * Nothing -> Committed above.
987 */
988 ret = auth_sae_send_confirm(hapd, sta, bssid);
989 if (ret)
990 return ret;
991
Roshan Pius3a1667e2018-07-03 15:17:14 -0700992 sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800993
994 /*
995 * Since this was triggered on Confirm RX, run another
996 * step to get to Accepted without waiting for
997 * additional events.
998 */
Hai Shalom021b0b52019-04-10 11:17:58 -0700999 return sae_sm_step(hapd, sta, bssid, auth_transaction,
Hai Shalomc3565922019-10-28 11:58:20 -07001000 WLAN_STATUS_SUCCESS, 0, sta_removed);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001001 }
1002 break;
1003 case SAE_CONFIRMED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001004 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001005 if (auth_transaction == 1) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001006 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001007 return WLAN_STATUS_SUCCESS;
1008 sta->sae->sync++;
1009
Hai Shalomc3565922019-10-28 11:58:20 -07001010 ret = auth_sae_send_commit(hapd, sta, bssid, 1,
1011 status_code);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001012 if (ret)
1013 return ret;
1014
1015 if (sae_process_commit(sta->sae) < 0)
1016 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1017
1018 ret = auth_sae_send_confirm(hapd, sta, bssid);
1019 if (ret)
1020 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001021
1022 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001023 } else {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001024 sta->sae->send_confirm = 0xffff;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001025 sae_accept_sta(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001026 }
1027 break;
1028 case SAE_ACCEPTED:
Roshan Pius3a1667e2018-07-03 15:17:14 -07001029 if (auth_transaction == 1 &&
1030 (hapd->conf->mesh & MESH_ENABLED)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001031 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
1032 ") doing reauthentication",
1033 MAC2STR(sta->addr));
Dmitry Shmidte4663042016-04-04 10:07:49 -07001034 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
Hai Shalom5f92bc92019-04-18 11:54:11 -07001035 ap_free_sta(hapd, sta);
1036 *sta_removed = 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001037 } else if (auth_transaction == 1) {
1038 wpa_printf(MSG_DEBUG, "SAE: Start reauthentication");
Hai Shalomc3565922019-10-28 11:58:20 -07001039 ret = auth_sae_send_commit(hapd, sta, bssid, 1,
1040 status_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001041 if (ret)
1042 return ret;
1043 sae_set_state(sta, SAE_COMMITTED, "Sent Commit");
1044
1045 if (sae_process_commit(sta->sae) < 0)
1046 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1047 sta->sae->sync = 0;
1048 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001049 } else {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001050 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001051 return WLAN_STATUS_SUCCESS;
1052 sta->sae->sync++;
1053
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001054 ret = auth_sae_send_confirm(hapd, sta, bssid);
1055 sae_clear_temp_data(sta->sae);
1056 if (ret)
1057 return ret;
1058 }
1059 break;
1060 default:
1061 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
1062 sta->sae->state);
1063 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1064 }
1065 return WLAN_STATUS_SUCCESS;
1066}
1067
1068
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001069static void sae_pick_next_group(struct hostapd_data *hapd, struct sta_info *sta)
1070{
1071 struct sae_data *sae = sta->sae;
1072 int i, *groups = hapd->conf->sae_groups;
Hai Shalom021b0b52019-04-10 11:17:58 -07001073 int default_groups[] = { 19, 0 };
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001074
1075 if (sae->state != SAE_COMMITTED)
1076 return;
1077
1078 wpa_printf(MSG_DEBUG, "SAE: Previously selected group: %d", sae->group);
1079
Hai Shalom021b0b52019-04-10 11:17:58 -07001080 if (!groups)
1081 groups = default_groups;
1082 for (i = 0; groups[i] > 0; i++) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001083 if (sae->group == groups[i])
1084 break;
1085 }
1086
Hai Shalom021b0b52019-04-10 11:17:58 -07001087 if (groups[i] <= 0) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001088 wpa_printf(MSG_DEBUG,
1089 "SAE: Previously selected group not found from the current configuration");
1090 return;
1091 }
1092
1093 for (;;) {
1094 i++;
1095 if (groups[i] <= 0) {
1096 wpa_printf(MSG_DEBUG,
1097 "SAE: No alternative group enabled");
1098 return;
1099 }
1100
1101 if (sae_set_group(sae, groups[i]) < 0)
1102 continue;
1103
1104 break;
1105 }
1106 wpa_printf(MSG_DEBUG, "SAE: Selected new group: %d", groups[i]);
1107}
1108
1109
Hai Shalomc3565922019-10-28 11:58:20 -07001110static int sae_status_success(struct hostapd_data *hapd, u16 status_code)
1111{
Hai Shalomfdcde762020-04-02 11:19:20 -07001112 int sae_pwe = hapd->conf->sae_pwe;
1113 int id_in_use;
1114
1115 id_in_use = hostapd_sae_pw_id_in_use(hapd->conf);
1116 if (id_in_use == 2 && sae_pwe != 3)
1117 sae_pwe = 1;
1118 else if (id_in_use == 1 && sae_pwe == 0)
1119 sae_pwe = 2;
1120
1121 return ((sae_pwe == 0 || sae_pwe == 3) &&
Hai Shalomc3565922019-10-28 11:58:20 -07001122 status_code == WLAN_STATUS_SUCCESS) ||
Hai Shalomfdcde762020-04-02 11:19:20 -07001123 (sae_pwe == 1 &&
Hai Shalomc3565922019-10-28 11:58:20 -07001124 status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT) ||
Hai Shalomfdcde762020-04-02 11:19:20 -07001125 (sae_pwe == 2 &&
Hai Shalomc3565922019-10-28 11:58:20 -07001126 (status_code == WLAN_STATUS_SUCCESS ||
1127 status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT));
1128}
1129
1130
1131static int sae_is_group_enabled(struct hostapd_data *hapd, int group)
1132{
1133 int *groups = hapd->conf->sae_groups;
1134 int default_groups[] = { 19, 0 };
1135 int i;
1136
1137 if (!groups)
1138 groups = default_groups;
1139
1140 for (i = 0; groups[i] > 0; i++) {
1141 if (groups[i] == group)
1142 return 1;
1143 }
1144
1145 return 0;
1146}
1147
1148
1149static int check_sae_rejected_groups(struct hostapd_data *hapd,
1150 const struct wpabuf *groups)
1151{
1152 size_t i, count;
1153 const u8 *pos;
1154
1155 if (!groups)
1156 return 0;
1157
1158 pos = wpabuf_head(groups);
1159 count = wpabuf_len(groups) / 2;
1160 for (i = 0; i < count; i++) {
1161 int enabled;
1162 u16 group;
1163
1164 group = WPA_GET_LE16(pos);
1165 pos += 2;
1166 enabled = sae_is_group_enabled(hapd, group);
1167 wpa_printf(MSG_DEBUG, "SAE: Rejected group %u is %s",
1168 group, enabled ? "enabled" : "disabled");
1169 if (enabled)
1170 return 1;
1171 }
1172
1173 return 0;
1174}
1175
1176
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001177static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
1178 const struct ieee80211_mgmt *mgmt, size_t len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001179 u16 auth_transaction, u16 status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001180{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001181 int resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001182 struct wpabuf *data = NULL;
Hai Shalom021b0b52019-04-10 11:17:58 -07001183 int *groups = hapd->conf->sae_groups;
1184 int default_groups[] = { 19, 0 };
1185 const u8 *pos, *end;
Hai Shalom5f92bc92019-04-18 11:54:11 -07001186 int sta_removed = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -07001187
1188 if (!groups)
1189 groups = default_groups;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001190
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001191#ifdef CONFIG_TESTING_OPTIONS
1192 if (hapd->conf->sae_reflection_attack && auth_transaction == 1) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001193 wpa_printf(MSG_DEBUG, "SAE: TESTING - reflection attack");
1194 pos = mgmt->u.auth.variable;
1195 end = ((const u8 *) mgmt) + len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001196 send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001197 auth_transaction, resp, pos, end - pos,
1198 "auth-sae-reflection-attack");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001199 goto remove_sta;
1200 }
1201
1202 if (hapd->conf->sae_commit_override && auth_transaction == 1) {
1203 wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override");
Hai Shalomfdcde762020-04-02 11:19:20 -07001204 send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001205 auth_transaction, resp,
1206 wpabuf_head(hapd->conf->sae_commit_override),
Roshan Pius3a1667e2018-07-03 15:17:14 -07001207 wpabuf_len(hapd->conf->sae_commit_override),
1208 "sae-commit-override");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001209 goto remove_sta;
1210 }
1211#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001212 if (!sta->sae) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001213 if (auth_transaction != 1 ||
Hai Shalomc3565922019-10-28 11:58:20 -07001214 !sae_status_success(hapd, status_code)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001215 wpa_printf(MSG_DEBUG, "SAE: Unexpected Status Code %u",
1216 status_code);
1217 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1218 goto reply;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001219 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001220 sta->sae = os_zalloc(sizeof(*sta->sae));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001221 if (!sta->sae) {
1222 resp = -1;
1223 goto remove_sta;
1224 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001225 sae_set_state(sta, SAE_NOTHING, "Init");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001226 sta->sae->sync = 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001227 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001228
Dmitry Shmidte4663042016-04-04 10:07:49 -07001229 if (sta->mesh_sae_pmksa_caching) {
1230 wpa_printf(MSG_DEBUG,
1231 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
1232 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
1233 sta->mesh_sae_pmksa_caching = 0;
1234 }
1235
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001236 if (auth_transaction == 1) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001237 const u8 *token = NULL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001238 size_t token_len = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -07001239 int allow_reuse = 0;
1240
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001241 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1242 HOSTAPD_LEVEL_DEBUG,
Hai Shalom81f62d82019-07-22 12:10:00 -07001243 "start SAE authentication (RX commit, status=%u (%s))",
1244 status_code, status2str(status_code));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001245
1246 if ((hapd->conf->mesh & MESH_ENABLED) &&
1247 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
1248 sta->sae->tmp) {
1249 pos = mgmt->u.auth.variable;
1250 end = ((const u8 *) mgmt) + len;
1251 if (pos + sizeof(le16) > end) {
1252 wpa_printf(MSG_ERROR,
1253 "SAE: Too short anti-clogging token request");
1254 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1255 goto reply;
1256 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001257 resp = sae_group_allowed(sta->sae, groups,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001258 WPA_GET_LE16(pos));
1259 if (resp != WLAN_STATUS_SUCCESS) {
1260 wpa_printf(MSG_ERROR,
1261 "SAE: Invalid group in anti-clogging token request");
1262 goto reply;
1263 }
1264 pos += sizeof(le16);
1265
1266 wpabuf_free(sta->sae->tmp->anti_clogging_token);
1267 sta->sae->tmp->anti_clogging_token =
1268 wpabuf_alloc_copy(pos, end - pos);
1269 if (sta->sae->tmp->anti_clogging_token == NULL) {
1270 wpa_printf(MSG_ERROR,
1271 "SAE: Failed to alloc for anti-clogging token");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001272 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1273 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001274 }
1275
1276 /*
1277 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
1278 * is 76, a new Commit Message shall be constructed
1279 * with the Anti-Clogging Token from the received
1280 * Authentication frame, and the commit-scalar and
1281 * COMMIT-ELEMENT previously sent.
1282 */
Hai Shalomc3565922019-10-28 11:58:20 -07001283 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0,
1284 status_code);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001285 if (resp != WLAN_STATUS_SUCCESS) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001286 wpa_printf(MSG_ERROR,
1287 "SAE: Failed to send commit message");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001288 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001289 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001290 sae_set_state(sta, SAE_COMMITTED,
1291 "Sent Commit (anti-clogging token case in mesh)");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001292 sta->sae->sync = 0;
1293 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001294 return;
1295 }
1296
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001297 if ((hapd->conf->mesh & MESH_ENABLED) &&
1298 status_code ==
1299 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
1300 sta->sae->tmp) {
1301 wpa_printf(MSG_DEBUG,
1302 "SAE: Peer did not accept our SAE group");
1303 sae_pick_next_group(hapd, sta);
1304 goto remove_sta;
1305 }
1306
Hai Shalomc3565922019-10-28 11:58:20 -07001307 if (!sae_status_success(hapd, status_code))
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001308 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001309
Roshan Pius3a1667e2018-07-03 15:17:14 -07001310 if (!(hapd->conf->mesh & MESH_ENABLED) &&
1311 sta->sae->state == SAE_COMMITTED) {
1312 /* This is needed in the infrastructure BSS case to
1313 * address a sequence where a STA entry may remain in
1314 * hostapd across two attempts to do SAE authentication
1315 * by the same STA. The second attempt may end up trying
1316 * to use a different group and that would not be
1317 * allowed if we remain in Committed state with the
1318 * previously set parameters. */
Hai Shalom021b0b52019-04-10 11:17:58 -07001319 pos = mgmt->u.auth.variable;
1320 end = ((const u8 *) mgmt) + len;
1321 if (end - pos >= (int) sizeof(le16) &&
1322 sae_group_allowed(sta->sae, groups,
1323 WPA_GET_LE16(pos)) ==
1324 WLAN_STATUS_SUCCESS) {
1325 /* Do not waste resources deriving the same PWE
1326 * again since the same group is reused. */
1327 sae_set_state(sta, SAE_NOTHING,
1328 "Allow previous PWE to be reused");
1329 allow_reuse = 1;
1330 } else {
1331 sae_set_state(sta, SAE_NOTHING,
1332 "Clear existing state to allow restart");
1333 sae_clear_data(sta->sae);
1334 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001335 }
1336
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001337 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
1338 ((const u8 *) mgmt) + len -
1339 mgmt->u.auth.variable, &token,
Hai Shalomc3565922019-10-28 11:58:20 -07001340 &token_len, groups, status_code ==
1341 WLAN_STATUS_SAE_HASH_TO_ELEMENT);
Dmitry Shmidt41712582015-06-29 11:02:15 -07001342 if (resp == SAE_SILENTLY_DISCARD) {
1343 wpa_printf(MSG_DEBUG,
1344 "SAE: Drop commit message from " MACSTR " due to reflection attack",
1345 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001346 goto remove_sta;
Dmitry Shmidt41712582015-06-29 11:02:15 -07001347 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001348
1349 if (resp == WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER) {
1350 wpa_msg(hapd->msg_ctx, MSG_INFO,
1351 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER
1352 MACSTR, MAC2STR(sta->addr));
1353 sae_clear_retransmit_timer(hapd, sta);
1354 sae_set_state(sta, SAE_NOTHING,
1355 "Unknown Password Identifier");
1356 goto remove_sta;
1357 }
1358
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001359 if (token && check_sae_token(hapd, sta->addr, token, token_len)
1360 < 0) {
1361 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
1362 "incorrect token from " MACSTR,
1363 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001364 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1365 goto remove_sta;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001366 }
1367
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001368 if (resp != WLAN_STATUS_SUCCESS)
1369 goto reply;
1370
Hai Shalomc3565922019-10-28 11:58:20 -07001371 if (sta->sae->tmp &&
1372 check_sae_rejected_groups(
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001373 hapd, sta->sae->tmp->peer_rejected_groups)) {
Hai Shalomc3565922019-10-28 11:58:20 -07001374 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001375 goto reply;
Hai Shalomc3565922019-10-28 11:58:20 -07001376 }
1377
Hai Shalom021b0b52019-04-10 11:17:58 -07001378 if (!token && use_sae_anti_clogging(hapd) && !allow_reuse) {
Hai Shalomfdcde762020-04-02 11:19:20 -07001379 int h2e = 0;
1380
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001381 wpa_printf(MSG_DEBUG,
1382 "SAE: Request anti-clogging token from "
1383 MACSTR, MAC2STR(sta->addr));
Hai Shalomfdcde762020-04-02 11:19:20 -07001384 if (sta->sae->tmp)
1385 h2e = sta->sae->tmp->h2e;
1386 if (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT)
1387 h2e = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001388 data = auth_build_token_req(hapd, sta->sae->group,
Hai Shalomfdcde762020-04-02 11:19:20 -07001389 sta->addr, h2e);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001390 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
1391 if (hapd->conf->mesh & MESH_ENABLED)
Roshan Pius3a1667e2018-07-03 15:17:14 -07001392 sae_set_state(sta, SAE_NOTHING,
1393 "Request anti-clogging token case in mesh");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001394 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001395 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001396
Hai Shalom021b0b52019-04-10 11:17:58 -07001397 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction,
Hai Shalomc3565922019-10-28 11:58:20 -07001398 status_code, allow_reuse, &sta_removed);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001399 } else if (auth_transaction == 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001400 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1401 HOSTAPD_LEVEL_DEBUG,
Hai Shalom81f62d82019-07-22 12:10:00 -07001402 "SAE authentication (RX confirm, status=%u (%s))",
1403 status_code, status2str(status_code));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001404 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001405 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001406 if (sta->sae->state >= SAE_CONFIRMED ||
1407 !(hapd->conf->mesh & MESH_ENABLED)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001408 const u8 *var;
1409 size_t var_len;
1410 u16 peer_send_confirm;
1411
1412 var = mgmt->u.auth.variable;
1413 var_len = ((u8 *) mgmt) + len - mgmt->u.auth.variable;
1414 if (var_len < 2) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001415 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001416 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001417 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001418
1419 peer_send_confirm = WPA_GET_LE16(var);
1420
1421 if (sta->sae->state == SAE_ACCEPTED &&
1422 (peer_send_confirm <= sta->sae->rc ||
1423 peer_send_confirm == 0xffff)) {
1424 wpa_printf(MSG_DEBUG,
1425 "SAE: Silently ignore unexpected Confirm from peer "
1426 MACSTR
1427 " (peer-send-confirm=%u Rc=%u)",
1428 MAC2STR(sta->addr),
1429 peer_send_confirm, sta->sae->rc);
1430 return;
1431 }
1432
1433 if (sae_check_confirm(sta->sae, var, var_len) < 0) {
1434 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1435 goto reply;
1436 }
1437 sta->sae->rc = peer_send_confirm;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001438 }
Hai Shalomc3565922019-10-28 11:58:20 -07001439 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction,
1440 status_code, 0, &sta_removed);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001441 } else {
1442 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1443 HOSTAPD_LEVEL_DEBUG,
Hai Shalom81f62d82019-07-22 12:10:00 -07001444 "unexpected SAE authentication transaction %u (status=%u (%s))",
1445 auth_transaction, status_code,
1446 status2str(status_code));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001447 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001448 goto remove_sta;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001449 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1450 }
1451
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001452reply:
Hai Shalom5f92bc92019-04-18 11:54:11 -07001453 if (!sta_removed && resp != WLAN_STATUS_SUCCESS) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001454 pos = mgmt->u.auth.variable;
1455 end = ((const u8 *) mgmt) + len;
1456
1457 /* Copy the Finite Cyclic Group field from the request if we
1458 * rejected it as unsupported group. */
1459 if (resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
1460 !data && end - pos >= 2)
1461 data = wpabuf_alloc_copy(pos, 2);
1462
Hai Shalom5f92bc92019-04-18 11:54:11 -07001463 sae_sme_send_external_auth_status(hapd, sta, resp);
Hai Shalomfdcde762020-04-02 11:19:20 -07001464 send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001465 auth_transaction, resp,
1466 data ? wpabuf_head(data) : (u8 *) "",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001467 data ? wpabuf_len(data) : 0, "auth-sae");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001468 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001469
1470remove_sta:
Hai Shalom5f92bc92019-04-18 11:54:11 -07001471 if (!sta_removed && sta->added_unassoc &&
1472 (resp != WLAN_STATUS_SUCCESS ||
1473 status_code != WLAN_STATUS_SUCCESS)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001474 hostapd_drv_sta_remove(hapd, sta->addr);
1475 sta->added_unassoc = 0;
1476 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001477 wpabuf_free(data);
1478}
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001479
1480
1481/**
1482 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1483 * @hapd: BSS data for the device initiating the authentication
1484 * @sta: the peer to which commit authentication frame is sent
1485 *
1486 * This function implements Init event handling (IEEE Std 802.11-2012,
1487 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1488 * sta->sae structure should be initialized appropriately via a call to
1489 * sae_prepare_commit().
1490 */
1491int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
1492{
1493 int ret;
1494
1495 if (!sta->sae || !sta->sae->tmp)
1496 return -1;
1497
1498 if (sta->sae->state != SAE_NOTHING)
1499 return -1;
1500
Hai Shalomc3565922019-10-28 11:58:20 -07001501 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0, -1);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001502 if (ret)
1503 return -1;
1504
Roshan Pius3a1667e2018-07-03 15:17:14 -07001505 sae_set_state(sta, SAE_COMMITTED, "Init and sent commit");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001506 sta->sae->sync = 0;
1507 sae_set_retransmit_timer(hapd, sta);
1508
1509 return 0;
1510}
1511
Hai Shalom021b0b52019-04-10 11:17:58 -07001512
1513void auth_sae_process_commit(void *eloop_ctx, void *user_ctx)
1514{
1515 struct hostapd_data *hapd = eloop_ctx;
1516 struct hostapd_sae_commit_queue *q;
1517 unsigned int queue_len;
1518
1519 q = dl_list_first(&hapd->sae_commit_queue,
1520 struct hostapd_sae_commit_queue, list);
1521 if (!q)
1522 return;
1523 wpa_printf(MSG_DEBUG,
1524 "SAE: Process next available message from queue");
1525 dl_list_del(&q->list);
1526 handle_auth(hapd, (const struct ieee80211_mgmt *) q->msg, q->len,
1527 q->rssi, 1);
1528 os_free(q);
1529
1530 if (eloop_is_timeout_registered(auth_sae_process_commit, hapd, NULL))
1531 return;
1532 queue_len = dl_list_len(&hapd->sae_commit_queue);
1533 eloop_register_timeout(0, queue_len * 10000, auth_sae_process_commit,
1534 hapd, NULL);
1535}
1536
1537
1538static void auth_sae_queue(struct hostapd_data *hapd,
1539 const struct ieee80211_mgmt *mgmt, size_t len,
1540 int rssi)
1541{
1542 struct hostapd_sae_commit_queue *q, *q2;
1543 unsigned int queue_len;
1544 const struct ieee80211_mgmt *mgmt2;
1545
1546 queue_len = dl_list_len(&hapd->sae_commit_queue);
1547 if (queue_len >= 15) {
1548 wpa_printf(MSG_DEBUG,
1549 "SAE: No more room in message queue - drop the new frame from "
1550 MACSTR, MAC2STR(mgmt->sa));
1551 return;
1552 }
1553
1554 wpa_printf(MSG_DEBUG, "SAE: Queue Authentication message from "
1555 MACSTR " for processing (queue_len %u)", MAC2STR(mgmt->sa),
1556 queue_len);
1557 q = os_zalloc(sizeof(*q) + len);
1558 if (!q)
1559 return;
1560 q->rssi = rssi;
1561 q->len = len;
1562 os_memcpy(q->msg, mgmt, len);
1563
1564 /* Check whether there is already a queued Authentication frame from the
1565 * same station with the same transaction number and if so, replace that
1566 * queue entry with the new one. This avoids issues with a peer that
1567 * sends multiple times (e.g., due to frequent SAE retries). There is no
1568 * point in us trying to process the old attempts after a new one has
1569 * obsoleted them. */
1570 dl_list_for_each(q2, &hapd->sae_commit_queue,
1571 struct hostapd_sae_commit_queue, list) {
1572 mgmt2 = (const struct ieee80211_mgmt *) q2->msg;
1573 if (os_memcmp(mgmt->sa, mgmt2->sa, ETH_ALEN) == 0 &&
1574 mgmt->u.auth.auth_transaction ==
1575 mgmt2->u.auth.auth_transaction) {
1576 wpa_printf(MSG_DEBUG,
1577 "SAE: Replace queued message from same STA with same transaction number");
1578 dl_list_add(&q2->list, &q->list);
1579 dl_list_del(&q2->list);
1580 os_free(q2);
1581 goto queued;
1582 }
1583 }
1584
1585 /* No pending identical entry, so add to the end of the queue */
1586 dl_list_add_tail(&hapd->sae_commit_queue, &q->list);
1587
1588queued:
1589 if (eloop_is_timeout_registered(auth_sae_process_commit, hapd, NULL))
1590 return;
1591 eloop_register_timeout(0, queue_len * 10000, auth_sae_process_commit,
1592 hapd, NULL);
1593}
1594
1595
1596static int auth_sae_queued_addr(struct hostapd_data *hapd, const u8 *addr)
1597{
1598 struct hostapd_sae_commit_queue *q;
1599 const struct ieee80211_mgmt *mgmt;
1600
1601 dl_list_for_each(q, &hapd->sae_commit_queue,
1602 struct hostapd_sae_commit_queue, list) {
1603 mgmt = (const struct ieee80211_mgmt *) q->msg;
1604 if (os_memcmp(addr, mgmt->sa, ETH_ALEN) == 0)
1605 return 1;
1606 }
1607
1608 return 0;
1609}
1610
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001611#endif /* CONFIG_SAE */
1612
1613
Hai Shalomfdcde762020-04-02 11:19:20 -07001614static u16 wpa_res_to_status_code(enum wpa_validate_result res)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001615{
Hai Shalomfdcde762020-04-02 11:19:20 -07001616 switch (res) {
1617 case WPA_IE_OK:
1618 return WLAN_STATUS_SUCCESS;
1619 case WPA_INVALID_IE:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001620 return WLAN_STATUS_INVALID_IE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001621 case WPA_INVALID_GROUP:
1622 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1623 case WPA_INVALID_PAIRWISE:
1624 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1625 case WPA_INVALID_AKMP:
1626 return WLAN_STATUS_AKMP_NOT_VALID;
1627 case WPA_NOT_ENABLED:
1628 return WLAN_STATUS_INVALID_IE;
1629 case WPA_ALLOC_FAIL:
1630 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1631 case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
1632 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1633 case WPA_INVALID_MGMT_GROUP_CIPHER:
1634 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1635 case WPA_INVALID_MDIE:
1636 return WLAN_STATUS_INVALID_MDIE;
1637 case WPA_INVALID_PROTO:
1638 return WLAN_STATUS_INVALID_IE;
1639 case WPA_INVALID_PMKID:
1640 return WLAN_STATUS_INVALID_PMKID;
1641 case WPA_DENIED_OTHER_REASON:
1642 return WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1643 }
1644 return WLAN_STATUS_INVALID_IE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001645}
1646
1647
1648#ifdef CONFIG_FILS
1649
1650static void handle_auth_fils_finish(struct hostapd_data *hapd,
1651 struct sta_info *sta, u16 resp,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001652 struct wpabuf *data, int pub);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001653
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001654void handle_auth_fils(struct hostapd_data *hapd, struct sta_info *sta,
1655 const u8 *pos, size_t len, u16 auth_alg,
1656 u16 auth_transaction, u16 status_code,
1657 void (*cb)(struct hostapd_data *hapd,
1658 struct sta_info *sta, u16 resp,
1659 struct wpabuf *data, int pub))
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001660{
1661 u16 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001662 const u8 *end;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001663 struct ieee802_11_elems elems;
Hai Shalomfdcde762020-04-02 11:19:20 -07001664 enum wpa_validate_result res;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001665 struct wpa_ie_data rsn;
1666 struct rsn_pmksa_cache_entry *pmksa = NULL;
1667
1668 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
1669 return;
1670
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001671 end = pos + len;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001672
1673 wpa_hexdump(MSG_DEBUG, "FILS: Authentication frame fields",
1674 pos, end - pos);
1675
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001676 /* TODO: FILS PK */
1677#ifdef CONFIG_FILS_SK_PFS
1678 if (auth_alg == WLAN_AUTH_FILS_SK_PFS) {
1679 u16 group;
1680 struct wpabuf *pub;
1681 size_t elem_len;
1682
1683 /* Using FILS PFS */
1684
1685 /* Finite Cyclic Group */
1686 if (end - pos < 2) {
1687 wpa_printf(MSG_DEBUG,
1688 "FILS: No room for Finite Cyclic Group");
1689 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1690 goto fail;
1691 }
1692 group = WPA_GET_LE16(pos);
1693 pos += 2;
1694 if (group != hapd->conf->fils_dh_group) {
1695 wpa_printf(MSG_DEBUG,
1696 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1697 group, hapd->conf->fils_dh_group);
1698 resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
1699 goto fail;
1700 }
1701
1702 crypto_ecdh_deinit(sta->fils_ecdh);
1703 sta->fils_ecdh = crypto_ecdh_init(group);
1704 if (!sta->fils_ecdh) {
1705 wpa_printf(MSG_INFO,
1706 "FILS: Could not initialize ECDH with group %d",
1707 group);
1708 resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
1709 goto fail;
1710 }
1711
1712 pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
1713 if (!pub) {
1714 wpa_printf(MSG_DEBUG,
1715 "FILS: Failed to derive ECDH public key");
1716 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1717 goto fail;
1718 }
1719 elem_len = wpabuf_len(pub);
1720 wpabuf_free(pub);
1721
1722 /* Element */
1723 if ((size_t) (end - pos) < elem_len) {
1724 wpa_printf(MSG_DEBUG, "FILS: No room for Element");
1725 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1726 goto fail;
1727 }
1728
1729 wpabuf_free(sta->fils_g_sta);
1730 sta->fils_g_sta = wpabuf_alloc_copy(pos, elem_len);
1731 wpabuf_clear_free(sta->fils_dh_ss);
1732 sta->fils_dh_ss = crypto_ecdh_set_peerkey(sta->fils_ecdh, 1,
1733 pos, elem_len);
1734 if (!sta->fils_dh_ss) {
1735 wpa_printf(MSG_DEBUG, "FILS: ECDH operation failed");
1736 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1737 goto fail;
1738 }
1739 wpa_hexdump_buf_key(MSG_DEBUG, "FILS: DH_SS", sta->fils_dh_ss);
1740 pos += elem_len;
1741 } else {
1742 crypto_ecdh_deinit(sta->fils_ecdh);
1743 sta->fils_ecdh = NULL;
1744 wpabuf_clear_free(sta->fils_dh_ss);
1745 sta->fils_dh_ss = NULL;
1746 }
1747#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001748
1749 wpa_hexdump(MSG_DEBUG, "FILS: Remaining IEs", pos, end - pos);
1750 if (ieee802_11_parse_elems(pos, end - pos, &elems, 1) == ParseFailed) {
1751 wpa_printf(MSG_DEBUG, "FILS: Could not parse elements");
1752 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1753 goto fail;
1754 }
1755
1756 /* RSNE */
1757 wpa_hexdump(MSG_DEBUG, "FILS: RSN element",
1758 elems.rsn_ie, elems.rsn_ie_len);
1759 if (!elems.rsn_ie ||
1760 wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2,
1761 &rsn) < 0) {
1762 wpa_printf(MSG_DEBUG, "FILS: No valid RSN element");
1763 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1764 goto fail;
1765 }
1766
1767 if (!sta->wpa_sm)
1768 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr,
1769 NULL);
1770 if (!sta->wpa_sm) {
1771 wpa_printf(MSG_DEBUG,
1772 "FILS: Failed to initialize RSN state machine");
1773 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1774 goto fail;
1775 }
1776
1777 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -07001778 hapd->iface->freq,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001779 elems.rsn_ie - 2, elems.rsn_ie_len + 2,
Hai Shalomc3565922019-10-28 11:58:20 -07001780 elems.rsnxe ? elems.rsnxe - 2 : NULL,
1781 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001782 elems.mdie, elems.mdie_len, NULL, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001783 resp = wpa_res_to_status_code(res);
1784 if (resp != WLAN_STATUS_SUCCESS)
1785 goto fail;
1786
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001787 if (!elems.fils_nonce) {
1788 wpa_printf(MSG_DEBUG, "FILS: No FILS Nonce field");
1789 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1790 goto fail;
1791 }
1792 wpa_hexdump(MSG_DEBUG, "FILS: SNonce", elems.fils_nonce,
1793 FILS_NONCE_LEN);
1794 os_memcpy(sta->fils_snonce, elems.fils_nonce, FILS_NONCE_LEN);
1795
1796 /* PMKID List */
1797 if (rsn.pmkid && rsn.num_pmkid > 0) {
1798 u8 num;
1799 const u8 *pmkid;
1800
1801 wpa_hexdump(MSG_DEBUG, "FILS: PMKID List",
1802 rsn.pmkid, rsn.num_pmkid * PMKID_LEN);
1803
1804 pmkid = rsn.pmkid;
1805 num = rsn.num_pmkid;
1806 while (num) {
1807 wpa_hexdump(MSG_DEBUG, "FILS: PMKID", pmkid, PMKID_LEN);
1808 pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr,
1809 pmkid);
1810 if (pmksa)
1811 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001812 pmksa = wpa_auth_pmksa_get_fils_cache_id(hapd->wpa_auth,
1813 sta->addr,
1814 pmkid);
1815 if (pmksa)
1816 break;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001817 pmkid += PMKID_LEN;
1818 num--;
1819 }
1820 }
1821 if (pmksa && wpa_auth_sta_key_mgmt(sta->wpa_sm) != pmksa->akmp) {
1822 wpa_printf(MSG_DEBUG,
1823 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1824 wpa_auth_sta_key_mgmt(sta->wpa_sm), pmksa->akmp);
1825 pmksa = NULL;
1826 }
1827 if (pmksa)
1828 wpa_printf(MSG_DEBUG, "FILS: Found matching PMKSA cache entry");
1829
1830 /* FILS Session */
1831 if (!elems.fils_session) {
1832 wpa_printf(MSG_DEBUG, "FILS: No FILS Session element");
1833 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1834 goto fail;
1835 }
1836 wpa_hexdump(MSG_DEBUG, "FILS: FILS Session", elems.fils_session,
1837 FILS_SESSION_LEN);
1838 os_memcpy(sta->fils_session, elems.fils_session, FILS_SESSION_LEN);
1839
Hai Shalomfdcde762020-04-02 11:19:20 -07001840 /* Wrapped Data */
1841 if (elems.wrapped_data) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001842 wpa_hexdump(MSG_DEBUG, "FILS: Wrapped Data",
Hai Shalomfdcde762020-04-02 11:19:20 -07001843 elems.wrapped_data,
1844 elems.wrapped_data_len);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001845 if (!pmksa) {
1846#ifndef CONFIG_NO_RADIUS
1847 if (!sta->eapol_sm) {
1848 sta->eapol_sm =
1849 ieee802_1x_alloc_eapol_sm(hapd, sta);
1850 }
1851 wpa_printf(MSG_DEBUG,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001852 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001853 ieee802_1x_encapsulate_radius(
Hai Shalomfdcde762020-04-02 11:19:20 -07001854 hapd, sta, elems.wrapped_data,
1855 elems.wrapped_data_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001856 sta->fils_pending_cb = cb;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001857 wpa_printf(MSG_DEBUG,
1858 "FILS: Will send Authentication frame once the response from authentication server is available");
1859 sta->flags |= WLAN_STA_PENDING_FILS_ERP;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001860 /* Calculate pending PMKID here so that we do not need
1861 * to maintain a copy of the EAP-Initiate/Reauth
1862 * message. */
1863 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta->wpa_sm),
Hai Shalomfdcde762020-04-02 11:19:20 -07001864 elems.wrapped_data,
1865 elems.wrapped_data_len,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001866 sta->fils_erp_pmkid) == 0)
1867 sta->fils_erp_pmkid_set = 1;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001868 return;
1869#else /* CONFIG_NO_RADIUS */
1870 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1871 goto fail;
1872#endif /* CONFIG_NO_RADIUS */
1873 }
1874 }
1875
1876fail:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001877 if (cb) {
1878 struct wpabuf *data;
1879 int pub = 0;
1880
1881 data = prepare_auth_resp_fils(hapd, sta, &resp, pmksa, NULL,
1882 NULL, 0, &pub);
1883 if (!data) {
1884 wpa_printf(MSG_DEBUG,
1885 "%s: prepare_auth_resp_fils() returned failure",
1886 __func__);
1887 }
1888
1889 cb(hapd, sta, resp, data, pub);
1890 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001891}
1892
1893
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001894static struct wpabuf *
1895prepare_auth_resp_fils(struct hostapd_data *hapd,
1896 struct sta_info *sta, u16 *resp,
1897 struct rsn_pmksa_cache_entry *pmksa,
1898 struct wpabuf *erp_resp,
1899 const u8 *msk, size_t msk_len,
1900 int *is_pub)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001901{
1902 u8 fils_nonce[FILS_NONCE_LEN];
1903 size_t ielen;
1904 struct wpabuf *data = NULL;
1905 const u8 *ie;
1906 u8 *ie_buf = NULL;
1907 const u8 *pmk = NULL;
1908 size_t pmk_len = 0;
Paul Stewart092955c2017-02-06 09:13:09 -08001909 u8 pmk_buf[PMK_LEN_MAX];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001910 struct wpabuf *pub = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001911
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001912 if (*resp != WLAN_STATUS_SUCCESS)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001913 goto fail;
1914
1915 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
1916 if (!ie) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001917 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001918 goto fail;
1919 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001920
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001921 if (pmksa) {
1922 /* Add PMKID of the selected PMKSA into RSNE */
1923 ie_buf = os_malloc(ielen + 2 + 2 + PMKID_LEN);
1924 if (!ie_buf) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001925 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001926 goto fail;
1927 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001928
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001929 os_memcpy(ie_buf, ie, ielen);
1930 if (wpa_insert_pmkid(ie_buf, &ielen, pmksa->pmkid) < 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001931 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001932 goto fail;
1933 }
1934 ie = ie_buf;
1935 }
1936
1937 if (random_get_bytes(fils_nonce, FILS_NONCE_LEN) < 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001938 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001939 goto fail;
1940 }
1941 wpa_hexdump(MSG_DEBUG, "RSN: Generated FILS Nonce",
1942 fils_nonce, FILS_NONCE_LEN);
1943
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001944#ifdef CONFIG_FILS_SK_PFS
1945 if (sta->fils_dh_ss && sta->fils_ecdh) {
1946 pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
1947 if (!pub) {
1948 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1949 goto fail;
1950 }
1951 }
1952#endif /* CONFIG_FILS_SK_PFS */
1953
1954 data = wpabuf_alloc(1000 + ielen + (pub ? wpabuf_len(pub) : 0));
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001955 if (!data) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001956 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001957 goto fail;
1958 }
1959
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001960 /* TODO: FILS PK */
1961#ifdef CONFIG_FILS_SK_PFS
1962 if (pub) {
1963 /* Finite Cyclic Group */
1964 wpabuf_put_le16(data, hapd->conf->fils_dh_group);
1965
1966 /* Element */
1967 wpabuf_put_buf(data, pub);
1968 }
1969#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001970
1971 /* RSNE */
1972 wpabuf_put_data(data, ie, ielen);
1973
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001974 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1975
1976#ifdef CONFIG_IEEE80211R_AP
1977 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm))) {
1978 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1979 int res;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001980 int use_sha384 = wpa_key_mgmt_sha384(
1981 wpa_auth_sta_key_mgmt(sta->wpa_sm));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001982
Roshan Pius3a1667e2018-07-03 15:17:14 -07001983 res = wpa_auth_write_fte(hapd->wpa_auth, use_sha384,
1984 wpabuf_put(data, 0),
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001985 wpabuf_tailroom(data));
1986 if (res < 0) {
1987 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1988 goto fail;
1989 }
1990 wpabuf_put(data, res);
1991 }
1992#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001993
1994 /* FILS Nonce */
1995 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1996 wpabuf_put_u8(data, 1 + FILS_NONCE_LEN); /* Length */
1997 /* Element ID Extension */
1998 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_NONCE);
1999 wpabuf_put_data(data, fils_nonce, FILS_NONCE_LEN);
2000
2001 /* FILS Session */
2002 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
2003 wpabuf_put_u8(data, 1 + FILS_SESSION_LEN); /* Length */
2004 /* Element ID Extension */
2005 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_SESSION);
2006 wpabuf_put_data(data, sta->fils_session, FILS_SESSION_LEN);
2007
Hai Shalomfdcde762020-04-02 11:19:20 -07002008 /* Wrapped Data */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002009 if (!pmksa && erp_resp) {
2010 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
2011 wpabuf_put_u8(data, 1 + wpabuf_len(erp_resp)); /* Length */
2012 /* Element ID Extension */
Hai Shalomfdcde762020-04-02 11:19:20 -07002013 wpabuf_put_u8(data, WLAN_EID_EXT_WRAPPED_DATA);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002014 wpabuf_put_buf(data, erp_resp);
2015
Paul Stewart092955c2017-02-06 09:13:09 -08002016 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta->wpa_sm),
2017 msk, msk_len, sta->fils_snonce, fils_nonce,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002018 sta->fils_dh_ss ?
2019 wpabuf_head(sta->fils_dh_ss) : NULL,
2020 sta->fils_dh_ss ?
2021 wpabuf_len(sta->fils_dh_ss) : 0,
2022 pmk_buf, &pmk_len)) {
Paul Stewart092955c2017-02-06 09:13:09 -08002023 wpa_printf(MSG_DEBUG, "FILS: Failed to derive PMK");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002024 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Paul Stewart092955c2017-02-06 09:13:09 -08002025 wpabuf_free(data);
2026 data = NULL;
2027 goto fail;
2028 }
2029 pmk = pmk_buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002030
2031 /* Don't use DHss in PTK derivation if PMKSA caching is not
2032 * used. */
2033 wpabuf_clear_free(sta->fils_dh_ss);
2034 sta->fils_dh_ss = NULL;
2035
2036 if (sta->fils_erp_pmkid_set) {
2037 /* TODO: get PMKLifetime from WPA parameters */
2038 unsigned int dot11RSNAConfigPMKLifetime = 43200;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002039 int session_timeout;
2040
2041 session_timeout = dot11RSNAConfigPMKLifetime;
2042 if (sta->session_timeout_set) {
2043 struct os_reltime now, diff;
2044
2045 os_get_reltime(&now);
2046 os_reltime_sub(&sta->session_timeout, &now,
2047 &diff);
2048 session_timeout = diff.sec;
2049 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002050
2051 sta->fils_erp_pmkid_set = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -07002052 wpa_auth_add_fils_pmk_pmkid(sta->wpa_sm, pmk, pmk_len,
2053 sta->fils_erp_pmkid);
Hai Shalom021b0b52019-04-10 11:17:58 -07002054 if (!hapd->conf->disable_pmksa_caching &&
2055 wpa_auth_pmksa_add2(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002056 hapd->wpa_auth, sta->addr,
2057 pmk, pmk_len,
2058 sta->fils_erp_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002059 session_timeout,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002060 wpa_auth_sta_key_mgmt(sta->wpa_sm)) < 0) {
2061 wpa_printf(MSG_ERROR,
2062 "FILS: Failed to add PMKSA cache entry based on ERP");
2063 }
2064 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002065 } else if (pmksa) {
2066 pmk = pmksa->pmk;
2067 pmk_len = pmksa->pmk_len;
2068 }
2069
2070 if (!pmk) {
2071 wpa_printf(MSG_DEBUG, "FILS: No PMK available");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002072 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002073 wpabuf_free(data);
2074 data = NULL;
2075 goto fail;
2076 }
2077
2078 if (fils_auth_pmk_to_ptk(sta->wpa_sm, pmk, pmk_len,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002079 sta->fils_snonce, fils_nonce,
2080 sta->fils_dh_ss ?
2081 wpabuf_head(sta->fils_dh_ss) : NULL,
2082 sta->fils_dh_ss ?
2083 wpabuf_len(sta->fils_dh_ss) : 0,
2084 sta->fils_g_sta, pub) < 0) {
2085 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002086 wpabuf_free(data);
2087 data = NULL;
2088 goto fail;
2089 }
2090
2091fail:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002092 if (is_pub)
2093 *is_pub = pub != NULL;
2094 os_free(ie_buf);
2095 wpabuf_free(pub);
2096 wpabuf_clear_free(sta->fils_dh_ss);
2097 sta->fils_dh_ss = NULL;
2098#ifdef CONFIG_FILS_SK_PFS
2099 crypto_ecdh_deinit(sta->fils_ecdh);
2100 sta->fils_ecdh = NULL;
2101#endif /* CONFIG_FILS_SK_PFS */
2102 return data;
2103}
2104
2105
2106static void handle_auth_fils_finish(struct hostapd_data *hapd,
2107 struct sta_info *sta, u16 resp,
2108 struct wpabuf *data, int pub)
2109{
2110 u16 auth_alg;
2111
2112 auth_alg = (pub ||
2113 resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) ?
2114 WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
Hai Shalomfdcde762020-04-02 11:19:20 -07002115 send_auth_reply(hapd, sta, sta->addr, hapd->own_addr, auth_alg, 2, resp,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002116 data ? wpabuf_head(data) : (u8 *) "",
Roshan Pius3a1667e2018-07-03 15:17:14 -07002117 data ? wpabuf_len(data) : 0, "auth-fils-finish");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002118 wpabuf_free(data);
2119
2120 if (resp == WLAN_STATUS_SUCCESS) {
2121 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2122 HOSTAPD_LEVEL_DEBUG,
2123 "authentication OK (FILS)");
2124 sta->flags |= WLAN_STA_AUTH;
2125 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002126 sta->auth_alg = pub ? WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002127 mlme_authenticate_indication(hapd, sta);
2128 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002129}
2130
2131
2132void ieee802_11_finish_fils_auth(struct hostapd_data *hapd,
2133 struct sta_info *sta, int success,
2134 struct wpabuf *erp_resp,
2135 const u8 *msk, size_t msk_len)
2136{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002137 struct wpabuf *data;
2138 int pub = 0;
2139 u16 resp;
2140
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002141 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002142
2143 if (!sta->fils_pending_cb)
2144 return;
2145 resp = success ? WLAN_STATUS_SUCCESS : WLAN_STATUS_UNSPECIFIED_FAILURE;
2146 data = prepare_auth_resp_fils(hapd, sta, &resp, NULL, erp_resp,
2147 msk, msk_len, &pub);
2148 if (!data) {
2149 wpa_printf(MSG_DEBUG,
2150 "%s: prepare_auth_resp_fils() returned failure",
2151 __func__);
2152 }
2153 sta->fils_pending_cb(hapd, sta, resp, data, pub);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002154}
2155
2156#endif /* CONFIG_FILS */
2157
2158
Hai Shalomfdcde762020-04-02 11:19:20 -07002159static int ieee802_11_allowed_address(struct hostapd_data *hapd, const u8 *addr,
2160 const u8 *msg, size_t len,
2161 struct radius_sta *info)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002162{
2163 int res;
2164
Hai Shalomfdcde762020-04-02 11:19:20 -07002165 res = hostapd_allowed_address(hapd, addr, msg, len, info, 0);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002166
2167 if (res == HOSTAPD_ACL_REJECT) {
Hai Shalomfdcde762020-04-02 11:19:20 -07002168 wpa_printf(MSG_DEBUG, "Station " MACSTR
2169 " not allowed to authenticate",
2170 MAC2STR(addr));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002171 return HOSTAPD_ACL_REJECT;
2172 }
2173
2174 if (res == HOSTAPD_ACL_PENDING) {
2175 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
2176 " waiting for an external authentication",
2177 MAC2STR(addr));
2178 /* Authentication code will re-send the authentication frame
2179 * after it has received (and cached) information from the
2180 * external source. */
2181 return HOSTAPD_ACL_PENDING;
2182 }
2183
2184 return res;
2185}
2186
2187
2188static int
2189ieee802_11_set_radius_info(struct hostapd_data *hapd, struct sta_info *sta,
Hai Shalomfdcde762020-04-02 11:19:20 -07002190 int res, struct radius_sta *info)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002191{
Hai Shalomfdcde762020-04-02 11:19:20 -07002192 u32 session_timeout = info->session_timeout;
2193 u32 acct_interim_interval = info->acct_interim_interval;
2194 struct vlan_description *vlan_id = &info->vlan_id;
2195 struct hostapd_sta_wpa_psk_short *psk = info->psk;
2196 char *identity = info->identity;
2197 char *radius_cui = info->radius_cui;
2198
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002199 if (vlan_id->notempty &&
2200 !hostapd_vlan_valid(hapd->conf->vlan, vlan_id)) {
2201 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
2202 HOSTAPD_LEVEL_INFO,
2203 "Invalid VLAN %d%s received from RADIUS server",
2204 vlan_id->untagged,
2205 vlan_id->tagged[0] ? "+" : "");
2206 return -1;
2207 }
2208 if (ap_sta_set_vlan(hapd, sta, vlan_id) < 0)
2209 return -1;
2210 if (sta->vlan_id)
2211 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
2212 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
2213
2214 hostapd_free_psk_list(sta->psk);
Hai Shalomfdcde762020-04-02 11:19:20 -07002215 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED)
2216 hostapd_copy_psk_list(&sta->psk, psk);
2217 else
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002218 sta->psk = NULL;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002219
Roshan Pius3a1667e2018-07-03 15:17:14 -07002220 os_free(sta->identity);
Hai Shalomfdcde762020-04-02 11:19:20 -07002221 if (identity)
2222 sta->identity = os_strdup(identity);
2223 else
2224 sta->identity = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002225
2226 os_free(sta->radius_cui);
Hai Shalomfdcde762020-04-02 11:19:20 -07002227 if (radius_cui)
2228 sta->radius_cui = os_strdup(radius_cui);
2229 else
2230 sta->radius_cui = NULL;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002231
2232 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
2233 sta->acct_interim_interval = acct_interim_interval;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002234 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT) {
2235 sta->session_timeout_set = 1;
2236 os_get_reltime(&sta->session_timeout);
2237 sta->session_timeout.sec += session_timeout;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002238 ap_sta_session_timeout(hapd, sta, session_timeout);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002239 } else {
2240 sta->session_timeout_set = 0;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002241 ap_sta_no_session_timeout(hapd, sta);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002242 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002243
2244 return 0;
2245}
2246
2247
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002248static void handle_auth(struct hostapd_data *hapd,
Hai Shalom74f70d42019-02-11 14:42:39 -08002249 const struct ieee80211_mgmt *mgmt, size_t len,
Hai Shalom021b0b52019-04-10 11:17:58 -07002250 int rssi, int from_queue)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002251{
2252 u16 auth_alg, auth_transaction, status_code;
2253 u16 resp = WLAN_STATUS_SUCCESS;
2254 struct sta_info *sta = NULL;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002255 int res, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002256 u16 fc;
2257 const u8 *challenge = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002258 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
2259 size_t resp_ies_len = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002260 u16 seq_ctrl;
Hai Shalomfdcde762020-04-02 11:19:20 -07002261 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002262
2263 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002264 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
2265 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002266 return;
2267 }
2268
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002269#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002270 if (hapd->iconf->ignore_auth_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002271 drand48() < hapd->iconf->ignore_auth_probability) {
2272 wpa_printf(MSG_INFO,
2273 "TESTING: ignoring auth frame from " MACSTR,
2274 MAC2STR(mgmt->sa));
2275 return;
2276 }
2277#endif /* CONFIG_TESTING_OPTIONS */
2278
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002279 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2280 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2281 status_code = le_to_host16(mgmt->u.auth.status_code);
2282 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002283 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002284
2285 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
2286 2 + WLAN_AUTH_CHALLENGE_LEN &&
2287 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
2288 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
2289 challenge = &mgmt->u.auth.variable[2];
2290
2291 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002292 "auth_transaction=%d status_code=%d wep=%d%s "
Hai Shalom021b0b52019-04-10 11:17:58 -07002293 "seq_ctrl=0x%x%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002294 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
2295 status_code, !!(fc & WLAN_FC_ISWEP),
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002296 challenge ? " challenge" : "",
Hai Shalom021b0b52019-04-10 11:17:58 -07002297 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "",
2298 from_queue ? " (from queue)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002299
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002300#ifdef CONFIG_NO_RC4
2301 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
2302 wpa_printf(MSG_INFO,
2303 "Unsupported authentication algorithm (%d)",
2304 auth_alg);
2305 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
2306 goto fail;
2307 }
2308#endif /* CONFIG_NO_RC4 */
2309
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002310 if (hapd->tkip_countermeasures) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002311 wpa_printf(MSG_DEBUG,
2312 "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication");
2313 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002314 goto fail;
2315 }
2316
2317 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
2318 auth_alg == WLAN_AUTH_OPEN) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002319#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002320 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002321 auth_alg == WLAN_AUTH_FT) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002322#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002323#ifdef CONFIG_SAE
2324 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
2325 auth_alg == WLAN_AUTH_SAE) ||
2326#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002327#ifdef CONFIG_FILS
2328 (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
2329 auth_alg == WLAN_AUTH_FILS_SK) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002330 (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
2331 hapd->conf->fils_dh_group &&
2332 auth_alg == WLAN_AUTH_FILS_SK_PFS) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002333#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002334 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
2335 auth_alg == WLAN_AUTH_SHARED_KEY))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002336 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
2337 auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002338 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
2339 goto fail;
2340 }
2341
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002342 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002343 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002344 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
2345 auth_transaction);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002346 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
2347 goto fail;
2348 }
2349
2350 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002351 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
2352 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002353 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2354 goto fail;
2355 }
2356
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002357 if (hapd->conf->no_auth_if_seen_on) {
2358 struct hostapd_data *other;
2359
2360 other = sta_track_seen_on(hapd->iface, mgmt->sa,
2361 hapd->conf->no_auth_if_seen_on);
2362 if (other) {
2363 u8 *pos;
2364 u32 info;
2365 u8 op_class, channel, phytype;
2366
2367 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
2368 MACSTR " since STA has been seen on %s",
2369 hapd->conf->iface, MAC2STR(mgmt->sa),
2370 hapd->conf->no_auth_if_seen_on);
2371
2372 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
2373 pos = &resp_ies[0];
2374 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
2375 *pos++ = 13;
2376 os_memcpy(pos, other->own_addr, ETH_ALEN);
2377 pos += ETH_ALEN;
2378 info = 0; /* TODO: BSSID Information */
2379 WPA_PUT_LE32(pos, info);
2380 pos += 4;
2381 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
2382 phytype = 8; /* dmg */
2383 else if (other->iconf->ieee80211ac)
2384 phytype = 9; /* vht */
2385 else if (other->iconf->ieee80211n)
2386 phytype = 7; /* ht */
2387 else if (other->iconf->hw_mode ==
2388 HOSTAPD_MODE_IEEE80211A)
2389 phytype = 4; /* ofdm */
2390 else if (other->iconf->hw_mode ==
2391 HOSTAPD_MODE_IEEE80211G)
2392 phytype = 6; /* erp */
2393 else
2394 phytype = 5; /* hrdsss */
2395 if (ieee80211_freq_to_channel_ext(
2396 hostapd_hw_get_freq(other,
2397 other->iconf->channel),
2398 other->iconf->secondary_channel,
2399 other->iconf->ieee80211ac,
2400 &op_class, &channel) == NUM_HOSTAPD_MODES) {
2401 op_class = 0;
2402 channel = other->iconf->channel;
2403 }
2404 *pos++ = op_class;
2405 *pos++ = channel;
2406 *pos++ = phytype;
2407 resp_ies_len = pos - &resp_ies[0];
2408 goto fail;
2409 }
2410 }
2411
Hai Shalomfdcde762020-04-02 11:19:20 -07002412 res = ieee802_11_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
2413 &rad_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002414 if (res == HOSTAPD_ACL_REJECT) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002415 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
2416 "Ignore Authentication frame from " MACSTR
2417 " due to ACL reject", MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2419 goto fail;
2420 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002421 if (res == HOSTAPD_ACL_PENDING)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002422 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002423
Hai Shalom021b0b52019-04-10 11:17:58 -07002424#ifdef CONFIG_SAE
2425 if (auth_alg == WLAN_AUTH_SAE && !from_queue &&
2426 (auth_transaction == 1 ||
2427 (auth_transaction == 2 && auth_sae_queued_addr(hapd, mgmt->sa)))) {
2428 /* Handle SAE Authentication commit message through a queue to
2429 * provide more control for postponing the needed heavy
2430 * processing under a possible DoS attack scenario. In addition,
2431 * queue SAE Authentication confirm message if there happens to
2432 * be a queued commit message from the same peer. This is needed
2433 * to avoid reordering Authentication frames within the same
2434 * SAE exchange. */
2435 auth_sae_queue(hapd, mgmt, len, rssi);
2436 return;
2437 }
2438#endif /* CONFIG_SAE */
2439
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002440 sta = ap_get_sta(hapd, mgmt->sa);
2441 if (sta) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002442 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
Hai Shalom74f70d42019-02-11 14:42:39 -08002443 sta->ft_over_ds = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002444 if ((fc & WLAN_FC_RETRY) &&
2445 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2446 sta->last_seq_ctrl == seq_ctrl &&
2447 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
2448 hostapd_logger(hapd, sta->addr,
2449 HOSTAPD_MODULE_IEEE80211,
2450 HOSTAPD_LEVEL_DEBUG,
2451 "Drop repeated authentication frame seq_ctrl=0x%x",
2452 seq_ctrl);
2453 return;
2454 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002455#ifdef CONFIG_MESH
2456 if ((hapd->conf->mesh & MESH_ENABLED) &&
2457 sta->plink_state == PLINK_BLOCKED) {
2458 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
2459 " is blocked - drop Authentication frame",
2460 MAC2STR(mgmt->sa));
2461 return;
2462 }
2463#endif /* CONFIG_MESH */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002464 } else {
2465#ifdef CONFIG_MESH
2466 if (hapd->conf->mesh & MESH_ENABLED) {
2467 /* if the mesh peer is not available, we don't do auth.
2468 */
2469 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002470 " not yet known - drop Authentication frame",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002471 MAC2STR(mgmt->sa));
2472 /*
2473 * Save a copy of the frame so that it can be processed
2474 * if a new peer entry is added shortly after this.
2475 */
2476 wpabuf_free(hapd->mesh_pending_auth);
2477 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
2478 os_get_reltime(&hapd->mesh_pending_auth_time);
2479 return;
2480 }
2481#endif /* CONFIG_MESH */
2482
2483 sta = ap_sta_add(hapd, mgmt->sa);
2484 if (!sta) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002485 wpa_printf(MSG_DEBUG, "ap_sta_add() failed");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002486 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2487 goto fail;
2488 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002489 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002490 sta->last_seq_ctrl = seq_ctrl;
2491 sta->last_subtype = WLAN_FC_STYPE_AUTH;
Hai Shalom74f70d42019-02-11 14:42:39 -08002492#ifdef CONFIG_MBO
2493 sta->auth_rssi = rssi;
2494#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002495
Hai Shalomfdcde762020-04-02 11:19:20 -07002496 res = ieee802_11_set_radius_info(hapd, sta, res, &rad_info);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002497 if (res) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002498 wpa_printf(MSG_DEBUG, "ieee802_11_set_radius_info() failed");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002499 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2500 goto fail;
2501 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002502
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002503 sta->flags &= ~WLAN_STA_PREAUTH;
2504 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
2505
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002506 /*
2507 * If the driver supports full AP client state, add a station to the
2508 * driver before sending authentication reply to make sure the driver
2509 * has resources, and not to go through the entire authentication and
2510 * association handshake, and fail it at the end.
2511 *
2512 * If this is not the first transaction, in a multi-step authentication
2513 * algorithm, the station already exists in the driver
2514 * (sta->added_unassoc = 1) so skip it.
2515 *
2516 * In mesh mode, the station was already added to the driver when the
2517 * NEW_PEER_CANDIDATE event is received.
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002518 *
2519 * If PMF was negotiated for the existing association, skip this to
2520 * avoid dropping the STA entry and the associated keys. This is needed
2521 * to allow the original connection work until the attempt can complete
2522 * (re)association, so that unprotected Authentication frame cannot be
2523 * used to bypass PMF protection.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002524 */
2525 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002526 (!(sta->flags & WLAN_STA_MFP) || !ap_sta_is_authorized(sta)) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002527 !(hapd->conf->mesh & MESH_ENABLED) &&
2528 !(sta->added_unassoc)) {
2529 /*
2530 * If a station that is already associated to the AP, is trying
2531 * to authenticate again, remove the STA entry, in order to make
2532 * sure the STA PS state gets cleared and configuration gets
2533 * updated. To handle this, station's added_unassoc flag is
2534 * cleared once the station has completed association.
2535 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07002536 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002537 hostapd_drv_sta_remove(hapd, sta->addr);
2538 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
2539 WLAN_STA_AUTHORIZED);
2540
Hai Shalom81f62d82019-07-22 12:10:00 -07002541 if (hostapd_sta_add(hapd, sta->addr, 0, 0,
2542 sta->supported_rates,
2543 sta->supported_rates_len,
2544 0, NULL, NULL, NULL, 0,
2545 sta->flags, 0, 0, 0, 0)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002546 hostapd_logger(hapd, sta->addr,
2547 HOSTAPD_MODULE_IEEE80211,
2548 HOSTAPD_LEVEL_NOTICE,
2549 "Could not add STA to kernel driver");
2550 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2551 goto fail;
2552 }
2553
2554 sta->added_unassoc = 1;
2555 }
2556
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002557 switch (auth_alg) {
2558 case WLAN_AUTH_OPEN:
2559 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2560 HOSTAPD_LEVEL_DEBUG,
2561 "authentication OK (open system)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002562 sta->flags |= WLAN_STA_AUTH;
2563 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
2564 sta->auth_alg = WLAN_AUTH_OPEN;
2565 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002566 break;
Hai Shalomfdcde762020-04-02 11:19:20 -07002567#ifdef CONFIG_WEP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002568#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002569 case WLAN_AUTH_SHARED_KEY:
2570 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
2571 fc & WLAN_FC_ISWEP);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002572 if (resp != 0)
2573 wpa_printf(MSG_DEBUG,
2574 "auth_shared_key() failed: status=%d", resp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002575 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
2576 mlme_authenticate_indication(hapd, sta);
2577 if (sta->challenge && auth_transaction == 1) {
2578 resp_ies[0] = WLAN_EID_CHALLENGE;
2579 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
2580 os_memcpy(resp_ies + 2, sta->challenge,
2581 WLAN_AUTH_CHALLENGE_LEN);
2582 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
2583 }
2584 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002585#endif /* CONFIG_NO_RC4 */
Hai Shalomfdcde762020-04-02 11:19:20 -07002586#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002587#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002588 case WLAN_AUTH_FT:
2589 sta->auth_alg = WLAN_AUTH_FT;
2590 if (sta->wpa_sm == NULL)
2591 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002592 sta->addr, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002593 if (sta->wpa_sm == NULL) {
2594 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
2595 "state machine");
2596 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2597 goto fail;
2598 }
2599 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
2600 auth_transaction, mgmt->u.auth.variable,
2601 len - IEEE80211_HDRLEN -
2602 sizeof(mgmt->u.auth),
2603 handle_auth_ft_finish, hapd);
2604 /* handle_auth_ft_finish() callback will complete auth. */
2605 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002606#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002607#ifdef CONFIG_SAE
2608 case WLAN_AUTH_SAE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002609#ifdef CONFIG_MESH
2610 if (status_code == WLAN_STATUS_SUCCESS &&
2611 hapd->conf->mesh & MESH_ENABLED) {
2612 if (sta->wpa_sm == NULL)
2613 sta->wpa_sm =
2614 wpa_auth_sta_init(hapd->wpa_auth,
2615 sta->addr, NULL);
2616 if (sta->wpa_sm == NULL) {
2617 wpa_printf(MSG_DEBUG,
2618 "SAE: Failed to initialize WPA state machine");
2619 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2620 goto fail;
2621 }
2622 }
2623#endif /* CONFIG_MESH */
2624 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
2625 status_code);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002626 return;
2627#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002628#ifdef CONFIG_FILS
2629 case WLAN_AUTH_FILS_SK:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002630 case WLAN_AUTH_FILS_SK_PFS:
2631 handle_auth_fils(hapd, sta, mgmt->u.auth.variable,
2632 len - IEEE80211_HDRLEN - sizeof(mgmt->u.auth),
2633 auth_alg, auth_transaction, status_code,
2634 handle_auth_fils_finish);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002635 return;
2636#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002637 }
2638
2639 fail:
Hai Shalomfdcde762020-04-02 11:19:20 -07002640 reply_res = send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, auth_alg,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002641 auth_transaction + 1, resp, resp_ies,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002642 resp_ies_len, "handle-auth");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002643
2644 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
2645 reply_res != WLAN_STATUS_SUCCESS)) {
2646 hostapd_drv_sta_remove(hapd, sta->addr);
2647 sta->added_unassoc = 0;
2648 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002649}
2650
2651
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002652int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002653{
2654 int i, j = 32, aid;
2655
2656 /* get a unique AID */
2657 if (sta->aid > 0) {
2658 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
2659 return 0;
2660 }
2661
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002662 if (TEST_FAIL())
2663 return -1;
2664
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002665 for (i = 0; i < AID_WORDS; i++) {
2666 if (hapd->sta_aid[i] == (u32) -1)
2667 continue;
2668 for (j = 0; j < 32; j++) {
2669 if (!(hapd->sta_aid[i] & BIT(j)))
2670 break;
2671 }
2672 if (j < 32)
2673 break;
2674 }
2675 if (j == 32)
2676 return -1;
2677 aid = i * 32 + j + 1;
2678 if (aid > 2007)
2679 return -1;
2680
2681 sta->aid = aid;
2682 hapd->sta_aid[i] |= BIT(j);
2683 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
2684 return 0;
2685}
2686
2687
2688static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
2689 const u8 *ssid_ie, size_t ssid_ie_len)
2690{
2691 if (ssid_ie == NULL)
2692 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2693
2694 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
2695 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002696 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2697 HOSTAPD_LEVEL_INFO,
2698 "Station tried to associate with unknown SSID "
Dmitry Shmidt3c479372014-02-04 10:50:36 -08002699 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002700 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2701 }
2702
2703 return WLAN_STATUS_SUCCESS;
2704}
2705
2706
2707static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
2708 const u8 *wmm_ie, size_t wmm_ie_len)
2709{
2710 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002711 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002712 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002713 struct wmm_information_element *wmm;
2714
2715 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002716 hostapd_logger(hapd, sta->addr,
2717 HOSTAPD_MODULE_WPA,
2718 HOSTAPD_LEVEL_DEBUG,
2719 "invalid WMM element in association "
2720 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002721 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2722 }
2723
2724 sta->flags |= WLAN_STA_WMM;
2725 wmm = (struct wmm_information_element *) wmm_ie;
2726 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002727 }
2728 return WLAN_STATUS_SUCCESS;
2729}
2730
Hai Shalom74f70d42019-02-11 14:42:39 -08002731static u16 check_multi_ap(struct hostapd_data *hapd, struct sta_info *sta,
2732 const u8 *multi_ap_ie, size_t multi_ap_len)
2733{
2734 u8 multi_ap_value = 0;
2735
2736 sta->flags &= ~WLAN_STA_MULTI_AP;
2737
2738 if (!hapd->conf->multi_ap)
2739 return WLAN_STATUS_SUCCESS;
2740
2741 if (multi_ap_ie) {
2742 const u8 *multi_ap_subelem;
2743
2744 multi_ap_subelem = get_ie(multi_ap_ie + 4,
2745 multi_ap_len - 4,
2746 MULTI_AP_SUB_ELEM_TYPE);
2747 if (multi_ap_subelem && multi_ap_subelem[1] == 1) {
2748 multi_ap_value = multi_ap_subelem[2];
2749 } else {
2750 hostapd_logger(hapd, sta->addr,
2751 HOSTAPD_MODULE_IEEE80211,
2752 HOSTAPD_LEVEL_INFO,
2753 "Multi-AP IE has missing or invalid Multi-AP subelement");
2754 return WLAN_STATUS_INVALID_IE;
2755 }
2756 }
2757
Hai Shalom021b0b52019-04-10 11:17:58 -07002758 if (multi_ap_value && multi_ap_value != MULTI_AP_BACKHAUL_STA)
2759 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2760 HOSTAPD_LEVEL_INFO,
2761 "Multi-AP IE with unexpected value 0x%02x",
2762 multi_ap_value);
Hai Shalom74f70d42019-02-11 14:42:39 -08002763
Hai Shalom021b0b52019-04-10 11:17:58 -07002764 if (!(multi_ap_value & MULTI_AP_BACKHAUL_STA)) {
2765 if (hapd->conf->multi_ap & FRONTHAUL_BSS)
2766 return WLAN_STATUS_SUCCESS;
Hai Shalom74f70d42019-02-11 14:42:39 -08002767
Hai Shalom021b0b52019-04-10 11:17:58 -07002768 hostapd_logger(hapd, sta->addr,
2769 HOSTAPD_MODULE_IEEE80211,
2770 HOSTAPD_LEVEL_INFO,
2771 "Non-Multi-AP STA tries to associate with backhaul-only BSS");
2772 return WLAN_STATUS_ASSOC_DENIED_UNSPEC;
Hai Shalom74f70d42019-02-11 14:42:39 -08002773 }
2774
Hai Shalom021b0b52019-04-10 11:17:58 -07002775 if (!(hapd->conf->multi_ap & BACKHAUL_BSS))
2776 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2777 HOSTAPD_LEVEL_DEBUG,
2778 "Backhaul STA tries to associate with fronthaul-only BSS");
2779
2780 sta->flags |= WLAN_STA_MULTI_AP;
2781 return WLAN_STATUS_SUCCESS;
Hai Shalom74f70d42019-02-11 14:42:39 -08002782}
2783
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002784
2785static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
2786 struct ieee802_11_elems *elems)
2787{
Dmitry Shmidt29333592017-01-09 12:27:11 -08002788 /* Supported rates not used in IEEE 802.11ad/DMG */
2789 if (hapd->iface->current_mode &&
2790 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD)
2791 return WLAN_STATUS_SUCCESS;
2792
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002793 if (!elems->supp_rates) {
2794 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2795 HOSTAPD_LEVEL_DEBUG,
2796 "No supported rates element in AssocReq");
2797 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2798 }
2799
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002800 if (elems->supp_rates_len + elems->ext_supp_rates_len >
2801 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002802 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2803 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002804 "Invalid supported rates element length %d+%d",
2805 elems->supp_rates_len,
2806 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002807 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2808 }
2809
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002810 sta->supported_rates_len = merge_byte_arrays(
2811 sta->supported_rates, sizeof(sta->supported_rates),
2812 elems->supp_rates, elems->supp_rates_len,
2813 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002814
2815 return WLAN_STATUS_SUCCESS;
2816}
2817
2818
Dmitry Shmidt051af732013-10-22 13:52:46 -07002819static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
2820 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
2821{
2822#ifdef CONFIG_INTERWORKING
2823 /* check for QoS Map support */
2824 if (ext_capab_ie_len >= 5) {
2825 if (ext_capab_ie[4] & 0x01)
2826 sta->qos_map_enabled = 1;
2827 }
2828#endif /* CONFIG_INTERWORKING */
2829
Roshan Pius3a1667e2018-07-03 15:17:14 -07002830 if (ext_capab_ie_len > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002831 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
Roshan Pius3a1667e2018-07-03 15:17:14 -07002832 os_free(sta->ext_capability);
2833 sta->ext_capability = os_malloc(1 + ext_capab_ie_len);
2834 if (sta->ext_capability) {
2835 sta->ext_capability[0] = ext_capab_ie_len;
2836 os_memcpy(sta->ext_capability + 1, ext_capab_ie,
2837 ext_capab_ie_len);
2838 }
2839 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002840
Dmitry Shmidt051af732013-10-22 13:52:46 -07002841 return WLAN_STATUS_SUCCESS;
2842}
2843
2844
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002845#ifdef CONFIG_OWE
2846
2847static int owe_group_supported(struct hostapd_data *hapd, u16 group)
2848{
2849 int i;
2850 int *groups = hapd->conf->owe_groups;
2851
2852 if (group != 19 && group != 20 && group != 21)
2853 return 0;
2854
2855 if (!groups)
2856 return 1;
2857
2858 for (i = 0; groups[i] > 0; i++) {
2859 if (groups[i] == group)
2860 return 1;
2861 }
2862
2863 return 0;
2864}
2865
2866
2867static u16 owe_process_assoc_req(struct hostapd_data *hapd,
2868 struct sta_info *sta, const u8 *owe_dh,
2869 u8 owe_dh_len)
2870{
2871 struct wpabuf *secret, *pub, *hkey;
2872 int res;
2873 u8 prk[SHA512_MAC_LEN], pmkid[SHA512_MAC_LEN];
2874 const char *info = "OWE Key Generation";
2875 const u8 *addr[2];
2876 size_t len[2];
2877 u16 group;
2878 size_t hash_len, prime_len;
2879
2880 if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) {
2881 wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching");
2882 return WLAN_STATUS_SUCCESS;
2883 }
2884
2885 group = WPA_GET_LE16(owe_dh);
2886 if (!owe_group_supported(hapd, group)) {
2887 wpa_printf(MSG_DEBUG, "OWE: Unsupported DH group %u", group);
2888 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2889 }
2890 if (group == 19)
2891 prime_len = 32;
2892 else if (group == 20)
2893 prime_len = 48;
2894 else if (group == 21)
2895 prime_len = 66;
2896 else
2897 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2898
2899 crypto_ecdh_deinit(sta->owe_ecdh);
2900 sta->owe_ecdh = crypto_ecdh_init(group);
2901 if (!sta->owe_ecdh)
2902 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2903 sta->owe_group = group;
2904
2905 secret = crypto_ecdh_set_peerkey(sta->owe_ecdh, 0, owe_dh + 2,
2906 owe_dh_len - 2);
2907 secret = wpabuf_zeropad(secret, prime_len);
2908 if (!secret) {
2909 wpa_printf(MSG_DEBUG, "OWE: Invalid peer DH public key");
2910 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2911 }
2912 wpa_hexdump_buf_key(MSG_DEBUG, "OWE: DH shared secret", secret);
2913
2914 /* prk = HKDF-extract(C | A | group, z) */
2915
2916 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
2917 if (!pub) {
2918 wpabuf_clear_free(secret);
2919 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2920 }
2921
2922 /* PMKID = Truncate-128(Hash(C | A)) */
2923 addr[0] = owe_dh + 2;
2924 len[0] = owe_dh_len - 2;
2925 addr[1] = wpabuf_head(pub);
2926 len[1] = wpabuf_len(pub);
2927 if (group == 19) {
2928 res = sha256_vector(2, addr, len, pmkid);
2929 hash_len = SHA256_MAC_LEN;
2930 } else if (group == 20) {
2931 res = sha384_vector(2, addr, len, pmkid);
2932 hash_len = SHA384_MAC_LEN;
2933 } else if (group == 21) {
2934 res = sha512_vector(2, addr, len, pmkid);
2935 hash_len = SHA512_MAC_LEN;
2936 } else {
2937 wpabuf_free(pub);
2938 wpabuf_clear_free(secret);
2939 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2940 }
2941 pub = wpabuf_zeropad(pub, prime_len);
2942 if (res < 0 || !pub) {
2943 wpabuf_free(pub);
2944 wpabuf_clear_free(secret);
2945 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2946 }
2947
2948 hkey = wpabuf_alloc(owe_dh_len - 2 + wpabuf_len(pub) + 2);
2949 if (!hkey) {
2950 wpabuf_free(pub);
2951 wpabuf_clear_free(secret);
2952 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2953 }
2954
2955 wpabuf_put_data(hkey, owe_dh + 2, owe_dh_len - 2); /* C */
2956 wpabuf_put_buf(hkey, pub); /* A */
2957 wpabuf_free(pub);
2958 wpabuf_put_le16(hkey, group); /* group */
2959 if (group == 19)
2960 res = hmac_sha256(wpabuf_head(hkey), wpabuf_len(hkey),
2961 wpabuf_head(secret), wpabuf_len(secret), prk);
2962 else if (group == 20)
2963 res = hmac_sha384(wpabuf_head(hkey), wpabuf_len(hkey),
2964 wpabuf_head(secret), wpabuf_len(secret), prk);
2965 else if (group == 21)
2966 res = hmac_sha512(wpabuf_head(hkey), wpabuf_len(hkey),
2967 wpabuf_head(secret), wpabuf_len(secret), prk);
2968 wpabuf_clear_free(hkey);
2969 wpabuf_clear_free(secret);
2970 if (res < 0)
2971 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2972
2973 wpa_hexdump_key(MSG_DEBUG, "OWE: prk", prk, hash_len);
2974
2975 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2976
2977 os_free(sta->owe_pmk);
2978 sta->owe_pmk = os_malloc(hash_len);
2979 if (!sta->owe_pmk) {
2980 os_memset(prk, 0, SHA512_MAC_LEN);
2981 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2982 }
2983
2984 if (group == 19)
2985 res = hmac_sha256_kdf(prk, hash_len, NULL, (const u8 *) info,
2986 os_strlen(info), sta->owe_pmk, hash_len);
2987 else if (group == 20)
2988 res = hmac_sha384_kdf(prk, hash_len, NULL, (const u8 *) info,
2989 os_strlen(info), sta->owe_pmk, hash_len);
2990 else if (group == 21)
2991 res = hmac_sha512_kdf(prk, hash_len, NULL, (const u8 *) info,
2992 os_strlen(info), sta->owe_pmk, hash_len);
2993 os_memset(prk, 0, SHA512_MAC_LEN);
2994 if (res < 0) {
2995 os_free(sta->owe_pmk);
2996 sta->owe_pmk = NULL;
2997 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2998 }
2999 sta->owe_pmk_len = hash_len;
3000
3001 wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sta->owe_pmk, sta->owe_pmk_len);
3002 wpa_hexdump(MSG_DEBUG, "OWE: PMKID", pmkid, PMKID_LEN);
3003 wpa_auth_pmksa_add2(hapd->wpa_auth, sta->addr, sta->owe_pmk,
3004 sta->owe_pmk_len, pmkid, 0, WPA_KEY_MGMT_OWE);
3005
3006 return WLAN_STATUS_SUCCESS;
3007}
3008
Hai Shalom81f62d82019-07-22 12:10:00 -07003009
3010u16 owe_validate_request(struct hostapd_data *hapd, const u8 *peer,
3011 const u8 *rsn_ie, size_t rsn_ie_len,
3012 const u8 *owe_dh, size_t owe_dh_len)
3013{
3014 struct wpa_ie_data data;
3015 int res;
3016
3017 if (!rsn_ie || rsn_ie_len < 2) {
3018 wpa_printf(MSG_DEBUG, "OWE: Invalid RSNE from " MACSTR,
3019 MAC2STR(peer));
3020 return WLAN_STATUS_INVALID_IE;
3021 }
3022 rsn_ie -= 2;
3023 rsn_ie_len += 2;
3024
3025 res = wpa_parse_wpa_ie_rsn(rsn_ie, rsn_ie_len, &data);
3026 if (res) {
3027 wpa_printf(MSG_DEBUG, "Failed to parse RSNE from " MACSTR
3028 " (res=%d)", MAC2STR(peer), res);
3029 wpa_hexdump(MSG_DEBUG, "RSNE", rsn_ie, rsn_ie_len);
3030 return wpa_res_to_status_code(res);
3031 }
3032 if (!(data.key_mgmt & WPA_KEY_MGMT_OWE)) {
3033 wpa_printf(MSG_DEBUG,
3034 "OWE: Unexpected key mgmt 0x%x from " MACSTR,
3035 (unsigned int) data.key_mgmt, MAC2STR(peer));
3036 return WLAN_STATUS_AKMP_NOT_VALID;
3037 }
3038 if (!owe_dh) {
3039 wpa_printf(MSG_DEBUG,
3040 "OWE: No Diffie-Hellman Parameter element from "
3041 MACSTR, MAC2STR(peer));
3042 return WLAN_STATUS_AKMP_NOT_VALID;
3043 }
3044
3045 return WLAN_STATUS_SUCCESS;
3046}
3047
3048
3049u16 owe_process_rsn_ie(struct hostapd_data *hapd,
3050 struct sta_info *sta,
3051 const u8 *rsn_ie, size_t rsn_ie_len,
3052 const u8 *owe_dh, size_t owe_dh_len)
3053{
3054 u16 status;
3055 u8 *owe_buf, ie[256 * 2];
3056 size_t ie_len = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07003057 enum wpa_validate_result res;
Hai Shalom81f62d82019-07-22 12:10:00 -07003058
3059 if (!rsn_ie || rsn_ie_len < 2) {
3060 wpa_printf(MSG_DEBUG, "OWE: No RSNE in (Re)AssocReq");
3061 status = WLAN_STATUS_INVALID_IE;
3062 goto end;
3063 }
3064
3065 if (!sta->wpa_sm)
3066 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr,
3067 NULL);
3068 if (!sta->wpa_sm) {
3069 wpa_printf(MSG_WARNING,
3070 "OWE: Failed to initialize WPA state machine");
3071 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
3072 goto end;
3073 }
3074 rsn_ie -= 2;
3075 rsn_ie_len += 2;
3076 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
3077 hapd->iface->freq, rsn_ie, rsn_ie_len,
Hai Shalomc3565922019-10-28 11:58:20 -07003078 NULL, 0, NULL, 0, owe_dh, owe_dh_len);
Hai Shalom81f62d82019-07-22 12:10:00 -07003079 status = wpa_res_to_status_code(res);
3080 if (status != WLAN_STATUS_SUCCESS)
3081 goto end;
3082 status = owe_process_assoc_req(hapd, sta, owe_dh, owe_dh_len);
3083 if (status != WLAN_STATUS_SUCCESS)
3084 goto end;
3085 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, ie, sizeof(ie),
3086 NULL, 0);
3087 if (!owe_buf) {
3088 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
3089 goto end;
3090 }
3091
3092 if (sta->owe_ecdh) {
3093 struct wpabuf *pub;
3094
3095 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
3096 if (!pub) {
3097 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
3098 goto end;
3099 }
3100
3101 /* OWE Diffie-Hellman Parameter element */
3102 *owe_buf++ = WLAN_EID_EXTENSION; /* Element ID */
3103 *owe_buf++ = 1 + 2 + wpabuf_len(pub); /* Length */
3104 *owe_buf++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension
3105 */
3106 WPA_PUT_LE16(owe_buf, sta->owe_group);
3107 owe_buf += 2;
3108 os_memcpy(owe_buf, wpabuf_head(pub), wpabuf_len(pub));
3109 owe_buf += wpabuf_len(pub);
3110 wpabuf_free(pub);
3111 sta->external_dh_updated = 1;
3112 }
3113 ie_len = owe_buf - ie;
3114
3115end:
3116 wpa_printf(MSG_DEBUG, "OWE: Update status %d, ie len %d for peer "
3117 MACSTR, status, (unsigned int) ie_len,
3118 MAC2STR(sta->addr));
3119 hostapd_drv_update_dh_ie(hapd, sta->addr, status,
3120 status == WLAN_STATUS_SUCCESS ? ie : NULL,
3121 ie_len);
3122
3123 return status;
3124}
3125
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003126#endif /* CONFIG_OWE */
3127
3128
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003129static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
3130 const u8 *ies, size_t ies_len, int reassoc)
3131{
3132 struct ieee802_11_elems elems;
3133 u16 resp;
3134 const u8 *wpa_ie;
3135 size_t wpa_ie_len;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003136 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003137
3138 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
3139 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3140 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
3141 "association request");
3142 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3143 }
3144
3145 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
3146 if (resp != WLAN_STATUS_SUCCESS)
3147 return resp;
3148 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
3149 if (resp != WLAN_STATUS_SUCCESS)
3150 return resp;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003151 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
3152 if (resp != WLAN_STATUS_SUCCESS)
3153 return resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154 resp = copy_supp_rates(hapd, sta, &elems);
3155 if (resp != WLAN_STATUS_SUCCESS)
3156 return resp;
Hai Shalom74f70d42019-02-11 14:42:39 -08003157
3158 resp = check_multi_ap(hapd, sta, elems.multi_ap, elems.multi_ap_len);
3159 if (resp != WLAN_STATUS_SUCCESS)
3160 return resp;
3161
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003162 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003163 if (resp != WLAN_STATUS_SUCCESS)
3164 return resp;
3165 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
3166 !(sta->flags & WLAN_STA_HT)) {
3167 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3168 HOSTAPD_LEVEL_INFO, "Station does not support "
3169 "mandatory HT PHY - reject association");
3170 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
3171 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003172
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003173#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003174 if (hapd->iconf->ieee80211ac) {
3175 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
3176 if (resp != WLAN_STATUS_SUCCESS)
3177 return resp;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003178
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003179 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
3180 if (resp != WLAN_STATUS_SUCCESS)
3181 return resp;
3182 }
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003183
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003184 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
3185 !(sta->flags & WLAN_STA_VHT)) {
3186 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3187 HOSTAPD_LEVEL_INFO, "Station does not support "
3188 "mandatory VHT PHY - reject association");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003189 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003190 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003191
3192 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
3193 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
3194 elems.vendor_vht_len);
3195 if (resp != WLAN_STATUS_SUCCESS)
3196 return resp;
3197 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003198#endif /* CONFIG_IEEE80211AC */
Hai Shalom81f62d82019-07-22 12:10:00 -07003199#ifdef CONFIG_IEEE80211AX
3200 if (hapd->iconf->ieee80211ax) {
3201 resp = copy_sta_he_capab(hapd, sta, IEEE80211_MODE_AP,
3202 elems.he_capabilities,
3203 elems.he_capabilities_len);
3204 if (resp != WLAN_STATUS_SUCCESS)
3205 return resp;
3206 }
3207#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003208
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003209#ifdef CONFIG_P2P
3210 if (elems.p2p) {
3211 wpabuf_free(sta->p2p_ie);
3212 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
3213 P2P_IE_VENDOR_TYPE);
3214 if (sta->p2p_ie)
3215 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
3216 } else {
3217 wpabuf_free(sta->p2p_ie);
3218 sta->p2p_ie = NULL;
3219 }
3220#endif /* CONFIG_P2P */
3221
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003222 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
3223 wpa_ie = elems.rsn_ie;
3224 wpa_ie_len = elems.rsn_ie_len;
3225 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
3226 elems.wpa_ie) {
3227 wpa_ie = elems.wpa_ie;
3228 wpa_ie_len = elems.wpa_ie_len;
3229 } else {
3230 wpa_ie = NULL;
3231 wpa_ie_len = 0;
3232 }
3233
3234#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003235 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003236 if (hapd->conf->wps_state && elems.wps_ie) {
3237 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
3238 "Request - assume WPS is used");
3239 sta->flags |= WLAN_STA_WPS;
3240 wpabuf_free(sta->wps_ie);
3241 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
3242 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003243 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
3244 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
3245 sta->flags |= WLAN_STA_WPS2;
3246 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003247 wpa_ie = NULL;
3248 wpa_ie_len = 0;
3249 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
3250 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
3251 "(Re)Association Request - reject");
3252 return WLAN_STATUS_INVALID_IE;
3253 }
3254 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
3255 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
3256 "(Re)Association Request - possible WPS use");
3257 sta->flags |= WLAN_STA_MAYBE_WPS;
3258 } else
3259#endif /* CONFIG_WPS */
3260 if (hapd->conf->wpa && wpa_ie == NULL) {
3261 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3262 HOSTAPD_LEVEL_INFO,
3263 "No WPA/RSN IE in association request");
3264 return WLAN_STATUS_INVALID_IE;
3265 }
3266
3267 if (hapd->conf->wpa && wpa_ie) {
Hai Shalomfdcde762020-04-02 11:19:20 -07003268 enum wpa_validate_result res;
3269
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003270 wpa_ie -= 2;
3271 wpa_ie_len += 2;
3272 if (sta->wpa_sm == NULL)
3273 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003274 sta->addr,
3275 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003276 if (sta->wpa_sm == NULL) {
3277 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
3278 "state machine");
3279 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3280 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003281 wpa_auth_set_auth_alg(sta->wpa_sm, sta->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003282 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -07003283 hapd->iface->freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003284 wpa_ie, wpa_ie_len,
Hai Shalomc3565922019-10-28 11:58:20 -07003285 elems.rsnxe ? elems.rsnxe - 2 : NULL,
3286 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003287 elems.mdie, elems.mdie_len,
3288 elems.owe_dh, elems.owe_dh_len);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003289 resp = wpa_res_to_status_code(res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003290 if (resp != WLAN_STATUS_SUCCESS)
3291 return resp;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003292 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
3293 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
3294 !sta->sa_query_timed_out &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003295 sta->sa_query_count > 0)
3296 ap_check_sa_query_timeout(hapd, sta);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003297 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
3298 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
3299 !sta->sa_query_timed_out &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003300 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
3301 /*
3302 * STA has already been associated with MFP and SA
3303 * Query timeout has not been reached. Reject the
3304 * association attempt temporarily and start SA Query,
3305 * if one is not pending.
3306 */
3307
3308 if (sta->sa_query_count == 0)
3309 ap_sta_start_sa_query(hapd, sta);
3310
3311 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
3312 }
3313
3314 if (wpa_auth_uses_mfp(sta->wpa_sm))
3315 sta->flags |= WLAN_STA_MFP;
3316 else
3317 sta->flags &= ~WLAN_STA_MFP;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003318
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003319#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003320 if (sta->auth_alg == WLAN_AUTH_FT) {
3321 if (!reassoc) {
3322 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
3323 "to use association (not "
3324 "re-association) with FT auth_alg",
3325 MAC2STR(sta->addr));
3326 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3327 }
3328
3329 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
3330 ies_len);
3331 if (resp != WLAN_STATUS_SUCCESS)
3332 return resp;
3333 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003334#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003335
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003336#ifdef CONFIG_SAE
Roshan Pius3a1667e2018-07-03 15:17:14 -07003337 if (wpa_auth_uses_sae(sta->wpa_sm) && sta->sae &&
3338 sta->sae->state == SAE_ACCEPTED)
3339 wpa_auth_add_sae_pmkid(sta->wpa_sm, sta->sae->pmkid);
3340
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003341 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003342 sta->auth_alg == WLAN_AUTH_OPEN) {
3343 struct rsn_pmksa_cache_entry *sa;
3344 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
3345 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
3346 wpa_printf(MSG_DEBUG,
3347 "SAE: No PMKSA cache entry found for "
3348 MACSTR, MAC2STR(sta->addr));
3349 return WLAN_STATUS_INVALID_PMKID;
3350 }
3351 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
3352 " using PMKSA caching", MAC2STR(sta->addr));
3353 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
3354 sta->auth_alg != WLAN_AUTH_SAE &&
3355 !(sta->auth_alg == WLAN_AUTH_FT &&
3356 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003357 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
3358 "SAE AKM after non-SAE auth_alg %u",
3359 MAC2STR(sta->addr), sta->auth_alg);
3360 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
3361 }
Hai Shalomc3565922019-10-28 11:58:20 -07003362
3363 if (hapd->conf->sae_pwe == 2 &&
3364 sta->auth_alg == WLAN_AUTH_SAE &&
3365 sta->sae && sta->sae->tmp && !sta->sae->tmp->h2e &&
3366 elems.rsnxe && elems.rsnxe_len >= 1 &&
3367 (elems.rsnxe[0] & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
3368 wpa_printf(MSG_INFO, "SAE: " MACSTR
3369 " indicates support for SAE H2E, but did not use it",
3370 MAC2STR(sta->addr));
3371 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3372 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003373#endif /* CONFIG_SAE */
3374
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003375#ifdef CONFIG_OWE
3376 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
3377 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
3378 elems.owe_dh) {
3379 resp = owe_process_assoc_req(hapd, sta, elems.owe_dh,
3380 elems.owe_dh_len);
3381 if (resp != WLAN_STATUS_SUCCESS)
3382 return resp;
3383 }
3384#endif /* CONFIG_OWE */
3385
Hai Shalom021b0b52019-04-10 11:17:58 -07003386#ifdef CONFIG_DPP2
3387 dpp_pfs_free(sta->dpp_pfs);
3388 sta->dpp_pfs = NULL;
3389
3390 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
3391 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
3392 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
3393 elems.owe_dh) {
3394 sta->dpp_pfs = dpp_pfs_init(
3395 wpabuf_head(hapd->conf->dpp_netaccesskey),
3396 wpabuf_len(hapd->conf->dpp_netaccesskey));
3397 if (!sta->dpp_pfs) {
3398 wpa_printf(MSG_DEBUG,
3399 "DPP: Could not initialize PFS");
3400 /* Try to continue without PFS */
3401 goto pfs_fail;
3402 }
3403
3404 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
3405 elems.owe_dh_len) < 0) {
3406 dpp_pfs_free(sta->dpp_pfs);
3407 sta->dpp_pfs = NULL;
3408 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3409 }
3410 }
3411
3412 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
3413 sta->dpp_pfs->secret : NULL);
3414 pfs_fail:
3415#endif /* CONFIG_DPP2 */
3416
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003417 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003418 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
3419 hostapd_logger(hapd, sta->addr,
3420 HOSTAPD_MODULE_IEEE80211,
3421 HOSTAPD_LEVEL_INFO,
3422 "Station tried to use TKIP with HT "
3423 "association");
3424 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
3425 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003426#ifdef CONFIG_HS20
3427 } else if (hapd->conf->osen) {
3428 if (elems.osen == NULL) {
3429 hostapd_logger(
3430 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3431 HOSTAPD_LEVEL_INFO,
3432 "No HS 2.0 OSEN element in association request");
3433 return WLAN_STATUS_INVALID_IE;
3434 }
3435
3436 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
3437 if (sta->wpa_sm == NULL)
3438 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
3439 sta->addr, NULL);
3440 if (sta->wpa_sm == NULL) {
3441 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
3442 "state machine");
3443 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3444 }
3445 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
3446 elems.osen - 2, elems.osen_len + 2) < 0)
3447 return WLAN_STATUS_INVALID_IE;
3448#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003449 } else
3450 wpa_auth_sta_no_wpa(sta->wpa_sm);
3451
3452#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003453 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
3454#endif /* CONFIG_P2P */
3455
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003456#ifdef CONFIG_HS20
3457 wpabuf_free(sta->hs20_ie);
3458 if (elems.hs20 && elems.hs20_len > 4) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003459 int release;
3460
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003461 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
3462 elems.hs20_len - 4);
Hai Shalom74f70d42019-02-11 14:42:39 -08003463 release = ((elems.hs20[4] >> 4) & 0x0f) + 1;
Hai Shalomc3565922019-10-28 11:58:20 -07003464 if (release >= 2 && !wpa_auth_uses_mfp(sta->wpa_sm) &&
3465 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003466 wpa_printf(MSG_DEBUG,
3467 "HS 2.0: PMF not negotiated by release %d station "
3468 MACSTR, release, MAC2STR(sta->addr));
3469 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
3470 }
3471 } else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003472 sta->hs20_ie = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08003473 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003474
3475 wpabuf_free(sta->roaming_consortium);
3476 if (elems.roaming_cons_sel)
3477 sta->roaming_consortium = wpabuf_alloc_copy(
3478 elems.roaming_cons_sel + 4,
3479 elems.roaming_cons_sel_len - 4);
3480 else
3481 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003482#endif /* CONFIG_HS20 */
3483
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003484#ifdef CONFIG_FST
3485 wpabuf_free(sta->mb_ies);
3486 if (hapd->iface->fst)
3487 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
3488 else
3489 sta->mb_ies = NULL;
3490#endif /* CONFIG_FST */
3491
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003492#ifdef CONFIG_MBO
3493 mbo_ap_check_sta_assoc(hapd, sta, &elems);
3494
3495 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
3496 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
3497 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
3498 wpa_printf(MSG_INFO,
3499 "MBO: Reject WPA2 association without PMF");
3500 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3501 }
3502#endif /* CONFIG_MBO */
3503
Hai Shalom74f70d42019-02-11 14:42:39 -08003504#if defined(CONFIG_FILS) && defined(CONFIG_OCV)
3505 if (wpa_auth_uses_ocv(sta->wpa_sm) &&
3506 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3507 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3508 sta->auth_alg == WLAN_AUTH_FILS_PK)) {
3509 struct wpa_channel_info ci;
3510 int tx_chanwidth;
3511 int tx_seg1_idx;
3512
3513 if (hostapd_drv_channel_info(hapd, &ci) != 0) {
3514 wpa_printf(MSG_WARNING,
3515 "Failed to get channel info to validate received OCI in FILS (Re)Association Request frame");
3516 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3517 }
3518
3519 if (get_sta_tx_parameters(sta->wpa_sm,
3520 channel_width_to_int(ci.chanwidth),
3521 ci.seg1_idx, &tx_chanwidth,
3522 &tx_seg1_idx) < 0)
3523 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3524
3525 if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
3526 tx_chanwidth, tx_seg1_idx) != 0) {
3527 wpa_printf(MSG_WARNING, "FILS: %s", ocv_errorstr);
3528 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3529 }
3530 }
3531#endif /* CONFIG_FILS && CONFIG_OCV */
3532
Dmitry Shmidt9c175262016-03-03 10:20:07 -08003533 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
3534 elems.supp_op_classes_len);
3535
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003536 if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) &&
3537 elems.rrm_enabled &&
3538 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
3539 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
3540 sizeof(sta->rrm_enabled_capa));
3541
Roshan Pius3a1667e2018-07-03 15:17:14 -07003542 if (elems.power_capab) {
3543 sta->min_tx_power = elems.power_capab[0];
3544 sta->max_tx_power = elems.power_capab[1];
3545 sta->power_capab = 1;
3546 } else {
3547 sta->power_capab = 0;
3548 }
3549
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003550 return WLAN_STATUS_SUCCESS;
3551}
3552
3553
3554static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
3555 u16 reason_code)
3556{
3557 int send_len;
3558 struct ieee80211_mgmt reply;
3559
3560 os_memset(&reply, 0, sizeof(reply));
3561 reply.frame_control =
3562 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
3563 os_memcpy(reply.da, addr, ETH_ALEN);
3564 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
3565 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
3566
3567 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
3568 reply.u.deauth.reason_code = host_to_le16(reason_code);
3569
Hai Shalomfdcde762020-04-02 11:19:20 -07003570 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0, NULL, 0, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003571 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
3572 strerror(errno));
3573}
3574
3575
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003576static int add_associated_sta(struct hostapd_data *hapd,
Hai Shalom74f70d42019-02-11 14:42:39 -08003577 struct sta_info *sta, int reassoc)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003578{
3579 struct ieee80211_ht_capabilities ht_cap;
3580 struct ieee80211_vht_capabilities vht_cap;
Hai Shalom81f62d82019-07-22 12:10:00 -07003581 struct ieee80211_he_capabilities he_cap;
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003582 int set = 1;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003583
3584 /*
3585 * Remove the STA entry to ensure the STA PS state gets cleared and
3586 * configuration gets updated. This is relevant for cases, such as
3587 * FT-over-the-DS, where a station re-associates back to the same AP but
3588 * skips the authentication flow, or if working with a driver that
3589 * does not support full AP client state.
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003590 *
3591 * Skip this if the STA has already completed FT reassociation and the
3592 * TK has been configured since the TX/RX PN must not be reset to 0 for
3593 * the same key.
Hai Shalom74f70d42019-02-11 14:42:39 -08003594 *
3595 * FT-over-the-DS has a special case where the STA entry (and as such,
3596 * the TK) has not yet been configured to the driver depending on which
3597 * driver interface is used. For that case, allow add-STA operation to
3598 * be used (instead of set-STA). This is needed to allow mac80211-based
3599 * drivers to accept the STA parameter configuration. Since this is
3600 * after a new FT-over-DS exchange, a new TK has been derived, so key
3601 * reinstallation is not a concern for this case.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003602 */
Hai Shalom74f70d42019-02-11 14:42:39 -08003603 wpa_printf(MSG_DEBUG, "Add associated STA " MACSTR
3604 " (added_unassoc=%d auth_alg=%u ft_over_ds=%u reassoc=%d authorized=%d ft_tk=%d fils_tk=%d)",
3605 MAC2STR(sta->addr), sta->added_unassoc, sta->auth_alg,
3606 sta->ft_over_ds, reassoc,
3607 !!(sta->flags & WLAN_STA_AUTHORIZED),
3608 wpa_auth_sta_ft_tk_already_set(sta->wpa_sm),
3609 wpa_auth_sta_fils_tk_already_set(sta->wpa_sm));
3610
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003611 if (!sta->added_unassoc &&
3612 (!(sta->flags & WLAN_STA_AUTHORIZED) ||
Hai Shalom74f70d42019-02-11 14:42:39 -08003613 (reassoc && sta->ft_over_ds && sta->auth_alg == WLAN_AUTH_FT) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003614 (!wpa_auth_sta_ft_tk_already_set(sta->wpa_sm) &&
3615 !wpa_auth_sta_fils_tk_already_set(sta->wpa_sm)))) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003616 hostapd_drv_sta_remove(hapd, sta->addr);
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003617 wpa_auth_sm_event(sta->wpa_sm, WPA_DRV_STA_REMOVED);
3618 set = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08003619
3620 /* Do not allow the FT-over-DS exception to be used more than
3621 * once per authentication exchange to guarantee a new TK is
3622 * used here */
3623 sta->ft_over_ds = 0;
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003624 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003625
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003626 if (sta->flags & WLAN_STA_HT)
3627 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003628#ifdef CONFIG_IEEE80211AC
3629 if (sta->flags & WLAN_STA_VHT)
3630 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
3631#endif /* CONFIG_IEEE80211AC */
Hai Shalom81f62d82019-07-22 12:10:00 -07003632#ifdef CONFIG_IEEE80211AX
3633 if (sta->flags & WLAN_STA_HE) {
3634 hostapd_get_he_capab(hapd, sta->he_capab, &he_cap,
3635 sta->he_capab_len);
3636 }
3637#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003638
3639 /*
3640 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
3641 * will be set when the ACK frame for the (Re)Association Response frame
3642 * is processed (TX status driver event).
3643 */
3644 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
3645 sta->supported_rates, sta->supported_rates_len,
3646 sta->listen_interval,
3647 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
3648 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
Hai Shalom81f62d82019-07-22 12:10:00 -07003649 sta->flags & WLAN_STA_HE ? &he_cap : NULL,
3650 sta->flags & WLAN_STA_HE ? sta->he_capab_len : 0,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003651 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003652 sta->vht_opmode, sta->p2p_ie ? 1 : 0,
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003653 set)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003654 hostapd_logger(hapd, sta->addr,
3655 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
3656 "Could not %s STA to kernel driver",
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003657 set ? "set" : "add");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003658
3659 if (sta->added_unassoc) {
3660 hostapd_drv_sta_remove(hapd, sta->addr);
3661 sta->added_unassoc = 0;
3662 }
3663
3664 return -1;
3665 }
3666
3667 sta->added_unassoc = 0;
3668
3669 return 0;
3670}
3671
3672
3673static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
Dmitry Shmidt29333592017-01-09 12:27:11 -08003674 const u8 *addr, u16 status_code, int reassoc,
Hai Shalomfdcde762020-04-02 11:19:20 -07003675 const u8 *ies, size_t ies_len, int rssi,
3676 int omit_rsnxe)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003677{
3678 int send_len;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003679 u8 *buf;
3680 size_t buflen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003681 struct ieee80211_mgmt *reply;
3682 u8 *p;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003683 u16 res = WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003684
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003685 buflen = sizeof(struct ieee80211_mgmt) + 1024;
3686#ifdef CONFIG_FILS
3687 if (sta && sta->fils_hlp_resp)
3688 buflen += wpabuf_len(sta->fils_hlp_resp);
Hai Shalom81f62d82019-07-22 12:10:00 -07003689 if (sta)
3690 buflen += 150;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003691#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003692#ifdef CONFIG_OWE
3693 if (sta && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE))
3694 buflen += 150;
3695#endif /* CONFIG_OWE */
Hai Shalom021b0b52019-04-10 11:17:58 -07003696#ifdef CONFIG_DPP2
3697 if (sta && sta->dpp_pfs)
3698 buflen += 5 + sta->dpp_pfs->curve->prime_len;
3699#endif /* CONFIG_DPP2 */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003700 buf = os_zalloc(buflen);
3701 if (!buf) {
3702 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3703 goto done;
3704 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003705 reply = (struct ieee80211_mgmt *) buf;
3706 reply->frame_control =
3707 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
3708 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
3709 WLAN_FC_STYPE_ASSOC_RESP));
Dmitry Shmidt29333592017-01-09 12:27:11 -08003710 os_memcpy(reply->da, addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003711 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
3712 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
3713
3714 send_len = IEEE80211_HDRLEN;
3715 send_len += sizeof(reply->u.assoc_resp);
3716 reply->u.assoc_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003717 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003718 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt29333592017-01-09 12:27:11 -08003719
3720 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0) |
3721 BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003722 /* Supported rates */
3723 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
3724 /* Extended supported rates */
3725 p = hostapd_eid_ext_supp_rates(hapd, p);
3726
Hai Shalomfdcde762020-04-02 11:19:20 -07003727 /* Radio measurement capabilities */
3728 p = hostapd_eid_rm_enabled_capab(hapd, p, buf + buflen - p);
3729
Hai Shalom74f70d42019-02-11 14:42:39 -08003730#ifdef CONFIG_MBO
3731 if (status_code == WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
3732 rssi != 0) {
3733 int delta = hapd->iconf->rssi_reject_assoc_rssi - rssi;
3734
3735 p = hostapd_eid_mbo_rssi_assoc_rej(hapd, p, buf + buflen - p,
3736 delta);
3737 }
3738#endif /* CONFIG_MBO */
3739
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003740#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt29333592017-01-09 12:27:11 -08003741 if (sta && status_code == WLAN_STATUS_SUCCESS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003742 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
3743 * Transition Information, RSN, [RIC Response] */
3744 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003745 buf + buflen - p,
Hai Shalomfdcde762020-04-02 11:19:20 -07003746 sta->auth_alg, ies, ies_len,
3747 omit_rsnxe);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003748 if (!p) {
3749 wpa_printf(MSG_DEBUG,
3750 "FT: Failed to write AssocResp IEs");
3751 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3752 goto done;
3753 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003754 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003755#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07003756#ifdef CONFIG_FILS
3757 if (sta && status_code == WLAN_STATUS_SUCCESS &&
3758 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3759 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3760 sta->auth_alg == WLAN_AUTH_FILS_PK))
3761 p = wpa_auth_write_assoc_resp_fils(sta->wpa_sm, p,
3762 buf + buflen - p,
3763 ies, ies_len);
3764#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003765
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003766#ifdef CONFIG_OWE
Hai Shalom74f70d42019-02-11 14:42:39 -08003767 if (sta && status_code == WLAN_STATUS_SUCCESS &&
3768 (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003769 p = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, p,
3770 buf + buflen - p,
3771 ies, ies_len);
3772#endif /* CONFIG_OWE */
3773
Dmitry Shmidt29333592017-01-09 12:27:11 -08003774 if (sta && status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003775 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003776
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003777 p = hostapd_eid_ht_capabilities(hapd, p);
3778 p = hostapd_eid_ht_operation(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003779
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003780#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -07003781 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
3782 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07003783 u32 nsts = 0, sta_nsts;
3784
Dmitry Shmidt29333592017-01-09 12:27:11 -08003785 if (sta && hapd->conf->use_sta_nsts && sta->vht_capabilities) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07003786 struct ieee80211_vht_capabilities *capa;
3787
3788 nsts = (hapd->iface->conf->vht_capab >>
3789 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
3790 capa = sta->vht_capabilities;
3791 sta_nsts = (le_to_host32(capa->vht_capabilities_info) >>
3792 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
3793
3794 if (nsts < sta_nsts)
3795 nsts = 0;
3796 else
3797 nsts = sta_nsts;
3798 }
3799 p = hostapd_eid_vht_capabilities(hapd, p, nsts);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003800 p = hostapd_eid_vht_operation(hapd, p);
3801 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003802#endif /* CONFIG_IEEE80211AC */
3803
Hai Shalom81f62d82019-07-22 12:10:00 -07003804#ifdef CONFIG_IEEE80211AX
3805 if (hapd->iconf->ieee80211ax) {
3806 p = hostapd_eid_he_capab(hapd, p, IEEE80211_MODE_AP);
3807 p = hostapd_eid_he_operation(hapd, p);
3808 p = hostapd_eid_spatial_reuse(hapd, p);
3809 p = hostapd_eid_he_mu_edca_parameter_set(hapd, p);
3810 }
3811#endif /* CONFIG_IEEE80211AX */
3812
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003813 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003814 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt29333592017-01-09 12:27:11 -08003815 if (sta && sta->qos_map_enabled)
Dmitry Shmidt051af732013-10-22 13:52:46 -07003816 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003817
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003818#ifdef CONFIG_FST
3819 if (hapd->iface->fst_ies) {
3820 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
3821 wpabuf_len(hapd->iface->fst_ies));
3822 p += wpabuf_len(hapd->iface->fst_ies);
3823 }
3824#endif /* CONFIG_FST */
3825
Hai Shalomfdcde762020-04-02 11:19:20 -07003826#ifdef CONFIG_TESTING_OPTIONS
3827 if (hapd->conf->rsnxe_override_ft &&
3828 buf + buflen - p >=
3829 (long int) wpabuf_len(hapd->conf->rsnxe_override_ft) &&
3830 sta && sta->auth_alg == WLAN_AUTH_FT) {
3831 wpa_printf(MSG_DEBUG, "TESTING: RSNXE FT override");
3832 os_memcpy(p, wpabuf_head(hapd->conf->rsnxe_override_ft),
3833 wpabuf_len(hapd->conf->rsnxe_override_ft));
3834 p += wpabuf_len(hapd->conf->rsnxe_override_ft);
3835 goto rsnxe_done;
3836 }
3837#endif /* CONFIG_TESTING_OPTIONS */
3838 if (!omit_rsnxe)
3839 p = hostapd_eid_rsnxe(hapd, p, buf + buflen - p);
3840#ifdef CONFIG_TESTING_OPTIONS
3841rsnxe_done:
3842#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalomc3565922019-10-28 11:58:20 -07003843
Hai Shalom021b0b52019-04-10 11:17:58 -07003844#ifdef CONFIG_OWE
3845 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
3846 sta && sta->owe_ecdh && status_code == WLAN_STATUS_SUCCESS &&
3847 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE) {
3848 struct wpabuf *pub;
3849
3850 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
3851 if (!pub) {
3852 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3853 goto done;
3854 }
3855 /* OWE Diffie-Hellman Parameter element */
3856 *p++ = WLAN_EID_EXTENSION; /* Element ID */
3857 *p++ = 1 + 2 + wpabuf_len(pub); /* Length */
3858 *p++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension */
3859 WPA_PUT_LE16(p, sta->owe_group);
3860 p += 2;
3861 os_memcpy(p, wpabuf_head(pub), wpabuf_len(pub));
3862 p += wpabuf_len(pub);
3863 wpabuf_free(pub);
3864 }
3865#endif /* CONFIG_OWE */
3866
3867#ifdef CONFIG_DPP2
3868 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
3869 sta && sta->dpp_pfs && status_code == WLAN_STATUS_SUCCESS &&
3870 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP) {
3871 os_memcpy(p, wpabuf_head(sta->dpp_pfs->ie),
3872 wpabuf_len(sta->dpp_pfs->ie));
3873 p += wpabuf_len(sta->dpp_pfs->ie);
3874 }
3875#endif /* CONFIG_DPP2 */
3876
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003877#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt29333592017-01-09 12:27:11 -08003878 if (sta && hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003879 p = hostapd_eid_vendor_vht(hapd, p);
3880#endif /* CONFIG_IEEE80211AC */
3881
Dmitry Shmidt29333592017-01-09 12:27:11 -08003882 if (sta && (sta->flags & WLAN_STA_WMM))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003883 p = hostapd_eid_wmm(hapd, p);
3884
3885#ifdef CONFIG_WPS
Dmitry Shmidt29333592017-01-09 12:27:11 -08003886 if (sta &&
3887 ((sta->flags & WLAN_STA_WPS) ||
3888 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003889 struct wpabuf *wps = wps_build_assoc_resp_ie();
3890 if (wps) {
3891 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
3892 p += wpabuf_len(wps);
3893 wpabuf_free(wps);
3894 }
3895 }
3896#endif /* CONFIG_WPS */
3897
Hai Shalom74f70d42019-02-11 14:42:39 -08003898 if (sta && (sta->flags & WLAN_STA_MULTI_AP))
3899 p = hostapd_eid_multi_ap(hapd, p);
3900
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003901#ifdef CONFIG_P2P
Dmitry Shmidt29333592017-01-09 12:27:11 -08003902 if (sta && sta->p2p_ie && hapd->p2p_group) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003903 struct wpabuf *p2p_resp_ie;
3904 enum p2p_status_code status;
3905 switch (status_code) {
3906 case WLAN_STATUS_SUCCESS:
3907 status = P2P_SC_SUCCESS;
3908 break;
3909 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
3910 status = P2P_SC_FAIL_LIMIT_REACHED;
3911 break;
3912 default:
3913 status = P2P_SC_FAIL_INVALID_PARAMS;
3914 break;
3915 }
3916 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
3917 if (p2p_resp_ie) {
3918 os_memcpy(p, wpabuf_head(p2p_resp_ie),
3919 wpabuf_len(p2p_resp_ie));
3920 p += wpabuf_len(p2p_resp_ie);
3921 wpabuf_free(p2p_resp_ie);
3922 }
3923 }
3924#endif /* CONFIG_P2P */
3925
3926#ifdef CONFIG_P2P_MANAGER
3927 if (hapd->conf->p2p & P2P_MANAGE)
3928 p = hostapd_eid_p2p_manage(hapd, p);
3929#endif /* CONFIG_P2P_MANAGER */
3930
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003931 p = hostapd_eid_mbo(hapd, p, buf + buflen - p);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003932
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003933 if (hapd->conf->assocresp_elements &&
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003934 (size_t) (buf + buflen - p) >=
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003935 wpabuf_len(hapd->conf->assocresp_elements)) {
3936 os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements),
3937 wpabuf_len(hapd->conf->assocresp_elements));
3938 p += wpabuf_len(hapd->conf->assocresp_elements);
3939 }
3940
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003941 send_len += p - reply->u.assoc_resp.variable;
3942
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003943#ifdef CONFIG_FILS
Dmitry Shmidt29333592017-01-09 12:27:11 -08003944 if (sta &&
3945 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003946 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3947 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
3948 status_code == WLAN_STATUS_SUCCESS) {
3949 struct ieee802_11_elems elems;
3950
3951 if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003952 ParseFailed || !elems.fils_session) {
3953 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3954 goto done;
3955 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003956
3957 /* FILS Session */
3958 *p++ = WLAN_EID_EXTENSION; /* Element ID */
3959 *p++ = 1 + FILS_SESSION_LEN; /* Length */
3960 *p++ = WLAN_EID_EXT_FILS_SESSION; /* Element ID Extension */
3961 os_memcpy(p, elems.fils_session, FILS_SESSION_LEN);
3962 send_len += 2 + 1 + FILS_SESSION_LEN;
3963
3964 send_len = fils_encrypt_assoc(sta->wpa_sm, buf, send_len,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003965 buflen, sta->fils_hlp_resp);
3966 if (send_len < 0) {
3967 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3968 goto done;
3969 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003970 }
3971#endif /* CONFIG_FILS */
3972
Hai Shalomfdcde762020-04-02 11:19:20 -07003973 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0, NULL, 0, 0) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003974 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
3975 strerror(errno));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003976 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003977 }
3978
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003979done:
3980 os_free(buf);
3981 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003982}
3983
3984
Roshan Pius3a1667e2018-07-03 15:17:14 -07003985#ifdef CONFIG_OWE
3986u8 * owe_assoc_req_process(struct hostapd_data *hapd, struct sta_info *sta,
3987 const u8 *owe_dh, u8 owe_dh_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07003988 u8 *owe_buf, size_t owe_buf_len, u16 *status)
Roshan Pius3a1667e2018-07-03 15:17:14 -07003989{
3990#ifdef CONFIG_TESTING_OPTIONS
3991 if (hapd->conf->own_ie_override) {
3992 wpa_printf(MSG_DEBUG, "OWE: Using IE override");
Hai Shalomfdcde762020-04-02 11:19:20 -07003993 *status = WLAN_STATUS_SUCCESS;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003994 return wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3995 owe_buf_len, NULL, 0);
3996 }
3997#endif /* CONFIG_TESTING_OPTIONS */
3998
3999 if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) {
4000 wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching");
4001 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
4002 owe_buf_len, NULL, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07004003 *status = WLAN_STATUS_SUCCESS;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004004 return owe_buf;
4005 }
4006
Hai Shalom81f62d82019-07-22 12:10:00 -07004007 if (sta->owe_pmk && sta->external_dh_updated) {
4008 wpa_printf(MSG_DEBUG, "OWE: Using previously derived PMK");
Hai Shalomfdcde762020-04-02 11:19:20 -07004009 *status = WLAN_STATUS_SUCCESS;
Hai Shalom81f62d82019-07-22 12:10:00 -07004010 return owe_buf;
4011 }
4012
Hai Shalomfdcde762020-04-02 11:19:20 -07004013 *status = owe_process_assoc_req(hapd, sta, owe_dh, owe_dh_len);
4014 if (*status != WLAN_STATUS_SUCCESS)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004015 return NULL;
4016
4017 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
4018 owe_buf_len, NULL, 0);
4019
4020 if (sta->owe_ecdh && owe_buf) {
4021 struct wpabuf *pub;
4022
4023 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
4024 if (!pub) {
Hai Shalomfdcde762020-04-02 11:19:20 -07004025 *status = WLAN_STATUS_UNSPECIFIED_FAILURE;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004026 return owe_buf;
4027 }
4028
4029 /* OWE Diffie-Hellman Parameter element */
4030 *owe_buf++ = WLAN_EID_EXTENSION; /* Element ID */
4031 *owe_buf++ = 1 + 2 + wpabuf_len(pub); /* Length */
4032 *owe_buf++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension
4033 */
4034 WPA_PUT_LE16(owe_buf, sta->owe_group);
4035 owe_buf += 2;
4036 os_memcpy(owe_buf, wpabuf_head(pub), wpabuf_len(pub));
4037 owe_buf += wpabuf_len(pub);
4038 wpabuf_free(pub);
4039 }
4040
4041 return owe_buf;
4042}
4043#endif /* CONFIG_OWE */
4044
4045
Paul Stewart092955c2017-02-06 09:13:09 -08004046#ifdef CONFIG_FILS
4047
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004048void fils_hlp_finish_assoc(struct hostapd_data *hapd, struct sta_info *sta)
Paul Stewart092955c2017-02-06 09:13:09 -08004049{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004050 u16 reply_res;
Paul Stewart092955c2017-02-06 09:13:09 -08004051
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004052 wpa_printf(MSG_DEBUG, "FILS: Finish association with " MACSTR,
4053 MAC2STR(sta->addr));
4054 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
4055 if (!sta->fils_pending_assoc_req)
Paul Stewart092955c2017-02-06 09:13:09 -08004056 return;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004057 reply_res = send_assoc_resp(hapd, sta, sta->addr, WLAN_STATUS_SUCCESS,
4058 sta->fils_pending_assoc_is_reassoc,
4059 sta->fils_pending_assoc_req,
Hai Shalomfdcde762020-04-02 11:19:20 -07004060 sta->fils_pending_assoc_req_len, 0, 0);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004061 os_free(sta->fils_pending_assoc_req);
4062 sta->fils_pending_assoc_req = NULL;
4063 sta->fils_pending_assoc_req_len = 0;
4064 wpabuf_free(sta->fils_hlp_resp);
4065 sta->fils_hlp_resp = NULL;
4066 wpabuf_free(sta->hlp_dhcp_discover);
4067 sta->hlp_dhcp_discover = NULL;
Paul Stewart092955c2017-02-06 09:13:09 -08004068
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004069 /*
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004070 * Remove the station in case transmission of a success response fails.
4071 * At this point the station was already added associated to the driver.
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004072 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004073 if (reply_res != WLAN_STATUS_SUCCESS)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004074 hostapd_drv_sta_remove(hapd, sta->addr);
Paul Stewart092955c2017-02-06 09:13:09 -08004075}
4076
4077
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004078void fils_hlp_timeout(void *eloop_ctx, void *eloop_data)
Paul Stewart092955c2017-02-06 09:13:09 -08004079{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004080 struct hostapd_data *hapd = eloop_ctx;
4081 struct sta_info *sta = eloop_data;
Paul Stewart092955c2017-02-06 09:13:09 -08004082
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004083 wpa_printf(MSG_DEBUG,
4084 "FILS: HLP response timeout - continue with association response for "
4085 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004086 if (sta->fils_drv_assoc_finish)
4087 hostapd_notify_assoc_fils_finish(hapd, sta);
4088 else
4089 fils_hlp_finish_assoc(hapd, sta);
Paul Stewart092955c2017-02-06 09:13:09 -08004090}
4091
4092#endif /* CONFIG_FILS */
4093
4094
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004095static void handle_assoc(struct hostapd_data *hapd,
4096 const struct ieee80211_mgmt *mgmt, size_t len,
Hai Shalom74f70d42019-02-11 14:42:39 -08004097 int reassoc, int rssi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004098{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004099 u16 capab_info, listen_interval, seq_ctrl, fc;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004100 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004101 const u8 *pos;
4102 int left, i;
4103 struct sta_info *sta;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004104 u8 *tmp = NULL;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004105#ifdef CONFIG_FILS
4106 int delay_assoc = 0;
4107#endif /* CONFIG_FILS */
Hai Shalomfdcde762020-04-02 11:19:20 -07004108 int omit_rsnxe = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004109
4110 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
4111 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004112 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
4113 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004114 return;
4115 }
4116
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004117#ifdef CONFIG_TESTING_OPTIONS
4118 if (reassoc) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004119 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004120 drand48() < hapd->iconf->ignore_reassoc_probability) {
4121 wpa_printf(MSG_INFO,
4122 "TESTING: ignoring reassoc request from "
4123 MACSTR, MAC2STR(mgmt->sa));
4124 return;
4125 }
4126 } else {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004127 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004128 drand48() < hapd->iconf->ignore_assoc_probability) {
4129 wpa_printf(MSG_INFO,
4130 "TESTING: ignoring assoc request from "
4131 MACSTR, MAC2STR(mgmt->sa));
4132 return;
4133 }
4134 }
4135#endif /* CONFIG_TESTING_OPTIONS */
4136
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004137 fc = le_to_host16(mgmt->frame_control);
4138 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
4139
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004140 if (reassoc) {
4141 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
4142 listen_interval = le_to_host16(
4143 mgmt->u.reassoc_req.listen_interval);
4144 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
4145 " capab_info=0x%02x listen_interval=%d current_ap="
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004146 MACSTR " seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004147 MAC2STR(mgmt->sa), capab_info, listen_interval,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004148 MAC2STR(mgmt->u.reassoc_req.current_ap),
4149 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004150 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
4151 pos = mgmt->u.reassoc_req.variable;
4152 } else {
4153 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
4154 listen_interval = le_to_host16(
4155 mgmt->u.assoc_req.listen_interval);
4156 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004157 " capab_info=0x%02x listen_interval=%d "
4158 "seq_ctrl=0x%x%s",
4159 MAC2STR(mgmt->sa), capab_info, listen_interval,
4160 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004161 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
4162 pos = mgmt->u.assoc_req.variable;
4163 }
4164
4165 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004166#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004167 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
4168 (sta->flags & WLAN_STA_AUTH) == 0) {
4169 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
4170 "prior to authentication since it is using "
4171 "over-the-DS FT", MAC2STR(mgmt->sa));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004172
4173 /*
4174 * Mark station as authenticated, to avoid adding station
4175 * entry in the driver as associated and not authenticated
4176 */
4177 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004178 } else
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004179#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004180 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08004181 if (hapd->iface->current_mode &&
4182 hapd->iface->current_mode->mode ==
4183 HOSTAPD_MODE_IEEE80211AD) {
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004184 int acl_res;
Hai Shalomfdcde762020-04-02 11:19:20 -07004185 struct radius_sta info;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004186
Hai Shalomfdcde762020-04-02 11:19:20 -07004187 acl_res = ieee802_11_allowed_address(hapd, mgmt->sa,
4188 (const u8 *) mgmt,
4189 len, &info);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004190 if (acl_res == HOSTAPD_ACL_REJECT) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004191 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
4192 "Ignore Association Request frame from "
4193 MACSTR " due to ACL reject",
4194 MAC2STR(mgmt->sa));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004195 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
4196 goto fail;
4197 }
4198 if (acl_res == HOSTAPD_ACL_PENDING)
4199 return;
4200
Dmitry Shmidt29333592017-01-09 12:27:11 -08004201 /* DMG/IEEE 802.11ad does not use authentication.
4202 * Allocate sta entry upon association. */
4203 sta = ap_sta_add(hapd, mgmt->sa);
4204 if (!sta) {
4205 hostapd_logger(hapd, mgmt->sa,
4206 HOSTAPD_MODULE_IEEE80211,
4207 HOSTAPD_LEVEL_INFO,
4208 "Failed to add STA");
4209 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
4210 goto fail;
4211 }
4212
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004213 acl_res = ieee802_11_set_radius_info(
Hai Shalomfdcde762020-04-02 11:19:20 -07004214 hapd, sta, acl_res, &info);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004215 if (acl_res) {
4216 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
4217 goto fail;
4218 }
4219
Dmitry Shmidt29333592017-01-09 12:27:11 -08004220 hostapd_logger(hapd, sta->addr,
4221 HOSTAPD_MODULE_IEEE80211,
4222 HOSTAPD_LEVEL_DEBUG,
4223 "Skip authentication for DMG/IEEE 802.11ad");
4224 sta->flags |= WLAN_STA_AUTH;
4225 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
4226 sta->auth_alg = WLAN_AUTH_OPEN;
4227 } else {
4228 hostapd_logger(hapd, mgmt->sa,
4229 HOSTAPD_MODULE_IEEE80211,
4230 HOSTAPD_LEVEL_INFO,
4231 "Station tried to associate before authentication (aid=%d flags=0x%x)",
4232 sta ? sta->aid : -1,
4233 sta ? sta->flags : 0);
4234 send_deauth(hapd, mgmt->sa,
4235 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
4236 return;
4237 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004238 }
4239
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004240 if ((fc & WLAN_FC_RETRY) &&
4241 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
4242 sta->last_seq_ctrl == seq_ctrl &&
Paul Stewart092955c2017-02-06 09:13:09 -08004243 sta->last_subtype == (reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
4244 WLAN_FC_STYPE_ASSOC_REQ)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004245 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4246 HOSTAPD_LEVEL_DEBUG,
4247 "Drop repeated association frame seq_ctrl=0x%x",
4248 seq_ctrl);
4249 return;
4250 }
4251 sta->last_seq_ctrl = seq_ctrl;
4252 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
4253 WLAN_FC_STYPE_ASSOC_REQ;
4254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004255 if (hapd->tkip_countermeasures) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004256 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004257 goto fail;
4258 }
4259
4260 if (listen_interval > hapd->conf->max_listen_interval) {
4261 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4262 HOSTAPD_LEVEL_DEBUG,
4263 "Too large Listen Interval (%d)",
4264 listen_interval);
4265 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
4266 goto fail;
4267 }
4268
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004269#ifdef CONFIG_MBO
4270 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
4271 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
4272 goto fail;
4273 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004274
4275 if (hapd->iconf->rssi_reject_assoc_rssi && rssi &&
4276 rssi < hapd->iconf->rssi_reject_assoc_rssi &&
4277 (sta->auth_rssi == 0 ||
4278 sta->auth_rssi < hapd->iconf->rssi_reject_assoc_rssi)) {
4279 resp = WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS;
4280 goto fail;
4281 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004282#endif /* CONFIG_MBO */
4283
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004284 /*
4285 * sta->capability is used in check_assoc_ies() for RRM enabled
4286 * capability element.
4287 */
4288 sta->capability = capab_info;
4289
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004290#ifdef CONFIG_FILS
4291 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
4292 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
4293 sta->auth_alg == WLAN_AUTH_FILS_PK) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004294 int res;
4295
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004296 /* The end of the payload is encrypted. Need to decrypt it
4297 * before parsing. */
4298
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004299 tmp = os_memdup(pos, left);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004300 if (!tmp) {
4301 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
4302 goto fail;
4303 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004304
Roshan Pius3a1667e2018-07-03 15:17:14 -07004305 res = fils_decrypt_assoc(sta->wpa_sm, sta->fils_session, mgmt,
4306 len, tmp, left);
4307 if (res < 0) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004308 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
4309 goto fail;
4310 }
4311 pos = tmp;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004312 left = res;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004313 }
4314#endif /* CONFIG_FILS */
4315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004316 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
4317 * is used */
4318 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
4319 if (resp != WLAN_STATUS_SUCCESS)
4320 goto fail;
Hai Shalomfdcde762020-04-02 11:19:20 -07004321 omit_rsnxe = !get_ie(pos, left, WLAN_EID_RSNX);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004322
4323 if (hostapd_get_aid(hapd, sta) < 0) {
4324 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4325 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
4326 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
4327 goto fail;
4328 }
4329
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004330 sta->listen_interval = listen_interval;
4331
Roshan Pius3a1667e2018-07-03 15:17:14 -07004332 if (hapd->iface->current_mode &&
4333 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004334 sta->flags |= WLAN_STA_NONERP;
4335 for (i = 0; i < sta->supported_rates_len; i++) {
4336 if ((sta->supported_rates[i] & 0x7f) > 22) {
4337 sta->flags &= ~WLAN_STA_NONERP;
4338 break;
4339 }
4340 }
4341 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
4342 sta->nonerp_set = 1;
4343 hapd->iface->num_sta_non_erp++;
4344 if (hapd->iface->num_sta_non_erp == 1)
4345 ieee802_11_set_beacons(hapd->iface);
4346 }
4347
4348 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
4349 !sta->no_short_slot_time_set) {
4350 sta->no_short_slot_time_set = 1;
4351 hapd->iface->num_sta_no_short_slot_time++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004352 if (hapd->iface->current_mode &&
4353 hapd->iface->current_mode->mode ==
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004354 HOSTAPD_MODE_IEEE80211G &&
4355 hapd->iface->num_sta_no_short_slot_time == 1)
4356 ieee802_11_set_beacons(hapd->iface);
4357 }
4358
4359 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
4360 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
4361 else
4362 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
4363
4364 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
4365 !sta->no_short_preamble_set) {
4366 sta->no_short_preamble_set = 1;
4367 hapd->iface->num_sta_no_short_preamble++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004368 if (hapd->iface->current_mode &&
4369 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004370 && hapd->iface->num_sta_no_short_preamble == 1)
4371 ieee802_11_set_beacons(hapd->iface);
4372 }
4373
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004374 update_ht_state(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004375
4376 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4377 HOSTAPD_LEVEL_DEBUG,
4378 "association OK (aid %d)", sta->aid);
4379 /* Station will be marked associated, after it acknowledges AssocResp
4380 */
4381 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
4382
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004383 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
4384 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
4385 "SA Query procedure", reassoc ? "re" : "");
4386 /* TODO: Send a protected Disassociate frame to the STA using
4387 * the old key and Reason Code "Previous Authentication no
4388 * longer valid". Make sure this is only sent protected since
4389 * unprotected frame would be received by the STA that is now
4390 * trying to associate.
4391 */
4392 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004393
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004394 /* Make sure that the previously registered inactivity timer will not
4395 * remove the STA immediately. */
4396 sta->timeout_next = STA_NULLFUNC;
4397
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004398#ifdef CONFIG_TAXONOMY
4399 taxonomy_sta_info_assoc_req(hapd, sta, pos, left);
4400#endif /* CONFIG_TAXONOMY */
4401
Dmitry Shmidt29333592017-01-09 12:27:11 -08004402 sta->pending_wds_enable = 0;
4403
Paul Stewart092955c2017-02-06 09:13:09 -08004404#ifdef CONFIG_FILS
4405 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
4406 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004407 sta->auth_alg == WLAN_AUTH_FILS_PK) {
4408 if (fils_process_hlp(hapd, sta, pos, left) > 0)
4409 delay_assoc = 1;
4410 }
Paul Stewart092955c2017-02-06 09:13:09 -08004411#endif /* CONFIG_FILS */
4412
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004413 fail:
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004414
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004415 /*
4416 * In case of a successful response, add the station to the driver.
4417 * Otherwise, the kernel may ignore Data frames before we process the
4418 * ACK frame (TX status). In case of a failure, this station will be
4419 * removed.
4420 *
4421 * Note that this is not compliant with the IEEE 802.11 standard that
4422 * states that a non-AP station should transition into the
4423 * authenticated/associated state only after the station acknowledges
4424 * the (Re)Association Response frame. However, still do this as:
4425 *
4426 * 1. In case the station does not acknowledge the (Re)Association
4427 * Response frame, it will be removed.
4428 * 2. Data frames will be dropped in the kernel until the station is
4429 * set into authorized state, and there are no significant known
4430 * issues with processing other non-Data Class 3 frames during this
4431 * window.
4432 */
Hai Shalom74f70d42019-02-11 14:42:39 -08004433 if (resp == WLAN_STATUS_SUCCESS && sta &&
4434 add_associated_sta(hapd, sta, reassoc))
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004435 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
4436
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004437#ifdef CONFIG_FILS
Hai Shalom74f70d42019-02-11 14:42:39 -08004438 if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS &&
4439 eloop_is_timeout_registered(fils_hlp_timeout, hapd, sta) &&
4440 sta->fils_pending_assoc_req) {
4441 /* Do not reschedule fils_hlp_timeout in case the station
4442 * retransmits (Re)Association Request frame while waiting for
4443 * the previously started FILS HLP wait, so that the timeout can
4444 * be determined from the first pending attempt. */
4445 wpa_printf(MSG_DEBUG,
4446 "FILS: Continue waiting for HLP processing before sending (Re)Association Response frame to "
4447 MACSTR, MAC2STR(sta->addr));
4448 os_free(tmp);
4449 return;
4450 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004451 if (sta) {
4452 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
4453 os_free(sta->fils_pending_assoc_req);
4454 sta->fils_pending_assoc_req = NULL;
4455 sta->fils_pending_assoc_req_len = 0;
4456 wpabuf_free(sta->fils_hlp_resp);
4457 sta->fils_hlp_resp = NULL;
4458 }
4459 if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS) {
4460 sta->fils_pending_assoc_req = tmp;
4461 sta->fils_pending_assoc_req_len = left;
4462 sta->fils_pending_assoc_is_reassoc = reassoc;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004463 sta->fils_drv_assoc_finish = 0;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004464 wpa_printf(MSG_DEBUG,
4465 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
4466 MACSTR, MAC2STR(sta->addr));
4467 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
4468 eloop_register_timeout(0, hapd->conf->fils_hlp_wait_time * 1024,
4469 fils_hlp_timeout, hapd, sta);
4470 return;
4471 }
4472#endif /* CONFIG_FILS */
4473
Dmitry Shmidt29333592017-01-09 12:27:11 -08004474 reply_res = send_assoc_resp(hapd, sta, mgmt->sa, resp, reassoc, pos,
Hai Shalomfdcde762020-04-02 11:19:20 -07004475 left, rssi, omit_rsnxe);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004476 os_free(tmp);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004477
4478 /*
4479 * Remove the station in case tranmission of a success response fails
4480 * (the STA was added associated to the driver) or if the station was
4481 * previously added unassociated.
4482 */
Dmitry Shmidt29333592017-01-09 12:27:11 -08004483 if (sta && ((reply_res != WLAN_STATUS_SUCCESS &&
4484 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004485 hostapd_drv_sta_remove(hapd, sta->addr);
4486 sta->added_unassoc = 0;
4487 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004488}
4489
4490
4491static void handle_disassoc(struct hostapd_data *hapd,
4492 const struct ieee80211_mgmt *mgmt, size_t len)
4493{
4494 struct sta_info *sta;
4495
4496 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004497 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
4498 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004499 return;
4500 }
4501
4502 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
4503 MAC2STR(mgmt->sa),
4504 le_to_host16(mgmt->u.disassoc.reason_code));
4505
4506 sta = ap_get_sta(hapd, mgmt->sa);
4507 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004508 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
4509 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004510 return;
4511 }
4512
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004513 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004514 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004515 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Hai Shalomfdcde762020-04-02 11:19:20 -07004516 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004517 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
4518 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4519 HOSTAPD_LEVEL_INFO, "disassociated");
4520 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
4521 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
4522 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
4523 * authenticated. */
4524 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -08004525 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004526 if (sta->ipaddr)
4527 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
4528 ap_sta_ip6addr_del(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004529 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004530 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004531
4532 if (sta->timeout_next == STA_NULLFUNC ||
4533 sta->timeout_next == STA_DISASSOC) {
4534 sta->timeout_next = STA_DEAUTH;
4535 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
4536 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
4537 hapd, sta);
4538 }
4539
4540 mlme_disassociate_indication(
4541 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
Dmitry Shmidt29333592017-01-09 12:27:11 -08004542
4543 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
4544 * disassociation. */
4545 if (hapd->iface->current_mode &&
4546 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
4547 sta->flags &= ~WLAN_STA_AUTH;
4548 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
4549 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4550 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
4551 ap_free_sta(hapd, sta);
4552 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004553}
4554
4555
4556static void handle_deauth(struct hostapd_data *hapd,
4557 const struct ieee80211_mgmt *mgmt, size_t len)
4558{
4559 struct sta_info *sta;
4560
4561 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004562 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
4563 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004564 return;
4565 }
4566
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004567 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004568 " reason_code=%d",
4569 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
4570
4571 sta = ap_get_sta(hapd, mgmt->sa);
4572 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004573 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
4574 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004575 MAC2STR(mgmt->sa));
4576 return;
4577 }
4578
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004579 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004580 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004581 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
4582 WLAN_STA_ASSOC_REQ_OK);
Hai Shalomfdcde762020-04-02 11:19:20 -07004583 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004584 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
4585 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4586 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
4587 mlme_deauthenticate_indication(
4588 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
4589 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
4590 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
4591 ap_free_sta(hapd, sta);
4592}
4593
4594
4595static void handle_beacon(struct hostapd_data *hapd,
4596 const struct ieee80211_mgmt *mgmt, size_t len,
4597 struct hostapd_frame_info *fi)
4598{
4599 struct ieee802_11_elems elems;
4600
4601 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004602 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
4603 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004604 return;
4605 }
4606
4607 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
4608 len - (IEEE80211_HDRLEN +
4609 sizeof(mgmt->u.beacon)), &elems,
4610 0);
4611
4612 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
4613}
4614
4615
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004616static int robust_action_frame(u8 category)
4617{
4618 return category != WLAN_ACTION_PUBLIC &&
4619 category != WLAN_ACTION_HT;
4620}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004621
4622
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004623static int handle_action(struct hostapd_data *hapd,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004624 const struct ieee80211_mgmt *mgmt, size_t len,
4625 unsigned int freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004626{
4627 struct sta_info *sta;
Hai Shalom74f70d42019-02-11 14:42:39 -08004628 u8 *action __maybe_unused;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004629
Hai Shalom74f70d42019-02-11 14:42:39 -08004630 if (len < IEEE80211_HDRLEN + 2 + 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004631 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4632 HOSTAPD_LEVEL_DEBUG,
4633 "handle_action - too short payload (len=%lu)",
4634 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004635 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004636 }
4637
Hai Shalom74f70d42019-02-11 14:42:39 -08004638 action = (u8 *) &mgmt->u.action.u;
4639 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
4640 " da " MACSTR " len %d freq %u",
4641 mgmt->u.action.category, *action,
4642 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) len, freq);
4643
4644 sta = ap_get_sta(hapd, mgmt->sa);
4645
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004646 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
4647 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
4648 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
4649 "frame (category=%u) from unassociated STA " MACSTR,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004650 mgmt->u.action.category, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004651 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004652 }
4653
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004654 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08004655 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
4656 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004657 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4658 HOSTAPD_LEVEL_DEBUG,
4659 "Dropped unprotected Robust Action frame from "
4660 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004661 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004662 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004663
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004664 if (sta) {
4665 u16 fc = le_to_host16(mgmt->frame_control);
4666 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
4667
4668 if ((fc & WLAN_FC_RETRY) &&
4669 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
4670 sta->last_seq_ctrl == seq_ctrl &&
4671 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
4672 hostapd_logger(hapd, sta->addr,
4673 HOSTAPD_MODULE_IEEE80211,
4674 HOSTAPD_LEVEL_DEBUG,
4675 "Drop repeated action frame seq_ctrl=0x%x",
4676 seq_ctrl);
4677 return 1;
4678 }
4679
4680 sta->last_seq_ctrl = seq_ctrl;
4681 sta->last_subtype = WLAN_FC_STYPE_ACTION;
4682 }
4683
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004684 switch (mgmt->u.action.category) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004685#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004686 case WLAN_ACTION_FT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004687 if (!sta ||
4688 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004689 len - IEEE80211_HDRLEN))
4690 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004691 return 1;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004692#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004693 case WLAN_ACTION_WMM:
4694 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004695 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004696 case WLAN_ACTION_SA_QUERY:
Hai Shalom021b0b52019-04-10 11:17:58 -07004697 ieee802_11_sa_query_action(hapd, mgmt, len);
4698 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004699#ifdef CONFIG_WNM_AP
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004700 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004701 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
4702 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004703#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004704#ifdef CONFIG_FST
4705 case WLAN_ACTION_FST:
4706 if (hapd->iface->fst)
4707 fst_rx_action(hapd->iface->fst, mgmt, len);
4708 else
4709 wpa_printf(MSG_DEBUG,
4710 "FST: Ignore FST Action frame - no FST attached");
4711 return 1;
4712#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004713 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08004714 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07004715 if (len >= IEEE80211_HDRLEN + 2 &&
4716 mgmt->u.action.u.public_action.action ==
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004717 WLAN_PA_20_40_BSS_COEX) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004718 hostapd_2040_coex_action(hapd, mgmt, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004719 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004720 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004721#ifdef CONFIG_DPP
4722 if (len >= IEEE80211_HDRLEN + 6 &&
4723 mgmt->u.action.u.vs_public_action.action ==
4724 WLAN_PA_VENDOR_SPECIFIC &&
4725 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
4726 OUI_WFA &&
4727 mgmt->u.action.u.vs_public_action.variable[0] ==
4728 DPP_OUI_TYPE) {
4729 const u8 *pos, *end;
4730
4731 pos = mgmt->u.action.u.vs_public_action.oui;
4732 end = ((const u8 *) mgmt) + len;
4733 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004734 freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004735 return 1;
4736 }
4737 if (len >= IEEE80211_HDRLEN + 2 &&
4738 (mgmt->u.action.u.public_action.action ==
4739 WLAN_PA_GAS_INITIAL_RESP ||
4740 mgmt->u.action.u.public_action.action ==
4741 WLAN_PA_GAS_COMEBACK_RESP)) {
4742 const u8 *pos, *end;
4743
4744 pos = &mgmt->u.action.u.public_action.action;
4745 end = ((const u8 *) mgmt) + len;
4746 gas_query_ap_rx(hapd->gas, mgmt->sa,
4747 mgmt->u.action.category,
4748 pos, end - pos, hapd->iface->freq);
4749 return 1;
4750 }
4751#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004752 if (hapd->public_action_cb) {
4753 hapd->public_action_cb(hapd->public_action_cb_ctx,
4754 (u8 *) mgmt, len,
4755 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004756 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004757 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004758 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004759 (u8 *) mgmt, len,
4760 hapd->iface->freq);
4761 }
4762 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004763 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004764 break;
4765 case WLAN_ACTION_VENDOR_SPECIFIC:
4766 if (hapd->vendor_action_cb) {
4767 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
4768 (u8 *) mgmt, len,
4769 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004770 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004771 }
4772 break;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004773 case WLAN_ACTION_RADIO_MEASUREMENT:
4774 hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len);
4775 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004776 }
4777
4778 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4779 HOSTAPD_LEVEL_DEBUG,
4780 "handle_action - unknown action category %d or invalid "
4781 "frame",
4782 mgmt->u.action.category);
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004783 if (!is_multicast_ether_addr(mgmt->da) &&
4784 !(mgmt->u.action.category & 0x80) &&
4785 !is_multicast_ether_addr(mgmt->sa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004786 struct ieee80211_mgmt *resp;
4787
4788 /*
4789 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
4790 * Return the Action frame to the source without change
4791 * except that MSB of the Category set to 1.
4792 */
4793 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
4794 "frame back to sender");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004795 resp = os_memdup(mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004796 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004797 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004798 os_memcpy(resp->da, resp->sa, ETH_ALEN);
4799 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
4800 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
4801 resp->u.action.category |= 0x80;
4802
Hai Shalomfdcde762020-04-02 11:19:20 -07004803 if (hostapd_drv_send_mlme(hapd, resp, len, 0, NULL, 0, 0) < 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004804 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
4805 "Action frame");
4806 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004807 os_free(resp);
4808 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004809
4810 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004811}
4812
4813
4814/**
4815 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
4816 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
4817 * sent to)
4818 * @buf: management frame data (starting from IEEE 802.11 header)
4819 * @len: length of frame data in octets
4820 * @fi: meta data about received frame (signal level, etc.)
4821 *
4822 * Process all incoming IEEE 802.11 management frames. This will be called for
4823 * each frame received from the kernel driver through wlan#ap interface. In
4824 * addition, it can be called to re-inserted pending frames (e.g., when using
4825 * external RADIUS server as an MAC ACL).
4826 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004827int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
4828 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004829{
4830 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004831 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004832 int ret = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004833 unsigned int freq;
4834 int ssi_signal = fi ? fi->ssi_signal : 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004835
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004836 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004837 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004838
Roshan Pius3a1667e2018-07-03 15:17:14 -07004839 if (fi && fi->freq)
4840 freq = fi->freq;
4841 else
4842 freq = hapd->iface->freq;
4843
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004844 mgmt = (struct ieee80211_mgmt *) buf;
4845 fc = le_to_host16(mgmt->frame_control);
4846 stype = WLAN_FC_GET_STYPE(fc);
4847
Hai Shalomc3565922019-10-28 11:58:20 -07004848 if (is_multicast_ether_addr(mgmt->sa) ||
4849 is_zero_ether_addr(mgmt->sa) ||
4850 os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
4851 /* Do not process any frames with unexpected/invalid SA so that
4852 * we do not add any state for unexpected STA addresses or end
4853 * up sending out frames to unexpected destination. */
4854 wpa_printf(MSG_DEBUG, "MGMT: Invalid SA=" MACSTR
4855 " in received frame - ignore this frame silently",
4856 MAC2STR(mgmt->sa));
4857 return 0;
4858 }
4859
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004860 if (stype == WLAN_FC_STYPE_BEACON) {
4861 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004862 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004863 }
4864
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004865 if (!is_broadcast_ether_addr(mgmt->bssid) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004866#ifdef CONFIG_P2P
4867 /* Invitation responses can be sent with the peer MAC as BSSID */
4868 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
4869 stype == WLAN_FC_STYPE_ACTION) &&
4870#endif /* CONFIG_P2P */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004871#ifdef CONFIG_MESH
4872 !(hapd->conf->mesh & MESH_ENABLED) &&
4873#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004874 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004875 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
4876 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004877 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004878 }
4879
4880
4881 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004882 handle_probe_req(hapd, mgmt, len, ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004883 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004884 }
4885
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004886 if ((!is_broadcast_ether_addr(mgmt->da) ||
4887 stype != WLAN_FC_STYPE_ACTION) &&
4888 os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004889 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4890 HOSTAPD_LEVEL_DEBUG,
4891 "MGMT: DA=" MACSTR " not our address",
4892 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004893 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004894 }
4895
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004896 if (hapd->iconf->track_sta_max_num)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004897 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004898
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004899 switch (stype) {
4900 case WLAN_FC_STYPE_AUTH:
4901 wpa_printf(MSG_DEBUG, "mgmt::auth");
Hai Shalom021b0b52019-04-10 11:17:58 -07004902 handle_auth(hapd, mgmt, len, ssi_signal, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004903 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004904 break;
4905 case WLAN_FC_STYPE_ASSOC_REQ:
4906 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
Hai Shalom74f70d42019-02-11 14:42:39 -08004907 handle_assoc(hapd, mgmt, len, 0, ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004908 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004909 break;
4910 case WLAN_FC_STYPE_REASSOC_REQ:
4911 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
Hai Shalom74f70d42019-02-11 14:42:39 -08004912 handle_assoc(hapd, mgmt, len, 1, ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004913 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004914 break;
4915 case WLAN_FC_STYPE_DISASSOC:
4916 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
4917 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004918 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004919 break;
4920 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004921 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004922 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004923 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004924 break;
4925 case WLAN_FC_STYPE_ACTION:
4926 wpa_printf(MSG_DEBUG, "mgmt::action");
Roshan Pius3a1667e2018-07-03 15:17:14 -07004927 ret = handle_action(hapd, mgmt, len, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004928 break;
4929 default:
4930 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4931 HOSTAPD_LEVEL_DEBUG,
4932 "unknown mgmt frame subtype %d", stype);
4933 break;
4934 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004935
4936 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004937}
4938
4939
4940static void handle_auth_cb(struct hostapd_data *hapd,
4941 const struct ieee80211_mgmt *mgmt,
4942 size_t len, int ok)
4943{
4944 u16 auth_alg, auth_transaction, status_code;
4945 struct sta_info *sta;
4946
Hai Shalome5e28bb2019-01-28 14:51:04 -08004947 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
4948 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
4949 (unsigned long) len);
4950
4951 /*
4952 * Initialize status_code here because we are not able to read
4953 * it from the short payload.
4954 */
4955 status_code = WLAN_STATUS_UNSPECIFIED_FAILURE;
4956 goto fail;
4957 }
4958
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004959 sta = ap_get_sta(hapd, mgmt->da);
4960 if (!sta) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004961 wpa_printf(MSG_DEBUG, "handle_auth_cb: STA " MACSTR
4962 " not found",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004963 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004964 return;
4965 }
4966
4967 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
4968 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
4969 status_code = le_to_host16(mgmt->u.auth.status_code);
4970
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004971 if (!ok) {
4972 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
4973 HOSTAPD_LEVEL_NOTICE,
4974 "did not acknowledge authentication response");
4975 goto fail;
4976 }
4977
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004978 if (status_code == WLAN_STATUS_SUCCESS &&
4979 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
4980 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
4981 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4982 HOSTAPD_LEVEL_INFO, "authenticated");
4983 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004984 if (sta->added_unassoc)
4985 hostapd_set_sta_flags(hapd, sta);
4986 return;
4987 }
4988
4989fail:
4990 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
4991 hostapd_drv_sta_remove(hapd, sta->addr);
4992 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004993 }
4994}
4995
4996
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004997static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
4998 struct sta_info *sta,
4999 char *ifname_wds)
5000{
Hai Shalomfdcde762020-04-02 11:19:20 -07005001#ifdef CONFIG_WEP
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005002 int i;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07005003 struct hostapd_ssid *ssid = &hapd->conf->ssid;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005004
5005 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
5006 return;
5007
5008 for (i = 0; i < 4; i++) {
5009 if (ssid->wep.key[i] &&
5010 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
Hai Shalomfdcde762020-04-02 11:19:20 -07005011 0, i == ssid->wep.idx, NULL, 0,
5012 ssid->wep.key[i], ssid->wep.len[i],
5013 i == ssid->wep.idx ?
5014 KEY_FLAG_GROUP_RX_TX_DEFAULT :
5015 KEY_FLAG_GROUP_RX_TX)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005016 wpa_printf(MSG_WARNING,
5017 "Could not set WEP keys for WDS interface; %s",
5018 ifname_wds);
5019 break;
5020 }
5021 }
Hai Shalomfdcde762020-04-02 11:19:20 -07005022#endif /* CONFIG_WEP */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005023}
5024
5025
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005026static void handle_assoc_cb(struct hostapd_data *hapd,
5027 const struct ieee80211_mgmt *mgmt,
5028 size_t len, int reassoc, int ok)
5029{
5030 u16 status;
5031 struct sta_info *sta;
5032 int new_assoc = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005033
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005034 sta = ap_get_sta(hapd, mgmt->da);
5035 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005036 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
5037 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005038 return;
5039 }
5040
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005041 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
5042 sizeof(mgmt->u.assoc_resp))) {
5043 wpa_printf(MSG_INFO,
5044 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
5045 reassoc, (unsigned long) len);
5046 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005047 return;
5048 }
5049
5050 if (reassoc)
5051 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
5052 else
5053 status = le_to_host16(mgmt->u.assoc_resp.status_code);
5054
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005055 if (!ok) {
5056 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
5057 HOSTAPD_LEVEL_DEBUG,
5058 "did not acknowledge association response");
5059 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
5060 /* The STA is added only in case of SUCCESS */
5061 if (status == WLAN_STATUS_SUCCESS)
5062 hostapd_drv_sta_remove(hapd, sta->addr);
5063
5064 return;
5065 }
5066
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005067 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07005068 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005069
5070 /* Stop previous accounting session, if one is started, and allocate
5071 * new session id for the new session. */
5072 accounting_sta_stop(hapd, sta);
5073
5074 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
5075 HOSTAPD_LEVEL_INFO,
5076 "associated (aid %d)",
5077 sta->aid);
5078
5079 if (sta->flags & WLAN_STA_ASSOC)
5080 new_assoc = 0;
5081 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005082 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005083 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
5084 !hapd->conf->osen) ||
5085 sta->auth_alg == WLAN_AUTH_FILS_SK ||
5086 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
5087 sta->auth_alg == WLAN_AUTH_FILS_PK ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005088 sta->auth_alg == WLAN_AUTH_FT) {
5089 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005090 * Open, static WEP, FT protocol, or FILS; no separate
5091 * authorization step.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005092 */
5093 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005094 }
5095
5096 if (reassoc)
5097 mlme_reassociate_indication(hapd, sta);
5098 else
5099 mlme_associate_indication(hapd, sta);
5100
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005101 sta->sa_query_timed_out = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005102
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005103 if (sta->eapol_sm == NULL) {
5104 /*
5105 * This STA does not use RADIUS server for EAP authentication,
5106 * so bind it to the selected VLAN interface now, since the
5107 * interface selection is not going to change anymore.
5108 */
Dmitry Shmidt83474442015-04-15 13:47:09 -07005109 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07005110 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005111 } else if (sta->vlan_id) {
5112 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
Dmitry Shmidt83474442015-04-15 13:47:09 -07005113 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07005114 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005115 }
5116
5117 hostapd_set_sta_flags(hapd, sta);
5118
Dmitry Shmidt29333592017-01-09 12:27:11 -08005119 if (!(sta->flags & WLAN_STA_WDS) && sta->pending_wds_enable) {
5120 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for STA "
5121 MACSTR " based on pending request",
5122 MAC2STR(sta->addr));
5123 sta->pending_wds_enable = 0;
5124 sta->flags |= WLAN_STA_WDS;
5125 }
5126
Hai Shalom74f70d42019-02-11 14:42:39 -08005127 if (sta->flags & (WLAN_STA_WDS | WLAN_STA_MULTI_AP)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08005128 int ret;
5129 char ifname_wds[IFNAMSIZ + 1];
5130
5131 wpa_printf(MSG_DEBUG, "Reenable 4-address WDS mode for STA "
5132 MACSTR " (aid %u)",
5133 MAC2STR(sta->addr), sta->aid);
5134 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
5135 sta->aid, 1);
5136 if (!ret)
5137 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
5138 }
5139
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005140 if (sta->auth_alg == WLAN_AUTH_FT)
5141 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
5142 else
5143 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
5144 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005145 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08005146
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005147#ifdef CONFIG_FILS
5148 if ((sta->auth_alg == WLAN_AUTH_FILS_SK ||
5149 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
5150 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
5151 fils_set_tk(sta->wpa_sm) < 0) {
5152 wpa_printf(MSG_DEBUG, "FILS: TK configuration failed");
5153 ap_sta_disconnect(hapd, sta, sta->addr,
5154 WLAN_REASON_UNSPECIFIED);
5155 return;
5156 }
5157#endif /* CONFIG_FILS */
5158
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08005159 if (sta->pending_eapol_rx) {
5160 struct os_reltime now, age;
5161
5162 os_get_reltime(&now);
5163 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
5164 if (age.sec == 0 && age.usec < 200000) {
5165 wpa_printf(MSG_DEBUG,
5166 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
5167 MAC2STR(sta->addr));
5168 ieee802_1x_receive(
5169 hapd, mgmt->da,
5170 wpabuf_head(sta->pending_eapol_rx->buf),
5171 wpabuf_len(sta->pending_eapol_rx->buf));
5172 }
5173 wpabuf_free(sta->pending_eapol_rx->buf);
5174 os_free(sta->pending_eapol_rx);
5175 sta->pending_eapol_rx = NULL;
5176 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005177}
5178
5179
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005180static void handle_deauth_cb(struct hostapd_data *hapd,
5181 const struct ieee80211_mgmt *mgmt,
5182 size_t len, int ok)
5183{
5184 struct sta_info *sta;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005185 if (is_multicast_ether_addr(mgmt->da))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005186 return;
5187 sta = ap_get_sta(hapd, mgmt->da);
5188 if (!sta) {
5189 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
5190 " not found", MAC2STR(mgmt->da));
5191 return;
5192 }
5193 if (ok)
5194 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
5195 MAC2STR(sta->addr));
5196 else
5197 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
5198 "deauth", MAC2STR(sta->addr));
5199
5200 ap_sta_deauth_cb(hapd, sta);
5201}
5202
5203
5204static void handle_disassoc_cb(struct hostapd_data *hapd,
5205 const struct ieee80211_mgmt *mgmt,
5206 size_t len, int ok)
5207{
5208 struct sta_info *sta;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005209 if (is_multicast_ether_addr(mgmt->da))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005210 return;
5211 sta = ap_get_sta(hapd, mgmt->da);
5212 if (!sta) {
5213 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
5214 " not found", MAC2STR(mgmt->da));
5215 return;
5216 }
5217 if (ok)
5218 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
5219 MAC2STR(sta->addr));
5220 else
5221 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
5222 "disassoc", MAC2STR(sta->addr));
5223
5224 ap_sta_disassoc_cb(hapd, sta);
5225}
5226
5227
Dmitry Shmidt29333592017-01-09 12:27:11 -08005228static void handle_action_cb(struct hostapd_data *hapd,
5229 const struct ieee80211_mgmt *mgmt,
5230 size_t len, int ok)
5231{
5232 struct sta_info *sta;
Paul Stewart092955c2017-02-06 09:13:09 -08005233 const struct rrm_measurement_report_element *report;
Dmitry Shmidt29333592017-01-09 12:27:11 -08005234
5235 if (is_multicast_ether_addr(mgmt->da))
5236 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005237#ifdef CONFIG_DPP
5238 if (len >= IEEE80211_HDRLEN + 6 &&
5239 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
5240 mgmt->u.action.u.vs_public_action.action ==
5241 WLAN_PA_VENDOR_SPECIFIC &&
5242 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
5243 OUI_WFA &&
5244 mgmt->u.action.u.vs_public_action.variable[0] ==
5245 DPP_OUI_TYPE) {
5246 const u8 *pos, *end;
5247
5248 pos = &mgmt->u.action.u.vs_public_action.variable[1];
5249 end = ((const u8 *) mgmt) + len;
5250 hostapd_dpp_tx_status(hapd, mgmt->da, pos, end - pos, ok);
5251 return;
5252 }
5253 if (len >= IEEE80211_HDRLEN + 2 &&
5254 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
5255 (mgmt->u.action.u.public_action.action ==
5256 WLAN_PA_GAS_INITIAL_REQ ||
5257 mgmt->u.action.u.public_action.action ==
5258 WLAN_PA_GAS_COMEBACK_REQ)) {
5259 const u8 *pos, *end;
5260
5261 pos = mgmt->u.action.u.public_action.variable;
5262 end = ((const u8 *) mgmt) + len;
5263 gas_query_ap_tx_status(hapd->gas, mgmt->da, pos, end - pos, ok);
5264 return;
5265 }
5266#endif /* CONFIG_DPP */
Dmitry Shmidt29333592017-01-09 12:27:11 -08005267 sta = ap_get_sta(hapd, mgmt->da);
5268 if (!sta) {
5269 wpa_printf(MSG_DEBUG, "handle_action_cb: STA " MACSTR
5270 " not found", MAC2STR(mgmt->da));
5271 return;
5272 }
5273
Paul Stewart092955c2017-02-06 09:13:09 -08005274 if (len < 24 + 5 + sizeof(*report))
Dmitry Shmidt29333592017-01-09 12:27:11 -08005275 return;
Paul Stewart092955c2017-02-06 09:13:09 -08005276 report = (const struct rrm_measurement_report_element *)
5277 &mgmt->u.action.u.rrm.variable[2];
Dmitry Shmidt29333592017-01-09 12:27:11 -08005278 if (mgmt->u.action.category == WLAN_ACTION_RADIO_MEASUREMENT &&
Paul Stewart092955c2017-02-06 09:13:09 -08005279 mgmt->u.action.u.rrm.action == WLAN_RRM_RADIO_MEASUREMENT_REQUEST &&
5280 report->eid == WLAN_EID_MEASURE_REQUEST &&
5281 report->len >= 3 &&
5282 report->type == MEASURE_TYPE_BEACON)
Dmitry Shmidt29333592017-01-09 12:27:11 -08005283 hostapd_rrm_beacon_req_tx_status(hapd, mgmt, len, ok);
5284}
5285
5286
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005287/**
5288 * ieee802_11_mgmt_cb - Process management frame TX status callback
5289 * @hapd: hostapd BSS data structure (the BSS from which the management frame
5290 * was sent from)
5291 * @buf: management frame data (starting from IEEE 802.11 header)
5292 * @len: length of frame data in octets
5293 * @stype: management frame subtype from frame control field
5294 * @ok: Whether the frame was ACK'ed
5295 */
5296void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
5297 u16 stype, int ok)
5298{
5299 const struct ieee80211_mgmt *mgmt;
5300 mgmt = (const struct ieee80211_mgmt *) buf;
5301
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005302#ifdef CONFIG_TESTING_OPTIONS
5303 if (hapd->ext_mgmt_frame_handling) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005304 size_t hex_len = 2 * len + 1;
5305 char *hex = os_malloc(hex_len);
5306
5307 if (hex) {
5308 wpa_snprintf_hex(hex, hex_len, buf, len);
5309 wpa_msg(hapd->msg_ctx, MSG_INFO,
5310 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
5311 stype, ok, hex);
5312 os_free(hex);
5313 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005314 return;
5315 }
5316#endif /* CONFIG_TESTING_OPTIONS */
5317
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005318 switch (stype) {
5319 case WLAN_FC_STYPE_AUTH:
5320 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
5321 handle_auth_cb(hapd, mgmt, len, ok);
5322 break;
5323 case WLAN_FC_STYPE_ASSOC_RESP:
5324 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
5325 handle_assoc_cb(hapd, mgmt, len, 0, ok);
5326 break;
5327 case WLAN_FC_STYPE_REASSOC_RESP:
5328 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
5329 handle_assoc_cb(hapd, mgmt, len, 1, ok);
5330 break;
5331 case WLAN_FC_STYPE_PROBE_RESP:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005332 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005333 break;
5334 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005335 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
5336 handle_deauth_cb(hapd, mgmt, len, ok);
5337 break;
5338 case WLAN_FC_STYPE_DISASSOC:
5339 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
5340 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005341 break;
5342 case WLAN_FC_STYPE_ACTION:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005343 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005344 handle_action_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005345 break;
5346 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005347 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005348 break;
5349 }
5350}
5351
5352
5353int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
5354{
5355 /* TODO */
5356 return 0;
5357}
5358
5359
5360int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
5361 char *buf, size_t buflen)
5362{
5363 /* TODO */
5364 return 0;
5365}
5366
5367
5368void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
5369 const u8 *buf, size_t len, int ack)
5370{
5371 struct sta_info *sta;
5372 struct hostapd_iface *iface = hapd->iface;
5373
5374 sta = ap_get_sta(hapd, addr);
5375 if (sta == NULL && iface->num_bss > 1) {
5376 size_t j;
5377 for (j = 0; j < iface->num_bss; j++) {
5378 hapd = iface->bss[j];
5379 sta = ap_get_sta(hapd, addr);
5380 if (sta)
5381 break;
5382 }
5383 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005384 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005385 return;
5386 if (sta->flags & WLAN_STA_PENDING_POLL) {
5387 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
5388 "activity poll", MAC2STR(sta->addr),
5389 ack ? "ACKed" : "did not ACK");
5390 if (ack)
5391 sta->flags &= ~WLAN_STA_PENDING_POLL;
5392 }
5393
5394 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
5395}
5396
5397
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005398void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
5399 const u8 *data, size_t len, int ack)
5400{
5401 struct sta_info *sta;
5402 struct hostapd_iface *iface = hapd->iface;
5403
5404 sta = ap_get_sta(hapd, dst);
5405 if (sta == NULL && iface->num_bss > 1) {
5406 size_t j;
5407 for (j = 0; j < iface->num_bss; j++) {
5408 hapd = iface->bss[j];
5409 sta = ap_get_sta(hapd, dst);
5410 if (sta)
5411 break;
5412 }
5413 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005414 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
5415 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
5416 MACSTR " that is not currently associated",
5417 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005418 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005419 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005420
5421 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
5422}
5423
5424
5425void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
5426{
5427 struct sta_info *sta;
5428 struct hostapd_iface *iface = hapd->iface;
5429
5430 sta = ap_get_sta(hapd, addr);
5431 if (sta == NULL && iface->num_bss > 1) {
5432 size_t j;
5433 for (j = 0; j < iface->num_bss; j++) {
5434 hapd = iface->bss[j];
5435 sta = ap_get_sta(hapd, addr);
5436 if (sta)
5437 break;
5438 }
5439 }
5440 if (sta == NULL)
5441 return;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005442 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
5443 MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005444 if (!(sta->flags & WLAN_STA_PENDING_POLL))
5445 return;
5446
5447 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
5448 "activity poll", MAC2STR(sta->addr));
5449 sta->flags &= ~WLAN_STA_PENDING_POLL;
5450}
5451
5452
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005453void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
5454 int wds)
5455{
5456 struct sta_info *sta;
5457
5458 sta = ap_get_sta(hapd, src);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005459 if (sta &&
5460 ((sta->flags & WLAN_STA_ASSOC) ||
5461 ((sta->flags & WLAN_STA_ASSOC_REQ_OK) && wds))) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005462 if (!hapd->conf->wds_sta)
5463 return;
5464
Dmitry Shmidt29333592017-01-09 12:27:11 -08005465 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK)) ==
5466 WLAN_STA_ASSOC_REQ_OK) {
5467 wpa_printf(MSG_DEBUG,
5468 "Postpone 4-address WDS mode enabling for STA "
5469 MACSTR " since TX status for AssocResp is not yet known",
5470 MAC2STR(sta->addr));
5471 sta->pending_wds_enable = 1;
5472 return;
5473 }
5474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005475 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005476 int ret;
5477 char ifname_wds[IFNAMSIZ + 1];
5478
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005479 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
5480 "STA " MACSTR " (aid %u)",
5481 MAC2STR(sta->addr), sta->aid);
5482 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005483 ret = hostapd_set_wds_sta(hapd, ifname_wds,
5484 sta->addr, sta->aid, 1);
5485 if (!ret)
5486 hostapd_set_wds_encryption(hapd, sta,
5487 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005488 }
5489 return;
5490 }
5491
5492 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
5493 MACSTR, MAC2STR(src));
Hai Shalomc3565922019-10-28 11:58:20 -07005494 if (is_multicast_ether_addr(src) || is_zero_ether_addr(src) ||
5495 os_memcmp(src, hapd->own_addr, ETH_ALEN) == 0) {
5496 /* Broadcast bit set in SA or unexpected SA?! Ignore the frame
5497 * silently. */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005498 return;
5499 }
5500
5501 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
5502 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
5503 "already been sent, but no TX status yet known - "
5504 "ignore Class 3 frame issue with " MACSTR,
5505 MAC2STR(src));
5506 return;
5507 }
5508
5509 if (sta && (sta->flags & WLAN_STA_AUTH))
5510 hostapd_drv_sta_disassoc(
5511 hapd, src,
5512 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
5513 else
5514 hostapd_drv_sta_deauth(
5515 hapd, src,
5516 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
5517}
5518
5519
5520#endif /* CONFIG_NATIVE_WINDOWS */