blob: 89911b1fdd42fd9bced9ade35be26387c411098a [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
135u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
136 int probe)
137{
138 int capab = WLAN_CAPABILITY_ESS;
139 int privacy;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800140 int dfs;
141
142 /* Check if any of configured channels require DFS */
143 dfs = hostapd_is_dfs_required(hapd->iface);
144 if (dfs < 0) {
145 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
146 dfs);
147 dfs = 0;
148 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700149
150 if (hapd->iface->num_sta_no_short_preamble == 0 &&
151 hapd->iconf->preamble == SHORT_PREAMBLE)
152 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
153
154 privacy = hapd->conf->ssid.wep.keys_set;
155
156 if (hapd->conf->ieee802_1x &&
157 (hapd->conf->default_wep_key_len ||
158 hapd->conf->individual_wep_key_len))
159 privacy = 1;
160
161 if (hapd->conf->wpa)
162 privacy = 1;
163
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800164#ifdef CONFIG_HS20
165 if (hapd->conf->osen)
166 privacy = 1;
167#endif /* CONFIG_HS20 */
168
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700169 if (sta) {
170 int policy, def_klen;
171 if (probe && sta->ssid_probe) {
172 policy = sta->ssid_probe->security_policy;
173 def_klen = sta->ssid_probe->wep.default_len;
174 } else {
175 policy = sta->ssid->security_policy;
176 def_klen = sta->ssid->wep.default_len;
177 }
178 privacy = policy != SECURITY_PLAINTEXT;
179 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
180 privacy = 0;
181 }
182
183 if (privacy)
184 capab |= WLAN_CAPABILITY_PRIVACY;
185
186 if (hapd->iface->current_mode &&
187 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
188 hapd->iface->num_sta_no_short_slot_time == 0)
189 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
190
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800191 /*
192 * Currently, Spectrum Management capability bit is set when directly
193 * requested in configuration by spectrum_mgmt_required or when AP is
194 * running on DFS channel.
195 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
196 */
197 if (hapd->iface->current_mode &&
198 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
199 (hapd->iconf->spectrum_mgmt_required || dfs))
200 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
201
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800202 if (hapd->conf->radio_measurements)
203 capab |= IEEE80211_CAP_RRM;
204
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205 return capab;
206}
207
208
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700209static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
210 u16 auth_transaction, const u8 *challenge,
211 int iswep)
212{
213 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
214 HOSTAPD_LEVEL_DEBUG,
215 "authentication (shared key, transaction %d)",
216 auth_transaction);
217
218 if (auth_transaction == 1) {
219 if (!sta->challenge) {
220 /* Generate a pseudo-random challenge */
221 u8 key[8];
222 struct os_time now;
223 int r;
224 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
225 if (sta->challenge == NULL)
226 return WLAN_STATUS_UNSPECIFIED_FAILURE;
227
228 os_get_time(&now);
229 r = os_random();
230 os_memcpy(key, &now.sec, 4);
231 os_memcpy(key + 4, &r, 4);
232 rc4_skip(key, sizeof(key), 0,
233 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
234 }
235 return 0;
236 }
237
238 if (auth_transaction != 3)
239 return WLAN_STATUS_UNSPECIFIED_FAILURE;
240
241 /* Transaction 3 */
242 if (!iswep || !sta->challenge || !challenge ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700243 os_memcmp_const(sta->challenge, challenge,
244 WLAN_AUTH_CHALLENGE_LEN)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
246 HOSTAPD_LEVEL_INFO,
247 "shared key authentication - invalid "
248 "challenge-response");
249 return WLAN_STATUS_CHALLENGE_FAIL;
250 }
251
252 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
253 HOSTAPD_LEVEL_DEBUG,
254 "authentication OK (shared key)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700255 sta->flags |= WLAN_STA_AUTH;
256 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257 os_free(sta->challenge);
258 sta->challenge = NULL;
259
260 return 0;
261}
262
263
264static void send_auth_reply(struct hostapd_data *hapd,
265 const u8 *dst, const u8 *bssid,
266 u16 auth_alg, u16 auth_transaction, u16 resp,
267 const u8 *ies, size_t ies_len)
268{
269 struct ieee80211_mgmt *reply;
270 u8 *buf;
271 size_t rlen;
272
273 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
274 buf = os_zalloc(rlen);
275 if (buf == NULL)
276 return;
277
278 reply = (struct ieee80211_mgmt *) buf;
279 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
280 WLAN_FC_STYPE_AUTH);
281 os_memcpy(reply->da, dst, ETH_ALEN);
282 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
283 os_memcpy(reply->bssid, bssid, ETH_ALEN);
284
285 reply->u.auth.auth_alg = host_to_le16(auth_alg);
286 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
287 reply->u.auth.status_code = host_to_le16(resp);
288
289 if (ies && ies_len)
290 os_memcpy(reply->u.auth.variable, ies, ies_len);
291
292 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
293 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
294 MAC2STR(dst), auth_alg, auth_transaction,
295 resp, (unsigned long) ies_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800296 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800297 wpa_printf(MSG_INFO, "send_auth_reply: send");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298
299 os_free(buf);
300}
301
302
303#ifdef CONFIG_IEEE80211R
304static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
305 u16 auth_transaction, u16 status,
306 const u8 *ies, size_t ies_len)
307{
308 struct hostapd_data *hapd = ctx;
309 struct sta_info *sta;
310
311 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
312 status, ies, ies_len);
313
314 if (status != WLAN_STATUS_SUCCESS)
315 return;
316
317 sta = ap_get_sta(hapd, dst);
318 if (sta == NULL)
319 return;
320
321 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
322 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
323 sta->flags |= WLAN_STA_AUTH;
324 mlme_authenticate_indication(hapd, sta);
325}
326#endif /* CONFIG_IEEE80211R */
327
328
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800329#ifdef CONFIG_SAE
330
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800331#define dot11RSNASAERetransPeriod 40 /* msec */
332#define dot11RSNASAESync 5 /* attempts */
333
334
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800335static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
336 struct sta_info *sta, int update)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800337{
338 struct wpabuf *buf;
339
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800340 if (hapd->conf->ssid.wpa_passphrase == NULL) {
341 wpa_printf(MSG_DEBUG, "SAE: No password available");
342 return NULL;
343 }
344
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800345 if (update &&
346 sae_prepare_commit(hapd->own_addr, sta->addr,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800347 (u8 *) hapd->conf->ssid.wpa_passphrase,
348 os_strlen(hapd->conf->ssid.wpa_passphrase),
349 sta->sae) < 0) {
350 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
351 return NULL;
352 }
353
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800354 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800355 if (buf == NULL)
356 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800357 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
358 sta->sae->tmp->anti_clogging_token : NULL);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800359
360 return buf;
361}
362
363
364static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
365 struct sta_info *sta)
366{
367 struct wpabuf *buf;
368
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800369 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800370 if (buf == NULL)
371 return NULL;
372
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800373 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800374
375 return buf;
376}
377
378
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800379static int auth_sae_send_commit(struct hostapd_data *hapd,
380 struct sta_info *sta,
381 const u8 *bssid, int update)
382{
383 struct wpabuf *data;
384
385 data = auth_build_sae_commit(hapd, sta, update);
386 if (data == NULL)
387 return WLAN_STATUS_UNSPECIFIED_FAILURE;
388
389 send_auth_reply(hapd, sta->addr, bssid,
390 WLAN_AUTH_SAE, 1, WLAN_STATUS_SUCCESS,
391 wpabuf_head(data), wpabuf_len(data));
392
393 wpabuf_free(data);
394
395 return WLAN_STATUS_SUCCESS;
396}
397
398
399static int auth_sae_send_confirm(struct hostapd_data *hapd,
400 struct sta_info *sta,
401 const u8 *bssid)
402{
403 struct wpabuf *data;
404
405 data = auth_build_sae_confirm(hapd, sta);
406 if (data == NULL)
407 return WLAN_STATUS_UNSPECIFIED_FAILURE;
408
409 send_auth_reply(hapd, sta->addr, bssid,
410 WLAN_AUTH_SAE, 2, WLAN_STATUS_SUCCESS,
411 wpabuf_head(data), wpabuf_len(data));
412
413 wpabuf_free(data);
414
415 return WLAN_STATUS_SUCCESS;
416}
417
418
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800419static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800420{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800421 struct sta_info *sta;
422 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800423
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800424 if (hapd->conf->sae_anti_clogging_threshold == 0)
425 return 1;
426
427 for (sta = hapd->sta_list; sta; sta = sta->next) {
428 if (!sta->sae)
429 continue;
430 if (sta->sae->state != SAE_COMMITTED &&
431 sta->sae->state != SAE_CONFIRMED)
432 continue;
433 open++;
434 if (open >= hapd->conf->sae_anti_clogging_threshold)
435 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800436 }
437
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800438 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800439}
440
441
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800442static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
443 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800444{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800445 u8 mac[SHA256_MAC_LEN];
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800446
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800447 if (token_len != SHA256_MAC_LEN)
448 return -1;
449 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
450 addr, ETH_ALEN, mac) < 0 ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700451 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800452 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800453
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800454 return 0;
455}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800456
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800457
458static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800459 int group, const u8 *addr)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800460{
461 struct wpabuf *buf;
462 u8 *token;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800463 struct os_reltime now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800464
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800465 os_get_reltime(&now);
466 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
467 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800468 if (random_get_bytes(hapd->sae_token_key,
469 sizeof(hapd->sae_token_key)) < 0)
470 return NULL;
471 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
472 hapd->sae_token_key, sizeof(hapd->sae_token_key));
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800473 hapd->last_sae_token_key_update = now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800474 }
475
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800476 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800477 if (buf == NULL)
478 return NULL;
479
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800480 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
481
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800482 token = wpabuf_put(buf, SHA256_MAC_LEN);
483 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
484 addr, ETH_ALEN, token);
485
486 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800487}
488
489
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800490static int sae_check_big_sync(struct sta_info *sta)
491{
492 if (sta->sae->sync > dot11RSNASAESync) {
493 sta->sae->state = SAE_NOTHING;
494 sta->sae->sync = 0;
495 return -1;
496 }
497 return 0;
498}
499
500
501static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
502{
503 struct hostapd_data *hapd = eloop_ctx;
504 struct sta_info *sta = eloop_data;
505 int ret;
506
507 if (sae_check_big_sync(sta))
508 return;
509 sta->sae->sync++;
510
511 switch (sta->sae->state) {
512 case SAE_COMMITTED:
513 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
514 eloop_register_timeout(0, dot11RSNASAERetransPeriod * 1000,
515 auth_sae_retransmit_timer, hapd, sta);
516 break;
517 case SAE_CONFIRMED:
518 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
519 eloop_register_timeout(0, dot11RSNASAERetransPeriod * 1000,
520 auth_sae_retransmit_timer, hapd, sta);
521 break;
522 default:
523 ret = -1;
524 break;
525 }
526
527 if (ret != WLAN_STATUS_SUCCESS)
528 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
529}
530
531
532void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
533{
534 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
535}
536
537
538static void sae_set_retransmit_timer(struct hostapd_data *hapd,
539 struct sta_info *sta)
540{
541 if (!(hapd->conf->mesh & MESH_ENABLED))
542 return;
543
544 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
545 eloop_register_timeout(0, dot11RSNASAERetransPeriod * 1000,
546 auth_sae_retransmit_timer, hapd, sta);
547}
548
549
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800550static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
551 const u8 *bssid, u8 auth_transaction)
552{
553 int ret;
554
555 if (auth_transaction != 1 && auth_transaction != 2)
556 return WLAN_STATUS_UNSPECIFIED_FAILURE;
557
558 switch (sta->sae->state) {
559 case SAE_NOTHING:
560 if (auth_transaction == 1) {
561 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
562 if (ret)
563 return ret;
564 sta->sae->state = SAE_COMMITTED;
565
566 if (sae_process_commit(sta->sae) < 0)
567 return WLAN_STATUS_UNSPECIFIED_FAILURE;
568
569 /*
570 * In mesh case, both Commit and Confirm can be sent
571 * immediately. In infrastructure BSS, only a single
572 * Authentication frame (Commit) is expected from the AP
573 * here and the second one (Confirm) will be sent once
574 * the STA has sent its second Authentication frame
575 * (Confirm).
576 */
577 if (hapd->conf->mesh & MESH_ENABLED) {
578 /*
579 * Send both Commit and Confirm immediately
580 * based on SAE finite state machine
581 * Nothing -> Confirm transition.
582 */
583 ret = auth_sae_send_confirm(hapd, sta, bssid);
584 if (ret)
585 return ret;
586 sta->sae->state = SAE_CONFIRMED;
587 } else {
588 /*
589 * For infrastructure BSS, send only the Commit
590 * message now to get alternating sequence of
591 * Authentication frames between the AP and STA.
592 * Confirm will be sent in
593 * Commited -> Confirmed/Accepted transition
594 * when receiving Confirm from STA.
595 */
596 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800597 sta->sae->sync = 0;
598 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800599 } else {
600 hostapd_logger(hapd, sta->addr,
601 HOSTAPD_MODULE_IEEE80211,
602 HOSTAPD_LEVEL_DEBUG,
603 "SAE confirm before commit");
604 }
605 break;
606 case SAE_COMMITTED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800607 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800608 if (auth_transaction == 1) {
609 if (sae_process_commit(sta->sae) < 0)
610 return WLAN_STATUS_UNSPECIFIED_FAILURE;
611
612 ret = auth_sae_send_confirm(hapd, sta, bssid);
613 if (ret)
614 return ret;
615 sta->sae->state = SAE_CONFIRMED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800616 sta->sae->sync = 0;
617 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800618 } else if (hapd->conf->mesh & MESH_ENABLED) {
619 /*
620 * In mesh case, follow SAE finite state machine and
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800621 * send Commit now, if sync count allows.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800622 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800623 if (sae_check_big_sync(sta))
624 return WLAN_STATUS_SUCCESS;
625 sta->sae->sync++;
626
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800627 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
628 if (ret)
629 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800630
631 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800632 } else {
633 /*
634 * For instructure BSS, send the postponed Confirm from
635 * Nothing -> Confirmed transition that was reduced to
636 * Nothing -> Committed above.
637 */
638 ret = auth_sae_send_confirm(hapd, sta, bssid);
639 if (ret)
640 return ret;
641
642 sta->sae->state = SAE_CONFIRMED;
643
644 /*
645 * Since this was triggered on Confirm RX, run another
646 * step to get to Accepted without waiting for
647 * additional events.
648 */
649 return sae_sm_step(hapd, sta, bssid, auth_transaction);
650 }
651 break;
652 case SAE_CONFIRMED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800653 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800654 if (auth_transaction == 1) {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800655 if (sae_check_big_sync(sta))
656 return WLAN_STATUS_SUCCESS;
657 sta->sae->sync++;
658
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800659 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
660 if (ret)
661 return ret;
662
663 if (sae_process_commit(sta->sae) < 0)
664 return WLAN_STATUS_UNSPECIFIED_FAILURE;
665
666 ret = auth_sae_send_confirm(hapd, sta, bssid);
667 if (ret)
668 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800669
670 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800671 } else {
672 sta->flags |= WLAN_STA_AUTH;
673 sta->auth_alg = WLAN_AUTH_SAE;
674 mlme_authenticate_indication(hapd, sta);
675 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
676 sta->sae->state = SAE_ACCEPTED;
677 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
678 sta->sae->pmk);
679 }
680 break;
681 case SAE_ACCEPTED:
682 if (auth_transaction == 1) {
683 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
684 ") doing reauthentication",
685 MAC2STR(sta->addr));
686 ap_free_sta(hapd, sta);
687 } else {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800688 if (sae_check_big_sync(sta))
689 return WLAN_STATUS_SUCCESS;
690 sta->sae->sync++;
691
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800692 ret = auth_sae_send_confirm(hapd, sta, bssid);
693 sae_clear_temp_data(sta->sae);
694 if (ret)
695 return ret;
696 }
697 break;
698 default:
699 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
700 sta->sae->state);
701 return WLAN_STATUS_UNSPECIFIED_FAILURE;
702 }
703 return WLAN_STATUS_SUCCESS;
704}
705
706
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800707static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
708 const struct ieee80211_mgmt *mgmt, size_t len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800709 u16 auth_transaction, u16 status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800710{
711 u16 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800712 struct wpabuf *data = NULL;
713
714 if (!sta->sae) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800715 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800716 return;
717 sta->sae = os_zalloc(sizeof(*sta->sae));
718 if (sta->sae == NULL)
719 return;
720 sta->sae->state = SAE_NOTHING;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800721 sta->sae->sync = 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800722 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800723
724 if (auth_transaction == 1) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800725 const u8 *token = NULL, *pos, *end;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800726 size_t token_len = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800727 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
728 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800729 "start SAE authentication (RX commit, status=%u)",
730 status_code);
731
732 if ((hapd->conf->mesh & MESH_ENABLED) &&
733 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
734 sta->sae->tmp) {
735 pos = mgmt->u.auth.variable;
736 end = ((const u8 *) mgmt) + len;
737 if (pos + sizeof(le16) > end) {
738 wpa_printf(MSG_ERROR,
739 "SAE: Too short anti-clogging token request");
740 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
741 goto reply;
742 }
743 resp = sae_group_allowed(sta->sae,
744 hapd->conf->sae_groups,
745 WPA_GET_LE16(pos));
746 if (resp != WLAN_STATUS_SUCCESS) {
747 wpa_printf(MSG_ERROR,
748 "SAE: Invalid group in anti-clogging token request");
749 goto reply;
750 }
751 pos += sizeof(le16);
752
753 wpabuf_free(sta->sae->tmp->anti_clogging_token);
754 sta->sae->tmp->anti_clogging_token =
755 wpabuf_alloc_copy(pos, end - pos);
756 if (sta->sae->tmp->anti_clogging_token == NULL) {
757 wpa_printf(MSG_ERROR,
758 "SAE: Failed to alloc for anti-clogging token");
759 return;
760 }
761
762 /*
763 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
764 * is 76, a new Commit Message shall be constructed
765 * with the Anti-Clogging Token from the received
766 * Authentication frame, and the commit-scalar and
767 * COMMIT-ELEMENT previously sent.
768 */
769 if (auth_sae_send_commit(hapd, sta, mgmt->bssid, 0)) {
770 wpa_printf(MSG_ERROR,
771 "SAE: Failed to send commit message");
772 return;
773 }
774 sta->sae->state = SAE_COMMITTED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800775 sta->sae->sync = 0;
776 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800777 return;
778 }
779
780 if (status_code != WLAN_STATUS_SUCCESS)
781 return;
782
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800783 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
784 ((const u8 *) mgmt) + len -
785 mgmt->u.auth.variable, &token,
786 &token_len, hapd->conf->sae_groups);
787 if (token && check_sae_token(hapd, sta->addr, token, token_len)
788 < 0) {
789 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
790 "incorrect token from " MACSTR,
791 MAC2STR(sta->addr));
792 return;
793 }
794
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800795 if (resp != WLAN_STATUS_SUCCESS)
796 goto reply;
797
798 if (!token && use_sae_anti_clogging(hapd)) {
799 wpa_printf(MSG_DEBUG,
800 "SAE: Request anti-clogging token from "
801 MACSTR, MAC2STR(sta->addr));
802 data = auth_build_token_req(hapd, sta->sae->group,
803 sta->addr);
804 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
805 if (hapd->conf->mesh & MESH_ENABLED)
806 sta->sae->state = SAE_NOTHING;
807 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800808 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800809
810 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800811 } else if (auth_transaction == 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800812 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
813 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800814 "SAE authentication (RX confirm, status=%u)",
815 status_code);
816 if (status_code != WLAN_STATUS_SUCCESS)
817 return;
818 if (sta->sae->state >= SAE_CONFIRMED ||
819 !(hapd->conf->mesh & MESH_ENABLED)) {
820 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
821 ((u8 *) mgmt) + len -
822 mgmt->u.auth.variable) < 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800823 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800824 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800825 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800826 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800827 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800828 } else {
829 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
830 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800831 "unexpected SAE authentication transaction %u (status=%u)",
832 auth_transaction, status_code);
833 if (status_code != WLAN_STATUS_SUCCESS)
834 return;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800835 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
836 }
837
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800838reply:
839 if (resp != WLAN_STATUS_SUCCESS) {
840 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
841 auth_transaction, resp,
842 data ? wpabuf_head(data) : (u8 *) "",
843 data ? wpabuf_len(data) : 0);
844 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800845 wpabuf_free(data);
846}
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800847
848
849/**
850 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
851 * @hapd: BSS data for the device initiating the authentication
852 * @sta: the peer to which commit authentication frame is sent
853 *
854 * This function implements Init event handling (IEEE Std 802.11-2012,
855 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
856 * sta->sae structure should be initialized appropriately via a call to
857 * sae_prepare_commit().
858 */
859int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
860{
861 int ret;
862
863 if (!sta->sae || !sta->sae->tmp)
864 return -1;
865
866 if (sta->sae->state != SAE_NOTHING)
867 return -1;
868
869 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
870 if (ret)
871 return -1;
872
873 sta->sae->state = SAE_COMMITTED;
874 sta->sae->sync = 0;
875 sae_set_retransmit_timer(hapd, sta);
876
877 return 0;
878}
879
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800880#endif /* CONFIG_SAE */
881
882
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700883static void handle_auth(struct hostapd_data *hapd,
884 const struct ieee80211_mgmt *mgmt, size_t len)
885{
886 u16 auth_alg, auth_transaction, status_code;
887 u16 resp = WLAN_STATUS_SUCCESS;
888 struct sta_info *sta = NULL;
889 int res;
890 u16 fc;
891 const u8 *challenge = NULL;
892 u32 session_timeout, acct_interim_interval;
893 int vlan_id = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800894 struct hostapd_sta_wpa_psk_short *psk = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
896 size_t resp_ies_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700897 char *identity = NULL;
898 char *radius_cui = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800899 u16 seq_ctrl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900
901 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800902 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
903 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700904 return;
905 }
906
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700907#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700908 if (hapd->iconf->ignore_auth_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700909 drand48() < hapd->iconf->ignore_auth_probability) {
910 wpa_printf(MSG_INFO,
911 "TESTING: ignoring auth frame from " MACSTR,
912 MAC2STR(mgmt->sa));
913 return;
914 }
915#endif /* CONFIG_TESTING_OPTIONS */
916
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
918 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
919 status_code = le_to_host16(mgmt->u.auth.status_code);
920 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800921 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922
923 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
924 2 + WLAN_AUTH_CHALLENGE_LEN &&
925 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
926 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
927 challenge = &mgmt->u.auth.variable[2];
928
929 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800930 "auth_transaction=%d status_code=%d wep=%d%s "
931 "seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700932 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
933 status_code, !!(fc & WLAN_FC_ISWEP),
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800934 challenge ? " challenge" : "",
935 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936
937 if (hapd->tkip_countermeasures) {
938 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
939 goto fail;
940 }
941
942 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
943 auth_alg == WLAN_AUTH_OPEN) ||
944#ifdef CONFIG_IEEE80211R
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800945 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 auth_alg == WLAN_AUTH_FT) ||
947#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800948#ifdef CONFIG_SAE
949 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
950 auth_alg == WLAN_AUTH_SAE) ||
951#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700952 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
953 auth_alg == WLAN_AUTH_SHARED_KEY))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800954 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
955 auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700956 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
957 goto fail;
958 }
959
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800960 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800962 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
963 auth_transaction);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700964 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
965 goto fail;
966 }
967
968 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800969 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
970 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
972 goto fail;
973 }
974
975 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
976 &session_timeout,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800977 &acct_interim_interval, &vlan_id,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800978 &psk, &identity, &radius_cui);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800979
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980 if (res == HOSTAPD_ACL_REJECT) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800981 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
982 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700983 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
984 goto fail;
985 }
986 if (res == HOSTAPD_ACL_PENDING) {
987 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
988 " waiting for an external authentication",
989 MAC2STR(mgmt->sa));
990 /* Authentication code will re-send the authentication frame
991 * after it has received (and cached) information from the
992 * external source. */
993 return;
994 }
995
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800996 sta = ap_get_sta(hapd, mgmt->sa);
997 if (sta) {
998 if ((fc & WLAN_FC_RETRY) &&
999 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1000 sta->last_seq_ctrl == seq_ctrl &&
1001 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1002 hostapd_logger(hapd, sta->addr,
1003 HOSTAPD_MODULE_IEEE80211,
1004 HOSTAPD_LEVEL_DEBUG,
1005 "Drop repeated authentication frame seq_ctrl=0x%x",
1006 seq_ctrl);
1007 return;
1008 }
1009 } else {
1010#ifdef CONFIG_MESH
1011 if (hapd->conf->mesh & MESH_ENABLED) {
1012 /* if the mesh peer is not available, we don't do auth.
1013 */
1014 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1015 " not yet known - drop Authentiation frame",
1016 MAC2STR(mgmt->sa));
1017 /*
1018 * Save a copy of the frame so that it can be processed
1019 * if a new peer entry is added shortly after this.
1020 */
1021 wpabuf_free(hapd->mesh_pending_auth);
1022 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1023 os_get_reltime(&hapd->mesh_pending_auth_time);
1024 return;
1025 }
1026#endif /* CONFIG_MESH */
1027
1028 sta = ap_sta_add(hapd, mgmt->sa);
1029 if (!sta) {
1030 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1031 goto fail;
1032 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001034 sta->last_seq_ctrl = seq_ctrl;
1035 sta->last_subtype = WLAN_FC_STYPE_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036
1037 if (vlan_id > 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001038 if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001039 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1040 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
1041 "%d received from RADIUS server",
1042 vlan_id);
1043 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1044 goto fail;
1045 }
1046 sta->vlan_id = vlan_id;
1047 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1048 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1049 }
1050
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001051 hostapd_free_psk_list(sta->psk);
1052 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1053 sta->psk = psk;
1054 psk = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001055 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001056 sta->psk = NULL;
1057 }
1058
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001059 sta->identity = identity;
1060 identity = NULL;
1061 sta->radius_cui = radius_cui;
1062 radius_cui = NULL;
1063
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001064 sta->flags &= ~WLAN_STA_PREAUTH;
1065 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1066
1067 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1068 sta->acct_interim_interval = acct_interim_interval;
1069 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1070 ap_sta_session_timeout(hapd, sta, session_timeout);
1071 else
1072 ap_sta_no_session_timeout(hapd, sta);
1073
1074 switch (auth_alg) {
1075 case WLAN_AUTH_OPEN:
1076 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1077 HOSTAPD_LEVEL_DEBUG,
1078 "authentication OK (open system)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001079 sta->flags |= WLAN_STA_AUTH;
1080 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1081 sta->auth_alg = WLAN_AUTH_OPEN;
1082 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 break;
1084 case WLAN_AUTH_SHARED_KEY:
1085 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1086 fc & WLAN_FC_ISWEP);
1087 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1088 mlme_authenticate_indication(hapd, sta);
1089 if (sta->challenge && auth_transaction == 1) {
1090 resp_ies[0] = WLAN_EID_CHALLENGE;
1091 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1092 os_memcpy(resp_ies + 2, sta->challenge,
1093 WLAN_AUTH_CHALLENGE_LEN);
1094 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1095 }
1096 break;
1097#ifdef CONFIG_IEEE80211R
1098 case WLAN_AUTH_FT:
1099 sta->auth_alg = WLAN_AUTH_FT;
1100 if (sta->wpa_sm == NULL)
1101 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001102 sta->addr, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 if (sta->wpa_sm == NULL) {
1104 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1105 "state machine");
1106 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1107 goto fail;
1108 }
1109 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1110 auth_transaction, mgmt->u.auth.variable,
1111 len - IEEE80211_HDRLEN -
1112 sizeof(mgmt->u.auth),
1113 handle_auth_ft_finish, hapd);
1114 /* handle_auth_ft_finish() callback will complete auth. */
1115 return;
1116#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001117#ifdef CONFIG_SAE
1118 case WLAN_AUTH_SAE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001119#ifdef CONFIG_MESH
1120 if (status_code == WLAN_STATUS_SUCCESS &&
1121 hapd->conf->mesh & MESH_ENABLED) {
1122 if (sta->wpa_sm == NULL)
1123 sta->wpa_sm =
1124 wpa_auth_sta_init(hapd->wpa_auth,
1125 sta->addr, NULL);
1126 if (sta->wpa_sm == NULL) {
1127 wpa_printf(MSG_DEBUG,
1128 "SAE: Failed to initialize WPA state machine");
1129 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1130 goto fail;
1131 }
1132 }
1133#endif /* CONFIG_MESH */
1134 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1135 status_code);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001136 return;
1137#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001138 }
1139
1140 fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001141 os_free(identity);
1142 os_free(radius_cui);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001143 hostapd_free_psk_list(psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001144
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1146 auth_transaction + 1, resp, resp_ies, resp_ies_len);
1147}
1148
1149
1150static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
1151{
1152 int i, j = 32, aid;
1153
1154 /* get a unique AID */
1155 if (sta->aid > 0) {
1156 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1157 return 0;
1158 }
1159
1160 for (i = 0; i < AID_WORDS; i++) {
1161 if (hapd->sta_aid[i] == (u32) -1)
1162 continue;
1163 for (j = 0; j < 32; j++) {
1164 if (!(hapd->sta_aid[i] & BIT(j)))
1165 break;
1166 }
1167 if (j < 32)
1168 break;
1169 }
1170 if (j == 32)
1171 return -1;
1172 aid = i * 32 + j + 1;
1173 if (aid > 2007)
1174 return -1;
1175
1176 sta->aid = aid;
1177 hapd->sta_aid[i] |= BIT(j);
1178 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1179 return 0;
1180}
1181
1182
1183static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1184 const u8 *ssid_ie, size_t ssid_ie_len)
1185{
1186 if (ssid_ie == NULL)
1187 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1188
1189 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1190 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1192 HOSTAPD_LEVEL_INFO,
1193 "Station tried to associate with unknown SSID "
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001194 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001195 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1196 }
1197
1198 return WLAN_STATUS_SUCCESS;
1199}
1200
1201
1202static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1203 const u8 *wmm_ie, size_t wmm_ie_len)
1204{
1205 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001206 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001208 struct wmm_information_element *wmm;
1209
1210 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001211 hostapd_logger(hapd, sta->addr,
1212 HOSTAPD_MODULE_WPA,
1213 HOSTAPD_LEVEL_DEBUG,
1214 "invalid WMM element in association "
1215 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001216 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1217 }
1218
1219 sta->flags |= WLAN_STA_WMM;
1220 wmm = (struct wmm_information_element *) wmm_ie;
1221 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 }
1223 return WLAN_STATUS_SUCCESS;
1224}
1225
1226
1227static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1228 struct ieee802_11_elems *elems)
1229{
1230 if (!elems->supp_rates) {
1231 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1232 HOSTAPD_LEVEL_DEBUG,
1233 "No supported rates element in AssocReq");
1234 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1235 }
1236
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001237 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1238 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001239 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1240 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001241 "Invalid supported rates element length %d+%d",
1242 elems->supp_rates_len,
1243 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1245 }
1246
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001247 sta->supported_rates_len = merge_byte_arrays(
1248 sta->supported_rates, sizeof(sta->supported_rates),
1249 elems->supp_rates, elems->supp_rates_len,
1250 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001251
1252 return WLAN_STATUS_SUCCESS;
1253}
1254
1255
Dmitry Shmidt051af732013-10-22 13:52:46 -07001256static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1257 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1258{
1259#ifdef CONFIG_INTERWORKING
1260 /* check for QoS Map support */
1261 if (ext_capab_ie_len >= 5) {
1262 if (ext_capab_ie[4] & 0x01)
1263 sta->qos_map_enabled = 1;
1264 }
1265#endif /* CONFIG_INTERWORKING */
1266
1267 return WLAN_STATUS_SUCCESS;
1268}
1269
1270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1272 const u8 *ies, size_t ies_len, int reassoc)
1273{
1274 struct ieee802_11_elems elems;
1275 u16 resp;
1276 const u8 *wpa_ie;
1277 size_t wpa_ie_len;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001278 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001279
1280 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1281 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1282 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1283 "association request");
1284 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1285 }
1286
1287 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1288 if (resp != WLAN_STATUS_SUCCESS)
1289 return resp;
1290 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1291 if (resp != WLAN_STATUS_SUCCESS)
1292 return resp;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001293 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1294 if (resp != WLAN_STATUS_SUCCESS)
1295 return resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001296 resp = copy_supp_rates(hapd, sta, &elems);
1297 if (resp != WLAN_STATUS_SUCCESS)
1298 return resp;
1299#ifdef CONFIG_IEEE80211N
1300 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
1301 elems.ht_capabilities_len);
1302 if (resp != WLAN_STATUS_SUCCESS)
1303 return resp;
1304 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1305 !(sta->flags & WLAN_STA_HT)) {
1306 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1307 HOSTAPD_LEVEL_INFO, "Station does not support "
1308 "mandatory HT PHY - reject association");
1309 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1310 }
1311#endif /* CONFIG_IEEE80211N */
1312
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001313#ifdef CONFIG_IEEE80211AC
1314 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
1315 elems.vht_capabilities_len);
1316 if (resp != WLAN_STATUS_SUCCESS)
1317 return resp;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08001318
1319 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1320 if (resp != WLAN_STATUS_SUCCESS)
1321 return resp;
1322
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001323 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1324 !(sta->flags & WLAN_STA_VHT)) {
1325 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1326 HOSTAPD_LEVEL_INFO, "Station does not support "
1327 "mandatory VHT PHY - reject association");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001328 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001329 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001330
1331 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1332 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1333 elems.vendor_vht_len);
1334 if (resp != WLAN_STATUS_SUCCESS)
1335 return resp;
1336 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001337#endif /* CONFIG_IEEE80211AC */
1338
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001339#ifdef CONFIG_P2P
1340 if (elems.p2p) {
1341 wpabuf_free(sta->p2p_ie);
1342 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1343 P2P_IE_VENDOR_TYPE);
1344 if (sta->p2p_ie)
1345 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1346 } else {
1347 wpabuf_free(sta->p2p_ie);
1348 sta->p2p_ie = NULL;
1349 }
1350#endif /* CONFIG_P2P */
1351
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1353 wpa_ie = elems.rsn_ie;
1354 wpa_ie_len = elems.rsn_ie_len;
1355 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1356 elems.wpa_ie) {
1357 wpa_ie = elems.wpa_ie;
1358 wpa_ie_len = elems.wpa_ie_len;
1359 } else {
1360 wpa_ie = NULL;
1361 wpa_ie_len = 0;
1362 }
1363
1364#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001365 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001366 if (hapd->conf->wps_state && elems.wps_ie) {
1367 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1368 "Request - assume WPS is used");
1369 sta->flags |= WLAN_STA_WPS;
1370 wpabuf_free(sta->wps_ie);
1371 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1372 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001373 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1374 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1375 sta->flags |= WLAN_STA_WPS2;
1376 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001377 wpa_ie = NULL;
1378 wpa_ie_len = 0;
1379 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1380 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1381 "(Re)Association Request - reject");
1382 return WLAN_STATUS_INVALID_IE;
1383 }
1384 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1385 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1386 "(Re)Association Request - possible WPS use");
1387 sta->flags |= WLAN_STA_MAYBE_WPS;
1388 } else
1389#endif /* CONFIG_WPS */
1390 if (hapd->conf->wpa && wpa_ie == NULL) {
1391 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1392 HOSTAPD_LEVEL_INFO,
1393 "No WPA/RSN IE in association request");
1394 return WLAN_STATUS_INVALID_IE;
1395 }
1396
1397 if (hapd->conf->wpa && wpa_ie) {
1398 int res;
1399 wpa_ie -= 2;
1400 wpa_ie_len += 2;
1401 if (sta->wpa_sm == NULL)
1402 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001403 sta->addr,
1404 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001405 if (sta->wpa_sm == NULL) {
1406 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1407 "state machine");
1408 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1409 }
1410 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1411 wpa_ie, wpa_ie_len,
1412 elems.mdie, elems.mdie_len);
1413 if (res == WPA_INVALID_GROUP)
1414 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1415 else if (res == WPA_INVALID_PAIRWISE)
1416 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1417 else if (res == WPA_INVALID_AKMP)
1418 resp = WLAN_STATUS_AKMP_NOT_VALID;
1419 else if (res == WPA_ALLOC_FAIL)
1420 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1421#ifdef CONFIG_IEEE80211W
1422 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1423 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1424 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1425 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1426#endif /* CONFIG_IEEE80211W */
1427 else if (res == WPA_INVALID_MDIE)
1428 resp = WLAN_STATUS_INVALID_MDIE;
1429 else if (res != WPA_IE_OK)
1430 resp = WLAN_STATUS_INVALID_IE;
1431 if (resp != WLAN_STATUS_SUCCESS)
1432 return resp;
1433#ifdef CONFIG_IEEE80211W
1434 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1435 sta->sa_query_count > 0)
1436 ap_check_sa_query_timeout(hapd, sta);
1437 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1438 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1439 /*
1440 * STA has already been associated with MFP and SA
1441 * Query timeout has not been reached. Reject the
1442 * association attempt temporarily and start SA Query,
1443 * if one is not pending.
1444 */
1445
1446 if (sta->sa_query_count == 0)
1447 ap_sta_start_sa_query(hapd, sta);
1448
1449 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1450 }
1451
1452 if (wpa_auth_uses_mfp(sta->wpa_sm))
1453 sta->flags |= WLAN_STA_MFP;
1454 else
1455 sta->flags &= ~WLAN_STA_MFP;
1456#endif /* CONFIG_IEEE80211W */
1457
1458#ifdef CONFIG_IEEE80211R
1459 if (sta->auth_alg == WLAN_AUTH_FT) {
1460 if (!reassoc) {
1461 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1462 "to use association (not "
1463 "re-association) with FT auth_alg",
1464 MAC2STR(sta->addr));
1465 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1466 }
1467
1468 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1469 ies_len);
1470 if (resp != WLAN_STATUS_SUCCESS)
1471 return resp;
1472 }
1473#endif /* CONFIG_IEEE80211R */
1474
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001475#ifdef CONFIG_SAE
1476 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001477 sta->auth_alg == WLAN_AUTH_OPEN) {
1478 struct rsn_pmksa_cache_entry *sa;
1479 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1480 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1481 wpa_printf(MSG_DEBUG,
1482 "SAE: No PMKSA cache entry found for "
1483 MACSTR, MAC2STR(sta->addr));
1484 return WLAN_STATUS_INVALID_PMKID;
1485 }
1486 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1487 " using PMKSA caching", MAC2STR(sta->addr));
1488 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1489 sta->auth_alg != WLAN_AUTH_SAE &&
1490 !(sta->auth_alg == WLAN_AUTH_FT &&
1491 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001492 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1493 "SAE AKM after non-SAE auth_alg %u",
1494 MAC2STR(sta->addr), sta->auth_alg);
1495 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1496 }
1497#endif /* CONFIG_SAE */
1498
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001499#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001500 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001501 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1502 hostapd_logger(hapd, sta->addr,
1503 HOSTAPD_MODULE_IEEE80211,
1504 HOSTAPD_LEVEL_INFO,
1505 "Station tried to use TKIP with HT "
1506 "association");
1507 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1508 }
1509#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001510#ifdef CONFIG_HS20
1511 } else if (hapd->conf->osen) {
1512 if (elems.osen == NULL) {
1513 hostapd_logger(
1514 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1515 HOSTAPD_LEVEL_INFO,
1516 "No HS 2.0 OSEN element in association request");
1517 return WLAN_STATUS_INVALID_IE;
1518 }
1519
1520 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1521 if (sta->wpa_sm == NULL)
1522 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1523 sta->addr, NULL);
1524 if (sta->wpa_sm == NULL) {
1525 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1526 "state machine");
1527 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1528 }
1529 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1530 elems.osen - 2, elems.osen_len + 2) < 0)
1531 return WLAN_STATUS_INVALID_IE;
1532#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001533 } else
1534 wpa_auth_sta_no_wpa(sta->wpa_sm);
1535
1536#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1538#endif /* CONFIG_P2P */
1539
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001540#ifdef CONFIG_HS20
1541 wpabuf_free(sta->hs20_ie);
1542 if (elems.hs20 && elems.hs20_len > 4) {
1543 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1544 elems.hs20_len - 4);
1545 } else
1546 sta->hs20_ie = NULL;
1547#endif /* CONFIG_HS20 */
1548
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001549 return WLAN_STATUS_SUCCESS;
1550}
1551
1552
1553static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1554 u16 reason_code)
1555{
1556 int send_len;
1557 struct ieee80211_mgmt reply;
1558
1559 os_memset(&reply, 0, sizeof(reply));
1560 reply.frame_control =
1561 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1562 os_memcpy(reply.da, addr, ETH_ALEN);
1563 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1564 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1565
1566 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1567 reply.u.deauth.reason_code = host_to_le16(reason_code);
1568
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001569 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001570 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1571 strerror(errno));
1572}
1573
1574
1575static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1576 u16 status_code, int reassoc, const u8 *ies,
1577 size_t ies_len)
1578{
1579 int send_len;
1580 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1581 struct ieee80211_mgmt *reply;
1582 u8 *p;
1583
1584 os_memset(buf, 0, sizeof(buf));
1585 reply = (struct ieee80211_mgmt *) buf;
1586 reply->frame_control =
1587 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1588 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1589 WLAN_FC_STYPE_ASSOC_RESP));
1590 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1591 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1592 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1593
1594 send_len = IEEE80211_HDRLEN;
1595 send_len += sizeof(reply->u.assoc_resp);
1596 reply->u.assoc_resp.capab_info =
1597 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1598 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001599 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001600 /* Supported rates */
1601 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1602 /* Extended supported rates */
1603 p = hostapd_eid_ext_supp_rates(hapd, p);
1604
1605#ifdef CONFIG_IEEE80211R
1606 if (status_code == WLAN_STATUS_SUCCESS) {
1607 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1608 * Transition Information, RSN, [RIC Response] */
1609 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1610 buf + sizeof(buf) - p,
1611 sta->auth_alg, ies, ies_len);
1612 }
1613#endif /* CONFIG_IEEE80211R */
1614
1615#ifdef CONFIG_IEEE80211W
1616 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1617 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1618#endif /* CONFIG_IEEE80211W */
1619
1620#ifdef CONFIG_IEEE80211N
1621 p = hostapd_eid_ht_capabilities(hapd, p);
1622 p = hostapd_eid_ht_operation(hapd, p);
1623#endif /* CONFIG_IEEE80211N */
1624
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001625#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001626 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1627 p = hostapd_eid_vht_capabilities(hapd, p);
1628 p = hostapd_eid_vht_operation(hapd, p);
1629 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001630#endif /* CONFIG_IEEE80211AC */
1631
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001632 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001633 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001634 if (sta->qos_map_enabled)
1635 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001636
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001637#ifdef CONFIG_IEEE80211AC
1638 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1639 p = hostapd_eid_vendor_vht(hapd, p);
1640#endif /* CONFIG_IEEE80211AC */
1641
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001642 if (sta->flags & WLAN_STA_WMM)
1643 p = hostapd_eid_wmm(hapd, p);
1644
1645#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001646 if ((sta->flags & WLAN_STA_WPS) ||
1647 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001648 struct wpabuf *wps = wps_build_assoc_resp_ie();
1649 if (wps) {
1650 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1651 p += wpabuf_len(wps);
1652 wpabuf_free(wps);
1653 }
1654 }
1655#endif /* CONFIG_WPS */
1656
1657#ifdef CONFIG_P2P
1658 if (sta->p2p_ie) {
1659 struct wpabuf *p2p_resp_ie;
1660 enum p2p_status_code status;
1661 switch (status_code) {
1662 case WLAN_STATUS_SUCCESS:
1663 status = P2P_SC_SUCCESS;
1664 break;
1665 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1666 status = P2P_SC_FAIL_LIMIT_REACHED;
1667 break;
1668 default:
1669 status = P2P_SC_FAIL_INVALID_PARAMS;
1670 break;
1671 }
1672 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1673 if (p2p_resp_ie) {
1674 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1675 wpabuf_len(p2p_resp_ie));
1676 p += wpabuf_len(p2p_resp_ie);
1677 wpabuf_free(p2p_resp_ie);
1678 }
1679 }
1680#endif /* CONFIG_P2P */
1681
1682#ifdef CONFIG_P2P_MANAGER
1683 if (hapd->conf->p2p & P2P_MANAGE)
1684 p = hostapd_eid_p2p_manage(hapd, p);
1685#endif /* CONFIG_P2P_MANAGER */
1686
1687 send_len += p - reply->u.assoc_resp.variable;
1688
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001689 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001690 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1691 strerror(errno));
1692}
1693
1694
1695static void handle_assoc(struct hostapd_data *hapd,
1696 const struct ieee80211_mgmt *mgmt, size_t len,
1697 int reassoc)
1698{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001699 u16 capab_info, listen_interval, seq_ctrl, fc;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001700 u16 resp = WLAN_STATUS_SUCCESS;
1701 const u8 *pos;
1702 int left, i;
1703 struct sta_info *sta;
1704
1705 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1706 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001707 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1708 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001709 return;
1710 }
1711
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001712#ifdef CONFIG_TESTING_OPTIONS
1713 if (reassoc) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001714 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001715 drand48() < hapd->iconf->ignore_reassoc_probability) {
1716 wpa_printf(MSG_INFO,
1717 "TESTING: ignoring reassoc request from "
1718 MACSTR, MAC2STR(mgmt->sa));
1719 return;
1720 }
1721 } else {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001722 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001723 drand48() < hapd->iconf->ignore_assoc_probability) {
1724 wpa_printf(MSG_INFO,
1725 "TESTING: ignoring assoc request from "
1726 MACSTR, MAC2STR(mgmt->sa));
1727 return;
1728 }
1729 }
1730#endif /* CONFIG_TESTING_OPTIONS */
1731
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001732 fc = le_to_host16(mgmt->frame_control);
1733 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1734
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001735 if (reassoc) {
1736 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1737 listen_interval = le_to_host16(
1738 mgmt->u.reassoc_req.listen_interval);
1739 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1740 " capab_info=0x%02x listen_interval=%d current_ap="
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001741 MACSTR " seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001742 MAC2STR(mgmt->sa), capab_info, listen_interval,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001743 MAC2STR(mgmt->u.reassoc_req.current_ap),
1744 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001745 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1746 pos = mgmt->u.reassoc_req.variable;
1747 } else {
1748 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1749 listen_interval = le_to_host16(
1750 mgmt->u.assoc_req.listen_interval);
1751 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001752 " capab_info=0x%02x listen_interval=%d "
1753 "seq_ctrl=0x%x%s",
1754 MAC2STR(mgmt->sa), capab_info, listen_interval,
1755 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1757 pos = mgmt->u.assoc_req.variable;
1758 }
1759
1760 sta = ap_get_sta(hapd, mgmt->sa);
1761#ifdef CONFIG_IEEE80211R
1762 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1763 (sta->flags & WLAN_STA_AUTH) == 0) {
1764 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1765 "prior to authentication since it is using "
1766 "over-the-DS FT", MAC2STR(mgmt->sa));
1767 } else
1768#endif /* CONFIG_IEEE80211R */
1769 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1770 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1771 HOSTAPD_LEVEL_INFO, "Station tried to "
1772 "associate before authentication "
1773 "(aid=%d flags=0x%x)",
1774 sta ? sta->aid : -1,
1775 sta ? sta->flags : 0);
1776 send_deauth(hapd, mgmt->sa,
1777 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1778 return;
1779 }
1780
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001781 if ((fc & WLAN_FC_RETRY) &&
1782 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1783 sta->last_seq_ctrl == seq_ctrl &&
1784 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1785 WLAN_FC_STYPE_ASSOC_REQ) {
1786 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1787 HOSTAPD_LEVEL_DEBUG,
1788 "Drop repeated association frame seq_ctrl=0x%x",
1789 seq_ctrl);
1790 return;
1791 }
1792 sta->last_seq_ctrl = seq_ctrl;
1793 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1794 WLAN_FC_STYPE_ASSOC_REQ;
1795
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001796 if (hapd->tkip_countermeasures) {
1797 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1798 goto fail;
1799 }
1800
1801 if (listen_interval > hapd->conf->max_listen_interval) {
1802 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1803 HOSTAPD_LEVEL_DEBUG,
1804 "Too large Listen Interval (%d)",
1805 listen_interval);
1806 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1807 goto fail;
1808 }
1809
1810 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1811 * is used */
1812 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1813 if (resp != WLAN_STATUS_SUCCESS)
1814 goto fail;
1815
1816 if (hostapd_get_aid(hapd, sta) < 0) {
1817 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1818 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1819 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1820 goto fail;
1821 }
1822
1823 sta->capability = capab_info;
1824 sta->listen_interval = listen_interval;
1825
1826 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1827 sta->flags |= WLAN_STA_NONERP;
1828 for (i = 0; i < sta->supported_rates_len; i++) {
1829 if ((sta->supported_rates[i] & 0x7f) > 22) {
1830 sta->flags &= ~WLAN_STA_NONERP;
1831 break;
1832 }
1833 }
1834 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1835 sta->nonerp_set = 1;
1836 hapd->iface->num_sta_non_erp++;
1837 if (hapd->iface->num_sta_non_erp == 1)
1838 ieee802_11_set_beacons(hapd->iface);
1839 }
1840
1841 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1842 !sta->no_short_slot_time_set) {
1843 sta->no_short_slot_time_set = 1;
1844 hapd->iface->num_sta_no_short_slot_time++;
1845 if (hapd->iface->current_mode->mode ==
1846 HOSTAPD_MODE_IEEE80211G &&
1847 hapd->iface->num_sta_no_short_slot_time == 1)
1848 ieee802_11_set_beacons(hapd->iface);
1849 }
1850
1851 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1852 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1853 else
1854 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1855
1856 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1857 !sta->no_short_preamble_set) {
1858 sta->no_short_preamble_set = 1;
1859 hapd->iface->num_sta_no_short_preamble++;
1860 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1861 && hapd->iface->num_sta_no_short_preamble == 1)
1862 ieee802_11_set_beacons(hapd->iface);
1863 }
1864
1865#ifdef CONFIG_IEEE80211N
1866 update_ht_state(hapd, sta);
1867#endif /* CONFIG_IEEE80211N */
1868
1869 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1870 HOSTAPD_LEVEL_DEBUG,
1871 "association OK (aid %d)", sta->aid);
1872 /* Station will be marked associated, after it acknowledges AssocResp
1873 */
1874 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1875
1876#ifdef CONFIG_IEEE80211W
1877 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1878 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1879 "SA Query procedure", reassoc ? "re" : "");
1880 /* TODO: Send a protected Disassociate frame to the STA using
1881 * the old key and Reason Code "Previous Authentication no
1882 * longer valid". Make sure this is only sent protected since
1883 * unprotected frame would be received by the STA that is now
1884 * trying to associate.
1885 */
1886 }
1887#endif /* CONFIG_IEEE80211W */
1888
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001889 /* Make sure that the previously registered inactivity timer will not
1890 * remove the STA immediately. */
1891 sta->timeout_next = STA_NULLFUNC;
1892
1893 fail:
1894 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1895}
1896
1897
1898static void handle_disassoc(struct hostapd_data *hapd,
1899 const struct ieee80211_mgmt *mgmt, size_t len)
1900{
1901 struct sta_info *sta;
1902
1903 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001904 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1905 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001906 return;
1907 }
1908
1909 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1910 MAC2STR(mgmt->sa),
1911 le_to_host16(mgmt->u.disassoc.reason_code));
1912
1913 sta = ap_get_sta(hapd, mgmt->sa);
1914 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001915 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1916 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001917 return;
1918 }
1919
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001920 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001921 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001922 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001923 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1924 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1925 HOSTAPD_LEVEL_INFO, "disassociated");
1926 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1927 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1928 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1929 * authenticated. */
1930 accounting_sta_stop(hapd, sta);
1931 ieee802_1x_free_station(sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001932 if (sta->ipaddr)
1933 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
1934 ap_sta_ip6addr_del(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001935 hostapd_drv_sta_remove(hapd, sta->addr);
1936
1937 if (sta->timeout_next == STA_NULLFUNC ||
1938 sta->timeout_next == STA_DISASSOC) {
1939 sta->timeout_next = STA_DEAUTH;
1940 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1941 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1942 hapd, sta);
1943 }
1944
1945 mlme_disassociate_indication(
1946 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1947}
1948
1949
1950static void handle_deauth(struct hostapd_data *hapd,
1951 const struct ieee80211_mgmt *mgmt, size_t len)
1952{
1953 struct sta_info *sta;
1954
1955 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001956 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1957 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001958 return;
1959 }
1960
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001961 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001962 " reason_code=%d",
1963 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1964
1965 sta = ap_get_sta(hapd, mgmt->sa);
1966 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001967 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1968 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001969 MAC2STR(mgmt->sa));
1970 return;
1971 }
1972
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001973 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001974 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001975 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1976 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001977 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1978 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1979 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1980 mlme_deauthenticate_indication(
1981 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1982 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1983 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1984 ap_free_sta(hapd, sta);
1985}
1986
1987
1988static void handle_beacon(struct hostapd_data *hapd,
1989 const struct ieee80211_mgmt *mgmt, size_t len,
1990 struct hostapd_frame_info *fi)
1991{
1992 struct ieee802_11_elems elems;
1993
1994 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001995 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
1996 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001997 return;
1998 }
1999
2000 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2001 len - (IEEE80211_HDRLEN +
2002 sizeof(mgmt->u.beacon)), &elems,
2003 0);
2004
2005 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2006}
2007
2008
2009#ifdef CONFIG_IEEE80211W
2010
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002011static int hostapd_sa_query_action(struct hostapd_data *hapd,
2012 const struct ieee80211_mgmt *mgmt,
2013 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002014{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002015 const u8 *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002016
2017 end = mgmt->u.action.u.sa_query_resp.trans_id +
2018 WLAN_SA_QUERY_TR_ID_LEN;
2019 if (((u8 *) mgmt) + len < end) {
2020 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2021 "frame (len=%lu)", (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002022 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002023 }
2024
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002025 ieee802_11_sa_query_action(hapd, mgmt->sa,
2026 mgmt->u.action.u.sa_query_resp.action,
2027 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002028 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002029}
2030
2031
2032static int robust_action_frame(u8 category)
2033{
2034 return category != WLAN_ACTION_PUBLIC &&
2035 category != WLAN_ACTION_HT;
2036}
2037#endif /* CONFIG_IEEE80211W */
2038
2039
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002040static int handle_action(struct hostapd_data *hapd,
2041 const struct ieee80211_mgmt *mgmt, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002042{
2043 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002044 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002045
2046 if (len < IEEE80211_HDRLEN + 1) {
2047 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2048 HOSTAPD_LEVEL_DEBUG,
2049 "handle_action - too short payload (len=%lu)",
2050 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002051 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002052 }
2053
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002054 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2055 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2056 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2057 "frame (category=%u) from unassociated STA " MACSTR,
2058 MAC2STR(mgmt->sa), mgmt->u.action.category);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002059 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002060 }
2061
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002062#ifdef CONFIG_IEEE80211W
2063 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08002064 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2065 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002066 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2067 HOSTAPD_LEVEL_DEBUG,
2068 "Dropped unprotected Robust Action frame from "
2069 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002070 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002071 }
2072#endif /* CONFIG_IEEE80211W */
2073
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002074 if (sta) {
2075 u16 fc = le_to_host16(mgmt->frame_control);
2076 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2077
2078 if ((fc & WLAN_FC_RETRY) &&
2079 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2080 sta->last_seq_ctrl == seq_ctrl &&
2081 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2082 hostapd_logger(hapd, sta->addr,
2083 HOSTAPD_MODULE_IEEE80211,
2084 HOSTAPD_LEVEL_DEBUG,
2085 "Drop repeated action frame seq_ctrl=0x%x",
2086 seq_ctrl);
2087 return 1;
2088 }
2089
2090 sta->last_seq_ctrl = seq_ctrl;
2091 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2092 }
2093
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002094 switch (mgmt->u.action.category) {
2095#ifdef CONFIG_IEEE80211R
2096 case WLAN_ACTION_FT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002097 if (!sta ||
2098 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002099 len - IEEE80211_HDRLEN))
2100 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002101 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002102#endif /* CONFIG_IEEE80211R */
2103 case WLAN_ACTION_WMM:
2104 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002105 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002106#ifdef CONFIG_IEEE80211W
2107 case WLAN_ACTION_SA_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002108 return hostapd_sa_query_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002109#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002110#ifdef CONFIG_WNM
2111 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002112 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2113 return 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002114#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002115 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08002116 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002117#ifdef CONFIG_IEEE80211N
2118 if (mgmt->u.action.u.public_action.action ==
2119 WLAN_PA_20_40_BSS_COEX) {
2120 wpa_printf(MSG_DEBUG,
2121 "HT20/40 coex mgmt frame received from STA "
2122 MACSTR, MAC2STR(mgmt->sa));
2123 hostapd_2040_coex_action(hapd, mgmt, len);
2124 }
2125#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126 if (hapd->public_action_cb) {
2127 hapd->public_action_cb(hapd->public_action_cb_ctx,
2128 (u8 *) mgmt, len,
2129 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002130 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002131 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002132 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002133 (u8 *) mgmt, len,
2134 hapd->iface->freq);
2135 }
2136 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002137 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002138 break;
2139 case WLAN_ACTION_VENDOR_SPECIFIC:
2140 if (hapd->vendor_action_cb) {
2141 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2142 (u8 *) mgmt, len,
2143 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002144 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002145 }
2146 break;
2147 }
2148
2149 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2150 HOSTAPD_LEVEL_DEBUG,
2151 "handle_action - unknown action category %d or invalid "
2152 "frame",
2153 mgmt->u.action.category);
2154 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2155 !(mgmt->sa[0] & 0x01)) {
2156 struct ieee80211_mgmt *resp;
2157
2158 /*
2159 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2160 * Return the Action frame to the source without change
2161 * except that MSB of the Category set to 1.
2162 */
2163 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2164 "frame back to sender");
2165 resp = os_malloc(len);
2166 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002167 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002168 os_memcpy(resp, mgmt, len);
2169 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2170 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2171 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2172 resp->u.action.category |= 0x80;
2173
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002174 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2175 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2176 "Action frame");
2177 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002178 os_free(resp);
2179 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002180
2181 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002182}
2183
2184
2185/**
2186 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2187 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2188 * sent to)
2189 * @buf: management frame data (starting from IEEE 802.11 header)
2190 * @len: length of frame data in octets
2191 * @fi: meta data about received frame (signal level, etc.)
2192 *
2193 * Process all incoming IEEE 802.11 management frames. This will be called for
2194 * each frame received from the kernel driver through wlan#ap interface. In
2195 * addition, it can be called to re-inserted pending frames (e.g., when using
2196 * external RADIUS server as an MAC ACL).
2197 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002198int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2199 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002200{
2201 struct ieee80211_mgmt *mgmt;
2202 int broadcast;
2203 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002204 int ret = 0;
2205
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002206 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002207 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002208
2209 mgmt = (struct ieee80211_mgmt *) buf;
2210 fc = le_to_host16(mgmt->frame_control);
2211 stype = WLAN_FC_GET_STYPE(fc);
2212
2213 if (stype == WLAN_FC_STYPE_BEACON) {
2214 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002215 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002216 }
2217
2218 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2219 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2220 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2221
2222 if (!broadcast &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002223#ifdef CONFIG_P2P
2224 /* Invitation responses can be sent with the peer MAC as BSSID */
2225 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2226 stype == WLAN_FC_STYPE_ACTION) &&
2227#endif /* CONFIG_P2P */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002228#ifdef CONFIG_MESH
2229 !(hapd->conf->mesh & MESH_ENABLED) &&
2230#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002231 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002232 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2233 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002234 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002235 }
2236
2237
2238 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002239 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002240 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002241 }
2242
2243 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2244 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2245 HOSTAPD_LEVEL_DEBUG,
2246 "MGMT: DA=" MACSTR " not our address",
2247 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002248 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002249 }
2250
2251 switch (stype) {
2252 case WLAN_FC_STYPE_AUTH:
2253 wpa_printf(MSG_DEBUG, "mgmt::auth");
2254 handle_auth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002255 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002256 break;
2257 case WLAN_FC_STYPE_ASSOC_REQ:
2258 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2259 handle_assoc(hapd, mgmt, len, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002260 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002261 break;
2262 case WLAN_FC_STYPE_REASSOC_REQ:
2263 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2264 handle_assoc(hapd, mgmt, len, 1);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002265 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002266 break;
2267 case WLAN_FC_STYPE_DISASSOC:
2268 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2269 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002270 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002271 break;
2272 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002273 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002275 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002276 break;
2277 case WLAN_FC_STYPE_ACTION:
2278 wpa_printf(MSG_DEBUG, "mgmt::action");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002279 ret = handle_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002280 break;
2281 default:
2282 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2283 HOSTAPD_LEVEL_DEBUG,
2284 "unknown mgmt frame subtype %d", stype);
2285 break;
2286 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002287
2288 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002289}
2290
2291
2292static void handle_auth_cb(struct hostapd_data *hapd,
2293 const struct ieee80211_mgmt *mgmt,
2294 size_t len, int ok)
2295{
2296 u16 auth_alg, auth_transaction, status_code;
2297 struct sta_info *sta;
2298
2299 if (!ok) {
2300 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2301 HOSTAPD_LEVEL_NOTICE,
2302 "did not acknowledge authentication response");
2303 return;
2304 }
2305
2306 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002307 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2308 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002309 return;
2310 }
2311
2312 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2313 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2314 status_code = le_to_host16(mgmt->u.auth.status_code);
2315
2316 sta = ap_get_sta(hapd, mgmt->da);
2317 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002318 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2319 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002320 return;
2321 }
2322
2323 if (status_code == WLAN_STATUS_SUCCESS &&
2324 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2325 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2326 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2327 HOSTAPD_LEVEL_INFO, "authenticated");
2328 sta->flags |= WLAN_STA_AUTH;
2329 }
2330}
2331
2332
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002333static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2334 struct sta_info *sta,
2335 char *ifname_wds)
2336{
2337 int i;
2338 struct hostapd_ssid *ssid = sta->ssid;
2339
2340 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2341 return;
2342
2343 for (i = 0; i < 4; i++) {
2344 if (ssid->wep.key[i] &&
2345 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2346 i == ssid->wep.idx, NULL, 0,
2347 ssid->wep.key[i], ssid->wep.len[i])) {
2348 wpa_printf(MSG_WARNING,
2349 "Could not set WEP keys for WDS interface; %s",
2350 ifname_wds);
2351 break;
2352 }
2353 }
2354}
2355
2356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002357static void handle_assoc_cb(struct hostapd_data *hapd,
2358 const struct ieee80211_mgmt *mgmt,
2359 size_t len, int reassoc, int ok)
2360{
2361 u16 status;
2362 struct sta_info *sta;
2363 int new_assoc = 1;
2364 struct ieee80211_ht_capabilities ht_cap;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002365 struct ieee80211_vht_capabilities vht_cap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002366
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002367 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2368 sizeof(mgmt->u.assoc_resp))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002369 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2370 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002371 return;
2372 }
2373
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002374 sta = ap_get_sta(hapd, mgmt->da);
2375 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002376 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2377 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002378 return;
2379 }
2380
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002381 if (!ok) {
2382 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2383 HOSTAPD_LEVEL_DEBUG,
2384 "did not acknowledge association response");
2385 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2386 return;
2387 }
2388
2389 if (reassoc)
2390 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2391 else
2392 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2393
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002394 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002395 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002396
2397 /* Stop previous accounting session, if one is started, and allocate
2398 * new session id for the new session. */
2399 accounting_sta_stop(hapd, sta);
2400
2401 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2402 HOSTAPD_LEVEL_INFO,
2403 "associated (aid %d)",
2404 sta->aid);
2405
2406 if (sta->flags & WLAN_STA_ASSOC)
2407 new_assoc = 0;
2408 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002409 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002410 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002411 sta->auth_alg == WLAN_AUTH_FT) {
2412 /*
2413 * Open, static WEP, or FT protocol; no separate authorization
2414 * step.
2415 */
2416 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002417 }
2418
2419 if (reassoc)
2420 mlme_reassociate_indication(hapd, sta);
2421 else
2422 mlme_associate_indication(hapd, sta);
2423
2424#ifdef CONFIG_IEEE80211W
2425 sta->sa_query_timed_out = 0;
2426#endif /* CONFIG_IEEE80211W */
2427
2428 /*
2429 * Remove the STA entry in order to make sure the STA PS state gets
2430 * cleared and configuration gets updated in case of reassociation back
2431 * to the same AP.
2432 */
2433 hostapd_drv_sta_remove(hapd, sta->addr);
2434
2435#ifdef CONFIG_IEEE80211N
2436 if (sta->flags & WLAN_STA_HT)
2437 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
2438#endif /* CONFIG_IEEE80211N */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002439#ifdef CONFIG_IEEE80211AC
2440 if (sta->flags & WLAN_STA_VHT)
2441 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
2442#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002443
2444 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
2445 sta->supported_rates, sta->supported_rates_len,
2446 sta->listen_interval,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002447 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002448 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08002449 sta->flags, sta->qosinfo, sta->vht_opmode)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002450 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2451 HOSTAPD_LEVEL_NOTICE,
2452 "Could not add STA to kernel driver");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002453
2454 ap_sta_disconnect(hapd, sta, sta->addr,
2455 WLAN_REASON_DISASSOC_AP_BUSY);
2456
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002457 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002458 }
2459
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002460 if (sta->flags & WLAN_STA_WDS) {
2461 int ret;
2462 char ifname_wds[IFNAMSIZ + 1];
2463
2464 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2465 sta->aid, 1);
2466 if (!ret)
2467 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2468 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002469
2470 if (sta->eapol_sm == NULL) {
2471 /*
2472 * This STA does not use RADIUS server for EAP authentication,
2473 * so bind it to the selected VLAN interface now, since the
2474 * interface selection is not going to change anymore.
2475 */
2476 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002477 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002478 } else if (sta->vlan_id) {
2479 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2480 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002481 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002482 }
2483
2484 hostapd_set_sta_flags(hapd, sta);
2485
2486 if (sta->auth_alg == WLAN_AUTH_FT)
2487 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2488 else
2489 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2490 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2491
2492 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002493}
2494
2495
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002496static void handle_deauth_cb(struct hostapd_data *hapd,
2497 const struct ieee80211_mgmt *mgmt,
2498 size_t len, int ok)
2499{
2500 struct sta_info *sta;
2501 if (mgmt->da[0] & 0x01)
2502 return;
2503 sta = ap_get_sta(hapd, mgmt->da);
2504 if (!sta) {
2505 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2506 " not found", MAC2STR(mgmt->da));
2507 return;
2508 }
2509 if (ok)
2510 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2511 MAC2STR(sta->addr));
2512 else
2513 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2514 "deauth", MAC2STR(sta->addr));
2515
2516 ap_sta_deauth_cb(hapd, sta);
2517}
2518
2519
2520static void handle_disassoc_cb(struct hostapd_data *hapd,
2521 const struct ieee80211_mgmt *mgmt,
2522 size_t len, int ok)
2523{
2524 struct sta_info *sta;
2525 if (mgmt->da[0] & 0x01)
2526 return;
2527 sta = ap_get_sta(hapd, mgmt->da);
2528 if (!sta) {
2529 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2530 " not found", MAC2STR(mgmt->da));
2531 return;
2532 }
2533 if (ok)
2534 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2535 MAC2STR(sta->addr));
2536 else
2537 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2538 "disassoc", MAC2STR(sta->addr));
2539
2540 ap_sta_disassoc_cb(hapd, sta);
2541}
2542
2543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002544/**
2545 * ieee802_11_mgmt_cb - Process management frame TX status callback
2546 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2547 * was sent from)
2548 * @buf: management frame data (starting from IEEE 802.11 header)
2549 * @len: length of frame data in octets
2550 * @stype: management frame subtype from frame control field
2551 * @ok: Whether the frame was ACK'ed
2552 */
2553void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2554 u16 stype, int ok)
2555{
2556 const struct ieee80211_mgmt *mgmt;
2557 mgmt = (const struct ieee80211_mgmt *) buf;
2558
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002559#ifdef CONFIG_TESTING_OPTIONS
2560 if (hapd->ext_mgmt_frame_handling) {
2561 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2562 stype, ok);
2563 return;
2564 }
2565#endif /* CONFIG_TESTING_OPTIONS */
2566
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002567 switch (stype) {
2568 case WLAN_FC_STYPE_AUTH:
2569 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2570 handle_auth_cb(hapd, mgmt, len, ok);
2571 break;
2572 case WLAN_FC_STYPE_ASSOC_RESP:
2573 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2574 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2575 break;
2576 case WLAN_FC_STYPE_REASSOC_RESP:
2577 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2578 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2579 break;
2580 case WLAN_FC_STYPE_PROBE_RESP:
2581 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2582 break;
2583 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002584 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2585 handle_deauth_cb(hapd, mgmt, len, ok);
2586 break;
2587 case WLAN_FC_STYPE_DISASSOC:
2588 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2589 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002590 break;
2591 case WLAN_FC_STYPE_ACTION:
2592 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2593 break;
2594 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002595 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002596 break;
2597 }
2598}
2599
2600
2601int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2602{
2603 /* TODO */
2604 return 0;
2605}
2606
2607
2608int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2609 char *buf, size_t buflen)
2610{
2611 /* TODO */
2612 return 0;
2613}
2614
2615
2616void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2617 const u8 *buf, size_t len, int ack)
2618{
2619 struct sta_info *sta;
2620 struct hostapd_iface *iface = hapd->iface;
2621
2622 sta = ap_get_sta(hapd, addr);
2623 if (sta == NULL && iface->num_bss > 1) {
2624 size_t j;
2625 for (j = 0; j < iface->num_bss; j++) {
2626 hapd = iface->bss[j];
2627 sta = ap_get_sta(hapd, addr);
2628 if (sta)
2629 break;
2630 }
2631 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002632 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002633 return;
2634 if (sta->flags & WLAN_STA_PENDING_POLL) {
2635 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2636 "activity poll", MAC2STR(sta->addr),
2637 ack ? "ACKed" : "did not ACK");
2638 if (ack)
2639 sta->flags &= ~WLAN_STA_PENDING_POLL;
2640 }
2641
2642 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2643}
2644
2645
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002646void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2647 const u8 *data, size_t len, int ack)
2648{
2649 struct sta_info *sta;
2650 struct hostapd_iface *iface = hapd->iface;
2651
2652 sta = ap_get_sta(hapd, dst);
2653 if (sta == NULL && iface->num_bss > 1) {
2654 size_t j;
2655 for (j = 0; j < iface->num_bss; j++) {
2656 hapd = iface->bss[j];
2657 sta = ap_get_sta(hapd, dst);
2658 if (sta)
2659 break;
2660 }
2661 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002662 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2663 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2664 MACSTR " that is not currently associated",
2665 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002666 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002667 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002668
2669 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2670}
2671
2672
2673void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2674{
2675 struct sta_info *sta;
2676 struct hostapd_iface *iface = hapd->iface;
2677
2678 sta = ap_get_sta(hapd, addr);
2679 if (sta == NULL && iface->num_bss > 1) {
2680 size_t j;
2681 for (j = 0; j < iface->num_bss; j++) {
2682 hapd = iface->bss[j];
2683 sta = ap_get_sta(hapd, addr);
2684 if (sta)
2685 break;
2686 }
2687 }
2688 if (sta == NULL)
2689 return;
2690 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2691 return;
2692
2693 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2694 "activity poll", MAC2STR(sta->addr));
2695 sta->flags &= ~WLAN_STA_PENDING_POLL;
2696}
2697
2698
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2700 int wds)
2701{
2702 struct sta_info *sta;
2703
2704 sta = ap_get_sta(hapd, src);
2705 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002706 if (!hapd->conf->wds_sta)
2707 return;
2708
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002709 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002710 int ret;
2711 char ifname_wds[IFNAMSIZ + 1];
2712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002713 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2714 "STA " MACSTR " (aid %u)",
2715 MAC2STR(sta->addr), sta->aid);
2716 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002717 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2718 sta->addr, sta->aid, 1);
2719 if (!ret)
2720 hostapd_set_wds_encryption(hapd, sta,
2721 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002722 }
2723 return;
2724 }
2725
2726 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2727 MACSTR, MAC2STR(src));
2728 if (src[0] & 0x01) {
2729 /* Broadcast bit set in SA?! Ignore the frame silently. */
2730 return;
2731 }
2732
2733 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2734 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2735 "already been sent, but no TX status yet known - "
2736 "ignore Class 3 frame issue with " MACSTR,
2737 MAC2STR(src));
2738 return;
2739 }
2740
2741 if (sta && (sta->flags & WLAN_STA_AUTH))
2742 hostapd_drv_sta_disassoc(
2743 hapd, src,
2744 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2745 else
2746 hostapd_drv_sta_deauth(
2747 hapd, src,
2748 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2749}
2750
2751
2752#endif /* CONFIG_NATIVE_WINDOWS */