]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/ap/ieee802_11.c
Add initial parts for SAE
[thirdparty/hostap.git] / src / ap / ieee802_11.c
1 /*
2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
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"
16 #include "drivers/driver.h"
17 #include "common/ieee802_11_defs.h"
18 #include "common/ieee802_11_common.h"
19 #include "common/wpa_ctrl.h"
20 #include "radius/radius.h"
21 #include "radius/radius_client.h"
22 #include "p2p/p2p.h"
23 #include "wps/wps.h"
24 #include "hostapd.h"
25 #include "beacon.h"
26 #include "ieee802_11_auth.h"
27 #include "sta_info.h"
28 #include "ieee802_1x.h"
29 #include "wpa_auth.h"
30 #include "wmm.h"
31 #include "ap_list.h"
32 #include "accounting.h"
33 #include "ap_config.h"
34 #include "ap_mlme.h"
35 #include "p2p_hostapd.h"
36 #include "ap_drv_ops.h"
37 #include "ieee802_11.h"
38
39
40 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
41 {
42 u8 *pos = eid;
43 int i, num, count;
44
45 if (hapd->iface->current_rates == NULL)
46 return eid;
47
48 *pos++ = WLAN_EID_SUPP_RATES;
49 num = hapd->iface->num_rates;
50 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
51 num++;
52 if (num > 8) {
53 /* rest of the rates are encoded in Extended supported
54 * rates element */
55 num = 8;
56 }
57
58 *pos++ = num;
59 count = 0;
60 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
61 i++) {
62 count++;
63 *pos = hapd->iface->current_rates[i].rate / 5;
64 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
65 *pos |= 0x80;
66 pos++;
67 }
68
69 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
70 hapd->iface->num_rates < 8)
71 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
72
73 return pos;
74 }
75
76
77 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
78 {
79 u8 *pos = eid;
80 int i, num, count;
81
82 if (hapd->iface->current_rates == NULL)
83 return eid;
84
85 num = hapd->iface->num_rates;
86 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
87 num++;
88 if (num <= 8)
89 return eid;
90 num -= 8;
91
92 *pos++ = WLAN_EID_EXT_SUPP_RATES;
93 *pos++ = num;
94 count = 0;
95 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
96 i++) {
97 count++;
98 if (count <= 8)
99 continue; /* already in SuppRates IE */
100 *pos = hapd->iface->current_rates[i].rate / 5;
101 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
102 *pos |= 0x80;
103 pos++;
104 }
105
106 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
107 hapd->iface->num_rates >= 8)
108 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
109
110 return pos;
111 }
112
113
114 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
115 int probe)
116 {
117 int capab = WLAN_CAPABILITY_ESS;
118 int privacy;
119
120 if (hapd->iface->num_sta_no_short_preamble == 0 &&
121 hapd->iconf->preamble == SHORT_PREAMBLE)
122 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
123
124 privacy = hapd->conf->ssid.wep.keys_set;
125
126 if (hapd->conf->ieee802_1x &&
127 (hapd->conf->default_wep_key_len ||
128 hapd->conf->individual_wep_key_len))
129 privacy = 1;
130
131 if (hapd->conf->wpa)
132 privacy = 1;
133
134 if (sta) {
135 int policy, def_klen;
136 if (probe && sta->ssid_probe) {
137 policy = sta->ssid_probe->security_policy;
138 def_klen = sta->ssid_probe->wep.default_len;
139 } else {
140 policy = sta->ssid->security_policy;
141 def_klen = sta->ssid->wep.default_len;
142 }
143 privacy = policy != SECURITY_PLAINTEXT;
144 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
145 privacy = 0;
146 }
147
148 if (privacy)
149 capab |= WLAN_CAPABILITY_PRIVACY;
150
151 if (hapd->iface->current_mode &&
152 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
153 hapd->iface->num_sta_no_short_slot_time == 0)
154 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
155
156 return capab;
157 }
158
159
160 void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
161 {
162 int i;
163 if (len > HOSTAPD_MAX_SSID_LEN)
164 len = HOSTAPD_MAX_SSID_LEN;
165 for (i = 0; i < len; i++) {
166 if (ssid[i] >= 32 && ssid[i] < 127)
167 buf[i] = ssid[i];
168 else
169 buf[i] = '.';
170 }
171 buf[len] = '\0';
172 }
173
174
175 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
176 u16 auth_transaction, const u8 *challenge,
177 int iswep)
178 {
179 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
180 HOSTAPD_LEVEL_DEBUG,
181 "authentication (shared key, transaction %d)",
182 auth_transaction);
183
184 if (auth_transaction == 1) {
185 if (!sta->challenge) {
186 /* Generate a pseudo-random challenge */
187 u8 key[8];
188 struct os_time now;
189 int r;
190 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
191 if (sta->challenge == NULL)
192 return WLAN_STATUS_UNSPECIFIED_FAILURE;
193
194 os_get_time(&now);
195 r = os_random();
196 os_memcpy(key, &now.sec, 4);
197 os_memcpy(key + 4, &r, 4);
198 rc4_skip(key, sizeof(key), 0,
199 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
200 }
201 return 0;
202 }
203
204 if (auth_transaction != 3)
205 return WLAN_STATUS_UNSPECIFIED_FAILURE;
206
207 /* Transaction 3 */
208 if (!iswep || !sta->challenge || !challenge ||
209 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
210 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
211 HOSTAPD_LEVEL_INFO,
212 "shared key authentication - invalid "
213 "challenge-response");
214 return WLAN_STATUS_CHALLENGE_FAIL;
215 }
216
217 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
218 HOSTAPD_LEVEL_DEBUG,
219 "authentication OK (shared key)");
220 #ifdef IEEE80211_REQUIRE_AUTH_ACK
221 /* Station will be marked authenticated if it ACKs the
222 * authentication reply. */
223 #else
224 sta->flags |= WLAN_STA_AUTH;
225 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
226 #endif
227 os_free(sta->challenge);
228 sta->challenge = NULL;
229
230 return 0;
231 }
232
233
234 static void send_auth_reply(struct hostapd_data *hapd,
235 const u8 *dst, const u8 *bssid,
236 u16 auth_alg, u16 auth_transaction, u16 resp,
237 const u8 *ies, size_t ies_len)
238 {
239 struct ieee80211_mgmt *reply;
240 u8 *buf;
241 size_t rlen;
242
243 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
244 buf = os_zalloc(rlen);
245 if (buf == NULL)
246 return;
247
248 reply = (struct ieee80211_mgmt *) buf;
249 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
250 WLAN_FC_STYPE_AUTH);
251 os_memcpy(reply->da, dst, ETH_ALEN);
252 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
253 os_memcpy(reply->bssid, bssid, ETH_ALEN);
254
255 reply->u.auth.auth_alg = host_to_le16(auth_alg);
256 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
257 reply->u.auth.status_code = host_to_le16(resp);
258
259 if (ies && ies_len)
260 os_memcpy(reply->u.auth.variable, ies, ies_len);
261
262 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
263 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
264 MAC2STR(dst), auth_alg, auth_transaction,
265 resp, (unsigned long) ies_len);
266 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
267 perror("send_auth_reply: send");
268
269 os_free(buf);
270 }
271
272
273 #ifdef CONFIG_IEEE80211R
274 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
275 u16 auth_transaction, u16 status,
276 const u8 *ies, size_t ies_len)
277 {
278 struct hostapd_data *hapd = ctx;
279 struct sta_info *sta;
280
281 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
282 status, ies, ies_len);
283
284 if (status != WLAN_STATUS_SUCCESS)
285 return;
286
287 sta = ap_get_sta(hapd, dst);
288 if (sta == NULL)
289 return;
290
291 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
292 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
293 sta->flags |= WLAN_STA_AUTH;
294 mlme_authenticate_indication(hapd, sta);
295 }
296 #endif /* CONFIG_IEEE80211R */
297
298
299 #ifdef CONFIG_SAE
300 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
301 const struct ieee80211_mgmt *mgmt, size_t len,
302 u8 auth_transaction)
303 {
304 u16 resp = WLAN_STATUS_SUCCESS;
305 u8 *data = (u8 *) "TEST"; /* TODO */
306 size_t data_len = 4;
307
308 if (auth_transaction == 1) {
309 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
310 HOSTAPD_LEVEL_DEBUG,
311 "start SAE authentication (RX commit)");
312 sta->sae_state = SAE_COMMIT;
313 } else if (auth_transaction == 2) {
314 if (sta->sae_state != SAE_COMMIT) {
315 hostapd_logger(hapd, sta->addr,
316 HOSTAPD_MODULE_IEEE80211,
317 HOSTAPD_LEVEL_DEBUG,
318 "SAE confirm before commit");
319 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
320 }
321 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
322 HOSTAPD_LEVEL_DEBUG,
323 "SAE authentication (RX confirm)");
324 sta->flags |= WLAN_STA_AUTH;
325 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
326 sta->auth_alg = WLAN_AUTH_SAE;
327 mlme_authenticate_indication(hapd, sta);
328 } else {
329 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
330 HOSTAPD_LEVEL_DEBUG,
331 "unexpected SAE authentication transaction %u",
332 auth_transaction);
333 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
334 }
335
336 sta->auth_alg = WLAN_AUTH_SAE;
337
338 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
339 auth_transaction, resp, data, data_len);
340 }
341 #endif /* CONFIG_SAE */
342
343
344 static void handle_auth(struct hostapd_data *hapd,
345 const struct ieee80211_mgmt *mgmt, size_t len)
346 {
347 u16 auth_alg, auth_transaction, status_code;
348 u16 resp = WLAN_STATUS_SUCCESS;
349 struct sta_info *sta = NULL;
350 int res;
351 u16 fc;
352 const u8 *challenge = NULL;
353 u32 session_timeout, acct_interim_interval;
354 int vlan_id = 0;
355 u8 psk[PMK_LEN];
356 int has_psk = 0;
357 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
358 size_t resp_ies_len = 0;
359 char *identity = NULL;
360 char *radius_cui = NULL;
361
362 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
363 printf("handle_auth - too short payload (len=%lu)\n",
364 (unsigned long) len);
365 return;
366 }
367
368 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
369 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
370 status_code = le_to_host16(mgmt->u.auth.status_code);
371 fc = le_to_host16(mgmt->frame_control);
372
373 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
374 2 + WLAN_AUTH_CHALLENGE_LEN &&
375 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
376 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
377 challenge = &mgmt->u.auth.variable[2];
378
379 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
380 "auth_transaction=%d status_code=%d wep=%d%s",
381 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
382 status_code, !!(fc & WLAN_FC_ISWEP),
383 challenge ? " challenge" : "");
384
385 if (hapd->tkip_countermeasures) {
386 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
387 goto fail;
388 }
389
390 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
391 auth_alg == WLAN_AUTH_OPEN) ||
392 #ifdef CONFIG_IEEE80211R
393 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
394 auth_alg == WLAN_AUTH_FT) ||
395 #endif /* CONFIG_IEEE80211R */
396 #ifdef CONFIG_SAE
397 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
398 auth_alg == WLAN_AUTH_SAE) ||
399 #endif /* CONFIG_SAE */
400 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
401 auth_alg == WLAN_AUTH_SHARED_KEY))) {
402 printf("Unsupported authentication algorithm (%d)\n",
403 auth_alg);
404 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
405 goto fail;
406 }
407
408 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
409 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
410 printf("Unknown authentication transaction number (%d)\n",
411 auth_transaction);
412 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
413 goto fail;
414 }
415
416 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
417 printf("Station " MACSTR " not allowed to authenticate.\n",
418 MAC2STR(mgmt->sa));
419 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
420 goto fail;
421 }
422
423 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
424 &session_timeout,
425 &acct_interim_interval, &vlan_id,
426 psk, &has_psk, &identity, &radius_cui);
427
428 if (res == HOSTAPD_ACL_REJECT) {
429 printf("Station " MACSTR " not allowed to authenticate.\n",
430 MAC2STR(mgmt->sa));
431 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
432 goto fail;
433 }
434 if (res == HOSTAPD_ACL_PENDING) {
435 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
436 " waiting for an external authentication",
437 MAC2STR(mgmt->sa));
438 /* Authentication code will re-send the authentication frame
439 * after it has received (and cached) information from the
440 * external source. */
441 return;
442 }
443
444 sta = ap_sta_add(hapd, mgmt->sa);
445 if (!sta) {
446 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
447 goto fail;
448 }
449
450 if (vlan_id > 0) {
451 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
452 vlan_id) == NULL) {
453 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
454 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
455 "%d received from RADIUS server",
456 vlan_id);
457 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
458 goto fail;
459 }
460 sta->vlan_id = vlan_id;
461 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
462 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
463 }
464
465 if (has_psk && hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
466 os_free(sta->psk);
467 sta->psk = os_malloc(PMK_LEN);
468 if (sta->psk)
469 os_memcpy(sta->psk, psk, PMK_LEN);
470 } else {
471 os_free(sta->psk);
472 sta->psk = NULL;
473 }
474
475 sta->identity = identity;
476 identity = NULL;
477 sta->radius_cui = radius_cui;
478 radius_cui = NULL;
479
480 sta->flags &= ~WLAN_STA_PREAUTH;
481 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
482
483 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
484 sta->acct_interim_interval = acct_interim_interval;
485 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
486 ap_sta_session_timeout(hapd, sta, session_timeout);
487 else
488 ap_sta_no_session_timeout(hapd, sta);
489
490 switch (auth_alg) {
491 case WLAN_AUTH_OPEN:
492 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
493 HOSTAPD_LEVEL_DEBUG,
494 "authentication OK (open system)");
495 #ifdef IEEE80211_REQUIRE_AUTH_ACK
496 /* Station will be marked authenticated if it ACKs the
497 * authentication reply. */
498 #else
499 sta->flags |= WLAN_STA_AUTH;
500 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
501 sta->auth_alg = WLAN_AUTH_OPEN;
502 mlme_authenticate_indication(hapd, sta);
503 #endif
504 break;
505 case WLAN_AUTH_SHARED_KEY:
506 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
507 fc & WLAN_FC_ISWEP);
508 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
509 mlme_authenticate_indication(hapd, sta);
510 if (sta->challenge && auth_transaction == 1) {
511 resp_ies[0] = WLAN_EID_CHALLENGE;
512 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
513 os_memcpy(resp_ies + 2, sta->challenge,
514 WLAN_AUTH_CHALLENGE_LEN);
515 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
516 }
517 break;
518 #ifdef CONFIG_IEEE80211R
519 case WLAN_AUTH_FT:
520 sta->auth_alg = WLAN_AUTH_FT;
521 if (sta->wpa_sm == NULL)
522 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
523 sta->addr);
524 if (sta->wpa_sm == NULL) {
525 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
526 "state machine");
527 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
528 goto fail;
529 }
530 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
531 auth_transaction, mgmt->u.auth.variable,
532 len - IEEE80211_HDRLEN -
533 sizeof(mgmt->u.auth),
534 handle_auth_ft_finish, hapd);
535 /* handle_auth_ft_finish() callback will complete auth. */
536 return;
537 #endif /* CONFIG_IEEE80211R */
538 #ifdef CONFIG_SAE
539 case WLAN_AUTH_SAE:
540 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
541 return;
542 #endif /* CONFIG_SAE */
543 }
544
545 fail:
546 os_free(identity);
547 os_free(radius_cui);
548
549 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
550 auth_transaction + 1, resp, resp_ies, resp_ies_len);
551 }
552
553
554 static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
555 {
556 int i, j = 32, aid;
557
558 /* get a unique AID */
559 if (sta->aid > 0) {
560 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
561 return 0;
562 }
563
564 for (i = 0; i < AID_WORDS; i++) {
565 if (hapd->sta_aid[i] == (u32) -1)
566 continue;
567 for (j = 0; j < 32; j++) {
568 if (!(hapd->sta_aid[i] & BIT(j)))
569 break;
570 }
571 if (j < 32)
572 break;
573 }
574 if (j == 32)
575 return -1;
576 aid = i * 32 + j + 1;
577 if (aid > 2007)
578 return -1;
579
580 sta->aid = aid;
581 hapd->sta_aid[i] |= BIT(j);
582 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
583 return 0;
584 }
585
586
587 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
588 const u8 *ssid_ie, size_t ssid_ie_len)
589 {
590 if (ssid_ie == NULL)
591 return WLAN_STATUS_UNSPECIFIED_FAILURE;
592
593 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
594 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
595 char ssid_txt[33];
596 ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
597 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
598 HOSTAPD_LEVEL_INFO,
599 "Station tried to associate with unknown SSID "
600 "'%s'", ssid_txt);
601 return WLAN_STATUS_UNSPECIFIED_FAILURE;
602 }
603
604 return WLAN_STATUS_SUCCESS;
605 }
606
607
608 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
609 const u8 *wmm_ie, size_t wmm_ie_len)
610 {
611 sta->flags &= ~WLAN_STA_WMM;
612 sta->qosinfo = 0;
613 if (wmm_ie && hapd->conf->wmm_enabled) {
614 struct wmm_information_element *wmm;
615
616 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
617 hostapd_logger(hapd, sta->addr,
618 HOSTAPD_MODULE_WPA,
619 HOSTAPD_LEVEL_DEBUG,
620 "invalid WMM element in association "
621 "request");
622 return WLAN_STATUS_UNSPECIFIED_FAILURE;
623 }
624
625 sta->flags |= WLAN_STA_WMM;
626 wmm = (struct wmm_information_element *) wmm_ie;
627 sta->qosinfo = wmm->qos_info;
628 }
629 return WLAN_STATUS_SUCCESS;
630 }
631
632
633 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
634 struct ieee802_11_elems *elems)
635 {
636 if (!elems->supp_rates) {
637 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
638 HOSTAPD_LEVEL_DEBUG,
639 "No supported rates element in AssocReq");
640 return WLAN_STATUS_UNSPECIFIED_FAILURE;
641 }
642
643 if (elems->supp_rates_len + elems->ext_supp_rates_len >
644 sizeof(sta->supported_rates)) {
645 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
646 HOSTAPD_LEVEL_DEBUG,
647 "Invalid supported rates element length %d+%d",
648 elems->supp_rates_len,
649 elems->ext_supp_rates_len);
650 return WLAN_STATUS_UNSPECIFIED_FAILURE;
651 }
652
653 sta->supported_rates_len = merge_byte_arrays(
654 sta->supported_rates, sizeof(sta->supported_rates),
655 elems->supp_rates, elems->supp_rates_len,
656 elems->ext_supp_rates, elems->ext_supp_rates_len);
657
658 return WLAN_STATUS_SUCCESS;
659 }
660
661
662 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
663 const u8 *ies, size_t ies_len, int reassoc)
664 {
665 struct ieee802_11_elems elems;
666 u16 resp;
667 const u8 *wpa_ie;
668 size_t wpa_ie_len;
669
670 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
671 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
672 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
673 "association request");
674 return WLAN_STATUS_UNSPECIFIED_FAILURE;
675 }
676
677 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
678 if (resp != WLAN_STATUS_SUCCESS)
679 return resp;
680 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
681 if (resp != WLAN_STATUS_SUCCESS)
682 return resp;
683 resp = copy_supp_rates(hapd, sta, &elems);
684 if (resp != WLAN_STATUS_SUCCESS)
685 return resp;
686 #ifdef CONFIG_IEEE80211N
687 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
688 elems.ht_capabilities_len);
689 if (resp != WLAN_STATUS_SUCCESS)
690 return resp;
691 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
692 !(sta->flags & WLAN_STA_HT)) {
693 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
694 HOSTAPD_LEVEL_INFO, "Station does not support "
695 "mandatory HT PHY - reject association");
696 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
697 }
698 #endif /* CONFIG_IEEE80211N */
699
700 #ifdef CONFIG_IEEE80211AC
701 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
702 elems.vht_capabilities_len);
703 if (resp != WLAN_STATUS_SUCCESS)
704 return resp;
705 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
706 !(sta->flags & WLAN_STA_VHT)) {
707 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
708 HOSTAPD_LEVEL_INFO, "Station does not support "
709 "mandatory VHT PHY - reject association");
710 return WLAN_STATUS_UNSPECIFIED_FAILURE;
711 }
712 #endif /* CONFIG_IEEE80211AC */
713
714 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
715 wpa_ie = elems.rsn_ie;
716 wpa_ie_len = elems.rsn_ie_len;
717 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
718 elems.wpa_ie) {
719 wpa_ie = elems.wpa_ie;
720 wpa_ie_len = elems.wpa_ie_len;
721 } else {
722 wpa_ie = NULL;
723 wpa_ie_len = 0;
724 }
725
726 #ifdef CONFIG_WPS
727 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
728 if (hapd->conf->wps_state && elems.wps_ie) {
729 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
730 "Request - assume WPS is used");
731 sta->flags |= WLAN_STA_WPS;
732 wpabuf_free(sta->wps_ie);
733 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
734 WPS_IE_VENDOR_TYPE);
735 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
736 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
737 sta->flags |= WLAN_STA_WPS2;
738 }
739 wpa_ie = NULL;
740 wpa_ie_len = 0;
741 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
742 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
743 "(Re)Association Request - reject");
744 return WLAN_STATUS_INVALID_IE;
745 }
746 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
747 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
748 "(Re)Association Request - possible WPS use");
749 sta->flags |= WLAN_STA_MAYBE_WPS;
750 } else
751 #endif /* CONFIG_WPS */
752 if (hapd->conf->wpa && wpa_ie == NULL) {
753 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
754 HOSTAPD_LEVEL_INFO,
755 "No WPA/RSN IE in association request");
756 return WLAN_STATUS_INVALID_IE;
757 }
758
759 if (hapd->conf->wpa && wpa_ie) {
760 int res;
761 wpa_ie -= 2;
762 wpa_ie_len += 2;
763 if (sta->wpa_sm == NULL)
764 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
765 sta->addr);
766 if (sta->wpa_sm == NULL) {
767 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
768 "state machine");
769 return WLAN_STATUS_UNSPECIFIED_FAILURE;
770 }
771 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
772 wpa_ie, wpa_ie_len,
773 elems.mdie, elems.mdie_len);
774 if (res == WPA_INVALID_GROUP)
775 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
776 else if (res == WPA_INVALID_PAIRWISE)
777 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
778 else if (res == WPA_INVALID_AKMP)
779 resp = WLAN_STATUS_AKMP_NOT_VALID;
780 else if (res == WPA_ALLOC_FAIL)
781 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
782 #ifdef CONFIG_IEEE80211W
783 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
784 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
785 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
786 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
787 #endif /* CONFIG_IEEE80211W */
788 else if (res == WPA_INVALID_MDIE)
789 resp = WLAN_STATUS_INVALID_MDIE;
790 else if (res != WPA_IE_OK)
791 resp = WLAN_STATUS_INVALID_IE;
792 if (resp != WLAN_STATUS_SUCCESS)
793 return resp;
794 #ifdef CONFIG_IEEE80211W
795 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
796 sta->sa_query_count > 0)
797 ap_check_sa_query_timeout(hapd, sta);
798 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
799 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
800 /*
801 * STA has already been associated with MFP and SA
802 * Query timeout has not been reached. Reject the
803 * association attempt temporarily and start SA Query,
804 * if one is not pending.
805 */
806
807 if (sta->sa_query_count == 0)
808 ap_sta_start_sa_query(hapd, sta);
809
810 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
811 }
812
813 if (wpa_auth_uses_mfp(sta->wpa_sm))
814 sta->flags |= WLAN_STA_MFP;
815 else
816 sta->flags &= ~WLAN_STA_MFP;
817 #endif /* CONFIG_IEEE80211W */
818
819 #ifdef CONFIG_IEEE80211R
820 if (sta->auth_alg == WLAN_AUTH_FT) {
821 if (!reassoc) {
822 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
823 "to use association (not "
824 "re-association) with FT auth_alg",
825 MAC2STR(sta->addr));
826 return WLAN_STATUS_UNSPECIFIED_FAILURE;
827 }
828
829 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
830 ies_len);
831 if (resp != WLAN_STATUS_SUCCESS)
832 return resp;
833 }
834 #endif /* CONFIG_IEEE80211R */
835
836 #ifdef CONFIG_SAE
837 if (wpa_auth_uses_sae(sta->wpa_sm) &&
838 sta->auth_alg != WLAN_AUTH_SAE) {
839 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
840 "SAE AKM after non-SAE auth_alg %u",
841 MAC2STR(sta->addr), sta->auth_alg);
842 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
843 }
844 #endif /* CONFIG_SAE */
845
846 #ifdef CONFIG_IEEE80211N
847 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
848 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
849 hostapd_logger(hapd, sta->addr,
850 HOSTAPD_MODULE_IEEE80211,
851 HOSTAPD_LEVEL_INFO,
852 "Station tried to use TKIP with HT "
853 "association");
854 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
855 }
856 #endif /* CONFIG_IEEE80211N */
857 } else
858 wpa_auth_sta_no_wpa(sta->wpa_sm);
859
860 #ifdef CONFIG_P2P
861 if (elems.p2p) {
862 wpabuf_free(sta->p2p_ie);
863 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
864 P2P_IE_VENDOR_TYPE);
865
866 } else {
867 wpabuf_free(sta->p2p_ie);
868 sta->p2p_ie = NULL;
869 }
870
871 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
872 #endif /* CONFIG_P2P */
873
874 return WLAN_STATUS_SUCCESS;
875 }
876
877
878 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
879 u16 reason_code)
880 {
881 int send_len;
882 struct ieee80211_mgmt reply;
883
884 os_memset(&reply, 0, sizeof(reply));
885 reply.frame_control =
886 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
887 os_memcpy(reply.da, addr, ETH_ALEN);
888 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
889 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
890
891 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
892 reply.u.deauth.reason_code = host_to_le16(reason_code);
893
894 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
895 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
896 strerror(errno));
897 }
898
899
900 static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
901 u16 status_code, int reassoc, const u8 *ies,
902 size_t ies_len)
903 {
904 int send_len;
905 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
906 struct ieee80211_mgmt *reply;
907 u8 *p;
908
909 os_memset(buf, 0, sizeof(buf));
910 reply = (struct ieee80211_mgmt *) buf;
911 reply->frame_control =
912 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
913 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
914 WLAN_FC_STYPE_ASSOC_RESP));
915 os_memcpy(reply->da, sta->addr, ETH_ALEN);
916 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
917 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
918
919 send_len = IEEE80211_HDRLEN;
920 send_len += sizeof(reply->u.assoc_resp);
921 reply->u.assoc_resp.capab_info =
922 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
923 reply->u.assoc_resp.status_code = host_to_le16(status_code);
924 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
925 | BIT(14) | BIT(15));
926 /* Supported rates */
927 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
928 /* Extended supported rates */
929 p = hostapd_eid_ext_supp_rates(hapd, p);
930
931 #ifdef CONFIG_IEEE80211R
932 if (status_code == WLAN_STATUS_SUCCESS) {
933 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
934 * Transition Information, RSN, [RIC Response] */
935 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
936 buf + sizeof(buf) - p,
937 sta->auth_alg, ies, ies_len);
938 }
939 #endif /* CONFIG_IEEE80211R */
940
941 #ifdef CONFIG_IEEE80211W
942 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
943 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
944 #endif /* CONFIG_IEEE80211W */
945
946 #ifdef CONFIG_IEEE80211N
947 p = hostapd_eid_ht_capabilities(hapd, p);
948 p = hostapd_eid_ht_operation(hapd, p);
949 #endif /* CONFIG_IEEE80211N */
950
951 #ifdef CONFIG_IEEE80211AC
952 p = hostapd_eid_vht_capabilities(hapd, p);
953 p = hostapd_eid_vht_operation(hapd, p);
954 #endif /* CONFIG_IEEE80211AC */
955
956 p = hostapd_eid_ext_capab(hapd, p);
957 p = hostapd_eid_bss_max_idle_period(hapd, p);
958
959 if (sta->flags & WLAN_STA_WMM)
960 p = hostapd_eid_wmm(hapd, p);
961
962 #ifdef CONFIG_WPS
963 if ((sta->flags & WLAN_STA_WPS) ||
964 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
965 struct wpabuf *wps = wps_build_assoc_resp_ie();
966 if (wps) {
967 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
968 p += wpabuf_len(wps);
969 wpabuf_free(wps);
970 }
971 }
972 #endif /* CONFIG_WPS */
973
974 #ifdef CONFIG_P2P
975 if (sta->p2p_ie) {
976 struct wpabuf *p2p_resp_ie;
977 enum p2p_status_code status;
978 switch (status_code) {
979 case WLAN_STATUS_SUCCESS:
980 status = P2P_SC_SUCCESS;
981 break;
982 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
983 status = P2P_SC_FAIL_LIMIT_REACHED;
984 break;
985 default:
986 status = P2P_SC_FAIL_INVALID_PARAMS;
987 break;
988 }
989 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
990 if (p2p_resp_ie) {
991 os_memcpy(p, wpabuf_head(p2p_resp_ie),
992 wpabuf_len(p2p_resp_ie));
993 p += wpabuf_len(p2p_resp_ie);
994 wpabuf_free(p2p_resp_ie);
995 }
996 }
997 #endif /* CONFIG_P2P */
998
999 #ifdef CONFIG_P2P_MANAGER
1000 if (hapd->conf->p2p & P2P_MANAGE)
1001 p = hostapd_eid_p2p_manage(hapd, p);
1002 #endif /* CONFIG_P2P_MANAGER */
1003
1004 send_len += p - reply->u.assoc_resp.variable;
1005
1006 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
1007 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1008 strerror(errno));
1009 }
1010
1011
1012 static void handle_assoc(struct hostapd_data *hapd,
1013 const struct ieee80211_mgmt *mgmt, size_t len,
1014 int reassoc)
1015 {
1016 u16 capab_info, listen_interval;
1017 u16 resp = WLAN_STATUS_SUCCESS;
1018 const u8 *pos;
1019 int left, i;
1020 struct sta_info *sta;
1021
1022 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1023 sizeof(mgmt->u.assoc_req))) {
1024 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
1025 "\n", reassoc, (unsigned long) len);
1026 return;
1027 }
1028
1029 if (reassoc) {
1030 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1031 listen_interval = le_to_host16(
1032 mgmt->u.reassoc_req.listen_interval);
1033 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1034 " capab_info=0x%02x listen_interval=%d current_ap="
1035 MACSTR,
1036 MAC2STR(mgmt->sa), capab_info, listen_interval,
1037 MAC2STR(mgmt->u.reassoc_req.current_ap));
1038 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1039 pos = mgmt->u.reassoc_req.variable;
1040 } else {
1041 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1042 listen_interval = le_to_host16(
1043 mgmt->u.assoc_req.listen_interval);
1044 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1045 " capab_info=0x%02x listen_interval=%d",
1046 MAC2STR(mgmt->sa), capab_info, listen_interval);
1047 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1048 pos = mgmt->u.assoc_req.variable;
1049 }
1050
1051 sta = ap_get_sta(hapd, mgmt->sa);
1052 #ifdef CONFIG_IEEE80211R
1053 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1054 (sta->flags & WLAN_STA_AUTH) == 0) {
1055 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1056 "prior to authentication since it is using "
1057 "over-the-DS FT", MAC2STR(mgmt->sa));
1058 } else
1059 #endif /* CONFIG_IEEE80211R */
1060 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1061 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1062 HOSTAPD_LEVEL_INFO, "Station tried to "
1063 "associate before authentication "
1064 "(aid=%d flags=0x%x)",
1065 sta ? sta->aid : -1,
1066 sta ? sta->flags : 0);
1067 send_deauth(hapd, mgmt->sa,
1068 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1069 return;
1070 }
1071
1072 if (hapd->tkip_countermeasures) {
1073 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1074 goto fail;
1075 }
1076
1077 if (listen_interval > hapd->conf->max_listen_interval) {
1078 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1079 HOSTAPD_LEVEL_DEBUG,
1080 "Too large Listen Interval (%d)",
1081 listen_interval);
1082 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1083 goto fail;
1084 }
1085
1086 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1087 * is used */
1088 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1089 if (resp != WLAN_STATUS_SUCCESS)
1090 goto fail;
1091
1092 if (hostapd_get_aid(hapd, sta) < 0) {
1093 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1094 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1095 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1096 goto fail;
1097 }
1098
1099 sta->capability = capab_info;
1100 sta->listen_interval = listen_interval;
1101
1102 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1103 sta->flags |= WLAN_STA_NONERP;
1104 for (i = 0; i < sta->supported_rates_len; i++) {
1105 if ((sta->supported_rates[i] & 0x7f) > 22) {
1106 sta->flags &= ~WLAN_STA_NONERP;
1107 break;
1108 }
1109 }
1110 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1111 sta->nonerp_set = 1;
1112 hapd->iface->num_sta_non_erp++;
1113 if (hapd->iface->num_sta_non_erp == 1)
1114 ieee802_11_set_beacons(hapd->iface);
1115 }
1116
1117 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1118 !sta->no_short_slot_time_set) {
1119 sta->no_short_slot_time_set = 1;
1120 hapd->iface->num_sta_no_short_slot_time++;
1121 if (hapd->iface->current_mode->mode ==
1122 HOSTAPD_MODE_IEEE80211G &&
1123 hapd->iface->num_sta_no_short_slot_time == 1)
1124 ieee802_11_set_beacons(hapd->iface);
1125 }
1126
1127 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1128 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1129 else
1130 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1131
1132 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1133 !sta->no_short_preamble_set) {
1134 sta->no_short_preamble_set = 1;
1135 hapd->iface->num_sta_no_short_preamble++;
1136 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1137 && hapd->iface->num_sta_no_short_preamble == 1)
1138 ieee802_11_set_beacons(hapd->iface);
1139 }
1140
1141 #ifdef CONFIG_IEEE80211N
1142 update_ht_state(hapd, sta);
1143 #endif /* CONFIG_IEEE80211N */
1144
1145 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1146 HOSTAPD_LEVEL_DEBUG,
1147 "association OK (aid %d)", sta->aid);
1148 /* Station will be marked associated, after it acknowledges AssocResp
1149 */
1150 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1151
1152 #ifdef CONFIG_IEEE80211W
1153 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1154 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1155 "SA Query procedure", reassoc ? "re" : "");
1156 /* TODO: Send a protected Disassociate frame to the STA using
1157 * the old key and Reason Code "Previous Authentication no
1158 * longer valid". Make sure this is only sent protected since
1159 * unprotected frame would be received by the STA that is now
1160 * trying to associate.
1161 */
1162 }
1163 #endif /* CONFIG_IEEE80211W */
1164
1165 if (reassoc) {
1166 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1167 ETH_ALEN);
1168 }
1169
1170 if (sta->last_assoc_req)
1171 os_free(sta->last_assoc_req);
1172 sta->last_assoc_req = os_malloc(len);
1173 if (sta->last_assoc_req)
1174 os_memcpy(sta->last_assoc_req, mgmt, len);
1175
1176 /* Make sure that the previously registered inactivity timer will not
1177 * remove the STA immediately. */
1178 sta->timeout_next = STA_NULLFUNC;
1179
1180 fail:
1181 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1182 }
1183
1184
1185 static void handle_disassoc(struct hostapd_data *hapd,
1186 const struct ieee80211_mgmt *mgmt, size_t len)
1187 {
1188 struct sta_info *sta;
1189
1190 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1191 printf("handle_disassoc - too short payload (len=%lu)\n",
1192 (unsigned long) len);
1193 return;
1194 }
1195
1196 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1197 MAC2STR(mgmt->sa),
1198 le_to_host16(mgmt->u.disassoc.reason_code));
1199
1200 sta = ap_get_sta(hapd, mgmt->sa);
1201 if (sta == NULL) {
1202 printf("Station " MACSTR " trying to disassociate, but it "
1203 "is not associated.\n", MAC2STR(mgmt->sa));
1204 return;
1205 }
1206
1207 ap_sta_set_authorized(hapd, sta, 0);
1208 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1209 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1210 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1211 HOSTAPD_LEVEL_INFO, "disassociated");
1212 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1213 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1214 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1215 * authenticated. */
1216 accounting_sta_stop(hapd, sta);
1217 ieee802_1x_free_station(sta);
1218 hostapd_drv_sta_remove(hapd, sta->addr);
1219
1220 if (sta->timeout_next == STA_NULLFUNC ||
1221 sta->timeout_next == STA_DISASSOC) {
1222 sta->timeout_next = STA_DEAUTH;
1223 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1224 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1225 hapd, sta);
1226 }
1227
1228 mlme_disassociate_indication(
1229 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1230 }
1231
1232
1233 static void handle_deauth(struct hostapd_data *hapd,
1234 const struct ieee80211_mgmt *mgmt, size_t len)
1235 {
1236 struct sta_info *sta;
1237
1238 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1239 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1240 "payload (len=%lu)", (unsigned long) len);
1241 return;
1242 }
1243
1244 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
1245 " reason_code=%d",
1246 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1247
1248 sta = ap_get_sta(hapd, mgmt->sa);
1249 if (sta == NULL) {
1250 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1251 "to deauthenticate, but it is not authenticated",
1252 MAC2STR(mgmt->sa));
1253 return;
1254 }
1255
1256 ap_sta_set_authorized(hapd, sta, 0);
1257 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1258 WLAN_STA_ASSOC_REQ_OK);
1259 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1260 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1261 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1262 mlme_deauthenticate_indication(
1263 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1264 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1265 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1266 ap_free_sta(hapd, sta);
1267 }
1268
1269
1270 static void handle_beacon(struct hostapd_data *hapd,
1271 const struct ieee80211_mgmt *mgmt, size_t len,
1272 struct hostapd_frame_info *fi)
1273 {
1274 struct ieee802_11_elems elems;
1275
1276 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1277 printf("handle_beacon - too short payload (len=%lu)\n",
1278 (unsigned long) len);
1279 return;
1280 }
1281
1282 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1283 len - (IEEE80211_HDRLEN +
1284 sizeof(mgmt->u.beacon)), &elems,
1285 0);
1286
1287 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1288 }
1289
1290
1291 #ifdef CONFIG_IEEE80211W
1292
1293 static void hostapd_sa_query_action(struct hostapd_data *hapd,
1294 const struct ieee80211_mgmt *mgmt,
1295 size_t len)
1296 {
1297 const u8 *end;
1298
1299 end = mgmt->u.action.u.sa_query_resp.trans_id +
1300 WLAN_SA_QUERY_TR_ID_LEN;
1301 if (((u8 *) mgmt) + len < end) {
1302 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1303 "frame (len=%lu)", (unsigned long) len);
1304 return;
1305 }
1306
1307 ieee802_11_sa_query_action(hapd, mgmt->sa,
1308 mgmt->u.action.u.sa_query_resp.action,
1309 mgmt->u.action.u.sa_query_resp.trans_id);
1310 }
1311
1312
1313 static int robust_action_frame(u8 category)
1314 {
1315 return category != WLAN_ACTION_PUBLIC &&
1316 category != WLAN_ACTION_HT;
1317 }
1318 #endif /* CONFIG_IEEE80211W */
1319
1320
1321 static void handle_action(struct hostapd_data *hapd,
1322 const struct ieee80211_mgmt *mgmt, size_t len)
1323 {
1324 #if defined(CONFIG_IEEE80211W) || defined(CONFIG_IEEE80211R)
1325 struct sta_info *sta;
1326 sta = ap_get_sta(hapd, mgmt->sa);
1327 #endif /* CONFIG_IEEE80211W || CONFIG_IEEE80211R */
1328
1329 if (len < IEEE80211_HDRLEN + 1) {
1330 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1331 HOSTAPD_LEVEL_DEBUG,
1332 "handle_action - too short payload (len=%lu)",
1333 (unsigned long) len);
1334 return;
1335 }
1336
1337 #ifdef CONFIG_IEEE80211W
1338 if (sta && (sta->flags & WLAN_STA_MFP) &&
1339 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP) &&
1340 robust_action_frame(mgmt->u.action.category))) {
1341 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1342 HOSTAPD_LEVEL_DEBUG,
1343 "Dropped unprotected Robust Action frame from "
1344 "an MFP STA");
1345 return;
1346 }
1347 #endif /* CONFIG_IEEE80211W */
1348
1349 switch (mgmt->u.action.category) {
1350 #ifdef CONFIG_IEEE80211R
1351 case WLAN_ACTION_FT:
1352 {
1353 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1354 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
1355 "frame from unassociated STA " MACSTR,
1356 MAC2STR(mgmt->sa));
1357 return;
1358 }
1359
1360 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1361 len - IEEE80211_HDRLEN))
1362 break;
1363
1364 return;
1365 }
1366 #endif /* CONFIG_IEEE80211R */
1367 case WLAN_ACTION_WMM:
1368 hostapd_wmm_action(hapd, mgmt, len);
1369 return;
1370 #ifdef CONFIG_IEEE80211W
1371 case WLAN_ACTION_SA_QUERY:
1372 hostapd_sa_query_action(hapd, mgmt, len);
1373 return;
1374 #endif /* CONFIG_IEEE80211W */
1375 case WLAN_ACTION_PUBLIC:
1376 if (hapd->public_action_cb) {
1377 hapd->public_action_cb(hapd->public_action_cb_ctx,
1378 (u8 *) mgmt, len,
1379 hapd->iface->freq);
1380 return;
1381 }
1382 break;
1383 case WLAN_ACTION_VENDOR_SPECIFIC:
1384 if (hapd->vendor_action_cb) {
1385 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1386 (u8 *) mgmt, len,
1387 hapd->iface->freq) == 0)
1388 return;
1389 }
1390 break;
1391 }
1392
1393 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1394 HOSTAPD_LEVEL_DEBUG,
1395 "handle_action - unknown action category %d or invalid "
1396 "frame",
1397 mgmt->u.action.category);
1398 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1399 !(mgmt->sa[0] & 0x01)) {
1400 struct ieee80211_mgmt *resp;
1401
1402 /*
1403 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1404 * Return the Action frame to the source without change
1405 * except that MSB of the Category set to 1.
1406 */
1407 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1408 "frame back to sender");
1409 resp = os_malloc(len);
1410 if (resp == NULL)
1411 return;
1412 os_memcpy(resp, mgmt, len);
1413 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1414 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1415 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1416 resp->u.action.category |= 0x80;
1417
1418 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1419 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1420 "Action frame");
1421 }
1422 os_free(resp);
1423 }
1424 }
1425
1426
1427 /**
1428 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1429 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1430 * sent to)
1431 * @buf: management frame data (starting from IEEE 802.11 header)
1432 * @len: length of frame data in octets
1433 * @fi: meta data about received frame (signal level, etc.)
1434 *
1435 * Process all incoming IEEE 802.11 management frames. This will be called for
1436 * each frame received from the kernel driver through wlan#ap interface. In
1437 * addition, it can be called to re-inserted pending frames (e.g., when using
1438 * external RADIUS server as an MAC ACL).
1439 */
1440 void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1441 struct hostapd_frame_info *fi)
1442 {
1443 struct ieee80211_mgmt *mgmt;
1444 int broadcast;
1445 u16 fc, stype;
1446
1447 if (len < 24)
1448 return;
1449
1450 mgmt = (struct ieee80211_mgmt *) buf;
1451 fc = le_to_host16(mgmt->frame_control);
1452 stype = WLAN_FC_GET_STYPE(fc);
1453
1454 if (stype == WLAN_FC_STYPE_BEACON) {
1455 handle_beacon(hapd, mgmt, len, fi);
1456 return;
1457 }
1458
1459 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1460 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1461 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1462
1463 if (!broadcast &&
1464 #ifdef CONFIG_P2P
1465 /* Invitation responses can be sent with the peer MAC as BSSID */
1466 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1467 stype == WLAN_FC_STYPE_ACTION) &&
1468 #endif /* CONFIG_P2P */
1469 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1470 printf("MGMT: BSSID=" MACSTR " not our address\n",
1471 MAC2STR(mgmt->bssid));
1472 return;
1473 }
1474
1475
1476 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1477 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
1478 return;
1479 }
1480
1481 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1482 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1483 HOSTAPD_LEVEL_DEBUG,
1484 "MGMT: DA=" MACSTR " not our address",
1485 MAC2STR(mgmt->da));
1486 return;
1487 }
1488
1489 switch (stype) {
1490 case WLAN_FC_STYPE_AUTH:
1491 wpa_printf(MSG_DEBUG, "mgmt::auth");
1492 handle_auth(hapd, mgmt, len);
1493 break;
1494 case WLAN_FC_STYPE_ASSOC_REQ:
1495 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1496 handle_assoc(hapd, mgmt, len, 0);
1497 break;
1498 case WLAN_FC_STYPE_REASSOC_REQ:
1499 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1500 handle_assoc(hapd, mgmt, len, 1);
1501 break;
1502 case WLAN_FC_STYPE_DISASSOC:
1503 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1504 handle_disassoc(hapd, mgmt, len);
1505 break;
1506 case WLAN_FC_STYPE_DEAUTH:
1507 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
1508 handle_deauth(hapd, mgmt, len);
1509 break;
1510 case WLAN_FC_STYPE_ACTION:
1511 wpa_printf(MSG_DEBUG, "mgmt::action");
1512 handle_action(hapd, mgmt, len);
1513 break;
1514 default:
1515 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1516 HOSTAPD_LEVEL_DEBUG,
1517 "unknown mgmt frame subtype %d", stype);
1518 break;
1519 }
1520 }
1521
1522
1523 static void handle_auth_cb(struct hostapd_data *hapd,
1524 const struct ieee80211_mgmt *mgmt,
1525 size_t len, int ok)
1526 {
1527 u16 auth_alg, auth_transaction, status_code;
1528 struct sta_info *sta;
1529
1530 if (!ok) {
1531 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1532 HOSTAPD_LEVEL_NOTICE,
1533 "did not acknowledge authentication response");
1534 return;
1535 }
1536
1537 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1538 printf("handle_auth_cb - too short payload (len=%lu)\n",
1539 (unsigned long) len);
1540 return;
1541 }
1542
1543 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1544 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1545 status_code = le_to_host16(mgmt->u.auth.status_code);
1546
1547 sta = ap_get_sta(hapd, mgmt->da);
1548 if (!sta) {
1549 printf("handle_auth_cb: STA " MACSTR " not found\n",
1550 MAC2STR(mgmt->da));
1551 return;
1552 }
1553
1554 if (status_code == WLAN_STATUS_SUCCESS &&
1555 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1556 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1557 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1558 HOSTAPD_LEVEL_INFO, "authenticated");
1559 sta->flags |= WLAN_STA_AUTH;
1560 }
1561 }
1562
1563
1564 static void handle_assoc_cb(struct hostapd_data *hapd,
1565 const struct ieee80211_mgmt *mgmt,
1566 size_t len, int reassoc, int ok)
1567 {
1568 u16 status;
1569 struct sta_info *sta;
1570 int new_assoc = 1;
1571 struct ieee80211_ht_capabilities ht_cap;
1572
1573 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1574 sizeof(mgmt->u.assoc_resp))) {
1575 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1576 "(len=%lu)\n", reassoc, (unsigned long) len);
1577 return;
1578 }
1579
1580 sta = ap_get_sta(hapd, mgmt->da);
1581 if (!sta) {
1582 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1583 MAC2STR(mgmt->da));
1584 return;
1585 }
1586
1587 if (!ok) {
1588 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1589 HOSTAPD_LEVEL_DEBUG,
1590 "did not acknowledge association response");
1591 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
1592 return;
1593 }
1594
1595 if (reassoc)
1596 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1597 else
1598 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1599
1600 if (status != WLAN_STATUS_SUCCESS)
1601 goto fail;
1602
1603 /* Stop previous accounting session, if one is started, and allocate
1604 * new session id for the new session. */
1605 accounting_sta_stop(hapd, sta);
1606
1607 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1608 HOSTAPD_LEVEL_INFO,
1609 "associated (aid %d)",
1610 sta->aid);
1611
1612 if (sta->flags & WLAN_STA_ASSOC)
1613 new_assoc = 0;
1614 sta->flags |= WLAN_STA_ASSOC;
1615 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
1616 sta->auth_alg == WLAN_AUTH_FT) {
1617 /*
1618 * Open, static WEP, or FT protocol; no separate authorization
1619 * step.
1620 */
1621 ap_sta_set_authorized(hapd, sta, 1);
1622 }
1623
1624 if (reassoc)
1625 mlme_reassociate_indication(hapd, sta);
1626 else
1627 mlme_associate_indication(hapd, sta);
1628
1629 #ifdef CONFIG_IEEE80211W
1630 sta->sa_query_timed_out = 0;
1631 #endif /* CONFIG_IEEE80211W */
1632
1633 /*
1634 * Remove the STA entry in order to make sure the STA PS state gets
1635 * cleared and configuration gets updated in case of reassociation back
1636 * to the same AP.
1637 */
1638 hostapd_drv_sta_remove(hapd, sta->addr);
1639
1640 #ifdef CONFIG_IEEE80211N
1641 if (sta->flags & WLAN_STA_HT)
1642 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1643 #endif /* CONFIG_IEEE80211N */
1644
1645 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1646 sta->supported_rates, sta->supported_rates_len,
1647 sta->listen_interval,
1648 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1649 sta->flags, sta->qosinfo)) {
1650 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1651 HOSTAPD_LEVEL_NOTICE,
1652 "Could not add STA to kernel driver");
1653
1654 ap_sta_disconnect(hapd, sta, sta->addr,
1655 WLAN_REASON_DISASSOC_AP_BUSY);
1656
1657 goto fail;
1658 }
1659
1660 if (sta->flags & WLAN_STA_WDS)
1661 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
1662
1663 if (sta->eapol_sm == NULL) {
1664 /*
1665 * This STA does not use RADIUS server for EAP authentication,
1666 * so bind it to the selected VLAN interface now, since the
1667 * interface selection is not going to change anymore.
1668 */
1669 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1670 goto fail;
1671 } else if (sta->vlan_id) {
1672 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1673 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
1674 goto fail;
1675 }
1676
1677 hostapd_set_sta_flags(hapd, sta);
1678
1679 if (sta->auth_alg == WLAN_AUTH_FT)
1680 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1681 else
1682 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1683 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
1684
1685 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1686
1687 fail:
1688 /* Copy of the association request is not needed anymore */
1689 if (sta->last_assoc_req) {
1690 os_free(sta->last_assoc_req);
1691 sta->last_assoc_req = NULL;
1692 }
1693 }
1694
1695
1696 static void handle_deauth_cb(struct hostapd_data *hapd,
1697 const struct ieee80211_mgmt *mgmt,
1698 size_t len, int ok)
1699 {
1700 struct sta_info *sta;
1701 if (mgmt->da[0] & 0x01)
1702 return;
1703 sta = ap_get_sta(hapd, mgmt->da);
1704 if (!sta) {
1705 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
1706 " not found", MAC2STR(mgmt->da));
1707 return;
1708 }
1709 if (ok)
1710 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
1711 MAC2STR(sta->addr));
1712 else
1713 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
1714 "deauth", MAC2STR(sta->addr));
1715
1716 ap_sta_deauth_cb(hapd, sta);
1717 }
1718
1719
1720 static void handle_disassoc_cb(struct hostapd_data *hapd,
1721 const struct ieee80211_mgmt *mgmt,
1722 size_t len, int ok)
1723 {
1724 struct sta_info *sta;
1725 if (mgmt->da[0] & 0x01)
1726 return;
1727 sta = ap_get_sta(hapd, mgmt->da);
1728 if (!sta) {
1729 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
1730 " not found", MAC2STR(mgmt->da));
1731 return;
1732 }
1733 if (ok)
1734 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
1735 MAC2STR(sta->addr));
1736 else
1737 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
1738 "disassoc", MAC2STR(sta->addr));
1739
1740 ap_sta_disassoc_cb(hapd, sta);
1741 }
1742
1743
1744 /**
1745 * ieee802_11_mgmt_cb - Process management frame TX status callback
1746 * @hapd: hostapd BSS data structure (the BSS from which the management frame
1747 * was sent from)
1748 * @buf: management frame data (starting from IEEE 802.11 header)
1749 * @len: length of frame data in octets
1750 * @stype: management frame subtype from frame control field
1751 * @ok: Whether the frame was ACK'ed
1752 */
1753 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
1754 u16 stype, int ok)
1755 {
1756 const struct ieee80211_mgmt *mgmt;
1757 mgmt = (const struct ieee80211_mgmt *) buf;
1758
1759 switch (stype) {
1760 case WLAN_FC_STYPE_AUTH:
1761 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1762 handle_auth_cb(hapd, mgmt, len, ok);
1763 break;
1764 case WLAN_FC_STYPE_ASSOC_RESP:
1765 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1766 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1767 break;
1768 case WLAN_FC_STYPE_REASSOC_RESP:
1769 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1770 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1771 break;
1772 case WLAN_FC_STYPE_PROBE_RESP:
1773 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
1774 break;
1775 case WLAN_FC_STYPE_DEAUTH:
1776 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
1777 handle_deauth_cb(hapd, mgmt, len, ok);
1778 break;
1779 case WLAN_FC_STYPE_DISASSOC:
1780 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
1781 handle_disassoc_cb(hapd, mgmt, len, ok);
1782 break;
1783 case WLAN_FC_STYPE_ACTION:
1784 wpa_printf(MSG_DEBUG, "mgmt::action cb");
1785 break;
1786 default:
1787 printf("unknown mgmt cb frame subtype %d\n", stype);
1788 break;
1789 }
1790 }
1791
1792
1793 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
1794 {
1795 /* TODO */
1796 return 0;
1797 }
1798
1799
1800 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
1801 char *buf, size_t buflen)
1802 {
1803 /* TODO */
1804 return 0;
1805 }
1806
1807
1808 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
1809 const u8 *buf, size_t len, int ack)
1810 {
1811 struct sta_info *sta;
1812 struct hostapd_iface *iface = hapd->iface;
1813
1814 sta = ap_get_sta(hapd, addr);
1815 if (sta == NULL && iface->num_bss > 1) {
1816 size_t j;
1817 for (j = 0; j < iface->num_bss; j++) {
1818 hapd = iface->bss[j];
1819 sta = ap_get_sta(hapd, addr);
1820 if (sta)
1821 break;
1822 }
1823 }
1824 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
1825 return;
1826 if (sta->flags & WLAN_STA_PENDING_POLL) {
1827 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
1828 "activity poll", MAC2STR(sta->addr),
1829 ack ? "ACKed" : "did not ACK");
1830 if (ack)
1831 sta->flags &= ~WLAN_STA_PENDING_POLL;
1832 }
1833
1834 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
1835 }
1836
1837
1838 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
1839 const u8 *data, size_t len, int ack)
1840 {
1841 struct sta_info *sta;
1842 struct hostapd_iface *iface = hapd->iface;
1843
1844 sta = ap_get_sta(hapd, dst);
1845 if (sta == NULL && iface->num_bss > 1) {
1846 size_t j;
1847 for (j = 0; j < iface->num_bss; j++) {
1848 hapd = iface->bss[j];
1849 sta = ap_get_sta(hapd, dst);
1850 if (sta)
1851 break;
1852 }
1853 }
1854 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1855 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
1856 MACSTR " that is not currently associated",
1857 MAC2STR(dst));
1858 return;
1859 }
1860
1861 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
1862 }
1863
1864
1865 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
1866 {
1867 struct sta_info *sta;
1868 struct hostapd_iface *iface = hapd->iface;
1869
1870 sta = ap_get_sta(hapd, addr);
1871 if (sta == NULL && iface->num_bss > 1) {
1872 size_t j;
1873 for (j = 0; j < iface->num_bss; j++) {
1874 hapd = iface->bss[j];
1875 sta = ap_get_sta(hapd, addr);
1876 if (sta)
1877 break;
1878 }
1879 }
1880 if (sta == NULL)
1881 return;
1882 if (!(sta->flags & WLAN_STA_PENDING_POLL))
1883 return;
1884
1885 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
1886 "activity poll", MAC2STR(sta->addr));
1887 sta->flags &= ~WLAN_STA_PENDING_POLL;
1888 }
1889
1890
1891 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
1892 int wds)
1893 {
1894 struct sta_info *sta;
1895
1896 sta = ap_get_sta(hapd, src);
1897 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
1898 if (!hapd->conf->wds_sta)
1899 return;
1900
1901 if (wds && !(sta->flags & WLAN_STA_WDS)) {
1902 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
1903 "STA " MACSTR " (aid %u)",
1904 MAC2STR(sta->addr), sta->aid);
1905 sta->flags |= WLAN_STA_WDS;
1906 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
1907 }
1908 return;
1909 }
1910
1911 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
1912 MACSTR, MAC2STR(src));
1913 if (src[0] & 0x01) {
1914 /* Broadcast bit set in SA?! Ignore the frame silently. */
1915 return;
1916 }
1917
1918 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
1919 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
1920 "already been sent, but no TX status yet known - "
1921 "ignore Class 3 frame issue with " MACSTR,
1922 MAC2STR(src));
1923 return;
1924 }
1925
1926 if (sta && (sta->flags & WLAN_STA_AUTH))
1927 hostapd_drv_sta_disassoc(
1928 hapd, src,
1929 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1930 else
1931 hostapd_drv_sta_deauth(
1932 hapd, src,
1933 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1934 }
1935
1936
1937 #endif /* CONFIG_NATIVE_WINDOWS */