blob: 1cecc80606fd2e321faee4884056d88f744e610f [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.11 Management
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003 * Copyright (c) 2002-2014, 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"
17#include "crypto/random.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include "common/ieee802_11_defs.h"
19#include "common/ieee802_11_common.h"
20#include "common/wpa_ctrl.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080021#include "common/sae.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include "radius/radius.h"
23#include "radius/radius_client.h"
24#include "p2p/p2p.h"
25#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "hostapd.h"
28#include "beacon.h"
29#include "ieee802_11_auth.h"
30#include "sta_info.h"
31#include "ieee802_1x.h"
32#include "wpa_auth.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080033#include "pmksa_cache_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "wmm.h"
35#include "ap_list.h"
36#include "accounting.h"
37#include "ap_config.h"
38#include "ap_mlme.h"
39#include "p2p_hostapd.h"
40#include "ap_drv_ops.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080041#include "wnm_ap.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080042#include "hw_features.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "ieee802_11.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080044#include "dfs.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080045#include "mbo_ap.h"
Dmitry Shmidt849734c2016-05-27 09:59:01 -070046#include "rrm.h"
Dmitry Shmidtaca489e2016-09-28 15:44:14 -070047#include "taxonomy.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048
49
50u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
51{
52 u8 *pos = eid;
53 int i, num, count;
54
55 if (hapd->iface->current_rates == NULL)
56 return eid;
57
58 *pos++ = WLAN_EID_SUPP_RATES;
59 num = hapd->iface->num_rates;
60 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
61 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080062 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
63 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070064 if (num > 8) {
65 /* rest of the rates are encoded in Extended supported
66 * rates element */
67 num = 8;
68 }
69
70 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070071 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
72 i++) {
73 count++;
74 *pos = hapd->iface->current_rates[i].rate / 5;
75 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
76 *pos |= 0x80;
77 pos++;
78 }
79
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080080 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
81 count++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070082 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080083 }
84
85 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
86 count++;
87 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
88 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089
90 return pos;
91}
92
93
94u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
95{
96 u8 *pos = eid;
97 int i, num, count;
98
99 if (hapd->iface->current_rates == NULL)
100 return eid;
101
102 num = hapd->iface->num_rates;
103 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
104 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800105 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
106 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700107 if (num <= 8)
108 return eid;
109 num -= 8;
110
111 *pos++ = WLAN_EID_EXT_SUPP_RATES;
112 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700113 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
114 i++) {
115 count++;
116 if (count <= 8)
117 continue; /* already in SuppRates IE */
118 *pos = hapd->iface->current_rates[i].rate / 5;
119 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
120 *pos |= 0x80;
121 pos++;
122 }
123
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800124 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
125 count++;
126 if (count > 8)
127 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
128 }
129
130 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
131 count++;
132 if (count > 8)
133 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
134 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700135
136 return pos;
137}
138
139
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700140u16 hostapd_own_capab_info(struct hostapd_data *hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700141{
142 int capab = WLAN_CAPABILITY_ESS;
143 int privacy;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800144 int dfs;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700145 int i;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800146
147 /* Check if any of configured channels require DFS */
148 dfs = hostapd_is_dfs_required(hapd->iface);
149 if (dfs < 0) {
150 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
151 dfs);
152 dfs = 0;
153 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154
155 if (hapd->iface->num_sta_no_short_preamble == 0 &&
156 hapd->iconf->preamble == SHORT_PREAMBLE)
157 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
158
159 privacy = hapd->conf->ssid.wep.keys_set;
160
161 if (hapd->conf->ieee802_1x &&
162 (hapd->conf->default_wep_key_len ||
163 hapd->conf->individual_wep_key_len))
164 privacy = 1;
165
166 if (hapd->conf->wpa)
167 privacy = 1;
168
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800169#ifdef CONFIG_HS20
170 if (hapd->conf->osen)
171 privacy = 1;
172#endif /* CONFIG_HS20 */
173
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174 if (privacy)
175 capab |= WLAN_CAPABILITY_PRIVACY;
176
177 if (hapd->iface->current_mode &&
178 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
179 hapd->iface->num_sta_no_short_slot_time == 0)
180 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
181
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800182 /*
183 * Currently, Spectrum Management capability bit is set when directly
184 * requested in configuration by spectrum_mgmt_required or when AP is
185 * running on DFS channel.
186 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
187 */
188 if (hapd->iface->current_mode &&
189 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
190 (hapd->iconf->spectrum_mgmt_required || dfs))
191 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
192
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700193 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
194 if (hapd->conf->radio_measurements[i]) {
195 capab |= IEEE80211_CAP_RRM;
196 break;
197 }
198 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800199
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700200 return capab;
201}
202
203
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800204#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
206 u16 auth_transaction, const u8 *challenge,
207 int iswep)
208{
209 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
210 HOSTAPD_LEVEL_DEBUG,
211 "authentication (shared key, transaction %d)",
212 auth_transaction);
213
214 if (auth_transaction == 1) {
215 if (!sta->challenge) {
216 /* Generate a pseudo-random challenge */
217 u8 key[8];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
220 if (sta->challenge == NULL)
221 return WLAN_STATUS_UNSPECIFIED_FAILURE;
222
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800223 if (os_get_random(key, sizeof(key)) < 0) {
224 os_free(sta->challenge);
225 sta->challenge = NULL;
226 return WLAN_STATUS_UNSPECIFIED_FAILURE;
227 }
228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700229 rc4_skip(key, sizeof(key), 0,
230 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
231 }
232 return 0;
233 }
234
235 if (auth_transaction != 3)
236 return WLAN_STATUS_UNSPECIFIED_FAILURE;
237
238 /* Transaction 3 */
239 if (!iswep || !sta->challenge || !challenge ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700240 os_memcmp_const(sta->challenge, challenge,
241 WLAN_AUTH_CHALLENGE_LEN)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
243 HOSTAPD_LEVEL_INFO,
244 "shared key authentication - invalid "
245 "challenge-response");
246 return WLAN_STATUS_CHALLENGE_FAIL;
247 }
248
249 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
250 HOSTAPD_LEVEL_DEBUG,
251 "authentication OK (shared key)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700252 sta->flags |= WLAN_STA_AUTH;
253 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254 os_free(sta->challenge);
255 sta->challenge = NULL;
256
257 return 0;
258}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800259#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260
261
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800262static int send_auth_reply(struct hostapd_data *hapd,
263 const u8 *dst, const u8 *bssid,
264 u16 auth_alg, u16 auth_transaction, u16 resp,
265 const u8 *ies, size_t ies_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700266{
267 struct ieee80211_mgmt *reply;
268 u8 *buf;
269 size_t rlen;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800270 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271
272 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
273 buf = os_zalloc(rlen);
274 if (buf == NULL)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800275 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700276
277 reply = (struct ieee80211_mgmt *) buf;
278 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
279 WLAN_FC_STYPE_AUTH);
280 os_memcpy(reply->da, dst, ETH_ALEN);
281 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
282 os_memcpy(reply->bssid, bssid, ETH_ALEN);
283
284 reply->u.auth.auth_alg = host_to_le16(auth_alg);
285 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
286 reply->u.auth.status_code = host_to_le16(resp);
287
288 if (ies && ies_len)
289 os_memcpy(reply->u.auth.variable, ies, ies_len);
290
291 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
292 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
293 MAC2STR(dst), auth_alg, auth_transaction,
294 resp, (unsigned long) ies_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800295 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800296 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
297 else
298 reply_res = WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299
300 os_free(buf);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800301
302 return reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303}
304
305
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800306#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
308 u16 auth_transaction, u16 status,
309 const u8 *ies, size_t ies_len)
310{
311 struct hostapd_data *hapd = ctx;
312 struct sta_info *sta;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800313 int reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800315 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
316 auth_transaction, status, ies, ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317
318 sta = ap_get_sta(hapd, dst);
319 if (sta == NULL)
320 return;
321
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800322 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
323 status != WLAN_STATUS_SUCCESS)) {
324 hostapd_drv_sta_remove(hapd, sta->addr);
325 sta->added_unassoc = 0;
326 return;
327 }
328
329 if (status != WLAN_STATUS_SUCCESS)
330 return;
331
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
333 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
334 sta->flags |= WLAN_STA_AUTH;
335 mlme_authenticate_indication(hapd, sta);
336}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800337#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338
339
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800340#ifdef CONFIG_SAE
341
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800342#define dot11RSNASAESync 5 /* attempts */
343
344
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800345static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
346 struct sta_info *sta, int update)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800347{
348 struct wpabuf *buf;
349
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800350 if (hapd->conf->ssid.wpa_passphrase == NULL) {
351 wpa_printf(MSG_DEBUG, "SAE: No password available");
352 return NULL;
353 }
354
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800355 if (update &&
356 sae_prepare_commit(hapd->own_addr, sta->addr,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800357 (u8 *) hapd->conf->ssid.wpa_passphrase,
358 os_strlen(hapd->conf->ssid.wpa_passphrase),
359 sta->sae) < 0) {
360 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
361 return NULL;
362 }
363
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800364 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800365 if (buf == NULL)
366 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800367 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
368 sta->sae->tmp->anti_clogging_token : NULL);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800369
370 return buf;
371}
372
373
374static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
375 struct sta_info *sta)
376{
377 struct wpabuf *buf;
378
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800379 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800380 if (buf == NULL)
381 return NULL;
382
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800383 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800384
385 return buf;
386}
387
388
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800389static int auth_sae_send_commit(struct hostapd_data *hapd,
390 struct sta_info *sta,
391 const u8 *bssid, int update)
392{
393 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800394 int reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800395
396 data = auth_build_sae_commit(hapd, sta, update);
397 if (data == NULL)
398 return WLAN_STATUS_UNSPECIFIED_FAILURE;
399
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800400 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
401 WLAN_STATUS_SUCCESS, wpabuf_head(data),
402 wpabuf_len(data));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800403
404 wpabuf_free(data);
405
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800406 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800407}
408
409
410static int auth_sae_send_confirm(struct hostapd_data *hapd,
411 struct sta_info *sta,
412 const u8 *bssid)
413{
414 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800415 int reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800416
417 data = auth_build_sae_confirm(hapd, sta);
418 if (data == NULL)
419 return WLAN_STATUS_UNSPECIFIED_FAILURE;
420
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800421 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
422 WLAN_STATUS_SUCCESS, wpabuf_head(data),
423 wpabuf_len(data));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800424
425 wpabuf_free(data);
426
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800427 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800428}
429
430
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800431static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800432{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800433 struct sta_info *sta;
434 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800435
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800436 if (hapd->conf->sae_anti_clogging_threshold == 0)
437 return 1;
438
439 for (sta = hapd->sta_list; sta; sta = sta->next) {
440 if (!sta->sae)
441 continue;
442 if (sta->sae->state != SAE_COMMITTED &&
443 sta->sae->state != SAE_CONFIRMED)
444 continue;
445 open++;
446 if (open >= hapd->conf->sae_anti_clogging_threshold)
447 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800448 }
449
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800450 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800451}
452
453
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800454static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
455 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800456{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800457 u8 mac[SHA256_MAC_LEN];
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800458
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800459 if (token_len != SHA256_MAC_LEN)
460 return -1;
461 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
462 addr, ETH_ALEN, mac) < 0 ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700463 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800464 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800465
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800466 return 0;
467}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800468
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800469
470static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800471 int group, const u8 *addr)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800472{
473 struct wpabuf *buf;
474 u8 *token;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800475 struct os_reltime now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800476
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800477 os_get_reltime(&now);
478 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
479 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800480 if (random_get_bytes(hapd->sae_token_key,
481 sizeof(hapd->sae_token_key)) < 0)
482 return NULL;
483 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
484 hapd->sae_token_key, sizeof(hapd->sae_token_key));
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800485 hapd->last_sae_token_key_update = now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800486 }
487
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800488 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800489 if (buf == NULL)
490 return NULL;
491
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800492 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
493
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800494 token = wpabuf_put(buf, SHA256_MAC_LEN);
495 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
496 addr, ETH_ALEN, token);
497
498 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800499}
500
501
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800502static int sae_check_big_sync(struct sta_info *sta)
503{
504 if (sta->sae->sync > dot11RSNASAESync) {
505 sta->sae->state = SAE_NOTHING;
506 sta->sae->sync = 0;
507 return -1;
508 }
509 return 0;
510}
511
512
513static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
514{
515 struct hostapd_data *hapd = eloop_ctx;
516 struct sta_info *sta = eloop_data;
517 int ret;
518
519 if (sae_check_big_sync(sta))
520 return;
521 sta->sae->sync++;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700522 wpa_printf(MSG_DEBUG, "SAE: Auth SAE retransmit timer for " MACSTR
523 " (sync=%d state=%d)",
524 MAC2STR(sta->addr), sta->sae->sync, sta->sae->state);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800525
526 switch (sta->sae->state) {
527 case SAE_COMMITTED:
528 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800529 eloop_register_timeout(0,
530 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800531 auth_sae_retransmit_timer, hapd, sta);
532 break;
533 case SAE_CONFIRMED:
534 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800535 eloop_register_timeout(0,
536 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800537 auth_sae_retransmit_timer, hapd, sta);
538 break;
539 default:
540 ret = -1;
541 break;
542 }
543
544 if (ret != WLAN_STATUS_SUCCESS)
545 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
546}
547
548
549void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
550{
551 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
552}
553
554
555static void sae_set_retransmit_timer(struct hostapd_data *hapd,
556 struct sta_info *sta)
557{
558 if (!(hapd->conf->mesh & MESH_ENABLED))
559 return;
560
561 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800562 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800563 auth_sae_retransmit_timer, hapd, sta);
564}
565
566
Dmitry Shmidte4663042016-04-04 10:07:49 -0700567void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
568{
569 sta->flags |= WLAN_STA_AUTH;
570 sta->auth_alg = WLAN_AUTH_SAE;
571 mlme_authenticate_indication(hapd, sta);
572 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
573 sta->sae->state = SAE_ACCEPTED;
574 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
575 sta->sae->pmk, sta->sae->pmkid);
576}
577
578
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800579static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
580 const u8 *bssid, u8 auth_transaction)
581{
582 int ret;
583
584 if (auth_transaction != 1 && auth_transaction != 2)
585 return WLAN_STATUS_UNSPECIFIED_FAILURE;
586
587 switch (sta->sae->state) {
588 case SAE_NOTHING:
589 if (auth_transaction == 1) {
590 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
591 if (ret)
592 return ret;
593 sta->sae->state = SAE_COMMITTED;
594
595 if (sae_process_commit(sta->sae) < 0)
596 return WLAN_STATUS_UNSPECIFIED_FAILURE;
597
598 /*
599 * In mesh case, both Commit and Confirm can be sent
600 * immediately. In infrastructure BSS, only a single
601 * Authentication frame (Commit) is expected from the AP
602 * here and the second one (Confirm) will be sent once
603 * the STA has sent its second Authentication frame
604 * (Confirm).
605 */
606 if (hapd->conf->mesh & MESH_ENABLED) {
607 /*
608 * Send both Commit and Confirm immediately
609 * based on SAE finite state machine
610 * Nothing -> Confirm transition.
611 */
612 ret = auth_sae_send_confirm(hapd, sta, bssid);
613 if (ret)
614 return ret;
615 sta->sae->state = SAE_CONFIRMED;
616 } else {
617 /*
618 * For infrastructure BSS, send only the Commit
619 * message now to get alternating sequence of
620 * Authentication frames between the AP and STA.
621 * Confirm will be sent in
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800622 * Committed -> Confirmed/Accepted transition
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800623 * when receiving Confirm from STA.
624 */
625 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800626 sta->sae->sync = 0;
627 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800628 } else {
629 hostapd_logger(hapd, sta->addr,
630 HOSTAPD_MODULE_IEEE80211,
631 HOSTAPD_LEVEL_DEBUG,
632 "SAE confirm before commit");
633 }
634 break;
635 case SAE_COMMITTED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800636 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800637 if (auth_transaction == 1) {
638 if (sae_process_commit(sta->sae) < 0)
639 return WLAN_STATUS_UNSPECIFIED_FAILURE;
640
641 ret = auth_sae_send_confirm(hapd, sta, bssid);
642 if (ret)
643 return ret;
644 sta->sae->state = SAE_CONFIRMED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800645 sta->sae->sync = 0;
646 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800647 } else if (hapd->conf->mesh & MESH_ENABLED) {
648 /*
649 * In mesh case, follow SAE finite state machine and
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800650 * send Commit now, if sync count allows.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800651 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800652 if (sae_check_big_sync(sta))
653 return WLAN_STATUS_SUCCESS;
654 sta->sae->sync++;
655
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700656 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800657 if (ret)
658 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800659
660 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800661 } else {
662 /*
663 * For instructure BSS, send the postponed Confirm from
664 * Nothing -> Confirmed transition that was reduced to
665 * Nothing -> Committed above.
666 */
667 ret = auth_sae_send_confirm(hapd, sta, bssid);
668 if (ret)
669 return ret;
670
671 sta->sae->state = SAE_CONFIRMED;
672
673 /*
674 * Since this was triggered on Confirm RX, run another
675 * step to get to Accepted without waiting for
676 * additional events.
677 */
678 return sae_sm_step(hapd, sta, bssid, auth_transaction);
679 }
680 break;
681 case SAE_CONFIRMED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800682 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800683 if (auth_transaction == 1) {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800684 if (sae_check_big_sync(sta))
685 return WLAN_STATUS_SUCCESS;
686 sta->sae->sync++;
687
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800688 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
689 if (ret)
690 return ret;
691
692 if (sae_process_commit(sta->sae) < 0)
693 return WLAN_STATUS_UNSPECIFIED_FAILURE;
694
695 ret = auth_sae_send_confirm(hapd, sta, bssid);
696 if (ret)
697 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800698
699 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800700 } else {
Dmitry Shmidte4663042016-04-04 10:07:49 -0700701 sae_accept_sta(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800702 }
703 break;
704 case SAE_ACCEPTED:
705 if (auth_transaction == 1) {
706 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
707 ") doing reauthentication",
708 MAC2STR(sta->addr));
709 ap_free_sta(hapd, sta);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700710 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800711 } else {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800712 if (sae_check_big_sync(sta))
713 return WLAN_STATUS_SUCCESS;
714 sta->sae->sync++;
715
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800716 ret = auth_sae_send_confirm(hapd, sta, bssid);
717 sae_clear_temp_data(sta->sae);
718 if (ret)
719 return ret;
720 }
721 break;
722 default:
723 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
724 sta->sae->state);
725 return WLAN_STATUS_UNSPECIFIED_FAILURE;
726 }
727 return WLAN_STATUS_SUCCESS;
728}
729
730
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700731static void sae_pick_next_group(struct hostapd_data *hapd, struct sta_info *sta)
732{
733 struct sae_data *sae = sta->sae;
734 int i, *groups = hapd->conf->sae_groups;
735
736 if (sae->state != SAE_COMMITTED)
737 return;
738
739 wpa_printf(MSG_DEBUG, "SAE: Previously selected group: %d", sae->group);
740
741 for (i = 0; groups && groups[i] > 0; i++) {
742 if (sae->group == groups[i])
743 break;
744 }
745
746 if (!groups || groups[i] <= 0) {
747 wpa_printf(MSG_DEBUG,
748 "SAE: Previously selected group not found from the current configuration");
749 return;
750 }
751
752 for (;;) {
753 i++;
754 if (groups[i] <= 0) {
755 wpa_printf(MSG_DEBUG,
756 "SAE: No alternative group enabled");
757 return;
758 }
759
760 if (sae_set_group(sae, groups[i]) < 0)
761 continue;
762
763 break;
764 }
765 wpa_printf(MSG_DEBUG, "SAE: Selected new group: %d", groups[i]);
766}
767
768
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800769static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
770 const struct ieee80211_mgmt *mgmt, size_t len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800771 u16 auth_transaction, u16 status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800772{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800773 int resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800774 struct wpabuf *data = NULL;
775
776 if (!sta->sae) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800777 if (auth_transaction != 1 ||
778 status_code != WLAN_STATUS_SUCCESS) {
779 resp = -1;
780 goto remove_sta;
781 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800782 sta->sae = os_zalloc(sizeof(*sta->sae));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800783 if (!sta->sae) {
784 resp = -1;
785 goto remove_sta;
786 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800787 sta->sae->state = SAE_NOTHING;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800788 sta->sae->sync = 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800789 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800790
Dmitry Shmidte4663042016-04-04 10:07:49 -0700791 if (sta->mesh_sae_pmksa_caching) {
792 wpa_printf(MSG_DEBUG,
793 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
794 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
795 sta->mesh_sae_pmksa_caching = 0;
796 }
797
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800798 if (auth_transaction == 1) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800799 const u8 *token = NULL, *pos, *end;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800800 size_t token_len = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800801 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
802 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800803 "start SAE authentication (RX commit, status=%u)",
804 status_code);
805
806 if ((hapd->conf->mesh & MESH_ENABLED) &&
807 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
808 sta->sae->tmp) {
809 pos = mgmt->u.auth.variable;
810 end = ((const u8 *) mgmt) + len;
811 if (pos + sizeof(le16) > end) {
812 wpa_printf(MSG_ERROR,
813 "SAE: Too short anti-clogging token request");
814 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
815 goto reply;
816 }
817 resp = sae_group_allowed(sta->sae,
818 hapd->conf->sae_groups,
819 WPA_GET_LE16(pos));
820 if (resp != WLAN_STATUS_SUCCESS) {
821 wpa_printf(MSG_ERROR,
822 "SAE: Invalid group in anti-clogging token request");
823 goto reply;
824 }
825 pos += sizeof(le16);
826
827 wpabuf_free(sta->sae->tmp->anti_clogging_token);
828 sta->sae->tmp->anti_clogging_token =
829 wpabuf_alloc_copy(pos, end - pos);
830 if (sta->sae->tmp->anti_clogging_token == NULL) {
831 wpa_printf(MSG_ERROR,
832 "SAE: Failed to alloc for anti-clogging token");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800833 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
834 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800835 }
836
837 /*
838 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
839 * is 76, a new Commit Message shall be constructed
840 * with the Anti-Clogging Token from the received
841 * Authentication frame, and the commit-scalar and
842 * COMMIT-ELEMENT previously sent.
843 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800844 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
845 if (resp != WLAN_STATUS_SUCCESS) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800846 wpa_printf(MSG_ERROR,
847 "SAE: Failed to send commit message");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800848 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800849 }
850 sta->sae->state = SAE_COMMITTED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800851 sta->sae->sync = 0;
852 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800853 return;
854 }
855
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700856 if ((hapd->conf->mesh & MESH_ENABLED) &&
857 status_code ==
858 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
859 sta->sae->tmp) {
860 wpa_printf(MSG_DEBUG,
861 "SAE: Peer did not accept our SAE group");
862 sae_pick_next_group(hapd, sta);
863 goto remove_sta;
864 }
865
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800866 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800867 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800868
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800869 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
870 ((const u8 *) mgmt) + len -
871 mgmt->u.auth.variable, &token,
872 &token_len, hapd->conf->sae_groups);
Dmitry Shmidt41712582015-06-29 11:02:15 -0700873 if (resp == SAE_SILENTLY_DISCARD) {
874 wpa_printf(MSG_DEBUG,
875 "SAE: Drop commit message from " MACSTR " due to reflection attack",
876 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800877 goto remove_sta;
Dmitry Shmidt41712582015-06-29 11:02:15 -0700878 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800879 if (token && check_sae_token(hapd, sta->addr, token, token_len)
880 < 0) {
881 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
882 "incorrect token from " MACSTR,
883 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800884 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
885 goto remove_sta;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800886 }
887
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800888 if (resp != WLAN_STATUS_SUCCESS)
889 goto reply;
890
891 if (!token && use_sae_anti_clogging(hapd)) {
892 wpa_printf(MSG_DEBUG,
893 "SAE: Request anti-clogging token from "
894 MACSTR, MAC2STR(sta->addr));
895 data = auth_build_token_req(hapd, sta->sae->group,
896 sta->addr);
897 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
898 if (hapd->conf->mesh & MESH_ENABLED)
899 sta->sae->state = SAE_NOTHING;
900 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800901 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800902
903 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800904 } else if (auth_transaction == 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800905 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
906 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800907 "SAE authentication (RX confirm, status=%u)",
908 status_code);
909 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800910 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800911 if (sta->sae->state >= SAE_CONFIRMED ||
912 !(hapd->conf->mesh & MESH_ENABLED)) {
913 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
914 ((u8 *) mgmt) + len -
915 mgmt->u.auth.variable) < 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800916 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800917 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800918 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800919 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800920 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800921 } else {
922 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
923 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800924 "unexpected SAE authentication transaction %u (status=%u)",
925 auth_transaction, status_code);
926 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800927 goto remove_sta;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800928 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
929 }
930
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800931reply:
932 if (resp != WLAN_STATUS_SUCCESS) {
933 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
934 auth_transaction, resp,
935 data ? wpabuf_head(data) : (u8 *) "",
936 data ? wpabuf_len(data) : 0);
937 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800938
939remove_sta:
940 if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
941 status_code != WLAN_STATUS_SUCCESS)) {
942 hostapd_drv_sta_remove(hapd, sta->addr);
943 sta->added_unassoc = 0;
944 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800945 wpabuf_free(data);
946}
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800947
948
949/**
950 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
951 * @hapd: BSS data for the device initiating the authentication
952 * @sta: the peer to which commit authentication frame is sent
953 *
954 * This function implements Init event handling (IEEE Std 802.11-2012,
955 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
956 * sta->sae structure should be initialized appropriately via a call to
957 * sae_prepare_commit().
958 */
959int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
960{
961 int ret;
962
963 if (!sta->sae || !sta->sae->tmp)
964 return -1;
965
966 if (sta->sae->state != SAE_NOTHING)
967 return -1;
968
969 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
970 if (ret)
971 return -1;
972
973 sta->sae->state = SAE_COMMITTED;
974 sta->sae->sync = 0;
975 sae_set_retransmit_timer(hapd, sta);
976
977 return 0;
978}
979
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800980#endif /* CONFIG_SAE */
981
982
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800983static u16 wpa_res_to_status_code(int res)
984{
985 if (res == WPA_INVALID_GROUP)
986 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
987 if (res == WPA_INVALID_PAIRWISE)
988 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
989 if (res == WPA_INVALID_AKMP)
990 return WLAN_STATUS_AKMP_NOT_VALID;
991 if (res == WPA_ALLOC_FAIL)
992 return WLAN_STATUS_UNSPECIFIED_FAILURE;
993#ifdef CONFIG_IEEE80211W
994 if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
995 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
996 if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
997 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
998#endif /* CONFIG_IEEE80211W */
999 if (res == WPA_INVALID_MDIE)
1000 return WLAN_STATUS_INVALID_MDIE;
1001 if (res != WPA_IE_OK)
1002 return WLAN_STATUS_INVALID_IE;
1003 return WLAN_STATUS_SUCCESS;
1004}
1005
1006
1007#ifdef CONFIG_FILS
1008
1009static void handle_auth_fils_finish(struct hostapd_data *hapd,
1010 struct sta_info *sta, u16 resp,
1011 struct rsn_pmksa_cache_entry *pmksa,
1012 struct wpabuf *erp_resp,
1013 const u8 *msk, size_t msk_len);
1014
1015static void handle_auth_fils(struct hostapd_data *hapd, struct sta_info *sta,
1016 const struct ieee80211_mgmt *mgmt, size_t len,
1017 u16 auth_transaction, u16 status_code)
1018{
1019 u16 resp = WLAN_STATUS_SUCCESS;
1020 const u8 *pos, *end;
1021 struct ieee802_11_elems elems;
1022 int res;
1023 struct wpa_ie_data rsn;
1024 struct rsn_pmksa_cache_entry *pmksa = NULL;
1025
1026 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
1027 return;
1028
1029 pos = mgmt->u.auth.variable;
1030 end = ((const u8 *) mgmt) + len;
1031
1032 wpa_hexdump(MSG_DEBUG, "FILS: Authentication frame fields",
1033 pos, end - pos);
1034
1035 /* TODO: Finite Cyclic Group when using PK or PFS */
1036 /* TODO: Element when using PK or PFS */
1037
1038 wpa_hexdump(MSG_DEBUG, "FILS: Remaining IEs", pos, end - pos);
1039 if (ieee802_11_parse_elems(pos, end - pos, &elems, 1) == ParseFailed) {
1040 wpa_printf(MSG_DEBUG, "FILS: Could not parse elements");
1041 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1042 goto fail;
1043 }
1044
1045 /* RSNE */
1046 wpa_hexdump(MSG_DEBUG, "FILS: RSN element",
1047 elems.rsn_ie, elems.rsn_ie_len);
1048 if (!elems.rsn_ie ||
1049 wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2,
1050 &rsn) < 0) {
1051 wpa_printf(MSG_DEBUG, "FILS: No valid RSN element");
1052 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1053 goto fail;
1054 }
1055
1056 if (!sta->wpa_sm)
1057 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr,
1058 NULL);
1059 if (!sta->wpa_sm) {
1060 wpa_printf(MSG_DEBUG,
1061 "FILS: Failed to initialize RSN state machine");
1062 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1063 goto fail;
1064 }
1065
1066 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1067 elems.rsn_ie - 2, elems.rsn_ie_len + 2,
1068 elems.mdie, elems.mdie_len);
1069 resp = wpa_res_to_status_code(res);
1070 if (resp != WLAN_STATUS_SUCCESS)
1071 goto fail;
1072
1073 /* TODO: MDE when using FILS+FT */
1074 /* TODO: FTE when using FILS+FT */
1075
1076 if (!elems.fils_nonce) {
1077 wpa_printf(MSG_DEBUG, "FILS: No FILS Nonce field");
1078 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1079 goto fail;
1080 }
1081 wpa_hexdump(MSG_DEBUG, "FILS: SNonce", elems.fils_nonce,
1082 FILS_NONCE_LEN);
1083 os_memcpy(sta->fils_snonce, elems.fils_nonce, FILS_NONCE_LEN);
1084
1085 /* PMKID List */
1086 if (rsn.pmkid && rsn.num_pmkid > 0) {
1087 u8 num;
1088 const u8 *pmkid;
1089
1090 wpa_hexdump(MSG_DEBUG, "FILS: PMKID List",
1091 rsn.pmkid, rsn.num_pmkid * PMKID_LEN);
1092
1093 pmkid = rsn.pmkid;
1094 num = rsn.num_pmkid;
1095 while (num) {
1096 wpa_hexdump(MSG_DEBUG, "FILS: PMKID", pmkid, PMKID_LEN);
1097 pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr,
1098 pmkid);
1099 if (pmksa)
1100 break;
1101 pmkid += PMKID_LEN;
1102 num--;
1103 }
1104 }
1105 if (pmksa && wpa_auth_sta_key_mgmt(sta->wpa_sm) != pmksa->akmp) {
1106 wpa_printf(MSG_DEBUG,
1107 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1108 wpa_auth_sta_key_mgmt(sta->wpa_sm), pmksa->akmp);
1109 pmksa = NULL;
1110 }
1111 if (pmksa)
1112 wpa_printf(MSG_DEBUG, "FILS: Found matching PMKSA cache entry");
1113
1114 /* FILS Session */
1115 if (!elems.fils_session) {
1116 wpa_printf(MSG_DEBUG, "FILS: No FILS Session element");
1117 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1118 goto fail;
1119 }
1120 wpa_hexdump(MSG_DEBUG, "FILS: FILS Session", elems.fils_session,
1121 FILS_SESSION_LEN);
1122 os_memcpy(sta->fils_session, elems.fils_session, FILS_SESSION_LEN);
1123
1124 /* FILS Wrapped Data */
1125 if (elems.fils_wrapped_data) {
1126 wpa_hexdump(MSG_DEBUG, "FILS: Wrapped Data",
1127 elems.fils_wrapped_data,
1128 elems.fils_wrapped_data_len);
1129 if (!pmksa) {
1130#ifndef CONFIG_NO_RADIUS
1131 if (!sta->eapol_sm) {
1132 sta->eapol_sm =
1133 ieee802_1x_alloc_eapol_sm(hapd, sta);
1134 }
1135 wpa_printf(MSG_DEBUG,
1136 "FILS: Forward EAP-Identity/Re-auth Start to authentication server");
1137 ieee802_1x_encapsulate_radius(
1138 hapd, sta, elems.fils_wrapped_data,
1139 elems.fils_wrapped_data_len);
1140 wpa_printf(MSG_DEBUG,
1141 "FILS: Will send Authentication frame once the response from authentication server is available");
1142 sta->flags |= WLAN_STA_PENDING_FILS_ERP;
1143 return;
1144#else /* CONFIG_NO_RADIUS */
1145 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1146 goto fail;
1147#endif /* CONFIG_NO_RADIUS */
1148 }
1149 }
1150
1151fail:
1152 handle_auth_fils_finish(hapd, sta, resp, pmksa, NULL, NULL, 0);
1153}
1154
1155
1156static void handle_auth_fils_finish(struct hostapd_data *hapd,
1157 struct sta_info *sta, u16 resp,
1158 struct rsn_pmksa_cache_entry *pmksa,
1159 struct wpabuf *erp_resp,
1160 const u8 *msk, size_t msk_len)
1161{
1162 u8 fils_nonce[FILS_NONCE_LEN];
1163 size_t ielen;
1164 struct wpabuf *data = NULL;
1165 const u8 *ie;
1166 u8 *ie_buf = NULL;
1167 const u8 *pmk = NULL;
1168 size_t pmk_len = 0;
1169
1170 if (resp != WLAN_STATUS_SUCCESS)
1171 goto fail;
1172
1173 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
1174 if (!ie) {
1175 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1176 goto fail;
1177 }
1178 if (pmksa) {
1179 /* Add PMKID of the selected PMKSA into RSNE */
1180 ie_buf = os_malloc(ielen + 2 + 2 + PMKID_LEN);
1181 if (!ie_buf) {
1182 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1183 goto fail;
1184 }
1185 os_memcpy(ie_buf, ie, ielen);
1186 if (wpa_insert_pmkid(ie_buf, &ielen, pmksa->pmkid) < 0) {
1187 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1188 goto fail;
1189 }
1190 ie = ie_buf;
1191 }
1192
1193 if (random_get_bytes(fils_nonce, FILS_NONCE_LEN) < 0) {
1194 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1195 goto fail;
1196 }
1197 wpa_hexdump(MSG_DEBUG, "RSN: Generated FILS Nonce",
1198 fils_nonce, FILS_NONCE_LEN);
1199
1200 data = wpabuf_alloc(1000 + ielen);
1201 if (!data) {
1202 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1203 goto fail;
1204 }
1205
1206 /* TODO: Finite Cyclic Group when using PK or PFS */
1207 /* TODO: Element when using PK or PFS */
1208
1209 /* RSNE */
1210 wpabuf_put_data(data, ie, ielen);
1211
1212 /* TODO: MDE when using FILS+FT */
1213 /* TODO: FTE when using FILS+FT */
1214
1215 /* FILS Nonce */
1216 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1217 wpabuf_put_u8(data, 1 + FILS_NONCE_LEN); /* Length */
1218 /* Element ID Extension */
1219 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_NONCE);
1220 wpabuf_put_data(data, fils_nonce, FILS_NONCE_LEN);
1221
1222 /* FILS Session */
1223 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1224 wpabuf_put_u8(data, 1 + FILS_SESSION_LEN); /* Length */
1225 /* Element ID Extension */
1226 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_SESSION);
1227 wpabuf_put_data(data, sta->fils_session, FILS_SESSION_LEN);
1228
1229 /* FILS Wrapped Data */
1230 if (!pmksa && erp_resp) {
1231 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1232 wpabuf_put_u8(data, 1 + wpabuf_len(erp_resp)); /* Length */
1233 /* Element ID Extension */
1234 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_WRAPPED_DATA);
1235 wpabuf_put_buf(data, erp_resp);
1236
1237 pmk = msk;
1238 pmk_len = msk_len > PMK_LEN ? PMK_LEN : msk_len;
1239 } else if (pmksa) {
1240 pmk = pmksa->pmk;
1241 pmk_len = pmksa->pmk_len;
1242 }
1243
1244 if (!pmk) {
1245 wpa_printf(MSG_DEBUG, "FILS: No PMK available");
1246 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1247 wpabuf_free(data);
1248 data = NULL;
1249 goto fail;
1250 }
1251
1252 if (fils_auth_pmk_to_ptk(sta->wpa_sm, pmk, pmk_len,
1253 sta->fils_snonce, fils_nonce) < 0) {
1254 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1255 wpabuf_free(data);
1256 data = NULL;
1257 goto fail;
1258 }
1259
1260fail:
1261 send_auth_reply(hapd, sta->addr, hapd->own_addr, WLAN_AUTH_FILS_SK, 2,
1262 resp,
1263 data ? wpabuf_head(data) : (u8 *) "",
1264 data ? wpabuf_len(data) : 0);
1265 wpabuf_free(data);
1266
1267 if (resp == WLAN_STATUS_SUCCESS) {
1268 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1269 HOSTAPD_LEVEL_DEBUG,
1270 "authentication OK (FILS)");
1271 sta->flags |= WLAN_STA_AUTH;
1272 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1273 sta->auth_alg = WLAN_AUTH_FILS_SK;
1274 mlme_authenticate_indication(hapd, sta);
1275 }
1276
1277 os_free(ie_buf);
1278}
1279
1280
1281void ieee802_11_finish_fils_auth(struct hostapd_data *hapd,
1282 struct sta_info *sta, int success,
1283 struct wpabuf *erp_resp,
1284 const u8 *msk, size_t msk_len)
1285{
1286 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
1287 handle_auth_fils_finish(hapd, sta, success ? WLAN_STATUS_SUCCESS :
1288 WLAN_STATUS_UNSPECIFIED_FAILURE, NULL,
1289 erp_resp, msk, msk_len);
1290}
1291
1292#endif /* CONFIG_FILS */
1293
1294
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001295static void handle_auth(struct hostapd_data *hapd,
1296 const struct ieee80211_mgmt *mgmt, size_t len)
1297{
1298 u16 auth_alg, auth_transaction, status_code;
1299 u16 resp = WLAN_STATUS_SUCCESS;
1300 struct sta_info *sta = NULL;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001301 int res, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001302 u16 fc;
1303 const u8 *challenge = NULL;
1304 u32 session_timeout, acct_interim_interval;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001305 struct vlan_description vlan_id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001306 struct hostapd_sta_wpa_psk_short *psk = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001307 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1308 size_t resp_ies_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001309 char *identity = NULL;
1310 char *radius_cui = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001311 u16 seq_ctrl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001312
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001313 os_memset(&vlan_id, 0, sizeof(vlan_id));
1314
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001316 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
1317 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001318 return;
1319 }
1320
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001321#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001322 if (hapd->iconf->ignore_auth_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001323 drand48() < hapd->iconf->ignore_auth_probability) {
1324 wpa_printf(MSG_INFO,
1325 "TESTING: ignoring auth frame from " MACSTR,
1326 MAC2STR(mgmt->sa));
1327 return;
1328 }
1329#endif /* CONFIG_TESTING_OPTIONS */
1330
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001331 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1332 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1333 status_code = le_to_host16(mgmt->u.auth.status_code);
1334 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001335 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001336
1337 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
1338 2 + WLAN_AUTH_CHALLENGE_LEN &&
1339 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
1340 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
1341 challenge = &mgmt->u.auth.variable[2];
1342
1343 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001344 "auth_transaction=%d status_code=%d wep=%d%s "
1345 "seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001346 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
1347 status_code, !!(fc & WLAN_FC_ISWEP),
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001348 challenge ? " challenge" : "",
1349 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001350
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001351#ifdef CONFIG_NO_RC4
1352 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
1353 wpa_printf(MSG_INFO,
1354 "Unsupported authentication algorithm (%d)",
1355 auth_alg);
1356 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1357 goto fail;
1358 }
1359#endif /* CONFIG_NO_RC4 */
1360
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001361 if (hapd->tkip_countermeasures) {
1362 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1363 goto fail;
1364 }
1365
1366 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
1367 auth_alg == WLAN_AUTH_OPEN) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001368#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001369 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001370 auth_alg == WLAN_AUTH_FT) ||
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001371#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001372#ifdef CONFIG_SAE
1373 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
1374 auth_alg == WLAN_AUTH_SAE) ||
1375#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001376#ifdef CONFIG_FILS
1377 (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
1378 auth_alg == WLAN_AUTH_FILS_SK) ||
1379#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001380 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
1381 auth_alg == WLAN_AUTH_SHARED_KEY))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001382 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
1383 auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001384 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1385 goto fail;
1386 }
1387
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001388 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001389 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001390 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
1391 auth_transaction);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001392 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1393 goto fail;
1394 }
1395
1396 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001397 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1398 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1400 goto fail;
1401 }
1402
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001403 if (hapd->conf->no_auth_if_seen_on) {
1404 struct hostapd_data *other;
1405
1406 other = sta_track_seen_on(hapd->iface, mgmt->sa,
1407 hapd->conf->no_auth_if_seen_on);
1408 if (other) {
1409 u8 *pos;
1410 u32 info;
1411 u8 op_class, channel, phytype;
1412
1413 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
1414 MACSTR " since STA has been seen on %s",
1415 hapd->conf->iface, MAC2STR(mgmt->sa),
1416 hapd->conf->no_auth_if_seen_on);
1417
1418 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1419 pos = &resp_ies[0];
1420 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1421 *pos++ = 13;
1422 os_memcpy(pos, other->own_addr, ETH_ALEN);
1423 pos += ETH_ALEN;
1424 info = 0; /* TODO: BSSID Information */
1425 WPA_PUT_LE32(pos, info);
1426 pos += 4;
1427 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1428 phytype = 8; /* dmg */
1429 else if (other->iconf->ieee80211ac)
1430 phytype = 9; /* vht */
1431 else if (other->iconf->ieee80211n)
1432 phytype = 7; /* ht */
1433 else if (other->iconf->hw_mode ==
1434 HOSTAPD_MODE_IEEE80211A)
1435 phytype = 4; /* ofdm */
1436 else if (other->iconf->hw_mode ==
1437 HOSTAPD_MODE_IEEE80211G)
1438 phytype = 6; /* erp */
1439 else
1440 phytype = 5; /* hrdsss */
1441 if (ieee80211_freq_to_channel_ext(
1442 hostapd_hw_get_freq(other,
1443 other->iconf->channel),
1444 other->iconf->secondary_channel,
1445 other->iconf->ieee80211ac,
1446 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1447 op_class = 0;
1448 channel = other->iconf->channel;
1449 }
1450 *pos++ = op_class;
1451 *pos++ = channel;
1452 *pos++ = phytype;
1453 resp_ies_len = pos - &resp_ies[0];
1454 goto fail;
1455 }
1456 }
1457
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001458 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1459 &session_timeout,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001460 &acct_interim_interval, &vlan_id,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001461 &psk, &identity, &radius_cui);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001462
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001463 if (res == HOSTAPD_ACL_REJECT) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001464 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1465 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001466 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1467 goto fail;
1468 }
1469 if (res == HOSTAPD_ACL_PENDING) {
1470 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1471 " waiting for an external authentication",
1472 MAC2STR(mgmt->sa));
1473 /* Authentication code will re-send the authentication frame
1474 * after it has received (and cached) information from the
1475 * external source. */
1476 return;
1477 }
1478
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001479 sta = ap_get_sta(hapd, mgmt->sa);
1480 if (sta) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001481 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001482 if ((fc & WLAN_FC_RETRY) &&
1483 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1484 sta->last_seq_ctrl == seq_ctrl &&
1485 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1486 hostapd_logger(hapd, sta->addr,
1487 HOSTAPD_MODULE_IEEE80211,
1488 HOSTAPD_LEVEL_DEBUG,
1489 "Drop repeated authentication frame seq_ctrl=0x%x",
1490 seq_ctrl);
1491 return;
1492 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001493#ifdef CONFIG_MESH
1494 if ((hapd->conf->mesh & MESH_ENABLED) &&
1495 sta->plink_state == PLINK_BLOCKED) {
1496 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1497 " is blocked - drop Authentication frame",
1498 MAC2STR(mgmt->sa));
1499 return;
1500 }
1501#endif /* CONFIG_MESH */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001502 } else {
1503#ifdef CONFIG_MESH
1504 if (hapd->conf->mesh & MESH_ENABLED) {
1505 /* if the mesh peer is not available, we don't do auth.
1506 */
1507 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001508 " not yet known - drop Authentication frame",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001509 MAC2STR(mgmt->sa));
1510 /*
1511 * Save a copy of the frame so that it can be processed
1512 * if a new peer entry is added shortly after this.
1513 */
1514 wpabuf_free(hapd->mesh_pending_auth);
1515 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1516 os_get_reltime(&hapd->mesh_pending_auth_time);
1517 return;
1518 }
1519#endif /* CONFIG_MESH */
1520
1521 sta = ap_sta_add(hapd, mgmt->sa);
1522 if (!sta) {
1523 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1524 goto fail;
1525 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001526 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001527 sta->last_seq_ctrl = seq_ctrl;
1528 sta->last_subtype = WLAN_FC_STYPE_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001529
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001530 if (vlan_id.notempty &&
1531 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
1532 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1533 HOSTAPD_LEVEL_INFO,
1534 "Invalid VLAN %d%s received from RADIUS server",
1535 vlan_id.untagged,
1536 vlan_id.tagged[0] ? "+" : "");
1537 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1538 goto fail;
1539 }
1540 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1541 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1542 goto fail;
1543 }
1544 if (sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001545 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1546 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001547
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001548 hostapd_free_psk_list(sta->psk);
1549 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1550 sta->psk = psk;
1551 psk = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001552 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001553 sta->psk = NULL;
1554 }
1555
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001556 sta->identity = identity;
1557 identity = NULL;
1558 sta->radius_cui = radius_cui;
1559 radius_cui = NULL;
1560
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001561 sta->flags &= ~WLAN_STA_PREAUTH;
1562 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1563
1564 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1565 sta->acct_interim_interval = acct_interim_interval;
1566 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1567 ap_sta_session_timeout(hapd, sta, session_timeout);
1568 else
1569 ap_sta_no_session_timeout(hapd, sta);
1570
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001571 /*
1572 * If the driver supports full AP client state, add a station to the
1573 * driver before sending authentication reply to make sure the driver
1574 * has resources, and not to go through the entire authentication and
1575 * association handshake, and fail it at the end.
1576 *
1577 * If this is not the first transaction, in a multi-step authentication
1578 * algorithm, the station already exists in the driver
1579 * (sta->added_unassoc = 1) so skip it.
1580 *
1581 * In mesh mode, the station was already added to the driver when the
1582 * NEW_PEER_CANDIDATE event is received.
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001583 *
1584 * If PMF was negotiated for the existing association, skip this to
1585 * avoid dropping the STA entry and the associated keys. This is needed
1586 * to allow the original connection work until the attempt can complete
1587 * (re)association, so that unprotected Authentication frame cannot be
1588 * used to bypass PMF protection.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001589 */
1590 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001591 (!(sta->flags & WLAN_STA_MFP) || !ap_sta_is_authorized(sta)) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001592 !(hapd->conf->mesh & MESH_ENABLED) &&
1593 !(sta->added_unassoc)) {
1594 /*
1595 * If a station that is already associated to the AP, is trying
1596 * to authenticate again, remove the STA entry, in order to make
1597 * sure the STA PS state gets cleared and configuration gets
1598 * updated. To handle this, station's added_unassoc flag is
1599 * cleared once the station has completed association.
1600 */
1601 hostapd_drv_sta_remove(hapd, sta->addr);
1602 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
1603 WLAN_STA_AUTHORIZED);
1604
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07001605 if (hostapd_sta_add(hapd, sta->addr, 0, 0, NULL, 0, 0,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001606 NULL, NULL, sta->flags, 0, 0, 0, 0)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001607 hostapd_logger(hapd, sta->addr,
1608 HOSTAPD_MODULE_IEEE80211,
1609 HOSTAPD_LEVEL_NOTICE,
1610 "Could not add STA to kernel driver");
1611 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1612 goto fail;
1613 }
1614
1615 sta->added_unassoc = 1;
1616 }
1617
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001618 switch (auth_alg) {
1619 case WLAN_AUTH_OPEN:
1620 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1621 HOSTAPD_LEVEL_DEBUG,
1622 "authentication OK (open system)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623 sta->flags |= WLAN_STA_AUTH;
1624 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1625 sta->auth_alg = WLAN_AUTH_OPEN;
1626 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001627 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001628#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001629 case WLAN_AUTH_SHARED_KEY:
1630 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1631 fc & WLAN_FC_ISWEP);
1632 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1633 mlme_authenticate_indication(hapd, sta);
1634 if (sta->challenge && auth_transaction == 1) {
1635 resp_ies[0] = WLAN_EID_CHALLENGE;
1636 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1637 os_memcpy(resp_ies + 2, sta->challenge,
1638 WLAN_AUTH_CHALLENGE_LEN);
1639 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1640 }
1641 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001642#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001643#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001644 case WLAN_AUTH_FT:
1645 sta->auth_alg = WLAN_AUTH_FT;
1646 if (sta->wpa_sm == NULL)
1647 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001648 sta->addr, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001649 if (sta->wpa_sm == NULL) {
1650 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1651 "state machine");
1652 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1653 goto fail;
1654 }
1655 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1656 auth_transaction, mgmt->u.auth.variable,
1657 len - IEEE80211_HDRLEN -
1658 sizeof(mgmt->u.auth),
1659 handle_auth_ft_finish, hapd);
1660 /* handle_auth_ft_finish() callback will complete auth. */
1661 return;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001662#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001663#ifdef CONFIG_SAE
1664 case WLAN_AUTH_SAE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001665#ifdef CONFIG_MESH
1666 if (status_code == WLAN_STATUS_SUCCESS &&
1667 hapd->conf->mesh & MESH_ENABLED) {
1668 if (sta->wpa_sm == NULL)
1669 sta->wpa_sm =
1670 wpa_auth_sta_init(hapd->wpa_auth,
1671 sta->addr, NULL);
1672 if (sta->wpa_sm == NULL) {
1673 wpa_printf(MSG_DEBUG,
1674 "SAE: Failed to initialize WPA state machine");
1675 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1676 goto fail;
1677 }
1678 }
1679#endif /* CONFIG_MESH */
1680 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1681 status_code);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001682 return;
1683#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001684#ifdef CONFIG_FILS
1685 case WLAN_AUTH_FILS_SK:
1686 handle_auth_fils(hapd, sta, mgmt, len, auth_transaction,
1687 status_code);
1688 return;
1689#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001690 }
1691
1692 fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001693 os_free(identity);
1694 os_free(radius_cui);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001695 hostapd_free_psk_list(psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001696
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001697 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1698 auth_transaction + 1, resp, resp_ies,
1699 resp_ies_len);
1700
1701 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
1702 reply_res != WLAN_STATUS_SUCCESS)) {
1703 hostapd_drv_sta_remove(hapd, sta->addr);
1704 sta->added_unassoc = 0;
1705 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001706}
1707
1708
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001709int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001710{
1711 int i, j = 32, aid;
1712
1713 /* get a unique AID */
1714 if (sta->aid > 0) {
1715 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1716 return 0;
1717 }
1718
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07001719 if (TEST_FAIL())
1720 return -1;
1721
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001722 for (i = 0; i < AID_WORDS; i++) {
1723 if (hapd->sta_aid[i] == (u32) -1)
1724 continue;
1725 for (j = 0; j < 32; j++) {
1726 if (!(hapd->sta_aid[i] & BIT(j)))
1727 break;
1728 }
1729 if (j < 32)
1730 break;
1731 }
1732 if (j == 32)
1733 return -1;
1734 aid = i * 32 + j + 1;
1735 if (aid > 2007)
1736 return -1;
1737
1738 sta->aid = aid;
1739 hapd->sta_aid[i] |= BIT(j);
1740 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1741 return 0;
1742}
1743
1744
1745static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1746 const u8 *ssid_ie, size_t ssid_ie_len)
1747{
1748 if (ssid_ie == NULL)
1749 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1750
1751 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1752 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001753 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1754 HOSTAPD_LEVEL_INFO,
1755 "Station tried to associate with unknown SSID "
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001756 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1758 }
1759
1760 return WLAN_STATUS_SUCCESS;
1761}
1762
1763
1764static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1765 const u8 *wmm_ie, size_t wmm_ie_len)
1766{
1767 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001768 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001769 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001770 struct wmm_information_element *wmm;
1771
1772 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001773 hostapd_logger(hapd, sta->addr,
1774 HOSTAPD_MODULE_WPA,
1775 HOSTAPD_LEVEL_DEBUG,
1776 "invalid WMM element in association "
1777 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001778 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1779 }
1780
1781 sta->flags |= WLAN_STA_WMM;
1782 wmm = (struct wmm_information_element *) wmm_ie;
1783 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001784 }
1785 return WLAN_STATUS_SUCCESS;
1786}
1787
1788
1789static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1790 struct ieee802_11_elems *elems)
1791{
1792 if (!elems->supp_rates) {
1793 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1794 HOSTAPD_LEVEL_DEBUG,
1795 "No supported rates element in AssocReq");
1796 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1797 }
1798
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001799 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1800 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001801 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1802 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001803 "Invalid supported rates element length %d+%d",
1804 elems->supp_rates_len,
1805 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001806 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1807 }
1808
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001809 sta->supported_rates_len = merge_byte_arrays(
1810 sta->supported_rates, sizeof(sta->supported_rates),
1811 elems->supp_rates, elems->supp_rates_len,
1812 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001813
1814 return WLAN_STATUS_SUCCESS;
1815}
1816
1817
Dmitry Shmidt051af732013-10-22 13:52:46 -07001818static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1819 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1820{
1821#ifdef CONFIG_INTERWORKING
1822 /* check for QoS Map support */
1823 if (ext_capab_ie_len >= 5) {
1824 if (ext_capab_ie[4] & 0x01)
1825 sta->qos_map_enabled = 1;
1826 }
1827#endif /* CONFIG_INTERWORKING */
1828
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001829 if (ext_capab_ie_len > 0)
1830 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1831
Dmitry Shmidt051af732013-10-22 13:52:46 -07001832 return WLAN_STATUS_SUCCESS;
1833}
1834
1835
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001836static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1837 const u8 *ies, size_t ies_len, int reassoc)
1838{
1839 struct ieee802_11_elems elems;
1840 u16 resp;
1841 const u8 *wpa_ie;
1842 size_t wpa_ie_len;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001843 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001844
1845 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1846 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1847 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1848 "association request");
1849 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1850 }
1851
1852 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1853 if (resp != WLAN_STATUS_SUCCESS)
1854 return resp;
1855 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1856 if (resp != WLAN_STATUS_SUCCESS)
1857 return resp;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001858 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1859 if (resp != WLAN_STATUS_SUCCESS)
1860 return resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001861 resp = copy_supp_rates(hapd, sta, &elems);
1862 if (resp != WLAN_STATUS_SUCCESS)
1863 return resp;
1864#ifdef CONFIG_IEEE80211N
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001865 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001866 if (resp != WLAN_STATUS_SUCCESS)
1867 return resp;
1868 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1869 !(sta->flags & WLAN_STA_HT)) {
1870 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1871 HOSTAPD_LEVEL_INFO, "Station does not support "
1872 "mandatory HT PHY - reject association");
1873 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1874 }
1875#endif /* CONFIG_IEEE80211N */
1876
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001877#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001878 if (hapd->iconf->ieee80211ac) {
1879 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1880 if (resp != WLAN_STATUS_SUCCESS)
1881 return resp;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08001882
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001883 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1884 if (resp != WLAN_STATUS_SUCCESS)
1885 return resp;
1886 }
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08001887
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001888 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1889 !(sta->flags & WLAN_STA_VHT)) {
1890 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1891 HOSTAPD_LEVEL_INFO, "Station does not support "
1892 "mandatory VHT PHY - reject association");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001893 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001894 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001895
1896 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1897 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1898 elems.vendor_vht_len);
1899 if (resp != WLAN_STATUS_SUCCESS)
1900 return resp;
1901 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001902#endif /* CONFIG_IEEE80211AC */
1903
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001904#ifdef CONFIG_P2P
1905 if (elems.p2p) {
1906 wpabuf_free(sta->p2p_ie);
1907 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1908 P2P_IE_VENDOR_TYPE);
1909 if (sta->p2p_ie)
1910 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1911 } else {
1912 wpabuf_free(sta->p2p_ie);
1913 sta->p2p_ie = NULL;
1914 }
1915#endif /* CONFIG_P2P */
1916
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001917 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1918 wpa_ie = elems.rsn_ie;
1919 wpa_ie_len = elems.rsn_ie_len;
1920 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1921 elems.wpa_ie) {
1922 wpa_ie = elems.wpa_ie;
1923 wpa_ie_len = elems.wpa_ie_len;
1924 } else {
1925 wpa_ie = NULL;
1926 wpa_ie_len = 0;
1927 }
1928
1929#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001930 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001931 if (hapd->conf->wps_state && elems.wps_ie) {
1932 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1933 "Request - assume WPS is used");
1934 sta->flags |= WLAN_STA_WPS;
1935 wpabuf_free(sta->wps_ie);
1936 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1937 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001938 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1939 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1940 sta->flags |= WLAN_STA_WPS2;
1941 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001942 wpa_ie = NULL;
1943 wpa_ie_len = 0;
1944 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1945 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1946 "(Re)Association Request - reject");
1947 return WLAN_STATUS_INVALID_IE;
1948 }
1949 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1950 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1951 "(Re)Association Request - possible WPS use");
1952 sta->flags |= WLAN_STA_MAYBE_WPS;
1953 } else
1954#endif /* CONFIG_WPS */
1955 if (hapd->conf->wpa && wpa_ie == NULL) {
1956 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1957 HOSTAPD_LEVEL_INFO,
1958 "No WPA/RSN IE in association request");
1959 return WLAN_STATUS_INVALID_IE;
1960 }
1961
1962 if (hapd->conf->wpa && wpa_ie) {
1963 int res;
1964 wpa_ie -= 2;
1965 wpa_ie_len += 2;
1966 if (sta->wpa_sm == NULL)
1967 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001968 sta->addr,
1969 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001970 if (sta->wpa_sm == NULL) {
1971 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1972 "state machine");
1973 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1974 }
1975 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1976 wpa_ie, wpa_ie_len,
1977 elems.mdie, elems.mdie_len);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001978 resp = wpa_res_to_status_code(res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001979 if (resp != WLAN_STATUS_SUCCESS)
1980 return resp;
1981#ifdef CONFIG_IEEE80211W
1982 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1983 sta->sa_query_count > 0)
1984 ap_check_sa_query_timeout(hapd, sta);
1985 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1986 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1987 /*
1988 * STA has already been associated with MFP and SA
1989 * Query timeout has not been reached. Reject the
1990 * association attempt temporarily and start SA Query,
1991 * if one is not pending.
1992 */
1993
1994 if (sta->sa_query_count == 0)
1995 ap_sta_start_sa_query(hapd, sta);
1996
1997 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1998 }
1999
2000 if (wpa_auth_uses_mfp(sta->wpa_sm))
2001 sta->flags |= WLAN_STA_MFP;
2002 else
2003 sta->flags &= ~WLAN_STA_MFP;
2004#endif /* CONFIG_IEEE80211W */
2005
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002006#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002007 if (sta->auth_alg == WLAN_AUTH_FT) {
2008 if (!reassoc) {
2009 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
2010 "to use association (not "
2011 "re-association) with FT auth_alg",
2012 MAC2STR(sta->addr));
2013 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2014 }
2015
2016 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
2017 ies_len);
2018 if (resp != WLAN_STATUS_SUCCESS)
2019 return resp;
2020 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002021#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002022
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002023#ifdef CONFIG_SAE
2024 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002025 sta->auth_alg == WLAN_AUTH_OPEN) {
2026 struct rsn_pmksa_cache_entry *sa;
2027 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
2028 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
2029 wpa_printf(MSG_DEBUG,
2030 "SAE: No PMKSA cache entry found for "
2031 MACSTR, MAC2STR(sta->addr));
2032 return WLAN_STATUS_INVALID_PMKID;
2033 }
2034 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
2035 " using PMKSA caching", MAC2STR(sta->addr));
2036 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
2037 sta->auth_alg != WLAN_AUTH_SAE &&
2038 !(sta->auth_alg == WLAN_AUTH_FT &&
2039 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002040 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
2041 "SAE AKM after non-SAE auth_alg %u",
2042 MAC2STR(sta->addr), sta->auth_alg);
2043 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
2044 }
2045#endif /* CONFIG_SAE */
2046
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002047#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002048 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002049 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
2050 hostapd_logger(hapd, sta->addr,
2051 HOSTAPD_MODULE_IEEE80211,
2052 HOSTAPD_LEVEL_INFO,
2053 "Station tried to use TKIP with HT "
2054 "association");
2055 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
2056 }
2057#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002058#ifdef CONFIG_HS20
2059 } else if (hapd->conf->osen) {
2060 if (elems.osen == NULL) {
2061 hostapd_logger(
2062 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2063 HOSTAPD_LEVEL_INFO,
2064 "No HS 2.0 OSEN element in association request");
2065 return WLAN_STATUS_INVALID_IE;
2066 }
2067
2068 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
2069 if (sta->wpa_sm == NULL)
2070 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
2071 sta->addr, NULL);
2072 if (sta->wpa_sm == NULL) {
2073 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
2074 "state machine");
2075 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2076 }
2077 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
2078 elems.osen - 2, elems.osen_len + 2) < 0)
2079 return WLAN_STATUS_INVALID_IE;
2080#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002081 } else
2082 wpa_auth_sta_no_wpa(sta->wpa_sm);
2083
2084#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002085 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
2086#endif /* CONFIG_P2P */
2087
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002088#ifdef CONFIG_HS20
2089 wpabuf_free(sta->hs20_ie);
2090 if (elems.hs20 && elems.hs20_len > 4) {
2091 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
2092 elems.hs20_len - 4);
2093 } else
2094 sta->hs20_ie = NULL;
2095#endif /* CONFIG_HS20 */
2096
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002097#ifdef CONFIG_FST
2098 wpabuf_free(sta->mb_ies);
2099 if (hapd->iface->fst)
2100 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
2101 else
2102 sta->mb_ies = NULL;
2103#endif /* CONFIG_FST */
2104
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002105#ifdef CONFIG_MBO
2106 mbo_ap_check_sta_assoc(hapd, sta, &elems);
2107
2108 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
2109 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
2110 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
2111 wpa_printf(MSG_INFO,
2112 "MBO: Reject WPA2 association without PMF");
2113 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2114 }
2115#endif /* CONFIG_MBO */
2116
Dmitry Shmidt9c175262016-03-03 10:20:07 -08002117 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
2118 elems.supp_op_classes_len);
2119
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002120 if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) &&
2121 elems.rrm_enabled &&
2122 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
2123 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
2124 sizeof(sta->rrm_enabled_capa));
2125
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126 return WLAN_STATUS_SUCCESS;
2127}
2128
2129
2130static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
2131 u16 reason_code)
2132{
2133 int send_len;
2134 struct ieee80211_mgmt reply;
2135
2136 os_memset(&reply, 0, sizeof(reply));
2137 reply.frame_control =
2138 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
2139 os_memcpy(reply.da, addr, ETH_ALEN);
2140 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
2141 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
2142
2143 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
2144 reply.u.deauth.reason_code = host_to_le16(reason_code);
2145
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002146 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002147 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
2148 strerror(errno));
2149}
2150
2151
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002152static int add_associated_sta(struct hostapd_data *hapd,
2153 struct sta_info *sta)
2154{
2155 struct ieee80211_ht_capabilities ht_cap;
2156 struct ieee80211_vht_capabilities vht_cap;
2157
2158 /*
2159 * Remove the STA entry to ensure the STA PS state gets cleared and
2160 * configuration gets updated. This is relevant for cases, such as
2161 * FT-over-the-DS, where a station re-associates back to the same AP but
2162 * skips the authentication flow, or if working with a driver that
2163 * does not support full AP client state.
2164 */
2165 if (!sta->added_unassoc)
2166 hostapd_drv_sta_remove(hapd, sta->addr);
2167
2168#ifdef CONFIG_IEEE80211N
2169 if (sta->flags & WLAN_STA_HT)
2170 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
2171#endif /* CONFIG_IEEE80211N */
2172#ifdef CONFIG_IEEE80211AC
2173 if (sta->flags & WLAN_STA_VHT)
2174 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
2175#endif /* CONFIG_IEEE80211AC */
2176
2177 /*
2178 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
2179 * will be set when the ACK frame for the (Re)Association Response frame
2180 * is processed (TX status driver event).
2181 */
2182 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
2183 sta->supported_rates, sta->supported_rates_len,
2184 sta->listen_interval,
2185 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
2186 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
2187 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002188 sta->vht_opmode, sta->p2p_ie ? 1 : 0,
2189 sta->added_unassoc)) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002190 hostapd_logger(hapd, sta->addr,
2191 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
2192 "Could not %s STA to kernel driver",
2193 sta->added_unassoc ? "set" : "add");
2194
2195 if (sta->added_unassoc) {
2196 hostapd_drv_sta_remove(hapd, sta->addr);
2197 sta->added_unassoc = 0;
2198 }
2199
2200 return -1;
2201 }
2202
2203 sta->added_unassoc = 0;
2204
2205 return 0;
2206}
2207
2208
2209static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
2210 u16 status_code, int reassoc, const u8 *ies,
2211 size_t ies_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002212{
2213 int send_len;
2214 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
2215 struct ieee80211_mgmt *reply;
2216 u8 *p;
2217
2218 os_memset(buf, 0, sizeof(buf));
2219 reply = (struct ieee80211_mgmt *) buf;
2220 reply->frame_control =
2221 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2222 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
2223 WLAN_FC_STYPE_ASSOC_RESP));
2224 os_memcpy(reply->da, sta->addr, ETH_ALEN);
2225 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
2226 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
2227
2228 send_len = IEEE80211_HDRLEN;
2229 send_len += sizeof(reply->u.assoc_resp);
2230 reply->u.assoc_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002231 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002232 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08002233 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234 /* Supported rates */
2235 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
2236 /* Extended supported rates */
2237 p = hostapd_eid_ext_supp_rates(hapd, p);
2238
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002239#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002240 if (status_code == WLAN_STATUS_SUCCESS) {
2241 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
2242 * Transition Information, RSN, [RIC Response] */
2243 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
2244 buf + sizeof(buf) - p,
2245 sta->auth_alg, ies, ies_len);
2246 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002247#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002248
2249#ifdef CONFIG_IEEE80211W
2250 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
2251 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
2252#endif /* CONFIG_IEEE80211W */
2253
2254#ifdef CONFIG_IEEE80211N
2255 p = hostapd_eid_ht_capabilities(hapd, p);
2256 p = hostapd_eid_ht_operation(hapd, p);
2257#endif /* CONFIG_IEEE80211N */
2258
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002259#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002260 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07002261 u32 nsts = 0, sta_nsts;
2262
2263 if (hapd->conf->use_sta_nsts && sta->vht_capabilities) {
2264 struct ieee80211_vht_capabilities *capa;
2265
2266 nsts = (hapd->iface->conf->vht_capab >>
2267 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
2268 capa = sta->vht_capabilities;
2269 sta_nsts = (le_to_host32(capa->vht_capabilities_info) >>
2270 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
2271
2272 if (nsts < sta_nsts)
2273 nsts = 0;
2274 else
2275 nsts = sta_nsts;
2276 }
2277 p = hostapd_eid_vht_capabilities(hapd, p, nsts);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002278 p = hostapd_eid_vht_operation(hapd, p);
2279 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002280#endif /* CONFIG_IEEE80211AC */
2281
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002282 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002283 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002284 if (sta->qos_map_enabled)
2285 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002286
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002287#ifdef CONFIG_FST
2288 if (hapd->iface->fst_ies) {
2289 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
2290 wpabuf_len(hapd->iface->fst_ies));
2291 p += wpabuf_len(hapd->iface->fst_ies);
2292 }
2293#endif /* CONFIG_FST */
2294
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002295#ifdef CONFIG_IEEE80211AC
2296 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
2297 p = hostapd_eid_vendor_vht(hapd, p);
2298#endif /* CONFIG_IEEE80211AC */
2299
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002300 if (sta->flags & WLAN_STA_WMM)
2301 p = hostapd_eid_wmm(hapd, p);
2302
2303#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002304 if ((sta->flags & WLAN_STA_WPS) ||
2305 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 struct wpabuf *wps = wps_build_assoc_resp_ie();
2307 if (wps) {
2308 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
2309 p += wpabuf_len(wps);
2310 wpabuf_free(wps);
2311 }
2312 }
2313#endif /* CONFIG_WPS */
2314
2315#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08002316 if (sta->p2p_ie && hapd->p2p_group) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002317 struct wpabuf *p2p_resp_ie;
2318 enum p2p_status_code status;
2319 switch (status_code) {
2320 case WLAN_STATUS_SUCCESS:
2321 status = P2P_SC_SUCCESS;
2322 break;
2323 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
2324 status = P2P_SC_FAIL_LIMIT_REACHED;
2325 break;
2326 default:
2327 status = P2P_SC_FAIL_INVALID_PARAMS;
2328 break;
2329 }
2330 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
2331 if (p2p_resp_ie) {
2332 os_memcpy(p, wpabuf_head(p2p_resp_ie),
2333 wpabuf_len(p2p_resp_ie));
2334 p += wpabuf_len(p2p_resp_ie);
2335 wpabuf_free(p2p_resp_ie);
2336 }
2337 }
2338#endif /* CONFIG_P2P */
2339
2340#ifdef CONFIG_P2P_MANAGER
2341 if (hapd->conf->p2p & P2P_MANAGE)
2342 p = hostapd_eid_p2p_manage(hapd, p);
2343#endif /* CONFIG_P2P_MANAGER */
2344
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002345 p = hostapd_eid_mbo(hapd, p, buf + sizeof(buf) - p);
2346
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002347 if (hapd->conf->assocresp_elements &&
2348 (size_t) (buf + sizeof(buf) - p) >=
2349 wpabuf_len(hapd->conf->assocresp_elements)) {
2350 os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements),
2351 wpabuf_len(hapd->conf->assocresp_elements));
2352 p += wpabuf_len(hapd->conf->assocresp_elements);
2353 }
2354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002355 send_len += p - reply->u.assoc_resp.variable;
2356
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002357#ifdef CONFIG_FILS
2358 if ((sta->auth_alg == WLAN_AUTH_FILS_SK ||
2359 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
2360 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
2361 status_code == WLAN_STATUS_SUCCESS) {
2362 struct ieee802_11_elems elems;
2363
2364 if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
2365 ParseFailed || !elems.fils_session)
2366 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2367
2368 /* FILS Session */
2369 *p++ = WLAN_EID_EXTENSION; /* Element ID */
2370 *p++ = 1 + FILS_SESSION_LEN; /* Length */
2371 *p++ = WLAN_EID_EXT_FILS_SESSION; /* Element ID Extension */
2372 os_memcpy(p, elems.fils_session, FILS_SESSION_LEN);
2373 send_len += 2 + 1 + FILS_SESSION_LEN;
2374
2375 send_len = fils_encrypt_assoc(sta->wpa_sm, buf, send_len,
2376 sizeof(buf));
2377 if (send_len < 0)
2378 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2379 }
2380#endif /* CONFIG_FILS */
2381
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002382 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002383 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
2384 strerror(errno));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002385 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2386 }
2387
2388 return WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002389}
2390
2391
2392static void handle_assoc(struct hostapd_data *hapd,
2393 const struct ieee80211_mgmt *mgmt, size_t len,
2394 int reassoc)
2395{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002396 u16 capab_info, listen_interval, seq_ctrl, fc;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002397 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002398 const u8 *pos;
2399 int left, i;
2400 struct sta_info *sta;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002401 u8 *tmp = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002402
2403 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
2404 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002405 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
2406 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002407 return;
2408 }
2409
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002410#ifdef CONFIG_TESTING_OPTIONS
2411 if (reassoc) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002412 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002413 drand48() < hapd->iconf->ignore_reassoc_probability) {
2414 wpa_printf(MSG_INFO,
2415 "TESTING: ignoring reassoc request from "
2416 MACSTR, MAC2STR(mgmt->sa));
2417 return;
2418 }
2419 } else {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002420 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002421 drand48() < hapd->iconf->ignore_assoc_probability) {
2422 wpa_printf(MSG_INFO,
2423 "TESTING: ignoring assoc request from "
2424 MACSTR, MAC2STR(mgmt->sa));
2425 return;
2426 }
2427 }
2428#endif /* CONFIG_TESTING_OPTIONS */
2429
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002430 fc = le_to_host16(mgmt->frame_control);
2431 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2432
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002433 if (reassoc) {
2434 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
2435 listen_interval = le_to_host16(
2436 mgmt->u.reassoc_req.listen_interval);
2437 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
2438 " capab_info=0x%02x listen_interval=%d current_ap="
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002439 MACSTR " seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002440 MAC2STR(mgmt->sa), capab_info, listen_interval,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002441 MAC2STR(mgmt->u.reassoc_req.current_ap),
2442 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002443 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
2444 pos = mgmt->u.reassoc_req.variable;
2445 } else {
2446 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
2447 listen_interval = le_to_host16(
2448 mgmt->u.assoc_req.listen_interval);
2449 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002450 " capab_info=0x%02x listen_interval=%d "
2451 "seq_ctrl=0x%x%s",
2452 MAC2STR(mgmt->sa), capab_info, listen_interval,
2453 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002454 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
2455 pos = mgmt->u.assoc_req.variable;
2456 }
2457
2458 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002459#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002460 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
2461 (sta->flags & WLAN_STA_AUTH) == 0) {
2462 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
2463 "prior to authentication since it is using "
2464 "over-the-DS FT", MAC2STR(mgmt->sa));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002465
2466 /*
2467 * Mark station as authenticated, to avoid adding station
2468 * entry in the driver as associated and not authenticated
2469 */
2470 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002471 } else
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002472#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002473 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
2474 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2475 HOSTAPD_LEVEL_INFO, "Station tried to "
2476 "associate before authentication "
2477 "(aid=%d flags=0x%x)",
2478 sta ? sta->aid : -1,
2479 sta ? sta->flags : 0);
2480 send_deauth(hapd, mgmt->sa,
2481 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
2482 return;
2483 }
2484
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002485 if ((fc & WLAN_FC_RETRY) &&
2486 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2487 sta->last_seq_ctrl == seq_ctrl &&
2488 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2489 WLAN_FC_STYPE_ASSOC_REQ) {
2490 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2491 HOSTAPD_LEVEL_DEBUG,
2492 "Drop repeated association frame seq_ctrl=0x%x",
2493 seq_ctrl);
2494 return;
2495 }
2496 sta->last_seq_ctrl = seq_ctrl;
2497 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2498 WLAN_FC_STYPE_ASSOC_REQ;
2499
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002500 if (hapd->tkip_countermeasures) {
2501 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
2502 goto fail;
2503 }
2504
2505 if (listen_interval > hapd->conf->max_listen_interval) {
2506 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2507 HOSTAPD_LEVEL_DEBUG,
2508 "Too large Listen Interval (%d)",
2509 listen_interval);
2510 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
2511 goto fail;
2512 }
2513
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002514#ifdef CONFIG_MBO
2515 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
2516 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2517 goto fail;
2518 }
2519#endif /* CONFIG_MBO */
2520
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002521 /*
2522 * sta->capability is used in check_assoc_ies() for RRM enabled
2523 * capability element.
2524 */
2525 sta->capability = capab_info;
2526
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002527#ifdef CONFIG_FILS
2528 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
2529 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
2530 sta->auth_alg == WLAN_AUTH_FILS_PK) {
2531 /* The end of the payload is encrypted. Need to decrypt it
2532 * before parsing. */
2533
2534 tmp = os_malloc(left);
2535 if (!tmp) {
2536 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2537 goto fail;
2538 }
2539 os_memcpy(tmp, pos, left);
2540
2541 left = fils_decrypt_assoc(sta->wpa_sm, sta->fils_session, mgmt,
2542 len, tmp, left);
2543 if (left < 0) {
2544 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2545 goto fail;
2546 }
2547 pos = tmp;
2548 }
2549#endif /* CONFIG_FILS */
2550
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002551 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
2552 * is used */
2553 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
2554 if (resp != WLAN_STATUS_SUCCESS)
2555 goto fail;
2556
2557 if (hostapd_get_aid(hapd, sta) < 0) {
2558 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2559 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
2560 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2561 goto fail;
2562 }
2563
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002564 sta->listen_interval = listen_interval;
2565
2566 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
2567 sta->flags |= WLAN_STA_NONERP;
2568 for (i = 0; i < sta->supported_rates_len; i++) {
2569 if ((sta->supported_rates[i] & 0x7f) > 22) {
2570 sta->flags &= ~WLAN_STA_NONERP;
2571 break;
2572 }
2573 }
2574 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
2575 sta->nonerp_set = 1;
2576 hapd->iface->num_sta_non_erp++;
2577 if (hapd->iface->num_sta_non_erp == 1)
2578 ieee802_11_set_beacons(hapd->iface);
2579 }
2580
2581 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
2582 !sta->no_short_slot_time_set) {
2583 sta->no_short_slot_time_set = 1;
2584 hapd->iface->num_sta_no_short_slot_time++;
2585 if (hapd->iface->current_mode->mode ==
2586 HOSTAPD_MODE_IEEE80211G &&
2587 hapd->iface->num_sta_no_short_slot_time == 1)
2588 ieee802_11_set_beacons(hapd->iface);
2589 }
2590
2591 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2592 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
2593 else
2594 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
2595
2596 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
2597 !sta->no_short_preamble_set) {
2598 sta->no_short_preamble_set = 1;
2599 hapd->iface->num_sta_no_short_preamble++;
2600 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
2601 && hapd->iface->num_sta_no_short_preamble == 1)
2602 ieee802_11_set_beacons(hapd->iface);
2603 }
2604
2605#ifdef CONFIG_IEEE80211N
2606 update_ht_state(hapd, sta);
2607#endif /* CONFIG_IEEE80211N */
2608
2609 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2610 HOSTAPD_LEVEL_DEBUG,
2611 "association OK (aid %d)", sta->aid);
2612 /* Station will be marked associated, after it acknowledges AssocResp
2613 */
2614 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
2615
2616#ifdef CONFIG_IEEE80211W
2617 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
2618 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
2619 "SA Query procedure", reassoc ? "re" : "");
2620 /* TODO: Send a protected Disassociate frame to the STA using
2621 * the old key and Reason Code "Previous Authentication no
2622 * longer valid". Make sure this is only sent protected since
2623 * unprotected frame would be received by the STA that is now
2624 * trying to associate.
2625 */
2626 }
2627#endif /* CONFIG_IEEE80211W */
2628
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002629 /* Make sure that the previously registered inactivity timer will not
2630 * remove the STA immediately. */
2631 sta->timeout_next = STA_NULLFUNC;
2632
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002633#ifdef CONFIG_TAXONOMY
2634 taxonomy_sta_info_assoc_req(hapd, sta, pos, left);
2635#endif /* CONFIG_TAXONOMY */
2636
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002637 fail:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002638 /*
2639 * In case of a successful response, add the station to the driver.
2640 * Otherwise, the kernel may ignore Data frames before we process the
2641 * ACK frame (TX status). In case of a failure, this station will be
2642 * removed.
2643 *
2644 * Note that this is not compliant with the IEEE 802.11 standard that
2645 * states that a non-AP station should transition into the
2646 * authenticated/associated state only after the station acknowledges
2647 * the (Re)Association Response frame. However, still do this as:
2648 *
2649 * 1. In case the station does not acknowledge the (Re)Association
2650 * Response frame, it will be removed.
2651 * 2. Data frames will be dropped in the kernel until the station is
2652 * set into authorized state, and there are no significant known
2653 * issues with processing other non-Data Class 3 frames during this
2654 * window.
2655 */
2656 if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta))
2657 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2658
2659 reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002660 os_free(tmp);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002661
2662 /*
2663 * Remove the station in case tranmission of a success response fails
2664 * (the STA was added associated to the driver) or if the station was
2665 * previously added unassociated.
2666 */
2667 if ((reply_res != WLAN_STATUS_SUCCESS &&
2668 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) {
2669 hostapd_drv_sta_remove(hapd, sta->addr);
2670 sta->added_unassoc = 0;
2671 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002672}
2673
2674
2675static void handle_disassoc(struct hostapd_data *hapd,
2676 const struct ieee80211_mgmt *mgmt, size_t len)
2677{
2678 struct sta_info *sta;
2679
2680 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002681 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
2682 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002683 return;
2684 }
2685
2686 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
2687 MAC2STR(mgmt->sa),
2688 le_to_host16(mgmt->u.disassoc.reason_code));
2689
2690 sta = ap_get_sta(hapd, mgmt->sa);
2691 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002692 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2693 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002694 return;
2695 }
2696
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002697 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002698 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002700 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2701 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2702 HOSTAPD_LEVEL_INFO, "disassociated");
2703 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2704 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2705 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2706 * authenticated. */
2707 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -08002708 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002709 if (sta->ipaddr)
2710 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2711 ap_sta_ip6addr_del(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002712 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002713 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002714
2715 if (sta->timeout_next == STA_NULLFUNC ||
2716 sta->timeout_next == STA_DISASSOC) {
2717 sta->timeout_next = STA_DEAUTH;
2718 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2719 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2720 hapd, sta);
2721 }
2722
2723 mlme_disassociate_indication(
2724 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2725}
2726
2727
2728static void handle_deauth(struct hostapd_data *hapd,
2729 const struct ieee80211_mgmt *mgmt, size_t len)
2730{
2731 struct sta_info *sta;
2732
2733 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002734 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2735 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002736 return;
2737 }
2738
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002739 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002740 " reason_code=%d",
2741 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2742
2743 sta = ap_get_sta(hapd, mgmt->sa);
2744 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002745 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2746 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002747 MAC2STR(mgmt->sa));
2748 return;
2749 }
2750
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002751 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002752 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002753 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2754 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002755 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2756 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2757 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2758 mlme_deauthenticate_indication(
2759 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2760 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2761 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2762 ap_free_sta(hapd, sta);
2763}
2764
2765
2766static void handle_beacon(struct hostapd_data *hapd,
2767 const struct ieee80211_mgmt *mgmt, size_t len,
2768 struct hostapd_frame_info *fi)
2769{
2770 struct ieee802_11_elems elems;
2771
2772 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002773 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2774 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002775 return;
2776 }
2777
2778 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2779 len - (IEEE80211_HDRLEN +
2780 sizeof(mgmt->u.beacon)), &elems,
2781 0);
2782
2783 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2784}
2785
2786
2787#ifdef CONFIG_IEEE80211W
2788
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002789static int hostapd_sa_query_action(struct hostapd_data *hapd,
2790 const struct ieee80211_mgmt *mgmt,
2791 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002792{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002793 const u8 *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002794
2795 end = mgmt->u.action.u.sa_query_resp.trans_id +
2796 WLAN_SA_QUERY_TR_ID_LEN;
2797 if (((u8 *) mgmt) + len < end) {
2798 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2799 "frame (len=%lu)", (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002800 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002801 }
2802
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002803 ieee802_11_sa_query_action(hapd, mgmt->sa,
2804 mgmt->u.action.u.sa_query_resp.action,
2805 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002806 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002807}
2808
2809
2810static int robust_action_frame(u8 category)
2811{
2812 return category != WLAN_ACTION_PUBLIC &&
2813 category != WLAN_ACTION_HT;
2814}
2815#endif /* CONFIG_IEEE80211W */
2816
2817
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002818static int handle_action(struct hostapd_data *hapd,
2819 const struct ieee80211_mgmt *mgmt, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002820{
2821 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002822 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002823
2824 if (len < IEEE80211_HDRLEN + 1) {
2825 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2826 HOSTAPD_LEVEL_DEBUG,
2827 "handle_action - too short payload (len=%lu)",
2828 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002829 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002830 }
2831
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002832 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2833 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2834 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2835 "frame (category=%u) from unassociated STA " MACSTR,
2836 MAC2STR(mgmt->sa), mgmt->u.action.category);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002837 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002838 }
2839
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002840#ifdef CONFIG_IEEE80211W
2841 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08002842 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2843 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002844 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2845 HOSTAPD_LEVEL_DEBUG,
2846 "Dropped unprotected Robust Action frame from "
2847 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002848 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002849 }
2850#endif /* CONFIG_IEEE80211W */
2851
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002852 if (sta) {
2853 u16 fc = le_to_host16(mgmt->frame_control);
2854 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2855
2856 if ((fc & WLAN_FC_RETRY) &&
2857 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2858 sta->last_seq_ctrl == seq_ctrl &&
2859 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2860 hostapd_logger(hapd, sta->addr,
2861 HOSTAPD_MODULE_IEEE80211,
2862 HOSTAPD_LEVEL_DEBUG,
2863 "Drop repeated action frame seq_ctrl=0x%x",
2864 seq_ctrl);
2865 return 1;
2866 }
2867
2868 sta->last_seq_ctrl = seq_ctrl;
2869 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2870 }
2871
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002872 switch (mgmt->u.action.category) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002873#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002874 case WLAN_ACTION_FT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002875 if (!sta ||
2876 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002877 len - IEEE80211_HDRLEN))
2878 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002879 return 1;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002880#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002881 case WLAN_ACTION_WMM:
2882 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002883 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002884#ifdef CONFIG_IEEE80211W
2885 case WLAN_ACTION_SA_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002886 return hostapd_sa_query_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002887#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002888#ifdef CONFIG_WNM
2889 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002890 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2891 return 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002892#endif /* CONFIG_WNM */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002893#ifdef CONFIG_FST
2894 case WLAN_ACTION_FST:
2895 if (hapd->iface->fst)
2896 fst_rx_action(hapd->iface->fst, mgmt, len);
2897 else
2898 wpa_printf(MSG_DEBUG,
2899 "FST: Ignore FST Action frame - no FST attached");
2900 return 1;
2901#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002902 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08002903 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002904#ifdef CONFIG_IEEE80211N
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07002905 if (len >= IEEE80211_HDRLEN + 2 &&
2906 mgmt->u.action.u.public_action.action ==
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002907 WLAN_PA_20_40_BSS_COEX) {
2908 wpa_printf(MSG_DEBUG,
2909 "HT20/40 coex mgmt frame received from STA "
2910 MACSTR, MAC2STR(mgmt->sa));
2911 hostapd_2040_coex_action(hapd, mgmt, len);
2912 }
2913#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002914 if (hapd->public_action_cb) {
2915 hapd->public_action_cb(hapd->public_action_cb_ctx,
2916 (u8 *) mgmt, len,
2917 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002918 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002919 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002920 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002921 (u8 *) mgmt, len,
2922 hapd->iface->freq);
2923 }
2924 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002925 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002926 break;
2927 case WLAN_ACTION_VENDOR_SPECIFIC:
2928 if (hapd->vendor_action_cb) {
2929 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2930 (u8 *) mgmt, len,
2931 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002932 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002933 }
2934 break;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002935 case WLAN_ACTION_RADIO_MEASUREMENT:
2936 hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len);
2937 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002938 }
2939
2940 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2941 HOSTAPD_LEVEL_DEBUG,
2942 "handle_action - unknown action category %d or invalid "
2943 "frame",
2944 mgmt->u.action.category);
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07002945 if (!is_multicast_ether_addr(mgmt->da) &&
2946 !(mgmt->u.action.category & 0x80) &&
2947 !is_multicast_ether_addr(mgmt->sa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002948 struct ieee80211_mgmt *resp;
2949
2950 /*
2951 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2952 * Return the Action frame to the source without change
2953 * except that MSB of the Category set to 1.
2954 */
2955 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2956 "frame back to sender");
2957 resp = os_malloc(len);
2958 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002959 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002960 os_memcpy(resp, mgmt, len);
2961 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2962 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2963 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2964 resp->u.action.category |= 0x80;
2965
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002966 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2967 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2968 "Action frame");
2969 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002970 os_free(resp);
2971 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002972
2973 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002974}
2975
2976
2977/**
2978 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2979 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2980 * sent to)
2981 * @buf: management frame data (starting from IEEE 802.11 header)
2982 * @len: length of frame data in octets
2983 * @fi: meta data about received frame (signal level, etc.)
2984 *
2985 * Process all incoming IEEE 802.11 management frames. This will be called for
2986 * each frame received from the kernel driver through wlan#ap interface. In
2987 * addition, it can be called to re-inserted pending frames (e.g., when using
2988 * external RADIUS server as an MAC ACL).
2989 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002990int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2991 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002992{
2993 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002994 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002995 int ret = 0;
2996
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002997 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002998 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002999
3000 mgmt = (struct ieee80211_mgmt *) buf;
3001 fc = le_to_host16(mgmt->frame_control);
3002 stype = WLAN_FC_GET_STYPE(fc);
3003
3004 if (stype == WLAN_FC_STYPE_BEACON) {
3005 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003006 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003007 }
3008
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07003009 if (!is_broadcast_ether_addr(mgmt->bssid) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003010#ifdef CONFIG_P2P
3011 /* Invitation responses can be sent with the peer MAC as BSSID */
3012 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
3013 stype == WLAN_FC_STYPE_ACTION) &&
3014#endif /* CONFIG_P2P */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003015#ifdef CONFIG_MESH
3016 !(hapd->conf->mesh & MESH_ENABLED) &&
3017#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003018 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003019 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
3020 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003021 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003022 }
3023
3024
3025 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003026 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003027 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003028 }
3029
3030 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
3031 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3032 HOSTAPD_LEVEL_DEBUG,
3033 "MGMT: DA=" MACSTR " not our address",
3034 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003035 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003036 }
3037
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003038 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003039 sta_track_add(hapd->iface, mgmt->sa, fi->ssi_signal);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003040
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003041 switch (stype) {
3042 case WLAN_FC_STYPE_AUTH:
3043 wpa_printf(MSG_DEBUG, "mgmt::auth");
3044 handle_auth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003045 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003046 break;
3047 case WLAN_FC_STYPE_ASSOC_REQ:
3048 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
3049 handle_assoc(hapd, mgmt, len, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003050 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003051 break;
3052 case WLAN_FC_STYPE_REASSOC_REQ:
3053 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
3054 handle_assoc(hapd, mgmt, len, 1);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003055 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003056 break;
3057 case WLAN_FC_STYPE_DISASSOC:
3058 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
3059 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003060 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003061 break;
3062 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003063 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003064 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003065 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003066 break;
3067 case WLAN_FC_STYPE_ACTION:
3068 wpa_printf(MSG_DEBUG, "mgmt::action");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003069 ret = handle_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003070 break;
3071 default:
3072 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3073 HOSTAPD_LEVEL_DEBUG,
3074 "unknown mgmt frame subtype %d", stype);
3075 break;
3076 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003077
3078 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003079}
3080
3081
3082static void handle_auth_cb(struct hostapd_data *hapd,
3083 const struct ieee80211_mgmt *mgmt,
3084 size_t len, int ok)
3085{
3086 u16 auth_alg, auth_transaction, status_code;
3087 struct sta_info *sta;
3088
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003089 sta = ap_get_sta(hapd, mgmt->da);
3090 if (!sta) {
3091 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
3092 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003093 return;
3094 }
3095
3096 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3097 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
3098 status_code = le_to_host16(mgmt->u.auth.status_code);
3099
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003100 if (!ok) {
3101 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
3102 HOSTAPD_LEVEL_NOTICE,
3103 "did not acknowledge authentication response");
3104 goto fail;
3105 }
3106
3107 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
3108 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
3109 (unsigned long) len);
3110 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003111 }
3112
3113 if (status_code == WLAN_STATUS_SUCCESS &&
3114 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
3115 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
3116 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3117 HOSTAPD_LEVEL_INFO, "authenticated");
3118 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003119 if (sta->added_unassoc)
3120 hostapd_set_sta_flags(hapd, sta);
3121 return;
3122 }
3123
3124fail:
3125 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
3126 hostapd_drv_sta_remove(hapd, sta->addr);
3127 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003128 }
3129}
3130
3131
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003132static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
3133 struct sta_info *sta,
3134 char *ifname_wds)
3135{
3136 int i;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07003137 struct hostapd_ssid *ssid = &hapd->conf->ssid;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003138
3139 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
3140 return;
3141
3142 for (i = 0; i < 4; i++) {
3143 if (ssid->wep.key[i] &&
3144 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
3145 i == ssid->wep.idx, NULL, 0,
3146 ssid->wep.key[i], ssid->wep.len[i])) {
3147 wpa_printf(MSG_WARNING,
3148 "Could not set WEP keys for WDS interface; %s",
3149 ifname_wds);
3150 break;
3151 }
3152 }
3153}
3154
3155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003156static void handle_assoc_cb(struct hostapd_data *hapd,
3157 const struct ieee80211_mgmt *mgmt,
3158 size_t len, int reassoc, int ok)
3159{
3160 u16 status;
3161 struct sta_info *sta;
3162 int new_assoc = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003163
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003164 sta = ap_get_sta(hapd, mgmt->da);
3165 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003166 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
3167 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003168 return;
3169 }
3170
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003171 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
3172 sizeof(mgmt->u.assoc_resp))) {
3173 wpa_printf(MSG_INFO,
3174 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
3175 reassoc, (unsigned long) len);
3176 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07003177 return;
3178 }
3179
3180 if (reassoc)
3181 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
3182 else
3183 status = le_to_host16(mgmt->u.assoc_resp.status_code);
3184
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003185 if (!ok) {
3186 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
3187 HOSTAPD_LEVEL_DEBUG,
3188 "did not acknowledge association response");
3189 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
3190 /* The STA is added only in case of SUCCESS */
3191 if (status == WLAN_STATUS_SUCCESS)
3192 hostapd_drv_sta_remove(hapd, sta->addr);
3193
3194 return;
3195 }
3196
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003197 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003198 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003199
3200 /* Stop previous accounting session, if one is started, and allocate
3201 * new session id for the new session. */
3202 accounting_sta_stop(hapd, sta);
3203
3204 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3205 HOSTAPD_LEVEL_INFO,
3206 "associated (aid %d)",
3207 sta->aid);
3208
3209 if (sta->flags & WLAN_STA_ASSOC)
3210 new_assoc = 0;
3211 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003212 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003213 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
3214 !hapd->conf->osen) ||
3215 sta->auth_alg == WLAN_AUTH_FILS_SK ||
3216 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3217 sta->auth_alg == WLAN_AUTH_FILS_PK ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003218 sta->auth_alg == WLAN_AUTH_FT) {
3219 /*
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003220 * Open, static WEP, FT protocol, or FILS; no separate
3221 * authorization step.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003222 */
3223 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003224 }
3225
3226 if (reassoc)
3227 mlme_reassociate_indication(hapd, sta);
3228 else
3229 mlme_associate_indication(hapd, sta);
3230
3231#ifdef CONFIG_IEEE80211W
3232 sta->sa_query_timed_out = 0;
3233#endif /* CONFIG_IEEE80211W */
3234
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003235 if (sta->eapol_sm == NULL) {
3236 /*
3237 * This STA does not use RADIUS server for EAP authentication,
3238 * so bind it to the selected VLAN interface now, since the
3239 * interface selection is not going to change anymore.
3240 */
Dmitry Shmidt83474442015-04-15 13:47:09 -07003241 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003242 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003243 } else if (sta->vlan_id) {
3244 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
Dmitry Shmidt83474442015-04-15 13:47:09 -07003245 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003246 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003247 }
3248
3249 hostapd_set_sta_flags(hapd, sta);
3250
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003251 if (sta->flags & WLAN_STA_WDS) {
3252 int ret;
3253 char ifname_wds[IFNAMSIZ + 1];
3254
3255 wpa_printf(MSG_DEBUG, "Reenable 4-address WDS mode for STA "
3256 MACSTR " (aid %u)",
3257 MAC2STR(sta->addr), sta->aid);
3258 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
3259 sta->aid, 1);
3260 if (!ret)
3261 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
3262 }
3263
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003264 if (sta->auth_alg == WLAN_AUTH_FT)
3265 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
3266 else
3267 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
3268 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003269 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003270
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003271#ifdef CONFIG_FILS
3272 if ((sta->auth_alg == WLAN_AUTH_FILS_SK ||
3273 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3274 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
3275 fils_set_tk(sta->wpa_sm) < 0) {
3276 wpa_printf(MSG_DEBUG, "FILS: TK configuration failed");
3277 ap_sta_disconnect(hapd, sta, sta->addr,
3278 WLAN_REASON_UNSPECIFIED);
3279 return;
3280 }
3281#endif /* CONFIG_FILS */
3282
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003283 if (sta->pending_eapol_rx) {
3284 struct os_reltime now, age;
3285
3286 os_get_reltime(&now);
3287 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
3288 if (age.sec == 0 && age.usec < 200000) {
3289 wpa_printf(MSG_DEBUG,
3290 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
3291 MAC2STR(sta->addr));
3292 ieee802_1x_receive(
3293 hapd, mgmt->da,
3294 wpabuf_head(sta->pending_eapol_rx->buf),
3295 wpabuf_len(sta->pending_eapol_rx->buf));
3296 }
3297 wpabuf_free(sta->pending_eapol_rx->buf);
3298 os_free(sta->pending_eapol_rx);
3299 sta->pending_eapol_rx = NULL;
3300 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003301}
3302
3303
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003304static void handle_deauth_cb(struct hostapd_data *hapd,
3305 const struct ieee80211_mgmt *mgmt,
3306 size_t len, int ok)
3307{
3308 struct sta_info *sta;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003309 if (is_multicast_ether_addr(mgmt->da))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003310 return;
3311 sta = ap_get_sta(hapd, mgmt->da);
3312 if (!sta) {
3313 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
3314 " not found", MAC2STR(mgmt->da));
3315 return;
3316 }
3317 if (ok)
3318 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
3319 MAC2STR(sta->addr));
3320 else
3321 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
3322 "deauth", MAC2STR(sta->addr));
3323
3324 ap_sta_deauth_cb(hapd, sta);
3325}
3326
3327
3328static void handle_disassoc_cb(struct hostapd_data *hapd,
3329 const struct ieee80211_mgmt *mgmt,
3330 size_t len, int ok)
3331{
3332 struct sta_info *sta;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003333 if (is_multicast_ether_addr(mgmt->da))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003334 return;
3335 sta = ap_get_sta(hapd, mgmt->da);
3336 if (!sta) {
3337 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
3338 " not found", MAC2STR(mgmt->da));
3339 return;
3340 }
3341 if (ok)
3342 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
3343 MAC2STR(sta->addr));
3344 else
3345 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
3346 "disassoc", MAC2STR(sta->addr));
3347
3348 ap_sta_disassoc_cb(hapd, sta);
3349}
3350
3351
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003352/**
3353 * ieee802_11_mgmt_cb - Process management frame TX status callback
3354 * @hapd: hostapd BSS data structure (the BSS from which the management frame
3355 * was sent from)
3356 * @buf: management frame data (starting from IEEE 802.11 header)
3357 * @len: length of frame data in octets
3358 * @stype: management frame subtype from frame control field
3359 * @ok: Whether the frame was ACK'ed
3360 */
3361void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
3362 u16 stype, int ok)
3363{
3364 const struct ieee80211_mgmt *mgmt;
3365 mgmt = (const struct ieee80211_mgmt *) buf;
3366
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003367#ifdef CONFIG_TESTING_OPTIONS
3368 if (hapd->ext_mgmt_frame_handling) {
3369 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
3370 stype, ok);
3371 return;
3372 }
3373#endif /* CONFIG_TESTING_OPTIONS */
3374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003375 switch (stype) {
3376 case WLAN_FC_STYPE_AUTH:
3377 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
3378 handle_auth_cb(hapd, mgmt, len, ok);
3379 break;
3380 case WLAN_FC_STYPE_ASSOC_RESP:
3381 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
3382 handle_assoc_cb(hapd, mgmt, len, 0, ok);
3383 break;
3384 case WLAN_FC_STYPE_REASSOC_RESP:
3385 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
3386 handle_assoc_cb(hapd, mgmt, len, 1, ok);
3387 break;
3388 case WLAN_FC_STYPE_PROBE_RESP:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003389 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003390 break;
3391 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003392 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
3393 handle_deauth_cb(hapd, mgmt, len, ok);
3394 break;
3395 case WLAN_FC_STYPE_DISASSOC:
3396 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
3397 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003398 break;
3399 case WLAN_FC_STYPE_ACTION:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003400 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003401 break;
3402 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003403 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003404 break;
3405 }
3406}
3407
3408
3409int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
3410{
3411 /* TODO */
3412 return 0;
3413}
3414
3415
3416int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
3417 char *buf, size_t buflen)
3418{
3419 /* TODO */
3420 return 0;
3421}
3422
3423
3424void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
3425 const u8 *buf, size_t len, int ack)
3426{
3427 struct sta_info *sta;
3428 struct hostapd_iface *iface = hapd->iface;
3429
3430 sta = ap_get_sta(hapd, addr);
3431 if (sta == NULL && iface->num_bss > 1) {
3432 size_t j;
3433 for (j = 0; j < iface->num_bss; j++) {
3434 hapd = iface->bss[j];
3435 sta = ap_get_sta(hapd, addr);
3436 if (sta)
3437 break;
3438 }
3439 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003440 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003441 return;
3442 if (sta->flags & WLAN_STA_PENDING_POLL) {
3443 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
3444 "activity poll", MAC2STR(sta->addr),
3445 ack ? "ACKed" : "did not ACK");
3446 if (ack)
3447 sta->flags &= ~WLAN_STA_PENDING_POLL;
3448 }
3449
3450 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
3451}
3452
3453
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003454void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
3455 const u8 *data, size_t len, int ack)
3456{
3457 struct sta_info *sta;
3458 struct hostapd_iface *iface = hapd->iface;
3459
3460 sta = ap_get_sta(hapd, dst);
3461 if (sta == NULL && iface->num_bss > 1) {
3462 size_t j;
3463 for (j = 0; j < iface->num_bss; j++) {
3464 hapd = iface->bss[j];
3465 sta = ap_get_sta(hapd, dst);
3466 if (sta)
3467 break;
3468 }
3469 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003470 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
3471 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
3472 MACSTR " that is not currently associated",
3473 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003474 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003475 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003476
3477 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
3478}
3479
3480
3481void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
3482{
3483 struct sta_info *sta;
3484 struct hostapd_iface *iface = hapd->iface;
3485
3486 sta = ap_get_sta(hapd, addr);
3487 if (sta == NULL && iface->num_bss > 1) {
3488 size_t j;
3489 for (j = 0; j < iface->num_bss; j++) {
3490 hapd = iface->bss[j];
3491 sta = ap_get_sta(hapd, addr);
3492 if (sta)
3493 break;
3494 }
3495 }
3496 if (sta == NULL)
3497 return;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003498 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
3499 MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003500 if (!(sta->flags & WLAN_STA_PENDING_POLL))
3501 return;
3502
3503 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
3504 "activity poll", MAC2STR(sta->addr));
3505 sta->flags &= ~WLAN_STA_PENDING_POLL;
3506}
3507
3508
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003509void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
3510 int wds)
3511{
3512 struct sta_info *sta;
3513
3514 sta = ap_get_sta(hapd, src);
3515 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07003516 if (!hapd->conf->wds_sta)
3517 return;
3518
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003519 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003520 int ret;
3521 char ifname_wds[IFNAMSIZ + 1];
3522
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003523 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
3524 "STA " MACSTR " (aid %u)",
3525 MAC2STR(sta->addr), sta->aid);
3526 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003527 ret = hostapd_set_wds_sta(hapd, ifname_wds,
3528 sta->addr, sta->aid, 1);
3529 if (!ret)
3530 hostapd_set_wds_encryption(hapd, sta,
3531 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003532 }
3533 return;
3534 }
3535
3536 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
3537 MACSTR, MAC2STR(src));
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003538 if (is_multicast_ether_addr(src)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003539 /* Broadcast bit set in SA?! Ignore the frame silently. */
3540 return;
3541 }
3542
3543 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
3544 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
3545 "already been sent, but no TX status yet known - "
3546 "ignore Class 3 frame issue with " MACSTR,
3547 MAC2STR(src));
3548 return;
3549 }
3550
3551 if (sta && (sta->flags & WLAN_STA_AUTH))
3552 hostapd_drv_sta_disassoc(
3553 hapd, src,
3554 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3555 else
3556 hostapd_drv_sta_deauth(
3557 hapd, src,
3558 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3559}
3560
3561
3562#endif /* CONFIG_NATIVE_WINDOWS */