blob: 134ae0620f4353c02f5f0908c8fd3f5084bd765b [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 Shmidt8d520ff2011-05-09 14:06:53 -070046
47
48u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
49{
50 u8 *pos = eid;
51 int i, num, count;
52
53 if (hapd->iface->current_rates == NULL)
54 return eid;
55
56 *pos++ = WLAN_EID_SUPP_RATES;
57 num = hapd->iface->num_rates;
58 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
59 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080060 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
61 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070062 if (num > 8) {
63 /* rest of the rates are encoded in Extended supported
64 * rates element */
65 num = 8;
66 }
67
68 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
70 i++) {
71 count++;
72 *pos = hapd->iface->current_rates[i].rate / 5;
73 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
74 *pos |= 0x80;
75 pos++;
76 }
77
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080078 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
79 count++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080081 }
82
83 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
84 count++;
85 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
86 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087
88 return pos;
89}
90
91
92u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
93{
94 u8 *pos = eid;
95 int i, num, count;
96
97 if (hapd->iface->current_rates == NULL)
98 return eid;
99
100 num = hapd->iface->num_rates;
101 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
102 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800103 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
104 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105 if (num <= 8)
106 return eid;
107 num -= 8;
108
109 *pos++ = WLAN_EID_EXT_SUPP_RATES;
110 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700111 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
112 i++) {
113 count++;
114 if (count <= 8)
115 continue; /* already in SuppRates IE */
116 *pos = hapd->iface->current_rates[i].rate / 5;
117 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
118 *pos |= 0x80;
119 pos++;
120 }
121
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800122 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
123 count++;
124 if (count > 8)
125 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
126 }
127
128 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
129 count++;
130 if (count > 8)
131 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
132 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700133
134 return pos;
135}
136
137
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700138u16 hostapd_own_capab_info(struct hostapd_data *hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700139{
140 int capab = WLAN_CAPABILITY_ESS;
141 int privacy;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800142 int dfs;
143
144 /* Check if any of configured channels require DFS */
145 dfs = hostapd_is_dfs_required(hapd->iface);
146 if (dfs < 0) {
147 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
148 dfs);
149 dfs = 0;
150 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700151
152 if (hapd->iface->num_sta_no_short_preamble == 0 &&
153 hapd->iconf->preamble == SHORT_PREAMBLE)
154 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
155
156 privacy = hapd->conf->ssid.wep.keys_set;
157
158 if (hapd->conf->ieee802_1x &&
159 (hapd->conf->default_wep_key_len ||
160 hapd->conf->individual_wep_key_len))
161 privacy = 1;
162
163 if (hapd->conf->wpa)
164 privacy = 1;
165
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800166#ifdef CONFIG_HS20
167 if (hapd->conf->osen)
168 privacy = 1;
169#endif /* CONFIG_HS20 */
170
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171 if (privacy)
172 capab |= WLAN_CAPABILITY_PRIVACY;
173
174 if (hapd->iface->current_mode &&
175 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
176 hapd->iface->num_sta_no_short_slot_time == 0)
177 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
178
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800179 /*
180 * Currently, Spectrum Management capability bit is set when directly
181 * requested in configuration by spectrum_mgmt_required or when AP is
182 * running on DFS channel.
183 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
184 */
185 if (hapd->iface->current_mode &&
186 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
187 (hapd->iconf->spectrum_mgmt_required || dfs))
188 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
189
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800190 if (hapd->conf->radio_measurements)
191 capab |= IEEE80211_CAP_RRM;
192
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700193 return capab;
194}
195
196
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800197#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
199 u16 auth_transaction, const u8 *challenge,
200 int iswep)
201{
202 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
203 HOSTAPD_LEVEL_DEBUG,
204 "authentication (shared key, transaction %d)",
205 auth_transaction);
206
207 if (auth_transaction == 1) {
208 if (!sta->challenge) {
209 /* Generate a pseudo-random challenge */
210 u8 key[8];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800211
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700212 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
213 if (sta->challenge == NULL)
214 return WLAN_STATUS_UNSPECIFIED_FAILURE;
215
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800216 if (os_get_random(key, sizeof(key)) < 0) {
217 os_free(sta->challenge);
218 sta->challenge = NULL;
219 return WLAN_STATUS_UNSPECIFIED_FAILURE;
220 }
221
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 rc4_skip(key, sizeof(key), 0,
223 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
224 }
225 return 0;
226 }
227
228 if (auth_transaction != 3)
229 return WLAN_STATUS_UNSPECIFIED_FAILURE;
230
231 /* Transaction 3 */
232 if (!iswep || !sta->challenge || !challenge ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700233 os_memcmp_const(sta->challenge, challenge,
234 WLAN_AUTH_CHALLENGE_LEN)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700235 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
236 HOSTAPD_LEVEL_INFO,
237 "shared key authentication - invalid "
238 "challenge-response");
239 return WLAN_STATUS_CHALLENGE_FAIL;
240 }
241
242 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
243 HOSTAPD_LEVEL_DEBUG,
244 "authentication OK (shared key)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245 sta->flags |= WLAN_STA_AUTH;
246 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700247 os_free(sta->challenge);
248 sta->challenge = NULL;
249
250 return 0;
251}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800252#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253
254
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800255static int send_auth_reply(struct hostapd_data *hapd,
256 const u8 *dst, const u8 *bssid,
257 u16 auth_alg, u16 auth_transaction, u16 resp,
258 const u8 *ies, size_t ies_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700259{
260 struct ieee80211_mgmt *reply;
261 u8 *buf;
262 size_t rlen;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800263 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264
265 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
266 buf = os_zalloc(rlen);
267 if (buf == NULL)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800268 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269
270 reply = (struct ieee80211_mgmt *) buf;
271 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
272 WLAN_FC_STYPE_AUTH);
273 os_memcpy(reply->da, dst, ETH_ALEN);
274 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
275 os_memcpy(reply->bssid, bssid, ETH_ALEN);
276
277 reply->u.auth.auth_alg = host_to_le16(auth_alg);
278 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
279 reply->u.auth.status_code = host_to_le16(resp);
280
281 if (ies && ies_len)
282 os_memcpy(reply->u.auth.variable, ies, ies_len);
283
284 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
285 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
286 MAC2STR(dst), auth_alg, auth_transaction,
287 resp, (unsigned long) ies_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800288 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800289 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
290 else
291 reply_res = WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292
293 os_free(buf);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800294
295 return reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296}
297
298
299#ifdef CONFIG_IEEE80211R
300static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
301 u16 auth_transaction, u16 status,
302 const u8 *ies, size_t ies_len)
303{
304 struct hostapd_data *hapd = ctx;
305 struct sta_info *sta;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800306 int reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800308 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
309 auth_transaction, status, ies, ies_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310
311 sta = ap_get_sta(hapd, dst);
312 if (sta == NULL)
313 return;
314
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800315 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
316 status != WLAN_STATUS_SUCCESS)) {
317 hostapd_drv_sta_remove(hapd, sta->addr);
318 sta->added_unassoc = 0;
319 return;
320 }
321
322 if (status != WLAN_STATUS_SUCCESS)
323 return;
324
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
326 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
327 sta->flags |= WLAN_STA_AUTH;
328 mlme_authenticate_indication(hapd, sta);
329}
330#endif /* CONFIG_IEEE80211R */
331
332
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800333#ifdef CONFIG_SAE
334
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800335#define dot11RSNASAESync 5 /* attempts */
336
337
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800338static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
339 struct sta_info *sta, int update)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800340{
341 struct wpabuf *buf;
342
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800343 if (hapd->conf->ssid.wpa_passphrase == NULL) {
344 wpa_printf(MSG_DEBUG, "SAE: No password available");
345 return NULL;
346 }
347
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800348 if (update &&
349 sae_prepare_commit(hapd->own_addr, sta->addr,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800350 (u8 *) hapd->conf->ssid.wpa_passphrase,
351 os_strlen(hapd->conf->ssid.wpa_passphrase),
352 sta->sae) < 0) {
353 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
354 return NULL;
355 }
356
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800357 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800358 if (buf == NULL)
359 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800360 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
361 sta->sae->tmp->anti_clogging_token : NULL);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800362
363 return buf;
364}
365
366
367static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
368 struct sta_info *sta)
369{
370 struct wpabuf *buf;
371
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800372 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800373 if (buf == NULL)
374 return NULL;
375
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800376 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800377
378 return buf;
379}
380
381
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800382static int auth_sae_send_commit(struct hostapd_data *hapd,
383 struct sta_info *sta,
384 const u8 *bssid, int update)
385{
386 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800387 int reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800388
389 data = auth_build_sae_commit(hapd, sta, update);
390 if (data == NULL)
391 return WLAN_STATUS_UNSPECIFIED_FAILURE;
392
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800393 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
394 WLAN_STATUS_SUCCESS, wpabuf_head(data),
395 wpabuf_len(data));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800396
397 wpabuf_free(data);
398
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800399 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800400}
401
402
403static int auth_sae_send_confirm(struct hostapd_data *hapd,
404 struct sta_info *sta,
405 const u8 *bssid)
406{
407 struct wpabuf *data;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800408 int reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800409
410 data = auth_build_sae_confirm(hapd, sta);
411 if (data == NULL)
412 return WLAN_STATUS_UNSPECIFIED_FAILURE;
413
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800414 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
415 WLAN_STATUS_SUCCESS, wpabuf_head(data),
416 wpabuf_len(data));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800417
418 wpabuf_free(data);
419
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800420 return reply_res;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800421}
422
423
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800424static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800425{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800426 struct sta_info *sta;
427 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800428
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800429 if (hapd->conf->sae_anti_clogging_threshold == 0)
430 return 1;
431
432 for (sta = hapd->sta_list; sta; sta = sta->next) {
433 if (!sta->sae)
434 continue;
435 if (sta->sae->state != SAE_COMMITTED &&
436 sta->sae->state != SAE_CONFIRMED)
437 continue;
438 open++;
439 if (open >= hapd->conf->sae_anti_clogging_threshold)
440 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800441 }
442
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800443 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800444}
445
446
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800447static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
448 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800449{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800450 u8 mac[SHA256_MAC_LEN];
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800451
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800452 if (token_len != SHA256_MAC_LEN)
453 return -1;
454 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
455 addr, ETH_ALEN, mac) < 0 ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700456 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800457 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800458
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800459 return 0;
460}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800461
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800462
463static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800464 int group, const u8 *addr)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800465{
466 struct wpabuf *buf;
467 u8 *token;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800468 struct os_reltime now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800469
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800470 os_get_reltime(&now);
471 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
472 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800473 if (random_get_bytes(hapd->sae_token_key,
474 sizeof(hapd->sae_token_key)) < 0)
475 return NULL;
476 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
477 hapd->sae_token_key, sizeof(hapd->sae_token_key));
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800478 hapd->last_sae_token_key_update = now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800479 }
480
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800481 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800482 if (buf == NULL)
483 return NULL;
484
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800485 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
486
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800487 token = wpabuf_put(buf, SHA256_MAC_LEN);
488 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
489 addr, ETH_ALEN, token);
490
491 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800492}
493
494
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800495static int sae_check_big_sync(struct sta_info *sta)
496{
497 if (sta->sae->sync > dot11RSNASAESync) {
498 sta->sae->state = SAE_NOTHING;
499 sta->sae->sync = 0;
500 return -1;
501 }
502 return 0;
503}
504
505
506static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
507{
508 struct hostapd_data *hapd = eloop_ctx;
509 struct sta_info *sta = eloop_data;
510 int ret;
511
512 if (sae_check_big_sync(sta))
513 return;
514 sta->sae->sync++;
515
516 switch (sta->sae->state) {
517 case SAE_COMMITTED:
518 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800519 eloop_register_timeout(0,
520 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800521 auth_sae_retransmit_timer, hapd, sta);
522 break;
523 case SAE_CONFIRMED:
524 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800525 eloop_register_timeout(0,
526 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800527 auth_sae_retransmit_timer, hapd, sta);
528 break;
529 default:
530 ret = -1;
531 break;
532 }
533
534 if (ret != WLAN_STATUS_SUCCESS)
535 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
536}
537
538
539void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
540{
541 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
542}
543
544
545static void sae_set_retransmit_timer(struct hostapd_data *hapd,
546 struct sta_info *sta)
547{
548 if (!(hapd->conf->mesh & MESH_ENABLED))
549 return;
550
551 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800552 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800553 auth_sae_retransmit_timer, hapd, sta);
554}
555
556
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800557static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
558 const u8 *bssid, u8 auth_transaction)
559{
560 int ret;
561
562 if (auth_transaction != 1 && auth_transaction != 2)
563 return WLAN_STATUS_UNSPECIFIED_FAILURE;
564
565 switch (sta->sae->state) {
566 case SAE_NOTHING:
567 if (auth_transaction == 1) {
568 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
569 if (ret)
570 return ret;
571 sta->sae->state = SAE_COMMITTED;
572
573 if (sae_process_commit(sta->sae) < 0)
574 return WLAN_STATUS_UNSPECIFIED_FAILURE;
575
576 /*
577 * In mesh case, both Commit and Confirm can be sent
578 * immediately. In infrastructure BSS, only a single
579 * Authentication frame (Commit) is expected from the AP
580 * here and the second one (Confirm) will be sent once
581 * the STA has sent its second Authentication frame
582 * (Confirm).
583 */
584 if (hapd->conf->mesh & MESH_ENABLED) {
585 /*
586 * Send both Commit and Confirm immediately
587 * based on SAE finite state machine
588 * Nothing -> Confirm transition.
589 */
590 ret = auth_sae_send_confirm(hapd, sta, bssid);
591 if (ret)
592 return ret;
593 sta->sae->state = SAE_CONFIRMED;
594 } else {
595 /*
596 * For infrastructure BSS, send only the Commit
597 * message now to get alternating sequence of
598 * Authentication frames between the AP and STA.
599 * Confirm will be sent in
600 * Commited -> Confirmed/Accepted transition
601 * when receiving Confirm from STA.
602 */
603 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800604 sta->sae->sync = 0;
605 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800606 } else {
607 hostapd_logger(hapd, sta->addr,
608 HOSTAPD_MODULE_IEEE80211,
609 HOSTAPD_LEVEL_DEBUG,
610 "SAE confirm before commit");
611 }
612 break;
613 case SAE_COMMITTED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800614 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800615 if (auth_transaction == 1) {
616 if (sae_process_commit(sta->sae) < 0)
617 return WLAN_STATUS_UNSPECIFIED_FAILURE;
618
619 ret = auth_sae_send_confirm(hapd, sta, bssid);
620 if (ret)
621 return ret;
622 sta->sae->state = SAE_CONFIRMED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800623 sta->sae->sync = 0;
624 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800625 } else if (hapd->conf->mesh & MESH_ENABLED) {
626 /*
627 * In mesh case, follow SAE finite state machine and
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800628 * send Commit now, if sync count allows.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800629 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800630 if (sae_check_big_sync(sta))
631 return WLAN_STATUS_SUCCESS;
632 sta->sae->sync++;
633
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700634 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800635 if (ret)
636 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800637
638 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800639 } else {
640 /*
641 * For instructure BSS, send the postponed Confirm from
642 * Nothing -> Confirmed transition that was reduced to
643 * Nothing -> Committed above.
644 */
645 ret = auth_sae_send_confirm(hapd, sta, bssid);
646 if (ret)
647 return ret;
648
649 sta->sae->state = SAE_CONFIRMED;
650
651 /*
652 * Since this was triggered on Confirm RX, run another
653 * step to get to Accepted without waiting for
654 * additional events.
655 */
656 return sae_sm_step(hapd, sta, bssid, auth_transaction);
657 }
658 break;
659 case SAE_CONFIRMED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800660 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800661 if (auth_transaction == 1) {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800662 if (sae_check_big_sync(sta))
663 return WLAN_STATUS_SUCCESS;
664 sta->sae->sync++;
665
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800666 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
667 if (ret)
668 return ret;
669
670 if (sae_process_commit(sta->sae) < 0)
671 return WLAN_STATUS_UNSPECIFIED_FAILURE;
672
673 ret = auth_sae_send_confirm(hapd, sta, bssid);
674 if (ret)
675 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800676
677 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800678 } else {
679 sta->flags |= WLAN_STA_AUTH;
680 sta->auth_alg = WLAN_AUTH_SAE;
681 mlme_authenticate_indication(hapd, sta);
682 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
683 sta->sae->state = SAE_ACCEPTED;
684 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800685 sta->sae->pmk, sta->sae->pmkid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800686 }
687 break;
688 case SAE_ACCEPTED:
689 if (auth_transaction == 1) {
690 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
691 ") doing reauthentication",
692 MAC2STR(sta->addr));
693 ap_free_sta(hapd, sta);
694 } else {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800695 if (sae_check_big_sync(sta))
696 return WLAN_STATUS_SUCCESS;
697 sta->sae->sync++;
698
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800699 ret = auth_sae_send_confirm(hapd, sta, bssid);
700 sae_clear_temp_data(sta->sae);
701 if (ret)
702 return ret;
703 }
704 break;
705 default:
706 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
707 sta->sae->state);
708 return WLAN_STATUS_UNSPECIFIED_FAILURE;
709 }
710 return WLAN_STATUS_SUCCESS;
711}
712
713
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800714static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
715 const struct ieee80211_mgmt *mgmt, size_t len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800716 u16 auth_transaction, u16 status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800717{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800718 int resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800719 struct wpabuf *data = NULL;
720
721 if (!sta->sae) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800722 if (auth_transaction != 1 ||
723 status_code != WLAN_STATUS_SUCCESS) {
724 resp = -1;
725 goto remove_sta;
726 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800727 sta->sae = os_zalloc(sizeof(*sta->sae));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800728 if (!sta->sae) {
729 resp = -1;
730 goto remove_sta;
731 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800732 sta->sae->state = SAE_NOTHING;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800733 sta->sae->sync = 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800734 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800735
736 if (auth_transaction == 1) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800737 const u8 *token = NULL, *pos, *end;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800738 size_t token_len = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800739 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
740 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800741 "start SAE authentication (RX commit, status=%u)",
742 status_code);
743
744 if ((hapd->conf->mesh & MESH_ENABLED) &&
745 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
746 sta->sae->tmp) {
747 pos = mgmt->u.auth.variable;
748 end = ((const u8 *) mgmt) + len;
749 if (pos + sizeof(le16) > end) {
750 wpa_printf(MSG_ERROR,
751 "SAE: Too short anti-clogging token request");
752 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
753 goto reply;
754 }
755 resp = sae_group_allowed(sta->sae,
756 hapd->conf->sae_groups,
757 WPA_GET_LE16(pos));
758 if (resp != WLAN_STATUS_SUCCESS) {
759 wpa_printf(MSG_ERROR,
760 "SAE: Invalid group in anti-clogging token request");
761 goto reply;
762 }
763 pos += sizeof(le16);
764
765 wpabuf_free(sta->sae->tmp->anti_clogging_token);
766 sta->sae->tmp->anti_clogging_token =
767 wpabuf_alloc_copy(pos, end - pos);
768 if (sta->sae->tmp->anti_clogging_token == NULL) {
769 wpa_printf(MSG_ERROR,
770 "SAE: Failed to alloc for anti-clogging token");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800771 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
772 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800773 }
774
775 /*
776 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
777 * is 76, a new Commit Message shall be constructed
778 * with the Anti-Clogging Token from the received
779 * Authentication frame, and the commit-scalar and
780 * COMMIT-ELEMENT previously sent.
781 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800782 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
783 if (resp != WLAN_STATUS_SUCCESS) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800784 wpa_printf(MSG_ERROR,
785 "SAE: Failed to send commit message");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800786 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800787 }
788 sta->sae->state = SAE_COMMITTED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800789 sta->sae->sync = 0;
790 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800791 return;
792 }
793
794 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800795 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800796
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800797 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
798 ((const u8 *) mgmt) + len -
799 mgmt->u.auth.variable, &token,
800 &token_len, hapd->conf->sae_groups);
Dmitry Shmidt41712582015-06-29 11:02:15 -0700801 if (resp == SAE_SILENTLY_DISCARD) {
802 wpa_printf(MSG_DEBUG,
803 "SAE: Drop commit message from " MACSTR " due to reflection attack",
804 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800805 goto remove_sta;
Dmitry Shmidt41712582015-06-29 11:02:15 -0700806 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800807 if (token && check_sae_token(hapd, sta->addr, token, token_len)
808 < 0) {
809 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
810 "incorrect token from " MACSTR,
811 MAC2STR(sta->addr));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800812 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
813 goto remove_sta;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800814 }
815
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800816 if (resp != WLAN_STATUS_SUCCESS)
817 goto reply;
818
819 if (!token && use_sae_anti_clogging(hapd)) {
820 wpa_printf(MSG_DEBUG,
821 "SAE: Request anti-clogging token from "
822 MACSTR, MAC2STR(sta->addr));
823 data = auth_build_token_req(hapd, sta->sae->group,
824 sta->addr);
825 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
826 if (hapd->conf->mesh & MESH_ENABLED)
827 sta->sae->state = SAE_NOTHING;
828 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800829 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800830
831 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800832 } else if (auth_transaction == 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800833 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
834 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800835 "SAE authentication (RX confirm, status=%u)",
836 status_code);
837 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800838 goto remove_sta;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800839 if (sta->sae->state >= SAE_CONFIRMED ||
840 !(hapd->conf->mesh & MESH_ENABLED)) {
841 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
842 ((u8 *) mgmt) + len -
843 mgmt->u.auth.variable) < 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800844 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800845 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800846 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800847 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800848 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800849 } else {
850 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
851 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800852 "unexpected SAE authentication transaction %u (status=%u)",
853 auth_transaction, status_code);
854 if (status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800855 goto remove_sta;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800856 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
857 }
858
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800859reply:
860 if (resp != WLAN_STATUS_SUCCESS) {
861 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
862 auth_transaction, resp,
863 data ? wpabuf_head(data) : (u8 *) "",
864 data ? wpabuf_len(data) : 0);
865 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800866
867remove_sta:
868 if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
869 status_code != WLAN_STATUS_SUCCESS)) {
870 hostapd_drv_sta_remove(hapd, sta->addr);
871 sta->added_unassoc = 0;
872 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800873 wpabuf_free(data);
874}
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800875
876
877/**
878 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
879 * @hapd: BSS data for the device initiating the authentication
880 * @sta: the peer to which commit authentication frame is sent
881 *
882 * This function implements Init event handling (IEEE Std 802.11-2012,
883 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
884 * sta->sae structure should be initialized appropriately via a call to
885 * sae_prepare_commit().
886 */
887int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
888{
889 int ret;
890
891 if (!sta->sae || !sta->sae->tmp)
892 return -1;
893
894 if (sta->sae->state != SAE_NOTHING)
895 return -1;
896
897 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
898 if (ret)
899 return -1;
900
901 sta->sae->state = SAE_COMMITTED;
902 sta->sae->sync = 0;
903 sae_set_retransmit_timer(hapd, sta);
904
905 return 0;
906}
907
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800908#endif /* CONFIG_SAE */
909
910
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700911static void handle_auth(struct hostapd_data *hapd,
912 const struct ieee80211_mgmt *mgmt, size_t len)
913{
914 u16 auth_alg, auth_transaction, status_code;
915 u16 resp = WLAN_STATUS_SUCCESS;
916 struct sta_info *sta = NULL;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800917 int res, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918 u16 fc;
919 const u8 *challenge = NULL;
920 u32 session_timeout, acct_interim_interval;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800921 struct vlan_description vlan_id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800922 struct hostapd_sta_wpa_psk_short *psk = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700923 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
924 size_t resp_ies_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700925 char *identity = NULL;
926 char *radius_cui = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800927 u16 seq_ctrl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800929 os_memset(&vlan_id, 0, sizeof(vlan_id));
930
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800932 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
933 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934 return;
935 }
936
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700937#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700938 if (hapd->iconf->ignore_auth_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700939 drand48() < hapd->iconf->ignore_auth_probability) {
940 wpa_printf(MSG_INFO,
941 "TESTING: ignoring auth frame from " MACSTR,
942 MAC2STR(mgmt->sa));
943 return;
944 }
945#endif /* CONFIG_TESTING_OPTIONS */
946
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
948 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
949 status_code = le_to_host16(mgmt->u.auth.status_code);
950 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800951 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700952
953 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
954 2 + WLAN_AUTH_CHALLENGE_LEN &&
955 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
956 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
957 challenge = &mgmt->u.auth.variable[2];
958
959 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800960 "auth_transaction=%d status_code=%d wep=%d%s "
961 "seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
963 status_code, !!(fc & WLAN_FC_ISWEP),
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800964 challenge ? " challenge" : "",
965 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700966
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800967#ifdef CONFIG_NO_RC4
968 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
969 wpa_printf(MSG_INFO,
970 "Unsupported authentication algorithm (%d)",
971 auth_alg);
972 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
973 goto fail;
974 }
975#endif /* CONFIG_NO_RC4 */
976
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 if (hapd->tkip_countermeasures) {
978 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
979 goto fail;
980 }
981
982 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
983 auth_alg == WLAN_AUTH_OPEN) ||
984#ifdef CONFIG_IEEE80211R
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800985 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986 auth_alg == WLAN_AUTH_FT) ||
987#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800988#ifdef CONFIG_SAE
989 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
990 auth_alg == WLAN_AUTH_SAE) ||
991#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
993 auth_alg == WLAN_AUTH_SHARED_KEY))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800994 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
995 auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
997 goto fail;
998 }
999
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001000 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001001 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001002 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
1003 auth_transaction);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1005 goto fail;
1006 }
1007
1008 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001009 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1010 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001011 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1012 goto fail;
1013 }
1014
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001015 if (hapd->conf->no_auth_if_seen_on) {
1016 struct hostapd_data *other;
1017
1018 other = sta_track_seen_on(hapd->iface, mgmt->sa,
1019 hapd->conf->no_auth_if_seen_on);
1020 if (other) {
1021 u8 *pos;
1022 u32 info;
1023 u8 op_class, channel, phytype;
1024
1025 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
1026 MACSTR " since STA has been seen on %s",
1027 hapd->conf->iface, MAC2STR(mgmt->sa),
1028 hapd->conf->no_auth_if_seen_on);
1029
1030 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1031 pos = &resp_ies[0];
1032 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1033 *pos++ = 13;
1034 os_memcpy(pos, other->own_addr, ETH_ALEN);
1035 pos += ETH_ALEN;
1036 info = 0; /* TODO: BSSID Information */
1037 WPA_PUT_LE32(pos, info);
1038 pos += 4;
1039 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1040 phytype = 8; /* dmg */
1041 else if (other->iconf->ieee80211ac)
1042 phytype = 9; /* vht */
1043 else if (other->iconf->ieee80211n)
1044 phytype = 7; /* ht */
1045 else if (other->iconf->hw_mode ==
1046 HOSTAPD_MODE_IEEE80211A)
1047 phytype = 4; /* ofdm */
1048 else if (other->iconf->hw_mode ==
1049 HOSTAPD_MODE_IEEE80211G)
1050 phytype = 6; /* erp */
1051 else
1052 phytype = 5; /* hrdsss */
1053 if (ieee80211_freq_to_channel_ext(
1054 hostapd_hw_get_freq(other,
1055 other->iconf->channel),
1056 other->iconf->secondary_channel,
1057 other->iconf->ieee80211ac,
1058 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1059 op_class = 0;
1060 channel = other->iconf->channel;
1061 }
1062 *pos++ = op_class;
1063 *pos++ = channel;
1064 *pos++ = phytype;
1065 resp_ies_len = pos - &resp_ies[0];
1066 goto fail;
1067 }
1068 }
1069
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1071 &session_timeout,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001072 &acct_interim_interval, &vlan_id,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001073 &psk, &identity, &radius_cui);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001074
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075 if (res == HOSTAPD_ACL_REJECT) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001076 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1077 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001078 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1079 goto fail;
1080 }
1081 if (res == HOSTAPD_ACL_PENDING) {
1082 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1083 " waiting for an external authentication",
1084 MAC2STR(mgmt->sa));
1085 /* Authentication code will re-send the authentication frame
1086 * after it has received (and cached) information from the
1087 * external source. */
1088 return;
1089 }
1090
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001091 sta = ap_get_sta(hapd, mgmt->sa);
1092 if (sta) {
1093 if ((fc & WLAN_FC_RETRY) &&
1094 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1095 sta->last_seq_ctrl == seq_ctrl &&
1096 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1097 hostapd_logger(hapd, sta->addr,
1098 HOSTAPD_MODULE_IEEE80211,
1099 HOSTAPD_LEVEL_DEBUG,
1100 "Drop repeated authentication frame seq_ctrl=0x%x",
1101 seq_ctrl);
1102 return;
1103 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001104#ifdef CONFIG_MESH
1105 if ((hapd->conf->mesh & MESH_ENABLED) &&
1106 sta->plink_state == PLINK_BLOCKED) {
1107 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1108 " is blocked - drop Authentication frame",
1109 MAC2STR(mgmt->sa));
1110 return;
1111 }
1112#endif /* CONFIG_MESH */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001113 } else {
1114#ifdef CONFIG_MESH
1115 if (hapd->conf->mesh & MESH_ENABLED) {
1116 /* if the mesh peer is not available, we don't do auth.
1117 */
1118 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001119 " not yet known - drop Authentication frame",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001120 MAC2STR(mgmt->sa));
1121 /*
1122 * Save a copy of the frame so that it can be processed
1123 * if a new peer entry is added shortly after this.
1124 */
1125 wpabuf_free(hapd->mesh_pending_auth);
1126 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1127 os_get_reltime(&hapd->mesh_pending_auth_time);
1128 return;
1129 }
1130#endif /* CONFIG_MESH */
1131
1132 sta = ap_sta_add(hapd, mgmt->sa);
1133 if (!sta) {
1134 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1135 goto fail;
1136 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001137 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001138 sta->last_seq_ctrl = seq_ctrl;
1139 sta->last_subtype = WLAN_FC_STYPE_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001140
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001141 if (vlan_id.notempty &&
1142 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
1143 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1144 HOSTAPD_LEVEL_INFO,
1145 "Invalid VLAN %d%s received from RADIUS server",
1146 vlan_id.untagged,
1147 vlan_id.tagged[0] ? "+" : "");
1148 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1149 goto fail;
1150 }
1151 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1152 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1153 goto fail;
1154 }
1155 if (sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1157 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001159 hostapd_free_psk_list(sta->psk);
1160 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1161 sta->psk = psk;
1162 psk = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001163 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001164 sta->psk = NULL;
1165 }
1166
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001167 sta->identity = identity;
1168 identity = NULL;
1169 sta->radius_cui = radius_cui;
1170 radius_cui = NULL;
1171
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001172 sta->flags &= ~WLAN_STA_PREAUTH;
1173 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1174
1175 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1176 sta->acct_interim_interval = acct_interim_interval;
1177 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1178 ap_sta_session_timeout(hapd, sta, session_timeout);
1179 else
1180 ap_sta_no_session_timeout(hapd, sta);
1181
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001182 /*
1183 * If the driver supports full AP client state, add a station to the
1184 * driver before sending authentication reply to make sure the driver
1185 * has resources, and not to go through the entire authentication and
1186 * association handshake, and fail it at the end.
1187 *
1188 * If this is not the first transaction, in a multi-step authentication
1189 * algorithm, the station already exists in the driver
1190 * (sta->added_unassoc = 1) so skip it.
1191 *
1192 * In mesh mode, the station was already added to the driver when the
1193 * NEW_PEER_CANDIDATE event is received.
1194 */
1195 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
1196 !(hapd->conf->mesh & MESH_ENABLED) &&
1197 !(sta->added_unassoc)) {
1198 /*
1199 * If a station that is already associated to the AP, is trying
1200 * to authenticate again, remove the STA entry, in order to make
1201 * sure the STA PS state gets cleared and configuration gets
1202 * updated. To handle this, station's added_unassoc flag is
1203 * cleared once the station has completed association.
1204 */
1205 hostapd_drv_sta_remove(hapd, sta->addr);
1206 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
1207 WLAN_STA_AUTHORIZED);
1208
1209 if (hostapd_sta_add(hapd, sta->addr, 0, 0, 0, 0, 0,
1210 NULL, NULL, sta->flags, 0, 0, 0)) {
1211 hostapd_logger(hapd, sta->addr,
1212 HOSTAPD_MODULE_IEEE80211,
1213 HOSTAPD_LEVEL_NOTICE,
1214 "Could not add STA to kernel driver");
1215 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1216 goto fail;
1217 }
1218
1219 sta->added_unassoc = 1;
1220 }
1221
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 switch (auth_alg) {
1223 case WLAN_AUTH_OPEN:
1224 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1225 HOSTAPD_LEVEL_DEBUG,
1226 "authentication OK (open system)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227 sta->flags |= WLAN_STA_AUTH;
1228 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1229 sta->auth_alg = WLAN_AUTH_OPEN;
1230 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001232#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001233 case WLAN_AUTH_SHARED_KEY:
1234 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1235 fc & WLAN_FC_ISWEP);
1236 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1237 mlme_authenticate_indication(hapd, sta);
1238 if (sta->challenge && auth_transaction == 1) {
1239 resp_ies[0] = WLAN_EID_CHALLENGE;
1240 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1241 os_memcpy(resp_ies + 2, sta->challenge,
1242 WLAN_AUTH_CHALLENGE_LEN);
1243 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1244 }
1245 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001246#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001247#ifdef CONFIG_IEEE80211R
1248 case WLAN_AUTH_FT:
1249 sta->auth_alg = WLAN_AUTH_FT;
1250 if (sta->wpa_sm == NULL)
1251 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001252 sta->addr, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001253 if (sta->wpa_sm == NULL) {
1254 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1255 "state machine");
1256 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1257 goto fail;
1258 }
1259 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1260 auth_transaction, mgmt->u.auth.variable,
1261 len - IEEE80211_HDRLEN -
1262 sizeof(mgmt->u.auth),
1263 handle_auth_ft_finish, hapd);
1264 /* handle_auth_ft_finish() callback will complete auth. */
1265 return;
1266#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001267#ifdef CONFIG_SAE
1268 case WLAN_AUTH_SAE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001269#ifdef CONFIG_MESH
1270 if (status_code == WLAN_STATUS_SUCCESS &&
1271 hapd->conf->mesh & MESH_ENABLED) {
1272 if (sta->wpa_sm == NULL)
1273 sta->wpa_sm =
1274 wpa_auth_sta_init(hapd->wpa_auth,
1275 sta->addr, NULL);
1276 if (sta->wpa_sm == NULL) {
1277 wpa_printf(MSG_DEBUG,
1278 "SAE: Failed to initialize WPA state machine");
1279 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1280 goto fail;
1281 }
1282 }
1283#endif /* CONFIG_MESH */
1284 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1285 status_code);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001286 return;
1287#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001288 }
1289
1290 fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001291 os_free(identity);
1292 os_free(radius_cui);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001293 hostapd_free_psk_list(psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001294
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001295 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1296 auth_transaction + 1, resp, resp_ies,
1297 resp_ies_len);
1298
1299 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
1300 reply_res != WLAN_STATUS_SUCCESS)) {
1301 hostapd_drv_sta_remove(hapd, sta->addr);
1302 sta->added_unassoc = 0;
1303 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001304}
1305
1306
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001307int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308{
1309 int i, j = 32, aid;
1310
1311 /* get a unique AID */
1312 if (sta->aid > 0) {
1313 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1314 return 0;
1315 }
1316
1317 for (i = 0; i < AID_WORDS; i++) {
1318 if (hapd->sta_aid[i] == (u32) -1)
1319 continue;
1320 for (j = 0; j < 32; j++) {
1321 if (!(hapd->sta_aid[i] & BIT(j)))
1322 break;
1323 }
1324 if (j < 32)
1325 break;
1326 }
1327 if (j == 32)
1328 return -1;
1329 aid = i * 32 + j + 1;
1330 if (aid > 2007)
1331 return -1;
1332
1333 sta->aid = aid;
1334 hapd->sta_aid[i] |= BIT(j);
1335 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1336 return 0;
1337}
1338
1339
1340static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1341 const u8 *ssid_ie, size_t ssid_ie_len)
1342{
1343 if (ssid_ie == NULL)
1344 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1345
1346 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1347 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001348 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1349 HOSTAPD_LEVEL_INFO,
1350 "Station tried to associate with unknown SSID "
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001351 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1353 }
1354
1355 return WLAN_STATUS_SUCCESS;
1356}
1357
1358
1359static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1360 const u8 *wmm_ie, size_t wmm_ie_len)
1361{
1362 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001363 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001364 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001365 struct wmm_information_element *wmm;
1366
1367 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001368 hostapd_logger(hapd, sta->addr,
1369 HOSTAPD_MODULE_WPA,
1370 HOSTAPD_LEVEL_DEBUG,
1371 "invalid WMM element in association "
1372 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001373 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1374 }
1375
1376 sta->flags |= WLAN_STA_WMM;
1377 wmm = (struct wmm_information_element *) wmm_ie;
1378 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001379 }
1380 return WLAN_STATUS_SUCCESS;
1381}
1382
1383
1384static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1385 struct ieee802_11_elems *elems)
1386{
1387 if (!elems->supp_rates) {
1388 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1389 HOSTAPD_LEVEL_DEBUG,
1390 "No supported rates element in AssocReq");
1391 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1392 }
1393
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001394 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1395 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001396 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1397 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001398 "Invalid supported rates element length %d+%d",
1399 elems->supp_rates_len,
1400 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001401 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1402 }
1403
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001404 sta->supported_rates_len = merge_byte_arrays(
1405 sta->supported_rates, sizeof(sta->supported_rates),
1406 elems->supp_rates, elems->supp_rates_len,
1407 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001408
1409 return WLAN_STATUS_SUCCESS;
1410}
1411
1412
Dmitry Shmidt051af732013-10-22 13:52:46 -07001413static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1414 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1415{
1416#ifdef CONFIG_INTERWORKING
1417 /* check for QoS Map support */
1418 if (ext_capab_ie_len >= 5) {
1419 if (ext_capab_ie[4] & 0x01)
1420 sta->qos_map_enabled = 1;
1421 }
1422#endif /* CONFIG_INTERWORKING */
1423
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001424 if (ext_capab_ie_len > 0)
1425 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1426
Dmitry Shmidt051af732013-10-22 13:52:46 -07001427 return WLAN_STATUS_SUCCESS;
1428}
1429
1430
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001431static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1432 const u8 *ies, size_t ies_len, int reassoc)
1433{
1434 struct ieee802_11_elems elems;
1435 u16 resp;
1436 const u8 *wpa_ie;
1437 size_t wpa_ie_len;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001438 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001439
1440 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1441 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1442 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1443 "association request");
1444 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1445 }
1446
1447 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1448 if (resp != WLAN_STATUS_SUCCESS)
1449 return resp;
1450 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1451 if (resp != WLAN_STATUS_SUCCESS)
1452 return resp;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001453 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1454 if (resp != WLAN_STATUS_SUCCESS)
1455 return resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001456 resp = copy_supp_rates(hapd, sta, &elems);
1457 if (resp != WLAN_STATUS_SUCCESS)
1458 return resp;
1459#ifdef CONFIG_IEEE80211N
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001460 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001461 if (resp != WLAN_STATUS_SUCCESS)
1462 return resp;
1463 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1464 !(sta->flags & WLAN_STA_HT)) {
1465 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1466 HOSTAPD_LEVEL_INFO, "Station does not support "
1467 "mandatory HT PHY - reject association");
1468 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1469 }
1470#endif /* CONFIG_IEEE80211N */
1471
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001472#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001473 if (hapd->iconf->ieee80211ac) {
1474 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1475 if (resp != WLAN_STATUS_SUCCESS)
1476 return resp;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08001477
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001478 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1479 if (resp != WLAN_STATUS_SUCCESS)
1480 return resp;
1481 }
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08001482
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001483 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1484 !(sta->flags & WLAN_STA_VHT)) {
1485 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1486 HOSTAPD_LEVEL_INFO, "Station does not support "
1487 "mandatory VHT PHY - reject association");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001488 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001489 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001490
1491 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1492 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1493 elems.vendor_vht_len);
1494 if (resp != WLAN_STATUS_SUCCESS)
1495 return resp;
1496 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001497#endif /* CONFIG_IEEE80211AC */
1498
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001499#ifdef CONFIG_P2P
1500 if (elems.p2p) {
1501 wpabuf_free(sta->p2p_ie);
1502 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1503 P2P_IE_VENDOR_TYPE);
1504 if (sta->p2p_ie)
1505 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1506 } else {
1507 wpabuf_free(sta->p2p_ie);
1508 sta->p2p_ie = NULL;
1509 }
1510#endif /* CONFIG_P2P */
1511
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001512 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1513 wpa_ie = elems.rsn_ie;
1514 wpa_ie_len = elems.rsn_ie_len;
1515 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1516 elems.wpa_ie) {
1517 wpa_ie = elems.wpa_ie;
1518 wpa_ie_len = elems.wpa_ie_len;
1519 } else {
1520 wpa_ie = NULL;
1521 wpa_ie_len = 0;
1522 }
1523
1524#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001525 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001526 if (hapd->conf->wps_state && elems.wps_ie) {
1527 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1528 "Request - assume WPS is used");
1529 sta->flags |= WLAN_STA_WPS;
1530 wpabuf_free(sta->wps_ie);
1531 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1532 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001533 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1534 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1535 sta->flags |= WLAN_STA_WPS2;
1536 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537 wpa_ie = NULL;
1538 wpa_ie_len = 0;
1539 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1540 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1541 "(Re)Association Request - reject");
1542 return WLAN_STATUS_INVALID_IE;
1543 }
1544 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1545 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1546 "(Re)Association Request - possible WPS use");
1547 sta->flags |= WLAN_STA_MAYBE_WPS;
1548 } else
1549#endif /* CONFIG_WPS */
1550 if (hapd->conf->wpa && wpa_ie == NULL) {
1551 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1552 HOSTAPD_LEVEL_INFO,
1553 "No WPA/RSN IE in association request");
1554 return WLAN_STATUS_INVALID_IE;
1555 }
1556
1557 if (hapd->conf->wpa && wpa_ie) {
1558 int res;
1559 wpa_ie -= 2;
1560 wpa_ie_len += 2;
1561 if (sta->wpa_sm == NULL)
1562 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001563 sta->addr,
1564 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565 if (sta->wpa_sm == NULL) {
1566 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1567 "state machine");
1568 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1569 }
1570 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1571 wpa_ie, wpa_ie_len,
1572 elems.mdie, elems.mdie_len);
1573 if (res == WPA_INVALID_GROUP)
1574 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1575 else if (res == WPA_INVALID_PAIRWISE)
1576 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1577 else if (res == WPA_INVALID_AKMP)
1578 resp = WLAN_STATUS_AKMP_NOT_VALID;
1579 else if (res == WPA_ALLOC_FAIL)
1580 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1581#ifdef CONFIG_IEEE80211W
1582 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1583 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1584 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1585 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1586#endif /* CONFIG_IEEE80211W */
1587 else if (res == WPA_INVALID_MDIE)
1588 resp = WLAN_STATUS_INVALID_MDIE;
1589 else if (res != WPA_IE_OK)
1590 resp = WLAN_STATUS_INVALID_IE;
1591 if (resp != WLAN_STATUS_SUCCESS)
1592 return resp;
1593#ifdef CONFIG_IEEE80211W
1594 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1595 sta->sa_query_count > 0)
1596 ap_check_sa_query_timeout(hapd, sta);
1597 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1598 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1599 /*
1600 * STA has already been associated with MFP and SA
1601 * Query timeout has not been reached. Reject the
1602 * association attempt temporarily and start SA Query,
1603 * if one is not pending.
1604 */
1605
1606 if (sta->sa_query_count == 0)
1607 ap_sta_start_sa_query(hapd, sta);
1608
1609 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1610 }
1611
1612 if (wpa_auth_uses_mfp(sta->wpa_sm))
1613 sta->flags |= WLAN_STA_MFP;
1614 else
1615 sta->flags &= ~WLAN_STA_MFP;
1616#endif /* CONFIG_IEEE80211W */
1617
1618#ifdef CONFIG_IEEE80211R
1619 if (sta->auth_alg == WLAN_AUTH_FT) {
1620 if (!reassoc) {
1621 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1622 "to use association (not "
1623 "re-association) with FT auth_alg",
1624 MAC2STR(sta->addr));
1625 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1626 }
1627
1628 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1629 ies_len);
1630 if (resp != WLAN_STATUS_SUCCESS)
1631 return resp;
1632 }
1633#endif /* CONFIG_IEEE80211R */
1634
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001635#ifdef CONFIG_SAE
1636 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001637 sta->auth_alg == WLAN_AUTH_OPEN) {
1638 struct rsn_pmksa_cache_entry *sa;
1639 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1640 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1641 wpa_printf(MSG_DEBUG,
1642 "SAE: No PMKSA cache entry found for "
1643 MACSTR, MAC2STR(sta->addr));
1644 return WLAN_STATUS_INVALID_PMKID;
1645 }
1646 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1647 " using PMKSA caching", MAC2STR(sta->addr));
1648 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1649 sta->auth_alg != WLAN_AUTH_SAE &&
1650 !(sta->auth_alg == WLAN_AUTH_FT &&
1651 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001652 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1653 "SAE AKM after non-SAE auth_alg %u",
1654 MAC2STR(sta->addr), sta->auth_alg);
1655 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1656 }
1657#endif /* CONFIG_SAE */
1658
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001659#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001660 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001661 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1662 hostapd_logger(hapd, sta->addr,
1663 HOSTAPD_MODULE_IEEE80211,
1664 HOSTAPD_LEVEL_INFO,
1665 "Station tried to use TKIP with HT "
1666 "association");
1667 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1668 }
1669#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001670#ifdef CONFIG_HS20
1671 } else if (hapd->conf->osen) {
1672 if (elems.osen == NULL) {
1673 hostapd_logger(
1674 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1675 HOSTAPD_LEVEL_INFO,
1676 "No HS 2.0 OSEN element in association request");
1677 return WLAN_STATUS_INVALID_IE;
1678 }
1679
1680 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1681 if (sta->wpa_sm == NULL)
1682 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1683 sta->addr, NULL);
1684 if (sta->wpa_sm == NULL) {
1685 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1686 "state machine");
1687 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1688 }
1689 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1690 elems.osen - 2, elems.osen_len + 2) < 0)
1691 return WLAN_STATUS_INVALID_IE;
1692#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001693 } else
1694 wpa_auth_sta_no_wpa(sta->wpa_sm);
1695
1696#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1698#endif /* CONFIG_P2P */
1699
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001700#ifdef CONFIG_HS20
1701 wpabuf_free(sta->hs20_ie);
1702 if (elems.hs20 && elems.hs20_len > 4) {
1703 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1704 elems.hs20_len - 4);
1705 } else
1706 sta->hs20_ie = NULL;
1707#endif /* CONFIG_HS20 */
1708
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001709#ifdef CONFIG_FST
1710 wpabuf_free(sta->mb_ies);
1711 if (hapd->iface->fst)
1712 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1713 else
1714 sta->mb_ies = NULL;
1715#endif /* CONFIG_FST */
1716
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001717#ifdef CONFIG_MBO
1718 mbo_ap_check_sta_assoc(hapd, sta, &elems);
1719
1720 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
1721 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
1722 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
1723 wpa_printf(MSG_INFO,
1724 "MBO: Reject WPA2 association without PMF");
1725 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1726 }
1727#endif /* CONFIG_MBO */
1728
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001729 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
1730 elems.supp_op_classes_len);
1731
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001732 return WLAN_STATUS_SUCCESS;
1733}
1734
1735
1736static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1737 u16 reason_code)
1738{
1739 int send_len;
1740 struct ieee80211_mgmt reply;
1741
1742 os_memset(&reply, 0, sizeof(reply));
1743 reply.frame_control =
1744 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1745 os_memcpy(reply.da, addr, ETH_ALEN);
1746 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1747 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1748
1749 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1750 reply.u.deauth.reason_code = host_to_le16(reason_code);
1751
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001752 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001753 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1754 strerror(errno));
1755}
1756
1757
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001758static int add_associated_sta(struct hostapd_data *hapd,
1759 struct sta_info *sta)
1760{
1761 struct ieee80211_ht_capabilities ht_cap;
1762 struct ieee80211_vht_capabilities vht_cap;
1763
1764 /*
1765 * Remove the STA entry to ensure the STA PS state gets cleared and
1766 * configuration gets updated. This is relevant for cases, such as
1767 * FT-over-the-DS, where a station re-associates back to the same AP but
1768 * skips the authentication flow, or if working with a driver that
1769 * does not support full AP client state.
1770 */
1771 if (!sta->added_unassoc)
1772 hostapd_drv_sta_remove(hapd, sta->addr);
1773
1774#ifdef CONFIG_IEEE80211N
1775 if (sta->flags & WLAN_STA_HT)
1776 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1777#endif /* CONFIG_IEEE80211N */
1778#ifdef CONFIG_IEEE80211AC
1779 if (sta->flags & WLAN_STA_VHT)
1780 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1781#endif /* CONFIG_IEEE80211AC */
1782
1783 /*
1784 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
1785 * will be set when the ACK frame for the (Re)Association Response frame
1786 * is processed (TX status driver event).
1787 */
1788 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1789 sta->supported_rates, sta->supported_rates_len,
1790 sta->listen_interval,
1791 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1792 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1793 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
1794 sta->vht_opmode, sta->added_unassoc)) {
1795 hostapd_logger(hapd, sta->addr,
1796 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
1797 "Could not %s STA to kernel driver",
1798 sta->added_unassoc ? "set" : "add");
1799
1800 if (sta->added_unassoc) {
1801 hostapd_drv_sta_remove(hapd, sta->addr);
1802 sta->added_unassoc = 0;
1803 }
1804
1805 return -1;
1806 }
1807
1808 sta->added_unassoc = 0;
1809
1810 return 0;
1811}
1812
1813
1814static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1815 u16 status_code, int reassoc, const u8 *ies,
1816 size_t ies_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817{
1818 int send_len;
1819 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1820 struct ieee80211_mgmt *reply;
1821 u8 *p;
1822
1823 os_memset(buf, 0, sizeof(buf));
1824 reply = (struct ieee80211_mgmt *) buf;
1825 reply->frame_control =
1826 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1827 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1828 WLAN_FC_STYPE_ASSOC_RESP));
1829 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1830 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1831 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1832
1833 send_len = IEEE80211_HDRLEN;
1834 send_len += sizeof(reply->u.assoc_resp);
1835 reply->u.assoc_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001836 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001837 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001838 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001839 /* Supported rates */
1840 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1841 /* Extended supported rates */
1842 p = hostapd_eid_ext_supp_rates(hapd, p);
1843
1844#ifdef CONFIG_IEEE80211R
1845 if (status_code == WLAN_STATUS_SUCCESS) {
1846 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1847 * Transition Information, RSN, [RIC Response] */
1848 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1849 buf + sizeof(buf) - p,
1850 sta->auth_alg, ies, ies_len);
1851 }
1852#endif /* CONFIG_IEEE80211R */
1853
1854#ifdef CONFIG_IEEE80211W
1855 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1856 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1857#endif /* CONFIG_IEEE80211W */
1858
1859#ifdef CONFIG_IEEE80211N
1860 p = hostapd_eid_ht_capabilities(hapd, p);
1861 p = hostapd_eid_ht_operation(hapd, p);
1862#endif /* CONFIG_IEEE80211N */
1863
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001864#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001865 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1866 p = hostapd_eid_vht_capabilities(hapd, p);
1867 p = hostapd_eid_vht_operation(hapd, p);
1868 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001869#endif /* CONFIG_IEEE80211AC */
1870
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001871 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001872 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001873 if (sta->qos_map_enabled)
1874 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001875
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001876#ifdef CONFIG_FST
1877 if (hapd->iface->fst_ies) {
1878 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1879 wpabuf_len(hapd->iface->fst_ies));
1880 p += wpabuf_len(hapd->iface->fst_ies);
1881 }
1882#endif /* CONFIG_FST */
1883
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001884#ifdef CONFIG_IEEE80211AC
1885 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1886 p = hostapd_eid_vendor_vht(hapd, p);
1887#endif /* CONFIG_IEEE80211AC */
1888
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001889 if (sta->flags & WLAN_STA_WMM)
1890 p = hostapd_eid_wmm(hapd, p);
1891
1892#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001893 if ((sta->flags & WLAN_STA_WPS) ||
1894 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001895 struct wpabuf *wps = wps_build_assoc_resp_ie();
1896 if (wps) {
1897 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1898 p += wpabuf_len(wps);
1899 wpabuf_free(wps);
1900 }
1901 }
1902#endif /* CONFIG_WPS */
1903
1904#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001905 if (sta->p2p_ie && hapd->p2p_group) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001906 struct wpabuf *p2p_resp_ie;
1907 enum p2p_status_code status;
1908 switch (status_code) {
1909 case WLAN_STATUS_SUCCESS:
1910 status = P2P_SC_SUCCESS;
1911 break;
1912 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1913 status = P2P_SC_FAIL_LIMIT_REACHED;
1914 break;
1915 default:
1916 status = P2P_SC_FAIL_INVALID_PARAMS;
1917 break;
1918 }
1919 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1920 if (p2p_resp_ie) {
1921 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1922 wpabuf_len(p2p_resp_ie));
1923 p += wpabuf_len(p2p_resp_ie);
1924 wpabuf_free(p2p_resp_ie);
1925 }
1926 }
1927#endif /* CONFIG_P2P */
1928
1929#ifdef CONFIG_P2P_MANAGER
1930 if (hapd->conf->p2p & P2P_MANAGE)
1931 p = hostapd_eid_p2p_manage(hapd, p);
1932#endif /* CONFIG_P2P_MANAGER */
1933
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001934 p = hostapd_eid_mbo(hapd, p, buf + sizeof(buf) - p);
1935
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001936 send_len += p - reply->u.assoc_resp.variable;
1937
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001938 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001939 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1940 strerror(errno));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001941 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1942 }
1943
1944 return WLAN_STATUS_SUCCESS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001945}
1946
1947
1948static void handle_assoc(struct hostapd_data *hapd,
1949 const struct ieee80211_mgmt *mgmt, size_t len,
1950 int reassoc)
1951{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001952 u16 capab_info, listen_interval, seq_ctrl, fc;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001953 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001954 const u8 *pos;
1955 int left, i;
1956 struct sta_info *sta;
1957
1958 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1959 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001960 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1961 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001962 return;
1963 }
1964
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001965#ifdef CONFIG_TESTING_OPTIONS
1966 if (reassoc) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001967 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001968 drand48() < hapd->iconf->ignore_reassoc_probability) {
1969 wpa_printf(MSG_INFO,
1970 "TESTING: ignoring reassoc request from "
1971 MACSTR, MAC2STR(mgmt->sa));
1972 return;
1973 }
1974 } else {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001975 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001976 drand48() < hapd->iconf->ignore_assoc_probability) {
1977 wpa_printf(MSG_INFO,
1978 "TESTING: ignoring assoc request from "
1979 MACSTR, MAC2STR(mgmt->sa));
1980 return;
1981 }
1982 }
1983#endif /* CONFIG_TESTING_OPTIONS */
1984
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001985 fc = le_to_host16(mgmt->frame_control);
1986 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1987
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001988 if (reassoc) {
1989 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1990 listen_interval = le_to_host16(
1991 mgmt->u.reassoc_req.listen_interval);
1992 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1993 " capab_info=0x%02x listen_interval=%d current_ap="
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001994 MACSTR " seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001995 MAC2STR(mgmt->sa), capab_info, listen_interval,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001996 MAC2STR(mgmt->u.reassoc_req.current_ap),
1997 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001998 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1999 pos = mgmt->u.reassoc_req.variable;
2000 } else {
2001 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
2002 listen_interval = le_to_host16(
2003 mgmt->u.assoc_req.listen_interval);
2004 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002005 " capab_info=0x%02x listen_interval=%d "
2006 "seq_ctrl=0x%x%s",
2007 MAC2STR(mgmt->sa), capab_info, listen_interval,
2008 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002009 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
2010 pos = mgmt->u.assoc_req.variable;
2011 }
2012
2013 sta = ap_get_sta(hapd, mgmt->sa);
2014#ifdef CONFIG_IEEE80211R
2015 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
2016 (sta->flags & WLAN_STA_AUTH) == 0) {
2017 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
2018 "prior to authentication since it is using "
2019 "over-the-DS FT", MAC2STR(mgmt->sa));
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002020
2021 /*
2022 * Mark station as authenticated, to avoid adding station
2023 * entry in the driver as associated and not authenticated
2024 */
2025 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002026 } else
2027#endif /* CONFIG_IEEE80211R */
2028 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
2029 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2030 HOSTAPD_LEVEL_INFO, "Station tried to "
2031 "associate before authentication "
2032 "(aid=%d flags=0x%x)",
2033 sta ? sta->aid : -1,
2034 sta ? sta->flags : 0);
2035 send_deauth(hapd, mgmt->sa,
2036 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
2037 return;
2038 }
2039
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002040 if ((fc & WLAN_FC_RETRY) &&
2041 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2042 sta->last_seq_ctrl == seq_ctrl &&
2043 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2044 WLAN_FC_STYPE_ASSOC_REQ) {
2045 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2046 HOSTAPD_LEVEL_DEBUG,
2047 "Drop repeated association frame seq_ctrl=0x%x",
2048 seq_ctrl);
2049 return;
2050 }
2051 sta->last_seq_ctrl = seq_ctrl;
2052 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2053 WLAN_FC_STYPE_ASSOC_REQ;
2054
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002055 if (hapd->tkip_countermeasures) {
2056 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
2057 goto fail;
2058 }
2059
2060 if (listen_interval > hapd->conf->max_listen_interval) {
2061 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2062 HOSTAPD_LEVEL_DEBUG,
2063 "Too large Listen Interval (%d)",
2064 listen_interval);
2065 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
2066 goto fail;
2067 }
2068
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002069#ifdef CONFIG_MBO
2070 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
2071 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2072 goto fail;
2073 }
2074#endif /* CONFIG_MBO */
2075
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002076 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
2077 * is used */
2078 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
2079 if (resp != WLAN_STATUS_SUCCESS)
2080 goto fail;
2081
2082 if (hostapd_get_aid(hapd, sta) < 0) {
2083 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2084 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
2085 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2086 goto fail;
2087 }
2088
2089 sta->capability = capab_info;
2090 sta->listen_interval = listen_interval;
2091
2092 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
2093 sta->flags |= WLAN_STA_NONERP;
2094 for (i = 0; i < sta->supported_rates_len; i++) {
2095 if ((sta->supported_rates[i] & 0x7f) > 22) {
2096 sta->flags &= ~WLAN_STA_NONERP;
2097 break;
2098 }
2099 }
2100 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
2101 sta->nonerp_set = 1;
2102 hapd->iface->num_sta_non_erp++;
2103 if (hapd->iface->num_sta_non_erp == 1)
2104 ieee802_11_set_beacons(hapd->iface);
2105 }
2106
2107 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
2108 !sta->no_short_slot_time_set) {
2109 sta->no_short_slot_time_set = 1;
2110 hapd->iface->num_sta_no_short_slot_time++;
2111 if (hapd->iface->current_mode->mode ==
2112 HOSTAPD_MODE_IEEE80211G &&
2113 hapd->iface->num_sta_no_short_slot_time == 1)
2114 ieee802_11_set_beacons(hapd->iface);
2115 }
2116
2117 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2118 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
2119 else
2120 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
2121
2122 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
2123 !sta->no_short_preamble_set) {
2124 sta->no_short_preamble_set = 1;
2125 hapd->iface->num_sta_no_short_preamble++;
2126 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
2127 && hapd->iface->num_sta_no_short_preamble == 1)
2128 ieee802_11_set_beacons(hapd->iface);
2129 }
2130
2131#ifdef CONFIG_IEEE80211N
2132 update_ht_state(hapd, sta);
2133#endif /* CONFIG_IEEE80211N */
2134
2135 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2136 HOSTAPD_LEVEL_DEBUG,
2137 "association OK (aid %d)", sta->aid);
2138 /* Station will be marked associated, after it acknowledges AssocResp
2139 */
2140 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
2141
2142#ifdef CONFIG_IEEE80211W
2143 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
2144 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
2145 "SA Query procedure", reassoc ? "re" : "");
2146 /* TODO: Send a protected Disassociate frame to the STA using
2147 * the old key and Reason Code "Previous Authentication no
2148 * longer valid". Make sure this is only sent protected since
2149 * unprotected frame would be received by the STA that is now
2150 * trying to associate.
2151 */
2152 }
2153#endif /* CONFIG_IEEE80211W */
2154
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155 /* Make sure that the previously registered inactivity timer will not
2156 * remove the STA immediately. */
2157 sta->timeout_next = STA_NULLFUNC;
2158
2159 fail:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002160 /*
2161 * In case of a successful response, add the station to the driver.
2162 * Otherwise, the kernel may ignore Data frames before we process the
2163 * ACK frame (TX status). In case of a failure, this station will be
2164 * removed.
2165 *
2166 * Note that this is not compliant with the IEEE 802.11 standard that
2167 * states that a non-AP station should transition into the
2168 * authenticated/associated state only after the station acknowledges
2169 * the (Re)Association Response frame. However, still do this as:
2170 *
2171 * 1. In case the station does not acknowledge the (Re)Association
2172 * Response frame, it will be removed.
2173 * 2. Data frames will be dropped in the kernel until the station is
2174 * set into authorized state, and there are no significant known
2175 * issues with processing other non-Data Class 3 frames during this
2176 * window.
2177 */
2178 if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta))
2179 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2180
2181 reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
2182
2183 /*
2184 * Remove the station in case tranmission of a success response fails
2185 * (the STA was added associated to the driver) or if the station was
2186 * previously added unassociated.
2187 */
2188 if ((reply_res != WLAN_STATUS_SUCCESS &&
2189 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) {
2190 hostapd_drv_sta_remove(hapd, sta->addr);
2191 sta->added_unassoc = 0;
2192 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002193}
2194
2195
2196static void handle_disassoc(struct hostapd_data *hapd,
2197 const struct ieee80211_mgmt *mgmt, size_t len)
2198{
2199 struct sta_info *sta;
2200
2201 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002202 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
2203 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002204 return;
2205 }
2206
2207 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
2208 MAC2STR(mgmt->sa),
2209 le_to_host16(mgmt->u.disassoc.reason_code));
2210
2211 sta = ap_get_sta(hapd, mgmt->sa);
2212 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002213 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2214 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002215 return;
2216 }
2217
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002218 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002219 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002220 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002221 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2222 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2223 HOSTAPD_LEVEL_INFO, "disassociated");
2224 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2225 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2226 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2227 * authenticated. */
2228 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -08002229 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002230 if (sta->ipaddr)
2231 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2232 ap_sta_ip6addr_del(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002233 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002234 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002235
2236 if (sta->timeout_next == STA_NULLFUNC ||
2237 sta->timeout_next == STA_DISASSOC) {
2238 sta->timeout_next = STA_DEAUTH;
2239 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2240 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2241 hapd, sta);
2242 }
2243
2244 mlme_disassociate_indication(
2245 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2246}
2247
2248
2249static void handle_deauth(struct hostapd_data *hapd,
2250 const struct ieee80211_mgmt *mgmt, size_t len)
2251{
2252 struct sta_info *sta;
2253
2254 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002255 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2256 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002257 return;
2258 }
2259
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002260 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002261 " reason_code=%d",
2262 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2263
2264 sta = ap_get_sta(hapd, mgmt->sa);
2265 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002266 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2267 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002268 MAC2STR(mgmt->sa));
2269 return;
2270 }
2271
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002272 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002273 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2275 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002276 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2277 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2278 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2279 mlme_deauthenticate_indication(
2280 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2281 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2282 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2283 ap_free_sta(hapd, sta);
2284}
2285
2286
2287static void handle_beacon(struct hostapd_data *hapd,
2288 const struct ieee80211_mgmt *mgmt, size_t len,
2289 struct hostapd_frame_info *fi)
2290{
2291 struct ieee802_11_elems elems;
2292
2293 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002294 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2295 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002296 return;
2297 }
2298
2299 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2300 len - (IEEE80211_HDRLEN +
2301 sizeof(mgmt->u.beacon)), &elems,
2302 0);
2303
2304 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2305}
2306
2307
2308#ifdef CONFIG_IEEE80211W
2309
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002310static int hostapd_sa_query_action(struct hostapd_data *hapd,
2311 const struct ieee80211_mgmt *mgmt,
2312 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002313{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002314 const u8 *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002315
2316 end = mgmt->u.action.u.sa_query_resp.trans_id +
2317 WLAN_SA_QUERY_TR_ID_LEN;
2318 if (((u8 *) mgmt) + len < end) {
2319 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2320 "frame (len=%lu)", (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002321 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002322 }
2323
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002324 ieee802_11_sa_query_action(hapd, mgmt->sa,
2325 mgmt->u.action.u.sa_query_resp.action,
2326 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002327 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002328}
2329
2330
2331static int robust_action_frame(u8 category)
2332{
2333 return category != WLAN_ACTION_PUBLIC &&
2334 category != WLAN_ACTION_HT;
2335}
2336#endif /* CONFIG_IEEE80211W */
2337
2338
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002339static int handle_action(struct hostapd_data *hapd,
2340 const struct ieee80211_mgmt *mgmt, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002341{
2342 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002343 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002344
2345 if (len < IEEE80211_HDRLEN + 1) {
2346 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2347 HOSTAPD_LEVEL_DEBUG,
2348 "handle_action - too short payload (len=%lu)",
2349 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002350 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002351 }
2352
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002353 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2354 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2355 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2356 "frame (category=%u) from unassociated STA " MACSTR,
2357 MAC2STR(mgmt->sa), mgmt->u.action.category);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002358 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002359 }
2360
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002361#ifdef CONFIG_IEEE80211W
2362 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08002363 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2364 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002365 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2366 HOSTAPD_LEVEL_DEBUG,
2367 "Dropped unprotected Robust Action frame from "
2368 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002369 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002370 }
2371#endif /* CONFIG_IEEE80211W */
2372
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002373 if (sta) {
2374 u16 fc = le_to_host16(mgmt->frame_control);
2375 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2376
2377 if ((fc & WLAN_FC_RETRY) &&
2378 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2379 sta->last_seq_ctrl == seq_ctrl &&
2380 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2381 hostapd_logger(hapd, sta->addr,
2382 HOSTAPD_MODULE_IEEE80211,
2383 HOSTAPD_LEVEL_DEBUG,
2384 "Drop repeated action frame seq_ctrl=0x%x",
2385 seq_ctrl);
2386 return 1;
2387 }
2388
2389 sta->last_seq_ctrl = seq_ctrl;
2390 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2391 }
2392
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002393 switch (mgmt->u.action.category) {
2394#ifdef CONFIG_IEEE80211R
2395 case WLAN_ACTION_FT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002396 if (!sta ||
2397 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002398 len - IEEE80211_HDRLEN))
2399 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002400 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002401#endif /* CONFIG_IEEE80211R */
2402 case WLAN_ACTION_WMM:
2403 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002404 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002405#ifdef CONFIG_IEEE80211W
2406 case WLAN_ACTION_SA_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002407 return hostapd_sa_query_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002408#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002409#ifdef CONFIG_WNM
2410 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002411 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2412 return 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002413#endif /* CONFIG_WNM */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002414#ifdef CONFIG_FST
2415 case WLAN_ACTION_FST:
2416 if (hapd->iface->fst)
2417 fst_rx_action(hapd->iface->fst, mgmt, len);
2418 else
2419 wpa_printf(MSG_DEBUG,
2420 "FST: Ignore FST Action frame - no FST attached");
2421 return 1;
2422#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002423 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08002424 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002425#ifdef CONFIG_IEEE80211N
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07002426 if (len >= IEEE80211_HDRLEN + 2 &&
2427 mgmt->u.action.u.public_action.action ==
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002428 WLAN_PA_20_40_BSS_COEX) {
2429 wpa_printf(MSG_DEBUG,
2430 "HT20/40 coex mgmt frame received from STA "
2431 MACSTR, MAC2STR(mgmt->sa));
2432 hostapd_2040_coex_action(hapd, mgmt, len);
2433 }
2434#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002435 if (hapd->public_action_cb) {
2436 hapd->public_action_cb(hapd->public_action_cb_ctx,
2437 (u8 *) mgmt, len,
2438 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002439 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002440 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002441 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002442 (u8 *) mgmt, len,
2443 hapd->iface->freq);
2444 }
2445 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002446 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002447 break;
2448 case WLAN_ACTION_VENDOR_SPECIFIC:
2449 if (hapd->vendor_action_cb) {
2450 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2451 (u8 *) mgmt, len,
2452 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002453 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002454 }
2455 break;
2456 }
2457
2458 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2459 HOSTAPD_LEVEL_DEBUG,
2460 "handle_action - unknown action category %d or invalid "
2461 "frame",
2462 mgmt->u.action.category);
2463 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2464 !(mgmt->sa[0] & 0x01)) {
2465 struct ieee80211_mgmt *resp;
2466
2467 /*
2468 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2469 * Return the Action frame to the source without change
2470 * except that MSB of the Category set to 1.
2471 */
2472 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2473 "frame back to sender");
2474 resp = os_malloc(len);
2475 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002476 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002477 os_memcpy(resp, mgmt, len);
2478 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2479 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2480 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2481 resp->u.action.category |= 0x80;
2482
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002483 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2484 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2485 "Action frame");
2486 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002487 os_free(resp);
2488 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002489
2490 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002491}
2492
2493
2494/**
2495 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2496 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2497 * sent to)
2498 * @buf: management frame data (starting from IEEE 802.11 header)
2499 * @len: length of frame data in octets
2500 * @fi: meta data about received frame (signal level, etc.)
2501 *
2502 * Process all incoming IEEE 802.11 management frames. This will be called for
2503 * each frame received from the kernel driver through wlan#ap interface. In
2504 * addition, it can be called to re-inserted pending frames (e.g., when using
2505 * external RADIUS server as an MAC ACL).
2506 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002507int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2508 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002509{
2510 struct ieee80211_mgmt *mgmt;
2511 int broadcast;
2512 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002513 int ret = 0;
2514
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002515 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002516 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002517
2518 mgmt = (struct ieee80211_mgmt *) buf;
2519 fc = le_to_host16(mgmt->frame_control);
2520 stype = WLAN_FC_GET_STYPE(fc);
2521
2522 if (stype == WLAN_FC_STYPE_BEACON) {
2523 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002524 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002525 }
2526
2527 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2528 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2529 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2530
2531 if (!broadcast &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002532#ifdef CONFIG_P2P
2533 /* Invitation responses can be sent with the peer MAC as BSSID */
2534 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2535 stype == WLAN_FC_STYPE_ACTION) &&
2536#endif /* CONFIG_P2P */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002537#ifdef CONFIG_MESH
2538 !(hapd->conf->mesh & MESH_ENABLED) &&
2539#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002540 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002541 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2542 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002543 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002544 }
2545
2546
2547 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002548 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002549 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002550 }
2551
2552 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2553 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2554 HOSTAPD_LEVEL_DEBUG,
2555 "MGMT: DA=" MACSTR " not our address",
2556 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002557 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002558 }
2559
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002560 if (hapd->iconf->track_sta_max_num)
2561 sta_track_add(hapd->iface, mgmt->sa);
2562
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002563 switch (stype) {
2564 case WLAN_FC_STYPE_AUTH:
2565 wpa_printf(MSG_DEBUG, "mgmt::auth");
2566 handle_auth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002567 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002568 break;
2569 case WLAN_FC_STYPE_ASSOC_REQ:
2570 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2571 handle_assoc(hapd, mgmt, len, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002572 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002573 break;
2574 case WLAN_FC_STYPE_REASSOC_REQ:
2575 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2576 handle_assoc(hapd, mgmt, len, 1);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002577 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002578 break;
2579 case WLAN_FC_STYPE_DISASSOC:
2580 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2581 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002582 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002583 break;
2584 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002585 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002586 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002587 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002588 break;
2589 case WLAN_FC_STYPE_ACTION:
2590 wpa_printf(MSG_DEBUG, "mgmt::action");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002591 ret = handle_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002592 break;
2593 default:
2594 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2595 HOSTAPD_LEVEL_DEBUG,
2596 "unknown mgmt frame subtype %d", stype);
2597 break;
2598 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002599
2600 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002601}
2602
2603
2604static void handle_auth_cb(struct hostapd_data *hapd,
2605 const struct ieee80211_mgmt *mgmt,
2606 size_t len, int ok)
2607{
2608 u16 auth_alg, auth_transaction, status_code;
2609 struct sta_info *sta;
2610
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002611 sta = ap_get_sta(hapd, mgmt->da);
2612 if (!sta) {
2613 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2614 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002615 return;
2616 }
2617
2618 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2619 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2620 status_code = le_to_host16(mgmt->u.auth.status_code);
2621
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002622 if (!ok) {
2623 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2624 HOSTAPD_LEVEL_NOTICE,
2625 "did not acknowledge authentication response");
2626 goto fail;
2627 }
2628
2629 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2630 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2631 (unsigned long) len);
2632 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002633 }
2634
2635 if (status_code == WLAN_STATUS_SUCCESS &&
2636 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2637 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2638 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2639 HOSTAPD_LEVEL_INFO, "authenticated");
2640 sta->flags |= WLAN_STA_AUTH;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002641 if (sta->added_unassoc)
2642 hostapd_set_sta_flags(hapd, sta);
2643 return;
2644 }
2645
2646fail:
2647 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
2648 hostapd_drv_sta_remove(hapd, sta->addr);
2649 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002650 }
2651}
2652
2653
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002654static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2655 struct sta_info *sta,
2656 char *ifname_wds)
2657{
2658 int i;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002659 struct hostapd_ssid *ssid = &hapd->conf->ssid;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002660
2661 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2662 return;
2663
2664 for (i = 0; i < 4; i++) {
2665 if (ssid->wep.key[i] &&
2666 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2667 i == ssid->wep.idx, NULL, 0,
2668 ssid->wep.key[i], ssid->wep.len[i])) {
2669 wpa_printf(MSG_WARNING,
2670 "Could not set WEP keys for WDS interface; %s",
2671 ifname_wds);
2672 break;
2673 }
2674 }
2675}
2676
2677
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002678static void handle_assoc_cb(struct hostapd_data *hapd,
2679 const struct ieee80211_mgmt *mgmt,
2680 size_t len, int reassoc, int ok)
2681{
2682 u16 status;
2683 struct sta_info *sta;
2684 int new_assoc = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002685
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002686 sta = ap_get_sta(hapd, mgmt->da);
2687 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002688 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2689 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002690 return;
2691 }
2692
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002693 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2694 sizeof(mgmt->u.assoc_resp))) {
2695 wpa_printf(MSG_INFO,
2696 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2697 reassoc, (unsigned long) len);
2698 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002699 return;
2700 }
2701
2702 if (reassoc)
2703 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2704 else
2705 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2706
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002707 if (!ok) {
2708 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2709 HOSTAPD_LEVEL_DEBUG,
2710 "did not acknowledge association response");
2711 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2712 /* The STA is added only in case of SUCCESS */
2713 if (status == WLAN_STATUS_SUCCESS)
2714 hostapd_drv_sta_remove(hapd, sta->addr);
2715
2716 return;
2717 }
2718
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002719 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002720 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002721
2722 /* Stop previous accounting session, if one is started, and allocate
2723 * new session id for the new session. */
2724 accounting_sta_stop(hapd, sta);
2725
2726 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2727 HOSTAPD_LEVEL_INFO,
2728 "associated (aid %d)",
2729 sta->aid);
2730
2731 if (sta->flags & WLAN_STA_ASSOC)
2732 new_assoc = 0;
2733 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002734 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002735 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002736 sta->auth_alg == WLAN_AUTH_FT) {
2737 /*
2738 * Open, static WEP, or FT protocol; no separate authorization
2739 * step.
2740 */
2741 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002742 }
2743
2744 if (reassoc)
2745 mlme_reassociate_indication(hapd, sta);
2746 else
2747 mlme_associate_indication(hapd, sta);
2748
2749#ifdef CONFIG_IEEE80211W
2750 sta->sa_query_timed_out = 0;
2751#endif /* CONFIG_IEEE80211W */
2752
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002753 if (sta->flags & WLAN_STA_WDS) {
2754 int ret;
2755 char ifname_wds[IFNAMSIZ + 1];
2756
2757 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2758 sta->aid, 1);
2759 if (!ret)
2760 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2761 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002762
2763 if (sta->eapol_sm == NULL) {
2764 /*
2765 * This STA does not use RADIUS server for EAP authentication,
2766 * so bind it to the selected VLAN interface now, since the
2767 * interface selection is not going to change anymore.
2768 */
Dmitry Shmidt83474442015-04-15 13:47:09 -07002769 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002770 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002771 } else if (sta->vlan_id) {
2772 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
Dmitry Shmidt83474442015-04-15 13:47:09 -07002773 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002774 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002775 }
2776
2777 hostapd_set_sta_flags(hapd, sta);
2778
2779 if (sta->auth_alg == WLAN_AUTH_FT)
2780 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2781 else
2782 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2783 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002784 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08002785
2786 if (sta->pending_eapol_rx) {
2787 struct os_reltime now, age;
2788
2789 os_get_reltime(&now);
2790 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
2791 if (age.sec == 0 && age.usec < 200000) {
2792 wpa_printf(MSG_DEBUG,
2793 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
2794 MAC2STR(sta->addr));
2795 ieee802_1x_receive(
2796 hapd, mgmt->da,
2797 wpabuf_head(sta->pending_eapol_rx->buf),
2798 wpabuf_len(sta->pending_eapol_rx->buf));
2799 }
2800 wpabuf_free(sta->pending_eapol_rx->buf);
2801 os_free(sta->pending_eapol_rx);
2802 sta->pending_eapol_rx = NULL;
2803 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002804}
2805
2806
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002807static void handle_deauth_cb(struct hostapd_data *hapd,
2808 const struct ieee80211_mgmt *mgmt,
2809 size_t len, int ok)
2810{
2811 struct sta_info *sta;
2812 if (mgmt->da[0] & 0x01)
2813 return;
2814 sta = ap_get_sta(hapd, mgmt->da);
2815 if (!sta) {
2816 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2817 " not found", MAC2STR(mgmt->da));
2818 return;
2819 }
2820 if (ok)
2821 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2822 MAC2STR(sta->addr));
2823 else
2824 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2825 "deauth", MAC2STR(sta->addr));
2826
2827 ap_sta_deauth_cb(hapd, sta);
2828}
2829
2830
2831static void handle_disassoc_cb(struct hostapd_data *hapd,
2832 const struct ieee80211_mgmt *mgmt,
2833 size_t len, int ok)
2834{
2835 struct sta_info *sta;
2836 if (mgmt->da[0] & 0x01)
2837 return;
2838 sta = ap_get_sta(hapd, mgmt->da);
2839 if (!sta) {
2840 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2841 " not found", MAC2STR(mgmt->da));
2842 return;
2843 }
2844 if (ok)
2845 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2846 MAC2STR(sta->addr));
2847 else
2848 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2849 "disassoc", MAC2STR(sta->addr));
2850
2851 ap_sta_disassoc_cb(hapd, sta);
2852}
2853
2854
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002855/**
2856 * ieee802_11_mgmt_cb - Process management frame TX status callback
2857 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2858 * was sent from)
2859 * @buf: management frame data (starting from IEEE 802.11 header)
2860 * @len: length of frame data in octets
2861 * @stype: management frame subtype from frame control field
2862 * @ok: Whether the frame was ACK'ed
2863 */
2864void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2865 u16 stype, int ok)
2866{
2867 const struct ieee80211_mgmt *mgmt;
2868 mgmt = (const struct ieee80211_mgmt *) buf;
2869
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002870#ifdef CONFIG_TESTING_OPTIONS
2871 if (hapd->ext_mgmt_frame_handling) {
2872 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2873 stype, ok);
2874 return;
2875 }
2876#endif /* CONFIG_TESTING_OPTIONS */
2877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878 switch (stype) {
2879 case WLAN_FC_STYPE_AUTH:
2880 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2881 handle_auth_cb(hapd, mgmt, len, ok);
2882 break;
2883 case WLAN_FC_STYPE_ASSOC_RESP:
2884 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2885 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2886 break;
2887 case WLAN_FC_STYPE_REASSOC_RESP:
2888 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2889 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2890 break;
2891 case WLAN_FC_STYPE_PROBE_RESP:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002892 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002893 break;
2894 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002895 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2896 handle_deauth_cb(hapd, mgmt, len, ok);
2897 break;
2898 case WLAN_FC_STYPE_DISASSOC:
2899 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2900 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002901 break;
2902 case WLAN_FC_STYPE_ACTION:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002903 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904 break;
2905 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002906 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002907 break;
2908 }
2909}
2910
2911
2912int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2913{
2914 /* TODO */
2915 return 0;
2916}
2917
2918
2919int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2920 char *buf, size_t buflen)
2921{
2922 /* TODO */
2923 return 0;
2924}
2925
2926
2927void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2928 const u8 *buf, size_t len, int ack)
2929{
2930 struct sta_info *sta;
2931 struct hostapd_iface *iface = hapd->iface;
2932
2933 sta = ap_get_sta(hapd, addr);
2934 if (sta == NULL && iface->num_bss > 1) {
2935 size_t j;
2936 for (j = 0; j < iface->num_bss; j++) {
2937 hapd = iface->bss[j];
2938 sta = ap_get_sta(hapd, addr);
2939 if (sta)
2940 break;
2941 }
2942 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002943 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002944 return;
2945 if (sta->flags & WLAN_STA_PENDING_POLL) {
2946 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2947 "activity poll", MAC2STR(sta->addr),
2948 ack ? "ACKed" : "did not ACK");
2949 if (ack)
2950 sta->flags &= ~WLAN_STA_PENDING_POLL;
2951 }
2952
2953 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2954}
2955
2956
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002957void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2958 const u8 *data, size_t len, int ack)
2959{
2960 struct sta_info *sta;
2961 struct hostapd_iface *iface = hapd->iface;
2962
2963 sta = ap_get_sta(hapd, dst);
2964 if (sta == NULL && iface->num_bss > 1) {
2965 size_t j;
2966 for (j = 0; j < iface->num_bss; j++) {
2967 hapd = iface->bss[j];
2968 sta = ap_get_sta(hapd, dst);
2969 if (sta)
2970 break;
2971 }
2972 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002973 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2974 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2975 MACSTR " that is not currently associated",
2976 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002977 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002978 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002979
2980 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2981}
2982
2983
2984void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2985{
2986 struct sta_info *sta;
2987 struct hostapd_iface *iface = hapd->iface;
2988
2989 sta = ap_get_sta(hapd, addr);
2990 if (sta == NULL && iface->num_bss > 1) {
2991 size_t j;
2992 for (j = 0; j < iface->num_bss; j++) {
2993 hapd = iface->bss[j];
2994 sta = ap_get_sta(hapd, addr);
2995 if (sta)
2996 break;
2997 }
2998 }
2999 if (sta == NULL)
3000 return;
3001 if (!(sta->flags & WLAN_STA_PENDING_POLL))
3002 return;
3003
3004 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
3005 "activity poll", MAC2STR(sta->addr));
3006 sta->flags &= ~WLAN_STA_PENDING_POLL;
3007}
3008
3009
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003010void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
3011 int wds)
3012{
3013 struct sta_info *sta;
3014
3015 sta = ap_get_sta(hapd, src);
3016 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07003017 if (!hapd->conf->wds_sta)
3018 return;
3019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003020 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003021 int ret;
3022 char ifname_wds[IFNAMSIZ + 1];
3023
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003024 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
3025 "STA " MACSTR " (aid %u)",
3026 MAC2STR(sta->addr), sta->aid);
3027 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003028 ret = hostapd_set_wds_sta(hapd, ifname_wds,
3029 sta->addr, sta->aid, 1);
3030 if (!ret)
3031 hostapd_set_wds_encryption(hapd, sta,
3032 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003033 }
3034 return;
3035 }
3036
3037 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
3038 MACSTR, MAC2STR(src));
3039 if (src[0] & 0x01) {
3040 /* Broadcast bit set in SA?! Ignore the frame silently. */
3041 return;
3042 }
3043
3044 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
3045 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
3046 "already been sent, but no TX status yet known - "
3047 "ignore Class 3 frame issue with " MACSTR,
3048 MAC2STR(src));
3049 return;
3050 }
3051
3052 if (sta && (sta->flags & WLAN_STA_AUTH))
3053 hostapd_drv_sta_disassoc(
3054 hapd, src,
3055 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3056 else
3057 hostapd_drv_sta_deauth(
3058 hapd, src,
3059 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3060}
3061
3062
3063#endif /* CONFIG_NATIVE_WINDOWS */