blob: 4d30bae0c87c018f265321f2f02b17c73fe6afcc [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;
91
92 if (hapd->iface->current_rates == NULL)
93 return eid;
94
95 *pos++ = WLAN_EID_SUPP_RATES;
96 num = hapd->iface->num_rates;
97 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
98 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080099 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
100 num++;
Hai Shalomc3565922019-10-28 11:58:20 -0700101 if (hapd->conf->sae_pwe == 1)
102 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103 if (num > 8) {
104 /* rest of the rates are encoded in Extended supported
105 * rates element */
106 num = 8;
107 }
108
109 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700110 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
111 i++) {
112 count++;
113 *pos = hapd->iface->current_rates[i].rate / 5;
114 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
115 *pos |= 0x80;
116 pos++;
117 }
118
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800119 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
120 count++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700121 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800122 }
123
124 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
125 count++;
126 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
127 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700128
Hai Shalomc3565922019-10-28 11:58:20 -0700129 if (hapd->conf->sae_pwe == 1 && count < 8) {
130 count++;
131 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY;
132 }
133
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700134 return pos;
135}
136
137
138u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
139{
140 u8 *pos = eid;
141 int i, num, count;
142
143 if (hapd->iface->current_rates == NULL)
144 return eid;
145
146 num = hapd->iface->num_rates;
147 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
148 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800149 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
150 num++;
Hai Shalomc3565922019-10-28 11:58:20 -0700151 if (hapd->conf->sae_pwe == 1)
152 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700153 if (num <= 8)
154 return eid;
155 num -= 8;
156
157 *pos++ = WLAN_EID_EXT_SUPP_RATES;
158 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
160 i++) {
161 count++;
162 if (count <= 8)
163 continue; /* already in SuppRates IE */
164 *pos = hapd->iface->current_rates[i].rate / 5;
165 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
166 *pos |= 0x80;
167 pos++;
168 }
169
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800170 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
171 count++;
172 if (count > 8)
173 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
174 }
175
176 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
177 count++;
178 if (count > 8)
179 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
180 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181
Hai Shalomc3565922019-10-28 11:58:20 -0700182 if (hapd->conf->sae_pwe == 1) {
183 count++;
184 if (count > 8)
185 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY;
186 }
187
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700188 return pos;
189}
190
191
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700192u16 hostapd_own_capab_info(struct hostapd_data *hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700193{
194 int capab = WLAN_CAPABILITY_ESS;
195 int privacy;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800196 int dfs;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700197 int i;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800198
199 /* Check if any of configured channels require DFS */
200 dfs = hostapd_is_dfs_required(hapd->iface);
201 if (dfs < 0) {
202 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
203 dfs);
204 dfs = 0;
205 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700206
207 if (hapd->iface->num_sta_no_short_preamble == 0 &&
208 hapd->iconf->preamble == SHORT_PREAMBLE)
209 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
210
211 privacy = hapd->conf->ssid.wep.keys_set;
212
213 if (hapd->conf->ieee802_1x &&
214 (hapd->conf->default_wep_key_len ||
215 hapd->conf->individual_wep_key_len))
216 privacy = 1;
217
218 if (hapd->conf->wpa)
219 privacy = 1;
220
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800221#ifdef CONFIG_HS20
222 if (hapd->conf->osen)
223 privacy = 1;
224#endif /* CONFIG_HS20 */
225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226 if (privacy)
227 capab |= WLAN_CAPABILITY_PRIVACY;
228
229 if (hapd->iface->current_mode &&
230 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
231 hapd->iface->num_sta_no_short_slot_time == 0)
232 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
233
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800234 /*
235 * Currently, Spectrum Management capability bit is set when directly
236 * requested in configuration by spectrum_mgmt_required or when AP is
237 * running on DFS channel.
238 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
239 */
240 if (hapd->iface->current_mode &&
241 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
242 (hapd->iconf->spectrum_mgmt_required || dfs))
243 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
244
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700245 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
246 if (hapd->conf->radio_measurements[i]) {
247 capab |= IEEE80211_CAP_RRM;
248 break;
249 }
250 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800251
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700252 return capab;
253}
254
255
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800256#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
258 u16 auth_transaction, const u8 *challenge,
259 int iswep)
260{
261 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
262 HOSTAPD_LEVEL_DEBUG,
263 "authentication (shared key, transaction %d)",
264 auth_transaction);
265
266 if (auth_transaction == 1) {
267 if (!sta->challenge) {
268 /* Generate a pseudo-random challenge */
269 u8 key[8];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
272 if (sta->challenge == NULL)
273 return WLAN_STATUS_UNSPECIFIED_FAILURE;
274
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800275 if (os_get_random(key, sizeof(key)) < 0) {
276 os_free(sta->challenge);
277 sta->challenge = NULL;
278 return WLAN_STATUS_UNSPECIFIED_FAILURE;
279 }
280
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281 rc4_skip(key, sizeof(key), 0,
282 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
283 }
284 return 0;
285 }
286
287 if (auth_transaction != 3)
288 return WLAN_STATUS_UNSPECIFIED_FAILURE;
289
290 /* Transaction 3 */
291 if (!iswep || !sta->challenge || !challenge ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700292 os_memcmp_const(sta->challenge, challenge,
293 WLAN_AUTH_CHALLENGE_LEN)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
295 HOSTAPD_LEVEL_INFO,
296 "shared key authentication - invalid "
297 "challenge-response");
298 return WLAN_STATUS_CHALLENGE_FAIL;
299 }
300
301 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
302 HOSTAPD_LEVEL_DEBUG,
303 "authentication OK (shared key)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 sta->flags |= WLAN_STA_AUTH;
305 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700306 os_free(sta->challenge);
307 sta->challenge = NULL;
308
309 return 0;
310}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800311#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312
313
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800314static int send_auth_reply(struct hostapd_data *hapd,
315 const u8 *dst, const u8 *bssid,
316 u16 auth_alg, u16 auth_transaction, u16 resp,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700317 const u8 *ies, size_t ies_len, const char *dbg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318{
319 struct ieee80211_mgmt *reply;
320 u8 *buf;
321 size_t rlen;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800322 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323
324 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
325 buf = os_zalloc(rlen);
326 if (buf == NULL)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800327 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328
329 reply = (struct ieee80211_mgmt *) buf;
330 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
331 WLAN_FC_STYPE_AUTH);
332 os_memcpy(reply->da, dst, ETH_ALEN);
333 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
334 os_memcpy(reply->bssid, bssid, ETH_ALEN);
335
336 reply->u.auth.auth_alg = host_to_le16(auth_alg);
337 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
338 reply->u.auth.status_code = host_to_le16(resp);
339
340 if (ies && ies_len)
341 os_memcpy(reply->u.auth.variable, ies, ies_len);
342
343 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700344 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu) (dbg=%s)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700345 MAC2STR(dst), auth_alg, auth_transaction,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700346 resp, (unsigned long) ies_len, dbg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800347 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800348 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
349 else
350 reply_res = WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351
352 os_free(buf);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800353
354 return reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700355}
356
357
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800358#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
360 u16 auth_transaction, u16 status,
361 const u8 *ies, size_t ies_len)
362{
363 struct hostapd_data *hapd = ctx;
364 struct sta_info *sta;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800365 int reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700366
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800367 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700368 auth_transaction, status, ies, ies_len,
369 "auth-ft-finish");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700370
371 sta = ap_get_sta(hapd, dst);
372 if (sta == NULL)
373 return;
374
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800375 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
376 status != WLAN_STATUS_SUCCESS)) {
377 hostapd_drv_sta_remove(hapd, sta->addr);
378 sta->added_unassoc = 0;
379 return;
380 }
381
382 if (status != WLAN_STATUS_SUCCESS)
383 return;
384
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700385 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
386 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
387 sta->flags |= WLAN_STA_AUTH;
388 mlme_authenticate_indication(hapd, sta);
389}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800390#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700391
392
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800393#ifdef CONFIG_SAE
394
Roshan Pius3a1667e2018-07-03 15:17:14 -0700395static void sae_set_state(struct sta_info *sta, enum sae_state state,
396 const char *reason)
397{
398 wpa_printf(MSG_DEBUG, "SAE: State %s -> %s for peer " MACSTR " (%s)",
399 sae_state_txt(sta->sae->state), sae_state_txt(state),
400 MAC2STR(sta->addr), reason);
401 sta->sae->state = state;
402}
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800403
404
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800405static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
Hai Shalomc3565922019-10-28 11:58:20 -0700406 struct sta_info *sta, int update,
407 int status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800408{
409 struct wpabuf *buf;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700410 const char *password = NULL;
411 struct sae_password_entry *pw;
412 const char *rx_id = NULL;
Hai Shalomc3565922019-10-28 11:58:20 -0700413 int use_pt = 0;
414 struct sae_pt *pt = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800415
Hai Shalomc3565922019-10-28 11:58:20 -0700416 if (sta->sae->tmp) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700417 rx_id = sta->sae->tmp->pw_id;
Hai Shalomc3565922019-10-28 11:58:20 -0700418 use_pt = sta->sae->tmp->h2e;
419 }
420
421 if (status_code == WLAN_STATUS_SUCCESS)
422 use_pt = 0;
423 else if (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT)
424 use_pt = 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700425
426 for (pw = hapd->conf->sae_passwords; pw; pw = pw->next) {
427 if (!is_broadcast_ether_addr(pw->peer_addr) &&
428 os_memcmp(pw->peer_addr, sta->addr, ETH_ALEN) != 0)
429 continue;
430 if ((rx_id && !pw->identifier) || (!rx_id && pw->identifier))
431 continue;
432 if (rx_id && pw->identifier &&
433 os_strcmp(rx_id, pw->identifier) != 0)
434 continue;
435 password = pw->password;
Hai Shalomc3565922019-10-28 11:58:20 -0700436 pt = pw->pt;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700437 break;
438 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700439 if (!password) {
Hai Shalomc3565922019-10-28 11:58:20 -0700440 password = hapd->conf->ssid.wpa_passphrase;
441 pt = hapd->conf->ssid.pt;
442 }
443 if (!password || (use_pt && !pt)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800444 wpa_printf(MSG_DEBUG, "SAE: No password available");
445 return NULL;
446 }
447
Hai Shalomc3565922019-10-28 11:58:20 -0700448 if (update && use_pt &&
449 sae_prepare_commit_pt(sta->sae, pt, hapd->own_addr, sta->addr,
450 NULL) < 0)
451 return NULL;
452
453 if (update && !use_pt &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800454 sae_prepare_commit(hapd->own_addr, sta->addr,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700455 (u8 *) password, os_strlen(password), rx_id,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800456 sta->sae) < 0) {
457 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
458 return NULL;
459 }
460
Hai Shalom021b0b52019-04-10 11:17:58 -0700461 if (pw && pw->vlan_id) {
462 if (!sta->sae->tmp) {
463 wpa_printf(MSG_INFO,
464 "SAE: No temporary data allocated - cannot store VLAN ID");
465 return NULL;
466 }
467 sta->sae->tmp->vlan_id = pw->vlan_id;
468 }
469
Roshan Pius3a1667e2018-07-03 15:17:14 -0700470 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN +
471 (rx_id ? 3 + os_strlen(rx_id) : 0));
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800472 if (buf == NULL)
473 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800474 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
Roshan Pius3a1667e2018-07-03 15:17:14 -0700475 sta->sae->tmp->anti_clogging_token : NULL, rx_id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800476
477 return buf;
478}
479
480
481static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
482 struct sta_info *sta)
483{
484 struct wpabuf *buf;
485
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800486 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800487 if (buf == NULL)
488 return NULL;
489
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800490 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800491
492 return buf;
493}
494
495
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800496static int auth_sae_send_commit(struct hostapd_data *hapd,
497 struct sta_info *sta,
Hai Shalomc3565922019-10-28 11:58:20 -0700498 const u8 *bssid, int update, int status_code)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800499{
500 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800501 int reply_res;
Hai Shalomc3565922019-10-28 11:58:20 -0700502 u16 status;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800503
Hai Shalomc3565922019-10-28 11:58:20 -0700504 data = auth_build_sae_commit(hapd, sta, update, status_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700505 if (!data && sta->sae->tmp && sta->sae->tmp->pw_id)
506 return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800507 if (data == NULL)
508 return WLAN_STATUS_UNSPECIFIED_FAILURE;
509
Hai Shalomc3565922019-10-28 11:58:20 -0700510 status = (sta->sae->tmp && sta->sae->tmp->h2e) ?
511 WLAN_STATUS_SAE_HASH_TO_ELEMENT : WLAN_STATUS_SUCCESS;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800512 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
Hai Shalomc3565922019-10-28 11:58:20 -0700513 status, wpabuf_head(data),
Roshan Pius3a1667e2018-07-03 15:17:14 -0700514 wpabuf_len(data), "sae-send-commit");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800515
516 wpabuf_free(data);
517
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800518 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800519}
520
521
522static int auth_sae_send_confirm(struct hostapd_data *hapd,
523 struct sta_info *sta,
524 const u8 *bssid)
525{
526 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800527 int reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800528
529 data = auth_build_sae_confirm(hapd, sta);
530 if (data == NULL)
531 return WLAN_STATUS_UNSPECIFIED_FAILURE;
532
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800533 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
534 WLAN_STATUS_SUCCESS, wpabuf_head(data),
Roshan Pius3a1667e2018-07-03 15:17:14 -0700535 wpabuf_len(data), "sae-send-confirm");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800536
537 wpabuf_free(data);
538
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800539 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800540}
541
542
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800543static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800544{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800545 struct sta_info *sta;
546 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800547
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800548 if (hapd->conf->sae_anti_clogging_threshold == 0)
549 return 1;
550
551 for (sta = hapd->sta_list; sta; sta = sta->next) {
552 if (!sta->sae)
553 continue;
554 if (sta->sae->state != SAE_COMMITTED &&
555 sta->sae->state != SAE_CONFIRMED)
556 continue;
557 open++;
558 if (open >= hapd->conf->sae_anti_clogging_threshold)
559 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800560 }
561
Hai Shalom021b0b52019-04-10 11:17:58 -0700562 /* In addition to already existing open SAE sessions, check whether
563 * there are enough pending commit messages in the processing queue to
564 * potentially result in too many open sessions. */
565 if (open + dl_list_len(&hapd->sae_commit_queue) >=
566 hapd->conf->sae_anti_clogging_threshold)
567 return 1;
568
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800569 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800570}
571
572
Hai Shalom021b0b52019-04-10 11:17:58 -0700573static u8 sae_token_hash(struct hostapd_data *hapd, const u8 *addr)
574{
575 u8 hash[SHA256_MAC_LEN];
576
577 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
578 addr, ETH_ALEN, hash);
579 return hash[0];
580}
581
582
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800583static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
584 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800585{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800586 u8 mac[SHA256_MAC_LEN];
Hai Shalom021b0b52019-04-10 11:17:58 -0700587 const u8 *addrs[2];
588 size_t len[2];
589 u16 token_idx;
590 u8 idx;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800591
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800592 if (token_len != SHA256_MAC_LEN)
593 return -1;
Hai Shalom021b0b52019-04-10 11:17:58 -0700594 idx = sae_token_hash(hapd, addr);
595 token_idx = hapd->sae_pending_token_idx[idx];
596 if (token_idx == 0 || token_idx != WPA_GET_BE16(token)) {
597 wpa_printf(MSG_DEBUG, "SAE: Invalid anti-clogging token from "
598 MACSTR " - token_idx 0x%04x, expected 0x%04x",
599 MAC2STR(addr), WPA_GET_BE16(token), token_idx);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800600 return -1;
Hai Shalom021b0b52019-04-10 11:17:58 -0700601 }
602
603 addrs[0] = addr;
604 len[0] = ETH_ALEN;
605 addrs[1] = token;
606 len[1] = 2;
607 if (hmac_sha256_vector(hapd->sae_token_key, sizeof(hapd->sae_token_key),
608 2, addrs, len, mac) < 0 ||
609 os_memcmp_const(token + 2, &mac[2], SHA256_MAC_LEN - 2) != 0)
610 return -1;
611
612 hapd->sae_pending_token_idx[idx] = 0; /* invalidate used token */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800613
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800614 return 0;
615}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800616
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800617
618static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800619 int group, const u8 *addr)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800620{
621 struct wpabuf *buf;
622 u8 *token;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800623 struct os_reltime now;
Hai Shalom021b0b52019-04-10 11:17:58 -0700624 u8 idx[2];
625 const u8 *addrs[2];
626 size_t len[2];
627 u8 p_idx;
628 u16 token_idx;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800629
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800630 os_get_reltime(&now);
631 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
Hai Shalom021b0b52019-04-10 11:17:58 -0700632 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60) ||
633 hapd->sae_token_idx == 0xffff) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800634 if (random_get_bytes(hapd->sae_token_key,
635 sizeof(hapd->sae_token_key)) < 0)
636 return NULL;
637 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
638 hapd->sae_token_key, sizeof(hapd->sae_token_key));
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800639 hapd->last_sae_token_key_update = now;
Hai Shalom021b0b52019-04-10 11:17:58 -0700640 hapd->sae_token_idx = 0;
641 os_memset(hapd->sae_pending_token_idx, 0,
642 sizeof(hapd->sae_pending_token_idx));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800643 }
644
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800645 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800646 if (buf == NULL)
647 return NULL;
648
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800649 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
650
Hai Shalom021b0b52019-04-10 11:17:58 -0700651 p_idx = sae_token_hash(hapd, addr);
652 token_idx = hapd->sae_pending_token_idx[p_idx];
653 if (!token_idx) {
654 hapd->sae_token_idx++;
655 token_idx = hapd->sae_token_idx;
656 hapd->sae_pending_token_idx[p_idx] = token_idx;
657 }
658 WPA_PUT_BE16(idx, token_idx);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800659 token = wpabuf_put(buf, SHA256_MAC_LEN);
Hai Shalom021b0b52019-04-10 11:17:58 -0700660 addrs[0] = addr;
661 len[0] = ETH_ALEN;
662 addrs[1] = idx;
663 len[1] = sizeof(idx);
664 if (hmac_sha256_vector(hapd->sae_token_key, sizeof(hapd->sae_token_key),
665 2, addrs, len, token) < 0) {
666 wpabuf_free(buf);
667 return NULL;
668 }
669 WPA_PUT_BE16(token, token_idx);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800670
671 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800672}
673
674
Roshan Pius3a1667e2018-07-03 15:17:14 -0700675static int sae_check_big_sync(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800676{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700677 if (sta->sae->sync > hapd->conf->sae_sync) {
678 sae_set_state(sta, SAE_NOTHING, "Sync > dot11RSNASAESync");
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800679 sta->sae->sync = 0;
680 return -1;
681 }
682 return 0;
683}
684
685
686static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
687{
688 struct hostapd_data *hapd = eloop_ctx;
689 struct sta_info *sta = eloop_data;
690 int ret;
691
Roshan Pius3a1667e2018-07-03 15:17:14 -0700692 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800693 return;
694 sta->sae->sync++;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700695 wpa_printf(MSG_DEBUG, "SAE: Auth SAE retransmit timer for " MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700696 " (sync=%d state=%s)",
697 MAC2STR(sta->addr), sta->sae->sync,
698 sae_state_txt(sta->sae->state));
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800699
700 switch (sta->sae->state) {
701 case SAE_COMMITTED:
Hai Shalomc3565922019-10-28 11:58:20 -0700702 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0, -1);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800703 eloop_register_timeout(0,
704 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800705 auth_sae_retransmit_timer, hapd, sta);
706 break;
707 case SAE_CONFIRMED:
708 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800709 eloop_register_timeout(0,
710 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800711 auth_sae_retransmit_timer, hapd, sta);
712 break;
713 default:
714 ret = -1;
715 break;
716 }
717
718 if (ret != WLAN_STATUS_SUCCESS)
719 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
720}
721
722
723void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
724{
725 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
726}
727
728
729static void sae_set_retransmit_timer(struct hostapd_data *hapd,
730 struct sta_info *sta)
731{
732 if (!(hapd->conf->mesh & MESH_ENABLED))
733 return;
734
735 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800736 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800737 auth_sae_retransmit_timer, hapd, sta);
738}
739
740
Hai Shalom5f92bc92019-04-18 11:54:11 -0700741static void sae_sme_send_external_auth_status(struct hostapd_data *hapd,
742 struct sta_info *sta, u16 status)
743{
744 struct external_auth params;
745
746 os_memset(&params, 0, sizeof(params));
747 params.status = status;
748 params.bssid = sta->addr;
Hai Shalom81f62d82019-07-22 12:10:00 -0700749 if (status == WLAN_STATUS_SUCCESS && sta->sae &&
750 !hapd->conf->disable_pmksa_caching)
Hai Shalom5f92bc92019-04-18 11:54:11 -0700751 params.pmkid = sta->sae->pmkid;
752
753 hostapd_drv_send_external_auth_status(hapd, &params);
754}
755
756
Dmitry Shmidte4663042016-04-04 10:07:49 -0700757void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
758{
Hai Shalom021b0b52019-04-10 11:17:58 -0700759#ifndef CONFIG_NO_VLAN
760 struct vlan_description vlan_desc;
761
762 if (sta->sae->tmp && sta->sae->tmp->vlan_id > 0) {
763 wpa_printf(MSG_DEBUG, "SAE: Assign STA " MACSTR
764 " to VLAN ID %d",
765 MAC2STR(sta->addr), sta->sae->tmp->vlan_id);
766
767 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
768 vlan_desc.notempty = 1;
769 vlan_desc.untagged = sta->sae->tmp->vlan_id;
770 if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
771 wpa_printf(MSG_INFO,
772 "Invalid VLAN ID %d in sae_password",
773 sta->sae->tmp->vlan_id);
774 return;
775 }
776
777 if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0 ||
778 ap_sta_bind_vlan(hapd, sta) < 0) {
779 wpa_printf(MSG_INFO,
780 "Failed to assign VLAN ID %d from sae_password to "
781 MACSTR, sta->sae->tmp->vlan_id,
782 MAC2STR(sta->addr));
783 return;
784 }
785 }
786#endif /* CONFIG_NO_VLAN */
787
Dmitry Shmidte4663042016-04-04 10:07:49 -0700788 sta->flags |= WLAN_STA_AUTH;
789 sta->auth_alg = WLAN_AUTH_SAE;
790 mlme_authenticate_indication(hapd, sta);
791 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700792 sae_set_state(sta, SAE_ACCEPTED, "Accept Confirm");
Dmitry Shmidte4663042016-04-04 10:07:49 -0700793 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
794 sta->sae->pmk, sta->sae->pmkid);
Hai Shalom5f92bc92019-04-18 11:54:11 -0700795 sae_sme_send_external_auth_status(hapd, sta, WLAN_STATUS_SUCCESS);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700796}
797
798
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800799static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
Hai Shalomc3565922019-10-28 11:58:20 -0700800 const u8 *bssid, u16 auth_transaction, u16 status_code,
801 int allow_reuse, int *sta_removed)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800802{
803 int ret;
804
Hai Shalom5f92bc92019-04-18 11:54:11 -0700805 *sta_removed = 0;
806
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800807 if (auth_transaction != 1 && auth_transaction != 2)
808 return WLAN_STATUS_UNSPECIFIED_FAILURE;
809
Roshan Pius3a1667e2018-07-03 15:17:14 -0700810 wpa_printf(MSG_DEBUG, "SAE: Peer " MACSTR " state=%s auth_trans=%u",
811 MAC2STR(sta->addr), sae_state_txt(sta->sae->state),
812 auth_transaction);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800813 switch (sta->sae->state) {
814 case SAE_NOTHING:
815 if (auth_transaction == 1) {
Hai Shalomc3565922019-10-28 11:58:20 -0700816 if (sta->sae->tmp)
817 sta->sae->tmp->h2e = status_code ==
818 WLAN_STATUS_SAE_HASH_TO_ELEMENT;
Hai Shalom021b0b52019-04-10 11:17:58 -0700819 ret = auth_sae_send_commit(hapd, sta, bssid,
Hai Shalomc3565922019-10-28 11:58:20 -0700820 !allow_reuse, status_code);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800821 if (ret)
822 return ret;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700823 sae_set_state(sta, SAE_COMMITTED, "Sent Commit");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800824
825 if (sae_process_commit(sta->sae) < 0)
826 return WLAN_STATUS_UNSPECIFIED_FAILURE;
827
828 /*
Hai Shalomc3565922019-10-28 11:58:20 -0700829 * In mesh case, both Commit and Confirm are sent
830 * immediately. In infrastructure BSS, by default, only
831 * a single Authentication frame (Commit) is expected
832 * from the AP here and the second one (Confirm) will
833 * be sent once the STA has sent its second
834 * Authentication frame (Confirm). This behavior can be
835 * overridden with explicit configuration so that the
836 * infrastructure BSS case sends both frames together.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800837 */
Hai Shalomc3565922019-10-28 11:58:20 -0700838 if ((hapd->conf->mesh & MESH_ENABLED) ||
839 hapd->conf->sae_confirm_immediate) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800840 /*
841 * Send both Commit and Confirm immediately
842 * based on SAE finite state machine
843 * Nothing -> Confirm transition.
844 */
845 ret = auth_sae_send_confirm(hapd, sta, bssid);
846 if (ret)
847 return ret;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700848 sae_set_state(sta, SAE_CONFIRMED,
849 "Sent Confirm (mesh)");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800850 } else {
851 /*
852 * For infrastructure BSS, send only the Commit
853 * message now to get alternating sequence of
854 * Authentication frames between the AP and STA.
855 * Confirm will be sent in
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800856 * Committed -> Confirmed/Accepted transition
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800857 * when receiving Confirm from STA.
858 */
859 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800860 sta->sae->sync = 0;
861 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800862 } else {
863 hostapd_logger(hapd, sta->addr,
864 HOSTAPD_MODULE_IEEE80211,
865 HOSTAPD_LEVEL_DEBUG,
866 "SAE confirm before commit");
867 }
868 break;
869 case SAE_COMMITTED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800870 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800871 if (auth_transaction == 1) {
872 if (sae_process_commit(sta->sae) < 0)
873 return WLAN_STATUS_UNSPECIFIED_FAILURE;
874
875 ret = auth_sae_send_confirm(hapd, sta, bssid);
876 if (ret)
877 return ret;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700878 sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm");
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800879 sta->sae->sync = 0;
880 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800881 } else if (hapd->conf->mesh & MESH_ENABLED) {
882 /*
883 * In mesh case, follow SAE finite state machine and
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800884 * send Commit now, if sync count allows.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800885 */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700886 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800887 return WLAN_STATUS_SUCCESS;
888 sta->sae->sync++;
889
Hai Shalomc3565922019-10-28 11:58:20 -0700890 ret = auth_sae_send_commit(hapd, sta, bssid, 0,
891 status_code);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800892 if (ret)
893 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800894
895 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800896 } else {
897 /*
898 * For instructure BSS, send the postponed Confirm from
899 * Nothing -> Confirmed transition that was reduced to
900 * Nothing -> Committed above.
901 */
902 ret = auth_sae_send_confirm(hapd, sta, bssid);
903 if (ret)
904 return ret;
905
Roshan Pius3a1667e2018-07-03 15:17:14 -0700906 sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800907
908 /*
909 * Since this was triggered on Confirm RX, run another
910 * step to get to Accepted without waiting for
911 * additional events.
912 */
Hai Shalom021b0b52019-04-10 11:17:58 -0700913 return sae_sm_step(hapd, sta, bssid, auth_transaction,
Hai Shalomc3565922019-10-28 11:58:20 -0700914 WLAN_STATUS_SUCCESS, 0, sta_removed);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800915 }
916 break;
917 case SAE_CONFIRMED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800918 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800919 if (auth_transaction == 1) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700920 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800921 return WLAN_STATUS_SUCCESS;
922 sta->sae->sync++;
923
Hai Shalomc3565922019-10-28 11:58:20 -0700924 ret = auth_sae_send_commit(hapd, sta, bssid, 1,
925 status_code);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800926 if (ret)
927 return ret;
928
929 if (sae_process_commit(sta->sae) < 0)
930 return WLAN_STATUS_UNSPECIFIED_FAILURE;
931
932 ret = auth_sae_send_confirm(hapd, sta, bssid);
933 if (ret)
934 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800935
936 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800937 } else {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700938 sta->sae->send_confirm = 0xffff;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700939 sae_accept_sta(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800940 }
941 break;
942 case SAE_ACCEPTED:
Roshan Pius3a1667e2018-07-03 15:17:14 -0700943 if (auth_transaction == 1 &&
944 (hapd->conf->mesh & MESH_ENABLED)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800945 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
946 ") doing reauthentication",
947 MAC2STR(sta->addr));
Dmitry Shmidte4663042016-04-04 10:07:49 -0700948 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
Hai Shalom5f92bc92019-04-18 11:54:11 -0700949 ap_free_sta(hapd, sta);
950 *sta_removed = 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700951 } else if (auth_transaction == 1) {
952 wpa_printf(MSG_DEBUG, "SAE: Start reauthentication");
Hai Shalomc3565922019-10-28 11:58:20 -0700953 ret = auth_sae_send_commit(hapd, sta, bssid, 1,
954 status_code);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700955 if (ret)
956 return ret;
957 sae_set_state(sta, SAE_COMMITTED, "Sent Commit");
958
959 if (sae_process_commit(sta->sae) < 0)
960 return WLAN_STATUS_UNSPECIFIED_FAILURE;
961 sta->sae->sync = 0;
962 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800963 } else {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700964 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800965 return WLAN_STATUS_SUCCESS;
966 sta->sae->sync++;
967
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800968 ret = auth_sae_send_confirm(hapd, sta, bssid);
969 sae_clear_temp_data(sta->sae);
970 if (ret)
971 return ret;
972 }
973 break;
974 default:
975 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
976 sta->sae->state);
977 return WLAN_STATUS_UNSPECIFIED_FAILURE;
978 }
979 return WLAN_STATUS_SUCCESS;
980}
981
982
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700983static void sae_pick_next_group(struct hostapd_data *hapd, struct sta_info *sta)
984{
985 struct sae_data *sae = sta->sae;
986 int i, *groups = hapd->conf->sae_groups;
Hai Shalom021b0b52019-04-10 11:17:58 -0700987 int default_groups[] = { 19, 0 };
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700988
989 if (sae->state != SAE_COMMITTED)
990 return;
991
992 wpa_printf(MSG_DEBUG, "SAE: Previously selected group: %d", sae->group);
993
Hai Shalom021b0b52019-04-10 11:17:58 -0700994 if (!groups)
995 groups = default_groups;
996 for (i = 0; groups[i] > 0; i++) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700997 if (sae->group == groups[i])
998 break;
999 }
1000
Hai Shalom021b0b52019-04-10 11:17:58 -07001001 if (groups[i] <= 0) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001002 wpa_printf(MSG_DEBUG,
1003 "SAE: Previously selected group not found from the current configuration");
1004 return;
1005 }
1006
1007 for (;;) {
1008 i++;
1009 if (groups[i] <= 0) {
1010 wpa_printf(MSG_DEBUG,
1011 "SAE: No alternative group enabled");
1012 return;
1013 }
1014
1015 if (sae_set_group(sae, groups[i]) < 0)
1016 continue;
1017
1018 break;
1019 }
1020 wpa_printf(MSG_DEBUG, "SAE: Selected new group: %d", groups[i]);
1021}
1022
1023
Hai Shalomc3565922019-10-28 11:58:20 -07001024static int sae_status_success(struct hostapd_data *hapd, u16 status_code)
1025{
1026 return (hapd->conf->sae_pwe == 0 &&
1027 status_code == WLAN_STATUS_SUCCESS) ||
1028 (hapd->conf->sae_pwe == 1 &&
1029 status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT) ||
1030 (hapd->conf->sae_pwe == 2 &&
1031 (status_code == WLAN_STATUS_SUCCESS ||
1032 status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT));
1033}
1034
1035
1036static int sae_is_group_enabled(struct hostapd_data *hapd, int group)
1037{
1038 int *groups = hapd->conf->sae_groups;
1039 int default_groups[] = { 19, 0 };
1040 int i;
1041
1042 if (!groups)
1043 groups = default_groups;
1044
1045 for (i = 0; groups[i] > 0; i++) {
1046 if (groups[i] == group)
1047 return 1;
1048 }
1049
1050 return 0;
1051}
1052
1053
1054static int check_sae_rejected_groups(struct hostapd_data *hapd,
1055 const struct wpabuf *groups)
1056{
1057 size_t i, count;
1058 const u8 *pos;
1059
1060 if (!groups)
1061 return 0;
1062
1063 pos = wpabuf_head(groups);
1064 count = wpabuf_len(groups) / 2;
1065 for (i = 0; i < count; i++) {
1066 int enabled;
1067 u16 group;
1068
1069 group = WPA_GET_LE16(pos);
1070 pos += 2;
1071 enabled = sae_is_group_enabled(hapd, group);
1072 wpa_printf(MSG_DEBUG, "SAE: Rejected group %u is %s",
1073 group, enabled ? "enabled" : "disabled");
1074 if (enabled)
1075 return 1;
1076 }
1077
1078 return 0;
1079}
1080
1081
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001082static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
1083 const struct ieee80211_mgmt *mgmt, size_t len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001084 u16 auth_transaction, u16 status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001085{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001086 int resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001087 struct wpabuf *data = NULL;
Hai Shalom021b0b52019-04-10 11:17:58 -07001088 int *groups = hapd->conf->sae_groups;
1089 int default_groups[] = { 19, 0 };
1090 const u8 *pos, *end;
Hai Shalom5f92bc92019-04-18 11:54:11 -07001091 int sta_removed = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -07001092
1093 if (!groups)
1094 groups = default_groups;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001095
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001096#ifdef CONFIG_TESTING_OPTIONS
1097 if (hapd->conf->sae_reflection_attack && auth_transaction == 1) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001098 wpa_printf(MSG_DEBUG, "SAE: TESTING - reflection attack");
1099 pos = mgmt->u.auth.variable;
1100 end = ((const u8 *) mgmt) + len;
1101 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001102 auth_transaction, resp, pos, end - pos,
1103 "auth-sae-reflection-attack");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001104 goto remove_sta;
1105 }
1106
1107 if (hapd->conf->sae_commit_override && auth_transaction == 1) {
1108 wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override");
1109 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
1110 auth_transaction, resp,
1111 wpabuf_head(hapd->conf->sae_commit_override),
Roshan Pius3a1667e2018-07-03 15:17:14 -07001112 wpabuf_len(hapd->conf->sae_commit_override),
1113 "sae-commit-override");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001114 goto remove_sta;
1115 }
1116#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001117 if (!sta->sae) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001118 if (auth_transaction != 1 ||
Hai Shalomc3565922019-10-28 11:58:20 -07001119 !sae_status_success(hapd, status_code)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001120 resp = -1;
1121 goto remove_sta;
1122 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001123 sta->sae = os_zalloc(sizeof(*sta->sae));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001124 if (!sta->sae) {
1125 resp = -1;
1126 goto remove_sta;
1127 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001128 sae_set_state(sta, SAE_NOTHING, "Init");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001129 sta->sae->sync = 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001130 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001131
Dmitry Shmidte4663042016-04-04 10:07:49 -07001132 if (sta->mesh_sae_pmksa_caching) {
1133 wpa_printf(MSG_DEBUG,
1134 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
1135 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
1136 sta->mesh_sae_pmksa_caching = 0;
1137 }
1138
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001139 if (auth_transaction == 1) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001140 const u8 *token = NULL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001141 size_t token_len = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -07001142 int allow_reuse = 0;
1143
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001144 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1145 HOSTAPD_LEVEL_DEBUG,
Hai Shalom81f62d82019-07-22 12:10:00 -07001146 "start SAE authentication (RX commit, status=%u (%s))",
1147 status_code, status2str(status_code));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001148
1149 if ((hapd->conf->mesh & MESH_ENABLED) &&
1150 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
1151 sta->sae->tmp) {
1152 pos = mgmt->u.auth.variable;
1153 end = ((const u8 *) mgmt) + len;
1154 if (pos + sizeof(le16) > end) {
1155 wpa_printf(MSG_ERROR,
1156 "SAE: Too short anti-clogging token request");
1157 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1158 goto reply;
1159 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001160 resp = sae_group_allowed(sta->sae, groups,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001161 WPA_GET_LE16(pos));
1162 if (resp != WLAN_STATUS_SUCCESS) {
1163 wpa_printf(MSG_ERROR,
1164 "SAE: Invalid group in anti-clogging token request");
1165 goto reply;
1166 }
1167 pos += sizeof(le16);
1168
1169 wpabuf_free(sta->sae->tmp->anti_clogging_token);
1170 sta->sae->tmp->anti_clogging_token =
1171 wpabuf_alloc_copy(pos, end - pos);
1172 if (sta->sae->tmp->anti_clogging_token == NULL) {
1173 wpa_printf(MSG_ERROR,
1174 "SAE: Failed to alloc for anti-clogging token");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001175 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1176 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001177 }
1178
1179 /*
1180 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
1181 * is 76, a new Commit Message shall be constructed
1182 * with the Anti-Clogging Token from the received
1183 * Authentication frame, and the commit-scalar and
1184 * COMMIT-ELEMENT previously sent.
1185 */
Hai Shalomc3565922019-10-28 11:58:20 -07001186 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0,
1187 status_code);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001188 if (resp != WLAN_STATUS_SUCCESS) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001189 wpa_printf(MSG_ERROR,
1190 "SAE: Failed to send commit message");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001191 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001192 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001193 sae_set_state(sta, SAE_COMMITTED,
1194 "Sent Commit (anti-clogging token case in mesh)");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001195 sta->sae->sync = 0;
1196 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001197 return;
1198 }
1199
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001200 if ((hapd->conf->mesh & MESH_ENABLED) &&
1201 status_code ==
1202 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
1203 sta->sae->tmp) {
1204 wpa_printf(MSG_DEBUG,
1205 "SAE: Peer did not accept our SAE group");
1206 sae_pick_next_group(hapd, sta);
1207 goto remove_sta;
1208 }
1209
Hai Shalomc3565922019-10-28 11:58:20 -07001210 if (!sae_status_success(hapd, status_code))
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001211 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001212
Roshan Pius3a1667e2018-07-03 15:17:14 -07001213 if (!(hapd->conf->mesh & MESH_ENABLED) &&
1214 sta->sae->state == SAE_COMMITTED) {
1215 /* This is needed in the infrastructure BSS case to
1216 * address a sequence where a STA entry may remain in
1217 * hostapd across two attempts to do SAE authentication
1218 * by the same STA. The second attempt may end up trying
1219 * to use a different group and that would not be
1220 * allowed if we remain in Committed state with the
1221 * previously set parameters. */
Hai Shalom021b0b52019-04-10 11:17:58 -07001222 pos = mgmt->u.auth.variable;
1223 end = ((const u8 *) mgmt) + len;
1224 if (end - pos >= (int) sizeof(le16) &&
1225 sae_group_allowed(sta->sae, groups,
1226 WPA_GET_LE16(pos)) ==
1227 WLAN_STATUS_SUCCESS) {
1228 /* Do not waste resources deriving the same PWE
1229 * again since the same group is reused. */
1230 sae_set_state(sta, SAE_NOTHING,
1231 "Allow previous PWE to be reused");
1232 allow_reuse = 1;
1233 } else {
1234 sae_set_state(sta, SAE_NOTHING,
1235 "Clear existing state to allow restart");
1236 sae_clear_data(sta->sae);
1237 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001238 }
1239
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001240 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
1241 ((const u8 *) mgmt) + len -
1242 mgmt->u.auth.variable, &token,
Hai Shalomc3565922019-10-28 11:58:20 -07001243 &token_len, groups, status_code ==
1244 WLAN_STATUS_SAE_HASH_TO_ELEMENT);
Dmitry Shmidt41712582015-06-29 11:02:15 -07001245 if (resp == SAE_SILENTLY_DISCARD) {
1246 wpa_printf(MSG_DEBUG,
1247 "SAE: Drop commit message from " MACSTR " due to reflection attack",
1248 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001249 goto remove_sta;
Dmitry Shmidt41712582015-06-29 11:02:15 -07001250 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001251
1252 if (resp == WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER) {
1253 wpa_msg(hapd->msg_ctx, MSG_INFO,
1254 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER
1255 MACSTR, MAC2STR(sta->addr));
1256 sae_clear_retransmit_timer(hapd, sta);
1257 sae_set_state(sta, SAE_NOTHING,
1258 "Unknown Password Identifier");
1259 goto remove_sta;
1260 }
1261
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001262 if (token && check_sae_token(hapd, sta->addr, token, token_len)
1263 < 0) {
1264 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
1265 "incorrect token from " MACSTR,
1266 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001267 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1268 goto remove_sta;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001269 }
1270
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001271 if (resp != WLAN_STATUS_SUCCESS)
1272 goto reply;
1273
Hai Shalomc3565922019-10-28 11:58:20 -07001274 if (sta->sae->tmp &&
1275 check_sae_rejected_groups(
1276 hapd, sta->sae->tmp->peer_rejected_groups) < 0) {
1277 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1278 goto remove_sta;
1279 }
1280
Hai Shalom021b0b52019-04-10 11:17:58 -07001281 if (!token && use_sae_anti_clogging(hapd) && !allow_reuse) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001282 wpa_printf(MSG_DEBUG,
1283 "SAE: Request anti-clogging token from "
1284 MACSTR, MAC2STR(sta->addr));
1285 data = auth_build_token_req(hapd, sta->sae->group,
1286 sta->addr);
1287 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
1288 if (hapd->conf->mesh & MESH_ENABLED)
Roshan Pius3a1667e2018-07-03 15:17:14 -07001289 sae_set_state(sta, SAE_NOTHING,
1290 "Request anti-clogging token case in mesh");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001291 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001292 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001293
Hai Shalom021b0b52019-04-10 11:17:58 -07001294 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction,
Hai Shalomc3565922019-10-28 11:58:20 -07001295 status_code, allow_reuse, &sta_removed);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001296 } else if (auth_transaction == 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001297 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1298 HOSTAPD_LEVEL_DEBUG,
Hai Shalom81f62d82019-07-22 12:10:00 -07001299 "SAE authentication (RX confirm, status=%u (%s))",
1300 status_code, status2str(status_code));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001301 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001302 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001303 if (sta->sae->state >= SAE_CONFIRMED ||
1304 !(hapd->conf->mesh & MESH_ENABLED)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001305 const u8 *var;
1306 size_t var_len;
1307 u16 peer_send_confirm;
1308
1309 var = mgmt->u.auth.variable;
1310 var_len = ((u8 *) mgmt) + len - mgmt->u.auth.variable;
1311 if (var_len < 2) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001312 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001313 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001314 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001315
1316 peer_send_confirm = WPA_GET_LE16(var);
1317
1318 if (sta->sae->state == SAE_ACCEPTED &&
1319 (peer_send_confirm <= sta->sae->rc ||
1320 peer_send_confirm == 0xffff)) {
1321 wpa_printf(MSG_DEBUG,
1322 "SAE: Silently ignore unexpected Confirm from peer "
1323 MACSTR
1324 " (peer-send-confirm=%u Rc=%u)",
1325 MAC2STR(sta->addr),
1326 peer_send_confirm, sta->sae->rc);
1327 return;
1328 }
1329
1330 if (sae_check_confirm(sta->sae, var, var_len) < 0) {
1331 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1332 goto reply;
1333 }
1334 sta->sae->rc = peer_send_confirm;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001335 }
Hai Shalomc3565922019-10-28 11:58:20 -07001336 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction,
1337 status_code, 0, &sta_removed);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001338 } else {
1339 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1340 HOSTAPD_LEVEL_DEBUG,
Hai Shalom81f62d82019-07-22 12:10:00 -07001341 "unexpected SAE authentication transaction %u (status=%u (%s))",
1342 auth_transaction, status_code,
1343 status2str(status_code));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001344 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001345 goto remove_sta;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001346 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1347 }
1348
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001349reply:
Hai Shalom5f92bc92019-04-18 11:54:11 -07001350 if (!sta_removed && resp != WLAN_STATUS_SUCCESS) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001351 pos = mgmt->u.auth.variable;
1352 end = ((const u8 *) mgmt) + len;
1353
1354 /* Copy the Finite Cyclic Group field from the request if we
1355 * rejected it as unsupported group. */
1356 if (resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
1357 !data && end - pos >= 2)
1358 data = wpabuf_alloc_copy(pos, 2);
1359
Hai Shalom5f92bc92019-04-18 11:54:11 -07001360 sae_sme_send_external_auth_status(hapd, sta, resp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001361 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
1362 auth_transaction, resp,
1363 data ? wpabuf_head(data) : (u8 *) "",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001364 data ? wpabuf_len(data) : 0, "auth-sae");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001365 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001366
1367remove_sta:
Hai Shalom5f92bc92019-04-18 11:54:11 -07001368 if (!sta_removed && sta->added_unassoc &&
1369 (resp != WLAN_STATUS_SUCCESS ||
1370 status_code != WLAN_STATUS_SUCCESS)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001371 hostapd_drv_sta_remove(hapd, sta->addr);
1372 sta->added_unassoc = 0;
1373 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001374 wpabuf_free(data);
1375}
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001376
1377
1378/**
1379 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1380 * @hapd: BSS data for the device initiating the authentication
1381 * @sta: the peer to which commit authentication frame is sent
1382 *
1383 * This function implements Init event handling (IEEE Std 802.11-2012,
1384 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1385 * sta->sae structure should be initialized appropriately via a call to
1386 * sae_prepare_commit().
1387 */
1388int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
1389{
1390 int ret;
1391
1392 if (!sta->sae || !sta->sae->tmp)
1393 return -1;
1394
1395 if (sta->sae->state != SAE_NOTHING)
1396 return -1;
1397
Hai Shalomc3565922019-10-28 11:58:20 -07001398 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0, -1);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001399 if (ret)
1400 return -1;
1401
Roshan Pius3a1667e2018-07-03 15:17:14 -07001402 sae_set_state(sta, SAE_COMMITTED, "Init and sent commit");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001403 sta->sae->sync = 0;
1404 sae_set_retransmit_timer(hapd, sta);
1405
1406 return 0;
1407}
1408
Hai Shalom021b0b52019-04-10 11:17:58 -07001409
1410void auth_sae_process_commit(void *eloop_ctx, void *user_ctx)
1411{
1412 struct hostapd_data *hapd = eloop_ctx;
1413 struct hostapd_sae_commit_queue *q;
1414 unsigned int queue_len;
1415
1416 q = dl_list_first(&hapd->sae_commit_queue,
1417 struct hostapd_sae_commit_queue, list);
1418 if (!q)
1419 return;
1420 wpa_printf(MSG_DEBUG,
1421 "SAE: Process next available message from queue");
1422 dl_list_del(&q->list);
1423 handle_auth(hapd, (const struct ieee80211_mgmt *) q->msg, q->len,
1424 q->rssi, 1);
1425 os_free(q);
1426
1427 if (eloop_is_timeout_registered(auth_sae_process_commit, hapd, NULL))
1428 return;
1429 queue_len = dl_list_len(&hapd->sae_commit_queue);
1430 eloop_register_timeout(0, queue_len * 10000, auth_sae_process_commit,
1431 hapd, NULL);
1432}
1433
1434
1435static void auth_sae_queue(struct hostapd_data *hapd,
1436 const struct ieee80211_mgmt *mgmt, size_t len,
1437 int rssi)
1438{
1439 struct hostapd_sae_commit_queue *q, *q2;
1440 unsigned int queue_len;
1441 const struct ieee80211_mgmt *mgmt2;
1442
1443 queue_len = dl_list_len(&hapd->sae_commit_queue);
1444 if (queue_len >= 15) {
1445 wpa_printf(MSG_DEBUG,
1446 "SAE: No more room in message queue - drop the new frame from "
1447 MACSTR, MAC2STR(mgmt->sa));
1448 return;
1449 }
1450
1451 wpa_printf(MSG_DEBUG, "SAE: Queue Authentication message from "
1452 MACSTR " for processing (queue_len %u)", MAC2STR(mgmt->sa),
1453 queue_len);
1454 q = os_zalloc(sizeof(*q) + len);
1455 if (!q)
1456 return;
1457 q->rssi = rssi;
1458 q->len = len;
1459 os_memcpy(q->msg, mgmt, len);
1460
1461 /* Check whether there is already a queued Authentication frame from the
1462 * same station with the same transaction number and if so, replace that
1463 * queue entry with the new one. This avoids issues with a peer that
1464 * sends multiple times (e.g., due to frequent SAE retries). There is no
1465 * point in us trying to process the old attempts after a new one has
1466 * obsoleted them. */
1467 dl_list_for_each(q2, &hapd->sae_commit_queue,
1468 struct hostapd_sae_commit_queue, list) {
1469 mgmt2 = (const struct ieee80211_mgmt *) q2->msg;
1470 if (os_memcmp(mgmt->sa, mgmt2->sa, ETH_ALEN) == 0 &&
1471 mgmt->u.auth.auth_transaction ==
1472 mgmt2->u.auth.auth_transaction) {
1473 wpa_printf(MSG_DEBUG,
1474 "SAE: Replace queued message from same STA with same transaction number");
1475 dl_list_add(&q2->list, &q->list);
1476 dl_list_del(&q2->list);
1477 os_free(q2);
1478 goto queued;
1479 }
1480 }
1481
1482 /* No pending identical entry, so add to the end of the queue */
1483 dl_list_add_tail(&hapd->sae_commit_queue, &q->list);
1484
1485queued:
1486 if (eloop_is_timeout_registered(auth_sae_process_commit, hapd, NULL))
1487 return;
1488 eloop_register_timeout(0, queue_len * 10000, auth_sae_process_commit,
1489 hapd, NULL);
1490}
1491
1492
1493static int auth_sae_queued_addr(struct hostapd_data *hapd, const u8 *addr)
1494{
1495 struct hostapd_sae_commit_queue *q;
1496 const struct ieee80211_mgmt *mgmt;
1497
1498 dl_list_for_each(q, &hapd->sae_commit_queue,
1499 struct hostapd_sae_commit_queue, list) {
1500 mgmt = (const struct ieee80211_mgmt *) q->msg;
1501 if (os_memcmp(addr, mgmt->sa, ETH_ALEN) == 0)
1502 return 1;
1503 }
1504
1505 return 0;
1506}
1507
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001508#endif /* CONFIG_SAE */
1509
1510
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001511static u16 wpa_res_to_status_code(int res)
1512{
1513 if (res == WPA_INVALID_GROUP)
1514 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1515 if (res == WPA_INVALID_PAIRWISE)
1516 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1517 if (res == WPA_INVALID_AKMP)
1518 return WLAN_STATUS_AKMP_NOT_VALID;
1519 if (res == WPA_ALLOC_FAIL)
1520 return WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001521 if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1522 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1523 if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
Roshan Pius3a1667e2018-07-03 15:17:14 -07001524 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001525 if (res == WPA_INVALID_MDIE)
1526 return WLAN_STATUS_INVALID_MDIE;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001527 if (res == WPA_INVALID_PMKID)
1528 return WLAN_STATUS_INVALID_PMKID;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001529 if (res != WPA_IE_OK)
1530 return WLAN_STATUS_INVALID_IE;
1531 return WLAN_STATUS_SUCCESS;
1532}
1533
1534
1535#ifdef CONFIG_FILS
1536
1537static void handle_auth_fils_finish(struct hostapd_data *hapd,
1538 struct sta_info *sta, u16 resp,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001539 struct wpabuf *data, int pub);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001540
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001541void handle_auth_fils(struct hostapd_data *hapd, struct sta_info *sta,
1542 const u8 *pos, size_t len, u16 auth_alg,
1543 u16 auth_transaction, u16 status_code,
1544 void (*cb)(struct hostapd_data *hapd,
1545 struct sta_info *sta, u16 resp,
1546 struct wpabuf *data, int pub))
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001547{
1548 u16 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001549 const u8 *end;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001550 struct ieee802_11_elems elems;
1551 int res;
1552 struct wpa_ie_data rsn;
1553 struct rsn_pmksa_cache_entry *pmksa = NULL;
1554
1555 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
1556 return;
1557
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001558 end = pos + len;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001559
1560 wpa_hexdump(MSG_DEBUG, "FILS: Authentication frame fields",
1561 pos, end - pos);
1562
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001563 /* TODO: FILS PK */
1564#ifdef CONFIG_FILS_SK_PFS
1565 if (auth_alg == WLAN_AUTH_FILS_SK_PFS) {
1566 u16 group;
1567 struct wpabuf *pub;
1568 size_t elem_len;
1569
1570 /* Using FILS PFS */
1571
1572 /* Finite Cyclic Group */
1573 if (end - pos < 2) {
1574 wpa_printf(MSG_DEBUG,
1575 "FILS: No room for Finite Cyclic Group");
1576 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1577 goto fail;
1578 }
1579 group = WPA_GET_LE16(pos);
1580 pos += 2;
1581 if (group != hapd->conf->fils_dh_group) {
1582 wpa_printf(MSG_DEBUG,
1583 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1584 group, hapd->conf->fils_dh_group);
1585 resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
1586 goto fail;
1587 }
1588
1589 crypto_ecdh_deinit(sta->fils_ecdh);
1590 sta->fils_ecdh = crypto_ecdh_init(group);
1591 if (!sta->fils_ecdh) {
1592 wpa_printf(MSG_INFO,
1593 "FILS: Could not initialize ECDH with group %d",
1594 group);
1595 resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
1596 goto fail;
1597 }
1598
1599 pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
1600 if (!pub) {
1601 wpa_printf(MSG_DEBUG,
1602 "FILS: Failed to derive ECDH public key");
1603 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1604 goto fail;
1605 }
1606 elem_len = wpabuf_len(pub);
1607 wpabuf_free(pub);
1608
1609 /* Element */
1610 if ((size_t) (end - pos) < elem_len) {
1611 wpa_printf(MSG_DEBUG, "FILS: No room for Element");
1612 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1613 goto fail;
1614 }
1615
1616 wpabuf_free(sta->fils_g_sta);
1617 sta->fils_g_sta = wpabuf_alloc_copy(pos, elem_len);
1618 wpabuf_clear_free(sta->fils_dh_ss);
1619 sta->fils_dh_ss = crypto_ecdh_set_peerkey(sta->fils_ecdh, 1,
1620 pos, elem_len);
1621 if (!sta->fils_dh_ss) {
1622 wpa_printf(MSG_DEBUG, "FILS: ECDH operation failed");
1623 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1624 goto fail;
1625 }
1626 wpa_hexdump_buf_key(MSG_DEBUG, "FILS: DH_SS", sta->fils_dh_ss);
1627 pos += elem_len;
1628 } else {
1629 crypto_ecdh_deinit(sta->fils_ecdh);
1630 sta->fils_ecdh = NULL;
1631 wpabuf_clear_free(sta->fils_dh_ss);
1632 sta->fils_dh_ss = NULL;
1633 }
1634#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001635
1636 wpa_hexdump(MSG_DEBUG, "FILS: Remaining IEs", pos, end - pos);
1637 if (ieee802_11_parse_elems(pos, end - pos, &elems, 1) == ParseFailed) {
1638 wpa_printf(MSG_DEBUG, "FILS: Could not parse elements");
1639 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1640 goto fail;
1641 }
1642
1643 /* RSNE */
1644 wpa_hexdump(MSG_DEBUG, "FILS: RSN element",
1645 elems.rsn_ie, elems.rsn_ie_len);
1646 if (!elems.rsn_ie ||
1647 wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2,
1648 &rsn) < 0) {
1649 wpa_printf(MSG_DEBUG, "FILS: No valid RSN element");
1650 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1651 goto fail;
1652 }
1653
1654 if (!sta->wpa_sm)
1655 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr,
1656 NULL);
1657 if (!sta->wpa_sm) {
1658 wpa_printf(MSG_DEBUG,
1659 "FILS: Failed to initialize RSN state machine");
1660 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1661 goto fail;
1662 }
1663
1664 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -07001665 hapd->iface->freq,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001666 elems.rsn_ie - 2, elems.rsn_ie_len + 2,
Hai Shalomc3565922019-10-28 11:58:20 -07001667 elems.rsnxe ? elems.rsnxe - 2 : NULL,
1668 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001669 elems.mdie, elems.mdie_len, NULL, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001670 resp = wpa_res_to_status_code(res);
1671 if (resp != WLAN_STATUS_SUCCESS)
1672 goto fail;
1673
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001674 if (!elems.fils_nonce) {
1675 wpa_printf(MSG_DEBUG, "FILS: No FILS Nonce field");
1676 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1677 goto fail;
1678 }
1679 wpa_hexdump(MSG_DEBUG, "FILS: SNonce", elems.fils_nonce,
1680 FILS_NONCE_LEN);
1681 os_memcpy(sta->fils_snonce, elems.fils_nonce, FILS_NONCE_LEN);
1682
1683 /* PMKID List */
1684 if (rsn.pmkid && rsn.num_pmkid > 0) {
1685 u8 num;
1686 const u8 *pmkid;
1687
1688 wpa_hexdump(MSG_DEBUG, "FILS: PMKID List",
1689 rsn.pmkid, rsn.num_pmkid * PMKID_LEN);
1690
1691 pmkid = rsn.pmkid;
1692 num = rsn.num_pmkid;
1693 while (num) {
1694 wpa_hexdump(MSG_DEBUG, "FILS: PMKID", pmkid, PMKID_LEN);
1695 pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr,
1696 pmkid);
1697 if (pmksa)
1698 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001699 pmksa = wpa_auth_pmksa_get_fils_cache_id(hapd->wpa_auth,
1700 sta->addr,
1701 pmkid);
1702 if (pmksa)
1703 break;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001704 pmkid += PMKID_LEN;
1705 num--;
1706 }
1707 }
1708 if (pmksa && wpa_auth_sta_key_mgmt(sta->wpa_sm) != pmksa->akmp) {
1709 wpa_printf(MSG_DEBUG,
1710 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1711 wpa_auth_sta_key_mgmt(sta->wpa_sm), pmksa->akmp);
1712 pmksa = NULL;
1713 }
1714 if (pmksa)
1715 wpa_printf(MSG_DEBUG, "FILS: Found matching PMKSA cache entry");
1716
1717 /* FILS Session */
1718 if (!elems.fils_session) {
1719 wpa_printf(MSG_DEBUG, "FILS: No FILS Session element");
1720 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1721 goto fail;
1722 }
1723 wpa_hexdump(MSG_DEBUG, "FILS: FILS Session", elems.fils_session,
1724 FILS_SESSION_LEN);
1725 os_memcpy(sta->fils_session, elems.fils_session, FILS_SESSION_LEN);
1726
1727 /* FILS Wrapped Data */
1728 if (elems.fils_wrapped_data) {
1729 wpa_hexdump(MSG_DEBUG, "FILS: Wrapped Data",
1730 elems.fils_wrapped_data,
1731 elems.fils_wrapped_data_len);
1732 if (!pmksa) {
1733#ifndef CONFIG_NO_RADIUS
1734 if (!sta->eapol_sm) {
1735 sta->eapol_sm =
1736 ieee802_1x_alloc_eapol_sm(hapd, sta);
1737 }
1738 wpa_printf(MSG_DEBUG,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001739 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001740 ieee802_1x_encapsulate_radius(
1741 hapd, sta, elems.fils_wrapped_data,
1742 elems.fils_wrapped_data_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001743 sta->fils_pending_cb = cb;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001744 wpa_printf(MSG_DEBUG,
1745 "FILS: Will send Authentication frame once the response from authentication server is available");
1746 sta->flags |= WLAN_STA_PENDING_FILS_ERP;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001747 /* Calculate pending PMKID here so that we do not need
1748 * to maintain a copy of the EAP-Initiate/Reauth
1749 * message. */
1750 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta->wpa_sm),
1751 elems.fils_wrapped_data,
1752 elems.fils_wrapped_data_len,
1753 sta->fils_erp_pmkid) == 0)
1754 sta->fils_erp_pmkid_set = 1;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001755 return;
1756#else /* CONFIG_NO_RADIUS */
1757 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1758 goto fail;
1759#endif /* CONFIG_NO_RADIUS */
1760 }
1761 }
1762
1763fail:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001764 if (cb) {
1765 struct wpabuf *data;
1766 int pub = 0;
1767
1768 data = prepare_auth_resp_fils(hapd, sta, &resp, pmksa, NULL,
1769 NULL, 0, &pub);
1770 if (!data) {
1771 wpa_printf(MSG_DEBUG,
1772 "%s: prepare_auth_resp_fils() returned failure",
1773 __func__);
1774 }
1775
1776 cb(hapd, sta, resp, data, pub);
1777 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001778}
1779
1780
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001781static struct wpabuf *
1782prepare_auth_resp_fils(struct hostapd_data *hapd,
1783 struct sta_info *sta, u16 *resp,
1784 struct rsn_pmksa_cache_entry *pmksa,
1785 struct wpabuf *erp_resp,
1786 const u8 *msk, size_t msk_len,
1787 int *is_pub)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001788{
1789 u8 fils_nonce[FILS_NONCE_LEN];
1790 size_t ielen;
1791 struct wpabuf *data = NULL;
1792 const u8 *ie;
1793 u8 *ie_buf = NULL;
1794 const u8 *pmk = NULL;
1795 size_t pmk_len = 0;
Paul Stewart092955c2017-02-06 09:13:09 -08001796 u8 pmk_buf[PMK_LEN_MAX];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001797 struct wpabuf *pub = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001798
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001799 if (*resp != WLAN_STATUS_SUCCESS)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001800 goto fail;
1801
1802 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
1803 if (!ie) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001804 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001805 goto fail;
1806 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001807
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001808 if (pmksa) {
1809 /* Add PMKID of the selected PMKSA into RSNE */
1810 ie_buf = os_malloc(ielen + 2 + 2 + PMKID_LEN);
1811 if (!ie_buf) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001812 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001813 goto fail;
1814 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001815
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001816 os_memcpy(ie_buf, ie, ielen);
1817 if (wpa_insert_pmkid(ie_buf, &ielen, pmksa->pmkid) < 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001818 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001819 goto fail;
1820 }
1821 ie = ie_buf;
1822 }
1823
1824 if (random_get_bytes(fils_nonce, FILS_NONCE_LEN) < 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001825 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001826 goto fail;
1827 }
1828 wpa_hexdump(MSG_DEBUG, "RSN: Generated FILS Nonce",
1829 fils_nonce, FILS_NONCE_LEN);
1830
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001831#ifdef CONFIG_FILS_SK_PFS
1832 if (sta->fils_dh_ss && sta->fils_ecdh) {
1833 pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
1834 if (!pub) {
1835 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1836 goto fail;
1837 }
1838 }
1839#endif /* CONFIG_FILS_SK_PFS */
1840
1841 data = wpabuf_alloc(1000 + ielen + (pub ? wpabuf_len(pub) : 0));
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001842 if (!data) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001843 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001844 goto fail;
1845 }
1846
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001847 /* TODO: FILS PK */
1848#ifdef CONFIG_FILS_SK_PFS
1849 if (pub) {
1850 /* Finite Cyclic Group */
1851 wpabuf_put_le16(data, hapd->conf->fils_dh_group);
1852
1853 /* Element */
1854 wpabuf_put_buf(data, pub);
1855 }
1856#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001857
1858 /* RSNE */
1859 wpabuf_put_data(data, ie, ielen);
1860
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001861 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1862
1863#ifdef CONFIG_IEEE80211R_AP
1864 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm))) {
1865 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1866 int res;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001867 int use_sha384 = wpa_key_mgmt_sha384(
1868 wpa_auth_sta_key_mgmt(sta->wpa_sm));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001869
Roshan Pius3a1667e2018-07-03 15:17:14 -07001870 res = wpa_auth_write_fte(hapd->wpa_auth, use_sha384,
1871 wpabuf_put(data, 0),
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001872 wpabuf_tailroom(data));
1873 if (res < 0) {
1874 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1875 goto fail;
1876 }
1877 wpabuf_put(data, res);
1878 }
1879#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001880
1881 /* FILS Nonce */
1882 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1883 wpabuf_put_u8(data, 1 + FILS_NONCE_LEN); /* Length */
1884 /* Element ID Extension */
1885 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_NONCE);
1886 wpabuf_put_data(data, fils_nonce, FILS_NONCE_LEN);
1887
1888 /* FILS Session */
1889 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1890 wpabuf_put_u8(data, 1 + FILS_SESSION_LEN); /* Length */
1891 /* Element ID Extension */
1892 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_SESSION);
1893 wpabuf_put_data(data, sta->fils_session, FILS_SESSION_LEN);
1894
1895 /* FILS Wrapped Data */
1896 if (!pmksa && erp_resp) {
1897 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1898 wpabuf_put_u8(data, 1 + wpabuf_len(erp_resp)); /* Length */
1899 /* Element ID Extension */
1900 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_WRAPPED_DATA);
1901 wpabuf_put_buf(data, erp_resp);
1902
Paul Stewart092955c2017-02-06 09:13:09 -08001903 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta->wpa_sm),
1904 msk, msk_len, sta->fils_snonce, fils_nonce,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001905 sta->fils_dh_ss ?
1906 wpabuf_head(sta->fils_dh_ss) : NULL,
1907 sta->fils_dh_ss ?
1908 wpabuf_len(sta->fils_dh_ss) : 0,
1909 pmk_buf, &pmk_len)) {
Paul Stewart092955c2017-02-06 09:13:09 -08001910 wpa_printf(MSG_DEBUG, "FILS: Failed to derive PMK");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001911 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Paul Stewart092955c2017-02-06 09:13:09 -08001912 wpabuf_free(data);
1913 data = NULL;
1914 goto fail;
1915 }
1916 pmk = pmk_buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001917
1918 /* Don't use DHss in PTK derivation if PMKSA caching is not
1919 * used. */
1920 wpabuf_clear_free(sta->fils_dh_ss);
1921 sta->fils_dh_ss = NULL;
1922
1923 if (sta->fils_erp_pmkid_set) {
1924 /* TODO: get PMKLifetime from WPA parameters */
1925 unsigned int dot11RSNAConfigPMKLifetime = 43200;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001926 int session_timeout;
1927
1928 session_timeout = dot11RSNAConfigPMKLifetime;
1929 if (sta->session_timeout_set) {
1930 struct os_reltime now, diff;
1931
1932 os_get_reltime(&now);
1933 os_reltime_sub(&sta->session_timeout, &now,
1934 &diff);
1935 session_timeout = diff.sec;
1936 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001937
1938 sta->fils_erp_pmkid_set = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -07001939 wpa_auth_add_fils_pmk_pmkid(sta->wpa_sm, pmk, pmk_len,
1940 sta->fils_erp_pmkid);
Hai Shalom021b0b52019-04-10 11:17:58 -07001941 if (!hapd->conf->disable_pmksa_caching &&
1942 wpa_auth_pmksa_add2(
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001943 hapd->wpa_auth, sta->addr,
1944 pmk, pmk_len,
1945 sta->fils_erp_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001946 session_timeout,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001947 wpa_auth_sta_key_mgmt(sta->wpa_sm)) < 0) {
1948 wpa_printf(MSG_ERROR,
1949 "FILS: Failed to add PMKSA cache entry based on ERP");
1950 }
1951 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001952 } else if (pmksa) {
1953 pmk = pmksa->pmk;
1954 pmk_len = pmksa->pmk_len;
1955 }
1956
1957 if (!pmk) {
1958 wpa_printf(MSG_DEBUG, "FILS: No PMK available");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001959 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001960 wpabuf_free(data);
1961 data = NULL;
1962 goto fail;
1963 }
1964
1965 if (fils_auth_pmk_to_ptk(sta->wpa_sm, pmk, pmk_len,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001966 sta->fils_snonce, fils_nonce,
1967 sta->fils_dh_ss ?
1968 wpabuf_head(sta->fils_dh_ss) : NULL,
1969 sta->fils_dh_ss ?
1970 wpabuf_len(sta->fils_dh_ss) : 0,
1971 sta->fils_g_sta, pub) < 0) {
1972 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001973 wpabuf_free(data);
1974 data = NULL;
1975 goto fail;
1976 }
1977
1978fail:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001979 if (is_pub)
1980 *is_pub = pub != NULL;
1981 os_free(ie_buf);
1982 wpabuf_free(pub);
1983 wpabuf_clear_free(sta->fils_dh_ss);
1984 sta->fils_dh_ss = NULL;
1985#ifdef CONFIG_FILS_SK_PFS
1986 crypto_ecdh_deinit(sta->fils_ecdh);
1987 sta->fils_ecdh = NULL;
1988#endif /* CONFIG_FILS_SK_PFS */
1989 return data;
1990}
1991
1992
1993static void handle_auth_fils_finish(struct hostapd_data *hapd,
1994 struct sta_info *sta, u16 resp,
1995 struct wpabuf *data, int pub)
1996{
1997 u16 auth_alg;
1998
1999 auth_alg = (pub ||
2000 resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) ?
2001 WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
2002 send_auth_reply(hapd, sta->addr, hapd->own_addr, auth_alg, 2, resp,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002003 data ? wpabuf_head(data) : (u8 *) "",
Roshan Pius3a1667e2018-07-03 15:17:14 -07002004 data ? wpabuf_len(data) : 0, "auth-fils-finish");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002005 wpabuf_free(data);
2006
2007 if (resp == WLAN_STATUS_SUCCESS) {
2008 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2009 HOSTAPD_LEVEL_DEBUG,
2010 "authentication OK (FILS)");
2011 sta->flags |= WLAN_STA_AUTH;
2012 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002013 sta->auth_alg = pub ? WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002014 mlme_authenticate_indication(hapd, sta);
2015 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002016}
2017
2018
2019void ieee802_11_finish_fils_auth(struct hostapd_data *hapd,
2020 struct sta_info *sta, int success,
2021 struct wpabuf *erp_resp,
2022 const u8 *msk, size_t msk_len)
2023{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002024 struct wpabuf *data;
2025 int pub = 0;
2026 u16 resp;
2027
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002028 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002029
2030 if (!sta->fils_pending_cb)
2031 return;
2032 resp = success ? WLAN_STATUS_SUCCESS : WLAN_STATUS_UNSPECIFIED_FAILURE;
2033 data = prepare_auth_resp_fils(hapd, sta, &resp, NULL, erp_resp,
2034 msk, msk_len, &pub);
2035 if (!data) {
2036 wpa_printf(MSG_DEBUG,
2037 "%s: prepare_auth_resp_fils() returned failure",
2038 __func__);
2039 }
2040 sta->fils_pending_cb(hapd, sta, resp, data, pub);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002041}
2042
2043#endif /* CONFIG_FILS */
2044
2045
Roshan Pius3a1667e2018-07-03 15:17:14 -07002046int
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002047ieee802_11_allowed_address(struct hostapd_data *hapd, const u8 *addr,
2048 const u8 *msg, size_t len, u32 *session_timeout,
2049 u32 *acct_interim_interval,
2050 struct vlan_description *vlan_id,
2051 struct hostapd_sta_wpa_psk_short **psk,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002052 char **identity, char **radius_cui, int is_probe_req)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002053{
2054 int res;
2055
2056 os_memset(vlan_id, 0, sizeof(*vlan_id));
2057 res = hostapd_allowed_address(hapd, addr, msg, len,
2058 session_timeout, acct_interim_interval,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002059 vlan_id, psk, identity, radius_cui,
2060 is_probe_req);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002061
2062 if (res == HOSTAPD_ACL_REJECT) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002063 if (!is_probe_req)
2064 wpa_printf(MSG_DEBUG,
2065 "Station " MACSTR
2066 " not allowed to authenticate",
2067 MAC2STR(addr));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002068 return HOSTAPD_ACL_REJECT;
2069 }
2070
2071 if (res == HOSTAPD_ACL_PENDING) {
2072 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
2073 " waiting for an external authentication",
2074 MAC2STR(addr));
2075 /* Authentication code will re-send the authentication frame
2076 * after it has received (and cached) information from the
2077 * external source. */
2078 return HOSTAPD_ACL_PENDING;
2079 }
2080
2081 return res;
2082}
2083
2084
2085static int
2086ieee802_11_set_radius_info(struct hostapd_data *hapd, struct sta_info *sta,
2087 int res, u32 session_timeout,
2088 u32 acct_interim_interval,
2089 struct vlan_description *vlan_id,
2090 struct hostapd_sta_wpa_psk_short **psk,
2091 char **identity, char **radius_cui)
2092{
2093 if (vlan_id->notempty &&
2094 !hostapd_vlan_valid(hapd->conf->vlan, vlan_id)) {
2095 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
2096 HOSTAPD_LEVEL_INFO,
2097 "Invalid VLAN %d%s received from RADIUS server",
2098 vlan_id->untagged,
2099 vlan_id->tagged[0] ? "+" : "");
2100 return -1;
2101 }
2102 if (ap_sta_set_vlan(hapd, sta, vlan_id) < 0)
2103 return -1;
2104 if (sta->vlan_id)
2105 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
2106 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
2107
2108 hostapd_free_psk_list(sta->psk);
2109 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
2110 sta->psk = *psk;
2111 *psk = NULL;
2112 } else {
2113 sta->psk = NULL;
2114 }
2115
Roshan Pius3a1667e2018-07-03 15:17:14 -07002116 os_free(sta->identity);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002117 sta->identity = *identity;
2118 *identity = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002119
2120 os_free(sta->radius_cui);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002121 sta->radius_cui = *radius_cui;
2122 *radius_cui = NULL;
2123
2124 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
2125 sta->acct_interim_interval = acct_interim_interval;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002126 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT) {
2127 sta->session_timeout_set = 1;
2128 os_get_reltime(&sta->session_timeout);
2129 sta->session_timeout.sec += session_timeout;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002130 ap_sta_session_timeout(hapd, sta, session_timeout);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002131 } else {
2132 sta->session_timeout_set = 0;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002133 ap_sta_no_session_timeout(hapd, sta);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002134 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002135
2136 return 0;
2137}
2138
2139
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002140static void handle_auth(struct hostapd_data *hapd,
Hai Shalom74f70d42019-02-11 14:42:39 -08002141 const struct ieee80211_mgmt *mgmt, size_t len,
Hai Shalom021b0b52019-04-10 11:17:58 -07002142 int rssi, int from_queue)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002143{
2144 u16 auth_alg, auth_transaction, status_code;
2145 u16 resp = WLAN_STATUS_SUCCESS;
2146 struct sta_info *sta = NULL;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002147 int res, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002148 u16 fc;
2149 const u8 *challenge = NULL;
2150 u32 session_timeout, acct_interim_interval;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002151 struct vlan_description vlan_id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002152 struct hostapd_sta_wpa_psk_short *psk = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002153 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
2154 size_t resp_ies_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002155 char *identity = NULL;
2156 char *radius_cui = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002157 u16 seq_ctrl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002158
2159 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002160 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
2161 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162 return;
2163 }
2164
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002165#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002166 if (hapd->iconf->ignore_auth_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002167 drand48() < hapd->iconf->ignore_auth_probability) {
2168 wpa_printf(MSG_INFO,
2169 "TESTING: ignoring auth frame from " MACSTR,
2170 MAC2STR(mgmt->sa));
2171 return;
2172 }
2173#endif /* CONFIG_TESTING_OPTIONS */
2174
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002175 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2176 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2177 status_code = le_to_host16(mgmt->u.auth.status_code);
2178 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002179 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002180
2181 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
2182 2 + WLAN_AUTH_CHALLENGE_LEN &&
2183 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
2184 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
2185 challenge = &mgmt->u.auth.variable[2];
2186
2187 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002188 "auth_transaction=%d status_code=%d wep=%d%s "
Hai Shalom021b0b52019-04-10 11:17:58 -07002189 "seq_ctrl=0x%x%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002190 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
2191 status_code, !!(fc & WLAN_FC_ISWEP),
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002192 challenge ? " challenge" : "",
Hai Shalom021b0b52019-04-10 11:17:58 -07002193 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "",
2194 from_queue ? " (from queue)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002195
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002196#ifdef CONFIG_NO_RC4
2197 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
2198 wpa_printf(MSG_INFO,
2199 "Unsupported authentication algorithm (%d)",
2200 auth_alg);
2201 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
2202 goto fail;
2203 }
2204#endif /* CONFIG_NO_RC4 */
2205
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002206 if (hapd->tkip_countermeasures) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002207 wpa_printf(MSG_DEBUG,
2208 "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication");
2209 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002210 goto fail;
2211 }
2212
2213 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
2214 auth_alg == WLAN_AUTH_OPEN) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002215#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002216 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217 auth_alg == WLAN_AUTH_FT) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002218#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002219#ifdef CONFIG_SAE
2220 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
2221 auth_alg == WLAN_AUTH_SAE) ||
2222#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002223#ifdef CONFIG_FILS
2224 (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
2225 auth_alg == WLAN_AUTH_FILS_SK) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002226 (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
2227 hapd->conf->fils_dh_group &&
2228 auth_alg == WLAN_AUTH_FILS_SK_PFS) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002229#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002230 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
2231 auth_alg == WLAN_AUTH_SHARED_KEY))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002232 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
2233 auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
2235 goto fail;
2236 }
2237
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002238 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002240 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
2241 auth_transaction);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
2243 goto fail;
2244 }
2245
2246 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002247 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
2248 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002249 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2250 goto fail;
2251 }
2252
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002253 if (hapd->conf->no_auth_if_seen_on) {
2254 struct hostapd_data *other;
2255
2256 other = sta_track_seen_on(hapd->iface, mgmt->sa,
2257 hapd->conf->no_auth_if_seen_on);
2258 if (other) {
2259 u8 *pos;
2260 u32 info;
2261 u8 op_class, channel, phytype;
2262
2263 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
2264 MACSTR " since STA has been seen on %s",
2265 hapd->conf->iface, MAC2STR(mgmt->sa),
2266 hapd->conf->no_auth_if_seen_on);
2267
2268 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
2269 pos = &resp_ies[0];
2270 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
2271 *pos++ = 13;
2272 os_memcpy(pos, other->own_addr, ETH_ALEN);
2273 pos += ETH_ALEN;
2274 info = 0; /* TODO: BSSID Information */
2275 WPA_PUT_LE32(pos, info);
2276 pos += 4;
2277 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
2278 phytype = 8; /* dmg */
2279 else if (other->iconf->ieee80211ac)
2280 phytype = 9; /* vht */
2281 else if (other->iconf->ieee80211n)
2282 phytype = 7; /* ht */
2283 else if (other->iconf->hw_mode ==
2284 HOSTAPD_MODE_IEEE80211A)
2285 phytype = 4; /* ofdm */
2286 else if (other->iconf->hw_mode ==
2287 HOSTAPD_MODE_IEEE80211G)
2288 phytype = 6; /* erp */
2289 else
2290 phytype = 5; /* hrdsss */
2291 if (ieee80211_freq_to_channel_ext(
2292 hostapd_hw_get_freq(other,
2293 other->iconf->channel),
2294 other->iconf->secondary_channel,
2295 other->iconf->ieee80211ac,
2296 &op_class, &channel) == NUM_HOSTAPD_MODES) {
2297 op_class = 0;
2298 channel = other->iconf->channel;
2299 }
2300 *pos++ = op_class;
2301 *pos++ = channel;
2302 *pos++ = phytype;
2303 resp_ies_len = pos - &resp_ies[0];
2304 goto fail;
2305 }
2306 }
2307
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002308 res = ieee802_11_allowed_address(
2309 hapd, mgmt->sa, (const u8 *) mgmt, len, &session_timeout,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002310 &acct_interim_interval, &vlan_id, &psk, &identity, &radius_cui,
2311 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002312 if (res == HOSTAPD_ACL_REJECT) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002313 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
2314 "Ignore Authentication frame from " MACSTR
2315 " due to ACL reject", MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002316 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2317 goto fail;
2318 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002319 if (res == HOSTAPD_ACL_PENDING)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002320 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002321
Hai Shalom021b0b52019-04-10 11:17:58 -07002322#ifdef CONFIG_SAE
2323 if (auth_alg == WLAN_AUTH_SAE && !from_queue &&
2324 (auth_transaction == 1 ||
2325 (auth_transaction == 2 && auth_sae_queued_addr(hapd, mgmt->sa)))) {
2326 /* Handle SAE Authentication commit message through a queue to
2327 * provide more control for postponing the needed heavy
2328 * processing under a possible DoS attack scenario. In addition,
2329 * queue SAE Authentication confirm message if there happens to
2330 * be a queued commit message from the same peer. This is needed
2331 * to avoid reordering Authentication frames within the same
2332 * SAE exchange. */
2333 auth_sae_queue(hapd, mgmt, len, rssi);
2334 return;
2335 }
2336#endif /* CONFIG_SAE */
2337
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002338 sta = ap_get_sta(hapd, mgmt->sa);
2339 if (sta) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002340 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
Hai Shalom74f70d42019-02-11 14:42:39 -08002341 sta->ft_over_ds = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002342 if ((fc & WLAN_FC_RETRY) &&
2343 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2344 sta->last_seq_ctrl == seq_ctrl &&
2345 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
2346 hostapd_logger(hapd, sta->addr,
2347 HOSTAPD_MODULE_IEEE80211,
2348 HOSTAPD_LEVEL_DEBUG,
2349 "Drop repeated authentication frame seq_ctrl=0x%x",
2350 seq_ctrl);
2351 return;
2352 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002353#ifdef CONFIG_MESH
2354 if ((hapd->conf->mesh & MESH_ENABLED) &&
2355 sta->plink_state == PLINK_BLOCKED) {
2356 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
2357 " is blocked - drop Authentication frame",
2358 MAC2STR(mgmt->sa));
2359 return;
2360 }
2361#endif /* CONFIG_MESH */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002362 } else {
2363#ifdef CONFIG_MESH
2364 if (hapd->conf->mesh & MESH_ENABLED) {
2365 /* if the mesh peer is not available, we don't do auth.
2366 */
2367 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002368 " not yet known - drop Authentication frame",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002369 MAC2STR(mgmt->sa));
2370 /*
2371 * Save a copy of the frame so that it can be processed
2372 * if a new peer entry is added shortly after this.
2373 */
2374 wpabuf_free(hapd->mesh_pending_auth);
2375 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
2376 os_get_reltime(&hapd->mesh_pending_auth_time);
2377 return;
2378 }
2379#endif /* CONFIG_MESH */
2380
2381 sta = ap_sta_add(hapd, mgmt->sa);
2382 if (!sta) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002383 wpa_printf(MSG_DEBUG, "ap_sta_add() failed");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002384 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2385 goto fail;
2386 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002387 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002388 sta->last_seq_ctrl = seq_ctrl;
2389 sta->last_subtype = WLAN_FC_STYPE_AUTH;
Hai Shalom74f70d42019-02-11 14:42:39 -08002390#ifdef CONFIG_MBO
2391 sta->auth_rssi = rssi;
2392#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002393
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002394 res = ieee802_11_set_radius_info(
2395 hapd, sta, res, session_timeout, acct_interim_interval,
2396 &vlan_id, &psk, &identity, &radius_cui);
2397 if (res) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002398 wpa_printf(MSG_DEBUG, "ieee802_11_set_radius_info() failed");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002399 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2400 goto fail;
2401 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002403 sta->flags &= ~WLAN_STA_PREAUTH;
2404 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
2405
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002406 /*
2407 * If the driver supports full AP client state, add a station to the
2408 * driver before sending authentication reply to make sure the driver
2409 * has resources, and not to go through the entire authentication and
2410 * association handshake, and fail it at the end.
2411 *
2412 * If this is not the first transaction, in a multi-step authentication
2413 * algorithm, the station already exists in the driver
2414 * (sta->added_unassoc = 1) so skip it.
2415 *
2416 * In mesh mode, the station was already added to the driver when the
2417 * NEW_PEER_CANDIDATE event is received.
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002418 *
2419 * If PMF was negotiated for the existing association, skip this to
2420 * avoid dropping the STA entry and the associated keys. This is needed
2421 * to allow the original connection work until the attempt can complete
2422 * (re)association, so that unprotected Authentication frame cannot be
2423 * used to bypass PMF protection.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002424 */
2425 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002426 (!(sta->flags & WLAN_STA_MFP) || !ap_sta_is_authorized(sta)) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002427 !(hapd->conf->mesh & MESH_ENABLED) &&
2428 !(sta->added_unassoc)) {
2429 /*
2430 * If a station that is already associated to the AP, is trying
2431 * to authenticate again, remove the STA entry, in order to make
2432 * sure the STA PS state gets cleared and configuration gets
2433 * updated. To handle this, station's added_unassoc flag is
2434 * cleared once the station has completed association.
2435 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07002436 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002437 hostapd_drv_sta_remove(hapd, sta->addr);
2438 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
2439 WLAN_STA_AUTHORIZED);
2440
Hai Shalom81f62d82019-07-22 12:10:00 -07002441 if (hostapd_sta_add(hapd, sta->addr, 0, 0,
2442 sta->supported_rates,
2443 sta->supported_rates_len,
2444 0, NULL, NULL, NULL, 0,
2445 sta->flags, 0, 0, 0, 0)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002446 hostapd_logger(hapd, sta->addr,
2447 HOSTAPD_MODULE_IEEE80211,
2448 HOSTAPD_LEVEL_NOTICE,
2449 "Could not add STA to kernel driver");
2450 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2451 goto fail;
2452 }
2453
2454 sta->added_unassoc = 1;
2455 }
2456
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002457 switch (auth_alg) {
2458 case WLAN_AUTH_OPEN:
2459 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2460 HOSTAPD_LEVEL_DEBUG,
2461 "authentication OK (open system)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002462 sta->flags |= WLAN_STA_AUTH;
2463 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
2464 sta->auth_alg = WLAN_AUTH_OPEN;
2465 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002466 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002467#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002468 case WLAN_AUTH_SHARED_KEY:
2469 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
2470 fc & WLAN_FC_ISWEP);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002471 if (resp != 0)
2472 wpa_printf(MSG_DEBUG,
2473 "auth_shared_key() failed: status=%d", resp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002474 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
2475 mlme_authenticate_indication(hapd, sta);
2476 if (sta->challenge && auth_transaction == 1) {
2477 resp_ies[0] = WLAN_EID_CHALLENGE;
2478 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
2479 os_memcpy(resp_ies + 2, sta->challenge,
2480 WLAN_AUTH_CHALLENGE_LEN);
2481 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
2482 }
2483 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002484#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002485#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002486 case WLAN_AUTH_FT:
2487 sta->auth_alg = WLAN_AUTH_FT;
2488 if (sta->wpa_sm == NULL)
2489 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002490 sta->addr, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002491 if (sta->wpa_sm == NULL) {
2492 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
2493 "state machine");
2494 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2495 goto fail;
2496 }
2497 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
2498 auth_transaction, mgmt->u.auth.variable,
2499 len - IEEE80211_HDRLEN -
2500 sizeof(mgmt->u.auth),
2501 handle_auth_ft_finish, hapd);
2502 /* handle_auth_ft_finish() callback will complete auth. */
2503 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002504#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002505#ifdef CONFIG_SAE
2506 case WLAN_AUTH_SAE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002507#ifdef CONFIG_MESH
2508 if (status_code == WLAN_STATUS_SUCCESS &&
2509 hapd->conf->mesh & MESH_ENABLED) {
2510 if (sta->wpa_sm == NULL)
2511 sta->wpa_sm =
2512 wpa_auth_sta_init(hapd->wpa_auth,
2513 sta->addr, NULL);
2514 if (sta->wpa_sm == NULL) {
2515 wpa_printf(MSG_DEBUG,
2516 "SAE: Failed to initialize WPA state machine");
2517 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2518 goto fail;
2519 }
2520 }
2521#endif /* CONFIG_MESH */
2522 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
2523 status_code);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002524 return;
2525#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002526#ifdef CONFIG_FILS
2527 case WLAN_AUTH_FILS_SK:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002528 case WLAN_AUTH_FILS_SK_PFS:
2529 handle_auth_fils(hapd, sta, mgmt->u.auth.variable,
2530 len - IEEE80211_HDRLEN - sizeof(mgmt->u.auth),
2531 auth_alg, auth_transaction, status_code,
2532 handle_auth_fils_finish);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002533 return;
2534#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002535 }
2536
2537 fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002538 os_free(identity);
2539 os_free(radius_cui);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002540 hostapd_free_psk_list(psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002541
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002542 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
2543 auth_transaction + 1, resp, resp_ies,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002544 resp_ies_len, "handle-auth");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002545
2546 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
2547 reply_res != WLAN_STATUS_SUCCESS)) {
2548 hostapd_drv_sta_remove(hapd, sta->addr);
2549 sta->added_unassoc = 0;
2550 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002551}
2552
2553
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002554int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002555{
2556 int i, j = 32, aid;
2557
2558 /* get a unique AID */
2559 if (sta->aid > 0) {
2560 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
2561 return 0;
2562 }
2563
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002564 if (TEST_FAIL())
2565 return -1;
2566
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002567 for (i = 0; i < AID_WORDS; i++) {
2568 if (hapd->sta_aid[i] == (u32) -1)
2569 continue;
2570 for (j = 0; j < 32; j++) {
2571 if (!(hapd->sta_aid[i] & BIT(j)))
2572 break;
2573 }
2574 if (j < 32)
2575 break;
2576 }
2577 if (j == 32)
2578 return -1;
2579 aid = i * 32 + j + 1;
2580 if (aid > 2007)
2581 return -1;
2582
2583 sta->aid = aid;
2584 hapd->sta_aid[i] |= BIT(j);
2585 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
2586 return 0;
2587}
2588
2589
2590static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
2591 const u8 *ssid_ie, size_t ssid_ie_len)
2592{
2593 if (ssid_ie == NULL)
2594 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2595
2596 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
2597 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002598 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2599 HOSTAPD_LEVEL_INFO,
2600 "Station tried to associate with unknown SSID "
Dmitry Shmidt3c479372014-02-04 10:50:36 -08002601 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002602 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2603 }
2604
2605 return WLAN_STATUS_SUCCESS;
2606}
2607
2608
2609static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
2610 const u8 *wmm_ie, size_t wmm_ie_len)
2611{
2612 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002613 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002614 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002615 struct wmm_information_element *wmm;
2616
2617 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002618 hostapd_logger(hapd, sta->addr,
2619 HOSTAPD_MODULE_WPA,
2620 HOSTAPD_LEVEL_DEBUG,
2621 "invalid WMM element in association "
2622 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002623 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2624 }
2625
2626 sta->flags |= WLAN_STA_WMM;
2627 wmm = (struct wmm_information_element *) wmm_ie;
2628 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002629 }
2630 return WLAN_STATUS_SUCCESS;
2631}
2632
Hai Shalom74f70d42019-02-11 14:42:39 -08002633static u16 check_multi_ap(struct hostapd_data *hapd, struct sta_info *sta,
2634 const u8 *multi_ap_ie, size_t multi_ap_len)
2635{
2636 u8 multi_ap_value = 0;
2637
2638 sta->flags &= ~WLAN_STA_MULTI_AP;
2639
2640 if (!hapd->conf->multi_ap)
2641 return WLAN_STATUS_SUCCESS;
2642
2643 if (multi_ap_ie) {
2644 const u8 *multi_ap_subelem;
2645
2646 multi_ap_subelem = get_ie(multi_ap_ie + 4,
2647 multi_ap_len - 4,
2648 MULTI_AP_SUB_ELEM_TYPE);
2649 if (multi_ap_subelem && multi_ap_subelem[1] == 1) {
2650 multi_ap_value = multi_ap_subelem[2];
2651 } else {
2652 hostapd_logger(hapd, sta->addr,
2653 HOSTAPD_MODULE_IEEE80211,
2654 HOSTAPD_LEVEL_INFO,
2655 "Multi-AP IE has missing or invalid Multi-AP subelement");
2656 return WLAN_STATUS_INVALID_IE;
2657 }
2658 }
2659
Hai Shalom021b0b52019-04-10 11:17:58 -07002660 if (multi_ap_value && multi_ap_value != MULTI_AP_BACKHAUL_STA)
2661 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2662 HOSTAPD_LEVEL_INFO,
2663 "Multi-AP IE with unexpected value 0x%02x",
2664 multi_ap_value);
Hai Shalom74f70d42019-02-11 14:42:39 -08002665
Hai Shalom021b0b52019-04-10 11:17:58 -07002666 if (!(multi_ap_value & MULTI_AP_BACKHAUL_STA)) {
2667 if (hapd->conf->multi_ap & FRONTHAUL_BSS)
2668 return WLAN_STATUS_SUCCESS;
Hai Shalom74f70d42019-02-11 14:42:39 -08002669
Hai Shalom021b0b52019-04-10 11:17:58 -07002670 hostapd_logger(hapd, sta->addr,
2671 HOSTAPD_MODULE_IEEE80211,
2672 HOSTAPD_LEVEL_INFO,
2673 "Non-Multi-AP STA tries to associate with backhaul-only BSS");
2674 return WLAN_STATUS_ASSOC_DENIED_UNSPEC;
Hai Shalom74f70d42019-02-11 14:42:39 -08002675 }
2676
Hai Shalom021b0b52019-04-10 11:17:58 -07002677 if (!(hapd->conf->multi_ap & BACKHAUL_BSS))
2678 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2679 HOSTAPD_LEVEL_DEBUG,
2680 "Backhaul STA tries to associate with fronthaul-only BSS");
2681
2682 sta->flags |= WLAN_STA_MULTI_AP;
2683 return WLAN_STATUS_SUCCESS;
Hai Shalom74f70d42019-02-11 14:42:39 -08002684}
2685
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002686
2687static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
2688 struct ieee802_11_elems *elems)
2689{
Dmitry Shmidt29333592017-01-09 12:27:11 -08002690 /* Supported rates not used in IEEE 802.11ad/DMG */
2691 if (hapd->iface->current_mode &&
2692 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD)
2693 return WLAN_STATUS_SUCCESS;
2694
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002695 if (!elems->supp_rates) {
2696 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2697 HOSTAPD_LEVEL_DEBUG,
2698 "No supported rates element in AssocReq");
2699 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2700 }
2701
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002702 if (elems->supp_rates_len + elems->ext_supp_rates_len >
2703 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2705 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002706 "Invalid supported rates element length %d+%d",
2707 elems->supp_rates_len,
2708 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002709 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2710 }
2711
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002712 sta->supported_rates_len = merge_byte_arrays(
2713 sta->supported_rates, sizeof(sta->supported_rates),
2714 elems->supp_rates, elems->supp_rates_len,
2715 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002716
2717 return WLAN_STATUS_SUCCESS;
2718}
2719
2720
Dmitry Shmidt051af732013-10-22 13:52:46 -07002721static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
2722 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
2723{
2724#ifdef CONFIG_INTERWORKING
2725 /* check for QoS Map support */
2726 if (ext_capab_ie_len >= 5) {
2727 if (ext_capab_ie[4] & 0x01)
2728 sta->qos_map_enabled = 1;
2729 }
2730#endif /* CONFIG_INTERWORKING */
2731
Roshan Pius3a1667e2018-07-03 15:17:14 -07002732 if (ext_capab_ie_len > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002733 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
Roshan Pius3a1667e2018-07-03 15:17:14 -07002734 os_free(sta->ext_capability);
2735 sta->ext_capability = os_malloc(1 + ext_capab_ie_len);
2736 if (sta->ext_capability) {
2737 sta->ext_capability[0] = ext_capab_ie_len;
2738 os_memcpy(sta->ext_capability + 1, ext_capab_ie,
2739 ext_capab_ie_len);
2740 }
2741 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002742
Dmitry Shmidt051af732013-10-22 13:52:46 -07002743 return WLAN_STATUS_SUCCESS;
2744}
2745
2746
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002747#ifdef CONFIG_OWE
2748
2749static int owe_group_supported(struct hostapd_data *hapd, u16 group)
2750{
2751 int i;
2752 int *groups = hapd->conf->owe_groups;
2753
2754 if (group != 19 && group != 20 && group != 21)
2755 return 0;
2756
2757 if (!groups)
2758 return 1;
2759
2760 for (i = 0; groups[i] > 0; i++) {
2761 if (groups[i] == group)
2762 return 1;
2763 }
2764
2765 return 0;
2766}
2767
2768
2769static u16 owe_process_assoc_req(struct hostapd_data *hapd,
2770 struct sta_info *sta, const u8 *owe_dh,
2771 u8 owe_dh_len)
2772{
2773 struct wpabuf *secret, *pub, *hkey;
2774 int res;
2775 u8 prk[SHA512_MAC_LEN], pmkid[SHA512_MAC_LEN];
2776 const char *info = "OWE Key Generation";
2777 const u8 *addr[2];
2778 size_t len[2];
2779 u16 group;
2780 size_t hash_len, prime_len;
2781
2782 if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) {
2783 wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching");
2784 return WLAN_STATUS_SUCCESS;
2785 }
2786
2787 group = WPA_GET_LE16(owe_dh);
2788 if (!owe_group_supported(hapd, group)) {
2789 wpa_printf(MSG_DEBUG, "OWE: Unsupported DH group %u", group);
2790 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2791 }
2792 if (group == 19)
2793 prime_len = 32;
2794 else if (group == 20)
2795 prime_len = 48;
2796 else if (group == 21)
2797 prime_len = 66;
2798 else
2799 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2800
2801 crypto_ecdh_deinit(sta->owe_ecdh);
2802 sta->owe_ecdh = crypto_ecdh_init(group);
2803 if (!sta->owe_ecdh)
2804 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2805 sta->owe_group = group;
2806
2807 secret = crypto_ecdh_set_peerkey(sta->owe_ecdh, 0, owe_dh + 2,
2808 owe_dh_len - 2);
2809 secret = wpabuf_zeropad(secret, prime_len);
2810 if (!secret) {
2811 wpa_printf(MSG_DEBUG, "OWE: Invalid peer DH public key");
2812 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2813 }
2814 wpa_hexdump_buf_key(MSG_DEBUG, "OWE: DH shared secret", secret);
2815
2816 /* prk = HKDF-extract(C | A | group, z) */
2817
2818 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
2819 if (!pub) {
2820 wpabuf_clear_free(secret);
2821 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2822 }
2823
2824 /* PMKID = Truncate-128(Hash(C | A)) */
2825 addr[0] = owe_dh + 2;
2826 len[0] = owe_dh_len - 2;
2827 addr[1] = wpabuf_head(pub);
2828 len[1] = wpabuf_len(pub);
2829 if (group == 19) {
2830 res = sha256_vector(2, addr, len, pmkid);
2831 hash_len = SHA256_MAC_LEN;
2832 } else if (group == 20) {
2833 res = sha384_vector(2, addr, len, pmkid);
2834 hash_len = SHA384_MAC_LEN;
2835 } else if (group == 21) {
2836 res = sha512_vector(2, addr, len, pmkid);
2837 hash_len = SHA512_MAC_LEN;
2838 } else {
2839 wpabuf_free(pub);
2840 wpabuf_clear_free(secret);
2841 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2842 }
2843 pub = wpabuf_zeropad(pub, prime_len);
2844 if (res < 0 || !pub) {
2845 wpabuf_free(pub);
2846 wpabuf_clear_free(secret);
2847 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2848 }
2849
2850 hkey = wpabuf_alloc(owe_dh_len - 2 + wpabuf_len(pub) + 2);
2851 if (!hkey) {
2852 wpabuf_free(pub);
2853 wpabuf_clear_free(secret);
2854 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2855 }
2856
2857 wpabuf_put_data(hkey, owe_dh + 2, owe_dh_len - 2); /* C */
2858 wpabuf_put_buf(hkey, pub); /* A */
2859 wpabuf_free(pub);
2860 wpabuf_put_le16(hkey, group); /* group */
2861 if (group == 19)
2862 res = hmac_sha256(wpabuf_head(hkey), wpabuf_len(hkey),
2863 wpabuf_head(secret), wpabuf_len(secret), prk);
2864 else if (group == 20)
2865 res = hmac_sha384(wpabuf_head(hkey), wpabuf_len(hkey),
2866 wpabuf_head(secret), wpabuf_len(secret), prk);
2867 else if (group == 21)
2868 res = hmac_sha512(wpabuf_head(hkey), wpabuf_len(hkey),
2869 wpabuf_head(secret), wpabuf_len(secret), prk);
2870 wpabuf_clear_free(hkey);
2871 wpabuf_clear_free(secret);
2872 if (res < 0)
2873 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2874
2875 wpa_hexdump_key(MSG_DEBUG, "OWE: prk", prk, hash_len);
2876
2877 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2878
2879 os_free(sta->owe_pmk);
2880 sta->owe_pmk = os_malloc(hash_len);
2881 if (!sta->owe_pmk) {
2882 os_memset(prk, 0, SHA512_MAC_LEN);
2883 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2884 }
2885
2886 if (group == 19)
2887 res = hmac_sha256_kdf(prk, hash_len, NULL, (const u8 *) info,
2888 os_strlen(info), sta->owe_pmk, hash_len);
2889 else if (group == 20)
2890 res = hmac_sha384_kdf(prk, hash_len, NULL, (const u8 *) info,
2891 os_strlen(info), sta->owe_pmk, hash_len);
2892 else if (group == 21)
2893 res = hmac_sha512_kdf(prk, hash_len, NULL, (const u8 *) info,
2894 os_strlen(info), sta->owe_pmk, hash_len);
2895 os_memset(prk, 0, SHA512_MAC_LEN);
2896 if (res < 0) {
2897 os_free(sta->owe_pmk);
2898 sta->owe_pmk = NULL;
2899 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2900 }
2901 sta->owe_pmk_len = hash_len;
2902
2903 wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sta->owe_pmk, sta->owe_pmk_len);
2904 wpa_hexdump(MSG_DEBUG, "OWE: PMKID", pmkid, PMKID_LEN);
2905 wpa_auth_pmksa_add2(hapd->wpa_auth, sta->addr, sta->owe_pmk,
2906 sta->owe_pmk_len, pmkid, 0, WPA_KEY_MGMT_OWE);
2907
2908 return WLAN_STATUS_SUCCESS;
2909}
2910
Hai Shalom81f62d82019-07-22 12:10:00 -07002911
2912u16 owe_validate_request(struct hostapd_data *hapd, const u8 *peer,
2913 const u8 *rsn_ie, size_t rsn_ie_len,
2914 const u8 *owe_dh, size_t owe_dh_len)
2915{
2916 struct wpa_ie_data data;
2917 int res;
2918
2919 if (!rsn_ie || rsn_ie_len < 2) {
2920 wpa_printf(MSG_DEBUG, "OWE: Invalid RSNE from " MACSTR,
2921 MAC2STR(peer));
2922 return WLAN_STATUS_INVALID_IE;
2923 }
2924 rsn_ie -= 2;
2925 rsn_ie_len += 2;
2926
2927 res = wpa_parse_wpa_ie_rsn(rsn_ie, rsn_ie_len, &data);
2928 if (res) {
2929 wpa_printf(MSG_DEBUG, "Failed to parse RSNE from " MACSTR
2930 " (res=%d)", MAC2STR(peer), res);
2931 wpa_hexdump(MSG_DEBUG, "RSNE", rsn_ie, rsn_ie_len);
2932 return wpa_res_to_status_code(res);
2933 }
2934 if (!(data.key_mgmt & WPA_KEY_MGMT_OWE)) {
2935 wpa_printf(MSG_DEBUG,
2936 "OWE: Unexpected key mgmt 0x%x from " MACSTR,
2937 (unsigned int) data.key_mgmt, MAC2STR(peer));
2938 return WLAN_STATUS_AKMP_NOT_VALID;
2939 }
2940 if (!owe_dh) {
2941 wpa_printf(MSG_DEBUG,
2942 "OWE: No Diffie-Hellman Parameter element from "
2943 MACSTR, MAC2STR(peer));
2944 return WLAN_STATUS_AKMP_NOT_VALID;
2945 }
2946
2947 return WLAN_STATUS_SUCCESS;
2948}
2949
2950
2951u16 owe_process_rsn_ie(struct hostapd_data *hapd,
2952 struct sta_info *sta,
2953 const u8 *rsn_ie, size_t rsn_ie_len,
2954 const u8 *owe_dh, size_t owe_dh_len)
2955{
2956 u16 status;
2957 u8 *owe_buf, ie[256 * 2];
2958 size_t ie_len = 0;
2959 int res;
2960
2961 if (!rsn_ie || rsn_ie_len < 2) {
2962 wpa_printf(MSG_DEBUG, "OWE: No RSNE in (Re)AssocReq");
2963 status = WLAN_STATUS_INVALID_IE;
2964 goto end;
2965 }
2966
2967 if (!sta->wpa_sm)
2968 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr,
2969 NULL);
2970 if (!sta->wpa_sm) {
2971 wpa_printf(MSG_WARNING,
2972 "OWE: Failed to initialize WPA state machine");
2973 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2974 goto end;
2975 }
2976 rsn_ie -= 2;
2977 rsn_ie_len += 2;
2978 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
2979 hapd->iface->freq, rsn_ie, rsn_ie_len,
Hai Shalomc3565922019-10-28 11:58:20 -07002980 NULL, 0, NULL, 0, owe_dh, owe_dh_len);
Hai Shalom81f62d82019-07-22 12:10:00 -07002981 status = wpa_res_to_status_code(res);
2982 if (status != WLAN_STATUS_SUCCESS)
2983 goto end;
2984 status = owe_process_assoc_req(hapd, sta, owe_dh, owe_dh_len);
2985 if (status != WLAN_STATUS_SUCCESS)
2986 goto end;
2987 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, ie, sizeof(ie),
2988 NULL, 0);
2989 if (!owe_buf) {
2990 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2991 goto end;
2992 }
2993
2994 if (sta->owe_ecdh) {
2995 struct wpabuf *pub;
2996
2997 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
2998 if (!pub) {
2999 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
3000 goto end;
3001 }
3002
3003 /* OWE Diffie-Hellman Parameter element */
3004 *owe_buf++ = WLAN_EID_EXTENSION; /* Element ID */
3005 *owe_buf++ = 1 + 2 + wpabuf_len(pub); /* Length */
3006 *owe_buf++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension
3007 */
3008 WPA_PUT_LE16(owe_buf, sta->owe_group);
3009 owe_buf += 2;
3010 os_memcpy(owe_buf, wpabuf_head(pub), wpabuf_len(pub));
3011 owe_buf += wpabuf_len(pub);
3012 wpabuf_free(pub);
3013 sta->external_dh_updated = 1;
3014 }
3015 ie_len = owe_buf - ie;
3016
3017end:
3018 wpa_printf(MSG_DEBUG, "OWE: Update status %d, ie len %d for peer "
3019 MACSTR, status, (unsigned int) ie_len,
3020 MAC2STR(sta->addr));
3021 hostapd_drv_update_dh_ie(hapd, sta->addr, status,
3022 status == WLAN_STATUS_SUCCESS ? ie : NULL,
3023 ie_len);
3024
3025 return status;
3026}
3027
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003028#endif /* CONFIG_OWE */
3029
3030
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003031static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
3032 const u8 *ies, size_t ies_len, int reassoc)
3033{
3034 struct ieee802_11_elems elems;
3035 u16 resp;
3036 const u8 *wpa_ie;
3037 size_t wpa_ie_len;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003038 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003039
3040 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
3041 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3042 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
3043 "association request");
3044 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3045 }
3046
3047 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
3048 if (resp != WLAN_STATUS_SUCCESS)
3049 return resp;
3050 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
3051 if (resp != WLAN_STATUS_SUCCESS)
3052 return resp;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003053 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
3054 if (resp != WLAN_STATUS_SUCCESS)
3055 return resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003056 resp = copy_supp_rates(hapd, sta, &elems);
3057 if (resp != WLAN_STATUS_SUCCESS)
3058 return resp;
Hai Shalom74f70d42019-02-11 14:42:39 -08003059
3060 resp = check_multi_ap(hapd, sta, elems.multi_ap, elems.multi_ap_len);
3061 if (resp != WLAN_STATUS_SUCCESS)
3062 return resp;
3063
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003064#ifdef CONFIG_IEEE80211N
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003065 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003066 if (resp != WLAN_STATUS_SUCCESS)
3067 return resp;
3068 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
3069 !(sta->flags & WLAN_STA_HT)) {
3070 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3071 HOSTAPD_LEVEL_INFO, "Station does not support "
3072 "mandatory HT PHY - reject association");
3073 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
3074 }
3075#endif /* CONFIG_IEEE80211N */
3076
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003077#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003078 if (hapd->iconf->ieee80211ac) {
3079 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
3080 if (resp != WLAN_STATUS_SUCCESS)
3081 return resp;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003082
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003083 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
3084 if (resp != WLAN_STATUS_SUCCESS)
3085 return resp;
3086 }
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003087
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003088 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
3089 !(sta->flags & WLAN_STA_VHT)) {
3090 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3091 HOSTAPD_LEVEL_INFO, "Station does not support "
3092 "mandatory VHT PHY - reject association");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003093 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003094 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003095
3096 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
3097 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
3098 elems.vendor_vht_len);
3099 if (resp != WLAN_STATUS_SUCCESS)
3100 return resp;
3101 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003102#endif /* CONFIG_IEEE80211AC */
Hai Shalom81f62d82019-07-22 12:10:00 -07003103#ifdef CONFIG_IEEE80211AX
3104 if (hapd->iconf->ieee80211ax) {
3105 resp = copy_sta_he_capab(hapd, sta, IEEE80211_MODE_AP,
3106 elems.he_capabilities,
3107 elems.he_capabilities_len);
3108 if (resp != WLAN_STATUS_SUCCESS)
3109 return resp;
3110 }
3111#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003112
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003113#ifdef CONFIG_P2P
3114 if (elems.p2p) {
3115 wpabuf_free(sta->p2p_ie);
3116 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
3117 P2P_IE_VENDOR_TYPE);
3118 if (sta->p2p_ie)
3119 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
3120 } else {
3121 wpabuf_free(sta->p2p_ie);
3122 sta->p2p_ie = NULL;
3123 }
3124#endif /* CONFIG_P2P */
3125
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003126 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
3127 wpa_ie = elems.rsn_ie;
3128 wpa_ie_len = elems.rsn_ie_len;
3129 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
3130 elems.wpa_ie) {
3131 wpa_ie = elems.wpa_ie;
3132 wpa_ie_len = elems.wpa_ie_len;
3133 } else {
3134 wpa_ie = NULL;
3135 wpa_ie_len = 0;
3136 }
3137
3138#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003139 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003140 if (hapd->conf->wps_state && elems.wps_ie) {
3141 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
3142 "Request - assume WPS is used");
3143 sta->flags |= WLAN_STA_WPS;
3144 wpabuf_free(sta->wps_ie);
3145 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
3146 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003147 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
3148 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
3149 sta->flags |= WLAN_STA_WPS2;
3150 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003151 wpa_ie = NULL;
3152 wpa_ie_len = 0;
3153 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
3154 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
3155 "(Re)Association Request - reject");
3156 return WLAN_STATUS_INVALID_IE;
3157 }
3158 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
3159 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
3160 "(Re)Association Request - possible WPS use");
3161 sta->flags |= WLAN_STA_MAYBE_WPS;
3162 } else
3163#endif /* CONFIG_WPS */
3164 if (hapd->conf->wpa && wpa_ie == NULL) {
3165 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3166 HOSTAPD_LEVEL_INFO,
3167 "No WPA/RSN IE in association request");
3168 return WLAN_STATUS_INVALID_IE;
3169 }
3170
3171 if (hapd->conf->wpa && wpa_ie) {
3172 int res;
3173 wpa_ie -= 2;
3174 wpa_ie_len += 2;
3175 if (sta->wpa_sm == NULL)
3176 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003177 sta->addr,
3178 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003179 if (sta->wpa_sm == NULL) {
3180 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
3181 "state machine");
3182 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3183 }
Hai Shalom021b0b52019-04-10 11:17:58 -07003184 wpa_auth_set_auth_alg(sta->wpa_sm, sta->auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003185 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -07003186 hapd->iface->freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003187 wpa_ie, wpa_ie_len,
Hai Shalomc3565922019-10-28 11:58:20 -07003188 elems.rsnxe ? elems.rsnxe - 2 : NULL,
3189 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003190 elems.mdie, elems.mdie_len,
3191 elems.owe_dh, elems.owe_dh_len);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003192 resp = wpa_res_to_status_code(res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003193 if (resp != WLAN_STATUS_SUCCESS)
3194 return resp;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003195 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
3196 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
3197 !sta->sa_query_timed_out &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003198 sta->sa_query_count > 0)
3199 ap_check_sa_query_timeout(hapd, sta);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003200 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
3201 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
3202 !sta->sa_query_timed_out &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003203 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
3204 /*
3205 * STA has already been associated with MFP and SA
3206 * Query timeout has not been reached. Reject the
3207 * association attempt temporarily and start SA Query,
3208 * if one is not pending.
3209 */
3210
3211 if (sta->sa_query_count == 0)
3212 ap_sta_start_sa_query(hapd, sta);
3213
3214 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
3215 }
3216
3217 if (wpa_auth_uses_mfp(sta->wpa_sm))
3218 sta->flags |= WLAN_STA_MFP;
3219 else
3220 sta->flags &= ~WLAN_STA_MFP;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003221
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003222#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003223 if (sta->auth_alg == WLAN_AUTH_FT) {
3224 if (!reassoc) {
3225 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
3226 "to use association (not "
3227 "re-association) with FT auth_alg",
3228 MAC2STR(sta->addr));
3229 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3230 }
3231
3232 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
3233 ies_len);
3234 if (resp != WLAN_STATUS_SUCCESS)
3235 return resp;
3236 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003237#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003238
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003239#ifdef CONFIG_SAE
Roshan Pius3a1667e2018-07-03 15:17:14 -07003240 if (wpa_auth_uses_sae(sta->wpa_sm) && sta->sae &&
3241 sta->sae->state == SAE_ACCEPTED)
3242 wpa_auth_add_sae_pmkid(sta->wpa_sm, sta->sae->pmkid);
3243
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003244 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003245 sta->auth_alg == WLAN_AUTH_OPEN) {
3246 struct rsn_pmksa_cache_entry *sa;
3247 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
3248 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
3249 wpa_printf(MSG_DEBUG,
3250 "SAE: No PMKSA cache entry found for "
3251 MACSTR, MAC2STR(sta->addr));
3252 return WLAN_STATUS_INVALID_PMKID;
3253 }
3254 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
3255 " using PMKSA caching", MAC2STR(sta->addr));
3256 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
3257 sta->auth_alg != WLAN_AUTH_SAE &&
3258 !(sta->auth_alg == WLAN_AUTH_FT &&
3259 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003260 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
3261 "SAE AKM after non-SAE auth_alg %u",
3262 MAC2STR(sta->addr), sta->auth_alg);
3263 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
3264 }
Hai Shalomc3565922019-10-28 11:58:20 -07003265
3266 if (hapd->conf->sae_pwe == 2 &&
3267 sta->auth_alg == WLAN_AUTH_SAE &&
3268 sta->sae && sta->sae->tmp && !sta->sae->tmp->h2e &&
3269 elems.rsnxe && elems.rsnxe_len >= 1 &&
3270 (elems.rsnxe[0] & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
3271 wpa_printf(MSG_INFO, "SAE: " MACSTR
3272 " indicates support for SAE H2E, but did not use it",
3273 MAC2STR(sta->addr));
3274 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3275 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003276#endif /* CONFIG_SAE */
3277
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003278#ifdef CONFIG_OWE
3279 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
3280 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
3281 elems.owe_dh) {
3282 resp = owe_process_assoc_req(hapd, sta, elems.owe_dh,
3283 elems.owe_dh_len);
3284 if (resp != WLAN_STATUS_SUCCESS)
3285 return resp;
3286 }
3287#endif /* CONFIG_OWE */
3288
Hai Shalom021b0b52019-04-10 11:17:58 -07003289#ifdef CONFIG_DPP2
3290 dpp_pfs_free(sta->dpp_pfs);
3291 sta->dpp_pfs = NULL;
3292
3293 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
3294 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
3295 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
3296 elems.owe_dh) {
3297 sta->dpp_pfs = dpp_pfs_init(
3298 wpabuf_head(hapd->conf->dpp_netaccesskey),
3299 wpabuf_len(hapd->conf->dpp_netaccesskey));
3300 if (!sta->dpp_pfs) {
3301 wpa_printf(MSG_DEBUG,
3302 "DPP: Could not initialize PFS");
3303 /* Try to continue without PFS */
3304 goto pfs_fail;
3305 }
3306
3307 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
3308 elems.owe_dh_len) < 0) {
3309 dpp_pfs_free(sta->dpp_pfs);
3310 sta->dpp_pfs = NULL;
3311 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3312 }
3313 }
3314
3315 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
3316 sta->dpp_pfs->secret : NULL);
3317 pfs_fail:
3318#endif /* CONFIG_DPP2 */
3319
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003320#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003321 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003322 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
3323 hostapd_logger(hapd, sta->addr,
3324 HOSTAPD_MODULE_IEEE80211,
3325 HOSTAPD_LEVEL_INFO,
3326 "Station tried to use TKIP with HT "
3327 "association");
3328 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
3329 }
3330#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003331#ifdef CONFIG_HS20
3332 } else if (hapd->conf->osen) {
3333 if (elems.osen == NULL) {
3334 hostapd_logger(
3335 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3336 HOSTAPD_LEVEL_INFO,
3337 "No HS 2.0 OSEN element in association request");
3338 return WLAN_STATUS_INVALID_IE;
3339 }
3340
3341 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
3342 if (sta->wpa_sm == NULL)
3343 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
3344 sta->addr, NULL);
3345 if (sta->wpa_sm == NULL) {
3346 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
3347 "state machine");
3348 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3349 }
3350 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
3351 elems.osen - 2, elems.osen_len + 2) < 0)
3352 return WLAN_STATUS_INVALID_IE;
3353#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003354 } else
3355 wpa_auth_sta_no_wpa(sta->wpa_sm);
3356
3357#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003358 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
3359#endif /* CONFIG_P2P */
3360
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003361#ifdef CONFIG_HS20
3362 wpabuf_free(sta->hs20_ie);
3363 if (elems.hs20 && elems.hs20_len > 4) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003364 int release;
3365
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003366 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
3367 elems.hs20_len - 4);
Hai Shalom74f70d42019-02-11 14:42:39 -08003368 release = ((elems.hs20[4] >> 4) & 0x0f) + 1;
Hai Shalomc3565922019-10-28 11:58:20 -07003369 if (release >= 2 && !wpa_auth_uses_mfp(sta->wpa_sm) &&
3370 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003371 wpa_printf(MSG_DEBUG,
3372 "HS 2.0: PMF not negotiated by release %d station "
3373 MACSTR, release, MAC2STR(sta->addr));
3374 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
3375 }
3376 } else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003377 sta->hs20_ie = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08003378 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07003379
3380 wpabuf_free(sta->roaming_consortium);
3381 if (elems.roaming_cons_sel)
3382 sta->roaming_consortium = wpabuf_alloc_copy(
3383 elems.roaming_cons_sel + 4,
3384 elems.roaming_cons_sel_len - 4);
3385 else
3386 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003387#endif /* CONFIG_HS20 */
3388
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003389#ifdef CONFIG_FST
3390 wpabuf_free(sta->mb_ies);
3391 if (hapd->iface->fst)
3392 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
3393 else
3394 sta->mb_ies = NULL;
3395#endif /* CONFIG_FST */
3396
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003397#ifdef CONFIG_MBO
3398 mbo_ap_check_sta_assoc(hapd, sta, &elems);
3399
3400 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
3401 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
3402 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
3403 wpa_printf(MSG_INFO,
3404 "MBO: Reject WPA2 association without PMF");
3405 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3406 }
3407#endif /* CONFIG_MBO */
3408
Hai Shalom74f70d42019-02-11 14:42:39 -08003409#if defined(CONFIG_FILS) && defined(CONFIG_OCV)
3410 if (wpa_auth_uses_ocv(sta->wpa_sm) &&
3411 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3412 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3413 sta->auth_alg == WLAN_AUTH_FILS_PK)) {
3414 struct wpa_channel_info ci;
3415 int tx_chanwidth;
3416 int tx_seg1_idx;
3417
3418 if (hostapd_drv_channel_info(hapd, &ci) != 0) {
3419 wpa_printf(MSG_WARNING,
3420 "Failed to get channel info to validate received OCI in FILS (Re)Association Request frame");
3421 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3422 }
3423
3424 if (get_sta_tx_parameters(sta->wpa_sm,
3425 channel_width_to_int(ci.chanwidth),
3426 ci.seg1_idx, &tx_chanwidth,
3427 &tx_seg1_idx) < 0)
3428 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3429
3430 if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
3431 tx_chanwidth, tx_seg1_idx) != 0) {
3432 wpa_printf(MSG_WARNING, "FILS: %s", ocv_errorstr);
3433 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3434 }
3435 }
3436#endif /* CONFIG_FILS && CONFIG_OCV */
3437
Dmitry Shmidt9c175262016-03-03 10:20:07 -08003438 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
3439 elems.supp_op_classes_len);
3440
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003441 if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) &&
3442 elems.rrm_enabled &&
3443 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
3444 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
3445 sizeof(sta->rrm_enabled_capa));
3446
Roshan Pius3a1667e2018-07-03 15:17:14 -07003447 if (elems.power_capab) {
3448 sta->min_tx_power = elems.power_capab[0];
3449 sta->max_tx_power = elems.power_capab[1];
3450 sta->power_capab = 1;
3451 } else {
3452 sta->power_capab = 0;
3453 }
3454
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003455 return WLAN_STATUS_SUCCESS;
3456}
3457
3458
3459static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
3460 u16 reason_code)
3461{
3462 int send_len;
3463 struct ieee80211_mgmt reply;
3464
3465 os_memset(&reply, 0, sizeof(reply));
3466 reply.frame_control =
3467 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
3468 os_memcpy(reply.da, addr, ETH_ALEN);
3469 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
3470 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
3471
3472 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
3473 reply.u.deauth.reason_code = host_to_le16(reason_code);
3474
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003475 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003476 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
3477 strerror(errno));
3478}
3479
3480
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003481static int add_associated_sta(struct hostapd_data *hapd,
Hai Shalom74f70d42019-02-11 14:42:39 -08003482 struct sta_info *sta, int reassoc)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003483{
3484 struct ieee80211_ht_capabilities ht_cap;
3485 struct ieee80211_vht_capabilities vht_cap;
Hai Shalom81f62d82019-07-22 12:10:00 -07003486 struct ieee80211_he_capabilities he_cap;
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003487 int set = 1;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003488
3489 /*
3490 * Remove the STA entry to ensure the STA PS state gets cleared and
3491 * configuration gets updated. This is relevant for cases, such as
3492 * FT-over-the-DS, where a station re-associates back to the same AP but
3493 * skips the authentication flow, or if working with a driver that
3494 * does not support full AP client state.
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003495 *
3496 * Skip this if the STA has already completed FT reassociation and the
3497 * TK has been configured since the TX/RX PN must not be reset to 0 for
3498 * the same key.
Hai Shalom74f70d42019-02-11 14:42:39 -08003499 *
3500 * FT-over-the-DS has a special case where the STA entry (and as such,
3501 * the TK) has not yet been configured to the driver depending on which
3502 * driver interface is used. For that case, allow add-STA operation to
3503 * be used (instead of set-STA). This is needed to allow mac80211-based
3504 * drivers to accept the STA parameter configuration. Since this is
3505 * after a new FT-over-DS exchange, a new TK has been derived, so key
3506 * reinstallation is not a concern for this case.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003507 */
Hai Shalom74f70d42019-02-11 14:42:39 -08003508 wpa_printf(MSG_DEBUG, "Add associated STA " MACSTR
3509 " (added_unassoc=%d auth_alg=%u ft_over_ds=%u reassoc=%d authorized=%d ft_tk=%d fils_tk=%d)",
3510 MAC2STR(sta->addr), sta->added_unassoc, sta->auth_alg,
3511 sta->ft_over_ds, reassoc,
3512 !!(sta->flags & WLAN_STA_AUTHORIZED),
3513 wpa_auth_sta_ft_tk_already_set(sta->wpa_sm),
3514 wpa_auth_sta_fils_tk_already_set(sta->wpa_sm));
3515
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003516 if (!sta->added_unassoc &&
3517 (!(sta->flags & WLAN_STA_AUTHORIZED) ||
Hai Shalom74f70d42019-02-11 14:42:39 -08003518 (reassoc && sta->ft_over_ds && sta->auth_alg == WLAN_AUTH_FT) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003519 (!wpa_auth_sta_ft_tk_already_set(sta->wpa_sm) &&
3520 !wpa_auth_sta_fils_tk_already_set(sta->wpa_sm)))) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003521 hostapd_drv_sta_remove(hapd, sta->addr);
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003522 wpa_auth_sm_event(sta->wpa_sm, WPA_DRV_STA_REMOVED);
3523 set = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08003524
3525 /* Do not allow the FT-over-DS exception to be used more than
3526 * once per authentication exchange to guarantee a new TK is
3527 * used here */
3528 sta->ft_over_ds = 0;
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003529 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003530
3531#ifdef CONFIG_IEEE80211N
3532 if (sta->flags & WLAN_STA_HT)
3533 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
3534#endif /* CONFIG_IEEE80211N */
3535#ifdef CONFIG_IEEE80211AC
3536 if (sta->flags & WLAN_STA_VHT)
3537 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
3538#endif /* CONFIG_IEEE80211AC */
Hai Shalom81f62d82019-07-22 12:10:00 -07003539#ifdef CONFIG_IEEE80211AX
3540 if (sta->flags & WLAN_STA_HE) {
3541 hostapd_get_he_capab(hapd, sta->he_capab, &he_cap,
3542 sta->he_capab_len);
3543 }
3544#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003545
3546 /*
3547 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
3548 * will be set when the ACK frame for the (Re)Association Response frame
3549 * is processed (TX status driver event).
3550 */
3551 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
3552 sta->supported_rates, sta->supported_rates_len,
3553 sta->listen_interval,
3554 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
3555 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
Hai Shalom81f62d82019-07-22 12:10:00 -07003556 sta->flags & WLAN_STA_HE ? &he_cap : NULL,
3557 sta->flags & WLAN_STA_HE ? sta->he_capab_len : 0,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003558 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003559 sta->vht_opmode, sta->p2p_ie ? 1 : 0,
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003560 set)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003561 hostapd_logger(hapd, sta->addr,
3562 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
3563 "Could not %s STA to kernel driver",
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02003564 set ? "set" : "add");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003565
3566 if (sta->added_unassoc) {
3567 hostapd_drv_sta_remove(hapd, sta->addr);
3568 sta->added_unassoc = 0;
3569 }
3570
3571 return -1;
3572 }
3573
3574 sta->added_unassoc = 0;
3575
3576 return 0;
3577}
3578
3579
3580static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
Dmitry Shmidt29333592017-01-09 12:27:11 -08003581 const u8 *addr, u16 status_code, int reassoc,
Hai Shalom74f70d42019-02-11 14:42:39 -08003582 const u8 *ies, size_t ies_len, int rssi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003583{
3584 int send_len;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003585 u8 *buf;
3586 size_t buflen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003587 struct ieee80211_mgmt *reply;
3588 u8 *p;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003589 u16 res = WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003590
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003591 buflen = sizeof(struct ieee80211_mgmt) + 1024;
3592#ifdef CONFIG_FILS
3593 if (sta && sta->fils_hlp_resp)
3594 buflen += wpabuf_len(sta->fils_hlp_resp);
Hai Shalom81f62d82019-07-22 12:10:00 -07003595 if (sta)
3596 buflen += 150;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003597#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003598#ifdef CONFIG_OWE
3599 if (sta && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE))
3600 buflen += 150;
3601#endif /* CONFIG_OWE */
Hai Shalom021b0b52019-04-10 11:17:58 -07003602#ifdef CONFIG_DPP2
3603 if (sta && sta->dpp_pfs)
3604 buflen += 5 + sta->dpp_pfs->curve->prime_len;
3605#endif /* CONFIG_DPP2 */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003606 buf = os_zalloc(buflen);
3607 if (!buf) {
3608 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3609 goto done;
3610 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003611 reply = (struct ieee80211_mgmt *) buf;
3612 reply->frame_control =
3613 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
3614 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
3615 WLAN_FC_STYPE_ASSOC_RESP));
Dmitry Shmidt29333592017-01-09 12:27:11 -08003616 os_memcpy(reply->da, addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003617 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
3618 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
3619
3620 send_len = IEEE80211_HDRLEN;
3621 send_len += sizeof(reply->u.assoc_resp);
3622 reply->u.assoc_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003623 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003624 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt29333592017-01-09 12:27:11 -08003625
3626 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0) |
3627 BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003628 /* Supported rates */
3629 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
3630 /* Extended supported rates */
3631 p = hostapd_eid_ext_supp_rates(hapd, p);
3632
Hai Shalom74f70d42019-02-11 14:42:39 -08003633#ifdef CONFIG_MBO
3634 if (status_code == WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
3635 rssi != 0) {
3636 int delta = hapd->iconf->rssi_reject_assoc_rssi - rssi;
3637
3638 p = hostapd_eid_mbo_rssi_assoc_rej(hapd, p, buf + buflen - p,
3639 delta);
3640 }
3641#endif /* CONFIG_MBO */
3642
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003643#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt29333592017-01-09 12:27:11 -08003644 if (sta && status_code == WLAN_STATUS_SUCCESS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003645 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
3646 * Transition Information, RSN, [RIC Response] */
3647 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003648 buf + buflen - p,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003649 sta->auth_alg, ies, ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07003650 if (!p) {
3651 wpa_printf(MSG_DEBUG,
3652 "FT: Failed to write AssocResp IEs");
3653 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3654 goto done;
3655 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003656 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003657#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom81f62d82019-07-22 12:10:00 -07003658#ifdef CONFIG_FILS
3659 if (sta && status_code == WLAN_STATUS_SUCCESS &&
3660 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3661 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3662 sta->auth_alg == WLAN_AUTH_FILS_PK))
3663 p = wpa_auth_write_assoc_resp_fils(sta->wpa_sm, p,
3664 buf + buflen - p,
3665 ies, ies_len);
3666#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003667
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003668#ifdef CONFIG_OWE
Hai Shalom74f70d42019-02-11 14:42:39 -08003669 if (sta && status_code == WLAN_STATUS_SUCCESS &&
3670 (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003671 p = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, p,
3672 buf + buflen - p,
3673 ies, ies_len);
3674#endif /* CONFIG_OWE */
3675
Dmitry Shmidt29333592017-01-09 12:27:11 -08003676 if (sta && status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003677 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003678
3679#ifdef CONFIG_IEEE80211N
3680 p = hostapd_eid_ht_capabilities(hapd, p);
3681 p = hostapd_eid_ht_operation(hapd, p);
3682#endif /* CONFIG_IEEE80211N */
3683
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003684#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -07003685 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
3686 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07003687 u32 nsts = 0, sta_nsts;
3688
Dmitry Shmidt29333592017-01-09 12:27:11 -08003689 if (sta && hapd->conf->use_sta_nsts && sta->vht_capabilities) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07003690 struct ieee80211_vht_capabilities *capa;
3691
3692 nsts = (hapd->iface->conf->vht_capab >>
3693 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
3694 capa = sta->vht_capabilities;
3695 sta_nsts = (le_to_host32(capa->vht_capabilities_info) >>
3696 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
3697
3698 if (nsts < sta_nsts)
3699 nsts = 0;
3700 else
3701 nsts = sta_nsts;
3702 }
3703 p = hostapd_eid_vht_capabilities(hapd, p, nsts);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003704 p = hostapd_eid_vht_operation(hapd, p);
3705 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003706#endif /* CONFIG_IEEE80211AC */
3707
Hai Shalom81f62d82019-07-22 12:10:00 -07003708#ifdef CONFIG_IEEE80211AX
3709 if (hapd->iconf->ieee80211ax) {
3710 p = hostapd_eid_he_capab(hapd, p, IEEE80211_MODE_AP);
3711 p = hostapd_eid_he_operation(hapd, p);
3712 p = hostapd_eid_spatial_reuse(hapd, p);
3713 p = hostapd_eid_he_mu_edca_parameter_set(hapd, p);
3714 }
3715#endif /* CONFIG_IEEE80211AX */
3716
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003717 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003718 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt29333592017-01-09 12:27:11 -08003719 if (sta && sta->qos_map_enabled)
Dmitry Shmidt051af732013-10-22 13:52:46 -07003720 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003721
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003722#ifdef CONFIG_FST
3723 if (hapd->iface->fst_ies) {
3724 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
3725 wpabuf_len(hapd->iface->fst_ies));
3726 p += wpabuf_len(hapd->iface->fst_ies);
3727 }
3728#endif /* CONFIG_FST */
3729
Hai Shalomc3565922019-10-28 11:58:20 -07003730 p = hostapd_eid_rsnxe(hapd, p, buf + buflen - p);
3731
Hai Shalom021b0b52019-04-10 11:17:58 -07003732#ifdef CONFIG_OWE
3733 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
3734 sta && sta->owe_ecdh && status_code == WLAN_STATUS_SUCCESS &&
3735 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE) {
3736 struct wpabuf *pub;
3737
3738 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
3739 if (!pub) {
3740 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3741 goto done;
3742 }
3743 /* OWE Diffie-Hellman Parameter element */
3744 *p++ = WLAN_EID_EXTENSION; /* Element ID */
3745 *p++ = 1 + 2 + wpabuf_len(pub); /* Length */
3746 *p++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension */
3747 WPA_PUT_LE16(p, sta->owe_group);
3748 p += 2;
3749 os_memcpy(p, wpabuf_head(pub), wpabuf_len(pub));
3750 p += wpabuf_len(pub);
3751 wpabuf_free(pub);
3752 }
3753#endif /* CONFIG_OWE */
3754
3755#ifdef CONFIG_DPP2
3756 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
3757 sta && sta->dpp_pfs && status_code == WLAN_STATUS_SUCCESS &&
3758 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP) {
3759 os_memcpy(p, wpabuf_head(sta->dpp_pfs->ie),
3760 wpabuf_len(sta->dpp_pfs->ie));
3761 p += wpabuf_len(sta->dpp_pfs->ie);
3762 }
3763#endif /* CONFIG_DPP2 */
3764
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003765#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt29333592017-01-09 12:27:11 -08003766 if (sta && hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003767 p = hostapd_eid_vendor_vht(hapd, p);
3768#endif /* CONFIG_IEEE80211AC */
3769
Dmitry Shmidt29333592017-01-09 12:27:11 -08003770 if (sta && (sta->flags & WLAN_STA_WMM))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003771 p = hostapd_eid_wmm(hapd, p);
3772
3773#ifdef CONFIG_WPS
Dmitry Shmidt29333592017-01-09 12:27:11 -08003774 if (sta &&
3775 ((sta->flags & WLAN_STA_WPS) ||
3776 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003777 struct wpabuf *wps = wps_build_assoc_resp_ie();
3778 if (wps) {
3779 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
3780 p += wpabuf_len(wps);
3781 wpabuf_free(wps);
3782 }
3783 }
3784#endif /* CONFIG_WPS */
3785
Hai Shalom74f70d42019-02-11 14:42:39 -08003786 if (sta && (sta->flags & WLAN_STA_MULTI_AP))
3787 p = hostapd_eid_multi_ap(hapd, p);
3788
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003789#ifdef CONFIG_P2P
Dmitry Shmidt29333592017-01-09 12:27:11 -08003790 if (sta && sta->p2p_ie && hapd->p2p_group) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003791 struct wpabuf *p2p_resp_ie;
3792 enum p2p_status_code status;
3793 switch (status_code) {
3794 case WLAN_STATUS_SUCCESS:
3795 status = P2P_SC_SUCCESS;
3796 break;
3797 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
3798 status = P2P_SC_FAIL_LIMIT_REACHED;
3799 break;
3800 default:
3801 status = P2P_SC_FAIL_INVALID_PARAMS;
3802 break;
3803 }
3804 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
3805 if (p2p_resp_ie) {
3806 os_memcpy(p, wpabuf_head(p2p_resp_ie),
3807 wpabuf_len(p2p_resp_ie));
3808 p += wpabuf_len(p2p_resp_ie);
3809 wpabuf_free(p2p_resp_ie);
3810 }
3811 }
3812#endif /* CONFIG_P2P */
3813
3814#ifdef CONFIG_P2P_MANAGER
3815 if (hapd->conf->p2p & P2P_MANAGE)
3816 p = hostapd_eid_p2p_manage(hapd, p);
3817#endif /* CONFIG_P2P_MANAGER */
3818
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003819 p = hostapd_eid_mbo(hapd, p, buf + buflen - p);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003820
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003821 if (hapd->conf->assocresp_elements &&
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003822 (size_t) (buf + buflen - p) >=
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003823 wpabuf_len(hapd->conf->assocresp_elements)) {
3824 os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements),
3825 wpabuf_len(hapd->conf->assocresp_elements));
3826 p += wpabuf_len(hapd->conf->assocresp_elements);
3827 }
3828
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003829 send_len += p - reply->u.assoc_resp.variable;
3830
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003831#ifdef CONFIG_FILS
Dmitry Shmidt29333592017-01-09 12:27:11 -08003832 if (sta &&
3833 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003834 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3835 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
3836 status_code == WLAN_STATUS_SUCCESS) {
3837 struct ieee802_11_elems elems;
3838
3839 if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003840 ParseFailed || !elems.fils_session) {
3841 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3842 goto done;
3843 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003844
3845 /* FILS Session */
3846 *p++ = WLAN_EID_EXTENSION; /* Element ID */
3847 *p++ = 1 + FILS_SESSION_LEN; /* Length */
3848 *p++ = WLAN_EID_EXT_FILS_SESSION; /* Element ID Extension */
3849 os_memcpy(p, elems.fils_session, FILS_SESSION_LEN);
3850 send_len += 2 + 1 + FILS_SESSION_LEN;
3851
3852 send_len = fils_encrypt_assoc(sta->wpa_sm, buf, send_len,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003853 buflen, sta->fils_hlp_resp);
3854 if (send_len < 0) {
3855 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3856 goto done;
3857 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003858 }
3859#endif /* CONFIG_FILS */
3860
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003861 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003862 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
3863 strerror(errno));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003864 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003865 }
3866
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003867done:
3868 os_free(buf);
3869 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003870}
3871
3872
Roshan Pius3a1667e2018-07-03 15:17:14 -07003873#ifdef CONFIG_OWE
3874u8 * owe_assoc_req_process(struct hostapd_data *hapd, struct sta_info *sta,
3875 const u8 *owe_dh, u8 owe_dh_len,
3876 u8 *owe_buf, size_t owe_buf_len, u16 *reason)
3877{
3878#ifdef CONFIG_TESTING_OPTIONS
3879 if (hapd->conf->own_ie_override) {
3880 wpa_printf(MSG_DEBUG, "OWE: Using IE override");
3881 *reason = WLAN_STATUS_SUCCESS;
3882 return wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3883 owe_buf_len, NULL, 0);
3884 }
3885#endif /* CONFIG_TESTING_OPTIONS */
3886
3887 if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) {
3888 wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching");
3889 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3890 owe_buf_len, NULL, 0);
3891 *reason = WLAN_STATUS_SUCCESS;
3892 return owe_buf;
3893 }
3894
Hai Shalom81f62d82019-07-22 12:10:00 -07003895 if (sta->owe_pmk && sta->external_dh_updated) {
3896 wpa_printf(MSG_DEBUG, "OWE: Using previously derived PMK");
3897 *reason = WLAN_STATUS_SUCCESS;
3898 return owe_buf;
3899 }
3900
Roshan Pius3a1667e2018-07-03 15:17:14 -07003901 *reason = owe_process_assoc_req(hapd, sta, owe_dh, owe_dh_len);
3902 if (*reason != WLAN_STATUS_SUCCESS)
3903 return NULL;
3904
3905 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3906 owe_buf_len, NULL, 0);
3907
3908 if (sta->owe_ecdh && owe_buf) {
3909 struct wpabuf *pub;
3910
3911 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
3912 if (!pub) {
3913 *reason = WLAN_STATUS_UNSPECIFIED_FAILURE;
3914 return owe_buf;
3915 }
3916
3917 /* OWE Diffie-Hellman Parameter element */
3918 *owe_buf++ = WLAN_EID_EXTENSION; /* Element ID */
3919 *owe_buf++ = 1 + 2 + wpabuf_len(pub); /* Length */
3920 *owe_buf++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension
3921 */
3922 WPA_PUT_LE16(owe_buf, sta->owe_group);
3923 owe_buf += 2;
3924 os_memcpy(owe_buf, wpabuf_head(pub), wpabuf_len(pub));
3925 owe_buf += wpabuf_len(pub);
3926 wpabuf_free(pub);
3927 }
3928
3929 return owe_buf;
3930}
3931#endif /* CONFIG_OWE */
3932
3933
Paul Stewart092955c2017-02-06 09:13:09 -08003934#ifdef CONFIG_FILS
3935
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003936void fils_hlp_finish_assoc(struct hostapd_data *hapd, struct sta_info *sta)
Paul Stewart092955c2017-02-06 09:13:09 -08003937{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003938 u16 reply_res;
Paul Stewart092955c2017-02-06 09:13:09 -08003939
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003940 wpa_printf(MSG_DEBUG, "FILS: Finish association with " MACSTR,
3941 MAC2STR(sta->addr));
3942 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
3943 if (!sta->fils_pending_assoc_req)
Paul Stewart092955c2017-02-06 09:13:09 -08003944 return;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003945 reply_res = send_assoc_resp(hapd, sta, sta->addr, WLAN_STATUS_SUCCESS,
3946 sta->fils_pending_assoc_is_reassoc,
3947 sta->fils_pending_assoc_req,
Hai Shalom74f70d42019-02-11 14:42:39 -08003948 sta->fils_pending_assoc_req_len, 0);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003949 os_free(sta->fils_pending_assoc_req);
3950 sta->fils_pending_assoc_req = NULL;
3951 sta->fils_pending_assoc_req_len = 0;
3952 wpabuf_free(sta->fils_hlp_resp);
3953 sta->fils_hlp_resp = NULL;
3954 wpabuf_free(sta->hlp_dhcp_discover);
3955 sta->hlp_dhcp_discover = NULL;
Paul Stewart092955c2017-02-06 09:13:09 -08003956
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003957 /*
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003958 * Remove the station in case transmission of a success response fails.
3959 * At this point the station was already added associated to the driver.
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003960 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003961 if (reply_res != WLAN_STATUS_SUCCESS)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003962 hostapd_drv_sta_remove(hapd, sta->addr);
Paul Stewart092955c2017-02-06 09:13:09 -08003963}
3964
3965
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003966void fils_hlp_timeout(void *eloop_ctx, void *eloop_data)
Paul Stewart092955c2017-02-06 09:13:09 -08003967{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003968 struct hostapd_data *hapd = eloop_ctx;
3969 struct sta_info *sta = eloop_data;
Paul Stewart092955c2017-02-06 09:13:09 -08003970
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003971 wpa_printf(MSG_DEBUG,
3972 "FILS: HLP response timeout - continue with association response for "
3973 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003974 if (sta->fils_drv_assoc_finish)
3975 hostapd_notify_assoc_fils_finish(hapd, sta);
3976 else
3977 fils_hlp_finish_assoc(hapd, sta);
Paul Stewart092955c2017-02-06 09:13:09 -08003978}
3979
3980#endif /* CONFIG_FILS */
3981
3982
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003983static void handle_assoc(struct hostapd_data *hapd,
3984 const struct ieee80211_mgmt *mgmt, size_t len,
Hai Shalom74f70d42019-02-11 14:42:39 -08003985 int reassoc, int rssi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003986{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003987 u16 capab_info, listen_interval, seq_ctrl, fc;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003988 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003989 const u8 *pos;
3990 int left, i;
3991 struct sta_info *sta;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003992 u8 *tmp = NULL;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003993 struct hostapd_sta_wpa_psk_short *psk = NULL;
3994 char *identity = NULL;
3995 char *radius_cui = NULL;
3996#ifdef CONFIG_FILS
3997 int delay_assoc = 0;
3998#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003999
4000 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
4001 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004002 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
4003 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004004 return;
4005 }
4006
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004007#ifdef CONFIG_TESTING_OPTIONS
4008 if (reassoc) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004009 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004010 drand48() < hapd->iconf->ignore_reassoc_probability) {
4011 wpa_printf(MSG_INFO,
4012 "TESTING: ignoring reassoc request from "
4013 MACSTR, MAC2STR(mgmt->sa));
4014 return;
4015 }
4016 } else {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004017 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004018 drand48() < hapd->iconf->ignore_assoc_probability) {
4019 wpa_printf(MSG_INFO,
4020 "TESTING: ignoring assoc request from "
4021 MACSTR, MAC2STR(mgmt->sa));
4022 return;
4023 }
4024 }
4025#endif /* CONFIG_TESTING_OPTIONS */
4026
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004027 fc = le_to_host16(mgmt->frame_control);
4028 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
4029
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004030 if (reassoc) {
4031 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
4032 listen_interval = le_to_host16(
4033 mgmt->u.reassoc_req.listen_interval);
4034 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
4035 " capab_info=0x%02x listen_interval=%d current_ap="
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004036 MACSTR " seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004037 MAC2STR(mgmt->sa), capab_info, listen_interval,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004038 MAC2STR(mgmt->u.reassoc_req.current_ap),
4039 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004040 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
4041 pos = mgmt->u.reassoc_req.variable;
4042 } else {
4043 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
4044 listen_interval = le_to_host16(
4045 mgmt->u.assoc_req.listen_interval);
4046 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004047 " capab_info=0x%02x listen_interval=%d "
4048 "seq_ctrl=0x%x%s",
4049 MAC2STR(mgmt->sa), capab_info, listen_interval,
4050 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004051 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
4052 pos = mgmt->u.assoc_req.variable;
4053 }
4054
4055 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004056#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004057 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
4058 (sta->flags & WLAN_STA_AUTH) == 0) {
4059 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
4060 "prior to authentication since it is using "
4061 "over-the-DS FT", MAC2STR(mgmt->sa));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004062
4063 /*
4064 * Mark station as authenticated, to avoid adding station
4065 * entry in the driver as associated and not authenticated
4066 */
4067 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004068 } else
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004069#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004070 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08004071 if (hapd->iface->current_mode &&
4072 hapd->iface->current_mode->mode ==
4073 HOSTAPD_MODE_IEEE80211AD) {
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004074 int acl_res;
4075 u32 session_timeout, acct_interim_interval;
4076 struct vlan_description vlan_id;
4077
4078 acl_res = ieee802_11_allowed_address(
4079 hapd, mgmt->sa, (const u8 *) mgmt, len,
4080 &session_timeout, &acct_interim_interval,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004081 &vlan_id, &psk, &identity, &radius_cui, 0);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004082 if (acl_res == HOSTAPD_ACL_REJECT) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004083 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
4084 "Ignore Association Request frame from "
4085 MACSTR " due to ACL reject",
4086 MAC2STR(mgmt->sa));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004087 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
4088 goto fail;
4089 }
4090 if (acl_res == HOSTAPD_ACL_PENDING)
4091 return;
4092
Dmitry Shmidt29333592017-01-09 12:27:11 -08004093 /* DMG/IEEE 802.11ad does not use authentication.
4094 * Allocate sta entry upon association. */
4095 sta = ap_sta_add(hapd, mgmt->sa);
4096 if (!sta) {
4097 hostapd_logger(hapd, mgmt->sa,
4098 HOSTAPD_MODULE_IEEE80211,
4099 HOSTAPD_LEVEL_INFO,
4100 "Failed to add STA");
4101 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
4102 goto fail;
4103 }
4104
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004105 acl_res = ieee802_11_set_radius_info(
4106 hapd, sta, acl_res, session_timeout,
4107 acct_interim_interval, &vlan_id, &psk,
4108 &identity, &radius_cui);
4109 if (acl_res) {
4110 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
4111 goto fail;
4112 }
4113
Dmitry Shmidt29333592017-01-09 12:27:11 -08004114 hostapd_logger(hapd, sta->addr,
4115 HOSTAPD_MODULE_IEEE80211,
4116 HOSTAPD_LEVEL_DEBUG,
4117 "Skip authentication for DMG/IEEE 802.11ad");
4118 sta->flags |= WLAN_STA_AUTH;
4119 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
4120 sta->auth_alg = WLAN_AUTH_OPEN;
4121 } else {
4122 hostapd_logger(hapd, mgmt->sa,
4123 HOSTAPD_MODULE_IEEE80211,
4124 HOSTAPD_LEVEL_INFO,
4125 "Station tried to associate before authentication (aid=%d flags=0x%x)",
4126 sta ? sta->aid : -1,
4127 sta ? sta->flags : 0);
4128 send_deauth(hapd, mgmt->sa,
4129 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
4130 return;
4131 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004132 }
4133
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004134 if ((fc & WLAN_FC_RETRY) &&
4135 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
4136 sta->last_seq_ctrl == seq_ctrl &&
Paul Stewart092955c2017-02-06 09:13:09 -08004137 sta->last_subtype == (reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
4138 WLAN_FC_STYPE_ASSOC_REQ)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004139 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4140 HOSTAPD_LEVEL_DEBUG,
4141 "Drop repeated association frame seq_ctrl=0x%x",
4142 seq_ctrl);
4143 return;
4144 }
4145 sta->last_seq_ctrl = seq_ctrl;
4146 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
4147 WLAN_FC_STYPE_ASSOC_REQ;
4148
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004149 if (hapd->tkip_countermeasures) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004150 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004151 goto fail;
4152 }
4153
4154 if (listen_interval > hapd->conf->max_listen_interval) {
4155 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4156 HOSTAPD_LEVEL_DEBUG,
4157 "Too large Listen Interval (%d)",
4158 listen_interval);
4159 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
4160 goto fail;
4161 }
4162
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004163#ifdef CONFIG_MBO
4164 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
4165 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
4166 goto fail;
4167 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004168
4169 if (hapd->iconf->rssi_reject_assoc_rssi && rssi &&
4170 rssi < hapd->iconf->rssi_reject_assoc_rssi &&
4171 (sta->auth_rssi == 0 ||
4172 sta->auth_rssi < hapd->iconf->rssi_reject_assoc_rssi)) {
4173 resp = WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS;
4174 goto fail;
4175 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004176#endif /* CONFIG_MBO */
4177
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004178 /*
4179 * sta->capability is used in check_assoc_ies() for RRM enabled
4180 * capability element.
4181 */
4182 sta->capability = capab_info;
4183
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004184#ifdef CONFIG_FILS
4185 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
4186 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
4187 sta->auth_alg == WLAN_AUTH_FILS_PK) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004188 int res;
4189
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004190 /* The end of the payload is encrypted. Need to decrypt it
4191 * before parsing. */
4192
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004193 tmp = os_memdup(pos, left);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004194 if (!tmp) {
4195 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
4196 goto fail;
4197 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004198
Roshan Pius3a1667e2018-07-03 15:17:14 -07004199 res = fils_decrypt_assoc(sta->wpa_sm, sta->fils_session, mgmt,
4200 len, tmp, left);
4201 if (res < 0) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004202 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
4203 goto fail;
4204 }
4205 pos = tmp;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004206 left = res;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004207 }
4208#endif /* CONFIG_FILS */
4209
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004210 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
4211 * is used */
4212 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
4213 if (resp != WLAN_STATUS_SUCCESS)
4214 goto fail;
4215
4216 if (hostapd_get_aid(hapd, sta) < 0) {
4217 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4218 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
4219 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
4220 goto fail;
4221 }
4222
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004223 sta->listen_interval = listen_interval;
4224
Roshan Pius3a1667e2018-07-03 15:17:14 -07004225 if (hapd->iface->current_mode &&
4226 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004227 sta->flags |= WLAN_STA_NONERP;
4228 for (i = 0; i < sta->supported_rates_len; i++) {
4229 if ((sta->supported_rates[i] & 0x7f) > 22) {
4230 sta->flags &= ~WLAN_STA_NONERP;
4231 break;
4232 }
4233 }
4234 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
4235 sta->nonerp_set = 1;
4236 hapd->iface->num_sta_non_erp++;
4237 if (hapd->iface->num_sta_non_erp == 1)
4238 ieee802_11_set_beacons(hapd->iface);
4239 }
4240
4241 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
4242 !sta->no_short_slot_time_set) {
4243 sta->no_short_slot_time_set = 1;
4244 hapd->iface->num_sta_no_short_slot_time++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004245 if (hapd->iface->current_mode &&
4246 hapd->iface->current_mode->mode ==
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004247 HOSTAPD_MODE_IEEE80211G &&
4248 hapd->iface->num_sta_no_short_slot_time == 1)
4249 ieee802_11_set_beacons(hapd->iface);
4250 }
4251
4252 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
4253 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
4254 else
4255 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
4256
4257 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
4258 !sta->no_short_preamble_set) {
4259 sta->no_short_preamble_set = 1;
4260 hapd->iface->num_sta_no_short_preamble++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004261 if (hapd->iface->current_mode &&
4262 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004263 && hapd->iface->num_sta_no_short_preamble == 1)
4264 ieee802_11_set_beacons(hapd->iface);
4265 }
4266
4267#ifdef CONFIG_IEEE80211N
4268 update_ht_state(hapd, sta);
4269#endif /* CONFIG_IEEE80211N */
4270
4271 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4272 HOSTAPD_LEVEL_DEBUG,
4273 "association OK (aid %d)", sta->aid);
4274 /* Station will be marked associated, after it acknowledges AssocResp
4275 */
4276 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
4277
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004278 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
4279 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
4280 "SA Query procedure", reassoc ? "re" : "");
4281 /* TODO: Send a protected Disassociate frame to the STA using
4282 * the old key and Reason Code "Previous Authentication no
4283 * longer valid". Make sure this is only sent protected since
4284 * unprotected frame would be received by the STA that is now
4285 * trying to associate.
4286 */
4287 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004289 /* Make sure that the previously registered inactivity timer will not
4290 * remove the STA immediately. */
4291 sta->timeout_next = STA_NULLFUNC;
4292
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004293#ifdef CONFIG_TAXONOMY
4294 taxonomy_sta_info_assoc_req(hapd, sta, pos, left);
4295#endif /* CONFIG_TAXONOMY */
4296
Dmitry Shmidt29333592017-01-09 12:27:11 -08004297 sta->pending_wds_enable = 0;
4298
Paul Stewart092955c2017-02-06 09:13:09 -08004299#ifdef CONFIG_FILS
4300 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
4301 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004302 sta->auth_alg == WLAN_AUTH_FILS_PK) {
4303 if (fils_process_hlp(hapd, sta, pos, left) > 0)
4304 delay_assoc = 1;
4305 }
Paul Stewart092955c2017-02-06 09:13:09 -08004306#endif /* CONFIG_FILS */
4307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004308 fail:
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004309 os_free(identity);
4310 os_free(radius_cui);
4311 hostapd_free_psk_list(psk);
4312
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004313 /*
4314 * In case of a successful response, add the station to the driver.
4315 * Otherwise, the kernel may ignore Data frames before we process the
4316 * ACK frame (TX status). In case of a failure, this station will be
4317 * removed.
4318 *
4319 * Note that this is not compliant with the IEEE 802.11 standard that
4320 * states that a non-AP station should transition into the
4321 * authenticated/associated state only after the station acknowledges
4322 * the (Re)Association Response frame. However, still do this as:
4323 *
4324 * 1. In case the station does not acknowledge the (Re)Association
4325 * Response frame, it will be removed.
4326 * 2. Data frames will be dropped in the kernel until the station is
4327 * set into authorized state, and there are no significant known
4328 * issues with processing other non-Data Class 3 frames during this
4329 * window.
4330 */
Hai Shalom74f70d42019-02-11 14:42:39 -08004331 if (resp == WLAN_STATUS_SUCCESS && sta &&
4332 add_associated_sta(hapd, sta, reassoc))
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004333 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
4334
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004335#ifdef CONFIG_FILS
Hai Shalom74f70d42019-02-11 14:42:39 -08004336 if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS &&
4337 eloop_is_timeout_registered(fils_hlp_timeout, hapd, sta) &&
4338 sta->fils_pending_assoc_req) {
4339 /* Do not reschedule fils_hlp_timeout in case the station
4340 * retransmits (Re)Association Request frame while waiting for
4341 * the previously started FILS HLP wait, so that the timeout can
4342 * be determined from the first pending attempt. */
4343 wpa_printf(MSG_DEBUG,
4344 "FILS: Continue waiting for HLP processing before sending (Re)Association Response frame to "
4345 MACSTR, MAC2STR(sta->addr));
4346 os_free(tmp);
4347 return;
4348 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004349 if (sta) {
4350 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
4351 os_free(sta->fils_pending_assoc_req);
4352 sta->fils_pending_assoc_req = NULL;
4353 sta->fils_pending_assoc_req_len = 0;
4354 wpabuf_free(sta->fils_hlp_resp);
4355 sta->fils_hlp_resp = NULL;
4356 }
4357 if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS) {
4358 sta->fils_pending_assoc_req = tmp;
4359 sta->fils_pending_assoc_req_len = left;
4360 sta->fils_pending_assoc_is_reassoc = reassoc;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004361 sta->fils_drv_assoc_finish = 0;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004362 wpa_printf(MSG_DEBUG,
4363 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
4364 MACSTR, MAC2STR(sta->addr));
4365 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
4366 eloop_register_timeout(0, hapd->conf->fils_hlp_wait_time * 1024,
4367 fils_hlp_timeout, hapd, sta);
4368 return;
4369 }
4370#endif /* CONFIG_FILS */
4371
Dmitry Shmidt29333592017-01-09 12:27:11 -08004372 reply_res = send_assoc_resp(hapd, sta, mgmt->sa, resp, reassoc, pos,
Hai Shalom74f70d42019-02-11 14:42:39 -08004373 left, rssi);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004374 os_free(tmp);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004375
4376 /*
4377 * Remove the station in case tranmission of a success response fails
4378 * (the STA was added associated to the driver) or if the station was
4379 * previously added unassociated.
4380 */
Dmitry Shmidt29333592017-01-09 12:27:11 -08004381 if (sta && ((reply_res != WLAN_STATUS_SUCCESS &&
4382 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004383 hostapd_drv_sta_remove(hapd, sta->addr);
4384 sta->added_unassoc = 0;
4385 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004386}
4387
4388
4389static void handle_disassoc(struct hostapd_data *hapd,
4390 const struct ieee80211_mgmt *mgmt, size_t len)
4391{
4392 struct sta_info *sta;
4393
4394 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004395 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
4396 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004397 return;
4398 }
4399
4400 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
4401 MAC2STR(mgmt->sa),
4402 le_to_host16(mgmt->u.disassoc.reason_code));
4403
4404 sta = ap_get_sta(hapd, mgmt->sa);
4405 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004406 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
4407 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004408 return;
4409 }
4410
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004411 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004412 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004413 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004414 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
4415 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4416 HOSTAPD_LEVEL_INFO, "disassociated");
4417 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
4418 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
4419 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
4420 * authenticated. */
4421 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -08004422 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004423 if (sta->ipaddr)
4424 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
4425 ap_sta_ip6addr_del(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004426 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004427 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004428
4429 if (sta->timeout_next == STA_NULLFUNC ||
4430 sta->timeout_next == STA_DISASSOC) {
4431 sta->timeout_next = STA_DEAUTH;
4432 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
4433 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
4434 hapd, sta);
4435 }
4436
4437 mlme_disassociate_indication(
4438 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
Dmitry Shmidt29333592017-01-09 12:27:11 -08004439
4440 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
4441 * disassociation. */
4442 if (hapd->iface->current_mode &&
4443 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
4444 sta->flags &= ~WLAN_STA_AUTH;
4445 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
4446 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4447 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
4448 ap_free_sta(hapd, sta);
4449 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004450}
4451
4452
4453static void handle_deauth(struct hostapd_data *hapd,
4454 const struct ieee80211_mgmt *mgmt, size_t len)
4455{
4456 struct sta_info *sta;
4457
4458 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004459 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
4460 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004461 return;
4462 }
4463
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004464 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004465 " reason_code=%d",
4466 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
4467
4468 sta = ap_get_sta(hapd, mgmt->sa);
4469 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004470 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
4471 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004472 MAC2STR(mgmt->sa));
4473 return;
4474 }
4475
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004476 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004477 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004478 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
4479 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004480 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
4481 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4482 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
4483 mlme_deauthenticate_indication(
4484 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
4485 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
4486 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
4487 ap_free_sta(hapd, sta);
4488}
4489
4490
4491static void handle_beacon(struct hostapd_data *hapd,
4492 const struct ieee80211_mgmt *mgmt, size_t len,
4493 struct hostapd_frame_info *fi)
4494{
4495 struct ieee802_11_elems elems;
4496
4497 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004498 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
4499 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004500 return;
4501 }
4502
4503 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
4504 len - (IEEE80211_HDRLEN +
4505 sizeof(mgmt->u.beacon)), &elems,
4506 0);
4507
4508 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
4509}
4510
4511
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004512static int robust_action_frame(u8 category)
4513{
4514 return category != WLAN_ACTION_PUBLIC &&
4515 category != WLAN_ACTION_HT;
4516}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004517
4518
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004519static int handle_action(struct hostapd_data *hapd,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004520 const struct ieee80211_mgmt *mgmt, size_t len,
4521 unsigned int freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004522{
4523 struct sta_info *sta;
Hai Shalom74f70d42019-02-11 14:42:39 -08004524 u8 *action __maybe_unused;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004525
Hai Shalom74f70d42019-02-11 14:42:39 -08004526 if (len < IEEE80211_HDRLEN + 2 + 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004527 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4528 HOSTAPD_LEVEL_DEBUG,
4529 "handle_action - too short payload (len=%lu)",
4530 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004531 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004532 }
4533
Hai Shalom74f70d42019-02-11 14:42:39 -08004534 action = (u8 *) &mgmt->u.action.u;
4535 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
4536 " da " MACSTR " len %d freq %u",
4537 mgmt->u.action.category, *action,
4538 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) len, freq);
4539
4540 sta = ap_get_sta(hapd, mgmt->sa);
4541
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004542 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
4543 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
4544 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
4545 "frame (category=%u) from unassociated STA " MACSTR,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08004546 mgmt->u.action.category, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004547 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004548 }
4549
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004550 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08004551 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
4552 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004553 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4554 HOSTAPD_LEVEL_DEBUG,
4555 "Dropped unprotected Robust Action frame from "
4556 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004557 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004558 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004559
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004560 if (sta) {
4561 u16 fc = le_to_host16(mgmt->frame_control);
4562 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
4563
4564 if ((fc & WLAN_FC_RETRY) &&
4565 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
4566 sta->last_seq_ctrl == seq_ctrl &&
4567 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
4568 hostapd_logger(hapd, sta->addr,
4569 HOSTAPD_MODULE_IEEE80211,
4570 HOSTAPD_LEVEL_DEBUG,
4571 "Drop repeated action frame seq_ctrl=0x%x",
4572 seq_ctrl);
4573 return 1;
4574 }
4575
4576 sta->last_seq_ctrl = seq_ctrl;
4577 sta->last_subtype = WLAN_FC_STYPE_ACTION;
4578 }
4579
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004580 switch (mgmt->u.action.category) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004581#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004582 case WLAN_ACTION_FT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004583 if (!sta ||
4584 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004585 len - IEEE80211_HDRLEN))
4586 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004587 return 1;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004588#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004589 case WLAN_ACTION_WMM:
4590 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004591 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004592 case WLAN_ACTION_SA_QUERY:
Hai Shalom021b0b52019-04-10 11:17:58 -07004593 ieee802_11_sa_query_action(hapd, mgmt, len);
4594 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004595#ifdef CONFIG_WNM_AP
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004596 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004597 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
4598 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004599#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004600#ifdef CONFIG_FST
4601 case WLAN_ACTION_FST:
4602 if (hapd->iface->fst)
4603 fst_rx_action(hapd->iface->fst, mgmt, len);
4604 else
4605 wpa_printf(MSG_DEBUG,
4606 "FST: Ignore FST Action frame - no FST attached");
4607 return 1;
4608#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004609 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08004610 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004611#ifdef CONFIG_IEEE80211N
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07004612 if (len >= IEEE80211_HDRLEN + 2 &&
4613 mgmt->u.action.u.public_action.action ==
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004614 WLAN_PA_20_40_BSS_COEX) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004615 hostapd_2040_coex_action(hapd, mgmt, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004616 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07004617 }
4618#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004619#ifdef CONFIG_DPP
4620 if (len >= IEEE80211_HDRLEN + 6 &&
4621 mgmt->u.action.u.vs_public_action.action ==
4622 WLAN_PA_VENDOR_SPECIFIC &&
4623 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
4624 OUI_WFA &&
4625 mgmt->u.action.u.vs_public_action.variable[0] ==
4626 DPP_OUI_TYPE) {
4627 const u8 *pos, *end;
4628
4629 pos = mgmt->u.action.u.vs_public_action.oui;
4630 end = ((const u8 *) mgmt) + len;
4631 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004632 freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004633 return 1;
4634 }
4635 if (len >= IEEE80211_HDRLEN + 2 &&
4636 (mgmt->u.action.u.public_action.action ==
4637 WLAN_PA_GAS_INITIAL_RESP ||
4638 mgmt->u.action.u.public_action.action ==
4639 WLAN_PA_GAS_COMEBACK_RESP)) {
4640 const u8 *pos, *end;
4641
4642 pos = &mgmt->u.action.u.public_action.action;
4643 end = ((const u8 *) mgmt) + len;
4644 gas_query_ap_rx(hapd->gas, mgmt->sa,
4645 mgmt->u.action.category,
4646 pos, end - pos, hapd->iface->freq);
4647 return 1;
4648 }
4649#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004650 if (hapd->public_action_cb) {
4651 hapd->public_action_cb(hapd->public_action_cb_ctx,
4652 (u8 *) mgmt, len,
4653 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004654 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004655 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004656 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08004657 (u8 *) mgmt, len,
4658 hapd->iface->freq);
4659 }
4660 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004661 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004662 break;
4663 case WLAN_ACTION_VENDOR_SPECIFIC:
4664 if (hapd->vendor_action_cb) {
4665 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
4666 (u8 *) mgmt, len,
4667 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004668 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004669 }
4670 break;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004671 case WLAN_ACTION_RADIO_MEASUREMENT:
4672 hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len);
4673 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004674 }
4675
4676 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4677 HOSTAPD_LEVEL_DEBUG,
4678 "handle_action - unknown action category %d or invalid "
4679 "frame",
4680 mgmt->u.action.category);
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004681 if (!is_multicast_ether_addr(mgmt->da) &&
4682 !(mgmt->u.action.category & 0x80) &&
4683 !is_multicast_ether_addr(mgmt->sa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004684 struct ieee80211_mgmt *resp;
4685
4686 /*
4687 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
4688 * Return the Action frame to the source without change
4689 * except that MSB of the Category set to 1.
4690 */
4691 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
4692 "frame back to sender");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004693 resp = os_memdup(mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004694 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004695 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004696 os_memcpy(resp->da, resp->sa, ETH_ALEN);
4697 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
4698 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
4699 resp->u.action.category |= 0x80;
4700
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004701 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
4702 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
4703 "Action frame");
4704 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004705 os_free(resp);
4706 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004707
4708 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004709}
4710
4711
4712/**
4713 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
4714 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
4715 * sent to)
4716 * @buf: management frame data (starting from IEEE 802.11 header)
4717 * @len: length of frame data in octets
4718 * @fi: meta data about received frame (signal level, etc.)
4719 *
4720 * Process all incoming IEEE 802.11 management frames. This will be called for
4721 * each frame received from the kernel driver through wlan#ap interface. In
4722 * addition, it can be called to re-inserted pending frames (e.g., when using
4723 * external RADIUS server as an MAC ACL).
4724 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004725int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
4726 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004727{
4728 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004729 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004730 int ret = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004731 unsigned int freq;
4732 int ssi_signal = fi ? fi->ssi_signal : 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004733
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004734 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004735 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004736
Roshan Pius3a1667e2018-07-03 15:17:14 -07004737 if (fi && fi->freq)
4738 freq = fi->freq;
4739 else
4740 freq = hapd->iface->freq;
4741
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004742 mgmt = (struct ieee80211_mgmt *) buf;
4743 fc = le_to_host16(mgmt->frame_control);
4744 stype = WLAN_FC_GET_STYPE(fc);
4745
Hai Shalomc3565922019-10-28 11:58:20 -07004746 if (is_multicast_ether_addr(mgmt->sa) ||
4747 is_zero_ether_addr(mgmt->sa) ||
4748 os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
4749 /* Do not process any frames with unexpected/invalid SA so that
4750 * we do not add any state for unexpected STA addresses or end
4751 * up sending out frames to unexpected destination. */
4752 wpa_printf(MSG_DEBUG, "MGMT: Invalid SA=" MACSTR
4753 " in received frame - ignore this frame silently",
4754 MAC2STR(mgmt->sa));
4755 return 0;
4756 }
4757
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004758 if (stype == WLAN_FC_STYPE_BEACON) {
4759 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004760 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004761 }
4762
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07004763 if (!is_broadcast_ether_addr(mgmt->bssid) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004764#ifdef CONFIG_P2P
4765 /* Invitation responses can be sent with the peer MAC as BSSID */
4766 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
4767 stype == WLAN_FC_STYPE_ACTION) &&
4768#endif /* CONFIG_P2P */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004769#ifdef CONFIG_MESH
4770 !(hapd->conf->mesh & MESH_ENABLED) &&
4771#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004772 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004773 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
4774 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004775 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004776 }
4777
4778
4779 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004780 handle_probe_req(hapd, mgmt, len, ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004781 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004782 }
4783
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004784 if ((!is_broadcast_ether_addr(mgmt->da) ||
4785 stype != WLAN_FC_STYPE_ACTION) &&
4786 os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004787 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4788 HOSTAPD_LEVEL_DEBUG,
4789 "MGMT: DA=" MACSTR " not our address",
4790 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004791 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004792 }
4793
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004794 if (hapd->iconf->track_sta_max_num)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004795 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004796
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004797 switch (stype) {
4798 case WLAN_FC_STYPE_AUTH:
4799 wpa_printf(MSG_DEBUG, "mgmt::auth");
Hai Shalom021b0b52019-04-10 11:17:58 -07004800 handle_auth(hapd, mgmt, len, ssi_signal, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004801 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004802 break;
4803 case WLAN_FC_STYPE_ASSOC_REQ:
4804 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
Hai Shalom74f70d42019-02-11 14:42:39 -08004805 handle_assoc(hapd, mgmt, len, 0, ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004806 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004807 break;
4808 case WLAN_FC_STYPE_REASSOC_REQ:
4809 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
Hai Shalom74f70d42019-02-11 14:42:39 -08004810 handle_assoc(hapd, mgmt, len, 1, ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004811 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004812 break;
4813 case WLAN_FC_STYPE_DISASSOC:
4814 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
4815 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004816 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004817 break;
4818 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004819 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004820 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004821 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004822 break;
4823 case WLAN_FC_STYPE_ACTION:
4824 wpa_printf(MSG_DEBUG, "mgmt::action");
Roshan Pius3a1667e2018-07-03 15:17:14 -07004825 ret = handle_action(hapd, mgmt, len, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004826 break;
4827 default:
4828 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4829 HOSTAPD_LEVEL_DEBUG,
4830 "unknown mgmt frame subtype %d", stype);
4831 break;
4832 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004833
4834 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004835}
4836
4837
4838static void handle_auth_cb(struct hostapd_data *hapd,
4839 const struct ieee80211_mgmt *mgmt,
4840 size_t len, int ok)
4841{
4842 u16 auth_alg, auth_transaction, status_code;
4843 struct sta_info *sta;
4844
Hai Shalome5e28bb2019-01-28 14:51:04 -08004845 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
4846 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
4847 (unsigned long) len);
4848
4849 /*
4850 * Initialize status_code here because we are not able to read
4851 * it from the short payload.
4852 */
4853 status_code = WLAN_STATUS_UNSPECIFIED_FAILURE;
4854 goto fail;
4855 }
4856
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004857 sta = ap_get_sta(hapd, mgmt->da);
4858 if (!sta) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004859 wpa_printf(MSG_DEBUG, "handle_auth_cb: STA " MACSTR
4860 " not found",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004861 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004862 return;
4863 }
4864
4865 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
4866 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
4867 status_code = le_to_host16(mgmt->u.auth.status_code);
4868
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004869 if (!ok) {
4870 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
4871 HOSTAPD_LEVEL_NOTICE,
4872 "did not acknowledge authentication response");
4873 goto fail;
4874 }
4875
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004876 if (status_code == WLAN_STATUS_SUCCESS &&
4877 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
4878 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
4879 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4880 HOSTAPD_LEVEL_INFO, "authenticated");
4881 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004882 if (sta->added_unassoc)
4883 hostapd_set_sta_flags(hapd, sta);
4884 return;
4885 }
4886
4887fail:
4888 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
4889 hostapd_drv_sta_remove(hapd, sta->addr);
4890 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004891 }
4892}
4893
4894
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004895static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
4896 struct sta_info *sta,
4897 char *ifname_wds)
4898{
4899 int i;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07004900 struct hostapd_ssid *ssid = &hapd->conf->ssid;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004901
4902 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
4903 return;
4904
4905 for (i = 0; i < 4; i++) {
4906 if (ssid->wep.key[i] &&
4907 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
4908 i == ssid->wep.idx, NULL, 0,
4909 ssid->wep.key[i], ssid->wep.len[i])) {
4910 wpa_printf(MSG_WARNING,
4911 "Could not set WEP keys for WDS interface; %s",
4912 ifname_wds);
4913 break;
4914 }
4915 }
4916}
4917
4918
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004919static void handle_assoc_cb(struct hostapd_data *hapd,
4920 const struct ieee80211_mgmt *mgmt,
4921 size_t len, int reassoc, int ok)
4922{
4923 u16 status;
4924 struct sta_info *sta;
4925 int new_assoc = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004926
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004927 sta = ap_get_sta(hapd, mgmt->da);
4928 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004929 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
4930 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004931 return;
4932 }
4933
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004934 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
4935 sizeof(mgmt->u.assoc_resp))) {
4936 wpa_printf(MSG_INFO,
4937 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
4938 reassoc, (unsigned long) len);
4939 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004940 return;
4941 }
4942
4943 if (reassoc)
4944 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
4945 else
4946 status = le_to_host16(mgmt->u.assoc_resp.status_code);
4947
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004948 if (!ok) {
4949 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
4950 HOSTAPD_LEVEL_DEBUG,
4951 "did not acknowledge association response");
4952 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
4953 /* The STA is added only in case of SUCCESS */
4954 if (status == WLAN_STATUS_SUCCESS)
4955 hostapd_drv_sta_remove(hapd, sta->addr);
4956
4957 return;
4958 }
4959
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004960 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004961 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004962
4963 /* Stop previous accounting session, if one is started, and allocate
4964 * new session id for the new session. */
4965 accounting_sta_stop(hapd, sta);
4966
4967 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4968 HOSTAPD_LEVEL_INFO,
4969 "associated (aid %d)",
4970 sta->aid);
4971
4972 if (sta->flags & WLAN_STA_ASSOC)
4973 new_assoc = 0;
4974 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004975 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004976 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
4977 !hapd->conf->osen) ||
4978 sta->auth_alg == WLAN_AUTH_FILS_SK ||
4979 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
4980 sta->auth_alg == WLAN_AUTH_FILS_PK ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004981 sta->auth_alg == WLAN_AUTH_FT) {
4982 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004983 * Open, static WEP, FT protocol, or FILS; no separate
4984 * authorization step.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004985 */
4986 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004987 }
4988
4989 if (reassoc)
4990 mlme_reassociate_indication(hapd, sta);
4991 else
4992 mlme_associate_indication(hapd, sta);
4993
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004994 sta->sa_query_timed_out = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004995
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004996 if (sta->eapol_sm == NULL) {
4997 /*
4998 * This STA does not use RADIUS server for EAP authentication,
4999 * so bind it to the selected VLAN interface now, since the
5000 * interface selection is not going to change anymore.
5001 */
Dmitry Shmidt83474442015-04-15 13:47:09 -07005002 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07005003 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005004 } else if (sta->vlan_id) {
5005 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
Dmitry Shmidt83474442015-04-15 13:47:09 -07005006 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07005007 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005008 }
5009
5010 hostapd_set_sta_flags(hapd, sta);
5011
Dmitry Shmidt29333592017-01-09 12:27:11 -08005012 if (!(sta->flags & WLAN_STA_WDS) && sta->pending_wds_enable) {
5013 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for STA "
5014 MACSTR " based on pending request",
5015 MAC2STR(sta->addr));
5016 sta->pending_wds_enable = 0;
5017 sta->flags |= WLAN_STA_WDS;
5018 }
5019
Hai Shalom74f70d42019-02-11 14:42:39 -08005020 if (sta->flags & (WLAN_STA_WDS | WLAN_STA_MULTI_AP)) {
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08005021 int ret;
5022 char ifname_wds[IFNAMSIZ + 1];
5023
5024 wpa_printf(MSG_DEBUG, "Reenable 4-address WDS mode for STA "
5025 MACSTR " (aid %u)",
5026 MAC2STR(sta->addr), sta->aid);
5027 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
5028 sta->aid, 1);
5029 if (!ret)
5030 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
5031 }
5032
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005033 if (sta->auth_alg == WLAN_AUTH_FT)
5034 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
5035 else
5036 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
5037 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005038 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08005039
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005040#ifdef CONFIG_FILS
5041 if ((sta->auth_alg == WLAN_AUTH_FILS_SK ||
5042 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
5043 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
5044 fils_set_tk(sta->wpa_sm) < 0) {
5045 wpa_printf(MSG_DEBUG, "FILS: TK configuration failed");
5046 ap_sta_disconnect(hapd, sta, sta->addr,
5047 WLAN_REASON_UNSPECIFIED);
5048 return;
5049 }
5050#endif /* CONFIG_FILS */
5051
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08005052 if (sta->pending_eapol_rx) {
5053 struct os_reltime now, age;
5054
5055 os_get_reltime(&now);
5056 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
5057 if (age.sec == 0 && age.usec < 200000) {
5058 wpa_printf(MSG_DEBUG,
5059 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
5060 MAC2STR(sta->addr));
5061 ieee802_1x_receive(
5062 hapd, mgmt->da,
5063 wpabuf_head(sta->pending_eapol_rx->buf),
5064 wpabuf_len(sta->pending_eapol_rx->buf));
5065 }
5066 wpabuf_free(sta->pending_eapol_rx->buf);
5067 os_free(sta->pending_eapol_rx);
5068 sta->pending_eapol_rx = NULL;
5069 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005070}
5071
5072
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005073static void handle_deauth_cb(struct hostapd_data *hapd,
5074 const struct ieee80211_mgmt *mgmt,
5075 size_t len, int ok)
5076{
5077 struct sta_info *sta;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005078 if (is_multicast_ether_addr(mgmt->da))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005079 return;
5080 sta = ap_get_sta(hapd, mgmt->da);
5081 if (!sta) {
5082 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
5083 " not found", MAC2STR(mgmt->da));
5084 return;
5085 }
5086 if (ok)
5087 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
5088 MAC2STR(sta->addr));
5089 else
5090 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
5091 "deauth", MAC2STR(sta->addr));
5092
5093 ap_sta_deauth_cb(hapd, sta);
5094}
5095
5096
5097static void handle_disassoc_cb(struct hostapd_data *hapd,
5098 const struct ieee80211_mgmt *mgmt,
5099 size_t len, int ok)
5100{
5101 struct sta_info *sta;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07005102 if (is_multicast_ether_addr(mgmt->da))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005103 return;
5104 sta = ap_get_sta(hapd, mgmt->da);
5105 if (!sta) {
5106 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
5107 " not found", MAC2STR(mgmt->da));
5108 return;
5109 }
5110 if (ok)
5111 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
5112 MAC2STR(sta->addr));
5113 else
5114 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
5115 "disassoc", MAC2STR(sta->addr));
5116
5117 ap_sta_disassoc_cb(hapd, sta);
5118}
5119
5120
Dmitry Shmidt29333592017-01-09 12:27:11 -08005121static void handle_action_cb(struct hostapd_data *hapd,
5122 const struct ieee80211_mgmt *mgmt,
5123 size_t len, int ok)
5124{
5125 struct sta_info *sta;
Paul Stewart092955c2017-02-06 09:13:09 -08005126 const struct rrm_measurement_report_element *report;
Dmitry Shmidt29333592017-01-09 12:27:11 -08005127
5128 if (is_multicast_ether_addr(mgmt->da))
5129 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005130#ifdef CONFIG_DPP
5131 if (len >= IEEE80211_HDRLEN + 6 &&
5132 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
5133 mgmt->u.action.u.vs_public_action.action ==
5134 WLAN_PA_VENDOR_SPECIFIC &&
5135 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
5136 OUI_WFA &&
5137 mgmt->u.action.u.vs_public_action.variable[0] ==
5138 DPP_OUI_TYPE) {
5139 const u8 *pos, *end;
5140
5141 pos = &mgmt->u.action.u.vs_public_action.variable[1];
5142 end = ((const u8 *) mgmt) + len;
5143 hostapd_dpp_tx_status(hapd, mgmt->da, pos, end - pos, ok);
5144 return;
5145 }
5146 if (len >= IEEE80211_HDRLEN + 2 &&
5147 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
5148 (mgmt->u.action.u.public_action.action ==
5149 WLAN_PA_GAS_INITIAL_REQ ||
5150 mgmt->u.action.u.public_action.action ==
5151 WLAN_PA_GAS_COMEBACK_REQ)) {
5152 const u8 *pos, *end;
5153
5154 pos = mgmt->u.action.u.public_action.variable;
5155 end = ((const u8 *) mgmt) + len;
5156 gas_query_ap_tx_status(hapd->gas, mgmt->da, pos, end - pos, ok);
5157 return;
5158 }
5159#endif /* CONFIG_DPP */
Dmitry Shmidt29333592017-01-09 12:27:11 -08005160 sta = ap_get_sta(hapd, mgmt->da);
5161 if (!sta) {
5162 wpa_printf(MSG_DEBUG, "handle_action_cb: STA " MACSTR
5163 " not found", MAC2STR(mgmt->da));
5164 return;
5165 }
5166
Paul Stewart092955c2017-02-06 09:13:09 -08005167 if (len < 24 + 5 + sizeof(*report))
Dmitry Shmidt29333592017-01-09 12:27:11 -08005168 return;
Paul Stewart092955c2017-02-06 09:13:09 -08005169 report = (const struct rrm_measurement_report_element *)
5170 &mgmt->u.action.u.rrm.variable[2];
Dmitry Shmidt29333592017-01-09 12:27:11 -08005171 if (mgmt->u.action.category == WLAN_ACTION_RADIO_MEASUREMENT &&
Paul Stewart092955c2017-02-06 09:13:09 -08005172 mgmt->u.action.u.rrm.action == WLAN_RRM_RADIO_MEASUREMENT_REQUEST &&
5173 report->eid == WLAN_EID_MEASURE_REQUEST &&
5174 report->len >= 3 &&
5175 report->type == MEASURE_TYPE_BEACON)
Dmitry Shmidt29333592017-01-09 12:27:11 -08005176 hostapd_rrm_beacon_req_tx_status(hapd, mgmt, len, ok);
5177}
5178
5179
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005180/**
5181 * ieee802_11_mgmt_cb - Process management frame TX status callback
5182 * @hapd: hostapd BSS data structure (the BSS from which the management frame
5183 * was sent from)
5184 * @buf: management frame data (starting from IEEE 802.11 header)
5185 * @len: length of frame data in octets
5186 * @stype: management frame subtype from frame control field
5187 * @ok: Whether the frame was ACK'ed
5188 */
5189void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
5190 u16 stype, int ok)
5191{
5192 const struct ieee80211_mgmt *mgmt;
5193 mgmt = (const struct ieee80211_mgmt *) buf;
5194
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005195#ifdef CONFIG_TESTING_OPTIONS
5196 if (hapd->ext_mgmt_frame_handling) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005197 size_t hex_len = 2 * len + 1;
5198 char *hex = os_malloc(hex_len);
5199
5200 if (hex) {
5201 wpa_snprintf_hex(hex, hex_len, buf, len);
5202 wpa_msg(hapd->msg_ctx, MSG_INFO,
5203 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
5204 stype, ok, hex);
5205 os_free(hex);
5206 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005207 return;
5208 }
5209#endif /* CONFIG_TESTING_OPTIONS */
5210
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005211 switch (stype) {
5212 case WLAN_FC_STYPE_AUTH:
5213 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
5214 handle_auth_cb(hapd, mgmt, len, ok);
5215 break;
5216 case WLAN_FC_STYPE_ASSOC_RESP:
5217 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
5218 handle_assoc_cb(hapd, mgmt, len, 0, ok);
5219 break;
5220 case WLAN_FC_STYPE_REASSOC_RESP:
5221 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
5222 handle_assoc_cb(hapd, mgmt, len, 1, ok);
5223 break;
5224 case WLAN_FC_STYPE_PROBE_RESP:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005225 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005226 break;
5227 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005228 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
5229 handle_deauth_cb(hapd, mgmt, len, ok);
5230 break;
5231 case WLAN_FC_STYPE_DISASSOC:
5232 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
5233 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005234 break;
5235 case WLAN_FC_STYPE_ACTION:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005236 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005237 handle_action_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005238 break;
5239 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005240 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005241 break;
5242 }
5243}
5244
5245
5246int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
5247{
5248 /* TODO */
5249 return 0;
5250}
5251
5252
5253int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
5254 char *buf, size_t buflen)
5255{
5256 /* TODO */
5257 return 0;
5258}
5259
5260
5261void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
5262 const u8 *buf, size_t len, int ack)
5263{
5264 struct sta_info *sta;
5265 struct hostapd_iface *iface = hapd->iface;
5266
5267 sta = ap_get_sta(hapd, addr);
5268 if (sta == NULL && iface->num_bss > 1) {
5269 size_t j;
5270 for (j = 0; j < iface->num_bss; j++) {
5271 hapd = iface->bss[j];
5272 sta = ap_get_sta(hapd, addr);
5273 if (sta)
5274 break;
5275 }
5276 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005277 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005278 return;
5279 if (sta->flags & WLAN_STA_PENDING_POLL) {
5280 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
5281 "activity poll", MAC2STR(sta->addr),
5282 ack ? "ACKed" : "did not ACK");
5283 if (ack)
5284 sta->flags &= ~WLAN_STA_PENDING_POLL;
5285 }
5286
5287 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
5288}
5289
5290
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005291void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
5292 const u8 *data, size_t len, int ack)
5293{
5294 struct sta_info *sta;
5295 struct hostapd_iface *iface = hapd->iface;
5296
5297 sta = ap_get_sta(hapd, dst);
5298 if (sta == NULL && iface->num_bss > 1) {
5299 size_t j;
5300 for (j = 0; j < iface->num_bss; j++) {
5301 hapd = iface->bss[j];
5302 sta = ap_get_sta(hapd, dst);
5303 if (sta)
5304 break;
5305 }
5306 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005307 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
5308 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
5309 MACSTR " that is not currently associated",
5310 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005311 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005312 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005313
5314 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
5315}
5316
5317
5318void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
5319{
5320 struct sta_info *sta;
5321 struct hostapd_iface *iface = hapd->iface;
5322
5323 sta = ap_get_sta(hapd, addr);
5324 if (sta == NULL && iface->num_bss > 1) {
5325 size_t j;
5326 for (j = 0; j < iface->num_bss; j++) {
5327 hapd = iface->bss[j];
5328 sta = ap_get_sta(hapd, addr);
5329 if (sta)
5330 break;
5331 }
5332 }
5333 if (sta == NULL)
5334 return;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005335 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
5336 MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005337 if (!(sta->flags & WLAN_STA_PENDING_POLL))
5338 return;
5339
5340 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
5341 "activity poll", MAC2STR(sta->addr));
5342 sta->flags &= ~WLAN_STA_PENDING_POLL;
5343}
5344
5345
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005346void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
5347 int wds)
5348{
5349 struct sta_info *sta;
5350
5351 sta = ap_get_sta(hapd, src);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005352 if (sta &&
5353 ((sta->flags & WLAN_STA_ASSOC) ||
5354 ((sta->flags & WLAN_STA_ASSOC_REQ_OK) && wds))) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005355 if (!hapd->conf->wds_sta)
5356 return;
5357
Dmitry Shmidt29333592017-01-09 12:27:11 -08005358 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK)) ==
5359 WLAN_STA_ASSOC_REQ_OK) {
5360 wpa_printf(MSG_DEBUG,
5361 "Postpone 4-address WDS mode enabling for STA "
5362 MACSTR " since TX status for AssocResp is not yet known",
5363 MAC2STR(sta->addr));
5364 sta->pending_wds_enable = 1;
5365 return;
5366 }
5367
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005368 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005369 int ret;
5370 char ifname_wds[IFNAMSIZ + 1];
5371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005372 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
5373 "STA " MACSTR " (aid %u)",
5374 MAC2STR(sta->addr), sta->aid);
5375 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005376 ret = hostapd_set_wds_sta(hapd, ifname_wds,
5377 sta->addr, sta->aid, 1);
5378 if (!ret)
5379 hostapd_set_wds_encryption(hapd, sta,
5380 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005381 }
5382 return;
5383 }
5384
5385 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
5386 MACSTR, MAC2STR(src));
Hai Shalomc3565922019-10-28 11:58:20 -07005387 if (is_multicast_ether_addr(src) || is_zero_ether_addr(src) ||
5388 os_memcmp(src, hapd->own_addr, ETH_ALEN) == 0) {
5389 /* Broadcast bit set in SA or unexpected SA?! Ignore the frame
5390 * silently. */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005391 return;
5392 }
5393
5394 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
5395 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
5396 "already been sent, but no TX status yet known - "
5397 "ignore Class 3 frame issue with " MACSTR,
5398 MAC2STR(src));
5399 return;
5400 }
5401
5402 if (sta && (sta->flags & WLAN_STA_AUTH))
5403 hostapd_drv_sta_disassoc(
5404 hapd, src,
5405 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
5406 else
5407 hostapd_drv_sta_deauth(
5408 hapd, src,
5409 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
5410}
5411
5412
5413#endif /* CONFIG_NATIVE_WINDOWS */