blob: db20c86790936b8be17847039c29139b8e54a8e3 [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"
26#include "hostapd.h"
27#include "beacon.h"
28#include "ieee802_11_auth.h"
29#include "sta_info.h"
30#include "ieee802_1x.h"
31#include "wpa_auth.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080032#include "pmksa_cache_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "wmm.h"
34#include "ap_list.h"
35#include "accounting.h"
36#include "ap_config.h"
37#include "ap_mlme.h"
38#include "p2p_hostapd.h"
39#include "ap_drv_ops.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080040#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "ieee802_11.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080042#include "dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043
44
45u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
46{
47 u8 *pos = eid;
48 int i, num, count;
49
50 if (hapd->iface->current_rates == NULL)
51 return eid;
52
53 *pos++ = WLAN_EID_SUPP_RATES;
54 num = hapd->iface->num_rates;
55 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
56 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080057 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
58 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070059 if (num > 8) {
60 /* rest of the rates are encoded in Extended supported
61 * rates element */
62 num = 8;
63 }
64
65 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070066 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
67 i++) {
68 count++;
69 *pos = hapd->iface->current_rates[i].rate / 5;
70 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
71 *pos |= 0x80;
72 pos++;
73 }
74
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080075 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
76 count++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070077 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080078 }
79
80 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
81 count++;
82 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
83 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084
85 return pos;
86}
87
88
89u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
90{
91 u8 *pos = eid;
92 int i, num, count;
93
94 if (hapd->iface->current_rates == NULL)
95 return eid;
96
97 num = hapd->iface->num_rates;
98 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
99 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800100 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
101 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700102 if (num <= 8)
103 return eid;
104 num -= 8;
105
106 *pos++ = WLAN_EID_EXT_SUPP_RATES;
107 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700108 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
109 i++) {
110 count++;
111 if (count <= 8)
112 continue; /* already in SuppRates IE */
113 *pos = hapd->iface->current_rates[i].rate / 5;
114 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
115 *pos |= 0x80;
116 pos++;
117 }
118
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800119 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
120 count++;
121 if (count > 8)
122 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
123 }
124
125 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
126 count++;
127 if (count > 8)
128 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
129 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700130
131 return pos;
132}
133
134
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700135u16 hostapd_own_capab_info(struct hostapd_data *hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700136{
137 int capab = WLAN_CAPABILITY_ESS;
138 int privacy;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800139 int dfs;
140
141 /* Check if any of configured channels require DFS */
142 dfs = hostapd_is_dfs_required(hapd->iface);
143 if (dfs < 0) {
144 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
145 dfs);
146 dfs = 0;
147 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700148
149 if (hapd->iface->num_sta_no_short_preamble == 0 &&
150 hapd->iconf->preamble == SHORT_PREAMBLE)
151 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
152
153 privacy = hapd->conf->ssid.wep.keys_set;
154
155 if (hapd->conf->ieee802_1x &&
156 (hapd->conf->default_wep_key_len ||
157 hapd->conf->individual_wep_key_len))
158 privacy = 1;
159
160 if (hapd->conf->wpa)
161 privacy = 1;
162
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800163#ifdef CONFIG_HS20
164 if (hapd->conf->osen)
165 privacy = 1;
166#endif /* CONFIG_HS20 */
167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168 if (privacy)
169 capab |= WLAN_CAPABILITY_PRIVACY;
170
171 if (hapd->iface->current_mode &&
172 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
173 hapd->iface->num_sta_no_short_slot_time == 0)
174 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
175
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800176 /*
177 * Currently, Spectrum Management capability bit is set when directly
178 * requested in configuration by spectrum_mgmt_required or when AP is
179 * running on DFS channel.
180 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
181 */
182 if (hapd->iface->current_mode &&
183 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
184 (hapd->iconf->spectrum_mgmt_required || dfs))
185 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
186
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800187 if (hapd->conf->radio_measurements)
188 capab |= IEEE80211_CAP_RRM;
189
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700190 return capab;
191}
192
193
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700194static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
195 u16 auth_transaction, const u8 *challenge,
196 int iswep)
197{
198 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
199 HOSTAPD_LEVEL_DEBUG,
200 "authentication (shared key, transaction %d)",
201 auth_transaction);
202
203 if (auth_transaction == 1) {
204 if (!sta->challenge) {
205 /* Generate a pseudo-random challenge */
206 u8 key[8];
207 struct os_time now;
208 int r;
209 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
210 if (sta->challenge == NULL)
211 return WLAN_STATUS_UNSPECIFIED_FAILURE;
212
213 os_get_time(&now);
214 r = os_random();
215 os_memcpy(key, &now.sec, 4);
216 os_memcpy(key + 4, &r, 4);
217 rc4_skip(key, sizeof(key), 0,
218 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
219 }
220 return 0;
221 }
222
223 if (auth_transaction != 3)
224 return WLAN_STATUS_UNSPECIFIED_FAILURE;
225
226 /* Transaction 3 */
227 if (!iswep || !sta->challenge || !challenge ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700228 os_memcmp_const(sta->challenge, challenge,
229 WLAN_AUTH_CHALLENGE_LEN)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700230 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
231 HOSTAPD_LEVEL_INFO,
232 "shared key authentication - invalid "
233 "challenge-response");
234 return WLAN_STATUS_CHALLENGE_FAIL;
235 }
236
237 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
238 HOSTAPD_LEVEL_DEBUG,
239 "authentication OK (shared key)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240 sta->flags |= WLAN_STA_AUTH;
241 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242 os_free(sta->challenge);
243 sta->challenge = NULL;
244
245 return 0;
246}
247
248
249static void send_auth_reply(struct hostapd_data *hapd,
250 const u8 *dst, const u8 *bssid,
251 u16 auth_alg, u16 auth_transaction, u16 resp,
252 const u8 *ies, size_t ies_len)
253{
254 struct ieee80211_mgmt *reply;
255 u8 *buf;
256 size_t rlen;
257
258 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
259 buf = os_zalloc(rlen);
260 if (buf == NULL)
261 return;
262
263 reply = (struct ieee80211_mgmt *) buf;
264 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
265 WLAN_FC_STYPE_AUTH);
266 os_memcpy(reply->da, dst, ETH_ALEN);
267 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
268 os_memcpy(reply->bssid, bssid, ETH_ALEN);
269
270 reply->u.auth.auth_alg = host_to_le16(auth_alg);
271 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
272 reply->u.auth.status_code = host_to_le16(resp);
273
274 if (ies && ies_len)
275 os_memcpy(reply->u.auth.variable, ies, ies_len);
276
277 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
278 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
279 MAC2STR(dst), auth_alg, auth_transaction,
280 resp, (unsigned long) ies_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800281 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800282 wpa_printf(MSG_INFO, "send_auth_reply: send");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283
284 os_free(buf);
285}
286
287
288#ifdef CONFIG_IEEE80211R
289static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
290 u16 auth_transaction, u16 status,
291 const u8 *ies, size_t ies_len)
292{
293 struct hostapd_data *hapd = ctx;
294 struct sta_info *sta;
295
296 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
297 status, ies, ies_len);
298
299 if (status != WLAN_STATUS_SUCCESS)
300 return;
301
302 sta = ap_get_sta(hapd, dst);
303 if (sta == NULL)
304 return;
305
306 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
307 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
308 sta->flags |= WLAN_STA_AUTH;
309 mlme_authenticate_indication(hapd, sta);
310}
311#endif /* CONFIG_IEEE80211R */
312
313
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800314#ifdef CONFIG_SAE
315
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800316#define dot11RSNASAERetransPeriod 40 /* msec */
317#define dot11RSNASAESync 5 /* attempts */
318
319
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800320static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
321 struct sta_info *sta, int update)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800322{
323 struct wpabuf *buf;
324
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800325 if (hapd->conf->ssid.wpa_passphrase == NULL) {
326 wpa_printf(MSG_DEBUG, "SAE: No password available");
327 return NULL;
328 }
329
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800330 if (update &&
331 sae_prepare_commit(hapd->own_addr, sta->addr,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800332 (u8 *) hapd->conf->ssid.wpa_passphrase,
333 os_strlen(hapd->conf->ssid.wpa_passphrase),
334 sta->sae) < 0) {
335 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
336 return NULL;
337 }
338
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800339 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800340 if (buf == NULL)
341 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800342 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
343 sta->sae->tmp->anti_clogging_token : NULL);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800344
345 return buf;
346}
347
348
349static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
350 struct sta_info *sta)
351{
352 struct wpabuf *buf;
353
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800354 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800355 if (buf == NULL)
356 return NULL;
357
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800358 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800359
360 return buf;
361}
362
363
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800364static int auth_sae_send_commit(struct hostapd_data *hapd,
365 struct sta_info *sta,
366 const u8 *bssid, int update)
367{
368 struct wpabuf *data;
369
370 data = auth_build_sae_commit(hapd, sta, update);
371 if (data == NULL)
372 return WLAN_STATUS_UNSPECIFIED_FAILURE;
373
374 send_auth_reply(hapd, sta->addr, bssid,
375 WLAN_AUTH_SAE, 1, WLAN_STATUS_SUCCESS,
376 wpabuf_head(data), wpabuf_len(data));
377
378 wpabuf_free(data);
379
380 return WLAN_STATUS_SUCCESS;
381}
382
383
384static int auth_sae_send_confirm(struct hostapd_data *hapd,
385 struct sta_info *sta,
386 const u8 *bssid)
387{
388 struct wpabuf *data;
389
390 data = auth_build_sae_confirm(hapd, sta);
391 if (data == NULL)
392 return WLAN_STATUS_UNSPECIFIED_FAILURE;
393
394 send_auth_reply(hapd, sta->addr, bssid,
395 WLAN_AUTH_SAE, 2, WLAN_STATUS_SUCCESS,
396 wpabuf_head(data), wpabuf_len(data));
397
398 wpabuf_free(data);
399
400 return WLAN_STATUS_SUCCESS;
401}
402
403
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800404static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800405{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800406 struct sta_info *sta;
407 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800408
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800409 if (hapd->conf->sae_anti_clogging_threshold == 0)
410 return 1;
411
412 for (sta = hapd->sta_list; sta; sta = sta->next) {
413 if (!sta->sae)
414 continue;
415 if (sta->sae->state != SAE_COMMITTED &&
416 sta->sae->state != SAE_CONFIRMED)
417 continue;
418 open++;
419 if (open >= hapd->conf->sae_anti_clogging_threshold)
420 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800421 }
422
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800423 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800424}
425
426
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800427static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
428 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800429{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800430 u8 mac[SHA256_MAC_LEN];
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800431
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800432 if (token_len != SHA256_MAC_LEN)
433 return -1;
434 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
435 addr, ETH_ALEN, mac) < 0 ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700436 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800437 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800438
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800439 return 0;
440}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800441
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800442
443static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800444 int group, const u8 *addr)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800445{
446 struct wpabuf *buf;
447 u8 *token;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800448 struct os_reltime now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800449
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800450 os_get_reltime(&now);
451 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
452 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800453 if (random_get_bytes(hapd->sae_token_key,
454 sizeof(hapd->sae_token_key)) < 0)
455 return NULL;
456 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
457 hapd->sae_token_key, sizeof(hapd->sae_token_key));
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800458 hapd->last_sae_token_key_update = now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800459 }
460
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800461 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800462 if (buf == NULL)
463 return NULL;
464
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800465 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
466
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800467 token = wpabuf_put(buf, SHA256_MAC_LEN);
468 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
469 addr, ETH_ALEN, token);
470
471 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800472}
473
474
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800475static int sae_check_big_sync(struct sta_info *sta)
476{
477 if (sta->sae->sync > dot11RSNASAESync) {
478 sta->sae->state = SAE_NOTHING;
479 sta->sae->sync = 0;
480 return -1;
481 }
482 return 0;
483}
484
485
486static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
487{
488 struct hostapd_data *hapd = eloop_ctx;
489 struct sta_info *sta = eloop_data;
490 int ret;
491
492 if (sae_check_big_sync(sta))
493 return;
494 sta->sae->sync++;
495
496 switch (sta->sae->state) {
497 case SAE_COMMITTED:
498 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
499 eloop_register_timeout(0, dot11RSNASAERetransPeriod * 1000,
500 auth_sae_retransmit_timer, hapd, sta);
501 break;
502 case SAE_CONFIRMED:
503 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
504 eloop_register_timeout(0, dot11RSNASAERetransPeriod * 1000,
505 auth_sae_retransmit_timer, hapd, sta);
506 break;
507 default:
508 ret = -1;
509 break;
510 }
511
512 if (ret != WLAN_STATUS_SUCCESS)
513 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
514}
515
516
517void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
518{
519 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
520}
521
522
523static void sae_set_retransmit_timer(struct hostapd_data *hapd,
524 struct sta_info *sta)
525{
526 if (!(hapd->conf->mesh & MESH_ENABLED))
527 return;
528
529 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
530 eloop_register_timeout(0, dot11RSNASAERetransPeriod * 1000,
531 auth_sae_retransmit_timer, hapd, sta);
532}
533
534
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800535static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
536 const u8 *bssid, u8 auth_transaction)
537{
538 int ret;
539
540 if (auth_transaction != 1 && auth_transaction != 2)
541 return WLAN_STATUS_UNSPECIFIED_FAILURE;
542
543 switch (sta->sae->state) {
544 case SAE_NOTHING:
545 if (auth_transaction == 1) {
546 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
547 if (ret)
548 return ret;
549 sta->sae->state = SAE_COMMITTED;
550
551 if (sae_process_commit(sta->sae) < 0)
552 return WLAN_STATUS_UNSPECIFIED_FAILURE;
553
554 /*
555 * In mesh case, both Commit and Confirm can be sent
556 * immediately. In infrastructure BSS, only a single
557 * Authentication frame (Commit) is expected from the AP
558 * here and the second one (Confirm) will be sent once
559 * the STA has sent its second Authentication frame
560 * (Confirm).
561 */
562 if (hapd->conf->mesh & MESH_ENABLED) {
563 /*
564 * Send both Commit and Confirm immediately
565 * based on SAE finite state machine
566 * Nothing -> Confirm transition.
567 */
568 ret = auth_sae_send_confirm(hapd, sta, bssid);
569 if (ret)
570 return ret;
571 sta->sae->state = SAE_CONFIRMED;
572 } else {
573 /*
574 * For infrastructure BSS, send only the Commit
575 * message now to get alternating sequence of
576 * Authentication frames between the AP and STA.
577 * Confirm will be sent in
578 * Commited -> Confirmed/Accepted transition
579 * when receiving Confirm from STA.
580 */
581 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800582 sta->sae->sync = 0;
583 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800584 } else {
585 hostapd_logger(hapd, sta->addr,
586 HOSTAPD_MODULE_IEEE80211,
587 HOSTAPD_LEVEL_DEBUG,
588 "SAE confirm before commit");
589 }
590 break;
591 case SAE_COMMITTED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800592 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800593 if (auth_transaction == 1) {
594 if (sae_process_commit(sta->sae) < 0)
595 return WLAN_STATUS_UNSPECIFIED_FAILURE;
596
597 ret = auth_sae_send_confirm(hapd, sta, bssid);
598 if (ret)
599 return ret;
600 sta->sae->state = SAE_CONFIRMED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800601 sta->sae->sync = 0;
602 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800603 } else if (hapd->conf->mesh & MESH_ENABLED) {
604 /*
605 * In mesh case, follow SAE finite state machine and
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800606 * send Commit now, if sync count allows.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800607 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800608 if (sae_check_big_sync(sta))
609 return WLAN_STATUS_SUCCESS;
610 sta->sae->sync++;
611
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700612 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800613 if (ret)
614 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800615
616 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800617 } else {
618 /*
619 * For instructure BSS, send the postponed Confirm from
620 * Nothing -> Confirmed transition that was reduced to
621 * Nothing -> Committed above.
622 */
623 ret = auth_sae_send_confirm(hapd, sta, bssid);
624 if (ret)
625 return ret;
626
627 sta->sae->state = SAE_CONFIRMED;
628
629 /*
630 * Since this was triggered on Confirm RX, run another
631 * step to get to Accepted without waiting for
632 * additional events.
633 */
634 return sae_sm_step(hapd, sta, bssid, auth_transaction);
635 }
636 break;
637 case SAE_CONFIRMED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800638 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800639 if (auth_transaction == 1) {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800640 if (sae_check_big_sync(sta))
641 return WLAN_STATUS_SUCCESS;
642 sta->sae->sync++;
643
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800644 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
645 if (ret)
646 return ret;
647
648 if (sae_process_commit(sta->sae) < 0)
649 return WLAN_STATUS_UNSPECIFIED_FAILURE;
650
651 ret = auth_sae_send_confirm(hapd, sta, bssid);
652 if (ret)
653 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800654
655 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800656 } else {
657 sta->flags |= WLAN_STA_AUTH;
658 sta->auth_alg = WLAN_AUTH_SAE;
659 mlme_authenticate_indication(hapd, sta);
660 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
661 sta->sae->state = SAE_ACCEPTED;
662 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
663 sta->sae->pmk);
664 }
665 break;
666 case SAE_ACCEPTED:
667 if (auth_transaction == 1) {
668 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
669 ") doing reauthentication",
670 MAC2STR(sta->addr));
671 ap_free_sta(hapd, sta);
672 } else {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800673 if (sae_check_big_sync(sta))
674 return WLAN_STATUS_SUCCESS;
675 sta->sae->sync++;
676
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800677 ret = auth_sae_send_confirm(hapd, sta, bssid);
678 sae_clear_temp_data(sta->sae);
679 if (ret)
680 return ret;
681 }
682 break;
683 default:
684 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
685 sta->sae->state);
686 return WLAN_STATUS_UNSPECIFIED_FAILURE;
687 }
688 return WLAN_STATUS_SUCCESS;
689}
690
691
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800692static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
693 const struct ieee80211_mgmt *mgmt, size_t len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800694 u16 auth_transaction, u16 status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800695{
696 u16 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800697 struct wpabuf *data = NULL;
698
699 if (!sta->sae) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800700 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800701 return;
702 sta->sae = os_zalloc(sizeof(*sta->sae));
703 if (sta->sae == NULL)
704 return;
705 sta->sae->state = SAE_NOTHING;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800706 sta->sae->sync = 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800707 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800708
709 if (auth_transaction == 1) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800710 const u8 *token = NULL, *pos, *end;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800711 size_t token_len = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800712 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
713 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800714 "start SAE authentication (RX commit, status=%u)",
715 status_code);
716
717 if ((hapd->conf->mesh & MESH_ENABLED) &&
718 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
719 sta->sae->tmp) {
720 pos = mgmt->u.auth.variable;
721 end = ((const u8 *) mgmt) + len;
722 if (pos + sizeof(le16) > end) {
723 wpa_printf(MSG_ERROR,
724 "SAE: Too short anti-clogging token request");
725 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
726 goto reply;
727 }
728 resp = sae_group_allowed(sta->sae,
729 hapd->conf->sae_groups,
730 WPA_GET_LE16(pos));
731 if (resp != WLAN_STATUS_SUCCESS) {
732 wpa_printf(MSG_ERROR,
733 "SAE: Invalid group in anti-clogging token request");
734 goto reply;
735 }
736 pos += sizeof(le16);
737
738 wpabuf_free(sta->sae->tmp->anti_clogging_token);
739 sta->sae->tmp->anti_clogging_token =
740 wpabuf_alloc_copy(pos, end - pos);
741 if (sta->sae->tmp->anti_clogging_token == NULL) {
742 wpa_printf(MSG_ERROR,
743 "SAE: Failed to alloc for anti-clogging token");
744 return;
745 }
746
747 /*
748 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
749 * is 76, a new Commit Message shall be constructed
750 * with the Anti-Clogging Token from the received
751 * Authentication frame, and the commit-scalar and
752 * COMMIT-ELEMENT previously sent.
753 */
754 if (auth_sae_send_commit(hapd, sta, mgmt->bssid, 0)) {
755 wpa_printf(MSG_ERROR,
756 "SAE: Failed to send commit message");
757 return;
758 }
759 sta->sae->state = SAE_COMMITTED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800760 sta->sae->sync = 0;
761 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800762 return;
763 }
764
765 if (status_code != WLAN_STATUS_SUCCESS)
766 return;
767
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800768 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
769 ((const u8 *) mgmt) + len -
770 mgmt->u.auth.variable, &token,
771 &token_len, hapd->conf->sae_groups);
Dmitry Shmidt41712582015-06-29 11:02:15 -0700772 if (resp == SAE_SILENTLY_DISCARD) {
773 wpa_printf(MSG_DEBUG,
774 "SAE: Drop commit message from " MACSTR " due to reflection attack",
775 MAC2STR(sta->addr));
776 return;
777 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800778 if (token && check_sae_token(hapd, sta->addr, token, token_len)
779 < 0) {
780 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
781 "incorrect token from " MACSTR,
782 MAC2STR(sta->addr));
783 return;
784 }
785
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800786 if (resp != WLAN_STATUS_SUCCESS)
787 goto reply;
788
789 if (!token && use_sae_anti_clogging(hapd)) {
790 wpa_printf(MSG_DEBUG,
791 "SAE: Request anti-clogging token from "
792 MACSTR, MAC2STR(sta->addr));
793 data = auth_build_token_req(hapd, sta->sae->group,
794 sta->addr);
795 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
796 if (hapd->conf->mesh & MESH_ENABLED)
797 sta->sae->state = SAE_NOTHING;
798 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800799 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800800
801 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800802 } else if (auth_transaction == 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800803 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
804 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800805 "SAE authentication (RX confirm, status=%u)",
806 status_code);
807 if (status_code != WLAN_STATUS_SUCCESS)
808 return;
809 if (sta->sae->state >= SAE_CONFIRMED ||
810 !(hapd->conf->mesh & MESH_ENABLED)) {
811 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
812 ((u8 *) mgmt) + len -
813 mgmt->u.auth.variable) < 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800814 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800815 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800816 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800817 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800818 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800819 } else {
820 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
821 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800822 "unexpected SAE authentication transaction %u (status=%u)",
823 auth_transaction, status_code);
824 if (status_code != WLAN_STATUS_SUCCESS)
825 return;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800826 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
827 }
828
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800829reply:
830 if (resp != WLAN_STATUS_SUCCESS) {
831 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
832 auth_transaction, resp,
833 data ? wpabuf_head(data) : (u8 *) "",
834 data ? wpabuf_len(data) : 0);
835 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800836 wpabuf_free(data);
837}
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800838
839
840/**
841 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
842 * @hapd: BSS data for the device initiating the authentication
843 * @sta: the peer to which commit authentication frame is sent
844 *
845 * This function implements Init event handling (IEEE Std 802.11-2012,
846 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
847 * sta->sae structure should be initialized appropriately via a call to
848 * sae_prepare_commit().
849 */
850int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
851{
852 int ret;
853
854 if (!sta->sae || !sta->sae->tmp)
855 return -1;
856
857 if (sta->sae->state != SAE_NOTHING)
858 return -1;
859
860 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
861 if (ret)
862 return -1;
863
864 sta->sae->state = SAE_COMMITTED;
865 sta->sae->sync = 0;
866 sae_set_retransmit_timer(hapd, sta);
867
868 return 0;
869}
870
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800871#endif /* CONFIG_SAE */
872
873
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874static void handle_auth(struct hostapd_data *hapd,
875 const struct ieee80211_mgmt *mgmt, size_t len)
876{
877 u16 auth_alg, auth_transaction, status_code;
878 u16 resp = WLAN_STATUS_SUCCESS;
879 struct sta_info *sta = NULL;
880 int res;
881 u16 fc;
882 const u8 *challenge = NULL;
883 u32 session_timeout, acct_interim_interval;
884 int vlan_id = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800885 struct hostapd_sta_wpa_psk_short *psk = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700886 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
887 size_t resp_ies_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700888 char *identity = NULL;
889 char *radius_cui = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800890 u16 seq_ctrl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700891
892 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800893 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
894 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895 return;
896 }
897
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700898#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700899 if (hapd->iconf->ignore_auth_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700900 drand48() < hapd->iconf->ignore_auth_probability) {
901 wpa_printf(MSG_INFO,
902 "TESTING: ignoring auth frame from " MACSTR,
903 MAC2STR(mgmt->sa));
904 return;
905 }
906#endif /* CONFIG_TESTING_OPTIONS */
907
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700908 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
909 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
910 status_code = le_to_host16(mgmt->u.auth.status_code);
911 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800912 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913
914 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
915 2 + WLAN_AUTH_CHALLENGE_LEN &&
916 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
917 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
918 challenge = &mgmt->u.auth.variable[2];
919
920 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800921 "auth_transaction=%d status_code=%d wep=%d%s "
922 "seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700923 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
924 status_code, !!(fc & WLAN_FC_ISWEP),
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800925 challenge ? " challenge" : "",
926 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700927
928 if (hapd->tkip_countermeasures) {
929 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
930 goto fail;
931 }
932
933 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
934 auth_alg == WLAN_AUTH_OPEN) ||
935#ifdef CONFIG_IEEE80211R
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800936 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700937 auth_alg == WLAN_AUTH_FT) ||
938#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800939#ifdef CONFIG_SAE
940 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
941 auth_alg == WLAN_AUTH_SAE) ||
942#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
944 auth_alg == WLAN_AUTH_SHARED_KEY))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800945 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
946 auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
948 goto fail;
949 }
950
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800951 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700952 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800953 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
954 auth_transaction);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700955 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
956 goto fail;
957 }
958
959 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800960 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
961 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
963 goto fail;
964 }
965
966 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
967 &session_timeout,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800968 &acct_interim_interval, &vlan_id,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800969 &psk, &identity, &radius_cui);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800970
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971 if (res == HOSTAPD_ACL_REJECT) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800972 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
973 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700974 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
975 goto fail;
976 }
977 if (res == HOSTAPD_ACL_PENDING) {
978 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
979 " waiting for an external authentication",
980 MAC2STR(mgmt->sa));
981 /* Authentication code will re-send the authentication frame
982 * after it has received (and cached) information from the
983 * external source. */
984 return;
985 }
986
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800987 sta = ap_get_sta(hapd, mgmt->sa);
988 if (sta) {
989 if ((fc & WLAN_FC_RETRY) &&
990 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
991 sta->last_seq_ctrl == seq_ctrl &&
992 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
993 hostapd_logger(hapd, sta->addr,
994 HOSTAPD_MODULE_IEEE80211,
995 HOSTAPD_LEVEL_DEBUG,
996 "Drop repeated authentication frame seq_ctrl=0x%x",
997 seq_ctrl);
998 return;
999 }
1000 } else {
1001#ifdef CONFIG_MESH
1002 if (hapd->conf->mesh & MESH_ENABLED) {
1003 /* if the mesh peer is not available, we don't do auth.
1004 */
1005 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1006 " not yet known - drop Authentiation frame",
1007 MAC2STR(mgmt->sa));
1008 /*
1009 * Save a copy of the frame so that it can be processed
1010 * if a new peer entry is added shortly after this.
1011 */
1012 wpabuf_free(hapd->mesh_pending_auth);
1013 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1014 os_get_reltime(&hapd->mesh_pending_auth_time);
1015 return;
1016 }
1017#endif /* CONFIG_MESH */
1018
1019 sta = ap_sta_add(hapd, mgmt->sa);
1020 if (!sta) {
1021 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1022 goto fail;
1023 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001024 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001025 sta->last_seq_ctrl = seq_ctrl;
1026 sta->last_subtype = WLAN_FC_STYPE_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001027
1028 if (vlan_id > 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001029 if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1031 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
1032 "%d received from RADIUS server",
1033 vlan_id);
1034 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1035 goto fail;
1036 }
1037 sta->vlan_id = vlan_id;
1038 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1039 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1040 }
1041
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001042 hostapd_free_psk_list(sta->psk);
1043 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1044 sta->psk = psk;
1045 psk = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001046 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001047 sta->psk = NULL;
1048 }
1049
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001050 sta->identity = identity;
1051 identity = NULL;
1052 sta->radius_cui = radius_cui;
1053 radius_cui = NULL;
1054
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055 sta->flags &= ~WLAN_STA_PREAUTH;
1056 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1057
1058 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1059 sta->acct_interim_interval = acct_interim_interval;
1060 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1061 ap_sta_session_timeout(hapd, sta, session_timeout);
1062 else
1063 ap_sta_no_session_timeout(hapd, sta);
1064
1065 switch (auth_alg) {
1066 case WLAN_AUTH_OPEN:
1067 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1068 HOSTAPD_LEVEL_DEBUG,
1069 "authentication OK (open system)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070 sta->flags |= WLAN_STA_AUTH;
1071 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1072 sta->auth_alg = WLAN_AUTH_OPEN;
1073 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074 break;
1075 case WLAN_AUTH_SHARED_KEY:
1076 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1077 fc & WLAN_FC_ISWEP);
1078 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1079 mlme_authenticate_indication(hapd, sta);
1080 if (sta->challenge && auth_transaction == 1) {
1081 resp_ies[0] = WLAN_EID_CHALLENGE;
1082 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1083 os_memcpy(resp_ies + 2, sta->challenge,
1084 WLAN_AUTH_CHALLENGE_LEN);
1085 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1086 }
1087 break;
1088#ifdef CONFIG_IEEE80211R
1089 case WLAN_AUTH_FT:
1090 sta->auth_alg = WLAN_AUTH_FT;
1091 if (sta->wpa_sm == NULL)
1092 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001093 sta->addr, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094 if (sta->wpa_sm == NULL) {
1095 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1096 "state machine");
1097 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1098 goto fail;
1099 }
1100 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1101 auth_transaction, mgmt->u.auth.variable,
1102 len - IEEE80211_HDRLEN -
1103 sizeof(mgmt->u.auth),
1104 handle_auth_ft_finish, hapd);
1105 /* handle_auth_ft_finish() callback will complete auth. */
1106 return;
1107#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001108#ifdef CONFIG_SAE
1109 case WLAN_AUTH_SAE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001110#ifdef CONFIG_MESH
1111 if (status_code == WLAN_STATUS_SUCCESS &&
1112 hapd->conf->mesh & MESH_ENABLED) {
1113 if (sta->wpa_sm == NULL)
1114 sta->wpa_sm =
1115 wpa_auth_sta_init(hapd->wpa_auth,
1116 sta->addr, NULL);
1117 if (sta->wpa_sm == NULL) {
1118 wpa_printf(MSG_DEBUG,
1119 "SAE: Failed to initialize WPA state machine");
1120 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1121 goto fail;
1122 }
1123 }
1124#endif /* CONFIG_MESH */
1125 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1126 status_code);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001127 return;
1128#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129 }
1130
1131 fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001132 os_free(identity);
1133 os_free(radius_cui);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001134 hostapd_free_psk_list(psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001135
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001136 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1137 auth_transaction + 1, resp, resp_ies, resp_ies_len);
1138}
1139
1140
1141static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
1142{
1143 int i, j = 32, aid;
1144
1145 /* get a unique AID */
1146 if (sta->aid > 0) {
1147 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1148 return 0;
1149 }
1150
1151 for (i = 0; i < AID_WORDS; i++) {
1152 if (hapd->sta_aid[i] == (u32) -1)
1153 continue;
1154 for (j = 0; j < 32; j++) {
1155 if (!(hapd->sta_aid[i] & BIT(j)))
1156 break;
1157 }
1158 if (j < 32)
1159 break;
1160 }
1161 if (j == 32)
1162 return -1;
1163 aid = i * 32 + j + 1;
1164 if (aid > 2007)
1165 return -1;
1166
1167 sta->aid = aid;
1168 hapd->sta_aid[i] |= BIT(j);
1169 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1170 return 0;
1171}
1172
1173
1174static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1175 const u8 *ssid_ie, size_t ssid_ie_len)
1176{
1177 if (ssid_ie == NULL)
1178 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1179
1180 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1181 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001182 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1183 HOSTAPD_LEVEL_INFO,
1184 "Station tried to associate with unknown SSID "
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001185 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001186 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1187 }
1188
1189 return WLAN_STATUS_SUCCESS;
1190}
1191
1192
1193static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1194 const u8 *wmm_ie, size_t wmm_ie_len)
1195{
1196 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001198 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001199 struct wmm_information_element *wmm;
1200
1201 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202 hostapd_logger(hapd, sta->addr,
1203 HOSTAPD_MODULE_WPA,
1204 HOSTAPD_LEVEL_DEBUG,
1205 "invalid WMM element in association "
1206 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001207 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1208 }
1209
1210 sta->flags |= WLAN_STA_WMM;
1211 wmm = (struct wmm_information_element *) wmm_ie;
1212 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001213 }
1214 return WLAN_STATUS_SUCCESS;
1215}
1216
1217
1218static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1219 struct ieee802_11_elems *elems)
1220{
1221 if (!elems->supp_rates) {
1222 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1223 HOSTAPD_LEVEL_DEBUG,
1224 "No supported rates element in AssocReq");
1225 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1226 }
1227
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001228 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1229 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1231 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001232 "Invalid supported rates element length %d+%d",
1233 elems->supp_rates_len,
1234 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001235 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1236 }
1237
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001238 sta->supported_rates_len = merge_byte_arrays(
1239 sta->supported_rates, sizeof(sta->supported_rates),
1240 elems->supp_rates, elems->supp_rates_len,
1241 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001242
1243 return WLAN_STATUS_SUCCESS;
1244}
1245
1246
Dmitry Shmidt051af732013-10-22 13:52:46 -07001247static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1248 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1249{
1250#ifdef CONFIG_INTERWORKING
1251 /* check for QoS Map support */
1252 if (ext_capab_ie_len >= 5) {
1253 if (ext_capab_ie[4] & 0x01)
1254 sta->qos_map_enabled = 1;
1255 }
1256#endif /* CONFIG_INTERWORKING */
1257
1258 return WLAN_STATUS_SUCCESS;
1259}
1260
1261
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001262static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1263 const u8 *ies, size_t ies_len, int reassoc)
1264{
1265 struct ieee802_11_elems elems;
1266 u16 resp;
1267 const u8 *wpa_ie;
1268 size_t wpa_ie_len;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001269 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270
1271 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1272 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1273 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1274 "association request");
1275 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1276 }
1277
1278 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1279 if (resp != WLAN_STATUS_SUCCESS)
1280 return resp;
1281 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1282 if (resp != WLAN_STATUS_SUCCESS)
1283 return resp;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001284 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1285 if (resp != WLAN_STATUS_SUCCESS)
1286 return resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001287 resp = copy_supp_rates(hapd, sta, &elems);
1288 if (resp != WLAN_STATUS_SUCCESS)
1289 return resp;
1290#ifdef CONFIG_IEEE80211N
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001291 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001292 if (resp != WLAN_STATUS_SUCCESS)
1293 return resp;
1294 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1295 !(sta->flags & WLAN_STA_HT)) {
1296 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1297 HOSTAPD_LEVEL_INFO, "Station does not support "
1298 "mandatory HT PHY - reject association");
1299 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1300 }
1301#endif /* CONFIG_IEEE80211N */
1302
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001303#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001304 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001305 if (resp != WLAN_STATUS_SUCCESS)
1306 return resp;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08001307
1308 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1309 if (resp != WLAN_STATUS_SUCCESS)
1310 return resp;
1311
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001312 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1313 !(sta->flags & WLAN_STA_VHT)) {
1314 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1315 HOSTAPD_LEVEL_INFO, "Station does not support "
1316 "mandatory VHT PHY - reject association");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001317 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001318 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001319
1320 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1321 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1322 elems.vendor_vht_len);
1323 if (resp != WLAN_STATUS_SUCCESS)
1324 return resp;
1325 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001326#endif /* CONFIG_IEEE80211AC */
1327
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001328#ifdef CONFIG_P2P
1329 if (elems.p2p) {
1330 wpabuf_free(sta->p2p_ie);
1331 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1332 P2P_IE_VENDOR_TYPE);
1333 if (sta->p2p_ie)
1334 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1335 } else {
1336 wpabuf_free(sta->p2p_ie);
1337 sta->p2p_ie = NULL;
1338 }
1339#endif /* CONFIG_P2P */
1340
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001341 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1342 wpa_ie = elems.rsn_ie;
1343 wpa_ie_len = elems.rsn_ie_len;
1344 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1345 elems.wpa_ie) {
1346 wpa_ie = elems.wpa_ie;
1347 wpa_ie_len = elems.wpa_ie_len;
1348 } else {
1349 wpa_ie = NULL;
1350 wpa_ie_len = 0;
1351 }
1352
1353#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001354 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001355 if (hapd->conf->wps_state && elems.wps_ie) {
1356 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1357 "Request - assume WPS is used");
1358 sta->flags |= WLAN_STA_WPS;
1359 wpabuf_free(sta->wps_ie);
1360 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1361 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001362 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1363 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1364 sta->flags |= WLAN_STA_WPS2;
1365 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001366 wpa_ie = NULL;
1367 wpa_ie_len = 0;
1368 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1369 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1370 "(Re)Association Request - reject");
1371 return WLAN_STATUS_INVALID_IE;
1372 }
1373 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1374 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1375 "(Re)Association Request - possible WPS use");
1376 sta->flags |= WLAN_STA_MAYBE_WPS;
1377 } else
1378#endif /* CONFIG_WPS */
1379 if (hapd->conf->wpa && wpa_ie == NULL) {
1380 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1381 HOSTAPD_LEVEL_INFO,
1382 "No WPA/RSN IE in association request");
1383 return WLAN_STATUS_INVALID_IE;
1384 }
1385
1386 if (hapd->conf->wpa && wpa_ie) {
1387 int res;
1388 wpa_ie -= 2;
1389 wpa_ie_len += 2;
1390 if (sta->wpa_sm == NULL)
1391 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001392 sta->addr,
1393 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001394 if (sta->wpa_sm == NULL) {
1395 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1396 "state machine");
1397 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1398 }
1399 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1400 wpa_ie, wpa_ie_len,
1401 elems.mdie, elems.mdie_len);
1402 if (res == WPA_INVALID_GROUP)
1403 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1404 else if (res == WPA_INVALID_PAIRWISE)
1405 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1406 else if (res == WPA_INVALID_AKMP)
1407 resp = WLAN_STATUS_AKMP_NOT_VALID;
1408 else if (res == WPA_ALLOC_FAIL)
1409 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1410#ifdef CONFIG_IEEE80211W
1411 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1412 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1413 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1414 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1415#endif /* CONFIG_IEEE80211W */
1416 else if (res == WPA_INVALID_MDIE)
1417 resp = WLAN_STATUS_INVALID_MDIE;
1418 else if (res != WPA_IE_OK)
1419 resp = WLAN_STATUS_INVALID_IE;
1420 if (resp != WLAN_STATUS_SUCCESS)
1421 return resp;
1422#ifdef CONFIG_IEEE80211W
1423 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1424 sta->sa_query_count > 0)
1425 ap_check_sa_query_timeout(hapd, sta);
1426 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1427 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1428 /*
1429 * STA has already been associated with MFP and SA
1430 * Query timeout has not been reached. Reject the
1431 * association attempt temporarily and start SA Query,
1432 * if one is not pending.
1433 */
1434
1435 if (sta->sa_query_count == 0)
1436 ap_sta_start_sa_query(hapd, sta);
1437
1438 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1439 }
1440
1441 if (wpa_auth_uses_mfp(sta->wpa_sm))
1442 sta->flags |= WLAN_STA_MFP;
1443 else
1444 sta->flags &= ~WLAN_STA_MFP;
1445#endif /* CONFIG_IEEE80211W */
1446
1447#ifdef CONFIG_IEEE80211R
1448 if (sta->auth_alg == WLAN_AUTH_FT) {
1449 if (!reassoc) {
1450 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1451 "to use association (not "
1452 "re-association) with FT auth_alg",
1453 MAC2STR(sta->addr));
1454 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1455 }
1456
1457 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1458 ies_len);
1459 if (resp != WLAN_STATUS_SUCCESS)
1460 return resp;
1461 }
1462#endif /* CONFIG_IEEE80211R */
1463
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001464#ifdef CONFIG_SAE
1465 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001466 sta->auth_alg == WLAN_AUTH_OPEN) {
1467 struct rsn_pmksa_cache_entry *sa;
1468 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1469 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1470 wpa_printf(MSG_DEBUG,
1471 "SAE: No PMKSA cache entry found for "
1472 MACSTR, MAC2STR(sta->addr));
1473 return WLAN_STATUS_INVALID_PMKID;
1474 }
1475 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1476 " using PMKSA caching", MAC2STR(sta->addr));
1477 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1478 sta->auth_alg != WLAN_AUTH_SAE &&
1479 !(sta->auth_alg == WLAN_AUTH_FT &&
1480 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001481 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1482 "SAE AKM after non-SAE auth_alg %u",
1483 MAC2STR(sta->addr), sta->auth_alg);
1484 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1485 }
1486#endif /* CONFIG_SAE */
1487
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001488#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001489 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001490 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1491 hostapd_logger(hapd, sta->addr,
1492 HOSTAPD_MODULE_IEEE80211,
1493 HOSTAPD_LEVEL_INFO,
1494 "Station tried to use TKIP with HT "
1495 "association");
1496 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1497 }
1498#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001499#ifdef CONFIG_HS20
1500 } else if (hapd->conf->osen) {
1501 if (elems.osen == NULL) {
1502 hostapd_logger(
1503 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1504 HOSTAPD_LEVEL_INFO,
1505 "No HS 2.0 OSEN element in association request");
1506 return WLAN_STATUS_INVALID_IE;
1507 }
1508
1509 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1510 if (sta->wpa_sm == NULL)
1511 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1512 sta->addr, NULL);
1513 if (sta->wpa_sm == NULL) {
1514 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1515 "state machine");
1516 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1517 }
1518 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1519 elems.osen - 2, elems.osen_len + 2) < 0)
1520 return WLAN_STATUS_INVALID_IE;
1521#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001522 } else
1523 wpa_auth_sta_no_wpa(sta->wpa_sm);
1524
1525#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001526 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1527#endif /* CONFIG_P2P */
1528
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001529#ifdef CONFIG_HS20
1530 wpabuf_free(sta->hs20_ie);
1531 if (elems.hs20 && elems.hs20_len > 4) {
1532 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1533 elems.hs20_len - 4);
1534 } else
1535 sta->hs20_ie = NULL;
1536#endif /* CONFIG_HS20 */
1537
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001538 return WLAN_STATUS_SUCCESS;
1539}
1540
1541
1542static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1543 u16 reason_code)
1544{
1545 int send_len;
1546 struct ieee80211_mgmt reply;
1547
1548 os_memset(&reply, 0, sizeof(reply));
1549 reply.frame_control =
1550 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1551 os_memcpy(reply.da, addr, ETH_ALEN);
1552 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1553 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1554
1555 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1556 reply.u.deauth.reason_code = host_to_le16(reason_code);
1557
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001558 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001559 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1560 strerror(errno));
1561}
1562
1563
1564static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1565 u16 status_code, int reassoc, const u8 *ies,
1566 size_t ies_len)
1567{
1568 int send_len;
1569 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1570 struct ieee80211_mgmt *reply;
1571 u8 *p;
1572
1573 os_memset(buf, 0, sizeof(buf));
1574 reply = (struct ieee80211_mgmt *) buf;
1575 reply->frame_control =
1576 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1577 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1578 WLAN_FC_STYPE_ASSOC_RESP));
1579 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1580 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1581 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1582
1583 send_len = IEEE80211_HDRLEN;
1584 send_len += sizeof(reply->u.assoc_resp);
1585 reply->u.assoc_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001586 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001587 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001588 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001589 /* Supported rates */
1590 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1591 /* Extended supported rates */
1592 p = hostapd_eid_ext_supp_rates(hapd, p);
1593
1594#ifdef CONFIG_IEEE80211R
1595 if (status_code == WLAN_STATUS_SUCCESS) {
1596 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1597 * Transition Information, RSN, [RIC Response] */
1598 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1599 buf + sizeof(buf) - p,
1600 sta->auth_alg, ies, ies_len);
1601 }
1602#endif /* CONFIG_IEEE80211R */
1603
1604#ifdef CONFIG_IEEE80211W
1605 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1606 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1607#endif /* CONFIG_IEEE80211W */
1608
1609#ifdef CONFIG_IEEE80211N
1610 p = hostapd_eid_ht_capabilities(hapd, p);
1611 p = hostapd_eid_ht_operation(hapd, p);
1612#endif /* CONFIG_IEEE80211N */
1613
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001614#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001615 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1616 p = hostapd_eid_vht_capabilities(hapd, p);
1617 p = hostapd_eid_vht_operation(hapd, p);
1618 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001619#endif /* CONFIG_IEEE80211AC */
1620
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001622 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001623 if (sta->qos_map_enabled)
1624 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001625
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001626#ifdef CONFIG_IEEE80211AC
1627 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1628 p = hostapd_eid_vendor_vht(hapd, p);
1629#endif /* CONFIG_IEEE80211AC */
1630
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001631 if (sta->flags & WLAN_STA_WMM)
1632 p = hostapd_eid_wmm(hapd, p);
1633
1634#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001635 if ((sta->flags & WLAN_STA_WPS) ||
1636 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001637 struct wpabuf *wps = wps_build_assoc_resp_ie();
1638 if (wps) {
1639 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1640 p += wpabuf_len(wps);
1641 wpabuf_free(wps);
1642 }
1643 }
1644#endif /* CONFIG_WPS */
1645
1646#ifdef CONFIG_P2P
1647 if (sta->p2p_ie) {
1648 struct wpabuf *p2p_resp_ie;
1649 enum p2p_status_code status;
1650 switch (status_code) {
1651 case WLAN_STATUS_SUCCESS:
1652 status = P2P_SC_SUCCESS;
1653 break;
1654 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1655 status = P2P_SC_FAIL_LIMIT_REACHED;
1656 break;
1657 default:
1658 status = P2P_SC_FAIL_INVALID_PARAMS;
1659 break;
1660 }
1661 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1662 if (p2p_resp_ie) {
1663 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1664 wpabuf_len(p2p_resp_ie));
1665 p += wpabuf_len(p2p_resp_ie);
1666 wpabuf_free(p2p_resp_ie);
1667 }
1668 }
1669#endif /* CONFIG_P2P */
1670
1671#ifdef CONFIG_P2P_MANAGER
1672 if (hapd->conf->p2p & P2P_MANAGE)
1673 p = hostapd_eid_p2p_manage(hapd, p);
1674#endif /* CONFIG_P2P_MANAGER */
1675
1676 send_len += p - reply->u.assoc_resp.variable;
1677
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001678 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1680 strerror(errno));
1681}
1682
1683
1684static void handle_assoc(struct hostapd_data *hapd,
1685 const struct ieee80211_mgmt *mgmt, size_t len,
1686 int reassoc)
1687{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001688 u16 capab_info, listen_interval, seq_ctrl, fc;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001689 u16 resp = WLAN_STATUS_SUCCESS;
1690 const u8 *pos;
1691 int left, i;
1692 struct sta_info *sta;
1693
1694 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1695 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001696 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1697 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001698 return;
1699 }
1700
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001701#ifdef CONFIG_TESTING_OPTIONS
1702 if (reassoc) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001703 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001704 drand48() < hapd->iconf->ignore_reassoc_probability) {
1705 wpa_printf(MSG_INFO,
1706 "TESTING: ignoring reassoc request from "
1707 MACSTR, MAC2STR(mgmt->sa));
1708 return;
1709 }
1710 } else {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001711 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001712 drand48() < hapd->iconf->ignore_assoc_probability) {
1713 wpa_printf(MSG_INFO,
1714 "TESTING: ignoring assoc request from "
1715 MACSTR, MAC2STR(mgmt->sa));
1716 return;
1717 }
1718 }
1719#endif /* CONFIG_TESTING_OPTIONS */
1720
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001721 fc = le_to_host16(mgmt->frame_control);
1722 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1723
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001724 if (reassoc) {
1725 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1726 listen_interval = le_to_host16(
1727 mgmt->u.reassoc_req.listen_interval);
1728 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1729 " capab_info=0x%02x listen_interval=%d current_ap="
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001730 MACSTR " seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001731 MAC2STR(mgmt->sa), capab_info, listen_interval,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001732 MAC2STR(mgmt->u.reassoc_req.current_ap),
1733 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001734 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1735 pos = mgmt->u.reassoc_req.variable;
1736 } else {
1737 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1738 listen_interval = le_to_host16(
1739 mgmt->u.assoc_req.listen_interval);
1740 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001741 " capab_info=0x%02x listen_interval=%d "
1742 "seq_ctrl=0x%x%s",
1743 MAC2STR(mgmt->sa), capab_info, listen_interval,
1744 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001745 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1746 pos = mgmt->u.assoc_req.variable;
1747 }
1748
1749 sta = ap_get_sta(hapd, mgmt->sa);
1750#ifdef CONFIG_IEEE80211R
1751 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1752 (sta->flags & WLAN_STA_AUTH) == 0) {
1753 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1754 "prior to authentication since it is using "
1755 "over-the-DS FT", MAC2STR(mgmt->sa));
1756 } else
1757#endif /* CONFIG_IEEE80211R */
1758 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1759 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1760 HOSTAPD_LEVEL_INFO, "Station tried to "
1761 "associate before authentication "
1762 "(aid=%d flags=0x%x)",
1763 sta ? sta->aid : -1,
1764 sta ? sta->flags : 0);
1765 send_deauth(hapd, mgmt->sa,
1766 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1767 return;
1768 }
1769
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001770 if ((fc & WLAN_FC_RETRY) &&
1771 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1772 sta->last_seq_ctrl == seq_ctrl &&
1773 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1774 WLAN_FC_STYPE_ASSOC_REQ) {
1775 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1776 HOSTAPD_LEVEL_DEBUG,
1777 "Drop repeated association frame seq_ctrl=0x%x",
1778 seq_ctrl);
1779 return;
1780 }
1781 sta->last_seq_ctrl = seq_ctrl;
1782 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1783 WLAN_FC_STYPE_ASSOC_REQ;
1784
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001785 if (hapd->tkip_countermeasures) {
1786 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1787 goto fail;
1788 }
1789
1790 if (listen_interval > hapd->conf->max_listen_interval) {
1791 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1792 HOSTAPD_LEVEL_DEBUG,
1793 "Too large Listen Interval (%d)",
1794 listen_interval);
1795 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1796 goto fail;
1797 }
1798
1799 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1800 * is used */
1801 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1802 if (resp != WLAN_STATUS_SUCCESS)
1803 goto fail;
1804
1805 if (hostapd_get_aid(hapd, sta) < 0) {
1806 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1807 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1808 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1809 goto fail;
1810 }
1811
1812 sta->capability = capab_info;
1813 sta->listen_interval = listen_interval;
1814
1815 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1816 sta->flags |= WLAN_STA_NONERP;
1817 for (i = 0; i < sta->supported_rates_len; i++) {
1818 if ((sta->supported_rates[i] & 0x7f) > 22) {
1819 sta->flags &= ~WLAN_STA_NONERP;
1820 break;
1821 }
1822 }
1823 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1824 sta->nonerp_set = 1;
1825 hapd->iface->num_sta_non_erp++;
1826 if (hapd->iface->num_sta_non_erp == 1)
1827 ieee802_11_set_beacons(hapd->iface);
1828 }
1829
1830 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1831 !sta->no_short_slot_time_set) {
1832 sta->no_short_slot_time_set = 1;
1833 hapd->iface->num_sta_no_short_slot_time++;
1834 if (hapd->iface->current_mode->mode ==
1835 HOSTAPD_MODE_IEEE80211G &&
1836 hapd->iface->num_sta_no_short_slot_time == 1)
1837 ieee802_11_set_beacons(hapd->iface);
1838 }
1839
1840 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1841 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1842 else
1843 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1844
1845 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1846 !sta->no_short_preamble_set) {
1847 sta->no_short_preamble_set = 1;
1848 hapd->iface->num_sta_no_short_preamble++;
1849 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1850 && hapd->iface->num_sta_no_short_preamble == 1)
1851 ieee802_11_set_beacons(hapd->iface);
1852 }
1853
1854#ifdef CONFIG_IEEE80211N
1855 update_ht_state(hapd, sta);
1856#endif /* CONFIG_IEEE80211N */
1857
1858 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1859 HOSTAPD_LEVEL_DEBUG,
1860 "association OK (aid %d)", sta->aid);
1861 /* Station will be marked associated, after it acknowledges AssocResp
1862 */
1863 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1864
1865#ifdef CONFIG_IEEE80211W
1866 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1867 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1868 "SA Query procedure", reassoc ? "re" : "");
1869 /* TODO: Send a protected Disassociate frame to the STA using
1870 * the old key and Reason Code "Previous Authentication no
1871 * longer valid". Make sure this is only sent protected since
1872 * unprotected frame would be received by the STA that is now
1873 * trying to associate.
1874 */
1875 }
1876#endif /* CONFIG_IEEE80211W */
1877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878 /* Make sure that the previously registered inactivity timer will not
1879 * remove the STA immediately. */
1880 sta->timeout_next = STA_NULLFUNC;
1881
1882 fail:
1883 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1884}
1885
1886
1887static void handle_disassoc(struct hostapd_data *hapd,
1888 const struct ieee80211_mgmt *mgmt, size_t len)
1889{
1890 struct sta_info *sta;
1891
1892 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001893 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1894 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001895 return;
1896 }
1897
1898 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1899 MAC2STR(mgmt->sa),
1900 le_to_host16(mgmt->u.disassoc.reason_code));
1901
1902 sta = ap_get_sta(hapd, mgmt->sa);
1903 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001904 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1905 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001906 return;
1907 }
1908
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001909 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001910 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001911 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001912 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1913 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1914 HOSTAPD_LEVEL_INFO, "disassociated");
1915 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1916 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1917 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1918 * authenticated. */
1919 accounting_sta_stop(hapd, sta);
1920 ieee802_1x_free_station(sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001921 if (sta->ipaddr)
1922 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
1923 ap_sta_ip6addr_del(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001924 hostapd_drv_sta_remove(hapd, sta->addr);
1925
1926 if (sta->timeout_next == STA_NULLFUNC ||
1927 sta->timeout_next == STA_DISASSOC) {
1928 sta->timeout_next = STA_DEAUTH;
1929 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1930 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1931 hapd, sta);
1932 }
1933
1934 mlme_disassociate_indication(
1935 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1936}
1937
1938
1939static void handle_deauth(struct hostapd_data *hapd,
1940 const struct ieee80211_mgmt *mgmt, size_t len)
1941{
1942 struct sta_info *sta;
1943
1944 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001945 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1946 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001947 return;
1948 }
1949
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001950 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001951 " reason_code=%d",
1952 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1953
1954 sta = ap_get_sta(hapd, mgmt->sa);
1955 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001956 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1957 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001958 MAC2STR(mgmt->sa));
1959 return;
1960 }
1961
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001962 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001963 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001964 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1965 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001966 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1967 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1968 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1969 mlme_deauthenticate_indication(
1970 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1971 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1972 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1973 ap_free_sta(hapd, sta);
1974}
1975
1976
1977static void handle_beacon(struct hostapd_data *hapd,
1978 const struct ieee80211_mgmt *mgmt, size_t len,
1979 struct hostapd_frame_info *fi)
1980{
1981 struct ieee802_11_elems elems;
1982
1983 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001984 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
1985 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001986 return;
1987 }
1988
1989 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1990 len - (IEEE80211_HDRLEN +
1991 sizeof(mgmt->u.beacon)), &elems,
1992 0);
1993
1994 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1995}
1996
1997
1998#ifdef CONFIG_IEEE80211W
1999
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002000static int hostapd_sa_query_action(struct hostapd_data *hapd,
2001 const struct ieee80211_mgmt *mgmt,
2002 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002003{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002004 const u8 *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002005
2006 end = mgmt->u.action.u.sa_query_resp.trans_id +
2007 WLAN_SA_QUERY_TR_ID_LEN;
2008 if (((u8 *) mgmt) + len < end) {
2009 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2010 "frame (len=%lu)", (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002011 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002012 }
2013
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002014 ieee802_11_sa_query_action(hapd, mgmt->sa,
2015 mgmt->u.action.u.sa_query_resp.action,
2016 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002017 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002018}
2019
2020
2021static int robust_action_frame(u8 category)
2022{
2023 return category != WLAN_ACTION_PUBLIC &&
2024 category != WLAN_ACTION_HT;
2025}
2026#endif /* CONFIG_IEEE80211W */
2027
2028
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002029static int handle_action(struct hostapd_data *hapd,
2030 const struct ieee80211_mgmt *mgmt, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002031{
2032 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002033 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002034
2035 if (len < IEEE80211_HDRLEN + 1) {
2036 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2037 HOSTAPD_LEVEL_DEBUG,
2038 "handle_action - too short payload (len=%lu)",
2039 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002040 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002041 }
2042
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002043 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2044 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2045 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2046 "frame (category=%u) from unassociated STA " MACSTR,
2047 MAC2STR(mgmt->sa), mgmt->u.action.category);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002048 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002049 }
2050
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002051#ifdef CONFIG_IEEE80211W
2052 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08002053 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2054 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002055 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2056 HOSTAPD_LEVEL_DEBUG,
2057 "Dropped unprotected Robust Action frame from "
2058 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002059 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002060 }
2061#endif /* CONFIG_IEEE80211W */
2062
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002063 if (sta) {
2064 u16 fc = le_to_host16(mgmt->frame_control);
2065 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2066
2067 if ((fc & WLAN_FC_RETRY) &&
2068 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2069 sta->last_seq_ctrl == seq_ctrl &&
2070 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2071 hostapd_logger(hapd, sta->addr,
2072 HOSTAPD_MODULE_IEEE80211,
2073 HOSTAPD_LEVEL_DEBUG,
2074 "Drop repeated action frame seq_ctrl=0x%x",
2075 seq_ctrl);
2076 return 1;
2077 }
2078
2079 sta->last_seq_ctrl = seq_ctrl;
2080 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2081 }
2082
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002083 switch (mgmt->u.action.category) {
2084#ifdef CONFIG_IEEE80211R
2085 case WLAN_ACTION_FT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002086 if (!sta ||
2087 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088 len - IEEE80211_HDRLEN))
2089 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002090 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002091#endif /* CONFIG_IEEE80211R */
2092 case WLAN_ACTION_WMM:
2093 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002094 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002095#ifdef CONFIG_IEEE80211W
2096 case WLAN_ACTION_SA_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002097 return hostapd_sa_query_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002098#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002099#ifdef CONFIG_WNM
2100 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002101 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2102 return 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002103#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002104 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08002105 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002106#ifdef CONFIG_IEEE80211N
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07002107 if (len >= IEEE80211_HDRLEN + 2 &&
2108 mgmt->u.action.u.public_action.action ==
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002109 WLAN_PA_20_40_BSS_COEX) {
2110 wpa_printf(MSG_DEBUG,
2111 "HT20/40 coex mgmt frame received from STA "
2112 MACSTR, MAC2STR(mgmt->sa));
2113 hostapd_2040_coex_action(hapd, mgmt, len);
2114 }
2115#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002116 if (hapd->public_action_cb) {
2117 hapd->public_action_cb(hapd->public_action_cb_ctx,
2118 (u8 *) mgmt, len,
2119 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002120 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002121 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002122 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002123 (u8 *) mgmt, len,
2124 hapd->iface->freq);
2125 }
2126 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002127 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002128 break;
2129 case WLAN_ACTION_VENDOR_SPECIFIC:
2130 if (hapd->vendor_action_cb) {
2131 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2132 (u8 *) mgmt, len,
2133 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002134 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002135 }
2136 break;
2137 }
2138
2139 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2140 HOSTAPD_LEVEL_DEBUG,
2141 "handle_action - unknown action category %d or invalid "
2142 "frame",
2143 mgmt->u.action.category);
2144 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2145 !(mgmt->sa[0] & 0x01)) {
2146 struct ieee80211_mgmt *resp;
2147
2148 /*
2149 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2150 * Return the Action frame to the source without change
2151 * except that MSB of the Category set to 1.
2152 */
2153 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2154 "frame back to sender");
2155 resp = os_malloc(len);
2156 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002157 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002158 os_memcpy(resp, mgmt, len);
2159 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2160 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2161 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2162 resp->u.action.category |= 0x80;
2163
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002164 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2165 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2166 "Action frame");
2167 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002168 os_free(resp);
2169 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002170
2171 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172}
2173
2174
2175/**
2176 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2177 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2178 * sent to)
2179 * @buf: management frame data (starting from IEEE 802.11 header)
2180 * @len: length of frame data in octets
2181 * @fi: meta data about received frame (signal level, etc.)
2182 *
2183 * Process all incoming IEEE 802.11 management frames. This will be called for
2184 * each frame received from the kernel driver through wlan#ap interface. In
2185 * addition, it can be called to re-inserted pending frames (e.g., when using
2186 * external RADIUS server as an MAC ACL).
2187 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002188int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2189 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002190{
2191 struct ieee80211_mgmt *mgmt;
2192 int broadcast;
2193 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002194 int ret = 0;
2195
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002196 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002197 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002198
2199 mgmt = (struct ieee80211_mgmt *) buf;
2200 fc = le_to_host16(mgmt->frame_control);
2201 stype = WLAN_FC_GET_STYPE(fc);
2202
2203 if (stype == WLAN_FC_STYPE_BEACON) {
2204 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002205 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002206 }
2207
2208 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2209 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2210 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2211
2212 if (!broadcast &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002213#ifdef CONFIG_P2P
2214 /* Invitation responses can be sent with the peer MAC as BSSID */
2215 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2216 stype == WLAN_FC_STYPE_ACTION) &&
2217#endif /* CONFIG_P2P */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002218#ifdef CONFIG_MESH
2219 !(hapd->conf->mesh & MESH_ENABLED) &&
2220#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002221 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002222 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2223 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002224 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002225 }
2226
2227
2228 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002229 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002230 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002231 }
2232
2233 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2234 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2235 HOSTAPD_LEVEL_DEBUG,
2236 "MGMT: DA=" MACSTR " not our address",
2237 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002238 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239 }
2240
2241 switch (stype) {
2242 case WLAN_FC_STYPE_AUTH:
2243 wpa_printf(MSG_DEBUG, "mgmt::auth");
2244 handle_auth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002245 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002246 break;
2247 case WLAN_FC_STYPE_ASSOC_REQ:
2248 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2249 handle_assoc(hapd, mgmt, len, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002250 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002251 break;
2252 case WLAN_FC_STYPE_REASSOC_REQ:
2253 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2254 handle_assoc(hapd, mgmt, len, 1);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002255 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002256 break;
2257 case WLAN_FC_STYPE_DISASSOC:
2258 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2259 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002260 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002261 break;
2262 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002263 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002264 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002265 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002266 break;
2267 case WLAN_FC_STYPE_ACTION:
2268 wpa_printf(MSG_DEBUG, "mgmt::action");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002269 ret = handle_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002270 break;
2271 default:
2272 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2273 HOSTAPD_LEVEL_DEBUG,
2274 "unknown mgmt frame subtype %d", stype);
2275 break;
2276 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002277
2278 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002279}
2280
2281
2282static void handle_auth_cb(struct hostapd_data *hapd,
2283 const struct ieee80211_mgmt *mgmt,
2284 size_t len, int ok)
2285{
2286 u16 auth_alg, auth_transaction, status_code;
2287 struct sta_info *sta;
2288
2289 if (!ok) {
2290 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2291 HOSTAPD_LEVEL_NOTICE,
2292 "did not acknowledge authentication response");
2293 return;
2294 }
2295
2296 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002297 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2298 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002299 return;
2300 }
2301
2302 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2303 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2304 status_code = le_to_host16(mgmt->u.auth.status_code);
2305
2306 sta = ap_get_sta(hapd, mgmt->da);
2307 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002308 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2309 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002310 return;
2311 }
2312
2313 if (status_code == WLAN_STATUS_SUCCESS &&
2314 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2315 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2316 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2317 HOSTAPD_LEVEL_INFO, "authenticated");
2318 sta->flags |= WLAN_STA_AUTH;
2319 }
2320}
2321
2322
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002323static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2324 struct sta_info *sta,
2325 char *ifname_wds)
2326{
2327 int i;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002328 struct hostapd_ssid *ssid = &hapd->conf->ssid;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002329
2330 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2331 return;
2332
2333 for (i = 0; i < 4; i++) {
2334 if (ssid->wep.key[i] &&
2335 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2336 i == ssid->wep.idx, NULL, 0,
2337 ssid->wep.key[i], ssid->wep.len[i])) {
2338 wpa_printf(MSG_WARNING,
2339 "Could not set WEP keys for WDS interface; %s",
2340 ifname_wds);
2341 break;
2342 }
2343 }
2344}
2345
2346
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002347static void handle_assoc_cb(struct hostapd_data *hapd,
2348 const struct ieee80211_mgmt *mgmt,
2349 size_t len, int reassoc, int ok)
2350{
2351 u16 status;
2352 struct sta_info *sta;
2353 int new_assoc = 1;
2354 struct ieee80211_ht_capabilities ht_cap;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002355 struct ieee80211_vht_capabilities vht_cap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002357 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2358 sizeof(mgmt->u.assoc_resp))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002359 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2360 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002361 return;
2362 }
2363
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002364 sta = ap_get_sta(hapd, mgmt->da);
2365 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002366 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2367 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002368 return;
2369 }
2370
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002371 if (!ok) {
2372 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2373 HOSTAPD_LEVEL_DEBUG,
2374 "did not acknowledge association response");
2375 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2376 return;
2377 }
2378
2379 if (reassoc)
2380 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2381 else
2382 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2383
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002385 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002386
2387 /* Stop previous accounting session, if one is started, and allocate
2388 * new session id for the new session. */
2389 accounting_sta_stop(hapd, sta);
2390
2391 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2392 HOSTAPD_LEVEL_INFO,
2393 "associated (aid %d)",
2394 sta->aid);
2395
2396 if (sta->flags & WLAN_STA_ASSOC)
2397 new_assoc = 0;
2398 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002399 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002400 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002401 sta->auth_alg == WLAN_AUTH_FT) {
2402 /*
2403 * Open, static WEP, or FT protocol; no separate authorization
2404 * step.
2405 */
2406 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002407 }
2408
2409 if (reassoc)
2410 mlme_reassociate_indication(hapd, sta);
2411 else
2412 mlme_associate_indication(hapd, sta);
2413
2414#ifdef CONFIG_IEEE80211W
2415 sta->sa_query_timed_out = 0;
2416#endif /* CONFIG_IEEE80211W */
2417
2418 /*
2419 * Remove the STA entry in order to make sure the STA PS state gets
2420 * cleared and configuration gets updated in case of reassociation back
2421 * to the same AP.
2422 */
2423 hostapd_drv_sta_remove(hapd, sta->addr);
2424
2425#ifdef CONFIG_IEEE80211N
2426 if (sta->flags & WLAN_STA_HT)
2427 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
2428#endif /* CONFIG_IEEE80211N */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002429#ifdef CONFIG_IEEE80211AC
2430 if (sta->flags & WLAN_STA_VHT)
2431 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
2432#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002433
2434 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
2435 sta->supported_rates, sta->supported_rates_len,
2436 sta->listen_interval,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002437 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002438 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08002439 sta->flags, sta->qosinfo, sta->vht_opmode)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002440 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2441 HOSTAPD_LEVEL_NOTICE,
2442 "Could not add STA to kernel driver");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002443
2444 ap_sta_disconnect(hapd, sta, sta->addr,
2445 WLAN_REASON_DISASSOC_AP_BUSY);
2446
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002447 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002448 }
2449
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002450 if (sta->flags & WLAN_STA_WDS) {
2451 int ret;
2452 char ifname_wds[IFNAMSIZ + 1];
2453
2454 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2455 sta->aid, 1);
2456 if (!ret)
2457 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2458 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002459
2460 if (sta->eapol_sm == NULL) {
2461 /*
2462 * This STA does not use RADIUS server for EAP authentication,
2463 * so bind it to the selected VLAN interface now, since the
2464 * interface selection is not going to change anymore.
2465 */
Dmitry Shmidt83474442015-04-15 13:47:09 -07002466 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002467 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002468 } else if (sta->vlan_id) {
2469 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
Dmitry Shmidt83474442015-04-15 13:47:09 -07002470 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002471 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002472 }
2473
2474 hostapd_set_sta_flags(hapd, sta);
2475
2476 if (sta->auth_alg == WLAN_AUTH_FT)
2477 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2478 else
2479 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2480 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2481
2482 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002483}
2484
2485
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002486static void handle_deauth_cb(struct hostapd_data *hapd,
2487 const struct ieee80211_mgmt *mgmt,
2488 size_t len, int ok)
2489{
2490 struct sta_info *sta;
2491 if (mgmt->da[0] & 0x01)
2492 return;
2493 sta = ap_get_sta(hapd, mgmt->da);
2494 if (!sta) {
2495 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2496 " not found", MAC2STR(mgmt->da));
2497 return;
2498 }
2499 if (ok)
2500 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2501 MAC2STR(sta->addr));
2502 else
2503 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2504 "deauth", MAC2STR(sta->addr));
2505
2506 ap_sta_deauth_cb(hapd, sta);
2507}
2508
2509
2510static void handle_disassoc_cb(struct hostapd_data *hapd,
2511 const struct ieee80211_mgmt *mgmt,
2512 size_t len, int ok)
2513{
2514 struct sta_info *sta;
2515 if (mgmt->da[0] & 0x01)
2516 return;
2517 sta = ap_get_sta(hapd, mgmt->da);
2518 if (!sta) {
2519 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2520 " not found", MAC2STR(mgmt->da));
2521 return;
2522 }
2523 if (ok)
2524 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2525 MAC2STR(sta->addr));
2526 else
2527 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2528 "disassoc", MAC2STR(sta->addr));
2529
2530 ap_sta_disassoc_cb(hapd, sta);
2531}
2532
2533
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002534/**
2535 * ieee802_11_mgmt_cb - Process management frame TX status callback
2536 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2537 * was sent from)
2538 * @buf: management frame data (starting from IEEE 802.11 header)
2539 * @len: length of frame data in octets
2540 * @stype: management frame subtype from frame control field
2541 * @ok: Whether the frame was ACK'ed
2542 */
2543void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2544 u16 stype, int ok)
2545{
2546 const struct ieee80211_mgmt *mgmt;
2547 mgmt = (const struct ieee80211_mgmt *) buf;
2548
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002549#ifdef CONFIG_TESTING_OPTIONS
2550 if (hapd->ext_mgmt_frame_handling) {
2551 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2552 stype, ok);
2553 return;
2554 }
2555#endif /* CONFIG_TESTING_OPTIONS */
2556
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002557 switch (stype) {
2558 case WLAN_FC_STYPE_AUTH:
2559 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2560 handle_auth_cb(hapd, mgmt, len, ok);
2561 break;
2562 case WLAN_FC_STYPE_ASSOC_RESP:
2563 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2564 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2565 break;
2566 case WLAN_FC_STYPE_REASSOC_RESP:
2567 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2568 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2569 break;
2570 case WLAN_FC_STYPE_PROBE_RESP:
2571 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2572 break;
2573 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002574 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2575 handle_deauth_cb(hapd, mgmt, len, ok);
2576 break;
2577 case WLAN_FC_STYPE_DISASSOC:
2578 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2579 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002580 break;
2581 case WLAN_FC_STYPE_ACTION:
2582 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2583 break;
2584 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002585 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002586 break;
2587 }
2588}
2589
2590
2591int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2592{
2593 /* TODO */
2594 return 0;
2595}
2596
2597
2598int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2599 char *buf, size_t buflen)
2600{
2601 /* TODO */
2602 return 0;
2603}
2604
2605
2606void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2607 const u8 *buf, size_t len, int ack)
2608{
2609 struct sta_info *sta;
2610 struct hostapd_iface *iface = hapd->iface;
2611
2612 sta = ap_get_sta(hapd, addr);
2613 if (sta == NULL && iface->num_bss > 1) {
2614 size_t j;
2615 for (j = 0; j < iface->num_bss; j++) {
2616 hapd = iface->bss[j];
2617 sta = ap_get_sta(hapd, addr);
2618 if (sta)
2619 break;
2620 }
2621 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002622 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002623 return;
2624 if (sta->flags & WLAN_STA_PENDING_POLL) {
2625 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2626 "activity poll", MAC2STR(sta->addr),
2627 ack ? "ACKed" : "did not ACK");
2628 if (ack)
2629 sta->flags &= ~WLAN_STA_PENDING_POLL;
2630 }
2631
2632 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2633}
2634
2635
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002636void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2637 const u8 *data, size_t len, int ack)
2638{
2639 struct sta_info *sta;
2640 struct hostapd_iface *iface = hapd->iface;
2641
2642 sta = ap_get_sta(hapd, dst);
2643 if (sta == NULL && iface->num_bss > 1) {
2644 size_t j;
2645 for (j = 0; j < iface->num_bss; j++) {
2646 hapd = iface->bss[j];
2647 sta = ap_get_sta(hapd, dst);
2648 if (sta)
2649 break;
2650 }
2651 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002652 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2653 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2654 MACSTR " that is not currently associated",
2655 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002656 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002657 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002658
2659 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2660}
2661
2662
2663void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2664{
2665 struct sta_info *sta;
2666 struct hostapd_iface *iface = hapd->iface;
2667
2668 sta = ap_get_sta(hapd, addr);
2669 if (sta == NULL && iface->num_bss > 1) {
2670 size_t j;
2671 for (j = 0; j < iface->num_bss; j++) {
2672 hapd = iface->bss[j];
2673 sta = ap_get_sta(hapd, addr);
2674 if (sta)
2675 break;
2676 }
2677 }
2678 if (sta == NULL)
2679 return;
2680 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2681 return;
2682
2683 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2684 "activity poll", MAC2STR(sta->addr));
2685 sta->flags &= ~WLAN_STA_PENDING_POLL;
2686}
2687
2688
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002689void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2690 int wds)
2691{
2692 struct sta_info *sta;
2693
2694 sta = ap_get_sta(hapd, src);
2695 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002696 if (!hapd->conf->wds_sta)
2697 return;
2698
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002700 int ret;
2701 char ifname_wds[IFNAMSIZ + 1];
2702
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002703 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2704 "STA " MACSTR " (aid %u)",
2705 MAC2STR(sta->addr), sta->aid);
2706 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002707 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2708 sta->addr, sta->aid, 1);
2709 if (!ret)
2710 hostapd_set_wds_encryption(hapd, sta,
2711 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002712 }
2713 return;
2714 }
2715
2716 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2717 MACSTR, MAC2STR(src));
2718 if (src[0] & 0x01) {
2719 /* Broadcast bit set in SA?! Ignore the frame silently. */
2720 return;
2721 }
2722
2723 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2724 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2725 "already been sent, but no TX status yet known - "
2726 "ignore Class 3 frame issue with " MACSTR,
2727 MAC2STR(src));
2728 return;
2729 }
2730
2731 if (sta && (sta->flags & WLAN_STA_AUTH))
2732 hostapd_drv_sta_disassoc(
2733 hapd, src,
2734 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2735 else
2736 hostapd_drv_sta_deauth(
2737 hapd, src,
2738 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2739}
2740
2741
2742#endif /* CONFIG_NATIVE_WINDOWS */