blob: d7e7210f7a15907331c084039ad0a5390d6ed890 [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"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070024#include "radius/radius.h"
25#include "radius/radius_client.h"
26#include "p2p/p2p.h"
27#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080028#include "fst/fst.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029#include "hostapd.h"
30#include "beacon.h"
31#include "ieee802_11_auth.h"
32#include "sta_info.h"
33#include "ieee802_1x.h"
34#include "wpa_auth.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080035#include "pmksa_cache_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "wmm.h"
37#include "ap_list.h"
38#include "accounting.h"
39#include "ap_config.h"
40#include "ap_mlme.h"
41#include "p2p_hostapd.h"
42#include "ap_drv_ops.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080043#include "wnm_ap.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080044#include "hw_features.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045#include "ieee802_11.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080046#include "dfs.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080047#include "mbo_ap.h"
Dmitry Shmidt849734c2016-05-27 09:59:01 -070048#include "rrm.h"
Dmitry Shmidtaca489e2016-09-28 15:44:14 -070049#include "taxonomy.h"
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080050#include "fils_hlp.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070051#include "dpp_hostapd.h"
52#include "gas_query_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070053
54
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070055#ifdef CONFIG_FILS
56static struct wpabuf *
57prepare_auth_resp_fils(struct hostapd_data *hapd,
58 struct sta_info *sta, u16 *resp,
59 struct rsn_pmksa_cache_entry *pmksa,
60 struct wpabuf *erp_resp,
61 const u8 *msk, size_t msk_len,
62 int *is_pub);
63#endif /* CONFIG_FILS */
64
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070065u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
66{
67 u8 *pos = eid;
68 int i, num, count;
69
70 if (hapd->iface->current_rates == NULL)
71 return eid;
72
73 *pos++ = WLAN_EID_SUPP_RATES;
74 num = hapd->iface->num_rates;
75 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
76 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080077 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
78 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070079 if (num > 8) {
80 /* rest of the rates are encoded in Extended supported
81 * rates element */
82 num = 8;
83 }
84
85 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070086 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
87 i++) {
88 count++;
89 *pos = hapd->iface->current_rates[i].rate / 5;
90 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
91 *pos |= 0x80;
92 pos++;
93 }
94
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080095 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
96 count++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080098 }
99
100 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
101 count++;
102 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
103 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104
105 return pos;
106}
107
108
109u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
110{
111 u8 *pos = eid;
112 int i, num, count;
113
114 if (hapd->iface->current_rates == NULL)
115 return eid;
116
117 num = hapd->iface->num_rates;
118 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
119 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800120 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
121 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700122 if (num <= 8)
123 return eid;
124 num -= 8;
125
126 *pos++ = WLAN_EID_EXT_SUPP_RATES;
127 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700128 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
129 i++) {
130 count++;
131 if (count <= 8)
132 continue; /* already in SuppRates IE */
133 *pos = hapd->iface->current_rates[i].rate / 5;
134 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
135 *pos |= 0x80;
136 pos++;
137 }
138
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800139 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
140 count++;
141 if (count > 8)
142 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
143 }
144
145 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
146 count++;
147 if (count > 8)
148 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
149 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150
151 return pos;
152}
153
154
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700155u16 hostapd_own_capab_info(struct hostapd_data *hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700156{
157 int capab = WLAN_CAPABILITY_ESS;
158 int privacy;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800159 int dfs;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700160 int i;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800161
162 /* Check if any of configured channels require DFS */
163 dfs = hostapd_is_dfs_required(hapd->iface);
164 if (dfs < 0) {
165 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
166 dfs);
167 dfs = 0;
168 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700169
170 if (hapd->iface->num_sta_no_short_preamble == 0 &&
171 hapd->iconf->preamble == SHORT_PREAMBLE)
172 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
173
174 privacy = hapd->conf->ssid.wep.keys_set;
175
176 if (hapd->conf->ieee802_1x &&
177 (hapd->conf->default_wep_key_len ||
178 hapd->conf->individual_wep_key_len))
179 privacy = 1;
180
181 if (hapd->conf->wpa)
182 privacy = 1;
183
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800184#ifdef CONFIG_HS20
185 if (hapd->conf->osen)
186 privacy = 1;
187#endif /* CONFIG_HS20 */
188
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189 if (privacy)
190 capab |= WLAN_CAPABILITY_PRIVACY;
191
192 if (hapd->iface->current_mode &&
193 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
194 hapd->iface->num_sta_no_short_slot_time == 0)
195 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
196
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800197 /*
198 * Currently, Spectrum Management capability bit is set when directly
199 * requested in configuration by spectrum_mgmt_required or when AP is
200 * running on DFS channel.
201 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
202 */
203 if (hapd->iface->current_mode &&
204 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
205 (hapd->iconf->spectrum_mgmt_required || dfs))
206 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
207
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700208 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
209 if (hapd->conf->radio_measurements[i]) {
210 capab |= IEEE80211_CAP_RRM;
211 break;
212 }
213 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800214
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700215 return capab;
216}
217
218
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800219#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
221 u16 auth_transaction, const u8 *challenge,
222 int iswep)
223{
224 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
225 HOSTAPD_LEVEL_DEBUG,
226 "authentication (shared key, transaction %d)",
227 auth_transaction);
228
229 if (auth_transaction == 1) {
230 if (!sta->challenge) {
231 /* Generate a pseudo-random challenge */
232 u8 key[8];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800233
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700234 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
235 if (sta->challenge == NULL)
236 return WLAN_STATUS_UNSPECIFIED_FAILURE;
237
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800238 if (os_get_random(key, sizeof(key)) < 0) {
239 os_free(sta->challenge);
240 sta->challenge = NULL;
241 return WLAN_STATUS_UNSPECIFIED_FAILURE;
242 }
243
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700244 rc4_skip(key, sizeof(key), 0,
245 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
246 }
247 return 0;
248 }
249
250 if (auth_transaction != 3)
251 return WLAN_STATUS_UNSPECIFIED_FAILURE;
252
253 /* Transaction 3 */
254 if (!iswep || !sta->challenge || !challenge ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700255 os_memcmp_const(sta->challenge, challenge,
256 WLAN_AUTH_CHALLENGE_LEN)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
258 HOSTAPD_LEVEL_INFO,
259 "shared key authentication - invalid "
260 "challenge-response");
261 return WLAN_STATUS_CHALLENGE_FAIL;
262 }
263
264 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
265 HOSTAPD_LEVEL_DEBUG,
266 "authentication OK (shared key)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700267 sta->flags |= WLAN_STA_AUTH;
268 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269 os_free(sta->challenge);
270 sta->challenge = NULL;
271
272 return 0;
273}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800274#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275
276
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800277static int send_auth_reply(struct hostapd_data *hapd,
278 const u8 *dst, const u8 *bssid,
279 u16 auth_alg, u16 auth_transaction, u16 resp,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700280 const u8 *ies, size_t ies_len, const char *dbg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281{
282 struct ieee80211_mgmt *reply;
283 u8 *buf;
284 size_t rlen;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800285 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700286
287 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
288 buf = os_zalloc(rlen);
289 if (buf == NULL)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800290 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291
292 reply = (struct ieee80211_mgmt *) buf;
293 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
294 WLAN_FC_STYPE_AUTH);
295 os_memcpy(reply->da, dst, ETH_ALEN);
296 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
297 os_memcpy(reply->bssid, bssid, ETH_ALEN);
298
299 reply->u.auth.auth_alg = host_to_le16(auth_alg);
300 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
301 reply->u.auth.status_code = host_to_le16(resp);
302
303 if (ies && ies_len)
304 os_memcpy(reply->u.auth.variable, ies, ies_len);
305
306 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700307 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu) (dbg=%s)",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308 MAC2STR(dst), auth_alg, auth_transaction,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700309 resp, (unsigned long) ies_len, dbg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800310 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800311 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
312 else
313 reply_res = WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314
315 os_free(buf);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800316
317 return reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318}
319
320
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800321#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700322static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
323 u16 auth_transaction, u16 status,
324 const u8 *ies, size_t ies_len)
325{
326 struct hostapd_data *hapd = ctx;
327 struct sta_info *sta;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800328 int reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800330 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700331 auth_transaction, status, ies, ies_len,
332 "auth-ft-finish");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333
334 sta = ap_get_sta(hapd, dst);
335 if (sta == NULL)
336 return;
337
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800338 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
339 status != WLAN_STATUS_SUCCESS)) {
340 hostapd_drv_sta_remove(hapd, sta->addr);
341 sta->added_unassoc = 0;
342 return;
343 }
344
345 if (status != WLAN_STATUS_SUCCESS)
346 return;
347
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700348 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
349 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
350 sta->flags |= WLAN_STA_AUTH;
351 mlme_authenticate_indication(hapd, sta);
352}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800353#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354
355
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800356#ifdef CONFIG_SAE
357
Roshan Pius3a1667e2018-07-03 15:17:14 -0700358static void sae_set_state(struct sta_info *sta, enum sae_state state,
359 const char *reason)
360{
361 wpa_printf(MSG_DEBUG, "SAE: State %s -> %s for peer " MACSTR " (%s)",
362 sae_state_txt(sta->sae->state), sae_state_txt(state),
363 MAC2STR(sta->addr), reason);
364 sta->sae->state = state;
365}
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800366
367
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800368static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
369 struct sta_info *sta, int update)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800370{
371 struct wpabuf *buf;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700372 const char *password = NULL;
373 struct sae_password_entry *pw;
374 const char *rx_id = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800375
Roshan Pius3a1667e2018-07-03 15:17:14 -0700376 if (sta->sae->tmp)
377 rx_id = sta->sae->tmp->pw_id;
378
379 for (pw = hapd->conf->sae_passwords; pw; pw = pw->next) {
380 if (!is_broadcast_ether_addr(pw->peer_addr) &&
381 os_memcmp(pw->peer_addr, sta->addr, ETH_ALEN) != 0)
382 continue;
383 if ((rx_id && !pw->identifier) || (!rx_id && pw->identifier))
384 continue;
385 if (rx_id && pw->identifier &&
386 os_strcmp(rx_id, pw->identifier) != 0)
387 continue;
388 password = pw->password;
389 break;
390 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700391 if (!password)
392 password = hapd->conf->ssid.wpa_passphrase;
393 if (!password) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800394 wpa_printf(MSG_DEBUG, "SAE: No password available");
395 return NULL;
396 }
397
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800398 if (update &&
399 sae_prepare_commit(hapd->own_addr, sta->addr,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700400 (u8 *) password, os_strlen(password), rx_id,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800401 sta->sae) < 0) {
402 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
403 return NULL;
404 }
405
Roshan Pius3a1667e2018-07-03 15:17:14 -0700406 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN +
407 (rx_id ? 3 + os_strlen(rx_id) : 0));
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800408 if (buf == NULL)
409 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800410 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
Roshan Pius3a1667e2018-07-03 15:17:14 -0700411 sta->sae->tmp->anti_clogging_token : NULL, rx_id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800412
413 return buf;
414}
415
416
417static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
418 struct sta_info *sta)
419{
420 struct wpabuf *buf;
421
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800422 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800423 if (buf == NULL)
424 return NULL;
425
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800426 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800427
428 return buf;
429}
430
431
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800432static int auth_sae_send_commit(struct hostapd_data *hapd,
433 struct sta_info *sta,
434 const u8 *bssid, int update)
435{
436 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800437 int reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800438
439 data = auth_build_sae_commit(hapd, sta, update);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700440 if (!data && sta->sae->tmp && sta->sae->tmp->pw_id)
441 return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800442 if (data == NULL)
443 return WLAN_STATUS_UNSPECIFIED_FAILURE;
444
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800445 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
446 WLAN_STATUS_SUCCESS, wpabuf_head(data),
Roshan Pius3a1667e2018-07-03 15:17:14 -0700447 wpabuf_len(data), "sae-send-commit");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800448
449 wpabuf_free(data);
450
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800451 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800452}
453
454
455static int auth_sae_send_confirm(struct hostapd_data *hapd,
456 struct sta_info *sta,
457 const u8 *bssid)
458{
459 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800460 int reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800461
462 data = auth_build_sae_confirm(hapd, sta);
463 if (data == NULL)
464 return WLAN_STATUS_UNSPECIFIED_FAILURE;
465
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800466 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
467 WLAN_STATUS_SUCCESS, wpabuf_head(data),
Roshan Pius3a1667e2018-07-03 15:17:14 -0700468 wpabuf_len(data), "sae-send-confirm");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800469
470 wpabuf_free(data);
471
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800472 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800473}
474
475
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800476static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800477{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800478 struct sta_info *sta;
479 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800480
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800481 if (hapd->conf->sae_anti_clogging_threshold == 0)
482 return 1;
483
484 for (sta = hapd->sta_list; sta; sta = sta->next) {
485 if (!sta->sae)
486 continue;
487 if (sta->sae->state != SAE_COMMITTED &&
488 sta->sae->state != SAE_CONFIRMED)
489 continue;
490 open++;
491 if (open >= hapd->conf->sae_anti_clogging_threshold)
492 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800493 }
494
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800495 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800496}
497
498
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800499static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
500 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800501{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800502 u8 mac[SHA256_MAC_LEN];
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800503
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800504 if (token_len != SHA256_MAC_LEN)
505 return -1;
506 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
507 addr, ETH_ALEN, mac) < 0 ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700508 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800509 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800510
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800511 return 0;
512}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800513
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800514
515static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800516 int group, const u8 *addr)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800517{
518 struct wpabuf *buf;
519 u8 *token;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800520 struct os_reltime now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800521
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800522 os_get_reltime(&now);
523 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
524 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800525 if (random_get_bytes(hapd->sae_token_key,
526 sizeof(hapd->sae_token_key)) < 0)
527 return NULL;
528 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
529 hapd->sae_token_key, sizeof(hapd->sae_token_key));
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800530 hapd->last_sae_token_key_update = now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800531 }
532
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800533 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800534 if (buf == NULL)
535 return NULL;
536
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800537 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
538
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800539 token = wpabuf_put(buf, SHA256_MAC_LEN);
540 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
541 addr, ETH_ALEN, token);
542
543 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800544}
545
546
Roshan Pius3a1667e2018-07-03 15:17:14 -0700547static int sae_check_big_sync(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800548{
Roshan Pius3a1667e2018-07-03 15:17:14 -0700549 if (sta->sae->sync > hapd->conf->sae_sync) {
550 sae_set_state(sta, SAE_NOTHING, "Sync > dot11RSNASAESync");
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800551 sta->sae->sync = 0;
552 return -1;
553 }
554 return 0;
555}
556
557
558static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
559{
560 struct hostapd_data *hapd = eloop_ctx;
561 struct sta_info *sta = eloop_data;
562 int ret;
563
Roshan Pius3a1667e2018-07-03 15:17:14 -0700564 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800565 return;
566 sta->sae->sync++;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700567 wpa_printf(MSG_DEBUG, "SAE: Auth SAE retransmit timer for " MACSTR
Roshan Pius3a1667e2018-07-03 15:17:14 -0700568 " (sync=%d state=%s)",
569 MAC2STR(sta->addr), sta->sae->sync,
570 sae_state_txt(sta->sae->state));
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800571
572 switch (sta->sae->state) {
573 case SAE_COMMITTED:
574 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800575 eloop_register_timeout(0,
576 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800577 auth_sae_retransmit_timer, hapd, sta);
578 break;
579 case SAE_CONFIRMED:
580 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800581 eloop_register_timeout(0,
582 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800583 auth_sae_retransmit_timer, hapd, sta);
584 break;
585 default:
586 ret = -1;
587 break;
588 }
589
590 if (ret != WLAN_STATUS_SUCCESS)
591 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
592}
593
594
595void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
596{
597 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
598}
599
600
601static void sae_set_retransmit_timer(struct hostapd_data *hapd,
602 struct sta_info *sta)
603{
604 if (!(hapd->conf->mesh & MESH_ENABLED))
605 return;
606
607 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800608 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800609 auth_sae_retransmit_timer, hapd, sta);
610}
611
612
Dmitry Shmidte4663042016-04-04 10:07:49 -0700613void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
614{
615 sta->flags |= WLAN_STA_AUTH;
616 sta->auth_alg = WLAN_AUTH_SAE;
617 mlme_authenticate_indication(hapd, sta);
618 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700619 sae_set_state(sta, SAE_ACCEPTED, "Accept Confirm");
Dmitry Shmidte4663042016-04-04 10:07:49 -0700620 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
621 sta->sae->pmk, sta->sae->pmkid);
622}
623
624
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800625static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
626 const u8 *bssid, u8 auth_transaction)
627{
628 int ret;
629
630 if (auth_transaction != 1 && auth_transaction != 2)
631 return WLAN_STATUS_UNSPECIFIED_FAILURE;
632
Roshan Pius3a1667e2018-07-03 15:17:14 -0700633 wpa_printf(MSG_DEBUG, "SAE: Peer " MACSTR " state=%s auth_trans=%u",
634 MAC2STR(sta->addr), sae_state_txt(sta->sae->state),
635 auth_transaction);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800636 switch (sta->sae->state) {
637 case SAE_NOTHING:
638 if (auth_transaction == 1) {
639 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
640 if (ret)
641 return ret;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700642 sae_set_state(sta, SAE_COMMITTED, "Sent Commit");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800643
644 if (sae_process_commit(sta->sae) < 0)
645 return WLAN_STATUS_UNSPECIFIED_FAILURE;
646
647 /*
648 * In mesh case, both Commit and Confirm can be sent
649 * immediately. In infrastructure BSS, only a single
650 * Authentication frame (Commit) is expected from the AP
651 * here and the second one (Confirm) will be sent once
652 * the STA has sent its second Authentication frame
653 * (Confirm).
654 */
655 if (hapd->conf->mesh & MESH_ENABLED) {
656 /*
657 * Send both Commit and Confirm immediately
658 * based on SAE finite state machine
659 * Nothing -> Confirm transition.
660 */
661 ret = auth_sae_send_confirm(hapd, sta, bssid);
662 if (ret)
663 return ret;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700664 sae_set_state(sta, SAE_CONFIRMED,
665 "Sent Confirm (mesh)");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800666 } else {
667 /*
668 * For infrastructure BSS, send only the Commit
669 * message now to get alternating sequence of
670 * Authentication frames between the AP and STA.
671 * Confirm will be sent in
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800672 * Committed -> Confirmed/Accepted transition
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800673 * when receiving Confirm from STA.
674 */
675 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800676 sta->sae->sync = 0;
677 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800678 } else {
679 hostapd_logger(hapd, sta->addr,
680 HOSTAPD_MODULE_IEEE80211,
681 HOSTAPD_LEVEL_DEBUG,
682 "SAE confirm before commit");
683 }
684 break;
685 case SAE_COMMITTED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800686 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800687 if (auth_transaction == 1) {
688 if (sae_process_commit(sta->sae) < 0)
689 return WLAN_STATUS_UNSPECIFIED_FAILURE;
690
691 ret = auth_sae_send_confirm(hapd, sta, bssid);
692 if (ret)
693 return ret;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700694 sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm");
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800695 sta->sae->sync = 0;
696 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800697 } else if (hapd->conf->mesh & MESH_ENABLED) {
698 /*
699 * In mesh case, follow SAE finite state machine and
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800700 * send Commit now, if sync count allows.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800701 */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700702 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800703 return WLAN_STATUS_SUCCESS;
704 sta->sae->sync++;
705
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700706 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800707 if (ret)
708 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800709
710 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800711 } else {
712 /*
713 * For instructure BSS, send the postponed Confirm from
714 * Nothing -> Confirmed transition that was reduced to
715 * Nothing -> Committed above.
716 */
717 ret = auth_sae_send_confirm(hapd, sta, bssid);
718 if (ret)
719 return ret;
720
Roshan Pius3a1667e2018-07-03 15:17:14 -0700721 sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800722
723 /*
724 * Since this was triggered on Confirm RX, run another
725 * step to get to Accepted without waiting for
726 * additional events.
727 */
728 return sae_sm_step(hapd, sta, bssid, auth_transaction);
729 }
730 break;
731 case SAE_CONFIRMED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800732 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800733 if (auth_transaction == 1) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700734 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800735 return WLAN_STATUS_SUCCESS;
736 sta->sae->sync++;
737
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800738 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
739 if (ret)
740 return ret;
741
742 if (sae_process_commit(sta->sae) < 0)
743 return WLAN_STATUS_UNSPECIFIED_FAILURE;
744
745 ret = auth_sae_send_confirm(hapd, sta, bssid);
746 if (ret)
747 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800748
749 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800750 } else {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700751 sta->sae->send_confirm = 0xffff;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700752 sae_accept_sta(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800753 }
754 break;
755 case SAE_ACCEPTED:
Roshan Pius3a1667e2018-07-03 15:17:14 -0700756 if (auth_transaction == 1 &&
757 (hapd->conf->mesh & MESH_ENABLED)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800758 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
759 ") doing reauthentication",
760 MAC2STR(sta->addr));
761 ap_free_sta(hapd, sta);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700762 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700763 } else if (auth_transaction == 1) {
764 wpa_printf(MSG_DEBUG, "SAE: Start reauthentication");
765 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
766 if (ret)
767 return ret;
768 sae_set_state(sta, SAE_COMMITTED, "Sent Commit");
769
770 if (sae_process_commit(sta->sae) < 0)
771 return WLAN_STATUS_UNSPECIFIED_FAILURE;
772 sta->sae->sync = 0;
773 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800774 } else {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700775 if (sae_check_big_sync(hapd, sta))
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800776 return WLAN_STATUS_SUCCESS;
777 sta->sae->sync++;
778
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800779 ret = auth_sae_send_confirm(hapd, sta, bssid);
780 sae_clear_temp_data(sta->sae);
781 if (ret)
782 return ret;
783 }
784 break;
785 default:
786 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
787 sta->sae->state);
788 return WLAN_STATUS_UNSPECIFIED_FAILURE;
789 }
790 return WLAN_STATUS_SUCCESS;
791}
792
793
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700794static void sae_pick_next_group(struct hostapd_data *hapd, struct sta_info *sta)
795{
796 struct sae_data *sae = sta->sae;
797 int i, *groups = hapd->conf->sae_groups;
798
799 if (sae->state != SAE_COMMITTED)
800 return;
801
802 wpa_printf(MSG_DEBUG, "SAE: Previously selected group: %d", sae->group);
803
804 for (i = 0; groups && groups[i] > 0; i++) {
805 if (sae->group == groups[i])
806 break;
807 }
808
809 if (!groups || groups[i] <= 0) {
810 wpa_printf(MSG_DEBUG,
811 "SAE: Previously selected group not found from the current configuration");
812 return;
813 }
814
815 for (;;) {
816 i++;
817 if (groups[i] <= 0) {
818 wpa_printf(MSG_DEBUG,
819 "SAE: No alternative group enabled");
820 return;
821 }
822
823 if (sae_set_group(sae, groups[i]) < 0)
824 continue;
825
826 break;
827 }
828 wpa_printf(MSG_DEBUG, "SAE: Selected new group: %d", groups[i]);
829}
830
831
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800832static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
833 const struct ieee80211_mgmt *mgmt, size_t len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800834 u16 auth_transaction, u16 status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800835{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800836 int resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800837 struct wpabuf *data = NULL;
838
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700839#ifdef CONFIG_TESTING_OPTIONS
840 if (hapd->conf->sae_reflection_attack && auth_transaction == 1) {
841 const u8 *pos, *end;
842
843 wpa_printf(MSG_DEBUG, "SAE: TESTING - reflection attack");
844 pos = mgmt->u.auth.variable;
845 end = ((const u8 *) mgmt) + len;
846 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700847 auth_transaction, resp, pos, end - pos,
848 "auth-sae-reflection-attack");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700849 goto remove_sta;
850 }
851
852 if (hapd->conf->sae_commit_override && auth_transaction == 1) {
853 wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override");
854 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
855 auth_transaction, resp,
856 wpabuf_head(hapd->conf->sae_commit_override),
Roshan Pius3a1667e2018-07-03 15:17:14 -0700857 wpabuf_len(hapd->conf->sae_commit_override),
858 "sae-commit-override");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700859 goto remove_sta;
860 }
861#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800862 if (!sta->sae) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800863 if (auth_transaction != 1 ||
864 status_code != WLAN_STATUS_SUCCESS) {
865 resp = -1;
866 goto remove_sta;
867 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800868 sta->sae = os_zalloc(sizeof(*sta->sae));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800869 if (!sta->sae) {
870 resp = -1;
871 goto remove_sta;
872 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700873 sae_set_state(sta, SAE_NOTHING, "Init");
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800874 sta->sae->sync = 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800875 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800876
Dmitry Shmidte4663042016-04-04 10:07:49 -0700877 if (sta->mesh_sae_pmksa_caching) {
878 wpa_printf(MSG_DEBUG,
879 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
880 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
881 sta->mesh_sae_pmksa_caching = 0;
882 }
883
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800884 if (auth_transaction == 1) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800885 const u8 *token = NULL, *pos, *end;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800886 size_t token_len = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800887 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
888 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800889 "start SAE authentication (RX commit, status=%u)",
890 status_code);
891
892 if ((hapd->conf->mesh & MESH_ENABLED) &&
893 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
894 sta->sae->tmp) {
895 pos = mgmt->u.auth.variable;
896 end = ((const u8 *) mgmt) + len;
897 if (pos + sizeof(le16) > end) {
898 wpa_printf(MSG_ERROR,
899 "SAE: Too short anti-clogging token request");
900 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
901 goto reply;
902 }
903 resp = sae_group_allowed(sta->sae,
904 hapd->conf->sae_groups,
905 WPA_GET_LE16(pos));
906 if (resp != WLAN_STATUS_SUCCESS) {
907 wpa_printf(MSG_ERROR,
908 "SAE: Invalid group in anti-clogging token request");
909 goto reply;
910 }
911 pos += sizeof(le16);
912
913 wpabuf_free(sta->sae->tmp->anti_clogging_token);
914 sta->sae->tmp->anti_clogging_token =
915 wpabuf_alloc_copy(pos, end - pos);
916 if (sta->sae->tmp->anti_clogging_token == NULL) {
917 wpa_printf(MSG_ERROR,
918 "SAE: Failed to alloc for anti-clogging token");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800919 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
920 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800921 }
922
923 /*
924 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
925 * is 76, a new Commit Message shall be constructed
926 * with the Anti-Clogging Token from the received
927 * Authentication frame, and the commit-scalar and
928 * COMMIT-ELEMENT previously sent.
929 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800930 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
931 if (resp != WLAN_STATUS_SUCCESS) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800932 wpa_printf(MSG_ERROR,
933 "SAE: Failed to send commit message");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800934 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800935 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700936 sae_set_state(sta, SAE_COMMITTED,
937 "Sent Commit (anti-clogging token case in mesh)");
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800938 sta->sae->sync = 0;
939 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800940 return;
941 }
942
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700943 if ((hapd->conf->mesh & MESH_ENABLED) &&
944 status_code ==
945 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
946 sta->sae->tmp) {
947 wpa_printf(MSG_DEBUG,
948 "SAE: Peer did not accept our SAE group");
949 sae_pick_next_group(hapd, sta);
950 goto remove_sta;
951 }
952
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800953 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800954 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800955
Roshan Pius3a1667e2018-07-03 15:17:14 -0700956 if (!(hapd->conf->mesh & MESH_ENABLED) &&
957 sta->sae->state == SAE_COMMITTED) {
958 /* This is needed in the infrastructure BSS case to
959 * address a sequence where a STA entry may remain in
960 * hostapd across two attempts to do SAE authentication
961 * by the same STA. The second attempt may end up trying
962 * to use a different group and that would not be
963 * allowed if we remain in Committed state with the
964 * previously set parameters. */
965 sae_set_state(sta, SAE_NOTHING,
966 "Clear existing state to allow restart");
967 sae_clear_data(sta->sae);
968 }
969
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800970 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
971 ((const u8 *) mgmt) + len -
972 mgmt->u.auth.variable, &token,
973 &token_len, hapd->conf->sae_groups);
Dmitry Shmidt41712582015-06-29 11:02:15 -0700974 if (resp == SAE_SILENTLY_DISCARD) {
975 wpa_printf(MSG_DEBUG,
976 "SAE: Drop commit message from " MACSTR " due to reflection attack",
977 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800978 goto remove_sta;
Dmitry Shmidt41712582015-06-29 11:02:15 -0700979 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700980
981 if (resp == WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER) {
982 wpa_msg(hapd->msg_ctx, MSG_INFO,
983 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER
984 MACSTR, MAC2STR(sta->addr));
985 sae_clear_retransmit_timer(hapd, sta);
986 sae_set_state(sta, SAE_NOTHING,
987 "Unknown Password Identifier");
988 goto remove_sta;
989 }
990
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800991 if (token && check_sae_token(hapd, sta->addr, token, token_len)
992 < 0) {
993 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
994 "incorrect token from " MACSTR,
995 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800996 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
997 goto remove_sta;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800998 }
999
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001000 if (resp != WLAN_STATUS_SUCCESS)
1001 goto reply;
1002
1003 if (!token && use_sae_anti_clogging(hapd)) {
1004 wpa_printf(MSG_DEBUG,
1005 "SAE: Request anti-clogging token from "
1006 MACSTR, MAC2STR(sta->addr));
1007 data = auth_build_token_req(hapd, sta->sae->group,
1008 sta->addr);
1009 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
1010 if (hapd->conf->mesh & MESH_ENABLED)
Roshan Pius3a1667e2018-07-03 15:17:14 -07001011 sae_set_state(sta, SAE_NOTHING,
1012 "Request anti-clogging token case in mesh");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001013 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001014 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001015
1016 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001017 } else if (auth_transaction == 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001018 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1019 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001020 "SAE authentication (RX confirm, status=%u)",
1021 status_code);
1022 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001023 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001024 if (sta->sae->state >= SAE_CONFIRMED ||
1025 !(hapd->conf->mesh & MESH_ENABLED)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001026 const u8 *var;
1027 size_t var_len;
1028 u16 peer_send_confirm;
1029
1030 var = mgmt->u.auth.variable;
1031 var_len = ((u8 *) mgmt) + len - mgmt->u.auth.variable;
1032 if (var_len < 2) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001033 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001034 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001035 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001036
1037 peer_send_confirm = WPA_GET_LE16(var);
1038
1039 if (sta->sae->state == SAE_ACCEPTED &&
1040 (peer_send_confirm <= sta->sae->rc ||
1041 peer_send_confirm == 0xffff)) {
1042 wpa_printf(MSG_DEBUG,
1043 "SAE: Silently ignore unexpected Confirm from peer "
1044 MACSTR
1045 " (peer-send-confirm=%u Rc=%u)",
1046 MAC2STR(sta->addr),
1047 peer_send_confirm, sta->sae->rc);
1048 return;
1049 }
1050
1051 if (sae_check_confirm(sta->sae, var, var_len) < 0) {
1052 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1053 goto reply;
1054 }
1055 sta->sae->rc = peer_send_confirm;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001056 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001057 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001058 } else {
1059 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1060 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001061 "unexpected SAE authentication transaction %u (status=%u)",
1062 auth_transaction, status_code);
1063 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001064 goto remove_sta;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001065 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1066 }
1067
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001068reply:
1069 if (resp != WLAN_STATUS_SUCCESS) {
1070 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
1071 auth_transaction, resp,
1072 data ? wpabuf_head(data) : (u8 *) "",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001073 data ? wpabuf_len(data) : 0, "auth-sae");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001074 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001075
1076remove_sta:
1077 if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
1078 status_code != WLAN_STATUS_SUCCESS)) {
1079 hostapd_drv_sta_remove(hapd, sta->addr);
1080 sta->added_unassoc = 0;
1081 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001082 wpabuf_free(data);
1083}
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001084
1085
1086/**
1087 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1088 * @hapd: BSS data for the device initiating the authentication
1089 * @sta: the peer to which commit authentication frame is sent
1090 *
1091 * This function implements Init event handling (IEEE Std 802.11-2012,
1092 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1093 * sta->sae structure should be initialized appropriately via a call to
1094 * sae_prepare_commit().
1095 */
1096int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
1097{
1098 int ret;
1099
1100 if (!sta->sae || !sta->sae->tmp)
1101 return -1;
1102
1103 if (sta->sae->state != SAE_NOTHING)
1104 return -1;
1105
1106 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
1107 if (ret)
1108 return -1;
1109
Roshan Pius3a1667e2018-07-03 15:17:14 -07001110 sae_set_state(sta, SAE_COMMITTED, "Init and sent commit");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001111 sta->sae->sync = 0;
1112 sae_set_retransmit_timer(hapd, sta);
1113
1114 return 0;
1115}
1116
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001117#endif /* CONFIG_SAE */
1118
1119
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001120static u16 wpa_res_to_status_code(int res)
1121{
1122 if (res == WPA_INVALID_GROUP)
1123 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1124 if (res == WPA_INVALID_PAIRWISE)
1125 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1126 if (res == WPA_INVALID_AKMP)
1127 return WLAN_STATUS_AKMP_NOT_VALID;
1128 if (res == WPA_ALLOC_FAIL)
1129 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1130#ifdef CONFIG_IEEE80211W
1131 if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1132 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1133 if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
Roshan Pius3a1667e2018-07-03 15:17:14 -07001134 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001135#endif /* CONFIG_IEEE80211W */
1136 if (res == WPA_INVALID_MDIE)
1137 return WLAN_STATUS_INVALID_MDIE;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001138 if (res == WPA_INVALID_PMKID)
1139 return WLAN_STATUS_INVALID_PMKID;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001140 if (res != WPA_IE_OK)
1141 return WLAN_STATUS_INVALID_IE;
1142 return WLAN_STATUS_SUCCESS;
1143}
1144
1145
1146#ifdef CONFIG_FILS
1147
1148static void handle_auth_fils_finish(struct hostapd_data *hapd,
1149 struct sta_info *sta, u16 resp,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001150 struct wpabuf *data, int pub);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001151
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001152void handle_auth_fils(struct hostapd_data *hapd, struct sta_info *sta,
1153 const u8 *pos, size_t len, u16 auth_alg,
1154 u16 auth_transaction, u16 status_code,
1155 void (*cb)(struct hostapd_data *hapd,
1156 struct sta_info *sta, u16 resp,
1157 struct wpabuf *data, int pub))
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001158{
1159 u16 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001160 const u8 *end;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001161 struct ieee802_11_elems elems;
1162 int res;
1163 struct wpa_ie_data rsn;
1164 struct rsn_pmksa_cache_entry *pmksa = NULL;
1165
1166 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
1167 return;
1168
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001169 end = pos + len;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001170
1171 wpa_hexdump(MSG_DEBUG, "FILS: Authentication frame fields",
1172 pos, end - pos);
1173
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001174 /* TODO: FILS PK */
1175#ifdef CONFIG_FILS_SK_PFS
1176 if (auth_alg == WLAN_AUTH_FILS_SK_PFS) {
1177 u16 group;
1178 struct wpabuf *pub;
1179 size_t elem_len;
1180
1181 /* Using FILS PFS */
1182
1183 /* Finite Cyclic Group */
1184 if (end - pos < 2) {
1185 wpa_printf(MSG_DEBUG,
1186 "FILS: No room for Finite Cyclic Group");
1187 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1188 goto fail;
1189 }
1190 group = WPA_GET_LE16(pos);
1191 pos += 2;
1192 if (group != hapd->conf->fils_dh_group) {
1193 wpa_printf(MSG_DEBUG,
1194 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1195 group, hapd->conf->fils_dh_group);
1196 resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
1197 goto fail;
1198 }
1199
1200 crypto_ecdh_deinit(sta->fils_ecdh);
1201 sta->fils_ecdh = crypto_ecdh_init(group);
1202 if (!sta->fils_ecdh) {
1203 wpa_printf(MSG_INFO,
1204 "FILS: Could not initialize ECDH with group %d",
1205 group);
1206 resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
1207 goto fail;
1208 }
1209
1210 pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
1211 if (!pub) {
1212 wpa_printf(MSG_DEBUG,
1213 "FILS: Failed to derive ECDH public key");
1214 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1215 goto fail;
1216 }
1217 elem_len = wpabuf_len(pub);
1218 wpabuf_free(pub);
1219
1220 /* Element */
1221 if ((size_t) (end - pos) < elem_len) {
1222 wpa_printf(MSG_DEBUG, "FILS: No room for Element");
1223 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1224 goto fail;
1225 }
1226
1227 wpabuf_free(sta->fils_g_sta);
1228 sta->fils_g_sta = wpabuf_alloc_copy(pos, elem_len);
1229 wpabuf_clear_free(sta->fils_dh_ss);
1230 sta->fils_dh_ss = crypto_ecdh_set_peerkey(sta->fils_ecdh, 1,
1231 pos, elem_len);
1232 if (!sta->fils_dh_ss) {
1233 wpa_printf(MSG_DEBUG, "FILS: ECDH operation failed");
1234 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1235 goto fail;
1236 }
1237 wpa_hexdump_buf_key(MSG_DEBUG, "FILS: DH_SS", sta->fils_dh_ss);
1238 pos += elem_len;
1239 } else {
1240 crypto_ecdh_deinit(sta->fils_ecdh);
1241 sta->fils_ecdh = NULL;
1242 wpabuf_clear_free(sta->fils_dh_ss);
1243 sta->fils_dh_ss = NULL;
1244 }
1245#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001246
1247 wpa_hexdump(MSG_DEBUG, "FILS: Remaining IEs", pos, end - pos);
1248 if (ieee802_11_parse_elems(pos, end - pos, &elems, 1) == ParseFailed) {
1249 wpa_printf(MSG_DEBUG, "FILS: Could not parse elements");
1250 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1251 goto fail;
1252 }
1253
1254 /* RSNE */
1255 wpa_hexdump(MSG_DEBUG, "FILS: RSN element",
1256 elems.rsn_ie, elems.rsn_ie_len);
1257 if (!elems.rsn_ie ||
1258 wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2,
1259 &rsn) < 0) {
1260 wpa_printf(MSG_DEBUG, "FILS: No valid RSN element");
1261 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1262 goto fail;
1263 }
1264
1265 if (!sta->wpa_sm)
1266 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr,
1267 NULL);
1268 if (!sta->wpa_sm) {
1269 wpa_printf(MSG_DEBUG,
1270 "FILS: Failed to initialize RSN state machine");
1271 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1272 goto fail;
1273 }
1274
1275 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1276 elems.rsn_ie - 2, elems.rsn_ie_len + 2,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001277 elems.mdie, elems.mdie_len, NULL, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001278 resp = wpa_res_to_status_code(res);
1279 if (resp != WLAN_STATUS_SUCCESS)
1280 goto fail;
1281
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001282 if (!elems.fils_nonce) {
1283 wpa_printf(MSG_DEBUG, "FILS: No FILS Nonce field");
1284 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1285 goto fail;
1286 }
1287 wpa_hexdump(MSG_DEBUG, "FILS: SNonce", elems.fils_nonce,
1288 FILS_NONCE_LEN);
1289 os_memcpy(sta->fils_snonce, elems.fils_nonce, FILS_NONCE_LEN);
1290
1291 /* PMKID List */
1292 if (rsn.pmkid && rsn.num_pmkid > 0) {
1293 u8 num;
1294 const u8 *pmkid;
1295
1296 wpa_hexdump(MSG_DEBUG, "FILS: PMKID List",
1297 rsn.pmkid, rsn.num_pmkid * PMKID_LEN);
1298
1299 pmkid = rsn.pmkid;
1300 num = rsn.num_pmkid;
1301 while (num) {
1302 wpa_hexdump(MSG_DEBUG, "FILS: PMKID", pmkid, PMKID_LEN);
1303 pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr,
1304 pmkid);
1305 if (pmksa)
1306 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001307 pmksa = wpa_auth_pmksa_get_fils_cache_id(hapd->wpa_auth,
1308 sta->addr,
1309 pmkid);
1310 if (pmksa)
1311 break;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001312 pmkid += PMKID_LEN;
1313 num--;
1314 }
1315 }
1316 if (pmksa && wpa_auth_sta_key_mgmt(sta->wpa_sm) != pmksa->akmp) {
1317 wpa_printf(MSG_DEBUG,
1318 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1319 wpa_auth_sta_key_mgmt(sta->wpa_sm), pmksa->akmp);
1320 pmksa = NULL;
1321 }
1322 if (pmksa)
1323 wpa_printf(MSG_DEBUG, "FILS: Found matching PMKSA cache entry");
1324
1325 /* FILS Session */
1326 if (!elems.fils_session) {
1327 wpa_printf(MSG_DEBUG, "FILS: No FILS Session element");
1328 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1329 goto fail;
1330 }
1331 wpa_hexdump(MSG_DEBUG, "FILS: FILS Session", elems.fils_session,
1332 FILS_SESSION_LEN);
1333 os_memcpy(sta->fils_session, elems.fils_session, FILS_SESSION_LEN);
1334
1335 /* FILS Wrapped Data */
1336 if (elems.fils_wrapped_data) {
1337 wpa_hexdump(MSG_DEBUG, "FILS: Wrapped Data",
1338 elems.fils_wrapped_data,
1339 elems.fils_wrapped_data_len);
1340 if (!pmksa) {
1341#ifndef CONFIG_NO_RADIUS
1342 if (!sta->eapol_sm) {
1343 sta->eapol_sm =
1344 ieee802_1x_alloc_eapol_sm(hapd, sta);
1345 }
1346 wpa_printf(MSG_DEBUG,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001347 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001348 ieee802_1x_encapsulate_radius(
1349 hapd, sta, elems.fils_wrapped_data,
1350 elems.fils_wrapped_data_len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001351 sta->fils_pending_cb = cb;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001352 wpa_printf(MSG_DEBUG,
1353 "FILS: Will send Authentication frame once the response from authentication server is available");
1354 sta->flags |= WLAN_STA_PENDING_FILS_ERP;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001355 /* Calculate pending PMKID here so that we do not need
1356 * to maintain a copy of the EAP-Initiate/Reauth
1357 * message. */
1358 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta->wpa_sm),
1359 elems.fils_wrapped_data,
1360 elems.fils_wrapped_data_len,
1361 sta->fils_erp_pmkid) == 0)
1362 sta->fils_erp_pmkid_set = 1;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001363 return;
1364#else /* CONFIG_NO_RADIUS */
1365 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1366 goto fail;
1367#endif /* CONFIG_NO_RADIUS */
1368 }
1369 }
1370
1371fail:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001372 if (cb) {
1373 struct wpabuf *data;
1374 int pub = 0;
1375
1376 data = prepare_auth_resp_fils(hapd, sta, &resp, pmksa, NULL,
1377 NULL, 0, &pub);
1378 if (!data) {
1379 wpa_printf(MSG_DEBUG,
1380 "%s: prepare_auth_resp_fils() returned failure",
1381 __func__);
1382 }
1383
1384 cb(hapd, sta, resp, data, pub);
1385 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001386}
1387
1388
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001389static struct wpabuf *
1390prepare_auth_resp_fils(struct hostapd_data *hapd,
1391 struct sta_info *sta, u16 *resp,
1392 struct rsn_pmksa_cache_entry *pmksa,
1393 struct wpabuf *erp_resp,
1394 const u8 *msk, size_t msk_len,
1395 int *is_pub)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001396{
1397 u8 fils_nonce[FILS_NONCE_LEN];
1398 size_t ielen;
1399 struct wpabuf *data = NULL;
1400 const u8 *ie;
1401 u8 *ie_buf = NULL;
1402 const u8 *pmk = NULL;
1403 size_t pmk_len = 0;
Paul Stewart092955c2017-02-06 09:13:09 -08001404 u8 pmk_buf[PMK_LEN_MAX];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001405 struct wpabuf *pub = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001406
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001407 if (*resp != WLAN_STATUS_SUCCESS)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001408 goto fail;
1409
1410 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
1411 if (!ie) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001412 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001413 goto fail;
1414 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001415
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001416 if (pmksa) {
1417 /* Add PMKID of the selected PMKSA into RSNE */
1418 ie_buf = os_malloc(ielen + 2 + 2 + PMKID_LEN);
1419 if (!ie_buf) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001420 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001421 goto fail;
1422 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001423
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001424 os_memcpy(ie_buf, ie, ielen);
1425 if (wpa_insert_pmkid(ie_buf, &ielen, pmksa->pmkid) < 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001426 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001427 goto fail;
1428 }
1429 ie = ie_buf;
1430 }
1431
1432 if (random_get_bytes(fils_nonce, FILS_NONCE_LEN) < 0) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001433 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001434 goto fail;
1435 }
1436 wpa_hexdump(MSG_DEBUG, "RSN: Generated FILS Nonce",
1437 fils_nonce, FILS_NONCE_LEN);
1438
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001439#ifdef CONFIG_FILS_SK_PFS
1440 if (sta->fils_dh_ss && sta->fils_ecdh) {
1441 pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
1442 if (!pub) {
1443 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1444 goto fail;
1445 }
1446 }
1447#endif /* CONFIG_FILS_SK_PFS */
1448
1449 data = wpabuf_alloc(1000 + ielen + (pub ? wpabuf_len(pub) : 0));
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001450 if (!data) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001451 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001452 goto fail;
1453 }
1454
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001455 /* TODO: FILS PK */
1456#ifdef CONFIG_FILS_SK_PFS
1457 if (pub) {
1458 /* Finite Cyclic Group */
1459 wpabuf_put_le16(data, hapd->conf->fils_dh_group);
1460
1461 /* Element */
1462 wpabuf_put_buf(data, pub);
1463 }
1464#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001465
1466 /* RSNE */
1467 wpabuf_put_data(data, ie, ielen);
1468
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001469 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1470
1471#ifdef CONFIG_IEEE80211R_AP
1472 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm))) {
1473 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1474 int res;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001475 int use_sha384 = wpa_key_mgmt_sha384(
1476 wpa_auth_sta_key_mgmt(sta->wpa_sm));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001477
Roshan Pius3a1667e2018-07-03 15:17:14 -07001478 res = wpa_auth_write_fte(hapd->wpa_auth, use_sha384,
1479 wpabuf_put(data, 0),
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001480 wpabuf_tailroom(data));
1481 if (res < 0) {
1482 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1483 goto fail;
1484 }
1485 wpabuf_put(data, res);
1486 }
1487#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001488
1489 /* FILS Nonce */
1490 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1491 wpabuf_put_u8(data, 1 + FILS_NONCE_LEN); /* Length */
1492 /* Element ID Extension */
1493 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_NONCE);
1494 wpabuf_put_data(data, fils_nonce, FILS_NONCE_LEN);
1495
1496 /* FILS Session */
1497 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1498 wpabuf_put_u8(data, 1 + FILS_SESSION_LEN); /* Length */
1499 /* Element ID Extension */
1500 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_SESSION);
1501 wpabuf_put_data(data, sta->fils_session, FILS_SESSION_LEN);
1502
1503 /* FILS Wrapped Data */
1504 if (!pmksa && erp_resp) {
1505 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1506 wpabuf_put_u8(data, 1 + wpabuf_len(erp_resp)); /* Length */
1507 /* Element ID Extension */
1508 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_WRAPPED_DATA);
1509 wpabuf_put_buf(data, erp_resp);
1510
Paul Stewart092955c2017-02-06 09:13:09 -08001511 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta->wpa_sm),
1512 msk, msk_len, sta->fils_snonce, fils_nonce,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001513 sta->fils_dh_ss ?
1514 wpabuf_head(sta->fils_dh_ss) : NULL,
1515 sta->fils_dh_ss ?
1516 wpabuf_len(sta->fils_dh_ss) : 0,
1517 pmk_buf, &pmk_len)) {
Paul Stewart092955c2017-02-06 09:13:09 -08001518 wpa_printf(MSG_DEBUG, "FILS: Failed to derive PMK");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001519 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Paul Stewart092955c2017-02-06 09:13:09 -08001520 wpabuf_free(data);
1521 data = NULL;
1522 goto fail;
1523 }
1524 pmk = pmk_buf;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001525
1526 /* Don't use DHss in PTK derivation if PMKSA caching is not
1527 * used. */
1528 wpabuf_clear_free(sta->fils_dh_ss);
1529 sta->fils_dh_ss = NULL;
1530
1531 if (sta->fils_erp_pmkid_set) {
1532 /* TODO: get PMKLifetime from WPA parameters */
1533 unsigned int dot11RSNAConfigPMKLifetime = 43200;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001534 int session_timeout;
1535
1536 session_timeout = dot11RSNAConfigPMKLifetime;
1537 if (sta->session_timeout_set) {
1538 struct os_reltime now, diff;
1539
1540 os_get_reltime(&now);
1541 os_reltime_sub(&sta->session_timeout, &now,
1542 &diff);
1543 session_timeout = diff.sec;
1544 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001545
1546 sta->fils_erp_pmkid_set = 0;
1547 if (wpa_auth_pmksa_add2(
1548 hapd->wpa_auth, sta->addr,
1549 pmk, pmk_len,
1550 sta->fils_erp_pmkid,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001551 session_timeout,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001552 wpa_auth_sta_key_mgmt(sta->wpa_sm)) < 0) {
1553 wpa_printf(MSG_ERROR,
1554 "FILS: Failed to add PMKSA cache entry based on ERP");
1555 }
1556 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001557 } else if (pmksa) {
1558 pmk = pmksa->pmk;
1559 pmk_len = pmksa->pmk_len;
1560 }
1561
1562 if (!pmk) {
1563 wpa_printf(MSG_DEBUG, "FILS: No PMK available");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001564 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001565 wpabuf_free(data);
1566 data = NULL;
1567 goto fail;
1568 }
1569
1570 if (fils_auth_pmk_to_ptk(sta->wpa_sm, pmk, pmk_len,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001571 sta->fils_snonce, fils_nonce,
1572 sta->fils_dh_ss ?
1573 wpabuf_head(sta->fils_dh_ss) : NULL,
1574 sta->fils_dh_ss ?
1575 wpabuf_len(sta->fils_dh_ss) : 0,
1576 sta->fils_g_sta, pub) < 0) {
1577 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001578 wpabuf_free(data);
1579 data = NULL;
1580 goto fail;
1581 }
1582
1583fail:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001584 if (is_pub)
1585 *is_pub = pub != NULL;
1586 os_free(ie_buf);
1587 wpabuf_free(pub);
1588 wpabuf_clear_free(sta->fils_dh_ss);
1589 sta->fils_dh_ss = NULL;
1590#ifdef CONFIG_FILS_SK_PFS
1591 crypto_ecdh_deinit(sta->fils_ecdh);
1592 sta->fils_ecdh = NULL;
1593#endif /* CONFIG_FILS_SK_PFS */
1594 return data;
1595}
1596
1597
1598static void handle_auth_fils_finish(struct hostapd_data *hapd,
1599 struct sta_info *sta, u16 resp,
1600 struct wpabuf *data, int pub)
1601{
1602 u16 auth_alg;
1603
1604 auth_alg = (pub ||
1605 resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) ?
1606 WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
1607 send_auth_reply(hapd, sta->addr, hapd->own_addr, auth_alg, 2, resp,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001608 data ? wpabuf_head(data) : (u8 *) "",
Roshan Pius3a1667e2018-07-03 15:17:14 -07001609 data ? wpabuf_len(data) : 0, "auth-fils-finish");
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001610 wpabuf_free(data);
1611
1612 if (resp == WLAN_STATUS_SUCCESS) {
1613 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1614 HOSTAPD_LEVEL_DEBUG,
1615 "authentication OK (FILS)");
1616 sta->flags |= WLAN_STA_AUTH;
1617 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001618 sta->auth_alg = pub ? WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001619 mlme_authenticate_indication(hapd, sta);
1620 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001621}
1622
1623
1624void ieee802_11_finish_fils_auth(struct hostapd_data *hapd,
1625 struct sta_info *sta, int success,
1626 struct wpabuf *erp_resp,
1627 const u8 *msk, size_t msk_len)
1628{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001629 struct wpabuf *data;
1630 int pub = 0;
1631 u16 resp;
1632
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001633 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001634
1635 if (!sta->fils_pending_cb)
1636 return;
1637 resp = success ? WLAN_STATUS_SUCCESS : WLAN_STATUS_UNSPECIFIED_FAILURE;
1638 data = prepare_auth_resp_fils(hapd, sta, &resp, NULL, erp_resp,
1639 msk, msk_len, &pub);
1640 if (!data) {
1641 wpa_printf(MSG_DEBUG,
1642 "%s: prepare_auth_resp_fils() returned failure",
1643 __func__);
1644 }
1645 sta->fils_pending_cb(hapd, sta, resp, data, pub);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001646}
1647
1648#endif /* CONFIG_FILS */
1649
1650
Roshan Pius3a1667e2018-07-03 15:17:14 -07001651int
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001652ieee802_11_allowed_address(struct hostapd_data *hapd, const u8 *addr,
1653 const u8 *msg, size_t len, u32 *session_timeout,
1654 u32 *acct_interim_interval,
1655 struct vlan_description *vlan_id,
1656 struct hostapd_sta_wpa_psk_short **psk,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001657 char **identity, char **radius_cui, int is_probe_req)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001658{
1659 int res;
1660
1661 os_memset(vlan_id, 0, sizeof(*vlan_id));
1662 res = hostapd_allowed_address(hapd, addr, msg, len,
1663 session_timeout, acct_interim_interval,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001664 vlan_id, psk, identity, radius_cui,
1665 is_probe_req);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001666
1667 if (res == HOSTAPD_ACL_REJECT) {
1668 wpa_printf(MSG_INFO,
1669 "Station " MACSTR " not allowed to authenticate",
1670 MAC2STR(addr));
1671 return HOSTAPD_ACL_REJECT;
1672 }
1673
1674 if (res == HOSTAPD_ACL_PENDING) {
1675 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1676 " waiting for an external authentication",
1677 MAC2STR(addr));
1678 /* Authentication code will re-send the authentication frame
1679 * after it has received (and cached) information from the
1680 * external source. */
1681 return HOSTAPD_ACL_PENDING;
1682 }
1683
1684 return res;
1685}
1686
1687
1688static int
1689ieee802_11_set_radius_info(struct hostapd_data *hapd, struct sta_info *sta,
1690 int res, u32 session_timeout,
1691 u32 acct_interim_interval,
1692 struct vlan_description *vlan_id,
1693 struct hostapd_sta_wpa_psk_short **psk,
1694 char **identity, char **radius_cui)
1695{
1696 if (vlan_id->notempty &&
1697 !hostapd_vlan_valid(hapd->conf->vlan, vlan_id)) {
1698 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1699 HOSTAPD_LEVEL_INFO,
1700 "Invalid VLAN %d%s received from RADIUS server",
1701 vlan_id->untagged,
1702 vlan_id->tagged[0] ? "+" : "");
1703 return -1;
1704 }
1705 if (ap_sta_set_vlan(hapd, sta, vlan_id) < 0)
1706 return -1;
1707 if (sta->vlan_id)
1708 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1709 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1710
1711 hostapd_free_psk_list(sta->psk);
1712 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1713 sta->psk = *psk;
1714 *psk = NULL;
1715 } else {
1716 sta->psk = NULL;
1717 }
1718
Roshan Pius3a1667e2018-07-03 15:17:14 -07001719 os_free(sta->identity);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001720 sta->identity = *identity;
1721 *identity = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001722
1723 os_free(sta->radius_cui);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001724 sta->radius_cui = *radius_cui;
1725 *radius_cui = NULL;
1726
1727 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1728 sta->acct_interim_interval = acct_interim_interval;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001729 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT) {
1730 sta->session_timeout_set = 1;
1731 os_get_reltime(&sta->session_timeout);
1732 sta->session_timeout.sec += session_timeout;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001733 ap_sta_session_timeout(hapd, sta, session_timeout);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001734 } else {
1735 sta->session_timeout_set = 0;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001736 ap_sta_no_session_timeout(hapd, sta);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001737 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001738
1739 return 0;
1740}
1741
1742
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743static void handle_auth(struct hostapd_data *hapd,
1744 const struct ieee80211_mgmt *mgmt, size_t len)
1745{
1746 u16 auth_alg, auth_transaction, status_code;
1747 u16 resp = WLAN_STATUS_SUCCESS;
1748 struct sta_info *sta = NULL;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001749 int res, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001750 u16 fc;
1751 const u8 *challenge = NULL;
1752 u32 session_timeout, acct_interim_interval;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001753 struct vlan_description vlan_id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001754 struct hostapd_sta_wpa_psk_short *psk = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001755 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1756 size_t resp_ies_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001757 char *identity = NULL;
1758 char *radius_cui = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001759 u16 seq_ctrl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001760
1761 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001762 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
1763 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764 return;
1765 }
1766
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001767#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001768 if (hapd->iconf->ignore_auth_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001769 drand48() < hapd->iconf->ignore_auth_probability) {
1770 wpa_printf(MSG_INFO,
1771 "TESTING: ignoring auth frame from " MACSTR,
1772 MAC2STR(mgmt->sa));
1773 return;
1774 }
1775#endif /* CONFIG_TESTING_OPTIONS */
1776
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1778 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1779 status_code = le_to_host16(mgmt->u.auth.status_code);
1780 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001781 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001782
1783 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
1784 2 + WLAN_AUTH_CHALLENGE_LEN &&
1785 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
1786 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
1787 challenge = &mgmt->u.auth.variable[2];
1788
1789 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001790 "auth_transaction=%d status_code=%d wep=%d%s "
1791 "seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001792 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
1793 status_code, !!(fc & WLAN_FC_ISWEP),
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001794 challenge ? " challenge" : "",
1795 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001796
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001797#ifdef CONFIG_NO_RC4
1798 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
1799 wpa_printf(MSG_INFO,
1800 "Unsupported authentication algorithm (%d)",
1801 auth_alg);
1802 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1803 goto fail;
1804 }
1805#endif /* CONFIG_NO_RC4 */
1806
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001807 if (hapd->tkip_countermeasures) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001808 wpa_printf(MSG_DEBUG,
1809 "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication");
1810 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001811 goto fail;
1812 }
1813
1814 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
1815 auth_alg == WLAN_AUTH_OPEN) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001816#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001817 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001818 auth_alg == WLAN_AUTH_FT) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001819#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001820#ifdef CONFIG_SAE
1821 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
1822 auth_alg == WLAN_AUTH_SAE) ||
1823#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001824#ifdef CONFIG_FILS
1825 (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
1826 auth_alg == WLAN_AUTH_FILS_SK) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001827 (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
1828 hapd->conf->fils_dh_group &&
1829 auth_alg == WLAN_AUTH_FILS_SK_PFS) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001830#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001831 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
1832 auth_alg == WLAN_AUTH_SHARED_KEY))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001833 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
1834 auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1836 goto fail;
1837 }
1838
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001839 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001840 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001841 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
1842 auth_transaction);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001843 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1844 goto fail;
1845 }
1846
1847 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001848 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1849 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1851 goto fail;
1852 }
1853
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001854 if (hapd->conf->no_auth_if_seen_on) {
1855 struct hostapd_data *other;
1856
1857 other = sta_track_seen_on(hapd->iface, mgmt->sa,
1858 hapd->conf->no_auth_if_seen_on);
1859 if (other) {
1860 u8 *pos;
1861 u32 info;
1862 u8 op_class, channel, phytype;
1863
1864 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
1865 MACSTR " since STA has been seen on %s",
1866 hapd->conf->iface, MAC2STR(mgmt->sa),
1867 hapd->conf->no_auth_if_seen_on);
1868
1869 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1870 pos = &resp_ies[0];
1871 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1872 *pos++ = 13;
1873 os_memcpy(pos, other->own_addr, ETH_ALEN);
1874 pos += ETH_ALEN;
1875 info = 0; /* TODO: BSSID Information */
1876 WPA_PUT_LE32(pos, info);
1877 pos += 4;
1878 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1879 phytype = 8; /* dmg */
1880 else if (other->iconf->ieee80211ac)
1881 phytype = 9; /* vht */
1882 else if (other->iconf->ieee80211n)
1883 phytype = 7; /* ht */
1884 else if (other->iconf->hw_mode ==
1885 HOSTAPD_MODE_IEEE80211A)
1886 phytype = 4; /* ofdm */
1887 else if (other->iconf->hw_mode ==
1888 HOSTAPD_MODE_IEEE80211G)
1889 phytype = 6; /* erp */
1890 else
1891 phytype = 5; /* hrdsss */
1892 if (ieee80211_freq_to_channel_ext(
1893 hostapd_hw_get_freq(other,
1894 other->iconf->channel),
1895 other->iconf->secondary_channel,
1896 other->iconf->ieee80211ac,
1897 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1898 op_class = 0;
1899 channel = other->iconf->channel;
1900 }
1901 *pos++ = op_class;
1902 *pos++ = channel;
1903 *pos++ = phytype;
1904 resp_ies_len = pos - &resp_ies[0];
1905 goto fail;
1906 }
1907 }
1908
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001909 res = ieee802_11_allowed_address(
1910 hapd, mgmt->sa, (const u8 *) mgmt, len, &session_timeout,
Roshan Pius3a1667e2018-07-03 15:17:14 -07001911 &acct_interim_interval, &vlan_id, &psk, &identity, &radius_cui,
1912 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001913 if (res == HOSTAPD_ACL_REJECT) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001914 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1915 "Ignore Authentication frame from " MACSTR
1916 " due to ACL reject", MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001917 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1918 goto fail;
1919 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001920 if (res == HOSTAPD_ACL_PENDING)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001921 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001922
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001923 sta = ap_get_sta(hapd, mgmt->sa);
1924 if (sta) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001925 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001926 if ((fc & WLAN_FC_RETRY) &&
1927 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1928 sta->last_seq_ctrl == seq_ctrl &&
1929 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1930 hostapd_logger(hapd, sta->addr,
1931 HOSTAPD_MODULE_IEEE80211,
1932 HOSTAPD_LEVEL_DEBUG,
1933 "Drop repeated authentication frame seq_ctrl=0x%x",
1934 seq_ctrl);
1935 return;
1936 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001937#ifdef CONFIG_MESH
1938 if ((hapd->conf->mesh & MESH_ENABLED) &&
1939 sta->plink_state == PLINK_BLOCKED) {
1940 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1941 " is blocked - drop Authentication frame",
1942 MAC2STR(mgmt->sa));
1943 return;
1944 }
1945#endif /* CONFIG_MESH */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001946 } else {
1947#ifdef CONFIG_MESH
1948 if (hapd->conf->mesh & MESH_ENABLED) {
1949 /* if the mesh peer is not available, we don't do auth.
1950 */
1951 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001952 " not yet known - drop Authentication frame",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001953 MAC2STR(mgmt->sa));
1954 /*
1955 * Save a copy of the frame so that it can be processed
1956 * if a new peer entry is added shortly after this.
1957 */
1958 wpabuf_free(hapd->mesh_pending_auth);
1959 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1960 os_get_reltime(&hapd->mesh_pending_auth_time);
1961 return;
1962 }
1963#endif /* CONFIG_MESH */
1964
1965 sta = ap_sta_add(hapd, mgmt->sa);
1966 if (!sta) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001967 wpa_printf(MSG_DEBUG, "ap_sta_add() failed");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001968 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1969 goto fail;
1970 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001971 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001972 sta->last_seq_ctrl = seq_ctrl;
1973 sta->last_subtype = WLAN_FC_STYPE_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001974
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001975 res = ieee802_11_set_radius_info(
1976 hapd, sta, res, session_timeout, acct_interim_interval,
1977 &vlan_id, &psk, &identity, &radius_cui);
1978 if (res) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001979 wpa_printf(MSG_DEBUG, "ieee802_11_set_radius_info() failed");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001980 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1981 goto fail;
1982 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001983
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001984 sta->flags &= ~WLAN_STA_PREAUTH;
1985 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1986
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001987 /*
1988 * If the driver supports full AP client state, add a station to the
1989 * driver before sending authentication reply to make sure the driver
1990 * has resources, and not to go through the entire authentication and
1991 * association handshake, and fail it at the end.
1992 *
1993 * If this is not the first transaction, in a multi-step authentication
1994 * algorithm, the station already exists in the driver
1995 * (sta->added_unassoc = 1) so skip it.
1996 *
1997 * In mesh mode, the station was already added to the driver when the
1998 * NEW_PEER_CANDIDATE event is received.
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001999 *
2000 * If PMF was negotiated for the existing association, skip this to
2001 * avoid dropping the STA entry and the associated keys. This is needed
2002 * to allow the original connection work until the attempt can complete
2003 * (re)association, so that unprotected Authentication frame cannot be
2004 * used to bypass PMF protection.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002005 */
2006 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002007 (!(sta->flags & WLAN_STA_MFP) || !ap_sta_is_authorized(sta)) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002008 !(hapd->conf->mesh & MESH_ENABLED) &&
2009 !(sta->added_unassoc)) {
2010 /*
2011 * If a station that is already associated to the AP, is trying
2012 * to authenticate again, remove the STA entry, in order to make
2013 * sure the STA PS state gets cleared and configuration gets
2014 * updated. To handle this, station's added_unassoc flag is
2015 * cleared once the station has completed association.
2016 */
2017 hostapd_drv_sta_remove(hapd, sta->addr);
2018 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
2019 WLAN_STA_AUTHORIZED);
2020
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07002021 if (hostapd_sta_add(hapd, sta->addr, 0, 0, NULL, 0, 0,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002022 NULL, NULL, sta->flags, 0, 0, 0, 0)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002023 hostapd_logger(hapd, sta->addr,
2024 HOSTAPD_MODULE_IEEE80211,
2025 HOSTAPD_LEVEL_NOTICE,
2026 "Could not add STA to kernel driver");
2027 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2028 goto fail;
2029 }
2030
2031 sta->added_unassoc = 1;
2032 }
2033
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002034 switch (auth_alg) {
2035 case WLAN_AUTH_OPEN:
2036 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2037 HOSTAPD_LEVEL_DEBUG,
2038 "authentication OK (open system)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002039 sta->flags |= WLAN_STA_AUTH;
2040 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
2041 sta->auth_alg = WLAN_AUTH_OPEN;
2042 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002043 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002044#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002045 case WLAN_AUTH_SHARED_KEY:
2046 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
2047 fc & WLAN_FC_ISWEP);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002048 if (resp != 0)
2049 wpa_printf(MSG_DEBUG,
2050 "auth_shared_key() failed: status=%d", resp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002051 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
2052 mlme_authenticate_indication(hapd, sta);
2053 if (sta->challenge && auth_transaction == 1) {
2054 resp_ies[0] = WLAN_EID_CHALLENGE;
2055 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
2056 os_memcpy(resp_ies + 2, sta->challenge,
2057 WLAN_AUTH_CHALLENGE_LEN);
2058 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
2059 }
2060 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002061#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002062#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002063 case WLAN_AUTH_FT:
2064 sta->auth_alg = WLAN_AUTH_FT;
2065 if (sta->wpa_sm == NULL)
2066 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002067 sta->addr, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002068 if (sta->wpa_sm == NULL) {
2069 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
2070 "state machine");
2071 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2072 goto fail;
2073 }
2074 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
2075 auth_transaction, mgmt->u.auth.variable,
2076 len - IEEE80211_HDRLEN -
2077 sizeof(mgmt->u.auth),
2078 handle_auth_ft_finish, hapd);
2079 /* handle_auth_ft_finish() callback will complete auth. */
2080 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002081#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002082#ifdef CONFIG_SAE
2083 case WLAN_AUTH_SAE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002084#ifdef CONFIG_MESH
2085 if (status_code == WLAN_STATUS_SUCCESS &&
2086 hapd->conf->mesh & MESH_ENABLED) {
2087 if (sta->wpa_sm == NULL)
2088 sta->wpa_sm =
2089 wpa_auth_sta_init(hapd->wpa_auth,
2090 sta->addr, NULL);
2091 if (sta->wpa_sm == NULL) {
2092 wpa_printf(MSG_DEBUG,
2093 "SAE: Failed to initialize WPA state machine");
2094 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2095 goto fail;
2096 }
2097 }
2098#endif /* CONFIG_MESH */
2099 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
2100 status_code);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002101 return;
2102#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002103#ifdef CONFIG_FILS
2104 case WLAN_AUTH_FILS_SK:
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002105 case WLAN_AUTH_FILS_SK_PFS:
2106 handle_auth_fils(hapd, sta, mgmt->u.auth.variable,
2107 len - IEEE80211_HDRLEN - sizeof(mgmt->u.auth),
2108 auth_alg, auth_transaction, status_code,
2109 handle_auth_fils_finish);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002110 return;
2111#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002112 }
2113
2114 fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002115 os_free(identity);
2116 os_free(radius_cui);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002117 hostapd_free_psk_list(psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002118
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002119 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
2120 auth_transaction + 1, resp, resp_ies,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002121 resp_ies_len, "handle-auth");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002122
2123 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
2124 reply_res != WLAN_STATUS_SUCCESS)) {
2125 hostapd_drv_sta_remove(hapd, sta->addr);
2126 sta->added_unassoc = 0;
2127 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002128}
2129
2130
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002131int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132{
2133 int i, j = 32, aid;
2134
2135 /* get a unique AID */
2136 if (sta->aid > 0) {
2137 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
2138 return 0;
2139 }
2140
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002141 if (TEST_FAIL())
2142 return -1;
2143
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002144 for (i = 0; i < AID_WORDS; i++) {
2145 if (hapd->sta_aid[i] == (u32) -1)
2146 continue;
2147 for (j = 0; j < 32; j++) {
2148 if (!(hapd->sta_aid[i] & BIT(j)))
2149 break;
2150 }
2151 if (j < 32)
2152 break;
2153 }
2154 if (j == 32)
2155 return -1;
2156 aid = i * 32 + j + 1;
2157 if (aid > 2007)
2158 return -1;
2159
2160 sta->aid = aid;
2161 hapd->sta_aid[i] |= BIT(j);
2162 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
2163 return 0;
2164}
2165
2166
2167static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
2168 const u8 *ssid_ie, size_t ssid_ie_len)
2169{
2170 if (ssid_ie == NULL)
2171 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2172
2173 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
2174 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002175 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2176 HOSTAPD_LEVEL_INFO,
2177 "Station tried to associate with unknown SSID "
Dmitry Shmidt3c479372014-02-04 10:50:36 -08002178 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002179 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2180 }
2181
2182 return WLAN_STATUS_SUCCESS;
2183}
2184
2185
2186static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
2187 const u8 *wmm_ie, size_t wmm_ie_len)
2188{
2189 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002190 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002191 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002192 struct wmm_information_element *wmm;
2193
2194 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002195 hostapd_logger(hapd, sta->addr,
2196 HOSTAPD_MODULE_WPA,
2197 HOSTAPD_LEVEL_DEBUG,
2198 "invalid WMM element in association "
2199 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002200 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2201 }
2202
2203 sta->flags |= WLAN_STA_WMM;
2204 wmm = (struct wmm_information_element *) wmm_ie;
2205 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002206 }
2207 return WLAN_STATUS_SUCCESS;
2208}
2209
2210
2211static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
2212 struct ieee802_11_elems *elems)
2213{
Dmitry Shmidt29333592017-01-09 12:27:11 -08002214 /* Supported rates not used in IEEE 802.11ad/DMG */
2215 if (hapd->iface->current_mode &&
2216 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD)
2217 return WLAN_STATUS_SUCCESS;
2218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002219 if (!elems->supp_rates) {
2220 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2221 HOSTAPD_LEVEL_DEBUG,
2222 "No supported rates element in AssocReq");
2223 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2224 }
2225
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002226 if (elems->supp_rates_len + elems->ext_supp_rates_len >
2227 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002228 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2229 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002230 "Invalid supported rates element length %d+%d",
2231 elems->supp_rates_len,
2232 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002233 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2234 }
2235
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002236 sta->supported_rates_len = merge_byte_arrays(
2237 sta->supported_rates, sizeof(sta->supported_rates),
2238 elems->supp_rates, elems->supp_rates_len,
2239 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002240
2241 return WLAN_STATUS_SUCCESS;
2242}
2243
2244
Dmitry Shmidt051af732013-10-22 13:52:46 -07002245static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
2246 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
2247{
2248#ifdef CONFIG_INTERWORKING
2249 /* check for QoS Map support */
2250 if (ext_capab_ie_len >= 5) {
2251 if (ext_capab_ie[4] & 0x01)
2252 sta->qos_map_enabled = 1;
2253 }
2254#endif /* CONFIG_INTERWORKING */
2255
Roshan Pius3a1667e2018-07-03 15:17:14 -07002256 if (ext_capab_ie_len > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002257 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
Roshan Pius3a1667e2018-07-03 15:17:14 -07002258 os_free(sta->ext_capability);
2259 sta->ext_capability = os_malloc(1 + ext_capab_ie_len);
2260 if (sta->ext_capability) {
2261 sta->ext_capability[0] = ext_capab_ie_len;
2262 os_memcpy(sta->ext_capability + 1, ext_capab_ie,
2263 ext_capab_ie_len);
2264 }
2265 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002266
Dmitry Shmidt051af732013-10-22 13:52:46 -07002267 return WLAN_STATUS_SUCCESS;
2268}
2269
2270
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002271#ifdef CONFIG_OWE
2272
2273static int owe_group_supported(struct hostapd_data *hapd, u16 group)
2274{
2275 int i;
2276 int *groups = hapd->conf->owe_groups;
2277
2278 if (group != 19 && group != 20 && group != 21)
2279 return 0;
2280
2281 if (!groups)
2282 return 1;
2283
2284 for (i = 0; groups[i] > 0; i++) {
2285 if (groups[i] == group)
2286 return 1;
2287 }
2288
2289 return 0;
2290}
2291
2292
2293static u16 owe_process_assoc_req(struct hostapd_data *hapd,
2294 struct sta_info *sta, const u8 *owe_dh,
2295 u8 owe_dh_len)
2296{
2297 struct wpabuf *secret, *pub, *hkey;
2298 int res;
2299 u8 prk[SHA512_MAC_LEN], pmkid[SHA512_MAC_LEN];
2300 const char *info = "OWE Key Generation";
2301 const u8 *addr[2];
2302 size_t len[2];
2303 u16 group;
2304 size_t hash_len, prime_len;
2305
2306 if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) {
2307 wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching");
2308 return WLAN_STATUS_SUCCESS;
2309 }
2310
2311 group = WPA_GET_LE16(owe_dh);
2312 if (!owe_group_supported(hapd, group)) {
2313 wpa_printf(MSG_DEBUG, "OWE: Unsupported DH group %u", group);
2314 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2315 }
2316 if (group == 19)
2317 prime_len = 32;
2318 else if (group == 20)
2319 prime_len = 48;
2320 else if (group == 21)
2321 prime_len = 66;
2322 else
2323 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2324
2325 crypto_ecdh_deinit(sta->owe_ecdh);
2326 sta->owe_ecdh = crypto_ecdh_init(group);
2327 if (!sta->owe_ecdh)
2328 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2329 sta->owe_group = group;
2330
2331 secret = crypto_ecdh_set_peerkey(sta->owe_ecdh, 0, owe_dh + 2,
2332 owe_dh_len - 2);
2333 secret = wpabuf_zeropad(secret, prime_len);
2334 if (!secret) {
2335 wpa_printf(MSG_DEBUG, "OWE: Invalid peer DH public key");
2336 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2337 }
2338 wpa_hexdump_buf_key(MSG_DEBUG, "OWE: DH shared secret", secret);
2339
2340 /* prk = HKDF-extract(C | A | group, z) */
2341
2342 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
2343 if (!pub) {
2344 wpabuf_clear_free(secret);
2345 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2346 }
2347
2348 /* PMKID = Truncate-128(Hash(C | A)) */
2349 addr[0] = owe_dh + 2;
2350 len[0] = owe_dh_len - 2;
2351 addr[1] = wpabuf_head(pub);
2352 len[1] = wpabuf_len(pub);
2353 if (group == 19) {
2354 res = sha256_vector(2, addr, len, pmkid);
2355 hash_len = SHA256_MAC_LEN;
2356 } else if (group == 20) {
2357 res = sha384_vector(2, addr, len, pmkid);
2358 hash_len = SHA384_MAC_LEN;
2359 } else if (group == 21) {
2360 res = sha512_vector(2, addr, len, pmkid);
2361 hash_len = SHA512_MAC_LEN;
2362 } else {
2363 wpabuf_free(pub);
2364 wpabuf_clear_free(secret);
2365 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2366 }
2367 pub = wpabuf_zeropad(pub, prime_len);
2368 if (res < 0 || !pub) {
2369 wpabuf_free(pub);
2370 wpabuf_clear_free(secret);
2371 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2372 }
2373
2374 hkey = wpabuf_alloc(owe_dh_len - 2 + wpabuf_len(pub) + 2);
2375 if (!hkey) {
2376 wpabuf_free(pub);
2377 wpabuf_clear_free(secret);
2378 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2379 }
2380
2381 wpabuf_put_data(hkey, owe_dh + 2, owe_dh_len - 2); /* C */
2382 wpabuf_put_buf(hkey, pub); /* A */
2383 wpabuf_free(pub);
2384 wpabuf_put_le16(hkey, group); /* group */
2385 if (group == 19)
2386 res = hmac_sha256(wpabuf_head(hkey), wpabuf_len(hkey),
2387 wpabuf_head(secret), wpabuf_len(secret), prk);
2388 else if (group == 20)
2389 res = hmac_sha384(wpabuf_head(hkey), wpabuf_len(hkey),
2390 wpabuf_head(secret), wpabuf_len(secret), prk);
2391 else if (group == 21)
2392 res = hmac_sha512(wpabuf_head(hkey), wpabuf_len(hkey),
2393 wpabuf_head(secret), wpabuf_len(secret), prk);
2394 wpabuf_clear_free(hkey);
2395 wpabuf_clear_free(secret);
2396 if (res < 0)
2397 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2398
2399 wpa_hexdump_key(MSG_DEBUG, "OWE: prk", prk, hash_len);
2400
2401 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2402
2403 os_free(sta->owe_pmk);
2404 sta->owe_pmk = os_malloc(hash_len);
2405 if (!sta->owe_pmk) {
2406 os_memset(prk, 0, SHA512_MAC_LEN);
2407 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2408 }
2409
2410 if (group == 19)
2411 res = hmac_sha256_kdf(prk, hash_len, NULL, (const u8 *) info,
2412 os_strlen(info), sta->owe_pmk, hash_len);
2413 else if (group == 20)
2414 res = hmac_sha384_kdf(prk, hash_len, NULL, (const u8 *) info,
2415 os_strlen(info), sta->owe_pmk, hash_len);
2416 else if (group == 21)
2417 res = hmac_sha512_kdf(prk, hash_len, NULL, (const u8 *) info,
2418 os_strlen(info), sta->owe_pmk, hash_len);
2419 os_memset(prk, 0, SHA512_MAC_LEN);
2420 if (res < 0) {
2421 os_free(sta->owe_pmk);
2422 sta->owe_pmk = NULL;
2423 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2424 }
2425 sta->owe_pmk_len = hash_len;
2426
2427 wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sta->owe_pmk, sta->owe_pmk_len);
2428 wpa_hexdump(MSG_DEBUG, "OWE: PMKID", pmkid, PMKID_LEN);
2429 wpa_auth_pmksa_add2(hapd->wpa_auth, sta->addr, sta->owe_pmk,
2430 sta->owe_pmk_len, pmkid, 0, WPA_KEY_MGMT_OWE);
2431
2432 return WLAN_STATUS_SUCCESS;
2433}
2434
2435#endif /* CONFIG_OWE */
2436
2437
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002438static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
2439 const u8 *ies, size_t ies_len, int reassoc)
2440{
2441 struct ieee802_11_elems elems;
2442 u16 resp;
2443 const u8 *wpa_ie;
2444 size_t wpa_ie_len;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002445 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002446
2447 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
2448 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2449 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
2450 "association request");
2451 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2452 }
2453
2454 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
2455 if (resp != WLAN_STATUS_SUCCESS)
2456 return resp;
2457 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
2458 if (resp != WLAN_STATUS_SUCCESS)
2459 return resp;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002460 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
2461 if (resp != WLAN_STATUS_SUCCESS)
2462 return resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002463 resp = copy_supp_rates(hapd, sta, &elems);
2464 if (resp != WLAN_STATUS_SUCCESS)
2465 return resp;
2466#ifdef CONFIG_IEEE80211N
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002467 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002468 if (resp != WLAN_STATUS_SUCCESS)
2469 return resp;
2470 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
2471 !(sta->flags & WLAN_STA_HT)) {
2472 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2473 HOSTAPD_LEVEL_INFO, "Station does not support "
2474 "mandatory HT PHY - reject association");
2475 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
2476 }
2477#endif /* CONFIG_IEEE80211N */
2478
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002479#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002480 if (hapd->iconf->ieee80211ac) {
2481 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
2482 if (resp != WLAN_STATUS_SUCCESS)
2483 return resp;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08002484
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002485 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
2486 if (resp != WLAN_STATUS_SUCCESS)
2487 return resp;
2488 }
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08002489
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002490 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
2491 !(sta->flags & WLAN_STA_VHT)) {
2492 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2493 HOSTAPD_LEVEL_INFO, "Station does not support "
2494 "mandatory VHT PHY - reject association");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002495 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002496 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002497
2498 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
2499 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
2500 elems.vendor_vht_len);
2501 if (resp != WLAN_STATUS_SUCCESS)
2502 return resp;
2503 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002504#endif /* CONFIG_IEEE80211AC */
2505
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002506#ifdef CONFIG_P2P
2507 if (elems.p2p) {
2508 wpabuf_free(sta->p2p_ie);
2509 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
2510 P2P_IE_VENDOR_TYPE);
2511 if (sta->p2p_ie)
2512 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
2513 } else {
2514 wpabuf_free(sta->p2p_ie);
2515 sta->p2p_ie = NULL;
2516 }
2517#endif /* CONFIG_P2P */
2518
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002519 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
2520 wpa_ie = elems.rsn_ie;
2521 wpa_ie_len = elems.rsn_ie_len;
2522 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
2523 elems.wpa_ie) {
2524 wpa_ie = elems.wpa_ie;
2525 wpa_ie_len = elems.wpa_ie_len;
2526 } else {
2527 wpa_ie = NULL;
2528 wpa_ie_len = 0;
2529 }
2530
2531#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002532 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002533 if (hapd->conf->wps_state && elems.wps_ie) {
2534 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
2535 "Request - assume WPS is used");
2536 sta->flags |= WLAN_STA_WPS;
2537 wpabuf_free(sta->wps_ie);
2538 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
2539 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002540 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
2541 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
2542 sta->flags |= WLAN_STA_WPS2;
2543 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002544 wpa_ie = NULL;
2545 wpa_ie_len = 0;
2546 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
2547 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
2548 "(Re)Association Request - reject");
2549 return WLAN_STATUS_INVALID_IE;
2550 }
2551 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
2552 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
2553 "(Re)Association Request - possible WPS use");
2554 sta->flags |= WLAN_STA_MAYBE_WPS;
2555 } else
2556#endif /* CONFIG_WPS */
2557 if (hapd->conf->wpa && wpa_ie == NULL) {
2558 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2559 HOSTAPD_LEVEL_INFO,
2560 "No WPA/RSN IE in association request");
2561 return WLAN_STATUS_INVALID_IE;
2562 }
2563
2564 if (hapd->conf->wpa && wpa_ie) {
2565 int res;
2566 wpa_ie -= 2;
2567 wpa_ie_len += 2;
2568 if (sta->wpa_sm == NULL)
2569 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002570 sta->addr,
2571 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002572 if (sta->wpa_sm == NULL) {
2573 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
2574 "state machine");
2575 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2576 }
2577 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
2578 wpa_ie, wpa_ie_len,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002579 elems.mdie, elems.mdie_len,
2580 elems.owe_dh, elems.owe_dh_len);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002581 resp = wpa_res_to_status_code(res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002582 if (resp != WLAN_STATUS_SUCCESS)
2583 return resp;
2584#ifdef CONFIG_IEEE80211W
2585 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
2586 sta->sa_query_count > 0)
2587 ap_check_sa_query_timeout(hapd, sta);
2588 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
2589 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
2590 /*
2591 * STA has already been associated with MFP and SA
2592 * Query timeout has not been reached. Reject the
2593 * association attempt temporarily and start SA Query,
2594 * if one is not pending.
2595 */
2596
2597 if (sta->sa_query_count == 0)
2598 ap_sta_start_sa_query(hapd, sta);
2599
2600 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
2601 }
2602
2603 if (wpa_auth_uses_mfp(sta->wpa_sm))
2604 sta->flags |= WLAN_STA_MFP;
2605 else
2606 sta->flags &= ~WLAN_STA_MFP;
2607#endif /* CONFIG_IEEE80211W */
2608
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002609#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002610 if (sta->auth_alg == WLAN_AUTH_FT) {
2611 if (!reassoc) {
2612 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
2613 "to use association (not "
2614 "re-association) with FT auth_alg",
2615 MAC2STR(sta->addr));
2616 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2617 }
2618
2619 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
2620 ies_len);
2621 if (resp != WLAN_STATUS_SUCCESS)
2622 return resp;
2623 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002624#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002625
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002626#ifdef CONFIG_SAE
Roshan Pius3a1667e2018-07-03 15:17:14 -07002627 if (wpa_auth_uses_sae(sta->wpa_sm) && sta->sae &&
2628 sta->sae->state == SAE_ACCEPTED)
2629 wpa_auth_add_sae_pmkid(sta->wpa_sm, sta->sae->pmkid);
2630
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002631 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002632 sta->auth_alg == WLAN_AUTH_OPEN) {
2633 struct rsn_pmksa_cache_entry *sa;
2634 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
2635 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
2636 wpa_printf(MSG_DEBUG,
2637 "SAE: No PMKSA cache entry found for "
2638 MACSTR, MAC2STR(sta->addr));
2639 return WLAN_STATUS_INVALID_PMKID;
2640 }
2641 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
2642 " using PMKSA caching", MAC2STR(sta->addr));
2643 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
2644 sta->auth_alg != WLAN_AUTH_SAE &&
2645 !(sta->auth_alg == WLAN_AUTH_FT &&
2646 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002647 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
2648 "SAE AKM after non-SAE auth_alg %u",
2649 MAC2STR(sta->addr), sta->auth_alg);
2650 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
2651 }
2652#endif /* CONFIG_SAE */
2653
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002654#ifdef CONFIG_OWE
2655 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
2656 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
2657 elems.owe_dh) {
2658 resp = owe_process_assoc_req(hapd, sta, elems.owe_dh,
2659 elems.owe_dh_len);
2660 if (resp != WLAN_STATUS_SUCCESS)
2661 return resp;
2662 }
2663#endif /* CONFIG_OWE */
2664
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002665#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002666 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002667 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
2668 hostapd_logger(hapd, sta->addr,
2669 HOSTAPD_MODULE_IEEE80211,
2670 HOSTAPD_LEVEL_INFO,
2671 "Station tried to use TKIP with HT "
2672 "association");
2673 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
2674 }
2675#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002676#ifdef CONFIG_HS20
2677 } else if (hapd->conf->osen) {
2678 if (elems.osen == NULL) {
2679 hostapd_logger(
2680 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2681 HOSTAPD_LEVEL_INFO,
2682 "No HS 2.0 OSEN element in association request");
2683 return WLAN_STATUS_INVALID_IE;
2684 }
2685
2686 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
2687 if (sta->wpa_sm == NULL)
2688 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
2689 sta->addr, NULL);
2690 if (sta->wpa_sm == NULL) {
2691 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
2692 "state machine");
2693 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2694 }
2695 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
2696 elems.osen - 2, elems.osen_len + 2) < 0)
2697 return WLAN_STATUS_INVALID_IE;
2698#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699 } else
2700 wpa_auth_sta_no_wpa(sta->wpa_sm);
2701
2702#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002703 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
2704#endif /* CONFIG_P2P */
2705
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002706#ifdef CONFIG_HS20
2707 wpabuf_free(sta->hs20_ie);
2708 if (elems.hs20 && elems.hs20_len > 4) {
2709 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
2710 elems.hs20_len - 4);
2711 } else
2712 sta->hs20_ie = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002713
2714 wpabuf_free(sta->roaming_consortium);
2715 if (elems.roaming_cons_sel)
2716 sta->roaming_consortium = wpabuf_alloc_copy(
2717 elems.roaming_cons_sel + 4,
2718 elems.roaming_cons_sel_len - 4);
2719 else
2720 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002721#endif /* CONFIG_HS20 */
2722
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002723#ifdef CONFIG_FST
2724 wpabuf_free(sta->mb_ies);
2725 if (hapd->iface->fst)
2726 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
2727 else
2728 sta->mb_ies = NULL;
2729#endif /* CONFIG_FST */
2730
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002731#ifdef CONFIG_MBO
2732 mbo_ap_check_sta_assoc(hapd, sta, &elems);
2733
2734 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
2735 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
2736 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
2737 wpa_printf(MSG_INFO,
2738 "MBO: Reject WPA2 association without PMF");
2739 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2740 }
2741#endif /* CONFIG_MBO */
2742
Dmitry Shmidt9c175262016-03-03 10:20:07 -08002743 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
2744 elems.supp_op_classes_len);
2745
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002746 if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) &&
2747 elems.rrm_enabled &&
2748 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
2749 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
2750 sizeof(sta->rrm_enabled_capa));
2751
Roshan Pius3a1667e2018-07-03 15:17:14 -07002752 if (elems.power_capab) {
2753 sta->min_tx_power = elems.power_capab[0];
2754 sta->max_tx_power = elems.power_capab[1];
2755 sta->power_capab = 1;
2756 } else {
2757 sta->power_capab = 0;
2758 }
2759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002760 return WLAN_STATUS_SUCCESS;
2761}
2762
2763
2764static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
2765 u16 reason_code)
2766{
2767 int send_len;
2768 struct ieee80211_mgmt reply;
2769
2770 os_memset(&reply, 0, sizeof(reply));
2771 reply.frame_control =
2772 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
2773 os_memcpy(reply.da, addr, ETH_ALEN);
2774 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
2775 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
2776
2777 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
2778 reply.u.deauth.reason_code = host_to_le16(reason_code);
2779
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002780 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002781 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
2782 strerror(errno));
2783}
2784
2785
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002786static int add_associated_sta(struct hostapd_data *hapd,
2787 struct sta_info *sta)
2788{
2789 struct ieee80211_ht_capabilities ht_cap;
2790 struct ieee80211_vht_capabilities vht_cap;
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02002791 int set = 1;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002792
2793 /*
2794 * Remove the STA entry to ensure the STA PS state gets cleared and
2795 * configuration gets updated. This is relevant for cases, such as
2796 * FT-over-the-DS, where a station re-associates back to the same AP but
2797 * skips the authentication flow, or if working with a driver that
2798 * does not support full AP client state.
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02002799 *
2800 * Skip this if the STA has already completed FT reassociation and the
2801 * TK has been configured since the TX/RX PN must not be reset to 0 for
2802 * the same key.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002803 */
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02002804 if (!sta->added_unassoc &&
2805 (!(sta->flags & WLAN_STA_AUTHORIZED) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002806 (!wpa_auth_sta_ft_tk_already_set(sta->wpa_sm) &&
2807 !wpa_auth_sta_fils_tk_already_set(sta->wpa_sm)))) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002808 hostapd_drv_sta_remove(hapd, sta->addr);
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02002809 wpa_auth_sm_event(sta->wpa_sm, WPA_DRV_STA_REMOVED);
2810 set = 0;
2811 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002812
2813#ifdef CONFIG_IEEE80211N
2814 if (sta->flags & WLAN_STA_HT)
2815 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
2816#endif /* CONFIG_IEEE80211N */
2817#ifdef CONFIG_IEEE80211AC
2818 if (sta->flags & WLAN_STA_VHT)
2819 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
2820#endif /* CONFIG_IEEE80211AC */
2821
2822 /*
2823 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
2824 * will be set when the ACK frame for the (Re)Association Response frame
2825 * is processed (TX status driver event).
2826 */
2827 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
2828 sta->supported_rates, sta->supported_rates_len,
2829 sta->listen_interval,
2830 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
2831 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
2832 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002833 sta->vht_opmode, sta->p2p_ie ? 1 : 0,
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02002834 set)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002835 hostapd_logger(hapd, sta->addr,
2836 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
2837 "Could not %s STA to kernel driver",
Mathy Vanhoeff6e1f662017-07-14 15:15:35 +02002838 set ? "set" : "add");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002839
2840 if (sta->added_unassoc) {
2841 hostapd_drv_sta_remove(hapd, sta->addr);
2842 sta->added_unassoc = 0;
2843 }
2844
2845 return -1;
2846 }
2847
2848 sta->added_unassoc = 0;
2849
2850 return 0;
2851}
2852
2853
2854static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
Dmitry Shmidt29333592017-01-09 12:27:11 -08002855 const u8 *addr, u16 status_code, int reassoc,
2856 const u8 *ies, size_t ies_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002857{
2858 int send_len;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002859 u8 *buf;
2860 size_t buflen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002861 struct ieee80211_mgmt *reply;
2862 u8 *p;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002863 u16 res = WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002864
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002865 buflen = sizeof(struct ieee80211_mgmt) + 1024;
2866#ifdef CONFIG_FILS
2867 if (sta && sta->fils_hlp_resp)
2868 buflen += wpabuf_len(sta->fils_hlp_resp);
2869#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002870#ifdef CONFIG_OWE
2871 if (sta && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE))
2872 buflen += 150;
2873#endif /* CONFIG_OWE */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002874 buf = os_zalloc(buflen);
2875 if (!buf) {
2876 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
2877 goto done;
2878 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002879 reply = (struct ieee80211_mgmt *) buf;
2880 reply->frame_control =
2881 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2882 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
2883 WLAN_FC_STYPE_ASSOC_RESP));
Dmitry Shmidt29333592017-01-09 12:27:11 -08002884 os_memcpy(reply->da, addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002885 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
2886 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
2887
2888 send_len = IEEE80211_HDRLEN;
2889 send_len += sizeof(reply->u.assoc_resp);
2890 reply->u.assoc_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002891 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002892 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt29333592017-01-09 12:27:11 -08002893
2894 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0) |
2895 BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002896 /* Supported rates */
2897 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
2898 /* Extended supported rates */
2899 p = hostapd_eid_ext_supp_rates(hapd, p);
2900
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002901#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt29333592017-01-09 12:27:11 -08002902 if (sta && status_code == WLAN_STATUS_SUCCESS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002903 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
2904 * Transition Information, RSN, [RIC Response] */
2905 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002906 buf + buflen - p,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002907 sta->auth_alg, ies, ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002908 if (!p) {
2909 wpa_printf(MSG_DEBUG,
2910 "FT: Failed to write AssocResp IEs");
2911 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
2912 goto done;
2913 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002914 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002915#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002916
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002917#ifdef CONFIG_OWE
2918 if (sta && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE))
2919 p = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, p,
2920 buf + buflen - p,
2921 ies, ies_len);
2922#endif /* CONFIG_OWE */
2923
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002924#ifdef CONFIG_IEEE80211W
Dmitry Shmidt29333592017-01-09 12:27:11 -08002925 if (sta && status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002926 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
2927#endif /* CONFIG_IEEE80211W */
2928
2929#ifdef CONFIG_IEEE80211N
2930 p = hostapd_eid_ht_capabilities(hapd, p);
2931 p = hostapd_eid_ht_operation(hapd, p);
2932#endif /* CONFIG_IEEE80211N */
2933
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002934#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002935 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07002936 u32 nsts = 0, sta_nsts;
2937
Dmitry Shmidt29333592017-01-09 12:27:11 -08002938 if (sta && hapd->conf->use_sta_nsts && sta->vht_capabilities) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07002939 struct ieee80211_vht_capabilities *capa;
2940
2941 nsts = (hapd->iface->conf->vht_capab >>
2942 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
2943 capa = sta->vht_capabilities;
2944 sta_nsts = (le_to_host32(capa->vht_capabilities_info) >>
2945 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
2946
2947 if (nsts < sta_nsts)
2948 nsts = 0;
2949 else
2950 nsts = sta_nsts;
2951 }
2952 p = hostapd_eid_vht_capabilities(hapd, p, nsts);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002953 p = hostapd_eid_vht_operation(hapd, p);
2954 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002955#endif /* CONFIG_IEEE80211AC */
2956
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002957 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002958 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt29333592017-01-09 12:27:11 -08002959 if (sta && sta->qos_map_enabled)
Dmitry Shmidt051af732013-10-22 13:52:46 -07002960 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002961
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002962#ifdef CONFIG_FST
2963 if (hapd->iface->fst_ies) {
2964 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
2965 wpabuf_len(hapd->iface->fst_ies));
2966 p += wpabuf_len(hapd->iface->fst_ies);
2967 }
2968#endif /* CONFIG_FST */
2969
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002970#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt29333592017-01-09 12:27:11 -08002971 if (sta && hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002972 p = hostapd_eid_vendor_vht(hapd, p);
2973#endif /* CONFIG_IEEE80211AC */
2974
Dmitry Shmidt29333592017-01-09 12:27:11 -08002975 if (sta && (sta->flags & WLAN_STA_WMM))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002976 p = hostapd_eid_wmm(hapd, p);
2977
2978#ifdef CONFIG_WPS
Dmitry Shmidt29333592017-01-09 12:27:11 -08002979 if (sta &&
2980 ((sta->flags & WLAN_STA_WPS) ||
2981 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002982 struct wpabuf *wps = wps_build_assoc_resp_ie();
2983 if (wps) {
2984 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
2985 p += wpabuf_len(wps);
2986 wpabuf_free(wps);
2987 }
2988 }
2989#endif /* CONFIG_WPS */
2990
2991#ifdef CONFIG_P2P
Dmitry Shmidt29333592017-01-09 12:27:11 -08002992 if (sta && sta->p2p_ie && hapd->p2p_group) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002993 struct wpabuf *p2p_resp_ie;
2994 enum p2p_status_code status;
2995 switch (status_code) {
2996 case WLAN_STATUS_SUCCESS:
2997 status = P2P_SC_SUCCESS;
2998 break;
2999 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
3000 status = P2P_SC_FAIL_LIMIT_REACHED;
3001 break;
3002 default:
3003 status = P2P_SC_FAIL_INVALID_PARAMS;
3004 break;
3005 }
3006 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
3007 if (p2p_resp_ie) {
3008 os_memcpy(p, wpabuf_head(p2p_resp_ie),
3009 wpabuf_len(p2p_resp_ie));
3010 p += wpabuf_len(p2p_resp_ie);
3011 wpabuf_free(p2p_resp_ie);
3012 }
3013 }
3014#endif /* CONFIG_P2P */
3015
3016#ifdef CONFIG_P2P_MANAGER
3017 if (hapd->conf->p2p & P2P_MANAGE)
3018 p = hostapd_eid_p2p_manage(hapd, p);
3019#endif /* CONFIG_P2P_MANAGER */
3020
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003021 p = hostapd_eid_mbo(hapd, p, buf + buflen - p);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003022
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003023 if (hapd->conf->assocresp_elements &&
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003024 (size_t) (buf + buflen - p) >=
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003025 wpabuf_len(hapd->conf->assocresp_elements)) {
3026 os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements),
3027 wpabuf_len(hapd->conf->assocresp_elements));
3028 p += wpabuf_len(hapd->conf->assocresp_elements);
3029 }
3030
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003031 send_len += p - reply->u.assoc_resp.variable;
3032
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003033#ifdef CONFIG_FILS
Dmitry Shmidt29333592017-01-09 12:27:11 -08003034 if (sta &&
3035 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003036 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3037 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
3038 status_code == WLAN_STATUS_SUCCESS) {
3039 struct ieee802_11_elems elems;
3040
3041 if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003042 ParseFailed || !elems.fils_session) {
3043 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3044 goto done;
3045 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003046
3047 /* FILS Session */
3048 *p++ = WLAN_EID_EXTENSION; /* Element ID */
3049 *p++ = 1 + FILS_SESSION_LEN; /* Length */
3050 *p++ = WLAN_EID_EXT_FILS_SESSION; /* Element ID Extension */
3051 os_memcpy(p, elems.fils_session, FILS_SESSION_LEN);
3052 send_len += 2 + 1 + FILS_SESSION_LEN;
3053
3054 send_len = fils_encrypt_assoc(sta->wpa_sm, buf, send_len,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003055 buflen, sta->fils_hlp_resp);
3056 if (send_len < 0) {
3057 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3058 goto done;
3059 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003060 }
3061#endif /* CONFIG_FILS */
3062
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003063#ifdef CONFIG_OWE
3064 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
3065 sta && sta->owe_ecdh &&
3066 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE) {
3067 struct wpabuf *pub;
3068
3069 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
3070 if (!pub) {
3071 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3072 goto done;
3073 }
3074 /* OWE Diffie-Hellman Parameter element */
3075 *p++ = WLAN_EID_EXTENSION; /* Element ID */
3076 *p++ = 1 + 2 + wpabuf_len(pub); /* Length */
3077 *p++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension */
3078 WPA_PUT_LE16(p, sta->owe_group);
3079 p += 2;
3080 os_memcpy(p, wpabuf_head(pub), wpabuf_len(pub));
3081 p += wpabuf_len(pub);
3082 send_len += 3 + 2 + wpabuf_len(pub);
3083 wpabuf_free(pub);
3084 }
3085#endif /* CONFIG_OWE */
3086
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003087 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003088 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
3089 strerror(errno));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003090 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003091 }
3092
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003093done:
3094 os_free(buf);
3095 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003096}
3097
3098
Roshan Pius3a1667e2018-07-03 15:17:14 -07003099#ifdef CONFIG_OWE
3100u8 * owe_assoc_req_process(struct hostapd_data *hapd, struct sta_info *sta,
3101 const u8 *owe_dh, u8 owe_dh_len,
3102 u8 *owe_buf, size_t owe_buf_len, u16 *reason)
3103{
3104#ifdef CONFIG_TESTING_OPTIONS
3105 if (hapd->conf->own_ie_override) {
3106 wpa_printf(MSG_DEBUG, "OWE: Using IE override");
3107 *reason = WLAN_STATUS_SUCCESS;
3108 return wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3109 owe_buf_len, NULL, 0);
3110 }
3111#endif /* CONFIG_TESTING_OPTIONS */
3112
3113 if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) {
3114 wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching");
3115 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3116 owe_buf_len, NULL, 0);
3117 *reason = WLAN_STATUS_SUCCESS;
3118 return owe_buf;
3119 }
3120
3121 *reason = owe_process_assoc_req(hapd, sta, owe_dh, owe_dh_len);
3122 if (*reason != WLAN_STATUS_SUCCESS)
3123 return NULL;
3124
3125 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3126 owe_buf_len, NULL, 0);
3127
3128 if (sta->owe_ecdh && owe_buf) {
3129 struct wpabuf *pub;
3130
3131 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
3132 if (!pub) {
3133 *reason = WLAN_STATUS_UNSPECIFIED_FAILURE;
3134 return owe_buf;
3135 }
3136
3137 /* OWE Diffie-Hellman Parameter element */
3138 *owe_buf++ = WLAN_EID_EXTENSION; /* Element ID */
3139 *owe_buf++ = 1 + 2 + wpabuf_len(pub); /* Length */
3140 *owe_buf++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension
3141 */
3142 WPA_PUT_LE16(owe_buf, sta->owe_group);
3143 owe_buf += 2;
3144 os_memcpy(owe_buf, wpabuf_head(pub), wpabuf_len(pub));
3145 owe_buf += wpabuf_len(pub);
3146 wpabuf_free(pub);
3147 }
3148
3149 return owe_buf;
3150}
3151#endif /* CONFIG_OWE */
3152
3153
Paul Stewart092955c2017-02-06 09:13:09 -08003154#ifdef CONFIG_FILS
3155
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003156void fils_hlp_finish_assoc(struct hostapd_data *hapd, struct sta_info *sta)
Paul Stewart092955c2017-02-06 09:13:09 -08003157{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003158 u16 reply_res;
Paul Stewart092955c2017-02-06 09:13:09 -08003159
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003160 wpa_printf(MSG_DEBUG, "FILS: Finish association with " MACSTR,
3161 MAC2STR(sta->addr));
3162 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
3163 if (!sta->fils_pending_assoc_req)
Paul Stewart092955c2017-02-06 09:13:09 -08003164 return;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003165 reply_res = send_assoc_resp(hapd, sta, sta->addr, WLAN_STATUS_SUCCESS,
3166 sta->fils_pending_assoc_is_reassoc,
3167 sta->fils_pending_assoc_req,
3168 sta->fils_pending_assoc_req_len);
3169 os_free(sta->fils_pending_assoc_req);
3170 sta->fils_pending_assoc_req = NULL;
3171 sta->fils_pending_assoc_req_len = 0;
3172 wpabuf_free(sta->fils_hlp_resp);
3173 sta->fils_hlp_resp = NULL;
3174 wpabuf_free(sta->hlp_dhcp_discover);
3175 sta->hlp_dhcp_discover = NULL;
Paul Stewart092955c2017-02-06 09:13:09 -08003176
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003177 /*
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003178 * Remove the station in case transmission of a success response fails.
3179 * At this point the station was already added associated to the driver.
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003180 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003181 if (reply_res != WLAN_STATUS_SUCCESS)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003182 hostapd_drv_sta_remove(hapd, sta->addr);
Paul Stewart092955c2017-02-06 09:13:09 -08003183}
3184
3185
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003186void fils_hlp_timeout(void *eloop_ctx, void *eloop_data)
Paul Stewart092955c2017-02-06 09:13:09 -08003187{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003188 struct hostapd_data *hapd = eloop_ctx;
3189 struct sta_info *sta = eloop_data;
Paul Stewart092955c2017-02-06 09:13:09 -08003190
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003191 wpa_printf(MSG_DEBUG,
3192 "FILS: HLP response timeout - continue with association response for "
3193 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003194 if (sta->fils_drv_assoc_finish)
3195 hostapd_notify_assoc_fils_finish(hapd, sta);
3196 else
3197 fils_hlp_finish_assoc(hapd, sta);
Paul Stewart092955c2017-02-06 09:13:09 -08003198}
3199
3200#endif /* CONFIG_FILS */
3201
3202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003203static void handle_assoc(struct hostapd_data *hapd,
3204 const struct ieee80211_mgmt *mgmt, size_t len,
3205 int reassoc)
3206{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003207 u16 capab_info, listen_interval, seq_ctrl, fc;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003208 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003209 const u8 *pos;
3210 int left, i;
3211 struct sta_info *sta;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003212 u8 *tmp = NULL;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003213 struct hostapd_sta_wpa_psk_short *psk = NULL;
3214 char *identity = NULL;
3215 char *radius_cui = NULL;
3216#ifdef CONFIG_FILS
3217 int delay_assoc = 0;
3218#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003219
3220 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
3221 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003222 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
3223 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003224 return;
3225 }
3226
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003227#ifdef CONFIG_TESTING_OPTIONS
3228 if (reassoc) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003229 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003230 drand48() < hapd->iconf->ignore_reassoc_probability) {
3231 wpa_printf(MSG_INFO,
3232 "TESTING: ignoring reassoc request from "
3233 MACSTR, MAC2STR(mgmt->sa));
3234 return;
3235 }
3236 } else {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003237 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003238 drand48() < hapd->iconf->ignore_assoc_probability) {
3239 wpa_printf(MSG_INFO,
3240 "TESTING: ignoring assoc request from "
3241 MACSTR, MAC2STR(mgmt->sa));
3242 return;
3243 }
3244 }
3245#endif /* CONFIG_TESTING_OPTIONS */
3246
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003247 fc = le_to_host16(mgmt->frame_control);
3248 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
3249
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003250 if (reassoc) {
3251 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
3252 listen_interval = le_to_host16(
3253 mgmt->u.reassoc_req.listen_interval);
3254 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
3255 " capab_info=0x%02x listen_interval=%d current_ap="
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003256 MACSTR " seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003257 MAC2STR(mgmt->sa), capab_info, listen_interval,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003258 MAC2STR(mgmt->u.reassoc_req.current_ap),
3259 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003260 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
3261 pos = mgmt->u.reassoc_req.variable;
3262 } else {
3263 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
3264 listen_interval = le_to_host16(
3265 mgmt->u.assoc_req.listen_interval);
3266 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003267 " capab_info=0x%02x listen_interval=%d "
3268 "seq_ctrl=0x%x%s",
3269 MAC2STR(mgmt->sa), capab_info, listen_interval,
3270 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003271 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
3272 pos = mgmt->u.assoc_req.variable;
3273 }
3274
3275 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003276#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003277 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
3278 (sta->flags & WLAN_STA_AUTH) == 0) {
3279 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
3280 "prior to authentication since it is using "
3281 "over-the-DS FT", MAC2STR(mgmt->sa));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003282
3283 /*
3284 * Mark station as authenticated, to avoid adding station
3285 * entry in the driver as associated and not authenticated
3286 */
3287 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003288 } else
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003289#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003290 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
Dmitry Shmidt29333592017-01-09 12:27:11 -08003291 if (hapd->iface->current_mode &&
3292 hapd->iface->current_mode->mode ==
3293 HOSTAPD_MODE_IEEE80211AD) {
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003294 int acl_res;
3295 u32 session_timeout, acct_interim_interval;
3296 struct vlan_description vlan_id;
3297
3298 acl_res = ieee802_11_allowed_address(
3299 hapd, mgmt->sa, (const u8 *) mgmt, len,
3300 &session_timeout, &acct_interim_interval,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003301 &vlan_id, &psk, &identity, &radius_cui, 0);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003302 if (acl_res == HOSTAPD_ACL_REJECT) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003303 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
3304 "Ignore Association Request frame from "
3305 MACSTR " due to ACL reject",
3306 MAC2STR(mgmt->sa));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003307 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
3308 goto fail;
3309 }
3310 if (acl_res == HOSTAPD_ACL_PENDING)
3311 return;
3312
Dmitry Shmidt29333592017-01-09 12:27:11 -08003313 /* DMG/IEEE 802.11ad does not use authentication.
3314 * Allocate sta entry upon association. */
3315 sta = ap_sta_add(hapd, mgmt->sa);
3316 if (!sta) {
3317 hostapd_logger(hapd, mgmt->sa,
3318 HOSTAPD_MODULE_IEEE80211,
3319 HOSTAPD_LEVEL_INFO,
3320 "Failed to add STA");
3321 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
3322 goto fail;
3323 }
3324
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003325 acl_res = ieee802_11_set_radius_info(
3326 hapd, sta, acl_res, session_timeout,
3327 acct_interim_interval, &vlan_id, &psk,
3328 &identity, &radius_cui);
3329 if (acl_res) {
3330 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
3331 goto fail;
3332 }
3333
Dmitry Shmidt29333592017-01-09 12:27:11 -08003334 hostapd_logger(hapd, sta->addr,
3335 HOSTAPD_MODULE_IEEE80211,
3336 HOSTAPD_LEVEL_DEBUG,
3337 "Skip authentication for DMG/IEEE 802.11ad");
3338 sta->flags |= WLAN_STA_AUTH;
3339 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
3340 sta->auth_alg = WLAN_AUTH_OPEN;
3341 } else {
3342 hostapd_logger(hapd, mgmt->sa,
3343 HOSTAPD_MODULE_IEEE80211,
3344 HOSTAPD_LEVEL_INFO,
3345 "Station tried to associate before authentication (aid=%d flags=0x%x)",
3346 sta ? sta->aid : -1,
3347 sta ? sta->flags : 0);
3348 send_deauth(hapd, mgmt->sa,
3349 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
3350 return;
3351 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003352 }
3353
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003354 if ((fc & WLAN_FC_RETRY) &&
3355 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
3356 sta->last_seq_ctrl == seq_ctrl &&
Paul Stewart092955c2017-02-06 09:13:09 -08003357 sta->last_subtype == (reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
3358 WLAN_FC_STYPE_ASSOC_REQ)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003359 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3360 HOSTAPD_LEVEL_DEBUG,
3361 "Drop repeated association frame seq_ctrl=0x%x",
3362 seq_ctrl);
3363 return;
3364 }
3365 sta->last_seq_ctrl = seq_ctrl;
3366 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
3367 WLAN_FC_STYPE_ASSOC_REQ;
3368
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003369 if (hapd->tkip_countermeasures) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003370 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003371 goto fail;
3372 }
3373
3374 if (listen_interval > hapd->conf->max_listen_interval) {
3375 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3376 HOSTAPD_LEVEL_DEBUG,
3377 "Too large Listen Interval (%d)",
3378 listen_interval);
3379 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
3380 goto fail;
3381 }
3382
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003383#ifdef CONFIG_MBO
3384 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
3385 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
3386 goto fail;
3387 }
3388#endif /* CONFIG_MBO */
3389
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003390 /*
3391 * sta->capability is used in check_assoc_ies() for RRM enabled
3392 * capability element.
3393 */
3394 sta->capability = capab_info;
3395
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003396#ifdef CONFIG_FILS
3397 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3398 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3399 sta->auth_alg == WLAN_AUTH_FILS_PK) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003400 int res;
3401
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003402 /* The end of the payload is encrypted. Need to decrypt it
3403 * before parsing. */
3404
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003405 tmp = os_memdup(pos, left);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003406 if (!tmp) {
3407 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
3408 goto fail;
3409 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003410
Roshan Pius3a1667e2018-07-03 15:17:14 -07003411 res = fils_decrypt_assoc(sta->wpa_sm, sta->fils_session, mgmt,
3412 len, tmp, left);
3413 if (res < 0) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003414 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
3415 goto fail;
3416 }
3417 pos = tmp;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003418 left = res;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003419 }
3420#endif /* CONFIG_FILS */
3421
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003422 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
3423 * is used */
3424 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
3425 if (resp != WLAN_STATUS_SUCCESS)
3426 goto fail;
3427
3428 if (hostapd_get_aid(hapd, sta) < 0) {
3429 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3430 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
3431 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
3432 goto fail;
3433 }
3434
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003435 sta->listen_interval = listen_interval;
3436
Roshan Pius3a1667e2018-07-03 15:17:14 -07003437 if (hapd->iface->current_mode &&
3438 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003439 sta->flags |= WLAN_STA_NONERP;
3440 for (i = 0; i < sta->supported_rates_len; i++) {
3441 if ((sta->supported_rates[i] & 0x7f) > 22) {
3442 sta->flags &= ~WLAN_STA_NONERP;
3443 break;
3444 }
3445 }
3446 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
3447 sta->nonerp_set = 1;
3448 hapd->iface->num_sta_non_erp++;
3449 if (hapd->iface->num_sta_non_erp == 1)
3450 ieee802_11_set_beacons(hapd->iface);
3451 }
3452
3453 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
3454 !sta->no_short_slot_time_set) {
3455 sta->no_short_slot_time_set = 1;
3456 hapd->iface->num_sta_no_short_slot_time++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003457 if (hapd->iface->current_mode &&
3458 hapd->iface->current_mode->mode ==
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003459 HOSTAPD_MODE_IEEE80211G &&
3460 hapd->iface->num_sta_no_short_slot_time == 1)
3461 ieee802_11_set_beacons(hapd->iface);
3462 }
3463
3464 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
3465 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
3466 else
3467 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
3468
3469 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
3470 !sta->no_short_preamble_set) {
3471 sta->no_short_preamble_set = 1;
3472 hapd->iface->num_sta_no_short_preamble++;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003473 if (hapd->iface->current_mode &&
3474 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003475 && hapd->iface->num_sta_no_short_preamble == 1)
3476 ieee802_11_set_beacons(hapd->iface);
3477 }
3478
3479#ifdef CONFIG_IEEE80211N
3480 update_ht_state(hapd, sta);
3481#endif /* CONFIG_IEEE80211N */
3482
3483 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3484 HOSTAPD_LEVEL_DEBUG,
3485 "association OK (aid %d)", sta->aid);
3486 /* Station will be marked associated, after it acknowledges AssocResp
3487 */
3488 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
3489
3490#ifdef CONFIG_IEEE80211W
3491 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
3492 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
3493 "SA Query procedure", reassoc ? "re" : "");
3494 /* TODO: Send a protected Disassociate frame to the STA using
3495 * the old key and Reason Code "Previous Authentication no
3496 * longer valid". Make sure this is only sent protected since
3497 * unprotected frame would be received by the STA that is now
3498 * trying to associate.
3499 */
3500 }
3501#endif /* CONFIG_IEEE80211W */
3502
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003503 /* Make sure that the previously registered inactivity timer will not
3504 * remove the STA immediately. */
3505 sta->timeout_next = STA_NULLFUNC;
3506
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003507#ifdef CONFIG_TAXONOMY
3508 taxonomy_sta_info_assoc_req(hapd, sta, pos, left);
3509#endif /* CONFIG_TAXONOMY */
3510
Dmitry Shmidt29333592017-01-09 12:27:11 -08003511 sta->pending_wds_enable = 0;
3512
Paul Stewart092955c2017-02-06 09:13:09 -08003513#ifdef CONFIG_FILS
3514 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3515 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003516 sta->auth_alg == WLAN_AUTH_FILS_PK) {
3517 if (fils_process_hlp(hapd, sta, pos, left) > 0)
3518 delay_assoc = 1;
3519 }
Paul Stewart092955c2017-02-06 09:13:09 -08003520#endif /* CONFIG_FILS */
3521
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003522 fail:
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003523 os_free(identity);
3524 os_free(radius_cui);
3525 hostapd_free_psk_list(psk);
3526
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003527 /*
3528 * In case of a successful response, add the station to the driver.
3529 * Otherwise, the kernel may ignore Data frames before we process the
3530 * ACK frame (TX status). In case of a failure, this station will be
3531 * removed.
3532 *
3533 * Note that this is not compliant with the IEEE 802.11 standard that
3534 * states that a non-AP station should transition into the
3535 * authenticated/associated state only after the station acknowledges
3536 * the (Re)Association Response frame. However, still do this as:
3537 *
3538 * 1. In case the station does not acknowledge the (Re)Association
3539 * Response frame, it will be removed.
3540 * 2. Data frames will be dropped in the kernel until the station is
3541 * set into authorized state, and there are no significant known
3542 * issues with processing other non-Data Class 3 frames during this
3543 * window.
3544 */
Dmitry Shmidt29333592017-01-09 12:27:11 -08003545 if (resp == WLAN_STATUS_SUCCESS && sta && add_associated_sta(hapd, sta))
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003546 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
3547
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003548#ifdef CONFIG_FILS
3549 if (sta) {
3550 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
3551 os_free(sta->fils_pending_assoc_req);
3552 sta->fils_pending_assoc_req = NULL;
3553 sta->fils_pending_assoc_req_len = 0;
3554 wpabuf_free(sta->fils_hlp_resp);
3555 sta->fils_hlp_resp = NULL;
3556 }
3557 if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS) {
3558 sta->fils_pending_assoc_req = tmp;
3559 sta->fils_pending_assoc_req_len = left;
3560 sta->fils_pending_assoc_is_reassoc = reassoc;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003561 sta->fils_drv_assoc_finish = 0;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003562 wpa_printf(MSG_DEBUG,
3563 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
3564 MACSTR, MAC2STR(sta->addr));
3565 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
3566 eloop_register_timeout(0, hapd->conf->fils_hlp_wait_time * 1024,
3567 fils_hlp_timeout, hapd, sta);
3568 return;
3569 }
3570#endif /* CONFIG_FILS */
3571
Dmitry Shmidt29333592017-01-09 12:27:11 -08003572 reply_res = send_assoc_resp(hapd, sta, mgmt->sa, resp, reassoc, pos,
3573 left);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003574 os_free(tmp);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003575
3576 /*
3577 * Remove the station in case tranmission of a success response fails
3578 * (the STA was added associated to the driver) or if the station was
3579 * previously added unassociated.
3580 */
Dmitry Shmidt29333592017-01-09 12:27:11 -08003581 if (sta && ((reply_res != WLAN_STATUS_SUCCESS &&
3582 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003583 hostapd_drv_sta_remove(hapd, sta->addr);
3584 sta->added_unassoc = 0;
3585 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003586}
3587
3588
3589static void handle_disassoc(struct hostapd_data *hapd,
3590 const struct ieee80211_mgmt *mgmt, size_t len)
3591{
3592 struct sta_info *sta;
3593
3594 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003595 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
3596 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003597 return;
3598 }
3599
3600 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
3601 MAC2STR(mgmt->sa),
3602 le_to_host16(mgmt->u.disassoc.reason_code));
3603
3604 sta = ap_get_sta(hapd, mgmt->sa);
3605 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003606 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
3607 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003608 return;
3609 }
3610
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003611 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003612 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003613 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003614 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
3615 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3616 HOSTAPD_LEVEL_INFO, "disassociated");
3617 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
3618 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
3619 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
3620 * authenticated. */
3621 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -08003622 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003623 if (sta->ipaddr)
3624 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
3625 ap_sta_ip6addr_del(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003626 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003627 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003628
3629 if (sta->timeout_next == STA_NULLFUNC ||
3630 sta->timeout_next == STA_DISASSOC) {
3631 sta->timeout_next = STA_DEAUTH;
3632 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
3633 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
3634 hapd, sta);
3635 }
3636
3637 mlme_disassociate_indication(
3638 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
Dmitry Shmidt29333592017-01-09 12:27:11 -08003639
3640 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
3641 * disassociation. */
3642 if (hapd->iface->current_mode &&
3643 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
3644 sta->flags &= ~WLAN_STA_AUTH;
3645 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
3646 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3647 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
3648 ap_free_sta(hapd, sta);
3649 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003650}
3651
3652
3653static void handle_deauth(struct hostapd_data *hapd,
3654 const struct ieee80211_mgmt *mgmt, size_t len)
3655{
3656 struct sta_info *sta;
3657
3658 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003659 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
3660 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003661 return;
3662 }
3663
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003664 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003665 " reason_code=%d",
3666 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
3667
3668 sta = ap_get_sta(hapd, mgmt->sa);
3669 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003670 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
3671 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003672 MAC2STR(mgmt->sa));
3673 return;
3674 }
3675
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003676 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003677 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003678 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
3679 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003680 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
3681 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3682 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
3683 mlme_deauthenticate_indication(
3684 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
3685 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
3686 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
3687 ap_free_sta(hapd, sta);
3688}
3689
3690
3691static void handle_beacon(struct hostapd_data *hapd,
3692 const struct ieee80211_mgmt *mgmt, size_t len,
3693 struct hostapd_frame_info *fi)
3694{
3695 struct ieee802_11_elems elems;
3696
3697 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003698 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
3699 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003700 return;
3701 }
3702
3703 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
3704 len - (IEEE80211_HDRLEN +
3705 sizeof(mgmt->u.beacon)), &elems,
3706 0);
3707
3708 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
3709}
3710
3711
3712#ifdef CONFIG_IEEE80211W
3713
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003714static int hostapd_sa_query_action(struct hostapd_data *hapd,
3715 const struct ieee80211_mgmt *mgmt,
3716 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003717{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003718 const u8 *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003719
3720 end = mgmt->u.action.u.sa_query_resp.trans_id +
3721 WLAN_SA_QUERY_TR_ID_LEN;
3722 if (((u8 *) mgmt) + len < end) {
3723 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
3724 "frame (len=%lu)", (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003725 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003726 }
3727
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003728 ieee802_11_sa_query_action(hapd, mgmt->sa,
3729 mgmt->u.action.u.sa_query_resp.action,
3730 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003731 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003732}
3733
3734
3735static int robust_action_frame(u8 category)
3736{
3737 return category != WLAN_ACTION_PUBLIC &&
3738 category != WLAN_ACTION_HT;
3739}
3740#endif /* CONFIG_IEEE80211W */
3741
3742
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003743static int handle_action(struct hostapd_data *hapd,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003744 const struct ieee80211_mgmt *mgmt, size_t len,
3745 unsigned int freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003746{
3747 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003748 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003749
3750 if (len < IEEE80211_HDRLEN + 1) {
3751 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3752 HOSTAPD_LEVEL_DEBUG,
3753 "handle_action - too short payload (len=%lu)",
3754 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003755 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003756 }
3757
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003758 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
3759 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
3760 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
3761 "frame (category=%u) from unassociated STA " MACSTR,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08003762 mgmt->u.action.category, MAC2STR(mgmt->sa));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003763 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003764 }
3765
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003766#ifdef CONFIG_IEEE80211W
3767 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08003768 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
3769 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003770 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3771 HOSTAPD_LEVEL_DEBUG,
3772 "Dropped unprotected Robust Action frame from "
3773 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003774 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003775 }
3776#endif /* CONFIG_IEEE80211W */
3777
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003778 if (sta) {
3779 u16 fc = le_to_host16(mgmt->frame_control);
3780 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
3781
3782 if ((fc & WLAN_FC_RETRY) &&
3783 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
3784 sta->last_seq_ctrl == seq_ctrl &&
3785 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
3786 hostapd_logger(hapd, sta->addr,
3787 HOSTAPD_MODULE_IEEE80211,
3788 HOSTAPD_LEVEL_DEBUG,
3789 "Drop repeated action frame seq_ctrl=0x%x",
3790 seq_ctrl);
3791 return 1;
3792 }
3793
3794 sta->last_seq_ctrl = seq_ctrl;
3795 sta->last_subtype = WLAN_FC_STYPE_ACTION;
3796 }
3797
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003798 switch (mgmt->u.action.category) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003799#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003800 case WLAN_ACTION_FT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003801 if (!sta ||
3802 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003803 len - IEEE80211_HDRLEN))
3804 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003805 return 1;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003806#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003807 case WLAN_ACTION_WMM:
3808 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003809 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003810#ifdef CONFIG_IEEE80211W
3811 case WLAN_ACTION_SA_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003812 return hostapd_sa_query_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003813#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003814#ifdef CONFIG_WNM_AP
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003815 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003816 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
3817 return 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003818#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003819#ifdef CONFIG_FST
3820 case WLAN_ACTION_FST:
3821 if (hapd->iface->fst)
3822 fst_rx_action(hapd->iface->fst, mgmt, len);
3823 else
3824 wpa_printf(MSG_DEBUG,
3825 "FST: Ignore FST Action frame - no FST attached");
3826 return 1;
3827#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003828 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08003829 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003830#ifdef CONFIG_IEEE80211N
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07003831 if (len >= IEEE80211_HDRLEN + 2 &&
3832 mgmt->u.action.u.public_action.action ==
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003833 WLAN_PA_20_40_BSS_COEX) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003834 hostapd_2040_coex_action(hapd, mgmt, len);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003835 return 1;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003836 }
3837#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003838#ifdef CONFIG_DPP
3839 if (len >= IEEE80211_HDRLEN + 6 &&
3840 mgmt->u.action.u.vs_public_action.action ==
3841 WLAN_PA_VENDOR_SPECIFIC &&
3842 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
3843 OUI_WFA &&
3844 mgmt->u.action.u.vs_public_action.variable[0] ==
3845 DPP_OUI_TYPE) {
3846 const u8 *pos, *end;
3847
3848 pos = mgmt->u.action.u.vs_public_action.oui;
3849 end = ((const u8 *) mgmt) + len;
3850 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
Roshan Pius3a1667e2018-07-03 15:17:14 -07003851 freq);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003852 return 1;
3853 }
3854 if (len >= IEEE80211_HDRLEN + 2 &&
3855 (mgmt->u.action.u.public_action.action ==
3856 WLAN_PA_GAS_INITIAL_RESP ||
3857 mgmt->u.action.u.public_action.action ==
3858 WLAN_PA_GAS_COMEBACK_RESP)) {
3859 const u8 *pos, *end;
3860
3861 pos = &mgmt->u.action.u.public_action.action;
3862 end = ((const u8 *) mgmt) + len;
3863 gas_query_ap_rx(hapd->gas, mgmt->sa,
3864 mgmt->u.action.category,
3865 pos, end - pos, hapd->iface->freq);
3866 return 1;
3867 }
3868#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003869 if (hapd->public_action_cb) {
3870 hapd->public_action_cb(hapd->public_action_cb_ctx,
3871 (u8 *) mgmt, len,
3872 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003873 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003874 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003875 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003876 (u8 *) mgmt, len,
3877 hapd->iface->freq);
3878 }
3879 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003880 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003881 break;
3882 case WLAN_ACTION_VENDOR_SPECIFIC:
3883 if (hapd->vendor_action_cb) {
3884 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
3885 (u8 *) mgmt, len,
3886 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003887 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003888 }
3889 break;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003890 case WLAN_ACTION_RADIO_MEASUREMENT:
3891 hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len);
3892 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003893 }
3894
3895 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3896 HOSTAPD_LEVEL_DEBUG,
3897 "handle_action - unknown action category %d or invalid "
3898 "frame",
3899 mgmt->u.action.category);
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003900 if (!is_multicast_ether_addr(mgmt->da) &&
3901 !(mgmt->u.action.category & 0x80) &&
3902 !is_multicast_ether_addr(mgmt->sa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003903 struct ieee80211_mgmt *resp;
3904
3905 /*
3906 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
3907 * Return the Action frame to the source without change
3908 * except that MSB of the Category set to 1.
3909 */
3910 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
3911 "frame back to sender");
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003912 resp = os_memdup(mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003913 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003914 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003915 os_memcpy(resp->da, resp->sa, ETH_ALEN);
3916 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
3917 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
3918 resp->u.action.category |= 0x80;
3919
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003920 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
3921 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
3922 "Action frame");
3923 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003924 os_free(resp);
3925 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003926
3927 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003928}
3929
3930
3931/**
3932 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
3933 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
3934 * sent to)
3935 * @buf: management frame data (starting from IEEE 802.11 header)
3936 * @len: length of frame data in octets
3937 * @fi: meta data about received frame (signal level, etc.)
3938 *
3939 * Process all incoming IEEE 802.11 management frames. This will be called for
3940 * each frame received from the kernel driver through wlan#ap interface. In
3941 * addition, it can be called to re-inserted pending frames (e.g., when using
3942 * external RADIUS server as an MAC ACL).
3943 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003944int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
3945 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003946{
3947 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003948 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003949 int ret = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003950 unsigned int freq;
3951 int ssi_signal = fi ? fi->ssi_signal : 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003952
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003953 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003954 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003955
Roshan Pius3a1667e2018-07-03 15:17:14 -07003956 if (fi && fi->freq)
3957 freq = fi->freq;
3958 else
3959 freq = hapd->iface->freq;
3960
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003961 mgmt = (struct ieee80211_mgmt *) buf;
3962 fc = le_to_host16(mgmt->frame_control);
3963 stype = WLAN_FC_GET_STYPE(fc);
3964
3965 if (stype == WLAN_FC_STYPE_BEACON) {
3966 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003967 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003968 }
3969
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003970 if (!is_broadcast_ether_addr(mgmt->bssid) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003971#ifdef CONFIG_P2P
3972 /* Invitation responses can be sent with the peer MAC as BSSID */
3973 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
3974 stype == WLAN_FC_STYPE_ACTION) &&
3975#endif /* CONFIG_P2P */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003976#ifdef CONFIG_MESH
3977 !(hapd->conf->mesh & MESH_ENABLED) &&
3978#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003979 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003980 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
3981 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003982 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003983 }
3984
3985
3986 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003987 handle_probe_req(hapd, mgmt, len, ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003988 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003989 }
3990
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003991 if ((!is_broadcast_ether_addr(mgmt->da) ||
3992 stype != WLAN_FC_STYPE_ACTION) &&
3993 os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003994 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3995 HOSTAPD_LEVEL_DEBUG,
3996 "MGMT: DA=" MACSTR " not our address",
3997 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003998 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003999 }
4000
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004001 if (hapd->iconf->track_sta_max_num)
Roshan Pius3a1667e2018-07-03 15:17:14 -07004002 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004003
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004004 switch (stype) {
4005 case WLAN_FC_STYPE_AUTH:
4006 wpa_printf(MSG_DEBUG, "mgmt::auth");
4007 handle_auth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004008 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004009 break;
4010 case WLAN_FC_STYPE_ASSOC_REQ:
4011 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
4012 handle_assoc(hapd, mgmt, len, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004013 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004014 break;
4015 case WLAN_FC_STYPE_REASSOC_REQ:
4016 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
4017 handle_assoc(hapd, mgmt, len, 1);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004018 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004019 break;
4020 case WLAN_FC_STYPE_DISASSOC:
4021 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
4022 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004023 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004024 break;
4025 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004026 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004027 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004028 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004029 break;
4030 case WLAN_FC_STYPE_ACTION:
4031 wpa_printf(MSG_DEBUG, "mgmt::action");
Roshan Pius3a1667e2018-07-03 15:17:14 -07004032 ret = handle_action(hapd, mgmt, len, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004033 break;
4034 default:
4035 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4036 HOSTAPD_LEVEL_DEBUG,
4037 "unknown mgmt frame subtype %d", stype);
4038 break;
4039 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004040
4041 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004042}
4043
4044
4045static void handle_auth_cb(struct hostapd_data *hapd,
4046 const struct ieee80211_mgmt *mgmt,
4047 size_t len, int ok)
4048{
4049 u16 auth_alg, auth_transaction, status_code;
4050 struct sta_info *sta;
4051
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004052 sta = ap_get_sta(hapd, mgmt->da);
4053 if (!sta) {
4054 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
4055 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004056 return;
4057 }
4058
4059 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
4060 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
4061 status_code = le_to_host16(mgmt->u.auth.status_code);
4062
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004063 if (!ok) {
4064 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
4065 HOSTAPD_LEVEL_NOTICE,
4066 "did not acknowledge authentication response");
4067 goto fail;
4068 }
4069
4070 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
4071 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
4072 (unsigned long) len);
4073 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004074 }
4075
4076 if (status_code == WLAN_STATUS_SUCCESS &&
4077 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
4078 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
4079 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4080 HOSTAPD_LEVEL_INFO, "authenticated");
4081 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004082 if (sta->added_unassoc)
4083 hostapd_set_sta_flags(hapd, sta);
4084 return;
4085 }
4086
4087fail:
4088 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
4089 hostapd_drv_sta_remove(hapd, sta->addr);
4090 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004091 }
4092}
4093
4094
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004095static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
4096 struct sta_info *sta,
4097 char *ifname_wds)
4098{
4099 int i;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07004100 struct hostapd_ssid *ssid = &hapd->conf->ssid;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004101
4102 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
4103 return;
4104
4105 for (i = 0; i < 4; i++) {
4106 if (ssid->wep.key[i] &&
4107 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
4108 i == ssid->wep.idx, NULL, 0,
4109 ssid->wep.key[i], ssid->wep.len[i])) {
4110 wpa_printf(MSG_WARNING,
4111 "Could not set WEP keys for WDS interface; %s",
4112 ifname_wds);
4113 break;
4114 }
4115 }
4116}
4117
4118
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004119static void handle_assoc_cb(struct hostapd_data *hapd,
4120 const struct ieee80211_mgmt *mgmt,
4121 size_t len, int reassoc, int ok)
4122{
4123 u16 status;
4124 struct sta_info *sta;
4125 int new_assoc = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004126
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004127 sta = ap_get_sta(hapd, mgmt->da);
4128 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004129 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
4130 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004131 return;
4132 }
4133
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004134 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
4135 sizeof(mgmt->u.assoc_resp))) {
4136 wpa_printf(MSG_INFO,
4137 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
4138 reassoc, (unsigned long) len);
4139 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004140 return;
4141 }
4142
4143 if (reassoc)
4144 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
4145 else
4146 status = le_to_host16(mgmt->u.assoc_resp.status_code);
4147
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004148 if (!ok) {
4149 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
4150 HOSTAPD_LEVEL_DEBUG,
4151 "did not acknowledge association response");
4152 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
4153 /* The STA is added only in case of SUCCESS */
4154 if (status == WLAN_STATUS_SUCCESS)
4155 hostapd_drv_sta_remove(hapd, sta->addr);
4156
4157 return;
4158 }
4159
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004160 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004161 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004162
4163 /* Stop previous accounting session, if one is started, and allocate
4164 * new session id for the new session. */
4165 accounting_sta_stop(hapd, sta);
4166
4167 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4168 HOSTAPD_LEVEL_INFO,
4169 "associated (aid %d)",
4170 sta->aid);
4171
4172 if (sta->flags & WLAN_STA_ASSOC)
4173 new_assoc = 0;
4174 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004175 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004176 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
4177 !hapd->conf->osen) ||
4178 sta->auth_alg == WLAN_AUTH_FILS_SK ||
4179 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
4180 sta->auth_alg == WLAN_AUTH_FILS_PK ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004181 sta->auth_alg == WLAN_AUTH_FT) {
4182 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004183 * Open, static WEP, FT protocol, or FILS; no separate
4184 * authorization step.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004185 */
4186 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004187 }
4188
4189 if (reassoc)
4190 mlme_reassociate_indication(hapd, sta);
4191 else
4192 mlme_associate_indication(hapd, sta);
4193
4194#ifdef CONFIG_IEEE80211W
4195 sta->sa_query_timed_out = 0;
4196#endif /* CONFIG_IEEE80211W */
4197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004198 if (sta->eapol_sm == NULL) {
4199 /*
4200 * This STA does not use RADIUS server for EAP authentication,
4201 * so bind it to the selected VLAN interface now, since the
4202 * interface selection is not going to change anymore.
4203 */
Dmitry Shmidt83474442015-04-15 13:47:09 -07004204 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004205 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004206 } else if (sta->vlan_id) {
4207 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
Dmitry Shmidt83474442015-04-15 13:47:09 -07004208 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004209 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004210 }
4211
4212 hostapd_set_sta_flags(hapd, sta);
4213
Dmitry Shmidt29333592017-01-09 12:27:11 -08004214 if (!(sta->flags & WLAN_STA_WDS) && sta->pending_wds_enable) {
4215 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for STA "
4216 MACSTR " based on pending request",
4217 MAC2STR(sta->addr));
4218 sta->pending_wds_enable = 0;
4219 sta->flags |= WLAN_STA_WDS;
4220 }
4221
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08004222 if (sta->flags & WLAN_STA_WDS) {
4223 int ret;
4224 char ifname_wds[IFNAMSIZ + 1];
4225
4226 wpa_printf(MSG_DEBUG, "Reenable 4-address WDS mode for STA "
4227 MACSTR " (aid %u)",
4228 MAC2STR(sta->addr), sta->aid);
4229 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
4230 sta->aid, 1);
4231 if (!ret)
4232 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
4233 }
4234
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004235 if (sta->auth_alg == WLAN_AUTH_FT)
4236 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
4237 else
4238 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
4239 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004240 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004241
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004242#ifdef CONFIG_FILS
4243 if ((sta->auth_alg == WLAN_AUTH_FILS_SK ||
4244 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
4245 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
4246 fils_set_tk(sta->wpa_sm) < 0) {
4247 wpa_printf(MSG_DEBUG, "FILS: TK configuration failed");
4248 ap_sta_disconnect(hapd, sta, sta->addr,
4249 WLAN_REASON_UNSPECIFIED);
4250 return;
4251 }
4252#endif /* CONFIG_FILS */
4253
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004254 if (sta->pending_eapol_rx) {
4255 struct os_reltime now, age;
4256
4257 os_get_reltime(&now);
4258 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
4259 if (age.sec == 0 && age.usec < 200000) {
4260 wpa_printf(MSG_DEBUG,
4261 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
4262 MAC2STR(sta->addr));
4263 ieee802_1x_receive(
4264 hapd, mgmt->da,
4265 wpabuf_head(sta->pending_eapol_rx->buf),
4266 wpabuf_len(sta->pending_eapol_rx->buf));
4267 }
4268 wpabuf_free(sta->pending_eapol_rx->buf);
4269 os_free(sta->pending_eapol_rx);
4270 sta->pending_eapol_rx = NULL;
4271 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004272}
4273
4274
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004275static void handle_deauth_cb(struct hostapd_data *hapd,
4276 const struct ieee80211_mgmt *mgmt,
4277 size_t len, int ok)
4278{
4279 struct sta_info *sta;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004280 if (is_multicast_ether_addr(mgmt->da))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004281 return;
4282 sta = ap_get_sta(hapd, mgmt->da);
4283 if (!sta) {
4284 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
4285 " not found", MAC2STR(mgmt->da));
4286 return;
4287 }
4288 if (ok)
4289 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
4290 MAC2STR(sta->addr));
4291 else
4292 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
4293 "deauth", MAC2STR(sta->addr));
4294
4295 ap_sta_deauth_cb(hapd, sta);
4296}
4297
4298
4299static void handle_disassoc_cb(struct hostapd_data *hapd,
4300 const struct ieee80211_mgmt *mgmt,
4301 size_t len, int ok)
4302{
4303 struct sta_info *sta;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004304 if (is_multicast_ether_addr(mgmt->da))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004305 return;
4306 sta = ap_get_sta(hapd, mgmt->da);
4307 if (!sta) {
4308 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
4309 " not found", MAC2STR(mgmt->da));
4310 return;
4311 }
4312 if (ok)
4313 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
4314 MAC2STR(sta->addr));
4315 else
4316 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
4317 "disassoc", MAC2STR(sta->addr));
4318
4319 ap_sta_disassoc_cb(hapd, sta);
4320}
4321
4322
Dmitry Shmidt29333592017-01-09 12:27:11 -08004323static void handle_action_cb(struct hostapd_data *hapd,
4324 const struct ieee80211_mgmt *mgmt,
4325 size_t len, int ok)
4326{
4327 struct sta_info *sta;
Paul Stewart092955c2017-02-06 09:13:09 -08004328 const struct rrm_measurement_report_element *report;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004329
4330 if (is_multicast_ether_addr(mgmt->da))
4331 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004332#ifdef CONFIG_DPP
4333 if (len >= IEEE80211_HDRLEN + 6 &&
4334 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
4335 mgmt->u.action.u.vs_public_action.action ==
4336 WLAN_PA_VENDOR_SPECIFIC &&
4337 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
4338 OUI_WFA &&
4339 mgmt->u.action.u.vs_public_action.variable[0] ==
4340 DPP_OUI_TYPE) {
4341 const u8 *pos, *end;
4342
4343 pos = &mgmt->u.action.u.vs_public_action.variable[1];
4344 end = ((const u8 *) mgmt) + len;
4345 hostapd_dpp_tx_status(hapd, mgmt->da, pos, end - pos, ok);
4346 return;
4347 }
4348 if (len >= IEEE80211_HDRLEN + 2 &&
4349 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
4350 (mgmt->u.action.u.public_action.action ==
4351 WLAN_PA_GAS_INITIAL_REQ ||
4352 mgmt->u.action.u.public_action.action ==
4353 WLAN_PA_GAS_COMEBACK_REQ)) {
4354 const u8 *pos, *end;
4355
4356 pos = mgmt->u.action.u.public_action.variable;
4357 end = ((const u8 *) mgmt) + len;
4358 gas_query_ap_tx_status(hapd->gas, mgmt->da, pos, end - pos, ok);
4359 return;
4360 }
4361#endif /* CONFIG_DPP */
Dmitry Shmidt29333592017-01-09 12:27:11 -08004362 sta = ap_get_sta(hapd, mgmt->da);
4363 if (!sta) {
4364 wpa_printf(MSG_DEBUG, "handle_action_cb: STA " MACSTR
4365 " not found", MAC2STR(mgmt->da));
4366 return;
4367 }
4368
Paul Stewart092955c2017-02-06 09:13:09 -08004369 if (len < 24 + 5 + sizeof(*report))
Dmitry Shmidt29333592017-01-09 12:27:11 -08004370 return;
Paul Stewart092955c2017-02-06 09:13:09 -08004371 report = (const struct rrm_measurement_report_element *)
4372 &mgmt->u.action.u.rrm.variable[2];
Dmitry Shmidt29333592017-01-09 12:27:11 -08004373 if (mgmt->u.action.category == WLAN_ACTION_RADIO_MEASUREMENT &&
Paul Stewart092955c2017-02-06 09:13:09 -08004374 mgmt->u.action.u.rrm.action == WLAN_RRM_RADIO_MEASUREMENT_REQUEST &&
4375 report->eid == WLAN_EID_MEASURE_REQUEST &&
4376 report->len >= 3 &&
4377 report->type == MEASURE_TYPE_BEACON)
Dmitry Shmidt29333592017-01-09 12:27:11 -08004378 hostapd_rrm_beacon_req_tx_status(hapd, mgmt, len, ok);
4379}
4380
4381
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004382/**
4383 * ieee802_11_mgmt_cb - Process management frame TX status callback
4384 * @hapd: hostapd BSS data structure (the BSS from which the management frame
4385 * was sent from)
4386 * @buf: management frame data (starting from IEEE 802.11 header)
4387 * @len: length of frame data in octets
4388 * @stype: management frame subtype from frame control field
4389 * @ok: Whether the frame was ACK'ed
4390 */
4391void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
4392 u16 stype, int ok)
4393{
4394 const struct ieee80211_mgmt *mgmt;
4395 mgmt = (const struct ieee80211_mgmt *) buf;
4396
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004397#ifdef CONFIG_TESTING_OPTIONS
4398 if (hapd->ext_mgmt_frame_handling) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004399 size_t hex_len = 2 * len + 1;
4400 char *hex = os_malloc(hex_len);
4401
4402 if (hex) {
4403 wpa_snprintf_hex(hex, hex_len, buf, len);
4404 wpa_msg(hapd->msg_ctx, MSG_INFO,
4405 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
4406 stype, ok, hex);
4407 os_free(hex);
4408 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004409 return;
4410 }
4411#endif /* CONFIG_TESTING_OPTIONS */
4412
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004413 switch (stype) {
4414 case WLAN_FC_STYPE_AUTH:
4415 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
4416 handle_auth_cb(hapd, mgmt, len, ok);
4417 break;
4418 case WLAN_FC_STYPE_ASSOC_RESP:
4419 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
4420 handle_assoc_cb(hapd, mgmt, len, 0, ok);
4421 break;
4422 case WLAN_FC_STYPE_REASSOC_RESP:
4423 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
4424 handle_assoc_cb(hapd, mgmt, len, 1, ok);
4425 break;
4426 case WLAN_FC_STYPE_PROBE_RESP:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004427 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004428 break;
4429 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004430 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
4431 handle_deauth_cb(hapd, mgmt, len, ok);
4432 break;
4433 case WLAN_FC_STYPE_DISASSOC:
4434 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
4435 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004436 break;
4437 case WLAN_FC_STYPE_ACTION:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004438 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
Dmitry Shmidt29333592017-01-09 12:27:11 -08004439 handle_action_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004440 break;
4441 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004442 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004443 break;
4444 }
4445}
4446
4447
4448int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
4449{
4450 /* TODO */
4451 return 0;
4452}
4453
4454
4455int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
4456 char *buf, size_t buflen)
4457{
4458 /* TODO */
4459 return 0;
4460}
4461
4462
4463void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
4464 const u8 *buf, size_t len, int ack)
4465{
4466 struct sta_info *sta;
4467 struct hostapd_iface *iface = hapd->iface;
4468
4469 sta = ap_get_sta(hapd, addr);
4470 if (sta == NULL && iface->num_bss > 1) {
4471 size_t j;
4472 for (j = 0; j < iface->num_bss; j++) {
4473 hapd = iface->bss[j];
4474 sta = ap_get_sta(hapd, addr);
4475 if (sta)
4476 break;
4477 }
4478 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004479 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004480 return;
4481 if (sta->flags & WLAN_STA_PENDING_POLL) {
4482 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
4483 "activity poll", MAC2STR(sta->addr),
4484 ack ? "ACKed" : "did not ACK");
4485 if (ack)
4486 sta->flags &= ~WLAN_STA_PENDING_POLL;
4487 }
4488
4489 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
4490}
4491
4492
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004493void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
4494 const u8 *data, size_t len, int ack)
4495{
4496 struct sta_info *sta;
4497 struct hostapd_iface *iface = hapd->iface;
4498
4499 sta = ap_get_sta(hapd, dst);
4500 if (sta == NULL && iface->num_bss > 1) {
4501 size_t j;
4502 for (j = 0; j < iface->num_bss; j++) {
4503 hapd = iface->bss[j];
4504 sta = ap_get_sta(hapd, dst);
4505 if (sta)
4506 break;
4507 }
4508 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004509 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
4510 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
4511 MACSTR " that is not currently associated",
4512 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004513 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004514 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004515
4516 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
4517}
4518
4519
4520void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
4521{
4522 struct sta_info *sta;
4523 struct hostapd_iface *iface = hapd->iface;
4524
4525 sta = ap_get_sta(hapd, addr);
4526 if (sta == NULL && iface->num_bss > 1) {
4527 size_t j;
4528 for (j = 0; j < iface->num_bss; j++) {
4529 hapd = iface->bss[j];
4530 sta = ap_get_sta(hapd, addr);
4531 if (sta)
4532 break;
4533 }
4534 }
4535 if (sta == NULL)
4536 return;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07004537 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
4538 MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004539 if (!(sta->flags & WLAN_STA_PENDING_POLL))
4540 return;
4541
4542 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
4543 "activity poll", MAC2STR(sta->addr));
4544 sta->flags &= ~WLAN_STA_PENDING_POLL;
4545}
4546
4547
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004548void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
4549 int wds)
4550{
4551 struct sta_info *sta;
4552
4553 sta = ap_get_sta(hapd, src);
Dmitry Shmidt29333592017-01-09 12:27:11 -08004554 if (sta &&
4555 ((sta->flags & WLAN_STA_ASSOC) ||
4556 ((sta->flags & WLAN_STA_ASSOC_REQ_OK) && wds))) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004557 if (!hapd->conf->wds_sta)
4558 return;
4559
Dmitry Shmidt29333592017-01-09 12:27:11 -08004560 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK)) ==
4561 WLAN_STA_ASSOC_REQ_OK) {
4562 wpa_printf(MSG_DEBUG,
4563 "Postpone 4-address WDS mode enabling for STA "
4564 MACSTR " since TX status for AssocResp is not yet known",
4565 MAC2STR(sta->addr));
4566 sta->pending_wds_enable = 1;
4567 return;
4568 }
4569
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004570 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004571 int ret;
4572 char ifname_wds[IFNAMSIZ + 1];
4573
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004574 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
4575 "STA " MACSTR " (aid %u)",
4576 MAC2STR(sta->addr), sta->aid);
4577 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07004578 ret = hostapd_set_wds_sta(hapd, ifname_wds,
4579 sta->addr, sta->aid, 1);
4580 if (!ret)
4581 hostapd_set_wds_encryption(hapd, sta,
4582 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004583 }
4584 return;
4585 }
4586
4587 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
4588 MACSTR, MAC2STR(src));
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07004589 if (is_multicast_ether_addr(src)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004590 /* Broadcast bit set in SA?! Ignore the frame silently. */
4591 return;
4592 }
4593
4594 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
4595 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
4596 "already been sent, but no TX status yet known - "
4597 "ignore Class 3 frame issue with " MACSTR,
4598 MAC2STR(src));
4599 return;
4600 }
4601
4602 if (sta && (sta->flags & WLAN_STA_AUTH))
4603 hostapd_drv_sta_disassoc(
4604 hapd, src,
4605 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
4606 else
4607 hostapd_drv_sta_deauth(
4608 hapd, src,
4609 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
4610}
4611
4612
4613#endif /* CONFIG_NATIVE_WINDOWS */