blob: ec6f8a76bb9f69f07f67e4b3f38ab593dd10e121 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.11 Management
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003 * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#ifndef CONFIG_NATIVE_WINDOWS
12
13#include "utils/common.h"
14#include "utils/eloop.h"
15#include "crypto/crypto.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080016#include "crypto/sha256.h"
17#include "crypto/random.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include "common/ieee802_11_defs.h"
19#include "common/ieee802_11_common.h"
20#include "common/wpa_ctrl.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080021#include "common/sae.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include "radius/radius.h"
23#include "radius/radius_client.h"
24#include "p2p/p2p.h"
25#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "hostapd.h"
28#include "beacon.h"
29#include "ieee802_11_auth.h"
30#include "sta_info.h"
31#include "ieee802_1x.h"
32#include "wpa_auth.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080033#include "pmksa_cache_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "wmm.h"
35#include "ap_list.h"
36#include "accounting.h"
37#include "ap_config.h"
38#include "ap_mlme.h"
39#include "p2p_hostapd.h"
40#include "ap_drv_ops.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080041#include "wnm_ap.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080042#include "hw_features.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "ieee802_11.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080044#include "dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045
46
47u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
48{
49 u8 *pos = eid;
50 int i, num, count;
51
52 if (hapd->iface->current_rates == NULL)
53 return eid;
54
55 *pos++ = WLAN_EID_SUPP_RATES;
56 num = hapd->iface->num_rates;
57 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
58 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080059 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
60 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070061 if (num > 8) {
62 /* rest of the rates are encoded in Extended supported
63 * rates element */
64 num = 8;
65 }
66
67 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070068 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
69 i++) {
70 count++;
71 *pos = hapd->iface->current_rates[i].rate / 5;
72 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
73 *pos |= 0x80;
74 pos++;
75 }
76
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080077 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
78 count++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070079 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080080 }
81
82 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
83 count++;
84 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
85 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070086
87 return pos;
88}
89
90
91u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
92{
93 u8 *pos = eid;
94 int i, num, count;
95
96 if (hapd->iface->current_rates == NULL)
97 return eid;
98
99 num = hapd->iface->num_rates;
100 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
101 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800102 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
103 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 if (num <= 8)
105 return eid;
106 num -= 8;
107
108 *pos++ = WLAN_EID_EXT_SUPP_RATES;
109 *pos++ = num;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700110 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
111 i++) {
112 count++;
113 if (count <= 8)
114 continue; /* already in SuppRates IE */
115 *pos = hapd->iface->current_rates[i].rate / 5;
116 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
117 *pos |= 0x80;
118 pos++;
119 }
120
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800121 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
122 count++;
123 if (count > 8)
124 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
125 }
126
127 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
128 count++;
129 if (count > 8)
130 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
131 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700132
133 return pos;
134}
135
136
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700137u16 hostapd_own_capab_info(struct hostapd_data *hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700138{
139 int capab = WLAN_CAPABILITY_ESS;
140 int privacy;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800141 int dfs;
142
143 /* Check if any of configured channels require DFS */
144 dfs = hostapd_is_dfs_required(hapd->iface);
145 if (dfs < 0) {
146 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
147 dfs);
148 dfs = 0;
149 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150
151 if (hapd->iface->num_sta_no_short_preamble == 0 &&
152 hapd->iconf->preamble == SHORT_PREAMBLE)
153 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
154
155 privacy = hapd->conf->ssid.wep.keys_set;
156
157 if (hapd->conf->ieee802_1x &&
158 (hapd->conf->default_wep_key_len ||
159 hapd->conf->individual_wep_key_len))
160 privacy = 1;
161
162 if (hapd->conf->wpa)
163 privacy = 1;
164
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800165#ifdef CONFIG_HS20
166 if (hapd->conf->osen)
167 privacy = 1;
168#endif /* CONFIG_HS20 */
169
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170 if (privacy)
171 capab |= WLAN_CAPABILITY_PRIVACY;
172
173 if (hapd->iface->current_mode &&
174 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
175 hapd->iface->num_sta_no_short_slot_time == 0)
176 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
177
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800178 /*
179 * Currently, Spectrum Management capability bit is set when directly
180 * requested in configuration by spectrum_mgmt_required or when AP is
181 * running on DFS channel.
182 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
183 */
184 if (hapd->iface->current_mode &&
185 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
186 (hapd->iconf->spectrum_mgmt_required || dfs))
187 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
188
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800189 if (hapd->conf->radio_measurements)
190 capab |= IEEE80211_CAP_RRM;
191
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192 return capab;
193}
194
195
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800196#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700197static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
198 u16 auth_transaction, const u8 *challenge,
199 int iswep)
200{
201 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
202 HOSTAPD_LEVEL_DEBUG,
203 "authentication (shared key, transaction %d)",
204 auth_transaction);
205
206 if (auth_transaction == 1) {
207 if (!sta->challenge) {
208 /* Generate a pseudo-random challenge */
209 u8 key[8];
210 struct os_time now;
211 int r;
212 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
213 if (sta->challenge == NULL)
214 return WLAN_STATUS_UNSPECIFIED_FAILURE;
215
216 os_get_time(&now);
217 r = os_random();
218 os_memcpy(key, &now.sec, 4);
219 os_memcpy(key + 4, &r, 4);
220 rc4_skip(key, sizeof(key), 0,
221 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
222 }
223 return 0;
224 }
225
226 if (auth_transaction != 3)
227 return WLAN_STATUS_UNSPECIFIED_FAILURE;
228
229 /* Transaction 3 */
230 if (!iswep || !sta->challenge || !challenge ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700231 os_memcmp_const(sta->challenge, challenge,
232 WLAN_AUTH_CHALLENGE_LEN)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700233 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
234 HOSTAPD_LEVEL_INFO,
235 "shared key authentication - invalid "
236 "challenge-response");
237 return WLAN_STATUS_CHALLENGE_FAIL;
238 }
239
240 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
241 HOSTAPD_LEVEL_DEBUG,
242 "authentication OK (shared key)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243 sta->flags |= WLAN_STA_AUTH;
244 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245 os_free(sta->challenge);
246 sta->challenge = NULL;
247
248 return 0;
249}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800250#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700251
252
253static void send_auth_reply(struct hostapd_data *hapd,
254 const u8 *dst, const u8 *bssid,
255 u16 auth_alg, u16 auth_transaction, u16 resp,
256 const u8 *ies, size_t ies_len)
257{
258 struct ieee80211_mgmt *reply;
259 u8 *buf;
260 size_t rlen;
261
262 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
263 buf = os_zalloc(rlen);
264 if (buf == NULL)
265 return;
266
267 reply = (struct ieee80211_mgmt *) buf;
268 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
269 WLAN_FC_STYPE_AUTH);
270 os_memcpy(reply->da, dst, ETH_ALEN);
271 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
272 os_memcpy(reply->bssid, bssid, ETH_ALEN);
273
274 reply->u.auth.auth_alg = host_to_le16(auth_alg);
275 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
276 reply->u.auth.status_code = host_to_le16(resp);
277
278 if (ies && ies_len)
279 os_memcpy(reply->u.auth.variable, ies, ies_len);
280
281 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
282 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
283 MAC2STR(dst), auth_alg, auth_transaction,
284 resp, (unsigned long) ies_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800285 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800286 wpa_printf(MSG_INFO, "send_auth_reply: send");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700287
288 os_free(buf);
289}
290
291
292#ifdef CONFIG_IEEE80211R
293static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
294 u16 auth_transaction, u16 status,
295 const u8 *ies, size_t ies_len)
296{
297 struct hostapd_data *hapd = ctx;
298 struct sta_info *sta;
299
300 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
301 status, ies, ies_len);
302
303 if (status != WLAN_STATUS_SUCCESS)
304 return;
305
306 sta = ap_get_sta(hapd, dst);
307 if (sta == NULL)
308 return;
309
310 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
311 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
312 sta->flags |= WLAN_STA_AUTH;
313 mlme_authenticate_indication(hapd, sta);
314}
315#endif /* CONFIG_IEEE80211R */
316
317
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800318#ifdef CONFIG_SAE
319
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800320#define dot11RSNASAESync 5 /* attempts */
321
322
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800323static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
324 struct sta_info *sta, int update)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800325{
326 struct wpabuf *buf;
327
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800328 if (hapd->conf->ssid.wpa_passphrase == NULL) {
329 wpa_printf(MSG_DEBUG, "SAE: No password available");
330 return NULL;
331 }
332
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800333 if (update &&
334 sae_prepare_commit(hapd->own_addr, sta->addr,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800335 (u8 *) hapd->conf->ssid.wpa_passphrase,
336 os_strlen(hapd->conf->ssid.wpa_passphrase),
337 sta->sae) < 0) {
338 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
339 return NULL;
340 }
341
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800342 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800343 if (buf == NULL)
344 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800345 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
346 sta->sae->tmp->anti_clogging_token : NULL);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800347
348 return buf;
349}
350
351
352static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
353 struct sta_info *sta)
354{
355 struct wpabuf *buf;
356
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800357 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800358 if (buf == NULL)
359 return NULL;
360
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800361 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800362
363 return buf;
364}
365
366
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800367static int auth_sae_send_commit(struct hostapd_data *hapd,
368 struct sta_info *sta,
369 const u8 *bssid, int update)
370{
371 struct wpabuf *data;
372
373 data = auth_build_sae_commit(hapd, sta, update);
374 if (data == NULL)
375 return WLAN_STATUS_UNSPECIFIED_FAILURE;
376
377 send_auth_reply(hapd, sta->addr, bssid,
378 WLAN_AUTH_SAE, 1, WLAN_STATUS_SUCCESS,
379 wpabuf_head(data), wpabuf_len(data));
380
381 wpabuf_free(data);
382
383 return WLAN_STATUS_SUCCESS;
384}
385
386
387static int auth_sae_send_confirm(struct hostapd_data *hapd,
388 struct sta_info *sta,
389 const u8 *bssid)
390{
391 struct wpabuf *data;
392
393 data = auth_build_sae_confirm(hapd, sta);
394 if (data == NULL)
395 return WLAN_STATUS_UNSPECIFIED_FAILURE;
396
397 send_auth_reply(hapd, sta->addr, bssid,
398 WLAN_AUTH_SAE, 2, WLAN_STATUS_SUCCESS,
399 wpabuf_head(data), wpabuf_len(data));
400
401 wpabuf_free(data);
402
403 return WLAN_STATUS_SUCCESS;
404}
405
406
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800407static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800408{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800409 struct sta_info *sta;
410 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800411
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800412 if (hapd->conf->sae_anti_clogging_threshold == 0)
413 return 1;
414
415 for (sta = hapd->sta_list; sta; sta = sta->next) {
416 if (!sta->sae)
417 continue;
418 if (sta->sae->state != SAE_COMMITTED &&
419 sta->sae->state != SAE_CONFIRMED)
420 continue;
421 open++;
422 if (open >= hapd->conf->sae_anti_clogging_threshold)
423 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800424 }
425
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800426 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800427}
428
429
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800430static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
431 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800432{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800433 u8 mac[SHA256_MAC_LEN];
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800434
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800435 if (token_len != SHA256_MAC_LEN)
436 return -1;
437 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
438 addr, ETH_ALEN, mac) < 0 ||
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700439 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800440 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800441
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800442 return 0;
443}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800444
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800445
446static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800447 int group, const u8 *addr)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800448{
449 struct wpabuf *buf;
450 u8 *token;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800451 struct os_reltime now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800452
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800453 os_get_reltime(&now);
454 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
455 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800456 if (random_get_bytes(hapd->sae_token_key,
457 sizeof(hapd->sae_token_key)) < 0)
458 return NULL;
459 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
460 hapd->sae_token_key, sizeof(hapd->sae_token_key));
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800461 hapd->last_sae_token_key_update = now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800462 }
463
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800464 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800465 if (buf == NULL)
466 return NULL;
467
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800468 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
469
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800470 token = wpabuf_put(buf, SHA256_MAC_LEN);
471 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
472 addr, ETH_ALEN, token);
473
474 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800475}
476
477
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800478static int sae_check_big_sync(struct sta_info *sta)
479{
480 if (sta->sae->sync > dot11RSNASAESync) {
481 sta->sae->state = SAE_NOTHING;
482 sta->sae->sync = 0;
483 return -1;
484 }
485 return 0;
486}
487
488
489static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
490{
491 struct hostapd_data *hapd = eloop_ctx;
492 struct sta_info *sta = eloop_data;
493 int ret;
494
495 if (sae_check_big_sync(sta))
496 return;
497 sta->sae->sync++;
498
499 switch (sta->sae->state) {
500 case SAE_COMMITTED:
501 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800502 eloop_register_timeout(0,
503 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800504 auth_sae_retransmit_timer, hapd, sta);
505 break;
506 case SAE_CONFIRMED:
507 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800508 eloop_register_timeout(0,
509 hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800510 auth_sae_retransmit_timer, hapd, sta);
511 break;
512 default:
513 ret = -1;
514 break;
515 }
516
517 if (ret != WLAN_STATUS_SUCCESS)
518 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
519}
520
521
522void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
523{
524 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
525}
526
527
528static void sae_set_retransmit_timer(struct hostapd_data *hapd,
529 struct sta_info *sta)
530{
531 if (!(hapd->conf->mesh & MESH_ENABLED))
532 return;
533
534 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800535 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800536 auth_sae_retransmit_timer, hapd, sta);
537}
538
539
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800540static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
541 const u8 *bssid, u8 auth_transaction)
542{
543 int ret;
544
545 if (auth_transaction != 1 && auth_transaction != 2)
546 return WLAN_STATUS_UNSPECIFIED_FAILURE;
547
548 switch (sta->sae->state) {
549 case SAE_NOTHING:
550 if (auth_transaction == 1) {
551 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
552 if (ret)
553 return ret;
554 sta->sae->state = SAE_COMMITTED;
555
556 if (sae_process_commit(sta->sae) < 0)
557 return WLAN_STATUS_UNSPECIFIED_FAILURE;
558
559 /*
560 * In mesh case, both Commit and Confirm can be sent
561 * immediately. In infrastructure BSS, only a single
562 * Authentication frame (Commit) is expected from the AP
563 * here and the second one (Confirm) will be sent once
564 * the STA has sent its second Authentication frame
565 * (Confirm).
566 */
567 if (hapd->conf->mesh & MESH_ENABLED) {
568 /*
569 * Send both Commit and Confirm immediately
570 * based on SAE finite state machine
571 * Nothing -> Confirm transition.
572 */
573 ret = auth_sae_send_confirm(hapd, sta, bssid);
574 if (ret)
575 return ret;
576 sta->sae->state = SAE_CONFIRMED;
577 } else {
578 /*
579 * For infrastructure BSS, send only the Commit
580 * message now to get alternating sequence of
581 * Authentication frames between the AP and STA.
582 * Confirm will be sent in
583 * Commited -> Confirmed/Accepted transition
584 * when receiving Confirm from STA.
585 */
586 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800587 sta->sae->sync = 0;
588 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800589 } else {
590 hostapd_logger(hapd, sta->addr,
591 HOSTAPD_MODULE_IEEE80211,
592 HOSTAPD_LEVEL_DEBUG,
593 "SAE confirm before commit");
594 }
595 break;
596 case SAE_COMMITTED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800597 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800598 if (auth_transaction == 1) {
599 if (sae_process_commit(sta->sae) < 0)
600 return WLAN_STATUS_UNSPECIFIED_FAILURE;
601
602 ret = auth_sae_send_confirm(hapd, sta, bssid);
603 if (ret)
604 return ret;
605 sta->sae->state = SAE_CONFIRMED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800606 sta->sae->sync = 0;
607 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800608 } else if (hapd->conf->mesh & MESH_ENABLED) {
609 /*
610 * In mesh case, follow SAE finite state machine and
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800611 * send Commit now, if sync count allows.
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800612 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800613 if (sae_check_big_sync(sta))
614 return WLAN_STATUS_SUCCESS;
615 sta->sae->sync++;
616
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700617 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800618 if (ret)
619 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800620
621 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800622 } else {
623 /*
624 * For instructure BSS, send the postponed Confirm from
625 * Nothing -> Confirmed transition that was reduced to
626 * Nothing -> Committed above.
627 */
628 ret = auth_sae_send_confirm(hapd, sta, bssid);
629 if (ret)
630 return ret;
631
632 sta->sae->state = SAE_CONFIRMED;
633
634 /*
635 * Since this was triggered on Confirm RX, run another
636 * step to get to Accepted without waiting for
637 * additional events.
638 */
639 return sae_sm_step(hapd, sta, bssid, auth_transaction);
640 }
641 break;
642 case SAE_CONFIRMED:
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800643 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800644 if (auth_transaction == 1) {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800645 if (sae_check_big_sync(sta))
646 return WLAN_STATUS_SUCCESS;
647 sta->sae->sync++;
648
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800649 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
650 if (ret)
651 return ret;
652
653 if (sae_process_commit(sta->sae) < 0)
654 return WLAN_STATUS_UNSPECIFIED_FAILURE;
655
656 ret = auth_sae_send_confirm(hapd, sta, bssid);
657 if (ret)
658 return ret;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800659
660 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800661 } else {
662 sta->flags |= WLAN_STA_AUTH;
663 sta->auth_alg = WLAN_AUTH_SAE;
664 mlme_authenticate_indication(hapd, sta);
665 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
666 sta->sae->state = SAE_ACCEPTED;
667 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
668 sta->sae->pmk);
669 }
670 break;
671 case SAE_ACCEPTED:
672 if (auth_transaction == 1) {
673 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
674 ") doing reauthentication",
675 MAC2STR(sta->addr));
676 ap_free_sta(hapd, sta);
677 } else {
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800678 if (sae_check_big_sync(sta))
679 return WLAN_STATUS_SUCCESS;
680 sta->sae->sync++;
681
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800682 ret = auth_sae_send_confirm(hapd, sta, bssid);
683 sae_clear_temp_data(sta->sae);
684 if (ret)
685 return ret;
686 }
687 break;
688 default:
689 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
690 sta->sae->state);
691 return WLAN_STATUS_UNSPECIFIED_FAILURE;
692 }
693 return WLAN_STATUS_SUCCESS;
694}
695
696
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800697static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
698 const struct ieee80211_mgmt *mgmt, size_t len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800699 u16 auth_transaction, u16 status_code)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800700{
701 u16 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800702 struct wpabuf *data = NULL;
703
704 if (!sta->sae) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800705 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800706 return;
707 sta->sae = os_zalloc(sizeof(*sta->sae));
708 if (sta->sae == NULL)
709 return;
710 sta->sae->state = SAE_NOTHING;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800711 sta->sae->sync = 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800712 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800713
714 if (auth_transaction == 1) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800715 const u8 *token = NULL, *pos, *end;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800716 size_t token_len = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800717 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
718 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800719 "start SAE authentication (RX commit, status=%u)",
720 status_code);
721
722 if ((hapd->conf->mesh & MESH_ENABLED) &&
723 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
724 sta->sae->tmp) {
725 pos = mgmt->u.auth.variable;
726 end = ((const u8 *) mgmt) + len;
727 if (pos + sizeof(le16) > end) {
728 wpa_printf(MSG_ERROR,
729 "SAE: Too short anti-clogging token request");
730 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
731 goto reply;
732 }
733 resp = sae_group_allowed(sta->sae,
734 hapd->conf->sae_groups,
735 WPA_GET_LE16(pos));
736 if (resp != WLAN_STATUS_SUCCESS) {
737 wpa_printf(MSG_ERROR,
738 "SAE: Invalid group in anti-clogging token request");
739 goto reply;
740 }
741 pos += sizeof(le16);
742
743 wpabuf_free(sta->sae->tmp->anti_clogging_token);
744 sta->sae->tmp->anti_clogging_token =
745 wpabuf_alloc_copy(pos, end - pos);
746 if (sta->sae->tmp->anti_clogging_token == NULL) {
747 wpa_printf(MSG_ERROR,
748 "SAE: Failed to alloc for anti-clogging token");
749 return;
750 }
751
752 /*
753 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
754 * is 76, a new Commit Message shall be constructed
755 * with the Anti-Clogging Token from the received
756 * Authentication frame, and the commit-scalar and
757 * COMMIT-ELEMENT previously sent.
758 */
759 if (auth_sae_send_commit(hapd, sta, mgmt->bssid, 0)) {
760 wpa_printf(MSG_ERROR,
761 "SAE: Failed to send commit message");
762 return;
763 }
764 sta->sae->state = SAE_COMMITTED;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800765 sta->sae->sync = 0;
766 sae_set_retransmit_timer(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800767 return;
768 }
769
770 if (status_code != WLAN_STATUS_SUCCESS)
771 return;
772
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800773 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
774 ((const u8 *) mgmt) + len -
775 mgmt->u.auth.variable, &token,
776 &token_len, hapd->conf->sae_groups);
Dmitry Shmidt41712582015-06-29 11:02:15 -0700777 if (resp == SAE_SILENTLY_DISCARD) {
778 wpa_printf(MSG_DEBUG,
779 "SAE: Drop commit message from " MACSTR " due to reflection attack",
780 MAC2STR(sta->addr));
781 return;
782 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800783 if (token && check_sae_token(hapd, sta->addr, token, token_len)
784 < 0) {
785 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
786 "incorrect token from " MACSTR,
787 MAC2STR(sta->addr));
788 return;
789 }
790
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800791 if (resp != WLAN_STATUS_SUCCESS)
792 goto reply;
793
794 if (!token && use_sae_anti_clogging(hapd)) {
795 wpa_printf(MSG_DEBUG,
796 "SAE: Request anti-clogging token from "
797 MACSTR, MAC2STR(sta->addr));
798 data = auth_build_token_req(hapd, sta->sae->group,
799 sta->addr);
800 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
801 if (hapd->conf->mesh & MESH_ENABLED)
802 sta->sae->state = SAE_NOTHING;
803 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800804 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800805
806 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800807 } else if (auth_transaction == 2) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800808 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
809 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800810 "SAE authentication (RX confirm, status=%u)",
811 status_code);
812 if (status_code != WLAN_STATUS_SUCCESS)
813 return;
814 if (sta->sae->state >= SAE_CONFIRMED ||
815 !(hapd->conf->mesh & MESH_ENABLED)) {
816 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
817 ((u8 *) mgmt) + len -
818 mgmt->u.auth.variable) < 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800819 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800820 goto reply;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800821 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800822 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800823 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800824 } else {
825 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
826 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800827 "unexpected SAE authentication transaction %u (status=%u)",
828 auth_transaction, status_code);
829 if (status_code != WLAN_STATUS_SUCCESS)
830 return;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800831 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
832 }
833
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800834reply:
835 if (resp != WLAN_STATUS_SUCCESS) {
836 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
837 auth_transaction, resp,
838 data ? wpabuf_head(data) : (u8 *) "",
839 data ? wpabuf_len(data) : 0);
840 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800841 wpabuf_free(data);
842}
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800843
844
845/**
846 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
847 * @hapd: BSS data for the device initiating the authentication
848 * @sta: the peer to which commit authentication frame is sent
849 *
850 * This function implements Init event handling (IEEE Std 802.11-2012,
851 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
852 * sta->sae structure should be initialized appropriately via a call to
853 * sae_prepare_commit().
854 */
855int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
856{
857 int ret;
858
859 if (!sta->sae || !sta->sae->tmp)
860 return -1;
861
862 if (sta->sae->state != SAE_NOTHING)
863 return -1;
864
865 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
866 if (ret)
867 return -1;
868
869 sta->sae->state = SAE_COMMITTED;
870 sta->sae->sync = 0;
871 sae_set_retransmit_timer(hapd, sta);
872
873 return 0;
874}
875
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800876#endif /* CONFIG_SAE */
877
878
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879static void handle_auth(struct hostapd_data *hapd,
880 const struct ieee80211_mgmt *mgmt, size_t len)
881{
882 u16 auth_alg, auth_transaction, status_code;
883 u16 resp = WLAN_STATUS_SUCCESS;
884 struct sta_info *sta = NULL;
885 int res;
886 u16 fc;
887 const u8 *challenge = NULL;
888 u32 session_timeout, acct_interim_interval;
889 int vlan_id = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800890 struct hostapd_sta_wpa_psk_short *psk = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700891 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
892 size_t resp_ies_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700893 char *identity = NULL;
894 char *radius_cui = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800895 u16 seq_ctrl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896
897 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800898 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
899 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900 return;
901 }
902
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700903#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700904 if (hapd->iconf->ignore_auth_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700905 drand48() < hapd->iconf->ignore_auth_probability) {
906 wpa_printf(MSG_INFO,
907 "TESTING: ignoring auth frame from " MACSTR,
908 MAC2STR(mgmt->sa));
909 return;
910 }
911#endif /* CONFIG_TESTING_OPTIONS */
912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
914 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
915 status_code = le_to_host16(mgmt->u.auth.status_code);
916 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800917 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918
919 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
920 2 + WLAN_AUTH_CHALLENGE_LEN &&
921 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
922 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
923 challenge = &mgmt->u.auth.variable[2];
924
925 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800926 "auth_transaction=%d status_code=%d wep=%d%s "
927 "seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
929 status_code, !!(fc & WLAN_FC_ISWEP),
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800930 challenge ? " challenge" : "",
931 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700932
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800933#ifdef CONFIG_NO_RC4
934 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
935 wpa_printf(MSG_INFO,
936 "Unsupported authentication algorithm (%d)",
937 auth_alg);
938 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
939 goto fail;
940 }
941#endif /* CONFIG_NO_RC4 */
942
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 if (hapd->tkip_countermeasures) {
944 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
945 goto fail;
946 }
947
948 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
949 auth_alg == WLAN_AUTH_OPEN) ||
950#ifdef CONFIG_IEEE80211R
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800951 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700952 auth_alg == WLAN_AUTH_FT) ||
953#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800954#ifdef CONFIG_SAE
955 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
956 auth_alg == WLAN_AUTH_SAE) ||
957#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
959 auth_alg == WLAN_AUTH_SHARED_KEY))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800960 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
961 auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
963 goto fail;
964 }
965
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800966 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700967 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800968 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
969 auth_transaction);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700970 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
971 goto fail;
972 }
973
974 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800975 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
976 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
978 goto fail;
979 }
980
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800981 if (hapd->conf->no_auth_if_seen_on) {
982 struct hostapd_data *other;
983
984 other = sta_track_seen_on(hapd->iface, mgmt->sa,
985 hapd->conf->no_auth_if_seen_on);
986 if (other) {
987 u8 *pos;
988 u32 info;
989 u8 op_class, channel, phytype;
990
991 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
992 MACSTR " since STA has been seen on %s",
993 hapd->conf->iface, MAC2STR(mgmt->sa),
994 hapd->conf->no_auth_if_seen_on);
995
996 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
997 pos = &resp_ies[0];
998 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
999 *pos++ = 13;
1000 os_memcpy(pos, other->own_addr, ETH_ALEN);
1001 pos += ETH_ALEN;
1002 info = 0; /* TODO: BSSID Information */
1003 WPA_PUT_LE32(pos, info);
1004 pos += 4;
1005 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1006 phytype = 8; /* dmg */
1007 else if (other->iconf->ieee80211ac)
1008 phytype = 9; /* vht */
1009 else if (other->iconf->ieee80211n)
1010 phytype = 7; /* ht */
1011 else if (other->iconf->hw_mode ==
1012 HOSTAPD_MODE_IEEE80211A)
1013 phytype = 4; /* ofdm */
1014 else if (other->iconf->hw_mode ==
1015 HOSTAPD_MODE_IEEE80211G)
1016 phytype = 6; /* erp */
1017 else
1018 phytype = 5; /* hrdsss */
1019 if (ieee80211_freq_to_channel_ext(
1020 hostapd_hw_get_freq(other,
1021 other->iconf->channel),
1022 other->iconf->secondary_channel,
1023 other->iconf->ieee80211ac,
1024 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1025 op_class = 0;
1026 channel = other->iconf->channel;
1027 }
1028 *pos++ = op_class;
1029 *pos++ = channel;
1030 *pos++ = phytype;
1031 resp_ies_len = pos - &resp_ies[0];
1032 goto fail;
1033 }
1034 }
1035
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1037 &session_timeout,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001038 &acct_interim_interval, &vlan_id,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001039 &psk, &identity, &radius_cui);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001040
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041 if (res == HOSTAPD_ACL_REJECT) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001042 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1043 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001044 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1045 goto fail;
1046 }
1047 if (res == HOSTAPD_ACL_PENDING) {
1048 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1049 " waiting for an external authentication",
1050 MAC2STR(mgmt->sa));
1051 /* Authentication code will re-send the authentication frame
1052 * after it has received (and cached) information from the
1053 * external source. */
1054 return;
1055 }
1056
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001057 sta = ap_get_sta(hapd, mgmt->sa);
1058 if (sta) {
1059 if ((fc & WLAN_FC_RETRY) &&
1060 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1061 sta->last_seq_ctrl == seq_ctrl &&
1062 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1063 hostapd_logger(hapd, sta->addr,
1064 HOSTAPD_MODULE_IEEE80211,
1065 HOSTAPD_LEVEL_DEBUG,
1066 "Drop repeated authentication frame seq_ctrl=0x%x",
1067 seq_ctrl);
1068 return;
1069 }
1070 } else {
1071#ifdef CONFIG_MESH
1072 if (hapd->conf->mesh & MESH_ENABLED) {
1073 /* if the mesh peer is not available, we don't do auth.
1074 */
1075 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1076 " not yet known - drop Authentiation frame",
1077 MAC2STR(mgmt->sa));
1078 /*
1079 * Save a copy of the frame so that it can be processed
1080 * if a new peer entry is added shortly after this.
1081 */
1082 wpabuf_free(hapd->mesh_pending_auth);
1083 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1084 os_get_reltime(&hapd->mesh_pending_auth_time);
1085 return;
1086 }
1087#endif /* CONFIG_MESH */
1088
1089 sta = ap_sta_add(hapd, mgmt->sa);
1090 if (!sta) {
1091 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1092 goto fail;
1093 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001095 sta->last_seq_ctrl = seq_ctrl;
1096 sta->last_subtype = WLAN_FC_STYPE_AUTH;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001097
1098 if (vlan_id > 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001099 if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001100 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1101 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
1102 "%d received from RADIUS server",
1103 vlan_id);
1104 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1105 goto fail;
1106 }
1107 sta->vlan_id = vlan_id;
1108 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1109 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1110 }
1111
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001112 hostapd_free_psk_list(sta->psk);
1113 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1114 sta->psk = psk;
1115 psk = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001116 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001117 sta->psk = NULL;
1118 }
1119
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001120 sta->identity = identity;
1121 identity = NULL;
1122 sta->radius_cui = radius_cui;
1123 radius_cui = NULL;
1124
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001125 sta->flags &= ~WLAN_STA_PREAUTH;
1126 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1127
1128 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
1129 sta->acct_interim_interval = acct_interim_interval;
1130 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1131 ap_sta_session_timeout(hapd, sta, session_timeout);
1132 else
1133 ap_sta_no_session_timeout(hapd, sta);
1134
1135 switch (auth_alg) {
1136 case WLAN_AUTH_OPEN:
1137 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1138 HOSTAPD_LEVEL_DEBUG,
1139 "authentication OK (open system)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001140 sta->flags |= WLAN_STA_AUTH;
1141 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1142 sta->auth_alg = WLAN_AUTH_OPEN;
1143 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001145#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001146 case WLAN_AUTH_SHARED_KEY:
1147 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1148 fc & WLAN_FC_ISWEP);
1149 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1150 mlme_authenticate_indication(hapd, sta);
1151 if (sta->challenge && auth_transaction == 1) {
1152 resp_ies[0] = WLAN_EID_CHALLENGE;
1153 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1154 os_memcpy(resp_ies + 2, sta->challenge,
1155 WLAN_AUTH_CHALLENGE_LEN);
1156 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1157 }
1158 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001159#endif /* CONFIG_NO_RC4 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001160#ifdef CONFIG_IEEE80211R
1161 case WLAN_AUTH_FT:
1162 sta->auth_alg = WLAN_AUTH_FT;
1163 if (sta->wpa_sm == NULL)
1164 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001165 sta->addr, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001166 if (sta->wpa_sm == NULL) {
1167 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1168 "state machine");
1169 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1170 goto fail;
1171 }
1172 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1173 auth_transaction, mgmt->u.auth.variable,
1174 len - IEEE80211_HDRLEN -
1175 sizeof(mgmt->u.auth),
1176 handle_auth_ft_finish, hapd);
1177 /* handle_auth_ft_finish() callback will complete auth. */
1178 return;
1179#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001180#ifdef CONFIG_SAE
1181 case WLAN_AUTH_SAE:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001182#ifdef CONFIG_MESH
1183 if (status_code == WLAN_STATUS_SUCCESS &&
1184 hapd->conf->mesh & MESH_ENABLED) {
1185 if (sta->wpa_sm == NULL)
1186 sta->wpa_sm =
1187 wpa_auth_sta_init(hapd->wpa_auth,
1188 sta->addr, NULL);
1189 if (sta->wpa_sm == NULL) {
1190 wpa_printf(MSG_DEBUG,
1191 "SAE: Failed to initialize WPA state machine");
1192 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1193 goto fail;
1194 }
1195 }
1196#endif /* CONFIG_MESH */
1197 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1198 status_code);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001199 return;
1200#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001201 }
1202
1203 fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001204 os_free(identity);
1205 os_free(radius_cui);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001206 hostapd_free_psk_list(psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001207
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001208 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1209 auth_transaction + 1, resp, resp_ies, resp_ies_len);
1210}
1211
1212
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001213int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001214{
1215 int i, j = 32, aid;
1216
1217 /* get a unique AID */
1218 if (sta->aid > 0) {
1219 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1220 return 0;
1221 }
1222
1223 for (i = 0; i < AID_WORDS; i++) {
1224 if (hapd->sta_aid[i] == (u32) -1)
1225 continue;
1226 for (j = 0; j < 32; j++) {
1227 if (!(hapd->sta_aid[i] & BIT(j)))
1228 break;
1229 }
1230 if (j < 32)
1231 break;
1232 }
1233 if (j == 32)
1234 return -1;
1235 aid = i * 32 + j + 1;
1236 if (aid > 2007)
1237 return -1;
1238
1239 sta->aid = aid;
1240 hapd->sta_aid[i] |= BIT(j);
1241 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1242 return 0;
1243}
1244
1245
1246static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1247 const u8 *ssid_ie, size_t ssid_ie_len)
1248{
1249 if (ssid_ie == NULL)
1250 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1251
1252 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1253 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001254 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1255 HOSTAPD_LEVEL_INFO,
1256 "Station tried to associate with unknown SSID "
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001257 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001258 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1259 }
1260
1261 return WLAN_STATUS_SUCCESS;
1262}
1263
1264
1265static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1266 const u8 *wmm_ie, size_t wmm_ie_len)
1267{
1268 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001269 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001271 struct wmm_information_element *wmm;
1272
1273 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001274 hostapd_logger(hapd, sta->addr,
1275 HOSTAPD_MODULE_WPA,
1276 HOSTAPD_LEVEL_DEBUG,
1277 "invalid WMM element in association "
1278 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001279 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1280 }
1281
1282 sta->flags |= WLAN_STA_WMM;
1283 wmm = (struct wmm_information_element *) wmm_ie;
1284 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001285 }
1286 return WLAN_STATUS_SUCCESS;
1287}
1288
1289
1290static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1291 struct ieee802_11_elems *elems)
1292{
1293 if (!elems->supp_rates) {
1294 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1295 HOSTAPD_LEVEL_DEBUG,
1296 "No supported rates element in AssocReq");
1297 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1298 }
1299
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001300 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1301 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001302 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1303 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001304 "Invalid supported rates element length %d+%d",
1305 elems->supp_rates_len,
1306 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001307 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1308 }
1309
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001310 sta->supported_rates_len = merge_byte_arrays(
1311 sta->supported_rates, sizeof(sta->supported_rates),
1312 elems->supp_rates, elems->supp_rates_len,
1313 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001314
1315 return WLAN_STATUS_SUCCESS;
1316}
1317
1318
Dmitry Shmidt051af732013-10-22 13:52:46 -07001319static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1320 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1321{
1322#ifdef CONFIG_INTERWORKING
1323 /* check for QoS Map support */
1324 if (ext_capab_ie_len >= 5) {
1325 if (ext_capab_ie[4] & 0x01)
1326 sta->qos_map_enabled = 1;
1327 }
1328#endif /* CONFIG_INTERWORKING */
1329
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001330 if (ext_capab_ie_len > 0)
1331 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1332
Dmitry Shmidt051af732013-10-22 13:52:46 -07001333 return WLAN_STATUS_SUCCESS;
1334}
1335
1336
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
1338 const u8 *ies, size_t ies_len, int reassoc)
1339{
1340 struct ieee802_11_elems elems;
1341 u16 resp;
1342 const u8 *wpa_ie;
1343 size_t wpa_ie_len;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001344 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345
1346 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1347 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1348 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1349 "association request");
1350 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1351 }
1352
1353 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1354 if (resp != WLAN_STATUS_SUCCESS)
1355 return resp;
1356 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
1357 if (resp != WLAN_STATUS_SUCCESS)
1358 return resp;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001359 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
1360 if (resp != WLAN_STATUS_SUCCESS)
1361 return resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001362 resp = copy_supp_rates(hapd, sta, &elems);
1363 if (resp != WLAN_STATUS_SUCCESS)
1364 return resp;
1365#ifdef CONFIG_IEEE80211N
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001366 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001367 if (resp != WLAN_STATUS_SUCCESS)
1368 return resp;
1369 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1370 !(sta->flags & WLAN_STA_HT)) {
1371 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1372 HOSTAPD_LEVEL_INFO, "Station does not support "
1373 "mandatory HT PHY - reject association");
1374 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1375 }
1376#endif /* CONFIG_IEEE80211N */
1377
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001378#ifdef CONFIG_IEEE80211AC
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001379 if (hapd->iconf->ieee80211ac) {
1380 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1381 if (resp != WLAN_STATUS_SUCCESS)
1382 return resp;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08001383
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001384 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1385 if (resp != WLAN_STATUS_SUCCESS)
1386 return resp;
1387 }
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08001388
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001389 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1390 !(sta->flags & WLAN_STA_VHT)) {
1391 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1392 HOSTAPD_LEVEL_INFO, "Station does not support "
1393 "mandatory VHT PHY - reject association");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001394 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001395 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001396
1397 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1398 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1399 elems.vendor_vht_len);
1400 if (resp != WLAN_STATUS_SUCCESS)
1401 return resp;
1402 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001403#endif /* CONFIG_IEEE80211AC */
1404
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001405#ifdef CONFIG_P2P
1406 if (elems.p2p) {
1407 wpabuf_free(sta->p2p_ie);
1408 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1409 P2P_IE_VENDOR_TYPE);
1410 if (sta->p2p_ie)
1411 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1412 } else {
1413 wpabuf_free(sta->p2p_ie);
1414 sta->p2p_ie = NULL;
1415 }
1416#endif /* CONFIG_P2P */
1417
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001418 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1419 wpa_ie = elems.rsn_ie;
1420 wpa_ie_len = elems.rsn_ie_len;
1421 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1422 elems.wpa_ie) {
1423 wpa_ie = elems.wpa_ie;
1424 wpa_ie_len = elems.wpa_ie_len;
1425 } else {
1426 wpa_ie = NULL;
1427 wpa_ie_len = 0;
1428 }
1429
1430#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001431 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001432 if (hapd->conf->wps_state && elems.wps_ie) {
1433 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1434 "Request - assume WPS is used");
1435 sta->flags |= WLAN_STA_WPS;
1436 wpabuf_free(sta->wps_ie);
1437 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1438 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001439 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1440 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1441 sta->flags |= WLAN_STA_WPS2;
1442 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001443 wpa_ie = NULL;
1444 wpa_ie_len = 0;
1445 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1446 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1447 "(Re)Association Request - reject");
1448 return WLAN_STATUS_INVALID_IE;
1449 }
1450 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1451 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1452 "(Re)Association Request - possible WPS use");
1453 sta->flags |= WLAN_STA_MAYBE_WPS;
1454 } else
1455#endif /* CONFIG_WPS */
1456 if (hapd->conf->wpa && wpa_ie == NULL) {
1457 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1458 HOSTAPD_LEVEL_INFO,
1459 "No WPA/RSN IE in association request");
1460 return WLAN_STATUS_INVALID_IE;
1461 }
1462
1463 if (hapd->conf->wpa && wpa_ie) {
1464 int res;
1465 wpa_ie -= 2;
1466 wpa_ie_len += 2;
1467 if (sta->wpa_sm == NULL)
1468 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001469 sta->addr,
1470 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001471 if (sta->wpa_sm == NULL) {
1472 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1473 "state machine");
1474 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1475 }
1476 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1477 wpa_ie, wpa_ie_len,
1478 elems.mdie, elems.mdie_len);
1479 if (res == WPA_INVALID_GROUP)
1480 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1481 else if (res == WPA_INVALID_PAIRWISE)
1482 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1483 else if (res == WPA_INVALID_AKMP)
1484 resp = WLAN_STATUS_AKMP_NOT_VALID;
1485 else if (res == WPA_ALLOC_FAIL)
1486 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1487#ifdef CONFIG_IEEE80211W
1488 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1489 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1490 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1491 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1492#endif /* CONFIG_IEEE80211W */
1493 else if (res == WPA_INVALID_MDIE)
1494 resp = WLAN_STATUS_INVALID_MDIE;
1495 else if (res != WPA_IE_OK)
1496 resp = WLAN_STATUS_INVALID_IE;
1497 if (resp != WLAN_STATUS_SUCCESS)
1498 return resp;
1499#ifdef CONFIG_IEEE80211W
1500 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1501 sta->sa_query_count > 0)
1502 ap_check_sa_query_timeout(hapd, sta);
1503 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1504 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1505 /*
1506 * STA has already been associated with MFP and SA
1507 * Query timeout has not been reached. Reject the
1508 * association attempt temporarily and start SA Query,
1509 * if one is not pending.
1510 */
1511
1512 if (sta->sa_query_count == 0)
1513 ap_sta_start_sa_query(hapd, sta);
1514
1515 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1516 }
1517
1518 if (wpa_auth_uses_mfp(sta->wpa_sm))
1519 sta->flags |= WLAN_STA_MFP;
1520 else
1521 sta->flags &= ~WLAN_STA_MFP;
1522#endif /* CONFIG_IEEE80211W */
1523
1524#ifdef CONFIG_IEEE80211R
1525 if (sta->auth_alg == WLAN_AUTH_FT) {
1526 if (!reassoc) {
1527 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1528 "to use association (not "
1529 "re-association) with FT auth_alg",
1530 MAC2STR(sta->addr));
1531 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1532 }
1533
1534 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1535 ies_len);
1536 if (resp != WLAN_STATUS_SUCCESS)
1537 return resp;
1538 }
1539#endif /* CONFIG_IEEE80211R */
1540
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001541#ifdef CONFIG_SAE
1542 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001543 sta->auth_alg == WLAN_AUTH_OPEN) {
1544 struct rsn_pmksa_cache_entry *sa;
1545 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1546 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1547 wpa_printf(MSG_DEBUG,
1548 "SAE: No PMKSA cache entry found for "
1549 MACSTR, MAC2STR(sta->addr));
1550 return WLAN_STATUS_INVALID_PMKID;
1551 }
1552 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1553 " using PMKSA caching", MAC2STR(sta->addr));
1554 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1555 sta->auth_alg != WLAN_AUTH_SAE &&
1556 !(sta->auth_alg == WLAN_AUTH_FT &&
1557 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001558 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1559 "SAE AKM after non-SAE auth_alg %u",
1560 MAC2STR(sta->addr), sta->auth_alg);
1561 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1562 }
1563#endif /* CONFIG_SAE */
1564
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001566 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001567 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1568 hostapd_logger(hapd, sta->addr,
1569 HOSTAPD_MODULE_IEEE80211,
1570 HOSTAPD_LEVEL_INFO,
1571 "Station tried to use TKIP with HT "
1572 "association");
1573 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1574 }
1575#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001576#ifdef CONFIG_HS20
1577 } else if (hapd->conf->osen) {
1578 if (elems.osen == NULL) {
1579 hostapd_logger(
1580 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1581 HOSTAPD_LEVEL_INFO,
1582 "No HS 2.0 OSEN element in association request");
1583 return WLAN_STATUS_INVALID_IE;
1584 }
1585
1586 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1587 if (sta->wpa_sm == NULL)
1588 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1589 sta->addr, NULL);
1590 if (sta->wpa_sm == NULL) {
1591 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1592 "state machine");
1593 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1594 }
1595 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1596 elems.osen - 2, elems.osen_len + 2) < 0)
1597 return WLAN_STATUS_INVALID_IE;
1598#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001599 } else
1600 wpa_auth_sta_no_wpa(sta->wpa_sm);
1601
1602#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001603 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1604#endif /* CONFIG_P2P */
1605
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001606#ifdef CONFIG_HS20
1607 wpabuf_free(sta->hs20_ie);
1608 if (elems.hs20 && elems.hs20_len > 4) {
1609 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1610 elems.hs20_len - 4);
1611 } else
1612 sta->hs20_ie = NULL;
1613#endif /* CONFIG_HS20 */
1614
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001615#ifdef CONFIG_FST
1616 wpabuf_free(sta->mb_ies);
1617 if (hapd->iface->fst)
1618 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1619 else
1620 sta->mb_ies = NULL;
1621#endif /* CONFIG_FST */
1622
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623 return WLAN_STATUS_SUCCESS;
1624}
1625
1626
1627static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1628 u16 reason_code)
1629{
1630 int send_len;
1631 struct ieee80211_mgmt reply;
1632
1633 os_memset(&reply, 0, sizeof(reply));
1634 reply.frame_control =
1635 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1636 os_memcpy(reply.da, addr, ETH_ALEN);
1637 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1638 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1639
1640 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1641 reply.u.deauth.reason_code = host_to_le16(reason_code);
1642
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001643 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001644 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1645 strerror(errno));
1646}
1647
1648
1649static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1650 u16 status_code, int reassoc, const u8 *ies,
1651 size_t ies_len)
1652{
1653 int send_len;
1654 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1655 struct ieee80211_mgmt *reply;
1656 u8 *p;
1657
1658 os_memset(buf, 0, sizeof(buf));
1659 reply = (struct ieee80211_mgmt *) buf;
1660 reply->frame_control =
1661 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1662 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1663 WLAN_FC_STYPE_ASSOC_RESP));
1664 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1665 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1666 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1667
1668 send_len = IEEE80211_HDRLEN;
1669 send_len += sizeof(reply->u.assoc_resp);
1670 reply->u.assoc_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001671 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001673 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001674 /* Supported rates */
1675 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1676 /* Extended supported rates */
1677 p = hostapd_eid_ext_supp_rates(hapd, p);
1678
1679#ifdef CONFIG_IEEE80211R
1680 if (status_code == WLAN_STATUS_SUCCESS) {
1681 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1682 * Transition Information, RSN, [RIC Response] */
1683 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1684 buf + sizeof(buf) - p,
1685 sta->auth_alg, ies, ies_len);
1686 }
1687#endif /* CONFIG_IEEE80211R */
1688
1689#ifdef CONFIG_IEEE80211W
1690 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1691 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1692#endif /* CONFIG_IEEE80211W */
1693
1694#ifdef CONFIG_IEEE80211N
1695 p = hostapd_eid_ht_capabilities(hapd, p);
1696 p = hostapd_eid_ht_operation(hapd, p);
1697#endif /* CONFIG_IEEE80211N */
1698
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001699#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001700 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1701 p = hostapd_eid_vht_capabilities(hapd, p);
1702 p = hostapd_eid_vht_operation(hapd, p);
1703 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001704#endif /* CONFIG_IEEE80211AC */
1705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001706 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001707 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001708 if (sta->qos_map_enabled)
1709 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001710
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001711#ifdef CONFIG_FST
1712 if (hapd->iface->fst_ies) {
1713 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1714 wpabuf_len(hapd->iface->fst_ies));
1715 p += wpabuf_len(hapd->iface->fst_ies);
1716 }
1717#endif /* CONFIG_FST */
1718
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001719#ifdef CONFIG_IEEE80211AC
1720 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1721 p = hostapd_eid_vendor_vht(hapd, p);
1722#endif /* CONFIG_IEEE80211AC */
1723
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001724 if (sta->flags & WLAN_STA_WMM)
1725 p = hostapd_eid_wmm(hapd, p);
1726
1727#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001728 if ((sta->flags & WLAN_STA_WPS) ||
1729 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001730 struct wpabuf *wps = wps_build_assoc_resp_ie();
1731 if (wps) {
1732 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1733 p += wpabuf_len(wps);
1734 wpabuf_free(wps);
1735 }
1736 }
1737#endif /* CONFIG_WPS */
1738
1739#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001740 if (sta->p2p_ie && hapd->p2p_group) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001741 struct wpabuf *p2p_resp_ie;
1742 enum p2p_status_code status;
1743 switch (status_code) {
1744 case WLAN_STATUS_SUCCESS:
1745 status = P2P_SC_SUCCESS;
1746 break;
1747 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1748 status = P2P_SC_FAIL_LIMIT_REACHED;
1749 break;
1750 default:
1751 status = P2P_SC_FAIL_INVALID_PARAMS;
1752 break;
1753 }
1754 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1755 if (p2p_resp_ie) {
1756 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1757 wpabuf_len(p2p_resp_ie));
1758 p += wpabuf_len(p2p_resp_ie);
1759 wpabuf_free(p2p_resp_ie);
1760 }
1761 }
1762#endif /* CONFIG_P2P */
1763
1764#ifdef CONFIG_P2P_MANAGER
1765 if (hapd->conf->p2p & P2P_MANAGE)
1766 p = hostapd_eid_p2p_manage(hapd, p);
1767#endif /* CONFIG_P2P_MANAGER */
1768
1769 send_len += p - reply->u.assoc_resp.variable;
1770
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001771 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001772 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1773 strerror(errno));
1774}
1775
1776
1777static void handle_assoc(struct hostapd_data *hapd,
1778 const struct ieee80211_mgmt *mgmt, size_t len,
1779 int reassoc)
1780{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001781 u16 capab_info, listen_interval, seq_ctrl, fc;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001782 u16 resp = WLAN_STATUS_SUCCESS;
1783 const u8 *pos;
1784 int left, i;
1785 struct sta_info *sta;
1786
1787 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1788 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001789 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1790 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001791 return;
1792 }
1793
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001794#ifdef CONFIG_TESTING_OPTIONS
1795 if (reassoc) {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001796 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001797 drand48() < hapd->iconf->ignore_reassoc_probability) {
1798 wpa_printf(MSG_INFO,
1799 "TESTING: ignoring reassoc request from "
1800 MACSTR, MAC2STR(mgmt->sa));
1801 return;
1802 }
1803 } else {
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001804 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001805 drand48() < hapd->iconf->ignore_assoc_probability) {
1806 wpa_printf(MSG_INFO,
1807 "TESTING: ignoring assoc request from "
1808 MACSTR, MAC2STR(mgmt->sa));
1809 return;
1810 }
1811 }
1812#endif /* CONFIG_TESTING_OPTIONS */
1813
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001814 fc = le_to_host16(mgmt->frame_control);
1815 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
1816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817 if (reassoc) {
1818 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1819 listen_interval = le_to_host16(
1820 mgmt->u.reassoc_req.listen_interval);
1821 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1822 " capab_info=0x%02x listen_interval=%d current_ap="
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001823 MACSTR " seq_ctrl=0x%x%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824 MAC2STR(mgmt->sa), capab_info, listen_interval,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001825 MAC2STR(mgmt->u.reassoc_req.current_ap),
1826 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1828 pos = mgmt->u.reassoc_req.variable;
1829 } else {
1830 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1831 listen_interval = le_to_host16(
1832 mgmt->u.assoc_req.listen_interval);
1833 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001834 " capab_info=0x%02x listen_interval=%d "
1835 "seq_ctrl=0x%x%s",
1836 MAC2STR(mgmt->sa), capab_info, listen_interval,
1837 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1839 pos = mgmt->u.assoc_req.variable;
1840 }
1841
1842 sta = ap_get_sta(hapd, mgmt->sa);
1843#ifdef CONFIG_IEEE80211R
1844 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1845 (sta->flags & WLAN_STA_AUTH) == 0) {
1846 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1847 "prior to authentication since it is using "
1848 "over-the-DS FT", MAC2STR(mgmt->sa));
1849 } else
1850#endif /* CONFIG_IEEE80211R */
1851 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1852 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1853 HOSTAPD_LEVEL_INFO, "Station tried to "
1854 "associate before authentication "
1855 "(aid=%d flags=0x%x)",
1856 sta ? sta->aid : -1,
1857 sta ? sta->flags : 0);
1858 send_deauth(hapd, mgmt->sa,
1859 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1860 return;
1861 }
1862
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001863 if ((fc & WLAN_FC_RETRY) &&
1864 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1865 sta->last_seq_ctrl == seq_ctrl &&
1866 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1867 WLAN_FC_STYPE_ASSOC_REQ) {
1868 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1869 HOSTAPD_LEVEL_DEBUG,
1870 "Drop repeated association frame seq_ctrl=0x%x",
1871 seq_ctrl);
1872 return;
1873 }
1874 sta->last_seq_ctrl = seq_ctrl;
1875 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
1876 WLAN_FC_STYPE_ASSOC_REQ;
1877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878 if (hapd->tkip_countermeasures) {
1879 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1880 goto fail;
1881 }
1882
1883 if (listen_interval > hapd->conf->max_listen_interval) {
1884 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1885 HOSTAPD_LEVEL_DEBUG,
1886 "Too large Listen Interval (%d)",
1887 listen_interval);
1888 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1889 goto fail;
1890 }
1891
1892 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1893 * is used */
1894 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1895 if (resp != WLAN_STATUS_SUCCESS)
1896 goto fail;
1897
1898 if (hostapd_get_aid(hapd, sta) < 0) {
1899 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1900 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1901 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1902 goto fail;
1903 }
1904
1905 sta->capability = capab_info;
1906 sta->listen_interval = listen_interval;
1907
1908 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1909 sta->flags |= WLAN_STA_NONERP;
1910 for (i = 0; i < sta->supported_rates_len; i++) {
1911 if ((sta->supported_rates[i] & 0x7f) > 22) {
1912 sta->flags &= ~WLAN_STA_NONERP;
1913 break;
1914 }
1915 }
1916 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1917 sta->nonerp_set = 1;
1918 hapd->iface->num_sta_non_erp++;
1919 if (hapd->iface->num_sta_non_erp == 1)
1920 ieee802_11_set_beacons(hapd->iface);
1921 }
1922
1923 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1924 !sta->no_short_slot_time_set) {
1925 sta->no_short_slot_time_set = 1;
1926 hapd->iface->num_sta_no_short_slot_time++;
1927 if (hapd->iface->current_mode->mode ==
1928 HOSTAPD_MODE_IEEE80211G &&
1929 hapd->iface->num_sta_no_short_slot_time == 1)
1930 ieee802_11_set_beacons(hapd->iface);
1931 }
1932
1933 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1934 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1935 else
1936 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1937
1938 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1939 !sta->no_short_preamble_set) {
1940 sta->no_short_preamble_set = 1;
1941 hapd->iface->num_sta_no_short_preamble++;
1942 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1943 && hapd->iface->num_sta_no_short_preamble == 1)
1944 ieee802_11_set_beacons(hapd->iface);
1945 }
1946
1947#ifdef CONFIG_IEEE80211N
1948 update_ht_state(hapd, sta);
1949#endif /* CONFIG_IEEE80211N */
1950
1951 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1952 HOSTAPD_LEVEL_DEBUG,
1953 "association OK (aid %d)", sta->aid);
1954 /* Station will be marked associated, after it acknowledges AssocResp
1955 */
1956 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1957
1958#ifdef CONFIG_IEEE80211W
1959 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1960 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1961 "SA Query procedure", reassoc ? "re" : "");
1962 /* TODO: Send a protected Disassociate frame to the STA using
1963 * the old key and Reason Code "Previous Authentication no
1964 * longer valid". Make sure this is only sent protected since
1965 * unprotected frame would be received by the STA that is now
1966 * trying to associate.
1967 */
1968 }
1969#endif /* CONFIG_IEEE80211W */
1970
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001971 /* Make sure that the previously registered inactivity timer will not
1972 * remove the STA immediately. */
1973 sta->timeout_next = STA_NULLFUNC;
1974
1975 fail:
1976 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1977}
1978
1979
1980static void handle_disassoc(struct hostapd_data *hapd,
1981 const struct ieee80211_mgmt *mgmt, size_t len)
1982{
1983 struct sta_info *sta;
1984
1985 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001986 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1987 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001988 return;
1989 }
1990
1991 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1992 MAC2STR(mgmt->sa),
1993 le_to_host16(mgmt->u.disassoc.reason_code));
1994
1995 sta = ap_get_sta(hapd, mgmt->sa);
1996 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001997 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1998 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001999 return;
2000 }
2001
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002002 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002003 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002004 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002005 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2006 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2007 HOSTAPD_LEVEL_INFO, "disassociated");
2008 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2009 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2010 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2011 * authenticated. */
2012 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -08002013 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002014 if (sta->ipaddr)
2015 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2016 ap_sta_ip6addr_del(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002017 hostapd_drv_sta_remove(hapd, sta->addr);
2018
2019 if (sta->timeout_next == STA_NULLFUNC ||
2020 sta->timeout_next == STA_DISASSOC) {
2021 sta->timeout_next = STA_DEAUTH;
2022 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2023 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2024 hapd, sta);
2025 }
2026
2027 mlme_disassociate_indication(
2028 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2029}
2030
2031
2032static void handle_deauth(struct hostapd_data *hapd,
2033 const struct ieee80211_mgmt *mgmt, size_t len)
2034{
2035 struct sta_info *sta;
2036
2037 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002038 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2039 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002040 return;
2041 }
2042
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002043 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002044 " reason_code=%d",
2045 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
2046
2047 sta = ap_get_sta(hapd, mgmt->sa);
2048 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002049 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2050 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002051 MAC2STR(mgmt->sa));
2052 return;
2053 }
2054
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002055 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002056 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002057 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2058 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002059 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2060 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2061 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2062 mlme_deauthenticate_indication(
2063 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2064 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2065 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2066 ap_free_sta(hapd, sta);
2067}
2068
2069
2070static void handle_beacon(struct hostapd_data *hapd,
2071 const struct ieee80211_mgmt *mgmt, size_t len,
2072 struct hostapd_frame_info *fi)
2073{
2074 struct ieee802_11_elems elems;
2075
2076 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002077 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2078 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002079 return;
2080 }
2081
2082 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
2083 len - (IEEE80211_HDRLEN +
2084 sizeof(mgmt->u.beacon)), &elems,
2085 0);
2086
2087 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2088}
2089
2090
2091#ifdef CONFIG_IEEE80211W
2092
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002093static int hostapd_sa_query_action(struct hostapd_data *hapd,
2094 const struct ieee80211_mgmt *mgmt,
2095 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002096{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002097 const u8 *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002098
2099 end = mgmt->u.action.u.sa_query_resp.trans_id +
2100 WLAN_SA_QUERY_TR_ID_LEN;
2101 if (((u8 *) mgmt) + len < end) {
2102 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
2103 "frame (len=%lu)", (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002104 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002105 }
2106
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002107 ieee802_11_sa_query_action(hapd, mgmt->sa,
2108 mgmt->u.action.u.sa_query_resp.action,
2109 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002110 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002111}
2112
2113
2114static int robust_action_frame(u8 category)
2115{
2116 return category != WLAN_ACTION_PUBLIC &&
2117 category != WLAN_ACTION_HT;
2118}
2119#endif /* CONFIG_IEEE80211W */
2120
2121
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002122static int handle_action(struct hostapd_data *hapd,
2123 const struct ieee80211_mgmt *mgmt, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002124{
2125 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002126 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002127
2128 if (len < IEEE80211_HDRLEN + 1) {
2129 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2130 HOSTAPD_LEVEL_DEBUG,
2131 "handle_action - too short payload (len=%lu)",
2132 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002133 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002134 }
2135
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002136 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2137 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2138 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2139 "frame (category=%u) from unassociated STA " MACSTR,
2140 MAC2STR(mgmt->sa), mgmt->u.action.category);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002141 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002142 }
2143
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002144#ifdef CONFIG_IEEE80211W
2145 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08002146 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2147 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002148 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2149 HOSTAPD_LEVEL_DEBUG,
2150 "Dropped unprotected Robust Action frame from "
2151 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002152 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002153 }
2154#endif /* CONFIG_IEEE80211W */
2155
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002156 if (sta) {
2157 u16 fc = le_to_host16(mgmt->frame_control);
2158 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2159
2160 if ((fc & WLAN_FC_RETRY) &&
2161 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2162 sta->last_seq_ctrl == seq_ctrl &&
2163 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2164 hostapd_logger(hapd, sta->addr,
2165 HOSTAPD_MODULE_IEEE80211,
2166 HOSTAPD_LEVEL_DEBUG,
2167 "Drop repeated action frame seq_ctrl=0x%x",
2168 seq_ctrl);
2169 return 1;
2170 }
2171
2172 sta->last_seq_ctrl = seq_ctrl;
2173 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2174 }
2175
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002176 switch (mgmt->u.action.category) {
2177#ifdef CONFIG_IEEE80211R
2178 case WLAN_ACTION_FT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002179 if (!sta ||
2180 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002181 len - IEEE80211_HDRLEN))
2182 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002183 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002184#endif /* CONFIG_IEEE80211R */
2185 case WLAN_ACTION_WMM:
2186 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002187 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002188#ifdef CONFIG_IEEE80211W
2189 case WLAN_ACTION_SA_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002190 return hostapd_sa_query_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002191#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002192#ifdef CONFIG_WNM
2193 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002194 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2195 return 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002196#endif /* CONFIG_WNM */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002197#ifdef CONFIG_FST
2198 case WLAN_ACTION_FST:
2199 if (hapd->iface->fst)
2200 fst_rx_action(hapd->iface->fst, mgmt, len);
2201 else
2202 wpa_printf(MSG_DEBUG,
2203 "FST: Ignore FST Action frame - no FST attached");
2204 return 1;
2205#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002206 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08002207 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002208#ifdef CONFIG_IEEE80211N
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07002209 if (len >= IEEE80211_HDRLEN + 2 &&
2210 mgmt->u.action.u.public_action.action ==
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002211 WLAN_PA_20_40_BSS_COEX) {
2212 wpa_printf(MSG_DEBUG,
2213 "HT20/40 coex mgmt frame received from STA "
2214 MACSTR, MAC2STR(mgmt->sa));
2215 hostapd_2040_coex_action(hapd, mgmt, len);
2216 }
2217#endif /* CONFIG_IEEE80211N */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002218 if (hapd->public_action_cb) {
2219 hapd->public_action_cb(hapd->public_action_cb_ctx,
2220 (u8 *) mgmt, len,
2221 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002222 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002223 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002224 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002225 (u8 *) mgmt, len,
2226 hapd->iface->freq);
2227 }
2228 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002229 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002230 break;
2231 case WLAN_ACTION_VENDOR_SPECIFIC:
2232 if (hapd->vendor_action_cb) {
2233 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2234 (u8 *) mgmt, len,
2235 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002236 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002237 }
2238 break;
2239 }
2240
2241 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2242 HOSTAPD_LEVEL_DEBUG,
2243 "handle_action - unknown action category %d or invalid "
2244 "frame",
2245 mgmt->u.action.category);
2246 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2247 !(mgmt->sa[0] & 0x01)) {
2248 struct ieee80211_mgmt *resp;
2249
2250 /*
2251 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2252 * Return the Action frame to the source without change
2253 * except that MSB of the Category set to 1.
2254 */
2255 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2256 "frame back to sender");
2257 resp = os_malloc(len);
2258 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002259 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002260 os_memcpy(resp, mgmt, len);
2261 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2262 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2263 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2264 resp->u.action.category |= 0x80;
2265
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002266 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2267 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2268 "Action frame");
2269 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002270 os_free(resp);
2271 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002272
2273 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274}
2275
2276
2277/**
2278 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2279 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2280 * sent to)
2281 * @buf: management frame data (starting from IEEE 802.11 header)
2282 * @len: length of frame data in octets
2283 * @fi: meta data about received frame (signal level, etc.)
2284 *
2285 * Process all incoming IEEE 802.11 management frames. This will be called for
2286 * each frame received from the kernel driver through wlan#ap interface. In
2287 * addition, it can be called to re-inserted pending frames (e.g., when using
2288 * external RADIUS server as an MAC ACL).
2289 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002290int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2291 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002292{
2293 struct ieee80211_mgmt *mgmt;
2294 int broadcast;
2295 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002296 int ret = 0;
2297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002298 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002299 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002300
2301 mgmt = (struct ieee80211_mgmt *) buf;
2302 fc = le_to_host16(mgmt->frame_control);
2303 stype = WLAN_FC_GET_STYPE(fc);
2304
2305 if (stype == WLAN_FC_STYPE_BEACON) {
2306 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002307 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 }
2309
2310 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2311 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2312 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2313
2314 if (!broadcast &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002315#ifdef CONFIG_P2P
2316 /* Invitation responses can be sent with the peer MAC as BSSID */
2317 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2318 stype == WLAN_FC_STYPE_ACTION) &&
2319#endif /* CONFIG_P2P */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002320#ifdef CONFIG_MESH
2321 !(hapd->conf->mesh & MESH_ENABLED) &&
2322#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002323 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002324 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2325 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002326 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002327 }
2328
2329
2330 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002331 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002332 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002333 }
2334
2335 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2336 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2337 HOSTAPD_LEVEL_DEBUG,
2338 "MGMT: DA=" MACSTR " not our address",
2339 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002340 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002341 }
2342
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002343 if (hapd->iconf->track_sta_max_num)
2344 sta_track_add(hapd->iface, mgmt->sa);
2345
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002346 switch (stype) {
2347 case WLAN_FC_STYPE_AUTH:
2348 wpa_printf(MSG_DEBUG, "mgmt::auth");
2349 handle_auth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002350 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002351 break;
2352 case WLAN_FC_STYPE_ASSOC_REQ:
2353 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2354 handle_assoc(hapd, mgmt, len, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002355 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002356 break;
2357 case WLAN_FC_STYPE_REASSOC_REQ:
2358 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2359 handle_assoc(hapd, mgmt, len, 1);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002360 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002361 break;
2362 case WLAN_FC_STYPE_DISASSOC:
2363 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2364 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002365 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002366 break;
2367 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002368 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002369 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002370 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002371 break;
2372 case WLAN_FC_STYPE_ACTION:
2373 wpa_printf(MSG_DEBUG, "mgmt::action");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002374 ret = handle_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002375 break;
2376 default:
2377 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2378 HOSTAPD_LEVEL_DEBUG,
2379 "unknown mgmt frame subtype %d", stype);
2380 break;
2381 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002382
2383 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384}
2385
2386
2387static void handle_auth_cb(struct hostapd_data *hapd,
2388 const struct ieee80211_mgmt *mgmt,
2389 size_t len, int ok)
2390{
2391 u16 auth_alg, auth_transaction, status_code;
2392 struct sta_info *sta;
2393
2394 if (!ok) {
2395 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2396 HOSTAPD_LEVEL_NOTICE,
2397 "did not acknowledge authentication response");
2398 return;
2399 }
2400
2401 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002402 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2403 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002404 return;
2405 }
2406
2407 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2408 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2409 status_code = le_to_host16(mgmt->u.auth.status_code);
2410
2411 sta = ap_get_sta(hapd, mgmt->da);
2412 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002413 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2414 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002415 return;
2416 }
2417
2418 if (status_code == WLAN_STATUS_SUCCESS &&
2419 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2420 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2421 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2422 HOSTAPD_LEVEL_INFO, "authenticated");
2423 sta->flags |= WLAN_STA_AUTH;
2424 }
2425}
2426
2427
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002428static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2429 struct sta_info *sta,
2430 char *ifname_wds)
2431{
2432 int i;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002433 struct hostapd_ssid *ssid = &hapd->conf->ssid;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002434
2435 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2436 return;
2437
2438 for (i = 0; i < 4; i++) {
2439 if (ssid->wep.key[i] &&
2440 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2441 i == ssid->wep.idx, NULL, 0,
2442 ssid->wep.key[i], ssid->wep.len[i])) {
2443 wpa_printf(MSG_WARNING,
2444 "Could not set WEP keys for WDS interface; %s",
2445 ifname_wds);
2446 break;
2447 }
2448 }
2449}
2450
2451
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002452static void handle_assoc_cb(struct hostapd_data *hapd,
2453 const struct ieee80211_mgmt *mgmt,
2454 size_t len, int reassoc, int ok)
2455{
2456 u16 status;
2457 struct sta_info *sta;
2458 int new_assoc = 1;
2459 struct ieee80211_ht_capabilities ht_cap;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002460 struct ieee80211_vht_capabilities vht_cap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002461
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002462 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2463 sizeof(mgmt->u.assoc_resp))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002464 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2465 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002466 return;
2467 }
2468
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002469 sta = ap_get_sta(hapd, mgmt->da);
2470 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002471 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2472 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002473 return;
2474 }
2475
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002476 if (!ok) {
2477 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2478 HOSTAPD_LEVEL_DEBUG,
2479 "did not acknowledge association response");
2480 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
2481 return;
2482 }
2483
2484 if (reassoc)
2485 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2486 else
2487 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2488
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002489 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002490 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002491
2492 /* Stop previous accounting session, if one is started, and allocate
2493 * new session id for the new session. */
2494 accounting_sta_stop(hapd, sta);
2495
2496 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2497 HOSTAPD_LEVEL_INFO,
2498 "associated (aid %d)",
2499 sta->aid);
2500
2501 if (sta->flags & WLAN_STA_ASSOC)
2502 new_assoc = 0;
2503 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002504 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002505 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002506 sta->auth_alg == WLAN_AUTH_FT) {
2507 /*
2508 * Open, static WEP, or FT protocol; no separate authorization
2509 * step.
2510 */
2511 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002512 }
2513
2514 if (reassoc)
2515 mlme_reassociate_indication(hapd, sta);
2516 else
2517 mlme_associate_indication(hapd, sta);
2518
2519#ifdef CONFIG_IEEE80211W
2520 sta->sa_query_timed_out = 0;
2521#endif /* CONFIG_IEEE80211W */
2522
2523 /*
2524 * Remove the STA entry in order to make sure the STA PS state gets
2525 * cleared and configuration gets updated in case of reassociation back
2526 * to the same AP.
2527 */
2528 hostapd_drv_sta_remove(hapd, sta->addr);
2529
2530#ifdef CONFIG_IEEE80211N
2531 if (sta->flags & WLAN_STA_HT)
2532 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
2533#endif /* CONFIG_IEEE80211N */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002534#ifdef CONFIG_IEEE80211AC
2535 if (sta->flags & WLAN_STA_VHT)
2536 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
2537#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002538
2539 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
2540 sta->supported_rates, sta->supported_rates_len,
2541 sta->listen_interval,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002542 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002543 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08002544 sta->flags, sta->qosinfo, sta->vht_opmode)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002545 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2546 HOSTAPD_LEVEL_NOTICE,
2547 "Could not add STA to kernel driver");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002548
2549 ap_sta_disconnect(hapd, sta, sta->addr,
2550 WLAN_REASON_DISASSOC_AP_BUSY);
2551
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002552 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002553 }
2554
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002555 if (sta->flags & WLAN_STA_WDS) {
2556 int ret;
2557 char ifname_wds[IFNAMSIZ + 1];
2558
2559 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2560 sta->aid, 1);
2561 if (!ret)
2562 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2563 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002564
2565 if (sta->eapol_sm == NULL) {
2566 /*
2567 * This STA does not use RADIUS server for EAP authentication,
2568 * so bind it to the selected VLAN interface now, since the
2569 * interface selection is not going to change anymore.
2570 */
Dmitry Shmidt83474442015-04-15 13:47:09 -07002571 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002572 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002573 } else if (sta->vlan_id) {
2574 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
Dmitry Shmidt83474442015-04-15 13:47:09 -07002575 if (ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002576 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002577 }
2578
2579 hostapd_set_sta_flags(hapd, sta);
2580
2581 if (sta->auth_alg == WLAN_AUTH_FT)
2582 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2583 else
2584 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2585 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2586
2587 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002588}
2589
2590
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002591static void handle_deauth_cb(struct hostapd_data *hapd,
2592 const struct ieee80211_mgmt *mgmt,
2593 size_t len, int ok)
2594{
2595 struct sta_info *sta;
2596 if (mgmt->da[0] & 0x01)
2597 return;
2598 sta = ap_get_sta(hapd, mgmt->da);
2599 if (!sta) {
2600 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2601 " not found", MAC2STR(mgmt->da));
2602 return;
2603 }
2604 if (ok)
2605 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2606 MAC2STR(sta->addr));
2607 else
2608 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2609 "deauth", MAC2STR(sta->addr));
2610
2611 ap_sta_deauth_cb(hapd, sta);
2612}
2613
2614
2615static void handle_disassoc_cb(struct hostapd_data *hapd,
2616 const struct ieee80211_mgmt *mgmt,
2617 size_t len, int ok)
2618{
2619 struct sta_info *sta;
2620 if (mgmt->da[0] & 0x01)
2621 return;
2622 sta = ap_get_sta(hapd, mgmt->da);
2623 if (!sta) {
2624 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2625 " not found", MAC2STR(mgmt->da));
2626 return;
2627 }
2628 if (ok)
2629 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2630 MAC2STR(sta->addr));
2631 else
2632 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2633 "disassoc", MAC2STR(sta->addr));
2634
2635 ap_sta_disassoc_cb(hapd, sta);
2636}
2637
2638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002639/**
2640 * ieee802_11_mgmt_cb - Process management frame TX status callback
2641 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2642 * was sent from)
2643 * @buf: management frame data (starting from IEEE 802.11 header)
2644 * @len: length of frame data in octets
2645 * @stype: management frame subtype from frame control field
2646 * @ok: Whether the frame was ACK'ed
2647 */
2648void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2649 u16 stype, int ok)
2650{
2651 const struct ieee80211_mgmt *mgmt;
2652 mgmt = (const struct ieee80211_mgmt *) buf;
2653
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002654#ifdef CONFIG_TESTING_OPTIONS
2655 if (hapd->ext_mgmt_frame_handling) {
2656 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2657 stype, ok);
2658 return;
2659 }
2660#endif /* CONFIG_TESTING_OPTIONS */
2661
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002662 switch (stype) {
2663 case WLAN_FC_STYPE_AUTH:
2664 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2665 handle_auth_cb(hapd, mgmt, len, ok);
2666 break;
2667 case WLAN_FC_STYPE_ASSOC_RESP:
2668 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2669 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2670 break;
2671 case WLAN_FC_STYPE_REASSOC_RESP:
2672 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2673 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2674 break;
2675 case WLAN_FC_STYPE_PROBE_RESP:
2676 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2677 break;
2678 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002679 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2680 handle_deauth_cb(hapd, mgmt, len, ok);
2681 break;
2682 case WLAN_FC_STYPE_DISASSOC:
2683 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2684 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002685 break;
2686 case WLAN_FC_STYPE_ACTION:
2687 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2688 break;
2689 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002690 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002691 break;
2692 }
2693}
2694
2695
2696int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2697{
2698 /* TODO */
2699 return 0;
2700}
2701
2702
2703int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2704 char *buf, size_t buflen)
2705{
2706 /* TODO */
2707 return 0;
2708}
2709
2710
2711void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2712 const u8 *buf, size_t len, int ack)
2713{
2714 struct sta_info *sta;
2715 struct hostapd_iface *iface = hapd->iface;
2716
2717 sta = ap_get_sta(hapd, addr);
2718 if (sta == NULL && iface->num_bss > 1) {
2719 size_t j;
2720 for (j = 0; j < iface->num_bss; j++) {
2721 hapd = iface->bss[j];
2722 sta = ap_get_sta(hapd, addr);
2723 if (sta)
2724 break;
2725 }
2726 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002727 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002728 return;
2729 if (sta->flags & WLAN_STA_PENDING_POLL) {
2730 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2731 "activity poll", MAC2STR(sta->addr),
2732 ack ? "ACKed" : "did not ACK");
2733 if (ack)
2734 sta->flags &= ~WLAN_STA_PENDING_POLL;
2735 }
2736
2737 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2738}
2739
2740
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002741void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2742 const u8 *data, size_t len, int ack)
2743{
2744 struct sta_info *sta;
2745 struct hostapd_iface *iface = hapd->iface;
2746
2747 sta = ap_get_sta(hapd, dst);
2748 if (sta == NULL && iface->num_bss > 1) {
2749 size_t j;
2750 for (j = 0; j < iface->num_bss; j++) {
2751 hapd = iface->bss[j];
2752 sta = ap_get_sta(hapd, dst);
2753 if (sta)
2754 break;
2755 }
2756 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002757 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2758 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2759 MACSTR " that is not currently associated",
2760 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002761 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002762 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002763
2764 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2765}
2766
2767
2768void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2769{
2770 struct sta_info *sta;
2771 struct hostapd_iface *iface = hapd->iface;
2772
2773 sta = ap_get_sta(hapd, addr);
2774 if (sta == NULL && iface->num_bss > 1) {
2775 size_t j;
2776 for (j = 0; j < iface->num_bss; j++) {
2777 hapd = iface->bss[j];
2778 sta = ap_get_sta(hapd, addr);
2779 if (sta)
2780 break;
2781 }
2782 }
2783 if (sta == NULL)
2784 return;
2785 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2786 return;
2787
2788 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2789 "activity poll", MAC2STR(sta->addr));
2790 sta->flags &= ~WLAN_STA_PENDING_POLL;
2791}
2792
2793
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002794void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2795 int wds)
2796{
2797 struct sta_info *sta;
2798
2799 sta = ap_get_sta(hapd, src);
2800 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002801 if (!hapd->conf->wds_sta)
2802 return;
2803
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002804 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002805 int ret;
2806 char ifname_wds[IFNAMSIZ + 1];
2807
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002808 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2809 "STA " MACSTR " (aid %u)",
2810 MAC2STR(sta->addr), sta->aid);
2811 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002812 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2813 sta->addr, sta->aid, 1);
2814 if (!ret)
2815 hostapd_set_wds_encryption(hapd, sta,
2816 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002817 }
2818 return;
2819 }
2820
2821 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2822 MACSTR, MAC2STR(src));
2823 if (src[0] & 0x01) {
2824 /* Broadcast bit set in SA?! Ignore the frame silently. */
2825 return;
2826 }
2827
2828 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2829 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2830 "already been sent, but no TX status yet known - "
2831 "ignore Class 3 frame issue with " MACSTR,
2832 MAC2STR(src));
2833 return;
2834 }
2835
2836 if (sta && (sta->flags & WLAN_STA_AUTH))
2837 hostapd_drv_sta_disassoc(
2838 hapd, src,
2839 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2840 else
2841 hostapd_drv_sta_deauth(
2842 hapd, src,
2843 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2844}
2845
2846
2847#endif /* CONFIG_NATIVE_WINDOWS */