blob: 79235dfd086756e9bfce4cf19657384e83440e01 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.11 Management
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003 * Copyright (c) 2002-2012, 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 "drivers/driver.h"
19#include "common/ieee802_11_defs.h"
20#include "common/ieee802_11_common.h"
21#include "common/wpa_ctrl.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080022#include "common/sae.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023#include "radius/radius.h"
24#include "radius/radius_client.h"
25#include "p2p/p2p.h"
26#include "wps/wps.h"
27#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"
33#include "wmm.h"
34#include "ap_list.h"
35#include "accounting.h"
36#include "ap_config.h"
37#include "ap_mlme.h"
38#include "p2p_hostapd.h"
39#include "ap_drv_ops.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080040#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "ieee802_11.h"
42
43
44u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
45{
46 u8 *pos = eid;
47 int i, num, count;
48
49 if (hapd->iface->current_rates == NULL)
50 return eid;
51
52 *pos++ = WLAN_EID_SUPP_RATES;
53 num = hapd->iface->num_rates;
54 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
55 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080056 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
57 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070058 if (num > 8) {
59 /* rest of the rates are encoded in Extended supported
60 * rates element */
61 num = 8;
62 }
63
64 *pos++ = num;
65 count = 0;
66 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
67 i++) {
68 count++;
69 *pos = hapd->iface->current_rates[i].rate / 5;
70 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
71 *pos |= 0x80;
72 pos++;
73 }
74
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080075 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
76 count++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070077 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080078 }
79
80 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
81 count++;
82 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
83 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084
85 return pos;
86}
87
88
89u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
90{
91 u8 *pos = eid;
92 int i, num, count;
93
94 if (hapd->iface->current_rates == NULL)
95 return eid;
96
97 num = hapd->iface->num_rates;
98 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
99 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800100 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
101 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700102 if (num <= 8)
103 return eid;
104 num -= 8;
105
106 *pos++ = WLAN_EID_EXT_SUPP_RATES;
107 *pos++ = num;
108 count = 0;
109 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
110 i++) {
111 count++;
112 if (count <= 8)
113 continue; /* already in SuppRates IE */
114 *pos = hapd->iface->current_rates[i].rate / 5;
115 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
116 *pos |= 0x80;
117 pos++;
118 }
119
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800120 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
121 count++;
122 if (count > 8)
123 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
124 }
125
126 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
127 count++;
128 if (count > 8)
129 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
130 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700131
132 return pos;
133}
134
135
136u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
137 int probe)
138{
139 int capab = WLAN_CAPABILITY_ESS;
140 int privacy;
141
142 if (hapd->iface->num_sta_no_short_preamble == 0 &&
143 hapd->iconf->preamble == SHORT_PREAMBLE)
144 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
145
146 privacy = hapd->conf->ssid.wep.keys_set;
147
148 if (hapd->conf->ieee802_1x &&
149 (hapd->conf->default_wep_key_len ||
150 hapd->conf->individual_wep_key_len))
151 privacy = 1;
152
153 if (hapd->conf->wpa)
154 privacy = 1;
155
156 if (sta) {
157 int policy, def_klen;
158 if (probe && sta->ssid_probe) {
159 policy = sta->ssid_probe->security_policy;
160 def_klen = sta->ssid_probe->wep.default_len;
161 } else {
162 policy = sta->ssid->security_policy;
163 def_klen = sta->ssid->wep.default_len;
164 }
165 privacy = policy != SECURITY_PLAINTEXT;
166 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
167 privacy = 0;
168 }
169
170 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
178 return capab;
179}
180
181
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700182void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
183{
184 int i;
185 if (len > HOSTAPD_MAX_SSID_LEN)
186 len = HOSTAPD_MAX_SSID_LEN;
187 for (i = 0; i < len; i++) {
188 if (ssid[i] >= 32 && ssid[i] < 127)
189 buf[i] = ssid[i];
190 else
191 buf[i] = '.';
192 }
193 buf[len] = '\0';
194}
195
196
197static 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 ||
231 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
232 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
233 HOSTAPD_LEVEL_INFO,
234 "shared key authentication - invalid "
235 "challenge-response");
236 return WLAN_STATUS_CHALLENGE_FAIL;
237 }
238
239 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
240 HOSTAPD_LEVEL_DEBUG,
241 "authentication OK (shared key)");
242#ifdef IEEE80211_REQUIRE_AUTH_ACK
243 /* Station will be marked authenticated if it ACKs the
244 * authentication reply. */
245#else
246 sta->flags |= WLAN_STA_AUTH;
247 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
248#endif
249 os_free(sta->challenge);
250 sta->challenge = NULL;
251
252 return 0;
253}
254
255
256static void send_auth_reply(struct hostapd_data *hapd,
257 const u8 *dst, const u8 *bssid,
258 u16 auth_alg, u16 auth_transaction, u16 resp,
259 const u8 *ies, size_t ies_len)
260{
261 struct ieee80211_mgmt *reply;
262 u8 *buf;
263 size_t rlen;
264
265 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
266 buf = os_zalloc(rlen);
267 if (buf == NULL)
268 return;
269
270 reply = (struct ieee80211_mgmt *) buf;
271 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
272 WLAN_FC_STYPE_AUTH);
273 os_memcpy(reply->da, dst, ETH_ALEN);
274 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
275 os_memcpy(reply->bssid, bssid, ETH_ALEN);
276
277 reply->u.auth.auth_alg = host_to_le16(auth_alg);
278 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
279 reply->u.auth.status_code = host_to_le16(resp);
280
281 if (ies && ies_len)
282 os_memcpy(reply->u.auth.variable, ies, ies_len);
283
284 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
285 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
286 MAC2STR(dst), auth_alg, auth_transaction,
287 resp, (unsigned long) ies_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800288 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 perror("send_auth_reply: send");
290
291 os_free(buf);
292}
293
294
295#ifdef CONFIG_IEEE80211R
296static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
297 u16 auth_transaction, u16 status,
298 const u8 *ies, size_t ies_len)
299{
300 struct hostapd_data *hapd = ctx;
301 struct sta_info *sta;
302
303 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
304 status, ies, ies_len);
305
306 if (status != WLAN_STATUS_SUCCESS)
307 return;
308
309 sta = ap_get_sta(hapd, dst);
310 if (sta == NULL)
311 return;
312
313 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
314 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
315 sta->flags |= WLAN_STA_AUTH;
316 mlme_authenticate_indication(hapd, sta);
317}
318#endif /* CONFIG_IEEE80211R */
319
320
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800321#ifdef CONFIG_SAE
322
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800323static struct wpabuf * auth_process_sae_commit(struct hostapd_data *hapd,
324 struct sta_info *sta)
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
333 if (sae_prepare_commit(hapd->own_addr, sta->addr,
334 (u8 *) hapd->conf->ssid.wpa_passphrase,
335 os_strlen(hapd->conf->ssid.wpa_passphrase),
336 sta->sae) < 0) {
337 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
338 return NULL;
339 }
340
341 if (sae_process_commit(sta->sae) < 0) {
342 wpa_printf(MSG_DEBUG, "SAE: Failed to process peer commit");
343 return NULL;
344 }
345
346 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800347 if (buf == NULL)
348 return NULL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800349 sae_write_commit(sta->sae, buf, NULL);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800350
351 return buf;
352}
353
354
355static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
356 struct sta_info *sta)
357{
358 struct wpabuf *buf;
359
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800360 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800361 if (buf == NULL)
362 return NULL;
363
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800364 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800365
366 return buf;
367}
368
369
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800370static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800371{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800372 struct sta_info *sta;
373 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800374
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800375 if (hapd->conf->sae_anti_clogging_threshold == 0)
376 return 1;
377
378 for (sta = hapd->sta_list; sta; sta = sta->next) {
379 if (!sta->sae)
380 continue;
381 if (sta->sae->state != SAE_COMMITTED &&
382 sta->sae->state != SAE_CONFIRMED)
383 continue;
384 open++;
385 if (open >= hapd->conf->sae_anti_clogging_threshold)
386 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800387 }
388
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800389 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800390}
391
392
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800393static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
394 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800395{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800396 u8 mac[SHA256_MAC_LEN];
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800397
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800398 if (token_len != SHA256_MAC_LEN)
399 return -1;
400 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
401 addr, ETH_ALEN, mac) < 0 ||
402 os_memcmp(token, mac, SHA256_MAC_LEN) != 0)
403 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800404
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800405 return 0;
406}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800407
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800408
409static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
410 const u8 *addr)
411{
412 struct wpabuf *buf;
413 u8 *token;
414 struct os_time t;
415
416 os_get_time(&t);
417 if (hapd->last_sae_token_key_update == 0 ||
418 t.sec > hapd->last_sae_token_key_update + 60) {
419 if (random_get_bytes(hapd->sae_token_key,
420 sizeof(hapd->sae_token_key)) < 0)
421 return NULL;
422 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
423 hapd->sae_token_key, sizeof(hapd->sae_token_key));
424 hapd->last_sae_token_key_update = t.sec;
425 }
426
427 buf = wpabuf_alloc(SHA256_MAC_LEN);
428 if (buf == NULL)
429 return NULL;
430
431 token = wpabuf_put(buf, SHA256_MAC_LEN);
432 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
433 addr, ETH_ALEN, token);
434
435 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800436}
437
438
439static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
440 const struct ieee80211_mgmt *mgmt, size_t len,
441 u8 auth_transaction)
442{
443 u16 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800444 struct wpabuf *data = NULL;
445
446 if (!sta->sae) {
447 if (auth_transaction != 1)
448 return;
449 sta->sae = os_zalloc(sizeof(*sta->sae));
450 if (sta->sae == NULL)
451 return;
452 sta->sae->state = SAE_NOTHING;
453 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800454
455 if (auth_transaction == 1) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800456 const u8 *token = NULL;
457 size_t token_len = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800458 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
459 HOSTAPD_LEVEL_DEBUG,
460 "start SAE authentication (RX commit)");
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800461 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
462 ((const u8 *) mgmt) + len -
463 mgmt->u.auth.variable, &token,
464 &token_len, hapd->conf->sae_groups);
465 if (token && check_sae_token(hapd, sta->addr, token, token_len)
466 < 0) {
467 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
468 "incorrect token from " MACSTR,
469 MAC2STR(sta->addr));
470 return;
471 }
472
473 if (resp == WLAN_STATUS_SUCCESS) {
474 if (!token && use_sae_anti_clogging(hapd)) {
475 wpa_printf(MSG_DEBUG, "SAE: Request anti-"
476 "clogging token from " MACSTR,
477 MAC2STR(sta->addr));
478 data = auth_build_token_req(hapd, sta->addr);
479 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
480 } else {
481 data = auth_process_sae_commit(hapd, sta);
482 if (data == NULL)
483 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
484 else
485 sta->sae->state = SAE_COMMITTED;
486 }
487 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800488 } else if (auth_transaction == 2) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800489 if (sta->sae->state != SAE_COMMITTED) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800490 hostapd_logger(hapd, sta->addr,
491 HOSTAPD_MODULE_IEEE80211,
492 HOSTAPD_LEVEL_DEBUG,
493 "SAE confirm before commit");
494 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
495 }
496 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
497 HOSTAPD_LEVEL_DEBUG,
498 "SAE authentication (RX confirm)");
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800499 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
500 ((u8 *) mgmt) + len -
501 mgmt->u.auth.variable) < 0) {
502 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
503 } else {
504 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800505 sta->flags |= WLAN_STA_AUTH;
506 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
507 sta->auth_alg = WLAN_AUTH_SAE;
508 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800509
510 data = auth_build_sae_confirm(hapd, sta);
511 if (data == NULL)
512 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
513 else {
514 sta->sae->state = SAE_ACCEPTED;
515 sae_clear_temp_data(sta->sae);
516 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800517 }
518 } else {
519 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
520 HOSTAPD_LEVEL_DEBUG,
521 "unexpected SAE authentication transaction %u",
522 auth_transaction);
523 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
524 }
525
526 sta->auth_alg = WLAN_AUTH_SAE;
527
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800528 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
529 auth_transaction, resp,
530 data ? wpabuf_head(data) : (u8 *) "",
531 data ? wpabuf_len(data) : 0);
532 wpabuf_free(data);
533}
534#endif /* CONFIG_SAE */
535
536
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700537static void handle_auth(struct hostapd_data *hapd,
538 const struct ieee80211_mgmt *mgmt, size_t len)
539{
540 u16 auth_alg, auth_transaction, status_code;
541 u16 resp = WLAN_STATUS_SUCCESS;
542 struct sta_info *sta = NULL;
543 int res;
544 u16 fc;
545 const u8 *challenge = NULL;
546 u32 session_timeout, acct_interim_interval;
547 int vlan_id = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800548 struct hostapd_sta_wpa_psk_short *psk = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700549 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
550 size_t resp_ies_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700551 char *identity = NULL;
552 char *radius_cui = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553
554 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
555 printf("handle_auth - too short payload (len=%lu)\n",
556 (unsigned long) len);
557 return;
558 }
559
560 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
561 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
562 status_code = le_to_host16(mgmt->u.auth.status_code);
563 fc = le_to_host16(mgmt->frame_control);
564
565 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
566 2 + WLAN_AUTH_CHALLENGE_LEN &&
567 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
568 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
569 challenge = &mgmt->u.auth.variable[2];
570
571 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
572 "auth_transaction=%d status_code=%d wep=%d%s",
573 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
574 status_code, !!(fc & WLAN_FC_ISWEP),
575 challenge ? " challenge" : "");
576
577 if (hapd->tkip_countermeasures) {
578 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
579 goto fail;
580 }
581
582 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
583 auth_alg == WLAN_AUTH_OPEN) ||
584#ifdef CONFIG_IEEE80211R
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800585 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700586 auth_alg == WLAN_AUTH_FT) ||
587#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800588#ifdef CONFIG_SAE
589 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
590 auth_alg == WLAN_AUTH_SAE) ||
591#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
593 auth_alg == WLAN_AUTH_SHARED_KEY))) {
594 printf("Unsupported authentication algorithm (%d)\n",
595 auth_alg);
596 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
597 goto fail;
598 }
599
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800600 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700601 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
602 printf("Unknown authentication transaction number (%d)\n",
603 auth_transaction);
604 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
605 goto fail;
606 }
607
608 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
609 printf("Station " MACSTR " not allowed to authenticate.\n",
610 MAC2STR(mgmt->sa));
611 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
612 goto fail;
613 }
614
615 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
616 &session_timeout,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800617 &acct_interim_interval, &vlan_id,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800618 &psk, &identity, &radius_cui);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800619
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700620 if (res == HOSTAPD_ACL_REJECT) {
621 printf("Station " MACSTR " not allowed to authenticate.\n",
622 MAC2STR(mgmt->sa));
623 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
624 goto fail;
625 }
626 if (res == HOSTAPD_ACL_PENDING) {
627 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
628 " waiting for an external authentication",
629 MAC2STR(mgmt->sa));
630 /* Authentication code will re-send the authentication frame
631 * after it has received (and cached) information from the
632 * external source. */
633 return;
634 }
635
636 sta = ap_sta_add(hapd, mgmt->sa);
637 if (!sta) {
638 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
639 goto fail;
640 }
641
642 if (vlan_id > 0) {
643 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
644 vlan_id) == NULL) {
645 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
646 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
647 "%d received from RADIUS server",
648 vlan_id);
649 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
650 goto fail;
651 }
652 sta->vlan_id = vlan_id;
653 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
654 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
655 }
656
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800657 hostapd_free_psk_list(sta->psk);
658 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
659 sta->psk = psk;
660 psk = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800661 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800662 sta->psk = NULL;
663 }
664
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700665 sta->identity = identity;
666 identity = NULL;
667 sta->radius_cui = radius_cui;
668 radius_cui = NULL;
669
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670 sta->flags &= ~WLAN_STA_PREAUTH;
671 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
672
673 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
674 sta->acct_interim_interval = acct_interim_interval;
675 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
676 ap_sta_session_timeout(hapd, sta, session_timeout);
677 else
678 ap_sta_no_session_timeout(hapd, sta);
679
680 switch (auth_alg) {
681 case WLAN_AUTH_OPEN:
682 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
683 HOSTAPD_LEVEL_DEBUG,
684 "authentication OK (open system)");
685#ifdef IEEE80211_REQUIRE_AUTH_ACK
686 /* Station will be marked authenticated if it ACKs the
687 * authentication reply. */
688#else
689 sta->flags |= WLAN_STA_AUTH;
690 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
691 sta->auth_alg = WLAN_AUTH_OPEN;
692 mlme_authenticate_indication(hapd, sta);
693#endif
694 break;
695 case WLAN_AUTH_SHARED_KEY:
696 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
697 fc & WLAN_FC_ISWEP);
698 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
699 mlme_authenticate_indication(hapd, sta);
700 if (sta->challenge && auth_transaction == 1) {
701 resp_ies[0] = WLAN_EID_CHALLENGE;
702 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
703 os_memcpy(resp_ies + 2, sta->challenge,
704 WLAN_AUTH_CHALLENGE_LEN);
705 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
706 }
707 break;
708#ifdef CONFIG_IEEE80211R
709 case WLAN_AUTH_FT:
710 sta->auth_alg = WLAN_AUTH_FT;
711 if (sta->wpa_sm == NULL)
712 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
713 sta->addr);
714 if (sta->wpa_sm == NULL) {
715 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
716 "state machine");
717 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
718 goto fail;
719 }
720 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
721 auth_transaction, mgmt->u.auth.variable,
722 len - IEEE80211_HDRLEN -
723 sizeof(mgmt->u.auth),
724 handle_auth_ft_finish, hapd);
725 /* handle_auth_ft_finish() callback will complete auth. */
726 return;
727#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800728#ifdef CONFIG_SAE
729 case WLAN_AUTH_SAE:
730 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
731 return;
732#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 }
734
735 fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700736 os_free(identity);
737 os_free(radius_cui);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800738 hostapd_free_psk_list(psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700739
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
741 auth_transaction + 1, resp, resp_ies, resp_ies_len);
742}
743
744
745static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
746{
747 int i, j = 32, aid;
748
749 /* get a unique AID */
750 if (sta->aid > 0) {
751 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
752 return 0;
753 }
754
755 for (i = 0; i < AID_WORDS; i++) {
756 if (hapd->sta_aid[i] == (u32) -1)
757 continue;
758 for (j = 0; j < 32; j++) {
759 if (!(hapd->sta_aid[i] & BIT(j)))
760 break;
761 }
762 if (j < 32)
763 break;
764 }
765 if (j == 32)
766 return -1;
767 aid = i * 32 + j + 1;
768 if (aid > 2007)
769 return -1;
770
771 sta->aid = aid;
772 hapd->sta_aid[i] |= BIT(j);
773 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
774 return 0;
775}
776
777
778static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
779 const u8 *ssid_ie, size_t ssid_ie_len)
780{
781 if (ssid_ie == NULL)
782 return WLAN_STATUS_UNSPECIFIED_FAILURE;
783
784 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
785 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
786 char ssid_txt[33];
787 ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
788 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
789 HOSTAPD_LEVEL_INFO,
790 "Station tried to associate with unknown SSID "
791 "'%s'", ssid_txt);
792 return WLAN_STATUS_UNSPECIFIED_FAILURE;
793 }
794
795 return WLAN_STATUS_SUCCESS;
796}
797
798
799static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
800 const u8 *wmm_ie, size_t wmm_ie_len)
801{
802 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800803 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800805 struct wmm_information_element *wmm;
806
807 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 hostapd_logger(hapd, sta->addr,
809 HOSTAPD_MODULE_WPA,
810 HOSTAPD_LEVEL_DEBUG,
811 "invalid WMM element in association "
812 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800813 return WLAN_STATUS_UNSPECIFIED_FAILURE;
814 }
815
816 sta->flags |= WLAN_STA_WMM;
817 wmm = (struct wmm_information_element *) wmm_ie;
818 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819 }
820 return WLAN_STATUS_SUCCESS;
821}
822
823
824static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
825 struct ieee802_11_elems *elems)
826{
827 if (!elems->supp_rates) {
828 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
829 HOSTAPD_LEVEL_DEBUG,
830 "No supported rates element in AssocReq");
831 return WLAN_STATUS_UNSPECIFIED_FAILURE;
832 }
833
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700834 if (elems->supp_rates_len + elems->ext_supp_rates_len >
835 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700836 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
837 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700838 "Invalid supported rates element length %d+%d",
839 elems->supp_rates_len,
840 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841 return WLAN_STATUS_UNSPECIFIED_FAILURE;
842 }
843
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700844 sta->supported_rates_len = merge_byte_arrays(
845 sta->supported_rates, sizeof(sta->supported_rates),
846 elems->supp_rates, elems->supp_rates_len,
847 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700848
849 return WLAN_STATUS_SUCCESS;
850}
851
852
853static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
854 const u8 *ies, size_t ies_len, int reassoc)
855{
856 struct ieee802_11_elems elems;
857 u16 resp;
858 const u8 *wpa_ie;
859 size_t wpa_ie_len;
860
861 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
862 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
863 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
864 "association request");
865 return WLAN_STATUS_UNSPECIFIED_FAILURE;
866 }
867
868 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
869 if (resp != WLAN_STATUS_SUCCESS)
870 return resp;
871 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
872 if (resp != WLAN_STATUS_SUCCESS)
873 return resp;
874 resp = copy_supp_rates(hapd, sta, &elems);
875 if (resp != WLAN_STATUS_SUCCESS)
876 return resp;
877#ifdef CONFIG_IEEE80211N
878 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
879 elems.ht_capabilities_len);
880 if (resp != WLAN_STATUS_SUCCESS)
881 return resp;
882 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
883 !(sta->flags & WLAN_STA_HT)) {
884 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
885 HOSTAPD_LEVEL_INFO, "Station does not support "
886 "mandatory HT PHY - reject association");
887 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
888 }
889#endif /* CONFIG_IEEE80211N */
890
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700891#ifdef CONFIG_IEEE80211AC
892 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
893 elems.vht_capabilities_len);
894 if (resp != WLAN_STATUS_SUCCESS)
895 return resp;
896 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
897 !(sta->flags & WLAN_STA_VHT)) {
898 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
899 HOSTAPD_LEVEL_INFO, "Station does not support "
900 "mandatory VHT PHY - reject association");
901 return WLAN_STATUS_UNSPECIFIED_FAILURE;
902 }
903#endif /* CONFIG_IEEE80211AC */
904
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
906 wpa_ie = elems.rsn_ie;
907 wpa_ie_len = elems.rsn_ie_len;
908 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
909 elems.wpa_ie) {
910 wpa_ie = elems.wpa_ie;
911 wpa_ie_len = elems.wpa_ie_len;
912 } else {
913 wpa_ie = NULL;
914 wpa_ie_len = 0;
915 }
916
917#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800918 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700919 if (hapd->conf->wps_state && elems.wps_ie) {
920 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
921 "Request - assume WPS is used");
922 sta->flags |= WLAN_STA_WPS;
923 wpabuf_free(sta->wps_ie);
924 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
925 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800926 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
927 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
928 sta->flags |= WLAN_STA_WPS2;
929 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700930 wpa_ie = NULL;
931 wpa_ie_len = 0;
932 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
933 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
934 "(Re)Association Request - reject");
935 return WLAN_STATUS_INVALID_IE;
936 }
937 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
938 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
939 "(Re)Association Request - possible WPS use");
940 sta->flags |= WLAN_STA_MAYBE_WPS;
941 } else
942#endif /* CONFIG_WPS */
943 if (hapd->conf->wpa && wpa_ie == NULL) {
944 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
945 HOSTAPD_LEVEL_INFO,
946 "No WPA/RSN IE in association request");
947 return WLAN_STATUS_INVALID_IE;
948 }
949
950 if (hapd->conf->wpa && wpa_ie) {
951 int res;
952 wpa_ie -= 2;
953 wpa_ie_len += 2;
954 if (sta->wpa_sm == NULL)
955 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
956 sta->addr);
957 if (sta->wpa_sm == NULL) {
958 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
959 "state machine");
960 return WLAN_STATUS_UNSPECIFIED_FAILURE;
961 }
962 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
963 wpa_ie, wpa_ie_len,
964 elems.mdie, elems.mdie_len);
965 if (res == WPA_INVALID_GROUP)
966 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
967 else if (res == WPA_INVALID_PAIRWISE)
968 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
969 else if (res == WPA_INVALID_AKMP)
970 resp = WLAN_STATUS_AKMP_NOT_VALID;
971 else if (res == WPA_ALLOC_FAIL)
972 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
973#ifdef CONFIG_IEEE80211W
974 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
975 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
976 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
977 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
978#endif /* CONFIG_IEEE80211W */
979 else if (res == WPA_INVALID_MDIE)
980 resp = WLAN_STATUS_INVALID_MDIE;
981 else if (res != WPA_IE_OK)
982 resp = WLAN_STATUS_INVALID_IE;
983 if (resp != WLAN_STATUS_SUCCESS)
984 return resp;
985#ifdef CONFIG_IEEE80211W
986 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
987 sta->sa_query_count > 0)
988 ap_check_sa_query_timeout(hapd, sta);
989 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
990 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
991 /*
992 * STA has already been associated with MFP and SA
993 * Query timeout has not been reached. Reject the
994 * association attempt temporarily and start SA Query,
995 * if one is not pending.
996 */
997
998 if (sta->sa_query_count == 0)
999 ap_sta_start_sa_query(hapd, sta);
1000
1001 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1002 }
1003
1004 if (wpa_auth_uses_mfp(sta->wpa_sm))
1005 sta->flags |= WLAN_STA_MFP;
1006 else
1007 sta->flags &= ~WLAN_STA_MFP;
1008#endif /* CONFIG_IEEE80211W */
1009
1010#ifdef CONFIG_IEEE80211R
1011 if (sta->auth_alg == WLAN_AUTH_FT) {
1012 if (!reassoc) {
1013 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1014 "to use association (not "
1015 "re-association) with FT auth_alg",
1016 MAC2STR(sta->addr));
1017 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1018 }
1019
1020 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1021 ies_len);
1022 if (resp != WLAN_STATUS_SUCCESS)
1023 return resp;
1024 }
1025#endif /* CONFIG_IEEE80211R */
1026
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001027#ifdef CONFIG_SAE
1028 if (wpa_auth_uses_sae(sta->wpa_sm) &&
1029 sta->auth_alg != WLAN_AUTH_SAE) {
1030 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1031 "SAE AKM after non-SAE auth_alg %u",
1032 MAC2STR(sta->addr), sta->auth_alg);
1033 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1034 }
1035#endif /* CONFIG_SAE */
1036
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001038 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001039 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1040 hostapd_logger(hapd, sta->addr,
1041 HOSTAPD_MODULE_IEEE80211,
1042 HOSTAPD_LEVEL_INFO,
1043 "Station tried to use TKIP with HT "
1044 "association");
1045 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1046 }
1047#endif /* CONFIG_IEEE80211N */
1048 } else
1049 wpa_auth_sta_no_wpa(sta->wpa_sm);
1050
1051#ifdef CONFIG_P2P
1052 if (elems.p2p) {
1053 wpabuf_free(sta->p2p_ie);
1054 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1055 P2P_IE_VENDOR_TYPE);
1056
1057 } else {
1058 wpabuf_free(sta->p2p_ie);
1059 sta->p2p_ie = NULL;
1060 }
1061
1062 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1063#endif /* CONFIG_P2P */
1064
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001065#ifdef CONFIG_HS20
1066 wpabuf_free(sta->hs20_ie);
1067 if (elems.hs20 && elems.hs20_len > 4) {
1068 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1069 elems.hs20_len - 4);
1070 } else
1071 sta->hs20_ie = NULL;
1072#endif /* CONFIG_HS20 */
1073
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074 return WLAN_STATUS_SUCCESS;
1075}
1076
1077
1078static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1079 u16 reason_code)
1080{
1081 int send_len;
1082 struct ieee80211_mgmt reply;
1083
1084 os_memset(&reply, 0, sizeof(reply));
1085 reply.frame_control =
1086 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1087 os_memcpy(reply.da, addr, ETH_ALEN);
1088 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1089 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1090
1091 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1092 reply.u.deauth.reason_code = host_to_le16(reason_code);
1093
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001094 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001095 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1096 strerror(errno));
1097}
1098
1099
1100static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1101 u16 status_code, int reassoc, const u8 *ies,
1102 size_t ies_len)
1103{
1104 int send_len;
1105 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1106 struct ieee80211_mgmt *reply;
1107 u8 *p;
1108
1109 os_memset(buf, 0, sizeof(buf));
1110 reply = (struct ieee80211_mgmt *) buf;
1111 reply->frame_control =
1112 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1113 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1114 WLAN_FC_STYPE_ASSOC_RESP));
1115 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1116 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1117 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1118
1119 send_len = IEEE80211_HDRLEN;
1120 send_len += sizeof(reply->u.assoc_resp);
1121 reply->u.assoc_resp.capab_info =
1122 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1123 reply->u.assoc_resp.status_code = host_to_le16(status_code);
1124 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1125 | BIT(14) | BIT(15));
1126 /* Supported rates */
1127 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1128 /* Extended supported rates */
1129 p = hostapd_eid_ext_supp_rates(hapd, p);
1130
1131#ifdef CONFIG_IEEE80211R
1132 if (status_code == WLAN_STATUS_SUCCESS) {
1133 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1134 * Transition Information, RSN, [RIC Response] */
1135 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1136 buf + sizeof(buf) - p,
1137 sta->auth_alg, ies, ies_len);
1138 }
1139#endif /* CONFIG_IEEE80211R */
1140
1141#ifdef CONFIG_IEEE80211W
1142 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1143 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1144#endif /* CONFIG_IEEE80211W */
1145
1146#ifdef CONFIG_IEEE80211N
1147 p = hostapd_eid_ht_capabilities(hapd, p);
1148 p = hostapd_eid_ht_operation(hapd, p);
1149#endif /* CONFIG_IEEE80211N */
1150
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001151#ifdef CONFIG_IEEE80211AC
1152 p = hostapd_eid_vht_capabilities(hapd, p);
1153 p = hostapd_eid_vht_operation(hapd, p);
1154#endif /* CONFIG_IEEE80211AC */
1155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001157 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158
1159 if (sta->flags & WLAN_STA_WMM)
1160 p = hostapd_eid_wmm(hapd, p);
1161
1162#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001163 if ((sta->flags & WLAN_STA_WPS) ||
1164 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001165 struct wpabuf *wps = wps_build_assoc_resp_ie();
1166 if (wps) {
1167 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1168 p += wpabuf_len(wps);
1169 wpabuf_free(wps);
1170 }
1171 }
1172#endif /* CONFIG_WPS */
1173
1174#ifdef CONFIG_P2P
1175 if (sta->p2p_ie) {
1176 struct wpabuf *p2p_resp_ie;
1177 enum p2p_status_code status;
1178 switch (status_code) {
1179 case WLAN_STATUS_SUCCESS:
1180 status = P2P_SC_SUCCESS;
1181 break;
1182 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1183 status = P2P_SC_FAIL_LIMIT_REACHED;
1184 break;
1185 default:
1186 status = P2P_SC_FAIL_INVALID_PARAMS;
1187 break;
1188 }
1189 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1190 if (p2p_resp_ie) {
1191 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1192 wpabuf_len(p2p_resp_ie));
1193 p += wpabuf_len(p2p_resp_ie);
1194 wpabuf_free(p2p_resp_ie);
1195 }
1196 }
1197#endif /* CONFIG_P2P */
1198
1199#ifdef CONFIG_P2P_MANAGER
1200 if (hapd->conf->p2p & P2P_MANAGE)
1201 p = hostapd_eid_p2p_manage(hapd, p);
1202#endif /* CONFIG_P2P_MANAGER */
1203
1204 send_len += p - reply->u.assoc_resp.variable;
1205
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001206 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1208 strerror(errno));
1209}
1210
1211
1212static void handle_assoc(struct hostapd_data *hapd,
1213 const struct ieee80211_mgmt *mgmt, size_t len,
1214 int reassoc)
1215{
1216 u16 capab_info, listen_interval;
1217 u16 resp = WLAN_STATUS_SUCCESS;
1218 const u8 *pos;
1219 int left, i;
1220 struct sta_info *sta;
1221
1222 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1223 sizeof(mgmt->u.assoc_req))) {
1224 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
1225 "\n", reassoc, (unsigned long) len);
1226 return;
1227 }
1228
1229 if (reassoc) {
1230 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1231 listen_interval = le_to_host16(
1232 mgmt->u.reassoc_req.listen_interval);
1233 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1234 " capab_info=0x%02x listen_interval=%d current_ap="
1235 MACSTR,
1236 MAC2STR(mgmt->sa), capab_info, listen_interval,
1237 MAC2STR(mgmt->u.reassoc_req.current_ap));
1238 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1239 pos = mgmt->u.reassoc_req.variable;
1240 } else {
1241 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1242 listen_interval = le_to_host16(
1243 mgmt->u.assoc_req.listen_interval);
1244 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1245 " capab_info=0x%02x listen_interval=%d",
1246 MAC2STR(mgmt->sa), capab_info, listen_interval);
1247 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1248 pos = mgmt->u.assoc_req.variable;
1249 }
1250
1251 sta = ap_get_sta(hapd, mgmt->sa);
1252#ifdef CONFIG_IEEE80211R
1253 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1254 (sta->flags & WLAN_STA_AUTH) == 0) {
1255 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1256 "prior to authentication since it is using "
1257 "over-the-DS FT", MAC2STR(mgmt->sa));
1258 } else
1259#endif /* CONFIG_IEEE80211R */
1260 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1261 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1262 HOSTAPD_LEVEL_INFO, "Station tried to "
1263 "associate before authentication "
1264 "(aid=%d flags=0x%x)",
1265 sta ? sta->aid : -1,
1266 sta ? sta->flags : 0);
1267 send_deauth(hapd, mgmt->sa,
1268 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1269 return;
1270 }
1271
1272 if (hapd->tkip_countermeasures) {
1273 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1274 goto fail;
1275 }
1276
1277 if (listen_interval > hapd->conf->max_listen_interval) {
1278 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1279 HOSTAPD_LEVEL_DEBUG,
1280 "Too large Listen Interval (%d)",
1281 listen_interval);
1282 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1283 goto fail;
1284 }
1285
1286 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1287 * is used */
1288 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1289 if (resp != WLAN_STATUS_SUCCESS)
1290 goto fail;
1291
1292 if (hostapd_get_aid(hapd, sta) < 0) {
1293 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1294 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1295 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1296 goto fail;
1297 }
1298
1299 sta->capability = capab_info;
1300 sta->listen_interval = listen_interval;
1301
1302 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1303 sta->flags |= WLAN_STA_NONERP;
1304 for (i = 0; i < sta->supported_rates_len; i++) {
1305 if ((sta->supported_rates[i] & 0x7f) > 22) {
1306 sta->flags &= ~WLAN_STA_NONERP;
1307 break;
1308 }
1309 }
1310 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1311 sta->nonerp_set = 1;
1312 hapd->iface->num_sta_non_erp++;
1313 if (hapd->iface->num_sta_non_erp == 1)
1314 ieee802_11_set_beacons(hapd->iface);
1315 }
1316
1317 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1318 !sta->no_short_slot_time_set) {
1319 sta->no_short_slot_time_set = 1;
1320 hapd->iface->num_sta_no_short_slot_time++;
1321 if (hapd->iface->current_mode->mode ==
1322 HOSTAPD_MODE_IEEE80211G &&
1323 hapd->iface->num_sta_no_short_slot_time == 1)
1324 ieee802_11_set_beacons(hapd->iface);
1325 }
1326
1327 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1328 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1329 else
1330 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1331
1332 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1333 !sta->no_short_preamble_set) {
1334 sta->no_short_preamble_set = 1;
1335 hapd->iface->num_sta_no_short_preamble++;
1336 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1337 && hapd->iface->num_sta_no_short_preamble == 1)
1338 ieee802_11_set_beacons(hapd->iface);
1339 }
1340
1341#ifdef CONFIG_IEEE80211N
1342 update_ht_state(hapd, sta);
1343#endif /* CONFIG_IEEE80211N */
1344
1345 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1346 HOSTAPD_LEVEL_DEBUG,
1347 "association OK (aid %d)", sta->aid);
1348 /* Station will be marked associated, after it acknowledges AssocResp
1349 */
1350 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1351
1352#ifdef CONFIG_IEEE80211W
1353 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1354 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1355 "SA Query procedure", reassoc ? "re" : "");
1356 /* TODO: Send a protected Disassociate frame to the STA using
1357 * the old key and Reason Code "Previous Authentication no
1358 * longer valid". Make sure this is only sent protected since
1359 * unprotected frame would be received by the STA that is now
1360 * trying to associate.
1361 */
1362 }
1363#endif /* CONFIG_IEEE80211W */
1364
1365 if (reassoc) {
1366 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1367 ETH_ALEN);
1368 }
1369
1370 if (sta->last_assoc_req)
1371 os_free(sta->last_assoc_req);
1372 sta->last_assoc_req = os_malloc(len);
1373 if (sta->last_assoc_req)
1374 os_memcpy(sta->last_assoc_req, mgmt, len);
1375
1376 /* Make sure that the previously registered inactivity timer will not
1377 * remove the STA immediately. */
1378 sta->timeout_next = STA_NULLFUNC;
1379
1380 fail:
1381 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1382}
1383
1384
1385static void handle_disassoc(struct hostapd_data *hapd,
1386 const struct ieee80211_mgmt *mgmt, size_t len)
1387{
1388 struct sta_info *sta;
1389
1390 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1391 printf("handle_disassoc - too short payload (len=%lu)\n",
1392 (unsigned long) len);
1393 return;
1394 }
1395
1396 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1397 MAC2STR(mgmt->sa),
1398 le_to_host16(mgmt->u.disassoc.reason_code));
1399
1400 sta = ap_get_sta(hapd, mgmt->sa);
1401 if (sta == NULL) {
1402 printf("Station " MACSTR " trying to disassociate, but it "
1403 "is not associated.\n", MAC2STR(mgmt->sa));
1404 return;
1405 }
1406
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001407 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001408 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1410 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1411 HOSTAPD_LEVEL_INFO, "disassociated");
1412 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1413 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1414 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1415 * authenticated. */
1416 accounting_sta_stop(hapd, sta);
1417 ieee802_1x_free_station(sta);
1418 hostapd_drv_sta_remove(hapd, sta->addr);
1419
1420 if (sta->timeout_next == STA_NULLFUNC ||
1421 sta->timeout_next == STA_DISASSOC) {
1422 sta->timeout_next = STA_DEAUTH;
1423 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1424 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1425 hapd, sta);
1426 }
1427
1428 mlme_disassociate_indication(
1429 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1430}
1431
1432
1433static void handle_deauth(struct hostapd_data *hapd,
1434 const struct ieee80211_mgmt *mgmt, size_t len)
1435{
1436 struct sta_info *sta;
1437
1438 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001439 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1440 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001441 return;
1442 }
1443
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001444 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001445 " reason_code=%d",
1446 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1447
1448 sta = ap_get_sta(hapd, mgmt->sa);
1449 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001450 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1451 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001452 MAC2STR(mgmt->sa));
1453 return;
1454 }
1455
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001456 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1458 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001459 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1460 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1461 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1462 mlme_deauthenticate_indication(
1463 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1464 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1465 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1466 ap_free_sta(hapd, sta);
1467}
1468
1469
1470static void handle_beacon(struct hostapd_data *hapd,
1471 const struct ieee80211_mgmt *mgmt, size_t len,
1472 struct hostapd_frame_info *fi)
1473{
1474 struct ieee802_11_elems elems;
1475
1476 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1477 printf("handle_beacon - too short payload (len=%lu)\n",
1478 (unsigned long) len);
1479 return;
1480 }
1481
1482 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1483 len - (IEEE80211_HDRLEN +
1484 sizeof(mgmt->u.beacon)), &elems,
1485 0);
1486
1487 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1488}
1489
1490
1491#ifdef CONFIG_IEEE80211W
1492
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001493static void hostapd_sa_query_action(struct hostapd_data *hapd,
1494 const struct ieee80211_mgmt *mgmt,
1495 size_t len)
1496{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001497 const u8 *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001498
1499 end = mgmt->u.action.u.sa_query_resp.trans_id +
1500 WLAN_SA_QUERY_TR_ID_LEN;
1501 if (((u8 *) mgmt) + len < end) {
1502 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1503 "frame (len=%lu)", (unsigned long) len);
1504 return;
1505 }
1506
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001507 ieee802_11_sa_query_action(hapd, mgmt->sa,
1508 mgmt->u.action.u.sa_query_resp.action,
1509 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001510}
1511
1512
1513static int robust_action_frame(u8 category)
1514{
1515 return category != WLAN_ACTION_PUBLIC &&
1516 category != WLAN_ACTION_HT;
1517}
1518#endif /* CONFIG_IEEE80211W */
1519
1520
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001521#ifdef CONFIG_WNM
1522static void hostapd_wnm_action(struct hostapd_data *hapd, struct sta_info *sta,
1523 const struct ieee80211_mgmt *mgmt,
1524 size_t len)
1525{
1526 struct rx_action action;
1527 if (len < IEEE80211_HDRLEN + 2)
1528 return;
1529 os_memset(&action, 0, sizeof(action));
1530 action.da = mgmt->da;
1531 action.sa = mgmt->sa;
1532 action.bssid = mgmt->bssid;
1533 action.category = mgmt->u.action.category;
1534 action.data = (const u8 *) &mgmt->u.action.u.wnm_sleep_req.action;
1535 action.len = len - IEEE80211_HDRLEN - 1;
1536 action.freq = hapd->iface->freq;
1537 ieee802_11_rx_wnm_action_ap(hapd, &action);
1538}
1539#endif /* CONFIG_WNM */
1540
1541
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001542static void handle_action(struct hostapd_data *hapd,
1543 const struct ieee80211_mgmt *mgmt, size_t len)
1544{
1545 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001546 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001547
1548 if (len < IEEE80211_HDRLEN + 1) {
1549 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1550 HOSTAPD_LEVEL_DEBUG,
1551 "handle_action - too short payload (len=%lu)",
1552 (unsigned long) len);
1553 return;
1554 }
1555
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001556 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1557 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
1558 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
1559 "frame (category=%u) from unassociated STA " MACSTR,
1560 MAC2STR(mgmt->sa), mgmt->u.action.category);
1561 return;
1562 }
1563
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001564#ifdef CONFIG_IEEE80211W
1565 if (sta && (sta->flags & WLAN_STA_MFP) &&
1566 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP) &&
1567 robust_action_frame(mgmt->u.action.category))) {
1568 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1569 HOSTAPD_LEVEL_DEBUG,
1570 "Dropped unprotected Robust Action frame from "
1571 "an MFP STA");
1572 return;
1573 }
1574#endif /* CONFIG_IEEE80211W */
1575
1576 switch (mgmt->u.action.category) {
1577#ifdef CONFIG_IEEE80211R
1578 case WLAN_ACTION_FT:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001579 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1580 len - IEEE80211_HDRLEN))
1581 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001582 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001583#endif /* CONFIG_IEEE80211R */
1584 case WLAN_ACTION_WMM:
1585 hostapd_wmm_action(hapd, mgmt, len);
1586 return;
1587#ifdef CONFIG_IEEE80211W
1588 case WLAN_ACTION_SA_QUERY:
1589 hostapd_sa_query_action(hapd, mgmt, len);
1590 return;
1591#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001592#ifdef CONFIG_WNM
1593 case WLAN_ACTION_WNM:
1594 hostapd_wnm_action(hapd, sta, mgmt, len);
1595 return;
1596#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001597 case WLAN_ACTION_PUBLIC:
1598 if (hapd->public_action_cb) {
1599 hapd->public_action_cb(hapd->public_action_cb_ctx,
1600 (u8 *) mgmt, len,
1601 hapd->iface->freq);
1602 return;
1603 }
1604 break;
1605 case WLAN_ACTION_VENDOR_SPECIFIC:
1606 if (hapd->vendor_action_cb) {
1607 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1608 (u8 *) mgmt, len,
1609 hapd->iface->freq) == 0)
1610 return;
1611 }
1612 break;
1613 }
1614
1615 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1616 HOSTAPD_LEVEL_DEBUG,
1617 "handle_action - unknown action category %d or invalid "
1618 "frame",
1619 mgmt->u.action.category);
1620 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1621 !(mgmt->sa[0] & 0x01)) {
1622 struct ieee80211_mgmt *resp;
1623
1624 /*
1625 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1626 * Return the Action frame to the source without change
1627 * except that MSB of the Category set to 1.
1628 */
1629 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1630 "frame back to sender");
1631 resp = os_malloc(len);
1632 if (resp == NULL)
1633 return;
1634 os_memcpy(resp, mgmt, len);
1635 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1636 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1637 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1638 resp->u.action.category |= 0x80;
1639
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001640 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1641 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1642 "Action frame");
1643 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001644 os_free(resp);
1645 }
1646}
1647
1648
1649/**
1650 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1651 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1652 * sent to)
1653 * @buf: management frame data (starting from IEEE 802.11 header)
1654 * @len: length of frame data in octets
1655 * @fi: meta data about received frame (signal level, etc.)
1656 *
1657 * Process all incoming IEEE 802.11 management frames. This will be called for
1658 * each frame received from the kernel driver through wlan#ap interface. In
1659 * addition, it can be called to re-inserted pending frames (e.g., when using
1660 * external RADIUS server as an MAC ACL).
1661 */
1662void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1663 struct hostapd_frame_info *fi)
1664{
1665 struct ieee80211_mgmt *mgmt;
1666 int broadcast;
1667 u16 fc, stype;
1668
1669 if (len < 24)
1670 return;
1671
1672 mgmt = (struct ieee80211_mgmt *) buf;
1673 fc = le_to_host16(mgmt->frame_control);
1674 stype = WLAN_FC_GET_STYPE(fc);
1675
1676 if (stype == WLAN_FC_STYPE_BEACON) {
1677 handle_beacon(hapd, mgmt, len, fi);
1678 return;
1679 }
1680
1681 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1682 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1683 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1684
1685 if (!broadcast &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001686#ifdef CONFIG_P2P
1687 /* Invitation responses can be sent with the peer MAC as BSSID */
1688 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1689 stype == WLAN_FC_STYPE_ACTION) &&
1690#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001691 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1692 printf("MGMT: BSSID=" MACSTR " not our address\n",
1693 MAC2STR(mgmt->bssid));
1694 return;
1695 }
1696
1697
1698 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001699 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001700 return;
1701 }
1702
1703 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1704 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1705 HOSTAPD_LEVEL_DEBUG,
1706 "MGMT: DA=" MACSTR " not our address",
1707 MAC2STR(mgmt->da));
1708 return;
1709 }
1710
1711 switch (stype) {
1712 case WLAN_FC_STYPE_AUTH:
1713 wpa_printf(MSG_DEBUG, "mgmt::auth");
1714 handle_auth(hapd, mgmt, len);
1715 break;
1716 case WLAN_FC_STYPE_ASSOC_REQ:
1717 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1718 handle_assoc(hapd, mgmt, len, 0);
1719 break;
1720 case WLAN_FC_STYPE_REASSOC_REQ:
1721 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1722 handle_assoc(hapd, mgmt, len, 1);
1723 break;
1724 case WLAN_FC_STYPE_DISASSOC:
1725 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1726 handle_disassoc(hapd, mgmt, len);
1727 break;
1728 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001729 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001730 handle_deauth(hapd, mgmt, len);
1731 break;
1732 case WLAN_FC_STYPE_ACTION:
1733 wpa_printf(MSG_DEBUG, "mgmt::action");
1734 handle_action(hapd, mgmt, len);
1735 break;
1736 default:
1737 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1738 HOSTAPD_LEVEL_DEBUG,
1739 "unknown mgmt frame subtype %d", stype);
1740 break;
1741 }
1742}
1743
1744
1745static void handle_auth_cb(struct hostapd_data *hapd,
1746 const struct ieee80211_mgmt *mgmt,
1747 size_t len, int ok)
1748{
1749 u16 auth_alg, auth_transaction, status_code;
1750 struct sta_info *sta;
1751
1752 if (!ok) {
1753 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1754 HOSTAPD_LEVEL_NOTICE,
1755 "did not acknowledge authentication response");
1756 return;
1757 }
1758
1759 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1760 printf("handle_auth_cb - too short payload (len=%lu)\n",
1761 (unsigned long) len);
1762 return;
1763 }
1764
1765 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1766 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1767 status_code = le_to_host16(mgmt->u.auth.status_code);
1768
1769 sta = ap_get_sta(hapd, mgmt->da);
1770 if (!sta) {
1771 printf("handle_auth_cb: STA " MACSTR " not found\n",
1772 MAC2STR(mgmt->da));
1773 return;
1774 }
1775
1776 if (status_code == WLAN_STATUS_SUCCESS &&
1777 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1778 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1779 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1780 HOSTAPD_LEVEL_INFO, "authenticated");
1781 sta->flags |= WLAN_STA_AUTH;
1782 }
1783}
1784
1785
1786static void handle_assoc_cb(struct hostapd_data *hapd,
1787 const struct ieee80211_mgmt *mgmt,
1788 size_t len, int reassoc, int ok)
1789{
1790 u16 status;
1791 struct sta_info *sta;
1792 int new_assoc = 1;
1793 struct ieee80211_ht_capabilities ht_cap;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001794 struct ieee80211_vht_capabilities vht_cap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001795
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001796 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1797 sizeof(mgmt->u.assoc_resp))) {
1798 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1799 "(len=%lu)\n", reassoc, (unsigned long) len);
1800 return;
1801 }
1802
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001803 sta = ap_get_sta(hapd, mgmt->da);
1804 if (!sta) {
1805 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1806 MAC2STR(mgmt->da));
1807 return;
1808 }
1809
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001810 if (!ok) {
1811 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1812 HOSTAPD_LEVEL_DEBUG,
1813 "did not acknowledge association response");
1814 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
1815 return;
1816 }
1817
1818 if (reassoc)
1819 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1820 else
1821 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1822
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823 if (status != WLAN_STATUS_SUCCESS)
1824 goto fail;
1825
1826 /* Stop previous accounting session, if one is started, and allocate
1827 * new session id for the new session. */
1828 accounting_sta_stop(hapd, sta);
1829
1830 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1831 HOSTAPD_LEVEL_INFO,
1832 "associated (aid %d)",
1833 sta->aid);
1834
1835 if (sta->flags & WLAN_STA_ASSOC)
1836 new_assoc = 0;
1837 sta->flags |= WLAN_STA_ASSOC;
1838 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
1839 sta->auth_alg == WLAN_AUTH_FT) {
1840 /*
1841 * Open, static WEP, or FT protocol; no separate authorization
1842 * step.
1843 */
1844 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845 }
1846
1847 if (reassoc)
1848 mlme_reassociate_indication(hapd, sta);
1849 else
1850 mlme_associate_indication(hapd, sta);
1851
1852#ifdef CONFIG_IEEE80211W
1853 sta->sa_query_timed_out = 0;
1854#endif /* CONFIG_IEEE80211W */
1855
1856 /*
1857 * Remove the STA entry in order to make sure the STA PS state gets
1858 * cleared and configuration gets updated in case of reassociation back
1859 * to the same AP.
1860 */
1861 hostapd_drv_sta_remove(hapd, sta->addr);
1862
1863#ifdef CONFIG_IEEE80211N
1864 if (sta->flags & WLAN_STA_HT)
1865 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1866#endif /* CONFIG_IEEE80211N */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001867#ifdef CONFIG_IEEE80211AC
1868 if (sta->flags & WLAN_STA_VHT)
1869 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1870#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001871
1872 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1873 sta->supported_rates, sta->supported_rates_len,
1874 sta->listen_interval,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001875 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001876 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001877 sta->flags, sta->qosinfo)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1879 HOSTAPD_LEVEL_NOTICE,
1880 "Could not add STA to kernel driver");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001881
1882 ap_sta_disconnect(hapd, sta, sta->addr,
1883 WLAN_REASON_DISASSOC_AP_BUSY);
1884
1885 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001886 }
1887
1888 if (sta->flags & WLAN_STA_WDS)
1889 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
1890
1891 if (sta->eapol_sm == NULL) {
1892 /*
1893 * This STA does not use RADIUS server for EAP authentication,
1894 * so bind it to the selected VLAN interface now, since the
1895 * interface selection is not going to change anymore.
1896 */
1897 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1898 goto fail;
1899 } else if (sta->vlan_id) {
1900 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1901 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1902 goto fail;
1903 }
1904
1905 hostapd_set_sta_flags(hapd, sta);
1906
1907 if (sta->auth_alg == WLAN_AUTH_FT)
1908 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1909 else
1910 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1911 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
1912
1913 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1914
1915 fail:
1916 /* Copy of the association request is not needed anymore */
1917 if (sta->last_assoc_req) {
1918 os_free(sta->last_assoc_req);
1919 sta->last_assoc_req = NULL;
1920 }
1921}
1922
1923
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001924static void handle_deauth_cb(struct hostapd_data *hapd,
1925 const struct ieee80211_mgmt *mgmt,
1926 size_t len, int ok)
1927{
1928 struct sta_info *sta;
1929 if (mgmt->da[0] & 0x01)
1930 return;
1931 sta = ap_get_sta(hapd, mgmt->da);
1932 if (!sta) {
1933 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
1934 " not found", MAC2STR(mgmt->da));
1935 return;
1936 }
1937 if (ok)
1938 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
1939 MAC2STR(sta->addr));
1940 else
1941 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
1942 "deauth", MAC2STR(sta->addr));
1943
1944 ap_sta_deauth_cb(hapd, sta);
1945}
1946
1947
1948static void handle_disassoc_cb(struct hostapd_data *hapd,
1949 const struct ieee80211_mgmt *mgmt,
1950 size_t len, int ok)
1951{
1952 struct sta_info *sta;
1953 if (mgmt->da[0] & 0x01)
1954 return;
1955 sta = ap_get_sta(hapd, mgmt->da);
1956 if (!sta) {
1957 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
1958 " not found", MAC2STR(mgmt->da));
1959 return;
1960 }
1961 if (ok)
1962 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
1963 MAC2STR(sta->addr));
1964 else
1965 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
1966 "disassoc", MAC2STR(sta->addr));
1967
1968 ap_sta_disassoc_cb(hapd, sta);
1969}
1970
1971
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001972/**
1973 * ieee802_11_mgmt_cb - Process management frame TX status callback
1974 * @hapd: hostapd BSS data structure (the BSS from which the management frame
1975 * was sent from)
1976 * @buf: management frame data (starting from IEEE 802.11 header)
1977 * @len: length of frame data in octets
1978 * @stype: management frame subtype from frame control field
1979 * @ok: Whether the frame was ACK'ed
1980 */
1981void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
1982 u16 stype, int ok)
1983{
1984 const struct ieee80211_mgmt *mgmt;
1985 mgmt = (const struct ieee80211_mgmt *) buf;
1986
1987 switch (stype) {
1988 case WLAN_FC_STYPE_AUTH:
1989 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1990 handle_auth_cb(hapd, mgmt, len, ok);
1991 break;
1992 case WLAN_FC_STYPE_ASSOC_RESP:
1993 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1994 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1995 break;
1996 case WLAN_FC_STYPE_REASSOC_RESP:
1997 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1998 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1999 break;
2000 case WLAN_FC_STYPE_PROBE_RESP:
2001 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2002 break;
2003 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002004 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2005 handle_deauth_cb(hapd, mgmt, len, ok);
2006 break;
2007 case WLAN_FC_STYPE_DISASSOC:
2008 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2009 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002010 break;
2011 case WLAN_FC_STYPE_ACTION:
2012 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2013 break;
2014 default:
2015 printf("unknown mgmt cb frame subtype %d\n", stype);
2016 break;
2017 }
2018}
2019
2020
2021int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2022{
2023 /* TODO */
2024 return 0;
2025}
2026
2027
2028int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2029 char *buf, size_t buflen)
2030{
2031 /* TODO */
2032 return 0;
2033}
2034
2035
2036void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2037 const u8 *buf, size_t len, int ack)
2038{
2039 struct sta_info *sta;
2040 struct hostapd_iface *iface = hapd->iface;
2041
2042 sta = ap_get_sta(hapd, addr);
2043 if (sta == NULL && iface->num_bss > 1) {
2044 size_t j;
2045 for (j = 0; j < iface->num_bss; j++) {
2046 hapd = iface->bss[j];
2047 sta = ap_get_sta(hapd, addr);
2048 if (sta)
2049 break;
2050 }
2051 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002052 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002053 return;
2054 if (sta->flags & WLAN_STA_PENDING_POLL) {
2055 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2056 "activity poll", MAC2STR(sta->addr),
2057 ack ? "ACKed" : "did not ACK");
2058 if (ack)
2059 sta->flags &= ~WLAN_STA_PENDING_POLL;
2060 }
2061
2062 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2063}
2064
2065
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002066void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2067 const u8 *data, size_t len, int ack)
2068{
2069 struct sta_info *sta;
2070 struct hostapd_iface *iface = hapd->iface;
2071
2072 sta = ap_get_sta(hapd, dst);
2073 if (sta == NULL && iface->num_bss > 1) {
2074 size_t j;
2075 for (j = 0; j < iface->num_bss; j++) {
2076 hapd = iface->bss[j];
2077 sta = ap_get_sta(hapd, dst);
2078 if (sta)
2079 break;
2080 }
2081 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002082 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2083 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2084 MACSTR " that is not currently associated",
2085 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002086 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002087 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002088
2089 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2090}
2091
2092
2093void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2094{
2095 struct sta_info *sta;
2096 struct hostapd_iface *iface = hapd->iface;
2097
2098 sta = ap_get_sta(hapd, addr);
2099 if (sta == NULL && iface->num_bss > 1) {
2100 size_t j;
2101 for (j = 0; j < iface->num_bss; j++) {
2102 hapd = iface->bss[j];
2103 sta = ap_get_sta(hapd, addr);
2104 if (sta)
2105 break;
2106 }
2107 }
2108 if (sta == NULL)
2109 return;
2110 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2111 return;
2112
2113 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2114 "activity poll", MAC2STR(sta->addr));
2115 sta->flags &= ~WLAN_STA_PENDING_POLL;
2116}
2117
2118
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002119void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2120 int wds)
2121{
2122 struct sta_info *sta;
2123
2124 sta = ap_get_sta(hapd, src);
2125 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002126 if (!hapd->conf->wds_sta)
2127 return;
2128
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002129 if (wds && !(sta->flags & WLAN_STA_WDS)) {
2130 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2131 "STA " MACSTR " (aid %u)",
2132 MAC2STR(sta->addr), sta->aid);
2133 sta->flags |= WLAN_STA_WDS;
2134 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
2135 }
2136 return;
2137 }
2138
2139 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2140 MACSTR, MAC2STR(src));
2141 if (src[0] & 0x01) {
2142 /* Broadcast bit set in SA?! Ignore the frame silently. */
2143 return;
2144 }
2145
2146 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2147 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2148 "already been sent, but no TX status yet known - "
2149 "ignore Class 3 frame issue with " MACSTR,
2150 MAC2STR(src));
2151 return;
2152 }
2153
2154 if (sta && (sta->flags & WLAN_STA_AUTH))
2155 hostapd_drv_sta_disassoc(
2156 hapd, src,
2157 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2158 else
2159 hostapd_drv_sta_deauth(
2160 hapd, src,
2161 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2162}
2163
2164
2165#endif /* CONFIG_NATIVE_WINDOWS */