blob: 3d4488a1c7a5daea95ab538e1f5336aaafe8da48 [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 }
1330#endif /* CONFIG_IEEE80211AC */
1331
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001332#ifdef CONFIG_P2P
1333 if (elems.p2p) {
1334 wpabuf_free(sta->p2p_ie);
1335 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1336 P2P_IE_VENDOR_TYPE);
1337 if (sta->p2p_ie)
1338 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1339 } else {
1340 wpabuf_free(sta->p2p_ie);
1341 sta->p2p_ie = NULL;
1342 }
1343#endif /* CONFIG_P2P */
1344
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1346 wpa_ie = elems.rsn_ie;
1347 wpa_ie_len = elems.rsn_ie_len;
1348 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1349 elems.wpa_ie) {
1350 wpa_ie = elems.wpa_ie;
1351 wpa_ie_len = elems.wpa_ie_len;
1352 } else {
1353 wpa_ie = NULL;
1354 wpa_ie_len = 0;
1355 }
1356
1357#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001358 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001359 if (hapd->conf->wps_state && elems.wps_ie) {
1360 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1361 "Request - assume WPS is used");
1362 sta->flags |= WLAN_STA_WPS;
1363 wpabuf_free(sta->wps_ie);
1364 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1365 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001366 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1367 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1368 sta->flags |= WLAN_STA_WPS2;
1369 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001370 wpa_ie = NULL;
1371 wpa_ie_len = 0;
1372 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1373 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1374 "(Re)Association Request - reject");
1375 return WLAN_STATUS_INVALID_IE;
1376 }
1377 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1378 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1379 "(Re)Association Request - possible WPS use");
1380 sta->flags |= WLAN_STA_MAYBE_WPS;
1381 } else
1382#endif /* CONFIG_WPS */
1383 if (hapd->conf->wpa && wpa_ie == NULL) {
1384 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1385 HOSTAPD_LEVEL_INFO,
1386 "No WPA/RSN IE in association request");
1387 return WLAN_STATUS_INVALID_IE;
1388 }
1389
1390 if (hapd->conf->wpa && wpa_ie) {
1391 int res;
1392 wpa_ie -= 2;
1393 wpa_ie_len += 2;
1394 if (sta->wpa_sm == NULL)
1395 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001396 sta->addr,
1397 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001398 if (sta->wpa_sm == NULL) {
1399 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1400 "state machine");
1401 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1402 }
1403 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1404 wpa_ie, wpa_ie_len,
1405 elems.mdie, elems.mdie_len);
1406 if (res == WPA_INVALID_GROUP)
1407 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1408 else if (res == WPA_INVALID_PAIRWISE)
1409 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1410 else if (res == WPA_INVALID_AKMP)
1411 resp = WLAN_STATUS_AKMP_NOT_VALID;
1412 else if (res == WPA_ALLOC_FAIL)
1413 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1414#ifdef CONFIG_IEEE80211W
1415 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1416 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1417 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1418 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1419#endif /* CONFIG_IEEE80211W */
1420 else if (res == WPA_INVALID_MDIE)
1421 resp = WLAN_STATUS_INVALID_MDIE;
1422 else if (res != WPA_IE_OK)
1423 resp = WLAN_STATUS_INVALID_IE;
1424 if (resp != WLAN_STATUS_SUCCESS)
1425 return resp;
1426#ifdef CONFIG_IEEE80211W
1427 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1428 sta->sa_query_count > 0)
1429 ap_check_sa_query_timeout(hapd, sta);
1430 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1431 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1432 /*
1433 * STA has already been associated with MFP and SA
1434 * Query timeout has not been reached. Reject the
1435 * association attempt temporarily and start SA Query,
1436 * if one is not pending.
1437 */
1438
1439 if (sta->sa_query_count == 0)
1440 ap_sta_start_sa_query(hapd, sta);
1441
1442 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1443 }
1444
1445 if (wpa_auth_uses_mfp(sta->wpa_sm))
1446 sta->flags |= WLAN_STA_MFP;
1447 else
1448 sta->flags &= ~WLAN_STA_MFP;
1449#endif /* CONFIG_IEEE80211W */
1450
1451#ifdef CONFIG_IEEE80211R
1452 if (sta->auth_alg == WLAN_AUTH_FT) {
1453 if (!reassoc) {
1454 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1455 "to use association (not "
1456 "re-association) with FT auth_alg",
1457 MAC2STR(sta->addr));
1458 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1459 }
1460
1461 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1462 ies_len);
1463 if (resp != WLAN_STATUS_SUCCESS)
1464 return resp;
1465 }
1466#endif /* CONFIG_IEEE80211R */
1467
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001468#ifdef CONFIG_SAE
1469 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001470 sta->auth_alg == WLAN_AUTH_OPEN) {
1471 struct rsn_pmksa_cache_entry *sa;
1472 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1473 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1474 wpa_printf(MSG_DEBUG,
1475 "SAE: No PMKSA cache entry found for "
1476 MACSTR, MAC2STR(sta->addr));
1477 return WLAN_STATUS_INVALID_PMKID;
1478 }
1479 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1480 " using PMKSA caching", MAC2STR(sta->addr));
1481 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1482 sta->auth_alg != WLAN_AUTH_SAE &&
1483 !(sta->auth_alg == WLAN_AUTH_FT &&
1484 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001485 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1486 "SAE AKM after non-SAE auth_alg %u",
1487 MAC2STR(sta->addr), sta->auth_alg);
1488 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1489 }
1490#endif /* CONFIG_SAE */
1491
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001492#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001493 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001494 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1495 hostapd_logger(hapd, sta->addr,
1496 HOSTAPD_MODULE_IEEE80211,
1497 HOSTAPD_LEVEL_INFO,
1498 "Station tried to use TKIP with HT "
1499 "association");
1500 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1501 }
1502#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001503#ifdef CONFIG_HS20
1504 } else if (hapd->conf->osen) {
1505 if (elems.osen == NULL) {
1506 hostapd_logger(
1507 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1508 HOSTAPD_LEVEL_INFO,
1509 "No HS 2.0 OSEN element in association request");
1510 return WLAN_STATUS_INVALID_IE;
1511 }
1512
1513 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1514 if (sta->wpa_sm == NULL)
1515 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1516 sta->addr, NULL);
1517 if (sta->wpa_sm == NULL) {
1518 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1519 "state machine");
1520 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1521 }
1522 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1523 elems.osen - 2, elems.osen_len + 2) < 0)
1524 return WLAN_STATUS_INVALID_IE;
1525#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001526 } else
1527 wpa_auth_sta_no_wpa(sta->wpa_sm);
1528
1529#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001530 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1531#endif /* CONFIG_P2P */
1532
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001533#ifdef CONFIG_HS20
1534 wpabuf_free(sta->hs20_ie);
1535 if (elems.hs20 && elems.hs20_len > 4) {
1536 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1537 elems.hs20_len - 4);
1538 } else
1539 sta->hs20_ie = NULL;
1540#endif /* CONFIG_HS20 */
1541
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001542 return WLAN_STATUS_SUCCESS;
1543}
1544
1545
1546static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1547 u16 reason_code)
1548{
1549 int send_len;
1550 struct ieee80211_mgmt reply;
1551
1552 os_memset(&reply, 0, sizeof(reply));
1553 reply.frame_control =
1554 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1555 os_memcpy(reply.da, addr, ETH_ALEN);
1556 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1557 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1558
1559 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1560 reply.u.deauth.reason_code = host_to_le16(reason_code);
1561
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001562 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001563 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1564 strerror(errno));
1565}
1566
1567
1568static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1569 u16 status_code, int reassoc, const u8 *ies,
1570 size_t ies_len)
1571{
1572 int send_len;
1573 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1574 struct ieee80211_mgmt *reply;
1575 u8 *p;
1576
1577 os_memset(buf, 0, sizeof(buf));
1578 reply = (struct ieee80211_mgmt *) buf;
1579 reply->frame_control =
1580 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1581 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1582 WLAN_FC_STYPE_ASSOC_RESP));
1583 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1584 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1585 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1586
1587 send_len = IEEE80211_HDRLEN;
1588 send_len += sizeof(reply->u.assoc_resp);
1589 reply->u.assoc_resp.capab_info =
1590 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1591 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001592 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001593 /* Supported rates */
1594 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1595 /* Extended supported rates */
1596 p = hostapd_eid_ext_supp_rates(hapd, p);
1597
1598#ifdef CONFIG_IEEE80211R
1599 if (status_code == WLAN_STATUS_SUCCESS) {
1600 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1601 * Transition Information, RSN, [RIC Response] */
1602 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1603 buf + sizeof(buf) - p,
1604 sta->auth_alg, ies, ies_len);
1605 }
1606#endif /* CONFIG_IEEE80211R */
1607
1608#ifdef CONFIG_IEEE80211W
1609 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1610 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1611#endif /* CONFIG_IEEE80211W */
1612
1613#ifdef CONFIG_IEEE80211N
1614 p = hostapd_eid_ht_capabilities(hapd, p);
1615 p = hostapd_eid_ht_operation(hapd, p);
1616#endif /* CONFIG_IEEE80211N */
1617
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001618#ifdef CONFIG_IEEE80211AC
1619 p = hostapd_eid_vht_capabilities(hapd, p);
1620 p = hostapd_eid_vht_operation(hapd, p);
1621#endif /* CONFIG_IEEE80211AC */
1622
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001624 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001625 if (sta->qos_map_enabled)
1626 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001627
1628 if (sta->flags & WLAN_STA_WMM)
1629 p = hostapd_eid_wmm(hapd, p);
1630
1631#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001632 if ((sta->flags & WLAN_STA_WPS) ||
1633 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001634 struct wpabuf *wps = wps_build_assoc_resp_ie();
1635 if (wps) {
1636 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1637 p += wpabuf_len(wps);
1638 wpabuf_free(wps);
1639 }
1640 }
1641#endif /* CONFIG_WPS */
1642
1643#ifdef CONFIG_P2P
1644 if (sta->p2p_ie) {
1645 struct wpabuf *p2p_resp_ie;
1646 enum p2p_status_code status;
1647 switch (status_code) {
1648 case WLAN_STATUS_SUCCESS:
1649 status = P2P_SC_SUCCESS;
1650 break;
1651 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1652 status = P2P_SC_FAIL_LIMIT_REACHED;
1653 break;
1654 default:
1655 status = P2P_SC_FAIL_INVALID_PARAMS;
1656 break;
1657 }
1658 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1659 if (p2p_resp_ie) {
1660 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1661 wpabuf_len(p2p_resp_ie));
1662 p += wpabuf_len(p2p_resp_ie);
1663 wpabuf_free(p2p_resp_ie);
1664 }
1665 }
1666#endif /* CONFIG_P2P */
1667
1668#ifdef CONFIG_P2P_MANAGER
1669 if (hapd->conf->p2p & P2P_MANAGE)
1670 p = hostapd_eid_p2p_manage(hapd, p);
1671#endif /* CONFIG_P2P_MANAGER */
1672
1673 send_len += p - reply->u.assoc_resp.variable;
1674
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001675 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001676 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1677 strerror(errno));
1678}
1679
1680
1681static void handle_assoc(struct hostapd_data *hapd,
1682 const struct ieee80211_mgmt *mgmt, size_t len,
1683 int reassoc)
1684{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001685 u16 capab_info, listen_interval, seq_ctrl, fc;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001686 u16 resp = WLAN_STATUS_SUCCESS;
1687 const u8 *pos;
1688 int left, i;
1689 struct sta_info *sta;
1690
1691 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1692 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001693 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1694 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001695 return;
1696 }
1697
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001698#ifdef CONFIG_TESTING_OPTIONS
1699 if (reassoc) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001700 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001701 drand48() < hapd->iconf->ignore_reassoc_probability) {
1702 wpa_printf(MSG_INFO,
1703 "TESTING: ignoring reassoc request from "
1704 MACSTR, MAC2STR(mgmt->sa));
1705 return;
1706 }
1707 } else {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001708 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001709 drand48() < hapd->iconf->ignore_assoc_probability) {
1710 wpa_printf(MSG_INFO,
1711 "TESTING: ignoring assoc request from "
1712 MACSTR, MAC2STR(mgmt->sa));
1713 return;
1714 }
1715 }
1716#endif /* CONFIG_TESTING_OPTIONS */
1717
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001718 fc = le_to_host16(mgmt->frame_control);
1719 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1720
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001721 if (reassoc) {
1722 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1723 listen_interval = le_to_host16(
1724 mgmt->u.reassoc_req.listen_interval);
1725 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1726 " capab_info=0x%02x listen_interval=%d current_ap="
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001727 MACSTR " seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001728 MAC2STR(mgmt->sa), capab_info, listen_interval,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001729 MAC2STR(mgmt->u.reassoc_req.current_ap),
1730 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001731 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1732 pos = mgmt->u.reassoc_req.variable;
1733 } else {
1734 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1735 listen_interval = le_to_host16(
1736 mgmt->u.assoc_req.listen_interval);
1737 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001738 " capab_info=0x%02x listen_interval=%d "
1739 "seq_ctrl=0x%x%s",
1740 MAC2STR(mgmt->sa), capab_info, listen_interval,
1741 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001742 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1743 pos = mgmt->u.assoc_req.variable;
1744 }
1745
1746 sta = ap_get_sta(hapd, mgmt->sa);
1747#ifdef CONFIG_IEEE80211R
1748 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1749 (sta->flags & WLAN_STA_AUTH) == 0) {
1750 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1751 "prior to authentication since it is using "
1752 "over-the-DS FT", MAC2STR(mgmt->sa));
1753 } else
1754#endif /* CONFIG_IEEE80211R */
1755 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1756 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1757 HOSTAPD_LEVEL_INFO, "Station tried to "
1758 "associate before authentication "
1759 "(aid=%d flags=0x%x)",
1760 sta ? sta->aid : -1,
1761 sta ? sta->flags : 0);
1762 send_deauth(hapd, mgmt->sa,
1763 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1764 return;
1765 }
1766
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001767 if ((fc & WLAN_FC_RETRY) &&
1768 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1769 sta->last_seq_ctrl == seq_ctrl &&
1770 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1771 WLAN_FC_STYPE_ASSOC_REQ) {
1772 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1773 HOSTAPD_LEVEL_DEBUG,
1774 "Drop repeated association frame seq_ctrl=0x%x",
1775 seq_ctrl);
1776 return;
1777 }
1778 sta->last_seq_ctrl = seq_ctrl;
1779 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1780 WLAN_FC_STYPE_ASSOC_REQ;
1781
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001782 if (hapd->tkip_countermeasures) {
1783 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1784 goto fail;
1785 }
1786
1787 if (listen_interval > hapd->conf->max_listen_interval) {
1788 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1789 HOSTAPD_LEVEL_DEBUG,
1790 "Too large Listen Interval (%d)",
1791 listen_interval);
1792 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1793 goto fail;
1794 }
1795
1796 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1797 * is used */
1798 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1799 if (resp != WLAN_STATUS_SUCCESS)
1800 goto fail;
1801
1802 if (hostapd_get_aid(hapd, sta) < 0) {
1803 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1804 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1805 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1806 goto fail;
1807 }
1808
1809 sta->capability = capab_info;
1810 sta->listen_interval = listen_interval;
1811
1812 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1813 sta->flags |= WLAN_STA_NONERP;
1814 for (i = 0; i < sta->supported_rates_len; i++) {
1815 if ((sta->supported_rates[i] & 0x7f) > 22) {
1816 sta->flags &= ~WLAN_STA_NONERP;
1817 break;
1818 }
1819 }
1820 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1821 sta->nonerp_set = 1;
1822 hapd->iface->num_sta_non_erp++;
1823 if (hapd->iface->num_sta_non_erp == 1)
1824 ieee802_11_set_beacons(hapd->iface);
1825 }
1826
1827 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1828 !sta->no_short_slot_time_set) {
1829 sta->no_short_slot_time_set = 1;
1830 hapd->iface->num_sta_no_short_slot_time++;
1831 if (hapd->iface->current_mode->mode ==
1832 HOSTAPD_MODE_IEEE80211G &&
1833 hapd->iface->num_sta_no_short_slot_time == 1)
1834 ieee802_11_set_beacons(hapd->iface);
1835 }
1836
1837 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1838 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1839 else
1840 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1841
1842 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1843 !sta->no_short_preamble_set) {
1844 sta->no_short_preamble_set = 1;
1845 hapd->iface->num_sta_no_short_preamble++;
1846 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1847 && hapd->iface->num_sta_no_short_preamble == 1)
1848 ieee802_11_set_beacons(hapd->iface);
1849 }
1850
1851#ifdef CONFIG_IEEE80211N
1852 update_ht_state(hapd, sta);
1853#endif /* CONFIG_IEEE80211N */
1854
1855 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1856 HOSTAPD_LEVEL_DEBUG,
1857 "association OK (aid %d)", sta->aid);
1858 /* Station will be marked associated, after it acknowledges AssocResp
1859 */
1860 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1861
1862#ifdef CONFIG_IEEE80211W
1863 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1864 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1865 "SA Query procedure", reassoc ? "re" : "");
1866 /* TODO: Send a protected Disassociate frame to the STA using
1867 * the old key and Reason Code "Previous Authentication no
1868 * longer valid". Make sure this is only sent protected since
1869 * unprotected frame would be received by the STA that is now
1870 * trying to associate.
1871 */
1872 }
1873#endif /* CONFIG_IEEE80211W */
1874
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001875 /* Make sure that the previously registered inactivity timer will not
1876 * remove the STA immediately. */
1877 sta->timeout_next = STA_NULLFUNC;
1878
1879 fail:
1880 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1881}
1882
1883
1884static void handle_disassoc(struct hostapd_data *hapd,
1885 const struct ieee80211_mgmt *mgmt, size_t len)
1886{
1887 struct sta_info *sta;
1888
1889 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001890 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1891 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001892 return;
1893 }
1894
1895 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1896 MAC2STR(mgmt->sa),
1897 le_to_host16(mgmt->u.disassoc.reason_code));
1898
1899 sta = ap_get_sta(hapd, mgmt->sa);
1900 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001901 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1902 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001903 return;
1904 }
1905
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001906 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001907 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001908 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001909 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1910 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1911 HOSTAPD_LEVEL_INFO, "disassociated");
1912 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1913 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1914 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1915 * authenticated. */
1916 accounting_sta_stop(hapd, sta);
1917 ieee802_1x_free_station(sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001918 if (sta->ipaddr)
1919 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
1920 ap_sta_ip6addr_del(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001921 hostapd_drv_sta_remove(hapd, sta->addr);
1922
1923 if (sta->timeout_next == STA_NULLFUNC ||
1924 sta->timeout_next == STA_DISASSOC) {
1925 sta->timeout_next = STA_DEAUTH;
1926 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1927 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1928 hapd, sta);
1929 }
1930
1931 mlme_disassociate_indication(
1932 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1933}
1934
1935
1936static void handle_deauth(struct hostapd_data *hapd,
1937 const struct ieee80211_mgmt *mgmt, size_t len)
1938{
1939 struct sta_info *sta;
1940
1941 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001942 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1943 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001944 return;
1945 }
1946
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001947 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001948 " reason_code=%d",
1949 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1950
1951 sta = ap_get_sta(hapd, mgmt->sa);
1952 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001953 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1954 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001955 MAC2STR(mgmt->sa));
1956 return;
1957 }
1958
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001959 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001960 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001961 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1962 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001963 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1964 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1965 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1966 mlme_deauthenticate_indication(
1967 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1968 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1969 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1970 ap_free_sta(hapd, sta);
1971}
1972
1973
1974static void handle_beacon(struct hostapd_data *hapd,
1975 const struct ieee80211_mgmt *mgmt, size_t len,
1976 struct hostapd_frame_info *fi)
1977{
1978 struct ieee802_11_elems elems;
1979
1980 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001981 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
1982 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001983 return;
1984 }
1985
1986 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1987 len - (IEEE80211_HDRLEN +
1988 sizeof(mgmt->u.beacon)), &elems,
1989 0);
1990
1991 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1992}
1993
1994
1995#ifdef CONFIG_IEEE80211W
1996
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001997static int hostapd_sa_query_action(struct hostapd_data *hapd,
1998 const struct ieee80211_mgmt *mgmt,
1999 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002000{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002001 const u8 *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002002
2003 end = mgmt->u.action.u.sa_query_resp.trans_id +
2004 WLAN_SA_QUERY_TR_ID_LEN;
2005 if (((u8 *) mgmt) + len < end) {
2006 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2007 "frame (len=%lu)", (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002008 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002009 }
2010
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002011 ieee802_11_sa_query_action(hapd, mgmt->sa,
2012 mgmt->u.action.u.sa_query_resp.action,
2013 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002014 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002015}
2016
2017
2018static int robust_action_frame(u8 category)
2019{
2020 return category != WLAN_ACTION_PUBLIC &&
2021 category != WLAN_ACTION_HT;
2022}
2023#endif /* CONFIG_IEEE80211W */
2024
2025
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002026static int handle_action(struct hostapd_data *hapd,
2027 const struct ieee80211_mgmt *mgmt, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002028{
2029 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002030 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002031
2032 if (len < IEEE80211_HDRLEN + 1) {
2033 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2034 HOSTAPD_LEVEL_DEBUG,
2035 "handle_action - too short payload (len=%lu)",
2036 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002037 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002038 }
2039
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002040 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2041 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2042 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2043 "frame (category=%u) from unassociated STA " MACSTR,
2044 MAC2STR(mgmt->sa), mgmt->u.action.category);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002045 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002046 }
2047
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002048#ifdef CONFIG_IEEE80211W
2049 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08002050 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2051 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002052 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2053 HOSTAPD_LEVEL_DEBUG,
2054 "Dropped unprotected Robust Action frame from "
2055 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002056 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002057 }
2058#endif /* CONFIG_IEEE80211W */
2059
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002060 if (sta) {
2061 u16 fc = le_to_host16(mgmt->frame_control);
2062 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2063
2064 if ((fc & WLAN_FC_RETRY) &&
2065 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2066 sta->last_seq_ctrl == seq_ctrl &&
2067 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2068 hostapd_logger(hapd, sta->addr,
2069 HOSTAPD_MODULE_IEEE80211,
2070 HOSTAPD_LEVEL_DEBUG,
2071 "Drop repeated action frame seq_ctrl=0x%x",
2072 seq_ctrl);
2073 return 1;
2074 }
2075
2076 sta->last_seq_ctrl = seq_ctrl;
2077 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2078 }
2079
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002080 switch (mgmt->u.action.category) {
2081#ifdef CONFIG_IEEE80211R
2082 case WLAN_ACTION_FT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002083 if (!sta ||
2084 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002085 len - IEEE80211_HDRLEN))
2086 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002087 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088#endif /* CONFIG_IEEE80211R */
2089 case WLAN_ACTION_WMM:
2090 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002091 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002092#ifdef CONFIG_IEEE80211W
2093 case WLAN_ACTION_SA_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002094 return hostapd_sa_query_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002095#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002096#ifdef CONFIG_WNM
2097 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002098 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2099 return 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002100#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002101 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08002102 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002103#ifdef CONFIG_IEEE80211N
2104 if (mgmt->u.action.u.public_action.action ==
2105 WLAN_PA_20_40_BSS_COEX) {
2106 wpa_printf(MSG_DEBUG,
2107 "HT20/40 coex mgmt frame received from STA "
2108 MACSTR, MAC2STR(mgmt->sa));
2109 hostapd_2040_coex_action(hapd, mgmt, len);
2110 }
2111#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002112 if (hapd->public_action_cb) {
2113 hapd->public_action_cb(hapd->public_action_cb_ctx,
2114 (u8 *) mgmt, len,
2115 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002116 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002117 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002118 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002119 (u8 *) mgmt, len,
2120 hapd->iface->freq);
2121 }
2122 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002123 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002124 break;
2125 case WLAN_ACTION_VENDOR_SPECIFIC:
2126 if (hapd->vendor_action_cb) {
2127 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2128 (u8 *) mgmt, len,
2129 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002130 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002131 }
2132 break;
2133 }
2134
2135 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2136 HOSTAPD_LEVEL_DEBUG,
2137 "handle_action - unknown action category %d or invalid "
2138 "frame",
2139 mgmt->u.action.category);
2140 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2141 !(mgmt->sa[0] & 0x01)) {
2142 struct ieee80211_mgmt *resp;
2143
2144 /*
2145 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2146 * Return the Action frame to the source without change
2147 * except that MSB of the Category set to 1.
2148 */
2149 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2150 "frame back to sender");
2151 resp = os_malloc(len);
2152 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002153 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002154 os_memcpy(resp, mgmt, len);
2155 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2156 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2157 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2158 resp->u.action.category |= 0x80;
2159
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002160 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2161 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2162 "Action frame");
2163 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164 os_free(resp);
2165 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002166
2167 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002168}
2169
2170
2171/**
2172 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2173 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2174 * sent to)
2175 * @buf: management frame data (starting from IEEE 802.11 header)
2176 * @len: length of frame data in octets
2177 * @fi: meta data about received frame (signal level, etc.)
2178 *
2179 * Process all incoming IEEE 802.11 management frames. This will be called for
2180 * each frame received from the kernel driver through wlan#ap interface. In
2181 * addition, it can be called to re-inserted pending frames (e.g., when using
2182 * external RADIUS server as an MAC ACL).
2183 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002184int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2185 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186{
2187 struct ieee80211_mgmt *mgmt;
2188 int broadcast;
2189 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002190 int ret = 0;
2191
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002192 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002193 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002194
2195 mgmt = (struct ieee80211_mgmt *) buf;
2196 fc = le_to_host16(mgmt->frame_control);
2197 stype = WLAN_FC_GET_STYPE(fc);
2198
2199 if (stype == WLAN_FC_STYPE_BEACON) {
2200 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002201 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002202 }
2203
2204 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2205 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2206 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2207
2208 if (!broadcast &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002209#ifdef CONFIG_P2P
2210 /* Invitation responses can be sent with the peer MAC as BSSID */
2211 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2212 stype == WLAN_FC_STYPE_ACTION) &&
2213#endif /* CONFIG_P2P */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002214#ifdef CONFIG_MESH
2215 !(hapd->conf->mesh & MESH_ENABLED) &&
2216#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002218 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2219 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002220 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002221 }
2222
2223
2224 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002225 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002226 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002227 }
2228
2229 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2230 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2231 HOSTAPD_LEVEL_DEBUG,
2232 "MGMT: DA=" MACSTR " not our address",
2233 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002234 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002235 }
2236
2237 switch (stype) {
2238 case WLAN_FC_STYPE_AUTH:
2239 wpa_printf(MSG_DEBUG, "mgmt::auth");
2240 handle_auth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002241 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242 break;
2243 case WLAN_FC_STYPE_ASSOC_REQ:
2244 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2245 handle_assoc(hapd, mgmt, len, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002246 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002247 break;
2248 case WLAN_FC_STYPE_REASSOC_REQ:
2249 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2250 handle_assoc(hapd, mgmt, len, 1);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002251 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002252 break;
2253 case WLAN_FC_STYPE_DISASSOC:
2254 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2255 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002256 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002257 break;
2258 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002259 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002260 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002261 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002262 break;
2263 case WLAN_FC_STYPE_ACTION:
2264 wpa_printf(MSG_DEBUG, "mgmt::action");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002265 ret = handle_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002266 break;
2267 default:
2268 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2269 HOSTAPD_LEVEL_DEBUG,
2270 "unknown mgmt frame subtype %d", stype);
2271 break;
2272 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002273
2274 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002275}
2276
2277
2278static void handle_auth_cb(struct hostapd_data *hapd,
2279 const struct ieee80211_mgmt *mgmt,
2280 size_t len, int ok)
2281{
2282 u16 auth_alg, auth_transaction, status_code;
2283 struct sta_info *sta;
2284
2285 if (!ok) {
2286 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2287 HOSTAPD_LEVEL_NOTICE,
2288 "did not acknowledge authentication response");
2289 return;
2290 }
2291
2292 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002293 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2294 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002295 return;
2296 }
2297
2298 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2299 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2300 status_code = le_to_host16(mgmt->u.auth.status_code);
2301
2302 sta = ap_get_sta(hapd, mgmt->da);
2303 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002304 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2305 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 return;
2307 }
2308
2309 if (status_code == WLAN_STATUS_SUCCESS &&
2310 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2311 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2312 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2313 HOSTAPD_LEVEL_INFO, "authenticated");
2314 sta->flags |= WLAN_STA_AUTH;
2315 }
2316}
2317
2318
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002319static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2320 struct sta_info *sta,
2321 char *ifname_wds)
2322{
2323 int i;
2324 struct hostapd_ssid *ssid = sta->ssid;
2325
2326 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2327 return;
2328
2329 for (i = 0; i < 4; i++) {
2330 if (ssid->wep.key[i] &&
2331 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2332 i == ssid->wep.idx, NULL, 0,
2333 ssid->wep.key[i], ssid->wep.len[i])) {
2334 wpa_printf(MSG_WARNING,
2335 "Could not set WEP keys for WDS interface; %s",
2336 ifname_wds);
2337 break;
2338 }
2339 }
2340}
2341
2342
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002343static void handle_assoc_cb(struct hostapd_data *hapd,
2344 const struct ieee80211_mgmt *mgmt,
2345 size_t len, int reassoc, int ok)
2346{
2347 u16 status;
2348 struct sta_info *sta;
2349 int new_assoc = 1;
2350 struct ieee80211_ht_capabilities ht_cap;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002351 struct ieee80211_vht_capabilities vht_cap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002352
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002353 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2354 sizeof(mgmt->u.assoc_resp))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002355 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2356 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002357 return;
2358 }
2359
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002360 sta = ap_get_sta(hapd, mgmt->da);
2361 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002362 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2363 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002364 return;
2365 }
2366
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002367 if (!ok) {
2368 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2369 HOSTAPD_LEVEL_DEBUG,
2370 "did not acknowledge association response");
2371 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2372 return;
2373 }
2374
2375 if (reassoc)
2376 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2377 else
2378 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2379
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002380 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002381 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002382
2383 /* Stop previous accounting session, if one is started, and allocate
2384 * new session id for the new session. */
2385 accounting_sta_stop(hapd, sta);
2386
2387 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2388 HOSTAPD_LEVEL_INFO,
2389 "associated (aid %d)",
2390 sta->aid);
2391
2392 if (sta->flags & WLAN_STA_ASSOC)
2393 new_assoc = 0;
2394 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002395 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002396 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002397 sta->auth_alg == WLAN_AUTH_FT) {
2398 /*
2399 * Open, static WEP, or FT protocol; no separate authorization
2400 * step.
2401 */
2402 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002403 }
2404
2405 if (reassoc)
2406 mlme_reassociate_indication(hapd, sta);
2407 else
2408 mlme_associate_indication(hapd, sta);
2409
2410#ifdef CONFIG_IEEE80211W
2411 sta->sa_query_timed_out = 0;
2412#endif /* CONFIG_IEEE80211W */
2413
2414 /*
2415 * Remove the STA entry in order to make sure the STA PS state gets
2416 * cleared and configuration gets updated in case of reassociation back
2417 * to the same AP.
2418 */
2419 hostapd_drv_sta_remove(hapd, sta->addr);
2420
2421#ifdef CONFIG_IEEE80211N
2422 if (sta->flags & WLAN_STA_HT)
2423 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
2424#endif /* CONFIG_IEEE80211N */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002425#ifdef CONFIG_IEEE80211AC
2426 if (sta->flags & WLAN_STA_VHT)
2427 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
2428#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002429
2430 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
2431 sta->supported_rates, sta->supported_rates_len,
2432 sta->listen_interval,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002433 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002434 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08002435 sta->flags, sta->qosinfo, sta->vht_opmode)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002436 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2437 HOSTAPD_LEVEL_NOTICE,
2438 "Could not add STA to kernel driver");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002439
2440 ap_sta_disconnect(hapd, sta, sta->addr,
2441 WLAN_REASON_DISASSOC_AP_BUSY);
2442
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002443 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002444 }
2445
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002446 if (sta->flags & WLAN_STA_WDS) {
2447 int ret;
2448 char ifname_wds[IFNAMSIZ + 1];
2449
2450 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2451 sta->aid, 1);
2452 if (!ret)
2453 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2454 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002455
2456 if (sta->eapol_sm == NULL) {
2457 /*
2458 * This STA does not use RADIUS server for EAP authentication,
2459 * so bind it to the selected VLAN interface now, since the
2460 * interface selection is not going to change anymore.
2461 */
2462 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002463 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002464 } else if (sta->vlan_id) {
2465 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2466 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002467 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002468 }
2469
2470 hostapd_set_sta_flags(hapd, sta);
2471
2472 if (sta->auth_alg == WLAN_AUTH_FT)
2473 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2474 else
2475 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2476 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2477
2478 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002479}
2480
2481
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002482static void handle_deauth_cb(struct hostapd_data *hapd,
2483 const struct ieee80211_mgmt *mgmt,
2484 size_t len, int ok)
2485{
2486 struct sta_info *sta;
2487 if (mgmt->da[0] & 0x01)
2488 return;
2489 sta = ap_get_sta(hapd, mgmt->da);
2490 if (!sta) {
2491 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2492 " not found", MAC2STR(mgmt->da));
2493 return;
2494 }
2495 if (ok)
2496 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2497 MAC2STR(sta->addr));
2498 else
2499 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2500 "deauth", MAC2STR(sta->addr));
2501
2502 ap_sta_deauth_cb(hapd, sta);
2503}
2504
2505
2506static void handle_disassoc_cb(struct hostapd_data *hapd,
2507 const struct ieee80211_mgmt *mgmt,
2508 size_t len, int ok)
2509{
2510 struct sta_info *sta;
2511 if (mgmt->da[0] & 0x01)
2512 return;
2513 sta = ap_get_sta(hapd, mgmt->da);
2514 if (!sta) {
2515 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2516 " not found", MAC2STR(mgmt->da));
2517 return;
2518 }
2519 if (ok)
2520 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2521 MAC2STR(sta->addr));
2522 else
2523 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2524 "disassoc", MAC2STR(sta->addr));
2525
2526 ap_sta_disassoc_cb(hapd, sta);
2527}
2528
2529
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002530/**
2531 * ieee802_11_mgmt_cb - Process management frame TX status callback
2532 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2533 * was sent from)
2534 * @buf: management frame data (starting from IEEE 802.11 header)
2535 * @len: length of frame data in octets
2536 * @stype: management frame subtype from frame control field
2537 * @ok: Whether the frame was ACK'ed
2538 */
2539void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2540 u16 stype, int ok)
2541{
2542 const struct ieee80211_mgmt *mgmt;
2543 mgmt = (const struct ieee80211_mgmt *) buf;
2544
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002545#ifdef CONFIG_TESTING_OPTIONS
2546 if (hapd->ext_mgmt_frame_handling) {
2547 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2548 stype, ok);
2549 return;
2550 }
2551#endif /* CONFIG_TESTING_OPTIONS */
2552
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002553 switch (stype) {
2554 case WLAN_FC_STYPE_AUTH:
2555 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2556 handle_auth_cb(hapd, mgmt, len, ok);
2557 break;
2558 case WLAN_FC_STYPE_ASSOC_RESP:
2559 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2560 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2561 break;
2562 case WLAN_FC_STYPE_REASSOC_RESP:
2563 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2564 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2565 break;
2566 case WLAN_FC_STYPE_PROBE_RESP:
2567 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2568 break;
2569 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002570 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2571 handle_deauth_cb(hapd, mgmt, len, ok);
2572 break;
2573 case WLAN_FC_STYPE_DISASSOC:
2574 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2575 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576 break;
2577 case WLAN_FC_STYPE_ACTION:
2578 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2579 break;
2580 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002581 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002582 break;
2583 }
2584}
2585
2586
2587int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2588{
2589 /* TODO */
2590 return 0;
2591}
2592
2593
2594int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2595 char *buf, size_t buflen)
2596{
2597 /* TODO */
2598 return 0;
2599}
2600
2601
2602void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2603 const u8 *buf, size_t len, int ack)
2604{
2605 struct sta_info *sta;
2606 struct hostapd_iface *iface = hapd->iface;
2607
2608 sta = ap_get_sta(hapd, addr);
2609 if (sta == NULL && iface->num_bss > 1) {
2610 size_t j;
2611 for (j = 0; j < iface->num_bss; j++) {
2612 hapd = iface->bss[j];
2613 sta = ap_get_sta(hapd, addr);
2614 if (sta)
2615 break;
2616 }
2617 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002618 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002619 return;
2620 if (sta->flags & WLAN_STA_PENDING_POLL) {
2621 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2622 "activity poll", MAC2STR(sta->addr),
2623 ack ? "ACKed" : "did not ACK");
2624 if (ack)
2625 sta->flags &= ~WLAN_STA_PENDING_POLL;
2626 }
2627
2628 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2629}
2630
2631
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002632void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2633 const u8 *data, size_t len, int ack)
2634{
2635 struct sta_info *sta;
2636 struct hostapd_iface *iface = hapd->iface;
2637
2638 sta = ap_get_sta(hapd, dst);
2639 if (sta == NULL && iface->num_bss > 1) {
2640 size_t j;
2641 for (j = 0; j < iface->num_bss; j++) {
2642 hapd = iface->bss[j];
2643 sta = ap_get_sta(hapd, dst);
2644 if (sta)
2645 break;
2646 }
2647 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002648 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2649 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2650 MACSTR " that is not currently associated",
2651 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002652 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002653 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002654
2655 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2656}
2657
2658
2659void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2660{
2661 struct sta_info *sta;
2662 struct hostapd_iface *iface = hapd->iface;
2663
2664 sta = ap_get_sta(hapd, addr);
2665 if (sta == NULL && iface->num_bss > 1) {
2666 size_t j;
2667 for (j = 0; j < iface->num_bss; j++) {
2668 hapd = iface->bss[j];
2669 sta = ap_get_sta(hapd, addr);
2670 if (sta)
2671 break;
2672 }
2673 }
2674 if (sta == NULL)
2675 return;
2676 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2677 return;
2678
2679 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2680 "activity poll", MAC2STR(sta->addr));
2681 sta->flags &= ~WLAN_STA_PENDING_POLL;
2682}
2683
2684
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002685void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2686 int wds)
2687{
2688 struct sta_info *sta;
2689
2690 sta = ap_get_sta(hapd, src);
2691 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002692 if (!hapd->conf->wds_sta)
2693 return;
2694
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002695 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002696 int ret;
2697 char ifname_wds[IFNAMSIZ + 1];
2698
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2700 "STA " MACSTR " (aid %u)",
2701 MAC2STR(sta->addr), sta->aid);
2702 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002703 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2704 sta->addr, sta->aid, 1);
2705 if (!ret)
2706 hostapd_set_wds_encryption(hapd, sta,
2707 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002708 }
2709 return;
2710 }
2711
2712 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2713 MACSTR, MAC2STR(src));
2714 if (src[0] & 0x01) {
2715 /* Broadcast bit set in SA?! Ignore the frame silently. */
2716 return;
2717 }
2718
2719 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2720 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2721 "already been sent, but no TX status yet known - "
2722 "ignore Class 3 frame issue with " MACSTR,
2723 MAC2STR(src));
2724 return;
2725 }
2726
2727 if (sta && (sta->flags & WLAN_STA_AUTH))
2728 hostapd_drv_sta_disassoc(
2729 hapd, src,
2730 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2731 else
2732 hostapd_drv_sta_deauth(
2733 hapd, src,
2734 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2735}
2736
2737
2738#endif /* CONFIG_NATIVE_WINDOWS */