]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * hostapd / IEEE 802.11 Management | |
f2991170 | 3 | * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
7 | */ |
8 | ||
1057d78e | 9 | #include "utils/includes.h" |
6fc6879b JM |
10 | |
11 | #ifndef CONFIG_NATIVE_WINDOWS | |
12 | ||
1057d78e JM |
13 | #include "utils/common.h" |
14 | #include "utils/eloop.h" | |
03da66bd | 15 | #include "crypto/crypto.h" |
d136c376 JM |
16 | #include "crypto/sha256.h" |
17 | #include "crypto/random.h" | |
81f4f619 JM |
18 | #include "common/ieee802_11_defs.h" |
19 | #include "common/ieee802_11_common.h" | |
03da66bd | 20 | #include "common/wpa_ctrl.h" |
98efcc41 | 21 | #include "common/sae.h" |
03da66bd JM |
22 | #include "radius/radius.h" |
23 | #include "radius/radius_client.h" | |
e44f8bf2 | 24 | #include "p2p/p2p.h" |
ed7a09f9 | 25 | #include "wps/wps.h" |
037378ff | 26 | #include "fst/fst.h" |
6fc6879b | 27 | #include "hostapd.h" |
6fc6879b | 28 | #include "beacon.h" |
6fc6879b JM |
29 | #include "ieee802_11_auth.h" |
30 | #include "sta_info.h" | |
6fc6879b | 31 | #include "ieee802_1x.h" |
6226e38d | 32 | #include "wpa_auth.h" |
f2991170 | 33 | #include "pmksa_cache_auth.h" |
1057d78e | 34 | #include "wmm.h" |
6fc6879b JM |
35 | #include "ap_list.h" |
36 | #include "accounting.h" | |
6226e38d JM |
37 | #include "ap_config.h" |
38 | #include "ap_mlme.h" | |
dce044cc | 39 | #include "p2p_hostapd.h" |
cee7d66b | 40 | #include "ap_drv_ops.h" |
c79938a5 | 41 | #include "wnm_ap.h" |
0e2412d0 | 42 | #include "hw_features.h" |
6226e38d | 43 | #include "ieee802_11.h" |
3d7ad2f6 | 44 | #include "dfs.h" |
6fc6879b JM |
45 | |
46 | ||
47 | u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid) | |
48 | { | |
49 | u8 *pos = eid; | |
50 | int i, num, count; | |
51 | ||
52 | if (hapd->iface->current_rates == NULL) | |
53 | return eid; | |
54 | ||
55 | *pos++ = WLAN_EID_SUPP_RATES; | |
56 | num = hapd->iface->num_rates; | |
29448243 JM |
57 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
58 | num++; | |
202d97d4 JB |
59 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
60 | num++; | |
6fc6879b JM |
61 | if (num > 8) { |
62 | /* rest of the rates are encoded in Extended supported | |
63 | * rates element */ | |
64 | num = 8; | |
65 | } | |
66 | ||
67 | *pos++ = num; | |
6fc6879b JM |
68 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num; |
69 | i++) { | |
70 | count++; | |
71 | *pos = hapd->iface->current_rates[i].rate / 5; | |
72 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) | |
73 | *pos |= 0x80; | |
74 | pos++; | |
75 | } | |
76 | ||
202d97d4 JB |
77 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) { |
78 | count++; | |
29448243 | 79 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; |
202d97d4 JB |
80 | } |
81 | ||
82 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) { | |
83 | count++; | |
84 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; | |
85 | } | |
29448243 | 86 | |
6fc6879b JM |
87 | return pos; |
88 | } | |
89 | ||
90 | ||
91 | u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid) | |
92 | { | |
93 | u8 *pos = eid; | |
94 | int i, num, count; | |
95 | ||
96 | if (hapd->iface->current_rates == NULL) | |
97 | return eid; | |
98 | ||
99 | num = hapd->iface->num_rates; | |
29448243 JM |
100 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
101 | num++; | |
202d97d4 JB |
102 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
103 | num++; | |
6fc6879b JM |
104 | if (num <= 8) |
105 | return eid; | |
106 | num -= 8; | |
107 | ||
108 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
109 | *pos++ = num; | |
6fc6879b JM |
110 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8; |
111 | i++) { | |
112 | count++; | |
113 | if (count <= 8) | |
114 | continue; /* already in SuppRates IE */ | |
115 | *pos = hapd->iface->current_rates[i].rate / 5; | |
116 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) | |
117 | *pos |= 0x80; | |
118 | pos++; | |
119 | } | |
120 | ||
202d97d4 JB |
121 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) { |
122 | count++; | |
123 | if (count > 8) | |
124 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; | |
125 | } | |
126 | ||
127 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) { | |
128 | count++; | |
129 | if (count > 8) | |
130 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; | |
131 | } | |
29448243 | 132 | |
6fc6879b JM |
133 | return pos; |
134 | } | |
135 | ||
136 | ||
f41ded6f | 137 | u16 hostapd_own_capab_info(struct hostapd_data *hapd) |
6fc6879b JM |
138 | { |
139 | int capab = WLAN_CAPABILITY_ESS; | |
140 | int privacy; | |
3d7ad2f6 C |
141 | int dfs; |
142 | ||
143 | /* Check if any of configured channels require DFS */ | |
144 | dfs = hostapd_is_dfs_required(hapd->iface); | |
145 | if (dfs < 0) { | |
146 | wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d", | |
147 | dfs); | |
148 | dfs = 0; | |
149 | } | |
6fc6879b JM |
150 | |
151 | if (hapd->iface->num_sta_no_short_preamble == 0 && | |
152 | hapd->iconf->preamble == SHORT_PREAMBLE) | |
153 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; | |
154 | ||
155 | privacy = hapd->conf->ssid.wep.keys_set; | |
156 | ||
157 | if (hapd->conf->ieee802_1x && | |
158 | (hapd->conf->default_wep_key_len || | |
159 | hapd->conf->individual_wep_key_len)) | |
160 | privacy = 1; | |
161 | ||
162 | if (hapd->conf->wpa) | |
163 | privacy = 1; | |
164 | ||
a14896e8 JM |
165 | #ifdef CONFIG_HS20 |
166 | if (hapd->conf->osen) | |
167 | privacy = 1; | |
168 | #endif /* CONFIG_HS20 */ | |
169 | ||
6fc6879b JM |
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 | ||
3d7ad2f6 C |
178 | /* |
179 | * Currently, Spectrum Management capability bit is set when directly | |
180 | * requested in configuration by spectrum_mgmt_required or when AP is | |
181 | * running on DFS channel. | |
182 | * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit | |
183 | */ | |
184 | if (hapd->iface->current_mode && | |
185 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A && | |
186 | (hapd->iconf->spectrum_mgmt_required || dfs)) | |
187 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; | |
188 | ||
0629eeb4 JM |
189 | if (hapd->conf->radio_measurements) |
190 | capab |= IEEE80211_CAP_RRM; | |
191 | ||
6fc6879b JM |
192 | return capab; |
193 | } | |
194 | ||
195 | ||
7cb53ded | 196 | #ifndef CONFIG_NO_RC4 |
6fc6879b | 197 | static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta, |
b57e086c JM |
198 | u16 auth_transaction, const u8 *challenge, |
199 | int iswep) | |
6fc6879b JM |
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]; | |
0b04889f | 210 | struct os_time now; |
6fc6879b JM |
211 | int r; |
212 | sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN); | |
213 | if (sta->challenge == NULL) | |
214 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
215 | ||
0b04889f PE |
216 | os_get_time(&now); |
217 | r = os_random(); | |
218 | os_memcpy(key, &now.sec, 4); | |
6fc6879b | 219 | os_memcpy(key + 4, &r, 4); |
8ef16831 JM |
220 | rc4_skip(key, sizeof(key), 0, |
221 | sta->challenge, WLAN_AUTH_CHALLENGE_LEN); | |
6fc6879b JM |
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 || | |
34ef46ce JM |
231 | os_memcmp_const(sta->challenge, challenge, |
232 | WLAN_AUTH_CHALLENGE_LEN)) { | |
6fc6879b JM |
233 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
234 | HOSTAPD_LEVEL_INFO, | |
235 | "shared key authentication - invalid " | |
236 | "challenge-response"); | |
237 | return WLAN_STATUS_CHALLENGE_FAIL; | |
238 | } | |
239 | ||
240 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
241 | HOSTAPD_LEVEL_DEBUG, | |
242 | "authentication OK (shared key)"); | |
6fc6879b JM |
243 | sta->flags |= WLAN_STA_AUTH; |
244 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); | |
6fc6879b JM |
245 | os_free(sta->challenge); |
246 | sta->challenge = NULL; | |
247 | ||
248 | return 0; | |
249 | } | |
7cb53ded | 250 | #endif /* CONFIG_NO_RC4 */ |
6fc6879b JM |
251 | |
252 | ||
253 | static void send_auth_reply(struct hostapd_data *hapd, | |
254 | const u8 *dst, const u8 *bssid, | |
255 | u16 auth_alg, u16 auth_transaction, u16 resp, | |
256 | const u8 *ies, size_t ies_len) | |
257 | { | |
258 | struct ieee80211_mgmt *reply; | |
259 | u8 *buf; | |
260 | size_t rlen; | |
261 | ||
262 | rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len; | |
263 | buf = os_zalloc(rlen); | |
264 | if (buf == NULL) | |
265 | return; | |
266 | ||
267 | reply = (struct ieee80211_mgmt *) buf; | |
268 | reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
269 | WLAN_FC_STYPE_AUTH); | |
6fc6879b JM |
270 | os_memcpy(reply->da, dst, ETH_ALEN); |
271 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); | |
272 | os_memcpy(reply->bssid, bssid, ETH_ALEN); | |
273 | ||
274 | reply->u.auth.auth_alg = host_to_le16(auth_alg); | |
275 | reply->u.auth.auth_transaction = host_to_le16(auth_transaction); | |
276 | reply->u.auth.status_code = host_to_le16(resp); | |
277 | ||
278 | if (ies && ies_len) | |
279 | os_memcpy(reply->u.auth.variable, ies, ies_len); | |
280 | ||
281 | wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR | |
282 | " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)", | |
283 | MAC2STR(dst), auth_alg, auth_transaction, | |
284 | resp, (unsigned long) ies_len); | |
8cfa3527 | 285 | if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0) |
61323e70 | 286 | wpa_printf(MSG_INFO, "send_auth_reply: send"); |
6fc6879b JM |
287 | |
288 | os_free(buf); | |
289 | } | |
290 | ||
291 | ||
292 | #ifdef CONFIG_IEEE80211R | |
293 | static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid, | |
294 | u16 auth_transaction, u16 status, | |
295 | const u8 *ies, size_t ies_len) | |
296 | { | |
297 | struct hostapd_data *hapd = ctx; | |
298 | struct sta_info *sta; | |
299 | ||
300 | send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction, | |
301 | status, ies, ies_len); | |
302 | ||
303 | if (status != WLAN_STATUS_SUCCESS) | |
304 | return; | |
305 | ||
306 | sta = ap_get_sta(hapd, dst); | |
307 | if (sta == NULL) | |
308 | return; | |
309 | ||
310 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, | |
311 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); | |
312 | sta->flags |= WLAN_STA_AUTH; | |
313 | mlme_authenticate_indication(hapd, sta); | |
314 | } | |
315 | #endif /* CONFIG_IEEE80211R */ | |
316 | ||
317 | ||
c10347f2 | 318 | #ifdef CONFIG_SAE |
21af6d15 | 319 | |
f3b8ad4d BC |
320 | #define dot11RSNASAESync 5 /* attempts */ |
321 | ||
322 | ||
e96da42b | 323 | static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd, |
872b7545 | 324 | struct sta_info *sta, int update) |
21af6d15 JM |
325 | { |
326 | struct wpabuf *buf; | |
327 | ||
146f6c9a JM |
328 | if (hapd->conf->ssid.wpa_passphrase == NULL) { |
329 | wpa_printf(MSG_DEBUG, "SAE: No password available"); | |
330 | return NULL; | |
331 | } | |
332 | ||
872b7545 MH |
333 | if (update && |
334 | sae_prepare_commit(hapd->own_addr, sta->addr, | |
8e31e955 JM |
335 | (u8 *) hapd->conf->ssid.wpa_passphrase, |
336 | os_strlen(hapd->conf->ssid.wpa_passphrase), | |
337 | sta->sae) < 0) { | |
338 | wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE"); | |
21af6d15 | 339 | return NULL; |
8e31e955 | 340 | } |
21af6d15 | 341 | |
8e31e955 JM |
342 | buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN); |
343 | if (buf == NULL) | |
344 | return NULL; | |
872b7545 MH |
345 | sae_write_commit(sta->sae, buf, sta->sae->tmp ? |
346 | sta->sae->tmp->anti_clogging_token : NULL); | |
21af6d15 JM |
347 | |
348 | return buf; | |
349 | } | |
350 | ||
351 | ||
352 | static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd, | |
353 | struct sta_info *sta) | |
354 | { | |
355 | struct wpabuf *buf; | |
356 | ||
fb8fcc29 | 357 | buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN); |
21af6d15 JM |
358 | if (buf == NULL) |
359 | return NULL; | |
360 | ||
fb8fcc29 | 361 | sae_write_confirm(sta->sae, buf); |
21af6d15 JM |
362 | |
363 | return buf; | |
364 | } | |
365 | ||
366 | ||
e96da42b BC |
367 | static int auth_sae_send_commit(struct hostapd_data *hapd, |
368 | struct sta_info *sta, | |
872b7545 | 369 | const u8 *bssid, int update) |
e96da42b BC |
370 | { |
371 | struct wpabuf *data; | |
372 | ||
872b7545 | 373 | data = auth_build_sae_commit(hapd, sta, update); |
e96da42b BC |
374 | if (data == NULL) |
375 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
376 | ||
377 | send_auth_reply(hapd, sta->addr, bssid, | |
378 | WLAN_AUTH_SAE, 1, WLAN_STATUS_SUCCESS, | |
379 | wpabuf_head(data), wpabuf_len(data)); | |
380 | ||
381 | wpabuf_free(data); | |
382 | ||
383 | return WLAN_STATUS_SUCCESS; | |
384 | } | |
385 | ||
386 | ||
387 | static int auth_sae_send_confirm(struct hostapd_data *hapd, | |
388 | struct sta_info *sta, | |
389 | const u8 *bssid) | |
390 | { | |
391 | struct wpabuf *data; | |
392 | ||
393 | data = auth_build_sae_confirm(hapd, sta); | |
394 | if (data == NULL) | |
395 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
396 | ||
397 | send_auth_reply(hapd, sta->addr, bssid, | |
398 | WLAN_AUTH_SAE, 2, WLAN_STATUS_SUCCESS, | |
399 | wpabuf_head(data), wpabuf_len(data)); | |
400 | ||
401 | wpabuf_free(data); | |
402 | ||
403 | return WLAN_STATUS_SUCCESS; | |
404 | } | |
405 | ||
406 | ||
d136c376 JM |
407 | static int use_sae_anti_clogging(struct hostapd_data *hapd) |
408 | { | |
409 | struct sta_info *sta; | |
410 | unsigned int open = 0; | |
411 | ||
412 | if (hapd->conf->sae_anti_clogging_threshold == 0) | |
413 | return 1; | |
414 | ||
415 | for (sta = hapd->sta_list; sta; sta = sta->next) { | |
416 | if (!sta->sae) | |
417 | continue; | |
418 | if (sta->sae->state != SAE_COMMITTED && | |
419 | sta->sae->state != SAE_CONFIRMED) | |
420 | continue; | |
421 | open++; | |
422 | if (open >= hapd->conf->sae_anti_clogging_threshold) | |
423 | return 1; | |
424 | } | |
425 | ||
426 | return 0; | |
427 | } | |
428 | ||
429 | ||
430 | static int check_sae_token(struct hostapd_data *hapd, const u8 *addr, | |
431 | const u8 *token, size_t token_len) | |
432 | { | |
433 | u8 mac[SHA256_MAC_LEN]; | |
434 | ||
435 | if (token_len != SHA256_MAC_LEN) | |
436 | return -1; | |
437 | if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key), | |
438 | addr, ETH_ALEN, mac) < 0 || | |
0233dcac | 439 | os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0) |
d136c376 JM |
440 | return -1; |
441 | ||
442 | return 0; | |
443 | } | |
444 | ||
445 | ||
446 | static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd, | |
a959a3b6 | 447 | int group, const u8 *addr) |
d136c376 JM |
448 | { |
449 | struct wpabuf *buf; | |
450 | u8 *token; | |
fe52c210 | 451 | struct os_reltime now; |
d136c376 | 452 | |
fe52c210 JB |
453 | os_get_reltime(&now); |
454 | if (!os_reltime_initialized(&hapd->last_sae_token_key_update) || | |
455 | os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) { | |
a50414c3 JM |
456 | if (random_get_bytes(hapd->sae_token_key, |
457 | sizeof(hapd->sae_token_key)) < 0) | |
458 | return NULL; | |
d136c376 JM |
459 | wpa_hexdump(MSG_DEBUG, "SAE: Updated token key", |
460 | hapd->sae_token_key, sizeof(hapd->sae_token_key)); | |
fe52c210 | 461 | hapd->last_sae_token_key_update = now; |
d136c376 JM |
462 | } |
463 | ||
a959a3b6 | 464 | buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN); |
d136c376 JM |
465 | if (buf == NULL) |
466 | return NULL; | |
467 | ||
a959a3b6 MH |
468 | wpabuf_put_le16(buf, group); /* Finite Cyclic Group */ |
469 | ||
d136c376 JM |
470 | token = wpabuf_put(buf, SHA256_MAC_LEN); |
471 | hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key), | |
472 | addr, ETH_ALEN, token); | |
473 | ||
474 | return buf; | |
475 | } | |
476 | ||
477 | ||
f3b8ad4d BC |
478 | static int sae_check_big_sync(struct sta_info *sta) |
479 | { | |
480 | if (sta->sae->sync > dot11RSNASAESync) { | |
481 | sta->sae->state = SAE_NOTHING; | |
482 | sta->sae->sync = 0; | |
483 | return -1; | |
484 | } | |
485 | return 0; | |
486 | } | |
487 | ||
488 | ||
489 | static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data) | |
490 | { | |
491 | struct hostapd_data *hapd = eloop_ctx; | |
492 | struct sta_info *sta = eloop_data; | |
493 | int ret; | |
494 | ||
495 | if (sae_check_big_sync(sta)) | |
496 | return; | |
497 | sta->sae->sync++; | |
498 | ||
499 | switch (sta->sae->state) { | |
500 | case SAE_COMMITTED: | |
501 | ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0); | |
ecd40fef MH |
502 | eloop_register_timeout(0, |
503 | hapd->dot11RSNASAERetransPeriod * 1000, | |
f3b8ad4d BC |
504 | auth_sae_retransmit_timer, hapd, sta); |
505 | break; | |
506 | case SAE_CONFIRMED: | |
507 | ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr); | |
ecd40fef MH |
508 | eloop_register_timeout(0, |
509 | hapd->dot11RSNASAERetransPeriod * 1000, | |
f3b8ad4d BC |
510 | auth_sae_retransmit_timer, hapd, sta); |
511 | break; | |
512 | default: | |
513 | ret = -1; | |
514 | break; | |
515 | } | |
516 | ||
517 | if (ret != WLAN_STATUS_SUCCESS) | |
518 | wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret); | |
519 | } | |
520 | ||
521 | ||
522 | void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta) | |
523 | { | |
524 | eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta); | |
525 | } | |
526 | ||
527 | ||
528 | static void sae_set_retransmit_timer(struct hostapd_data *hapd, | |
529 | struct sta_info *sta) | |
530 | { | |
531 | if (!(hapd->conf->mesh & MESH_ENABLED)) | |
532 | return; | |
533 | ||
534 | eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta); | |
ecd40fef | 535 | eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000, |
f3b8ad4d BC |
536 | auth_sae_retransmit_timer, hapd, sta); |
537 | } | |
538 | ||
539 | ||
e96da42b BC |
540 | static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta, |
541 | const u8 *bssid, u8 auth_transaction) | |
542 | { | |
543 | int ret; | |
544 | ||
545 | if (auth_transaction != 1 && auth_transaction != 2) | |
546 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
547 | ||
548 | switch (sta->sae->state) { | |
549 | case SAE_NOTHING: | |
550 | if (auth_transaction == 1) { | |
872b7545 | 551 | ret = auth_sae_send_commit(hapd, sta, bssid, 1); |
e96da42b BC |
552 | if (ret) |
553 | return ret; | |
554 | sta->sae->state = SAE_COMMITTED; | |
555 | ||
556 | if (sae_process_commit(sta->sae) < 0) | |
557 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
558 | ||
559 | /* | |
560 | * In mesh case, both Commit and Confirm can be sent | |
561 | * immediately. In infrastructure BSS, only a single | |
562 | * Authentication frame (Commit) is expected from the AP | |
563 | * here and the second one (Confirm) will be sent once | |
564 | * the STA has sent its second Authentication frame | |
565 | * (Confirm). | |
566 | */ | |
567 | if (hapd->conf->mesh & MESH_ENABLED) { | |
568 | /* | |
569 | * Send both Commit and Confirm immediately | |
570 | * based on SAE finite state machine | |
571 | * Nothing -> Confirm transition. | |
572 | */ | |
573 | ret = auth_sae_send_confirm(hapd, sta, bssid); | |
574 | if (ret) | |
575 | return ret; | |
576 | sta->sae->state = SAE_CONFIRMED; | |
577 | } else { | |
578 | /* | |
579 | * For infrastructure BSS, send only the Commit | |
580 | * message now to get alternating sequence of | |
581 | * Authentication frames between the AP and STA. | |
582 | * Confirm will be sent in | |
583 | * Commited -> Confirmed/Accepted transition | |
584 | * when receiving Confirm from STA. | |
585 | */ | |
586 | } | |
f3b8ad4d BC |
587 | sta->sae->sync = 0; |
588 | sae_set_retransmit_timer(hapd, sta); | |
e96da42b BC |
589 | } else { |
590 | hostapd_logger(hapd, sta->addr, | |
591 | HOSTAPD_MODULE_IEEE80211, | |
592 | HOSTAPD_LEVEL_DEBUG, | |
593 | "SAE confirm before commit"); | |
594 | } | |
595 | break; | |
596 | case SAE_COMMITTED: | |
f3b8ad4d | 597 | sae_clear_retransmit_timer(hapd, sta); |
e96da42b BC |
598 | if (auth_transaction == 1) { |
599 | if (sae_process_commit(sta->sae) < 0) | |
600 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
601 | ||
602 | ret = auth_sae_send_confirm(hapd, sta, bssid); | |
603 | if (ret) | |
604 | return ret; | |
605 | sta->sae->state = SAE_CONFIRMED; | |
f3b8ad4d BC |
606 | sta->sae->sync = 0; |
607 | sae_set_retransmit_timer(hapd, sta); | |
e96da42b BC |
608 | } else if (hapd->conf->mesh & MESH_ENABLED) { |
609 | /* | |
610 | * In mesh case, follow SAE finite state machine and | |
f3b8ad4d | 611 | * send Commit now, if sync count allows. |
e96da42b | 612 | */ |
f3b8ad4d BC |
613 | if (sae_check_big_sync(sta)) |
614 | return WLAN_STATUS_SUCCESS; | |
615 | sta->sae->sync++; | |
616 | ||
fabc6dd8 | 617 | ret = auth_sae_send_commit(hapd, sta, bssid, 0); |
e96da42b BC |
618 | if (ret) |
619 | return ret; | |
f3b8ad4d BC |
620 | |
621 | sae_set_retransmit_timer(hapd, sta); | |
e96da42b BC |
622 | } else { |
623 | /* | |
624 | * For instructure BSS, send the postponed Confirm from | |
625 | * Nothing -> Confirmed transition that was reduced to | |
626 | * Nothing -> Committed above. | |
627 | */ | |
628 | ret = auth_sae_send_confirm(hapd, sta, bssid); | |
629 | if (ret) | |
630 | return ret; | |
631 | ||
632 | sta->sae->state = SAE_CONFIRMED; | |
633 | ||
634 | /* | |
635 | * Since this was triggered on Confirm RX, run another | |
636 | * step to get to Accepted without waiting for | |
637 | * additional events. | |
638 | */ | |
639 | return sae_sm_step(hapd, sta, bssid, auth_transaction); | |
640 | } | |
641 | break; | |
642 | case SAE_CONFIRMED: | |
f3b8ad4d | 643 | sae_clear_retransmit_timer(hapd, sta); |
e96da42b | 644 | if (auth_transaction == 1) { |
f3b8ad4d BC |
645 | if (sae_check_big_sync(sta)) |
646 | return WLAN_STATUS_SUCCESS; | |
647 | sta->sae->sync++; | |
648 | ||
872b7545 | 649 | ret = auth_sae_send_commit(hapd, sta, bssid, 1); |
e96da42b BC |
650 | if (ret) |
651 | return ret; | |
652 | ||
653 | if (sae_process_commit(sta->sae) < 0) | |
654 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
655 | ||
656 | ret = auth_sae_send_confirm(hapd, sta, bssid); | |
657 | if (ret) | |
658 | return ret; | |
f3b8ad4d BC |
659 | |
660 | sae_set_retransmit_timer(hapd, sta); | |
e96da42b BC |
661 | } else { |
662 | sta->flags |= WLAN_STA_AUTH; | |
663 | sta->auth_alg = WLAN_AUTH_SAE; | |
664 | mlme_authenticate_indication(hapd, sta); | |
665 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); | |
666 | sta->sae->state = SAE_ACCEPTED; | |
667 | wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr, | |
70c93963 | 668 | sta->sae->pmk, sta->sae->pmkid); |
e96da42b BC |
669 | } |
670 | break; | |
671 | case SAE_ACCEPTED: | |
672 | if (auth_transaction == 1) { | |
673 | wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR | |
674 | ") doing reauthentication", | |
675 | MAC2STR(sta->addr)); | |
676 | ap_free_sta(hapd, sta); | |
677 | } else { | |
f3b8ad4d BC |
678 | if (sae_check_big_sync(sta)) |
679 | return WLAN_STATUS_SUCCESS; | |
680 | sta->sae->sync++; | |
681 | ||
e96da42b BC |
682 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
683 | sae_clear_temp_data(sta->sae); | |
684 | if (ret) | |
685 | return ret; | |
686 | } | |
687 | break; | |
688 | default: | |
689 | wpa_printf(MSG_ERROR, "SAE: invalid state %d", | |
690 | sta->sae->state); | |
691 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
692 | } | |
693 | return WLAN_STATUS_SUCCESS; | |
694 | } | |
695 | ||
696 | ||
c10347f2 JM |
697 | static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta, |
698 | const struct ieee80211_mgmt *mgmt, size_t len, | |
afa2ffb4 | 699 | u16 auth_transaction, u16 status_code) |
c10347f2 JM |
700 | { |
701 | u16 resp = WLAN_STATUS_SUCCESS; | |
750efe6e | 702 | struct wpabuf *data = NULL; |
c10347f2 | 703 | |
98efcc41 | 704 | if (!sta->sae) { |
afa2ffb4 | 705 | if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS) |
d136c376 | 706 | return; |
98efcc41 JM |
707 | sta->sae = os_zalloc(sizeof(*sta->sae)); |
708 | if (sta->sae == NULL) | |
709 | return; | |
dd43026a | 710 | sta->sae->state = SAE_NOTHING; |
f3b8ad4d | 711 | sta->sae->sync = 0; |
98efcc41 JM |
712 | } |
713 | ||
c10347f2 | 714 | if (auth_transaction == 1) { |
a959a3b6 | 715 | const u8 *token = NULL, *pos, *end; |
d136c376 | 716 | size_t token_len = 0; |
c10347f2 JM |
717 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
718 | HOSTAPD_LEVEL_DEBUG, | |
afa2ffb4 JM |
719 | "start SAE authentication (RX commit, status=%u)", |
720 | status_code); | |
872b7545 MH |
721 | |
722 | if ((hapd->conf->mesh & MESH_ENABLED) && | |
afa2ffb4 JM |
723 | status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ && |
724 | sta->sae->tmp) { | |
a959a3b6 MH |
725 | pos = mgmt->u.auth.variable; |
726 | end = ((const u8 *) mgmt) + len; | |
727 | if (pos + sizeof(le16) > end) { | |
728 | wpa_printf(MSG_ERROR, | |
729 | "SAE: Too short anti-clogging token request"); | |
730 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
731 | goto reply; | |
732 | } | |
733 | resp = sae_group_allowed(sta->sae, | |
734 | hapd->conf->sae_groups, | |
735 | WPA_GET_LE16(pos)); | |
736 | if (resp != WLAN_STATUS_SUCCESS) { | |
737 | wpa_printf(MSG_ERROR, | |
738 | "SAE: Invalid group in anti-clogging token request"); | |
739 | goto reply; | |
740 | } | |
741 | pos += sizeof(le16); | |
742 | ||
872b7545 MH |
743 | wpabuf_free(sta->sae->tmp->anti_clogging_token); |
744 | sta->sae->tmp->anti_clogging_token = | |
a959a3b6 | 745 | wpabuf_alloc_copy(pos, end - pos); |
872b7545 MH |
746 | if (sta->sae->tmp->anti_clogging_token == NULL) { |
747 | wpa_printf(MSG_ERROR, | |
748 | "SAE: Failed to alloc for anti-clogging token"); | |
749 | return; | |
750 | } | |
751 | ||
752 | /* | |
753 | * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code | |
754 | * is 76, a new Commit Message shall be constructed | |
755 | * with the Anti-Clogging Token from the received | |
756 | * Authentication frame, and the commit-scalar and | |
757 | * COMMIT-ELEMENT previously sent. | |
758 | */ | |
759 | if (auth_sae_send_commit(hapd, sta, mgmt->bssid, 0)) { | |
760 | wpa_printf(MSG_ERROR, | |
761 | "SAE: Failed to send commit message"); | |
762 | return; | |
763 | } | |
764 | sta->sae->state = SAE_COMMITTED; | |
f3b8ad4d BC |
765 | sta->sae->sync = 0; |
766 | sae_set_retransmit_timer(hapd, sta); | |
872b7545 MH |
767 | return; |
768 | } | |
769 | ||
afa2ffb4 JM |
770 | if (status_code != WLAN_STATUS_SUCCESS) |
771 | return; | |
772 | ||
146f6c9a JM |
773 | resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable, |
774 | ((const u8 *) mgmt) + len - | |
d136c376 | 775 | mgmt->u.auth.variable, &token, |
625f202a | 776 | &token_len, hapd->conf->sae_groups); |
6a58444d JM |
777 | if (resp == SAE_SILENTLY_DISCARD) { |
778 | wpa_printf(MSG_DEBUG, | |
779 | "SAE: Drop commit message from " MACSTR " due to reflection attack", | |
780 | MAC2STR(sta->addr)); | |
781 | return; | |
782 | } | |
d136c376 JM |
783 | if (token && check_sae_token(hapd, sta->addr, token, token_len) |
784 | < 0) { | |
785 | wpa_printf(MSG_DEBUG, "SAE: Drop commit message with " | |
786 | "incorrect token from " MACSTR, | |
787 | MAC2STR(sta->addr)); | |
788 | return; | |
789 | } | |
790 | ||
e96da42b BC |
791 | if (resp != WLAN_STATUS_SUCCESS) |
792 | goto reply; | |
793 | ||
794 | if (!token && use_sae_anti_clogging(hapd)) { | |
795 | wpa_printf(MSG_DEBUG, | |
796 | "SAE: Request anti-clogging token from " | |
797 | MACSTR, MAC2STR(sta->addr)); | |
a959a3b6 MH |
798 | data = auth_build_token_req(hapd, sta->sae->group, |
799 | sta->addr); | |
e96da42b | 800 | resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ; |
872b7545 MH |
801 | if (hapd->conf->mesh & MESH_ENABLED) |
802 | sta->sae->state = SAE_NOTHING; | |
e96da42b | 803 | goto reply; |
750efe6e | 804 | } |
e96da42b BC |
805 | |
806 | resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction); | |
c10347f2 | 807 | } else if (auth_transaction == 2) { |
c10347f2 JM |
808 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
809 | HOSTAPD_LEVEL_DEBUG, | |
afa2ffb4 JM |
810 | "SAE authentication (RX confirm, status=%u)", |
811 | status_code); | |
812 | if (status_code != WLAN_STATUS_SUCCESS) | |
813 | return; | |
e96da42b BC |
814 | if (sta->sae->state >= SAE_CONFIRMED || |
815 | !(hapd->conf->mesh & MESH_ENABLED)) { | |
816 | if (sae_check_confirm(sta->sae, mgmt->u.auth.variable, | |
817 | ((u8 *) mgmt) + len - | |
818 | mgmt->u.auth.variable) < 0) { | |
750efe6e | 819 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
e96da42b | 820 | goto reply; |
b4fd3613 | 821 | } |
21af6d15 | 822 | } |
e96da42b | 823 | resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction); |
c10347f2 JM |
824 | } else { |
825 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
826 | HOSTAPD_LEVEL_DEBUG, | |
afa2ffb4 JM |
827 | "unexpected SAE authentication transaction %u (status=%u)", |
828 | auth_transaction, status_code); | |
829 | if (status_code != WLAN_STATUS_SUCCESS) | |
830 | return; | |
c10347f2 JM |
831 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
832 | } | |
833 | ||
e96da42b BC |
834 | reply: |
835 | if (resp != WLAN_STATUS_SUCCESS) { | |
836 | send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE, | |
837 | auth_transaction, resp, | |
838 | data ? wpabuf_head(data) : (u8 *) "", | |
839 | data ? wpabuf_len(data) : 0); | |
840 | } | |
21af6d15 | 841 | wpabuf_free(data); |
c10347f2 | 842 | } |
a206e2a1 BC |
843 | |
844 | ||
845 | /** | |
846 | * auth_sae_init_committed - Send COMMIT and start SAE in committed state | |
847 | * @hapd: BSS data for the device initiating the authentication | |
848 | * @sta: the peer to which commit authentication frame is sent | |
849 | * | |
850 | * This function implements Init event handling (IEEE Std 802.11-2012, | |
851 | * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the | |
852 | * sta->sae structure should be initialized appropriately via a call to | |
853 | * sae_prepare_commit(). | |
854 | */ | |
855 | int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta) | |
856 | { | |
857 | int ret; | |
858 | ||
859 | if (!sta->sae || !sta->sae->tmp) | |
860 | return -1; | |
861 | ||
862 | if (sta->sae->state != SAE_NOTHING) | |
863 | return -1; | |
864 | ||
865 | ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0); | |
866 | if (ret) | |
867 | return -1; | |
868 | ||
869 | sta->sae->state = SAE_COMMITTED; | |
f3b8ad4d BC |
870 | sta->sae->sync = 0; |
871 | sae_set_retransmit_timer(hapd, sta); | |
a206e2a1 BC |
872 | |
873 | return 0; | |
874 | } | |
875 | ||
c10347f2 JM |
876 | #endif /* CONFIG_SAE */ |
877 | ||
878 | ||
b57e086c JM |
879 | static void handle_auth(struct hostapd_data *hapd, |
880 | const struct ieee80211_mgmt *mgmt, size_t len) | |
6fc6879b JM |
881 | { |
882 | u16 auth_alg, auth_transaction, status_code; | |
883 | u16 resp = WLAN_STATUS_SUCCESS; | |
884 | struct sta_info *sta = NULL; | |
885 | int res; | |
886 | u16 fc; | |
b57e086c | 887 | const u8 *challenge = NULL; |
6fc6879b | 888 | u32 session_timeout, acct_interim_interval; |
1889af2e | 889 | struct vlan_description vlan_id; |
2ad3e6c8 | 890 | struct hostapd_sta_wpa_psk_short *psk = NULL; |
6fc6879b JM |
891 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; |
892 | size_t resp_ies_len = 0; | |
2092597f MB |
893 | char *identity = NULL; |
894 | char *radius_cui = NULL; | |
38cb0a2d | 895 | u16 seq_ctrl; |
6fc6879b | 896 | |
1889af2e MB |
897 | os_memset(&vlan_id, 0, sizeof(vlan_id)); |
898 | ||
6fc6879b | 899 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |
61323e70 JM |
900 | wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)", |
901 | (unsigned long) len); | |
6fc6879b JM |
902 | return; |
903 | } | |
904 | ||
c2aff6b1 | 905 | #ifdef CONFIG_TESTING_OPTIONS |
06df2aa6 | 906 | if (hapd->iconf->ignore_auth_probability > 0.0 && |
c2aff6b1 JB |
907 | drand48() < hapd->iconf->ignore_auth_probability) { |
908 | wpa_printf(MSG_INFO, | |
909 | "TESTING: ignoring auth frame from " MACSTR, | |
910 | MAC2STR(mgmt->sa)); | |
911 | return; | |
912 | } | |
913 | #endif /* CONFIG_TESTING_OPTIONS */ | |
914 | ||
6fc6879b JM |
915 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
916 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); | |
917 | status_code = le_to_host16(mgmt->u.auth.status_code); | |
918 | fc = le_to_host16(mgmt->frame_control); | |
38cb0a2d | 919 | seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
6fc6879b JM |
920 | |
921 | if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) + | |
922 | 2 + WLAN_AUTH_CHALLENGE_LEN && | |
923 | mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE && | |
924 | mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN) | |
925 | challenge = &mgmt->u.auth.variable[2]; | |
926 | ||
927 | wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d " | |
38cb0a2d IP |
928 | "auth_transaction=%d status_code=%d wep=%d%s " |
929 | "seq_ctrl=0x%x%s", | |
6fc6879b JM |
930 | MAC2STR(mgmt->sa), auth_alg, auth_transaction, |
931 | status_code, !!(fc & WLAN_FC_ISWEP), | |
38cb0a2d IP |
932 | challenge ? " challenge" : "", |
933 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); | |
6fc6879b | 934 | |
7cb53ded JM |
935 | #ifdef CONFIG_NO_RC4 |
936 | if (auth_alg == WLAN_AUTH_SHARED_KEY) { | |
937 | wpa_printf(MSG_INFO, | |
938 | "Unsupported authentication algorithm (%d)", | |
939 | auth_alg); | |
940 | resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; | |
941 | goto fail; | |
942 | } | |
943 | #endif /* CONFIG_NO_RC4 */ | |
944 | ||
6fc6879b JM |
945 | if (hapd->tkip_countermeasures) { |
946 | resp = WLAN_REASON_MICHAEL_MIC_FAILURE; | |
947 | goto fail; | |
948 | } | |
949 | ||
950 | if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) && | |
951 | auth_alg == WLAN_AUTH_OPEN) || | |
952 | #ifdef CONFIG_IEEE80211R | |
0bf927a0 | 953 | (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) && |
6fc6879b JM |
954 | auth_alg == WLAN_AUTH_FT) || |
955 | #endif /* CONFIG_IEEE80211R */ | |
c10347f2 JM |
956 | #ifdef CONFIG_SAE |
957 | (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) && | |
958 | auth_alg == WLAN_AUTH_SAE) || | |
959 | #endif /* CONFIG_SAE */ | |
6fc6879b JM |
960 | ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) && |
961 | auth_alg == WLAN_AUTH_SHARED_KEY))) { | |
61323e70 JM |
962 | wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)", |
963 | auth_alg); | |
6fc6879b JM |
964 | resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
965 | goto fail; | |
966 | } | |
967 | ||
c10347f2 | 968 | if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE || |
6fc6879b | 969 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) { |
61323e70 JM |
970 | wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)", |
971 | auth_transaction); | |
6fc6879b JM |
972 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
973 | goto fail; | |
974 | } | |
975 | ||
976 | if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) { | |
61323e70 JM |
977 | wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate", |
978 | MAC2STR(mgmt->sa)); | |
6fc6879b JM |
979 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
980 | goto fail; | |
981 | } | |
982 | ||
0e2412d0 JM |
983 | if (hapd->conf->no_auth_if_seen_on) { |
984 | struct hostapd_data *other; | |
985 | ||
986 | other = sta_track_seen_on(hapd->iface, mgmt->sa, | |
987 | hapd->conf->no_auth_if_seen_on); | |
988 | if (other) { | |
989 | u8 *pos; | |
990 | u32 info; | |
991 | u8 op_class, channel, phytype; | |
992 | ||
993 | wpa_printf(MSG_DEBUG, "%s: Reject authentication from " | |
994 | MACSTR " since STA has been seen on %s", | |
995 | hapd->conf->iface, MAC2STR(mgmt->sa), | |
996 | hapd->conf->no_auth_if_seen_on); | |
997 | ||
998 | resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION; | |
999 | pos = &resp_ies[0]; | |
1000 | *pos++ = WLAN_EID_NEIGHBOR_REPORT; | |
1001 | *pos++ = 13; | |
1002 | os_memcpy(pos, other->own_addr, ETH_ALEN); | |
1003 | pos += ETH_ALEN; | |
1004 | info = 0; /* TODO: BSSID Information */ | |
1005 | WPA_PUT_LE32(pos, info); | |
1006 | pos += 4; | |
1007 | if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD) | |
1008 | phytype = 8; /* dmg */ | |
1009 | else if (other->iconf->ieee80211ac) | |
1010 | phytype = 9; /* vht */ | |
1011 | else if (other->iconf->ieee80211n) | |
1012 | phytype = 7; /* ht */ | |
1013 | else if (other->iconf->hw_mode == | |
1014 | HOSTAPD_MODE_IEEE80211A) | |
1015 | phytype = 4; /* ofdm */ | |
1016 | else if (other->iconf->hw_mode == | |
1017 | HOSTAPD_MODE_IEEE80211G) | |
1018 | phytype = 6; /* erp */ | |
1019 | else | |
1020 | phytype = 5; /* hrdsss */ | |
1021 | if (ieee80211_freq_to_channel_ext( | |
1022 | hostapd_hw_get_freq(other, | |
1023 | other->iconf->channel), | |
1024 | other->iconf->secondary_channel, | |
1025 | other->iconf->ieee80211ac, | |
1026 | &op_class, &channel) == NUM_HOSTAPD_MODES) { | |
1027 | op_class = 0; | |
1028 | channel = other->iconf->channel; | |
1029 | } | |
1030 | *pos++ = op_class; | |
1031 | *pos++ = channel; | |
1032 | *pos++ = phytype; | |
1033 | resp_ies_len = pos - &resp_ies[0]; | |
1034 | goto fail; | |
1035 | } | |
1036 | } | |
1037 | ||
6fc6879b JM |
1038 | res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len, |
1039 | &session_timeout, | |
05ab9712 | 1040 | &acct_interim_interval, &vlan_id, |
2ad3e6c8 | 1041 | &psk, &identity, &radius_cui); |
05ab9712 | 1042 | |
6fc6879b | 1043 | if (res == HOSTAPD_ACL_REJECT) { |
61323e70 JM |
1044 | wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate", |
1045 | MAC2STR(mgmt->sa)); | |
6fc6879b JM |
1046 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
1047 | goto fail; | |
1048 | } | |
1049 | if (res == HOSTAPD_ACL_PENDING) { | |
1050 | wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR | |
1051 | " waiting for an external authentication", | |
1052 | MAC2STR(mgmt->sa)); | |
1053 | /* Authentication code will re-send the authentication frame | |
1054 | * after it has received (and cached) information from the | |
1055 | * external source. */ | |
1056 | return; | |
1057 | } | |
1058 | ||
38cb0a2d IP |
1059 | sta = ap_get_sta(hapd, mgmt->sa); |
1060 | if (sta) { | |
1061 | if ((fc & WLAN_FC_RETRY) && | |
1062 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && | |
1063 | sta->last_seq_ctrl == seq_ctrl && | |
1064 | sta->last_subtype == WLAN_FC_STYPE_AUTH) { | |
1065 | hostapd_logger(hapd, sta->addr, | |
1066 | HOSTAPD_MODULE_IEEE80211, | |
1067 | HOSTAPD_LEVEL_DEBUG, | |
1068 | "Drop repeated authentication frame seq_ctrl=0x%x", | |
1069 | seq_ctrl); | |
1070 | return; | |
1071 | } | |
1072 | } else { | |
c50d94f1 | 1073 | #ifdef CONFIG_MESH |
38cb0a2d IP |
1074 | if (hapd->conf->mesh & MESH_ENABLED) { |
1075 | /* if the mesh peer is not available, we don't do auth. | |
1076 | */ | |
3a322496 JM |
1077 | wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR |
1078 | " not yet known - drop Authentiation frame", | |
1079 | MAC2STR(mgmt->sa)); | |
1080 | /* | |
1081 | * Save a copy of the frame so that it can be processed | |
1082 | * if a new peer entry is added shortly after this. | |
1083 | */ | |
1084 | wpabuf_free(hapd->mesh_pending_auth); | |
1085 | hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len); | |
1086 | os_get_reltime(&hapd->mesh_pending_auth_time); | |
c50d94f1 | 1087 | return; |
38cb0a2d | 1088 | } |
c50d94f1 | 1089 | #endif /* CONFIG_MESH */ |
38cb0a2d | 1090 | |
c50d94f1 BC |
1091 | sta = ap_sta_add(hapd, mgmt->sa); |
1092 | if (!sta) { | |
1093 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; | |
1094 | goto fail; | |
1095 | } | |
6fc6879b | 1096 | } |
38cb0a2d IP |
1097 | sta->last_seq_ctrl = seq_ctrl; |
1098 | sta->last_subtype = WLAN_FC_STYPE_AUTH; | |
6fc6879b | 1099 | |
8be640b7 MB |
1100 | if (vlan_id.notempty && |
1101 | !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) { | |
6fc6879b | 1102 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
8be640b7 MB |
1103 | HOSTAPD_LEVEL_INFO, |
1104 | "Invalid VLAN %d%s received from RADIUS server", | |
1105 | vlan_id.untagged, | |
1106 | vlan_id.tagged[0] ? "+" : ""); | |
1107 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1108 | goto fail; | |
1109 | } | |
1110 | if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) { | |
1111 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1112 | goto fail; | |
6fc6879b | 1113 | } |
8be640b7 MB |
1114 | if (sta->vlan_id) |
1115 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, | |
1116 | HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id); | |
6fc6879b | 1117 | |
f2a14be7 | 1118 | hostapd_free_psk_list(sta->psk); |
5ee56c4e MB |
1119 | if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) { |
1120 | sta->psk = psk; | |
1121 | psk = NULL; | |
05ab9712 | 1122 | } else { |
05ab9712 MB |
1123 | sta->psk = NULL; |
1124 | } | |
1125 | ||
2092597f MB |
1126 | sta->identity = identity; |
1127 | identity = NULL; | |
1128 | sta->radius_cui = radius_cui; | |
1129 | radius_cui = NULL; | |
1130 | ||
6fc6879b JM |
1131 | sta->flags &= ~WLAN_STA_PREAUTH; |
1132 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); | |
1133 | ||
5843e1c9 | 1134 | if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval) |
6fc6879b JM |
1135 | sta->acct_interim_interval = acct_interim_interval; |
1136 | if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT) | |
1137 | ap_sta_session_timeout(hapd, sta, session_timeout); | |
1138 | else | |
1139 | ap_sta_no_session_timeout(hapd, sta); | |
1140 | ||
1141 | switch (auth_alg) { | |
1142 | case WLAN_AUTH_OPEN: | |
1143 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
1144 | HOSTAPD_LEVEL_DEBUG, | |
1145 | "authentication OK (open system)"); | |
6fc6879b JM |
1146 | sta->flags |= WLAN_STA_AUTH; |
1147 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); | |
1148 | sta->auth_alg = WLAN_AUTH_OPEN; | |
1149 | mlme_authenticate_indication(hapd, sta); | |
6fc6879b | 1150 | break; |
7cb53ded | 1151 | #ifndef CONFIG_NO_RC4 |
6fc6879b JM |
1152 | case WLAN_AUTH_SHARED_KEY: |
1153 | resp = auth_shared_key(hapd, sta, auth_transaction, challenge, | |
1154 | fc & WLAN_FC_ISWEP); | |
1155 | sta->auth_alg = WLAN_AUTH_SHARED_KEY; | |
1156 | mlme_authenticate_indication(hapd, sta); | |
1157 | if (sta->challenge && auth_transaction == 1) { | |
1158 | resp_ies[0] = WLAN_EID_CHALLENGE; | |
1159 | resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN; | |
1160 | os_memcpy(resp_ies + 2, sta->challenge, | |
1161 | WLAN_AUTH_CHALLENGE_LEN); | |
1162 | resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN; | |
1163 | } | |
1164 | break; | |
7cb53ded | 1165 | #endif /* CONFIG_NO_RC4 */ |
6fc6879b JM |
1166 | #ifdef CONFIG_IEEE80211R |
1167 | case WLAN_AUTH_FT: | |
1168 | sta->auth_alg = WLAN_AUTH_FT; | |
1169 | if (sta->wpa_sm == NULL) | |
1170 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
94ddef3e | 1171 | sta->addr, NULL); |
6fc6879b JM |
1172 | if (sta->wpa_sm == NULL) { |
1173 | wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA " | |
1174 | "state machine"); | |
1175 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1176 | goto fail; | |
1177 | } | |
1178 | wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid, | |
1179 | auth_transaction, mgmt->u.auth.variable, | |
1180 | len - IEEE80211_HDRLEN - | |
1181 | sizeof(mgmt->u.auth), | |
1182 | handle_auth_ft_finish, hapd); | |
1183 | /* handle_auth_ft_finish() callback will complete auth. */ | |
1184 | return; | |
1185 | #endif /* CONFIG_IEEE80211R */ | |
c10347f2 JM |
1186 | #ifdef CONFIG_SAE |
1187 | case WLAN_AUTH_SAE: | |
c50d94f1 | 1188 | #ifdef CONFIG_MESH |
afa2ffb4 JM |
1189 | if (status_code == WLAN_STATUS_SUCCESS && |
1190 | hapd->conf->mesh & MESH_ENABLED) { | |
c50d94f1 BC |
1191 | if (sta->wpa_sm == NULL) |
1192 | sta->wpa_sm = | |
1193 | wpa_auth_sta_init(hapd->wpa_auth, | |
1194 | sta->addr, NULL); | |
1195 | if (sta->wpa_sm == NULL) { | |
1196 | wpa_printf(MSG_DEBUG, | |
1197 | "SAE: Failed to initialize WPA state machine"); | |
1198 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1199 | goto fail; | |
1200 | } | |
1201 | } | |
1202 | #endif /* CONFIG_MESH */ | |
afa2ffb4 JM |
1203 | handle_auth_sae(hapd, sta, mgmt, len, auth_transaction, |
1204 | status_code); | |
c10347f2 JM |
1205 | return; |
1206 | #endif /* CONFIG_SAE */ | |
6fc6879b JM |
1207 | } |
1208 | ||
1209 | fail: | |
2092597f MB |
1210 | os_free(identity); |
1211 | os_free(radius_cui); | |
f2a14be7 | 1212 | hostapd_free_psk_list(psk); |
2092597f | 1213 | |
6fc6879b JM |
1214 | send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg, |
1215 | auth_transaction + 1, resp, resp_ies, resp_ies_len); | |
1216 | } | |
1217 | ||
1218 | ||
681753f2 | 1219 | int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta) |
d42a62b3 | 1220 | { |
2991469c JM |
1221 | int i, j = 32, aid; |
1222 | ||
d42a62b3 JM |
1223 | /* get a unique AID */ |
1224 | if (sta->aid > 0) { | |
1225 | wpa_printf(MSG_DEBUG, " old AID %d", sta->aid); | |
1226 | return 0; | |
1227 | } | |
1228 | ||
2991469c JM |
1229 | for (i = 0; i < AID_WORDS; i++) { |
1230 | if (hapd->sta_aid[i] == (u32) -1) | |
1231 | continue; | |
1232 | for (j = 0; j < 32; j++) { | |
1233 | if (!(hapd->sta_aid[i] & BIT(j))) | |
1234 | break; | |
1235 | } | |
1236 | if (j < 32) | |
d42a62b3 | 1237 | break; |
d42a62b3 | 1238 | } |
2991469c JM |
1239 | if (j == 32) |
1240 | return -1; | |
1241 | aid = i * 32 + j + 1; | |
1242 | if (aid > 2007) | |
1243 | return -1; | |
d42a62b3 | 1244 | |
2991469c JM |
1245 | sta->aid = aid; |
1246 | hapd->sta_aid[i] |= BIT(j); | |
d42a62b3 JM |
1247 | wpa_printf(MSG_DEBUG, " new AID %d", sta->aid); |
1248 | return 0; | |
1249 | } | |
1250 | ||
1251 | ||
5586f500 JM |
1252 | static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta, |
1253 | const u8 *ssid_ie, size_t ssid_ie_len) | |
6fc6879b | 1254 | { |
5586f500 JM |
1255 | if (ssid_ie == NULL) |
1256 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
6fc6879b | 1257 | |
5586f500 JM |
1258 | if (ssid_ie_len != hapd->conf->ssid.ssid_len || |
1259 | os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) { | |
5586f500 JM |
1260 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
1261 | HOSTAPD_LEVEL_INFO, | |
1262 | "Station tried to associate with unknown SSID " | |
b37d582e | 1263 | "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len)); |
5586f500 | 1264 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
b0194fe0 JM |
1265 | } |
1266 | ||
5586f500 JM |
1267 | return WLAN_STATUS_SUCCESS; |
1268 | } | |
6fc6879b | 1269 | |
6fc6879b | 1270 | |
5586f500 JM |
1271 | static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta, |
1272 | const u8 *wmm_ie, size_t wmm_ie_len) | |
1273 | { | |
3ae0800c | 1274 | sta->flags &= ~WLAN_STA_WMM; |
5d061637 | 1275 | sta->qosinfo = 0; |
5586f500 | 1276 | if (wmm_ie && hapd->conf->wmm_enabled) { |
5f32f79c | 1277 | struct wmm_information_element *wmm; |
5f32f79c | 1278 | |
c84b868a | 1279 | if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) { |
6fc6879b JM |
1280 | hostapd_logger(hapd, sta->addr, |
1281 | HOSTAPD_MODULE_WPA, | |
1282 | HOSTAPD_LEVEL_DEBUG, | |
3ae0800c | 1283 | "invalid WMM element in association " |
6fc6879b | 1284 | "request"); |
5f32f79c EP |
1285 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
1286 | } | |
1287 | ||
1288 | sta->flags |= WLAN_STA_WMM; | |
1289 | wmm = (struct wmm_information_element *) wmm_ie; | |
5d061637 | 1290 | sta->qosinfo = wmm->qos_info; |
6fc6879b | 1291 | } |
5586f500 JM |
1292 | return WLAN_STATUS_SUCCESS; |
1293 | } | |
6fc6879b | 1294 | |
5586f500 JM |
1295 | |
1296 | static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta, | |
1297 | struct ieee802_11_elems *elems) | |
1298 | { | |
1299 | if (!elems->supp_rates) { | |
1300 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
6fc6879b JM |
1301 | HOSTAPD_LEVEL_DEBUG, |
1302 | "No supported rates element in AssocReq"); | |
5586f500 | 1303 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
6fc6879b JM |
1304 | } |
1305 | ||
3489cfb0 JM |
1306 | if (elems->supp_rates_len + elems->ext_supp_rates_len > |
1307 | sizeof(sta->supported_rates)) { | |
5586f500 | 1308 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
6fc6879b | 1309 | HOSTAPD_LEVEL_DEBUG, |
3489cfb0 JM |
1310 | "Invalid supported rates element length %d+%d", |
1311 | elems->supp_rates_len, | |
1312 | elems->ext_supp_rates_len); | |
5586f500 | 1313 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
6fc6879b JM |
1314 | } |
1315 | ||
3489cfb0 JM |
1316 | sta->supported_rates_len = merge_byte_arrays( |
1317 | sta->supported_rates, sizeof(sta->supported_rates), | |
1318 | elems->supp_rates, elems->supp_rates_len, | |
1319 | elems->ext_supp_rates, elems->ext_supp_rates_len); | |
6fc6879b | 1320 | |
5586f500 JM |
1321 | return WLAN_STATUS_SUCCESS; |
1322 | } | |
1323 | ||
1324 | ||
c551700f KP |
1325 | static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta, |
1326 | const u8 *ext_capab_ie, size_t ext_capab_ie_len) | |
1327 | { | |
1328 | #ifdef CONFIG_INTERWORKING | |
1329 | /* check for QoS Map support */ | |
1330 | if (ext_capab_ie_len >= 5) { | |
1331 | if (ext_capab_ie[4] & 0x01) | |
1332 | sta->qos_map_enabled = 1; | |
1333 | } | |
1334 | #endif /* CONFIG_INTERWORKING */ | |
1335 | ||
98b05081 AO |
1336 | if (ext_capab_ie_len > 0) |
1337 | sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2)); | |
1338 | ||
c551700f KP |
1339 | return WLAN_STATUS_SUCCESS; |
1340 | } | |
1341 | ||
1342 | ||
5586f500 | 1343 | static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta, |
b57e086c | 1344 | const u8 *ies, size_t ies_len, int reassoc) |
5586f500 JM |
1345 | { |
1346 | struct ieee802_11_elems elems; | |
1347 | u16 resp; | |
ba091c06 | 1348 | const u8 *wpa_ie; |
5586f500 | 1349 | size_t wpa_ie_len; |
94ddef3e | 1350 | const u8 *p2p_dev_addr = NULL; |
5586f500 JM |
1351 | |
1352 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) { | |
1353 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
1354 | HOSTAPD_LEVEL_INFO, "Station sent an invalid " | |
1355 | "association request"); | |
1356 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1357 | } | |
1358 | ||
1359 | resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len); | |
1360 | if (resp != WLAN_STATUS_SUCCESS) | |
1361 | return resp; | |
1362 | resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len); | |
c551700f KP |
1363 | if (resp != WLAN_STATUS_SUCCESS) |
1364 | return resp; | |
1365 | resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len); | |
5586f500 JM |
1366 | if (resp != WLAN_STATUS_SUCCESS) |
1367 | return resp; | |
1368 | resp = copy_supp_rates(hapd, sta, &elems); | |
1369 | if (resp != WLAN_STATUS_SUCCESS) | |
1370 | return resp; | |
d45354be | 1371 | #ifdef CONFIG_IEEE80211N |
baae4cb9 | 1372 | resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities); |
5586f500 JM |
1373 | if (resp != WLAN_STATUS_SUCCESS) |
1374 | return resp; | |
29448243 JM |
1375 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && |
1376 | !(sta->flags & WLAN_STA_HT)) { | |
1377 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
1378 | HOSTAPD_LEVEL_INFO, "Station does not support " | |
1379 | "mandatory HT PHY - reject association"); | |
1380 | return WLAN_STATUS_ASSOC_DENIED_NO_HT; | |
1381 | } | |
d45354be | 1382 | #endif /* CONFIG_IEEE80211N */ |
5586f500 | 1383 | |
de3cdf35 | 1384 | #ifdef CONFIG_IEEE80211AC |
28ffd21c ARN |
1385 | if (hapd->iconf->ieee80211ac) { |
1386 | resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities); | |
1387 | if (resp != WLAN_STATUS_SUCCESS) | |
1388 | return resp; | |
8a458116 | 1389 | |
28ffd21c ARN |
1390 | resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif); |
1391 | if (resp != WLAN_STATUS_SUCCESS) | |
1392 | return resp; | |
1393 | } | |
8a458116 | 1394 | |
140e850a MP |
1395 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && |
1396 | !(sta->flags & WLAN_STA_VHT)) { | |
1397 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
1398 | HOSTAPD_LEVEL_INFO, "Station does not support " | |
1399 | "mandatory VHT PHY - reject association"); | |
13b24a76 | 1400 | return WLAN_STATUS_ASSOC_DENIED_NO_VHT; |
140e850a | 1401 | } |
e7d0e97b YL |
1402 | |
1403 | if (hapd->conf->vendor_vht && !elems.vht_capabilities) { | |
1404 | resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht, | |
1405 | elems.vendor_vht_len); | |
1406 | if (resp != WLAN_STATUS_SUCCESS) | |
1407 | return resp; | |
1408 | } | |
de3cdf35 MP |
1409 | #endif /* CONFIG_IEEE80211AC */ |
1410 | ||
94ddef3e JM |
1411 | #ifdef CONFIG_P2P |
1412 | if (elems.p2p) { | |
1413 | wpabuf_free(sta->p2p_ie); | |
1414 | sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len, | |
1415 | P2P_IE_VENDOR_TYPE); | |
1416 | if (sta->p2p_ie) | |
1417 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); | |
1418 | } else { | |
1419 | wpabuf_free(sta->p2p_ie); | |
1420 | sta->p2p_ie = NULL; | |
1421 | } | |
1422 | #endif /* CONFIG_P2P */ | |
1423 | ||
6fc6879b JM |
1424 | if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) { |
1425 | wpa_ie = elems.rsn_ie; | |
1426 | wpa_ie_len = elems.rsn_ie_len; | |
1427 | } else if ((hapd->conf->wpa & WPA_PROTO_WPA) && | |
1428 | elems.wpa_ie) { | |
1429 | wpa_ie = elems.wpa_ie; | |
1430 | wpa_ie_len = elems.wpa_ie_len; | |
1431 | } else { | |
1432 | wpa_ie = NULL; | |
1433 | wpa_ie_len = 0; | |
1434 | } | |
5586f500 | 1435 | |
ad08c363 | 1436 | #ifdef CONFIG_WPS |
17f6b900 | 1437 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
c47cf42e JM |
1438 | if (hapd->conf->wps_state && elems.wps_ie) { |
1439 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association " | |
1440 | "Request - assume WPS is used"); | |
1441 | sta->flags |= WLAN_STA_WPS; | |
1442 | wpabuf_free(sta->wps_ie); | |
16e46ec0 JM |
1443 | sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, |
1444 | WPS_IE_VENDOR_TYPE); | |
17f6b900 JM |
1445 | if (sta->wps_ie && wps_is_20(sta->wps_ie)) { |
1446 | wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0"); | |
1447 | sta->flags |= WLAN_STA_WPS2; | |
1448 | } | |
c47cf42e JM |
1449 | wpa_ie = NULL; |
1450 | wpa_ie_len = 0; | |
54f489be JM |
1451 | if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) { |
1452 | wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in " | |
1453 | "(Re)Association Request - reject"); | |
1454 | return WLAN_STATUS_INVALID_IE; | |
1455 | } | |
c47cf42e JM |
1456 | } else if (hapd->conf->wps_state && wpa_ie == NULL) { |
1457 | wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in " | |
1458 | "(Re)Association Request - possible WPS use"); | |
1459 | sta->flags |= WLAN_STA_MAYBE_WPS; | |
ad08c363 JM |
1460 | } else |
1461 | #endif /* CONFIG_WPS */ | |
6fc6879b | 1462 | if (hapd->conf->wpa && wpa_ie == NULL) { |
5586f500 JM |
1463 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
1464 | HOSTAPD_LEVEL_INFO, | |
1465 | "No WPA/RSN IE in association request"); | |
1466 | return WLAN_STATUS_INVALID_IE; | |
6fc6879b JM |
1467 | } |
1468 | ||
1469 | if (hapd->conf->wpa && wpa_ie) { | |
1470 | int res; | |
1471 | wpa_ie -= 2; | |
1472 | wpa_ie_len += 2; | |
1473 | if (sta->wpa_sm == NULL) | |
1474 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
94ddef3e JM |
1475 | sta->addr, |
1476 | p2p_dev_addr); | |
6fc6879b | 1477 | if (sta->wpa_sm == NULL) { |
5586f500 JM |
1478 | wpa_printf(MSG_WARNING, "Failed to initialize WPA " |
1479 | "state machine"); | |
1480 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
6fc6879b JM |
1481 | } |
1482 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, | |
1483 | wpa_ie, wpa_ie_len, | |
1484 | elems.mdie, elems.mdie_len); | |
1485 | if (res == WPA_INVALID_GROUP) | |
1486 | resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; | |
1487 | else if (res == WPA_INVALID_PAIRWISE) | |
1488 | resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; | |
1489 | else if (res == WPA_INVALID_AKMP) | |
1490 | resp = WLAN_STATUS_AKMP_NOT_VALID; | |
1491 | else if (res == WPA_ALLOC_FAIL) | |
1492 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1493 | #ifdef CONFIG_IEEE80211W | |
1494 | else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) | |
9a9876bf | 1495 | resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION; |
6fc6879b | 1496 | else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) |
9a9876bf | 1497 | resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION; |
6fc6879b JM |
1498 | #endif /* CONFIG_IEEE80211W */ |
1499 | else if (res == WPA_INVALID_MDIE) | |
1500 | resp = WLAN_STATUS_INVALID_MDIE; | |
1501 | else if (res != WPA_IE_OK) | |
1502 | resp = WLAN_STATUS_INVALID_IE; | |
1503 | if (resp != WLAN_STATUS_SUCCESS) | |
5586f500 | 1504 | return resp; |
f3f7540e | 1505 | #ifdef CONFIG_IEEE80211W |
45c94154 JM |
1506 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && |
1507 | sta->sa_query_count > 0) | |
1508 | ap_check_sa_query_timeout(hapd, sta); | |
8f4617c6 JM |
1509 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && |
1510 | (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) { | |
5d22a1d5 | 1511 | /* |
93b76319 JM |
1512 | * STA has already been associated with MFP and SA |
1513 | * Query timeout has not been reached. Reject the | |
1514 | * association attempt temporarily and start SA Query, | |
1515 | * if one is not pending. | |
5d22a1d5 JM |
1516 | */ |
1517 | ||
93b76319 JM |
1518 | if (sta->sa_query_count == 0) |
1519 | ap_sta_start_sa_query(hapd, sta); | |
5d22a1d5 | 1520 | |
5586f500 | 1521 | return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
5d22a1d5 JM |
1522 | } |
1523 | ||
f3f7540e JM |
1524 | if (wpa_auth_uses_mfp(sta->wpa_sm)) |
1525 | sta->flags |= WLAN_STA_MFP; | |
1526 | else | |
1527 | sta->flags &= ~WLAN_STA_MFP; | |
1528 | #endif /* CONFIG_IEEE80211W */ | |
6fc6879b JM |
1529 | |
1530 | #ifdef CONFIG_IEEE80211R | |
1531 | if (sta->auth_alg == WLAN_AUTH_FT) { | |
1532 | if (!reassoc) { | |
1533 | wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried " | |
1534 | "to use association (not " | |
1535 | "re-association) with FT auth_alg", | |
1536 | MAC2STR(sta->addr)); | |
5586f500 | 1537 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
6fc6879b JM |
1538 | } |
1539 | ||
5586f500 JM |
1540 | resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies, |
1541 | ies_len); | |
6fc6879b | 1542 | if (resp != WLAN_STATUS_SUCCESS) |
5586f500 | 1543 | return resp; |
6fc6879b JM |
1544 | } |
1545 | #endif /* CONFIG_IEEE80211R */ | |
5586f500 | 1546 | |
c10347f2 JM |
1547 | #ifdef CONFIG_SAE |
1548 | if (wpa_auth_uses_sae(sta->wpa_sm) && | |
f2991170 JM |
1549 | sta->auth_alg == WLAN_AUTH_OPEN) { |
1550 | struct rsn_pmksa_cache_entry *sa; | |
1551 | sa = wpa_auth_sta_get_pmksa(sta->wpa_sm); | |
1552 | if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) { | |
1553 | wpa_printf(MSG_DEBUG, | |
1554 | "SAE: No PMKSA cache entry found for " | |
1555 | MACSTR, MAC2STR(sta->addr)); | |
1556 | return WLAN_STATUS_INVALID_PMKID; | |
1557 | } | |
1558 | wpa_printf(MSG_DEBUG, "SAE: " MACSTR | |
1559 | " using PMKSA caching", MAC2STR(sta->addr)); | |
1560 | } else if (wpa_auth_uses_sae(sta->wpa_sm) && | |
1561 | sta->auth_alg != WLAN_AUTH_SAE && | |
1562 | !(sta->auth_alg == WLAN_AUTH_FT && | |
1563 | wpa_auth_uses_ft_sae(sta->wpa_sm))) { | |
c10347f2 JM |
1564 | wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use " |
1565 | "SAE AKM after non-SAE auth_alg %u", | |
1566 | MAC2STR(sta->addr), sta->auth_alg); | |
1567 | return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; | |
1568 | } | |
1569 | #endif /* CONFIG_SAE */ | |
1570 | ||
ff36ff00 | 1571 | #ifdef CONFIG_IEEE80211N |
f0c7a986 | 1572 | if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) && |
ff36ff00 | 1573 | wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) { |
5586f500 JM |
1574 | hostapd_logger(hapd, sta->addr, |
1575 | HOSTAPD_MODULE_IEEE80211, | |
1576 | HOSTAPD_LEVEL_INFO, | |
1577 | "Station tried to use TKIP with HT " | |
1578 | "association"); | |
1579 | return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; | |
ff36ff00 JM |
1580 | } |
1581 | #endif /* CONFIG_IEEE80211N */ | |
a14896e8 JM |
1582 | #ifdef CONFIG_HS20 |
1583 | } else if (hapd->conf->osen) { | |
1584 | if (elems.osen == NULL) { | |
1585 | hostapd_logger( | |
1586 | hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
1587 | HOSTAPD_LEVEL_INFO, | |
1588 | "No HS 2.0 OSEN element in association request"); | |
1589 | return WLAN_STATUS_INVALID_IE; | |
1590 | } | |
1591 | ||
1592 | wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association"); | |
1593 | if (sta->wpa_sm == NULL) | |
1594 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
1595 | sta->addr, NULL); | |
1596 | if (sta->wpa_sm == NULL) { | |
1597 | wpa_printf(MSG_WARNING, "Failed to initialize WPA " | |
1598 | "state machine"); | |
1599 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1600 | } | |
1601 | if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm, | |
1602 | elems.osen - 2, elems.osen_len + 2) < 0) | |
1603 | return WLAN_STATUS_INVALID_IE; | |
1604 | #endif /* CONFIG_HS20 */ | |
a8d05fca JM |
1605 | } else |
1606 | wpa_auth_sta_no_wpa(sta->wpa_sm); | |
6fc6879b | 1607 | |
b305c684 | 1608 | #ifdef CONFIG_P2P |
3f4ce13f | 1609 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len); |
b305c684 JM |
1610 | #endif /* CONFIG_P2P */ |
1611 | ||
f403dcd6 JM |
1612 | #ifdef CONFIG_HS20 |
1613 | wpabuf_free(sta->hs20_ie); | |
1614 | if (elems.hs20 && elems.hs20_len > 4) { | |
1615 | sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4, | |
1616 | elems.hs20_len - 4); | |
1617 | } else | |
1618 | sta->hs20_ie = NULL; | |
1619 | #endif /* CONFIG_HS20 */ | |
1620 | ||
ae667c08 AN |
1621 | #ifdef CONFIG_FST |
1622 | wpabuf_free(sta->mb_ies); | |
1623 | if (hapd->iface->fst) | |
1624 | sta->mb_ies = mb_ies_by_info(&elems.mb_ies); | |
1625 | else | |
1626 | sta->mb_ies = NULL; | |
1627 | #endif /* CONFIG_FST */ | |
1628 | ||
5586f500 JM |
1629 | return WLAN_STATUS_SUCCESS; |
1630 | } | |
1631 | ||
1632 | ||
1633 | static void send_deauth(struct hostapd_data *hapd, const u8 *addr, | |
1634 | u16 reason_code) | |
1635 | { | |
1636 | int send_len; | |
1637 | struct ieee80211_mgmt reply; | |
1638 | ||
1639 | os_memset(&reply, 0, sizeof(reply)); | |
1640 | reply.frame_control = | |
1641 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH); | |
1642 | os_memcpy(reply.da, addr, ETH_ALEN); | |
1643 | os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN); | |
1644 | os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN); | |
1645 | ||
1646 | send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth); | |
1647 | reply.u.deauth.reason_code = host_to_le16(reason_code); | |
1648 | ||
8cfa3527 | 1649 | if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0) |
5586f500 JM |
1650 | wpa_printf(MSG_INFO, "Failed to send deauth: %s", |
1651 | strerror(errno)); | |
1652 | } | |
1653 | ||
1654 | ||
1655 | static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta, | |
b57e086c | 1656 | u16 status_code, int reassoc, const u8 *ies, |
5586f500 JM |
1657 | size_t ies_len) |
1658 | { | |
1659 | int send_len; | |
1660 | u8 buf[sizeof(struct ieee80211_mgmt) + 1024]; | |
1661 | struct ieee80211_mgmt *reply; | |
1662 | u8 *p; | |
1663 | ||
1664 | os_memset(buf, 0, sizeof(buf)); | |
1665 | reply = (struct ieee80211_mgmt *) buf; | |
1666 | reply->frame_control = | |
1667 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
1668 | (reassoc ? WLAN_FC_STYPE_REASSOC_RESP : | |
1669 | WLAN_FC_STYPE_ASSOC_RESP)); | |
1670 | os_memcpy(reply->da, sta->addr, ETH_ALEN); | |
1671 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); | |
1672 | os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN); | |
1673 | ||
1674 | send_len = IEEE80211_HDRLEN; | |
1675 | send_len += sizeof(reply->u.assoc_resp); | |
1676 | reply->u.assoc_resp.capab_info = | |
f41ded6f | 1677 | host_to_le16(hostapd_own_capab_info(hapd)); |
5586f500 | 1678 | reply->u.assoc_resp.status_code = host_to_le16(status_code); |
93a1caec | 1679 | reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15)); |
5586f500 JM |
1680 | /* Supported rates */ |
1681 | p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable); | |
1682 | /* Extended supported rates */ | |
1683 | p = hostapd_eid_ext_supp_rates(hapd, p); | |
5586f500 JM |
1684 | |
1685 | #ifdef CONFIG_IEEE80211R | |
1686 | if (status_code == WLAN_STATUS_SUCCESS) { | |
1687 | /* IEEE 802.11r: Mobility Domain Information, Fast BSS | |
1688 | * Transition Information, RSN, [RIC Response] */ | |
1689 | p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p, | |
1690 | buf + sizeof(buf) - p, | |
1691 | sta->auth_alg, ies, ies_len); | |
1692 | } | |
1693 | #endif /* CONFIG_IEEE80211R */ | |
1694 | ||
1695 | #ifdef CONFIG_IEEE80211W | |
1696 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY) | |
1697 | p = hostapd_eid_assoc_comeback_time(hapd, sta, p); | |
1698 | #endif /* CONFIG_IEEE80211W */ | |
1699 | ||
1bc774a1 JM |
1700 | #ifdef CONFIG_IEEE80211N |
1701 | p = hostapd_eid_ht_capabilities(hapd, p); | |
1702 | p = hostapd_eid_ht_operation(hapd, p); | |
1703 | #endif /* CONFIG_IEEE80211N */ | |
1704 | ||
14708b50 | 1705 | #ifdef CONFIG_IEEE80211AC |
e7d0e97b YL |
1706 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) { |
1707 | p = hostapd_eid_vht_capabilities(hapd, p); | |
1708 | p = hostapd_eid_vht_operation(hapd, p); | |
1709 | } | |
14708b50 MP |
1710 | #endif /* CONFIG_IEEE80211AC */ |
1711 | ||
1161ff1e | 1712 | p = hostapd_eid_ext_capab(hapd, p); |
b6668734 | 1713 | p = hostapd_eid_bss_max_idle_period(hapd, p); |
c551700f KP |
1714 | if (sta->qos_map_enabled) |
1715 | p = hostapd_eid_qos_map_set(hapd, p); | |
1161ff1e | 1716 | |
347827ff AN |
1717 | #ifdef CONFIG_FST |
1718 | if (hapd->iface->fst_ies) { | |
1719 | os_memcpy(p, wpabuf_head(hapd->iface->fst_ies), | |
1720 | wpabuf_len(hapd->iface->fst_ies)); | |
1721 | p += wpabuf_len(hapd->iface->fst_ies); | |
1722 | } | |
1723 | #endif /* CONFIG_FST */ | |
1724 | ||
e7d0e97b YL |
1725 | #ifdef CONFIG_IEEE80211AC |
1726 | if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT)) | |
1727 | p = hostapd_eid_vendor_vht(hapd, p); | |
1728 | #endif /* CONFIG_IEEE80211AC */ | |
1729 | ||
1bc774a1 JM |
1730 | if (sta->flags & WLAN_STA_WMM) |
1731 | p = hostapd_eid_wmm(hapd, p); | |
1732 | ||
ed7a09f9 | 1733 | #ifdef CONFIG_WPS |
71093e5e JM |
1734 | if ((sta->flags & WLAN_STA_WPS) || |
1735 | ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) { | |
ed7a09f9 JM |
1736 | struct wpabuf *wps = wps_build_assoc_resp_ie(); |
1737 | if (wps) { | |
1738 | os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps)); | |
1739 | p += wpabuf_len(wps); | |
1740 | wpabuf_free(wps); | |
1741 | } | |
1742 | } | |
1743 | #endif /* CONFIG_WPS */ | |
1744 | ||
8ccbe415 | 1745 | #ifdef CONFIG_P2P |
4f6cd3f4 | 1746 | if (sta->p2p_ie && hapd->p2p_group) { |
8ccbe415 JM |
1747 | struct wpabuf *p2p_resp_ie; |
1748 | enum p2p_status_code status; | |
1749 | switch (status_code) { | |
1750 | case WLAN_STATUS_SUCCESS: | |
1751 | status = P2P_SC_SUCCESS; | |
1752 | break; | |
1753 | case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA: | |
1754 | status = P2P_SC_FAIL_LIMIT_REACHED; | |
1755 | break; | |
1756 | default: | |
1757 | status = P2P_SC_FAIL_INVALID_PARAMS; | |
1758 | break; | |
1759 | } | |
1760 | p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status); | |
1761 | if (p2p_resp_ie) { | |
1762 | os_memcpy(p, wpabuf_head(p2p_resp_ie), | |
1763 | wpabuf_len(p2p_resp_ie)); | |
1764 | p += wpabuf_len(p2p_resp_ie); | |
1765 | wpabuf_free(p2p_resp_ie); | |
1766 | } | |
1767 | } | |
1768 | #endif /* CONFIG_P2P */ | |
1769 | ||
962473c1 JM |
1770 | #ifdef CONFIG_P2P_MANAGER |
1771 | if (hapd->conf->p2p & P2P_MANAGE) | |
1772 | p = hostapd_eid_p2p_manage(hapd, p); | |
1773 | #endif /* CONFIG_P2P_MANAGER */ | |
1774 | ||
5586f500 JM |
1775 | send_len += p - reply->u.assoc_resp.variable; |
1776 | ||
8cfa3527 | 1777 | if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) |
5586f500 JM |
1778 | wpa_printf(MSG_INFO, "Failed to send assoc resp: %s", |
1779 | strerror(errno)); | |
1780 | } | |
1781 | ||
1782 | ||
1783 | static void handle_assoc(struct hostapd_data *hapd, | |
b57e086c JM |
1784 | const struct ieee80211_mgmt *mgmt, size_t len, |
1785 | int reassoc) | |
5586f500 | 1786 | { |
38cb0a2d | 1787 | u16 capab_info, listen_interval, seq_ctrl, fc; |
5586f500 | 1788 | u16 resp = WLAN_STATUS_SUCCESS; |
b57e086c | 1789 | const u8 *pos; |
5586f500 JM |
1790 | int left, i; |
1791 | struct sta_info *sta; | |
1792 | ||
1793 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) : | |
1794 | sizeof(mgmt->u.assoc_req))) { | |
61323e70 JM |
1795 | wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)", |
1796 | reassoc, (unsigned long) len); | |
5586f500 JM |
1797 | return; |
1798 | } | |
1799 | ||
c2aff6b1 JB |
1800 | #ifdef CONFIG_TESTING_OPTIONS |
1801 | if (reassoc) { | |
06df2aa6 | 1802 | if (hapd->iconf->ignore_reassoc_probability > 0.0 && |
c2aff6b1 JB |
1803 | drand48() < hapd->iconf->ignore_reassoc_probability) { |
1804 | wpa_printf(MSG_INFO, | |
1805 | "TESTING: ignoring reassoc request from " | |
1806 | MACSTR, MAC2STR(mgmt->sa)); | |
1807 | return; | |
1808 | } | |
1809 | } else { | |
06df2aa6 | 1810 | if (hapd->iconf->ignore_assoc_probability > 0.0 && |
c2aff6b1 JB |
1811 | drand48() < hapd->iconf->ignore_assoc_probability) { |
1812 | wpa_printf(MSG_INFO, | |
1813 | "TESTING: ignoring assoc request from " | |
1814 | MACSTR, MAC2STR(mgmt->sa)); | |
1815 | return; | |
1816 | } | |
1817 | } | |
1818 | #endif /* CONFIG_TESTING_OPTIONS */ | |
1819 | ||
38cb0a2d IP |
1820 | fc = le_to_host16(mgmt->frame_control); |
1821 | seq_ctrl = le_to_host16(mgmt->seq_ctrl); | |
1822 | ||
5586f500 JM |
1823 | if (reassoc) { |
1824 | capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info); | |
1825 | listen_interval = le_to_host16( | |
1826 | mgmt->u.reassoc_req.listen_interval); | |
1827 | wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR | |
1828 | " capab_info=0x%02x listen_interval=%d current_ap=" | |
38cb0a2d | 1829 | MACSTR " seq_ctrl=0x%x%s", |
5586f500 | 1830 | MAC2STR(mgmt->sa), capab_info, listen_interval, |
38cb0a2d IP |
1831 | MAC2STR(mgmt->u.reassoc_req.current_ap), |
1832 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); | |
5586f500 JM |
1833 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req)); |
1834 | pos = mgmt->u.reassoc_req.variable; | |
1835 | } else { | |
1836 | capab_info = le_to_host16(mgmt->u.assoc_req.capab_info); | |
1837 | listen_interval = le_to_host16( | |
1838 | mgmt->u.assoc_req.listen_interval); | |
1839 | wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR | |
38cb0a2d IP |
1840 | " capab_info=0x%02x listen_interval=%d " |
1841 | "seq_ctrl=0x%x%s", | |
1842 | MAC2STR(mgmt->sa), capab_info, listen_interval, | |
1843 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); | |
5586f500 JM |
1844 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req)); |
1845 | pos = mgmt->u.assoc_req.variable; | |
1846 | } | |
1847 | ||
1848 | sta = ap_get_sta(hapd, mgmt->sa); | |
1849 | #ifdef CONFIG_IEEE80211R | |
1850 | if (sta && sta->auth_alg == WLAN_AUTH_FT && | |
1851 | (sta->flags & WLAN_STA_AUTH) == 0) { | |
1852 | wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate " | |
1853 | "prior to authentication since it is using " | |
1854 | "over-the-DS FT", MAC2STR(mgmt->sa)); | |
1855 | } else | |
1856 | #endif /* CONFIG_IEEE80211R */ | |
1857 | if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) { | |
1858 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, | |
1859 | HOSTAPD_LEVEL_INFO, "Station tried to " | |
1860 | "associate before authentication " | |
1861 | "(aid=%d flags=0x%x)", | |
1862 | sta ? sta->aid : -1, | |
1863 | sta ? sta->flags : 0); | |
1864 | send_deauth(hapd, mgmt->sa, | |
1865 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); | |
1866 | return; | |
1867 | } | |
1868 | ||
38cb0a2d IP |
1869 | if ((fc & WLAN_FC_RETRY) && |
1870 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && | |
1871 | sta->last_seq_ctrl == seq_ctrl && | |
1872 | sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ : | |
1873 | WLAN_FC_STYPE_ASSOC_REQ) { | |
1874 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
1875 | HOSTAPD_LEVEL_DEBUG, | |
1876 | "Drop repeated association frame seq_ctrl=0x%x", | |
1877 | seq_ctrl); | |
1878 | return; | |
1879 | } | |
1880 | sta->last_seq_ctrl = seq_ctrl; | |
1881 | sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ : | |
1882 | WLAN_FC_STYPE_ASSOC_REQ; | |
1883 | ||
5586f500 JM |
1884 | if (hapd->tkip_countermeasures) { |
1885 | resp = WLAN_REASON_MICHAEL_MIC_FAILURE; | |
1886 | goto fail; | |
1887 | } | |
1888 | ||
1889 | if (listen_interval > hapd->conf->max_listen_interval) { | |
1890 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, | |
1891 | HOSTAPD_LEVEL_DEBUG, | |
1892 | "Too large Listen Interval (%d)", | |
1893 | listen_interval); | |
1894 | resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE; | |
1895 | goto fail; | |
1896 | } | |
1897 | ||
1898 | /* followed by SSID and Supported rates; and HT capabilities if 802.11n | |
1899 | * is used */ | |
1900 | resp = check_assoc_ies(hapd, sta, pos, left, reassoc); | |
1901 | if (resp != WLAN_STATUS_SUCCESS) | |
1902 | goto fail; | |
1903 | ||
1904 | if (hostapd_get_aid(hapd, sta) < 0) { | |
1905 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, | |
1906 | HOSTAPD_LEVEL_INFO, "No room for more AIDs"); | |
1907 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; | |
1908 | goto fail; | |
1909 | } | |
1910 | ||
1911 | sta->capability = capab_info; | |
1912 | sta->listen_interval = listen_interval; | |
1913 | ||
6fc6879b JM |
1914 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
1915 | sta->flags |= WLAN_STA_NONERP; | |
1916 | for (i = 0; i < sta->supported_rates_len; i++) { | |
1917 | if ((sta->supported_rates[i] & 0x7f) > 22) { | |
1918 | sta->flags &= ~WLAN_STA_NONERP; | |
1919 | break; | |
1920 | } | |
1921 | } | |
1922 | if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) { | |
1923 | sta->nonerp_set = 1; | |
1924 | hapd->iface->num_sta_non_erp++; | |
1925 | if (hapd->iface->num_sta_non_erp == 1) | |
1926 | ieee802_11_set_beacons(hapd->iface); | |
1927 | } | |
1928 | ||
1929 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) && | |
1930 | !sta->no_short_slot_time_set) { | |
1931 | sta->no_short_slot_time_set = 1; | |
1932 | hapd->iface->num_sta_no_short_slot_time++; | |
1933 | if (hapd->iface->current_mode->mode == | |
1934 | HOSTAPD_MODE_IEEE80211G && | |
1935 | hapd->iface->num_sta_no_short_slot_time == 1) | |
1936 | ieee802_11_set_beacons(hapd->iface); | |
1937 | } | |
1938 | ||
1939 | if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) | |
1940 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; | |
1941 | else | |
1942 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; | |
1943 | ||
1944 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && | |
1945 | !sta->no_short_preamble_set) { | |
1946 | sta->no_short_preamble_set = 1; | |
1947 | hapd->iface->num_sta_no_short_preamble++; | |
1948 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G | |
1949 | && hapd->iface->num_sta_no_short_preamble == 1) | |
1950 | ieee802_11_set_beacons(hapd->iface); | |
1951 | } | |
1952 | ||
d45354be | 1953 | #ifdef CONFIG_IEEE80211N |
5586f500 | 1954 | update_ht_state(hapd, sta); |
d45354be | 1955 | #endif /* CONFIG_IEEE80211N */ |
de9289c8 | 1956 | |
6fc6879b JM |
1957 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
1958 | HOSTAPD_LEVEL_DEBUG, | |
1959 | "association OK (aid %d)", sta->aid); | |
1960 | /* Station will be marked associated, after it acknowledges AssocResp | |
1961 | */ | |
b8281964 | 1962 | sta->flags |= WLAN_STA_ASSOC_REQ_OK; |
6fc6879b | 1963 | |
6f5c8dbd JM |
1964 | #ifdef CONFIG_IEEE80211W |
1965 | if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) { | |
1966 | wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out " | |
1967 | "SA Query procedure", reassoc ? "re" : ""); | |
1968 | /* TODO: Send a protected Disassociate frame to the STA using | |
1969 | * the old key and Reason Code "Previous Authentication no | |
1970 | * longer valid". Make sure this is only sent protected since | |
1971 | * unprotected frame would be received by the STA that is now | |
1972 | * trying to associate. | |
1973 | */ | |
1974 | } | |
1975 | #endif /* CONFIG_IEEE80211W */ | |
1976 | ||
6fc6879b JM |
1977 | /* Make sure that the previously registered inactivity timer will not |
1978 | * remove the STA immediately. */ | |
1979 | sta->timeout_next = STA_NULLFUNC; | |
1980 | ||
1981 | fail: | |
5586f500 | 1982 | send_assoc_resp(hapd, sta, resp, reassoc, pos, left); |
6fc6879b JM |
1983 | } |
1984 | ||
1985 | ||
6fc6879b | 1986 | static void handle_disassoc(struct hostapd_data *hapd, |
f8b1f695 | 1987 | const struct ieee80211_mgmt *mgmt, size_t len) |
6fc6879b JM |
1988 | { |
1989 | struct sta_info *sta; | |
1990 | ||
1991 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) { | |
61323e70 JM |
1992 | wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)", |
1993 | (unsigned long) len); | |
6fc6879b JM |
1994 | return; |
1995 | } | |
1996 | ||
1997 | wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d", | |
1998 | MAC2STR(mgmt->sa), | |
1999 | le_to_host16(mgmt->u.disassoc.reason_code)); | |
2000 | ||
6fc6879b JM |
2001 | sta = ap_get_sta(hapd, mgmt->sa); |
2002 | if (sta == NULL) { | |
61323e70 JM |
2003 | wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated", |
2004 | MAC2STR(mgmt->sa)); | |
6fc6879b JM |
2005 | return; |
2006 | } | |
2007 | ||
ae055af4 | 2008 | ap_sta_set_authorized(hapd, sta, 0); |
38cb0a2d | 2009 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
b8281964 | 2010 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
6fc6879b JM |
2011 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); |
2012 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
2013 | HOSTAPD_LEVEL_INFO, "disassociated"); | |
2014 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; | |
2015 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
2016 | /* Stop Accounting and IEEE 802.1X sessions, but leave the STA | |
2017 | * authenticated. */ | |
2018 | accounting_sta_stop(hapd, sta); | |
d7c3347f | 2019 | ieee802_1x_free_station(hapd, sta); |
7d597d46 | 2020 | if (sta->ipaddr) |
ed4ddb6d | 2021 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
bd00c431 | 2022 | ap_sta_ip6addr_del(hapd, sta); |
51e2a27a | 2023 | hostapd_drv_sta_remove(hapd, sta->addr); |
6fc6879b JM |
2024 | |
2025 | if (sta->timeout_next == STA_NULLFUNC || | |
2026 | sta->timeout_next == STA_DISASSOC) { | |
2027 | sta->timeout_next = STA_DEAUTH; | |
2028 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); | |
2029 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, | |
2030 | hapd, sta); | |
2031 | } | |
2032 | ||
2033 | mlme_disassociate_indication( | |
2034 | hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code)); | |
2035 | } | |
2036 | ||
2037 | ||
2038 | static void handle_deauth(struct hostapd_data *hapd, | |
f8b1f695 | 2039 | const struct ieee80211_mgmt *mgmt, size_t len) |
6fc6879b JM |
2040 | { |
2041 | struct sta_info *sta; | |
2042 | ||
2043 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) { | |
3ec1e902 JM |
2044 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short " |
2045 | "payload (len=%lu)", (unsigned long) len); | |
6fc6879b JM |
2046 | return; |
2047 | } | |
2048 | ||
3ec1e902 | 2049 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR |
24d75245 BG |
2050 | " reason_code=%d", |
2051 | MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code)); | |
6fc6879b | 2052 | |
6fc6879b JM |
2053 | sta = ap_get_sta(hapd, mgmt->sa); |
2054 | if (sta == NULL) { | |
3ec1e902 JM |
2055 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying " |
2056 | "to deauthenticate, but it is not authenticated", | |
24d75245 | 2057 | MAC2STR(mgmt->sa)); |
6fc6879b JM |
2058 | return; |
2059 | } | |
2060 | ||
ae055af4 | 2061 | ap_sta_set_authorized(hapd, sta, 0); |
38cb0a2d | 2062 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
b8281964 JM |
2063 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | |
2064 | WLAN_STA_ASSOC_REQ_OK); | |
6fc6879b JM |
2065 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
2066 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
2067 | HOSTAPD_LEVEL_DEBUG, "deauthenticated"); | |
2068 | mlme_deauthenticate_indication( | |
2069 | hapd, sta, le_to_host16(mgmt->u.deauth.reason_code)); | |
2070 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; | |
2071 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
2072 | ap_free_sta(hapd, sta); | |
2073 | } | |
2074 | ||
2075 | ||
2076 | static void handle_beacon(struct hostapd_data *hapd, | |
b57e086c | 2077 | const struct ieee80211_mgmt *mgmt, size_t len, |
6fc6879b JM |
2078 | struct hostapd_frame_info *fi) |
2079 | { | |
2080 | struct ieee802_11_elems elems; | |
2081 | ||
2082 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) { | |
61323e70 JM |
2083 | wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)", |
2084 | (unsigned long) len); | |
6fc6879b JM |
2085 | return; |
2086 | } | |
2087 | ||
3d536eb4 | 2088 | (void) ieee802_11_parse_elems(mgmt->u.beacon.variable, |
6fc6879b JM |
2089 | len - (IEEE80211_HDRLEN + |
2090 | sizeof(mgmt->u.beacon)), &elems, | |
2091 | 0); | |
2092 | ||
6fc6879b JM |
2093 | ap_list_process_beacon(hapd->iface, mgmt, &elems, fi); |
2094 | } | |
2095 | ||
2096 | ||
5d22a1d5 | 2097 | #ifdef CONFIG_IEEE80211W |
88b4b424 | 2098 | |
912b34f0 JM |
2099 | static int hostapd_sa_query_action(struct hostapd_data *hapd, |
2100 | const struct ieee80211_mgmt *mgmt, | |
2101 | size_t len) | |
5d22a1d5 | 2102 | { |
b57e086c | 2103 | const u8 *end; |
5d22a1d5 | 2104 | |
93b76319 JM |
2105 | end = mgmt->u.action.u.sa_query_resp.trans_id + |
2106 | WLAN_SA_QUERY_TR_ID_LEN; | |
5d22a1d5 | 2107 | if (((u8 *) mgmt) + len < end) { |
93b76319 | 2108 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action " |
5d22a1d5 | 2109 | "frame (len=%lu)", (unsigned long) len); |
912b34f0 | 2110 | return 0; |
5d22a1d5 JM |
2111 | } |
2112 | ||
d4370eac MP |
2113 | ieee802_11_sa_query_action(hapd, mgmt->sa, |
2114 | mgmt->u.action.u.sa_query_resp.action, | |
2115 | mgmt->u.action.u.sa_query_resp.trans_id); | |
912b34f0 | 2116 | return 1; |
5d22a1d5 | 2117 | } |
5d22a1d5 JM |
2118 | |
2119 | ||
c4e281fd JM |
2120 | static int robust_action_frame(u8 category) |
2121 | { | |
2122 | return category != WLAN_ACTION_PUBLIC && | |
2123 | category != WLAN_ACTION_HT; | |
2124 | } | |
9f64b827 | 2125 | #endif /* CONFIG_IEEE80211W */ |
c4e281fd JM |
2126 | |
2127 | ||
912b34f0 JM |
2128 | static int handle_action(struct hostapd_data *hapd, |
2129 | const struct ieee80211_mgmt *mgmt, size_t len) | |
6fc6879b | 2130 | { |
c4e281fd | 2131 | struct sta_info *sta; |
46eeedac | 2132 | sta = ap_get_sta(hapd, mgmt->sa); |
c4e281fd | 2133 | |
6fc6879b JM |
2134 | if (len < IEEE80211_HDRLEN + 1) { |
2135 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, | |
2136 | HOSTAPD_LEVEL_DEBUG, | |
2137 | "handle_action - too short payload (len=%lu)", | |
2138 | (unsigned long) len); | |
912b34f0 | 2139 | return 0; |
6fc6879b JM |
2140 | } |
2141 | ||
c79938a5 JM |
2142 | if (mgmt->u.action.category != WLAN_ACTION_PUBLIC && |
2143 | (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) { | |
2144 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action " | |
2145 | "frame (category=%u) from unassociated STA " MACSTR, | |
2146 | MAC2STR(mgmt->sa), mgmt->u.action.category); | |
912b34f0 | 2147 | return 0; |
c79938a5 JM |
2148 | } |
2149 | ||
c4e281fd JM |
2150 | #ifdef CONFIG_IEEE80211W |
2151 | if (sta && (sta->flags & WLAN_STA_MFP) && | |
7b2c42f8 JM |
2152 | !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) && |
2153 | robust_action_frame(mgmt->u.action.category)) { | |
c4e281fd JM |
2154 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
2155 | HOSTAPD_LEVEL_DEBUG, | |
2156 | "Dropped unprotected Robust Action frame from " | |
2157 | "an MFP STA"); | |
912b34f0 | 2158 | return 0; |
c4e281fd JM |
2159 | } |
2160 | #endif /* CONFIG_IEEE80211W */ | |
2161 | ||
38cb0a2d IP |
2162 | if (sta) { |
2163 | u16 fc = le_to_host16(mgmt->frame_control); | |
2164 | u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl); | |
2165 | ||
2166 | if ((fc & WLAN_FC_RETRY) && | |
2167 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && | |
2168 | sta->last_seq_ctrl == seq_ctrl && | |
2169 | sta->last_subtype == WLAN_FC_STYPE_ACTION) { | |
2170 | hostapd_logger(hapd, sta->addr, | |
2171 | HOSTAPD_MODULE_IEEE80211, | |
2172 | HOSTAPD_LEVEL_DEBUG, | |
2173 | "Drop repeated action frame seq_ctrl=0x%x", | |
2174 | seq_ctrl); | |
2175 | return 1; | |
2176 | } | |
2177 | ||
2178 | sta->last_seq_ctrl = seq_ctrl; | |
2179 | sta->last_subtype = WLAN_FC_STYPE_ACTION; | |
2180 | } | |
2181 | ||
6fc6879b JM |
2182 | switch (mgmt->u.action.category) { |
2183 | #ifdef CONFIG_IEEE80211R | |
2184 | case WLAN_ACTION_FT: | |
d6c6b1fb JM |
2185 | if (!sta || |
2186 | wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, | |
6fc6879b JM |
2187 | len - IEEE80211_HDRLEN)) |
2188 | break; | |
912b34f0 | 2189 | return 1; |
6fc6879b | 2190 | #endif /* CONFIG_IEEE80211R */ |
c2a71408 | 2191 | case WLAN_ACTION_WMM: |
3ae0800c | 2192 | hostapd_wmm_action(hapd, mgmt, len); |
912b34f0 | 2193 | return 1; |
5d22a1d5 | 2194 | #ifdef CONFIG_IEEE80211W |
93b76319 | 2195 | case WLAN_ACTION_SA_QUERY: |
912b34f0 | 2196 | return hostapd_sa_query_action(hapd, mgmt, len); |
5d22a1d5 | 2197 | #endif /* CONFIG_IEEE80211W */ |
c79938a5 JM |
2198 | #ifdef CONFIG_WNM |
2199 | case WLAN_ACTION_WNM: | |
dbfb8e82 JM |
2200 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, len); |
2201 | return 1; | |
c79938a5 | 2202 | #endif /* CONFIG_WNM */ |
037378ff AN |
2203 | #ifdef CONFIG_FST |
2204 | case WLAN_ACTION_FST: | |
2205 | if (hapd->iface->fst) | |
2206 | fst_rx_action(hapd->iface->fst, mgmt, len); | |
94edea89 JM |
2207 | else |
2208 | wpa_printf(MSG_DEBUG, | |
2209 | "FST: Ignore FST Action frame - no FST attached"); | |
037378ff AN |
2210 | return 1; |
2211 | #endif /* CONFIG_FST */ | |
c706d5aa | 2212 | case WLAN_ACTION_PUBLIC: |
5ce00d09 | 2213 | case WLAN_ACTION_PROTECTED_DUAL: |
587d60d2 | 2214 | #ifdef CONFIG_IEEE80211N |
fd66aa63 JM |
2215 | if (len >= IEEE80211_HDRLEN + 2 && |
2216 | mgmt->u.action.u.public_action.action == | |
587d60d2 PX |
2217 | WLAN_PA_20_40_BSS_COEX) { |
2218 | wpa_printf(MSG_DEBUG, | |
2219 | "HT20/40 coex mgmt frame received from STA " | |
2220 | MACSTR, MAC2STR(mgmt->sa)); | |
2221 | hostapd_2040_coex_action(hapd, mgmt, len); | |
2222 | } | |
2223 | #endif /* CONFIG_IEEE80211N */ | |
c706d5aa JM |
2224 | if (hapd->public_action_cb) { |
2225 | hapd->public_action_cb(hapd->public_action_cb_ctx, | |
2226 | (u8 *) mgmt, len, | |
2227 | hapd->iface->freq); | |
c706d5aa | 2228 | } |
2d9ffe1e | 2229 | if (hapd->public_action_cb2) { |
8dabf4bb | 2230 | hapd->public_action_cb2(hapd->public_action_cb2_ctx, |
2d9ffe1e JM |
2231 | (u8 *) mgmt, len, |
2232 | hapd->iface->freq); | |
2233 | } | |
2234 | if (hapd->public_action_cb || hapd->public_action_cb2) | |
912b34f0 | 2235 | return 1; |
c706d5aa | 2236 | break; |
e44f8bf2 JM |
2237 | case WLAN_ACTION_VENDOR_SPECIFIC: |
2238 | if (hapd->vendor_action_cb) { | |
2239 | if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx, | |
2240 | (u8 *) mgmt, len, | |
2241 | hapd->iface->freq) == 0) | |
912b34f0 | 2242 | return 1; |
e44f8bf2 JM |
2243 | } |
2244 | break; | |
6fc6879b JM |
2245 | } |
2246 | ||
2247 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, | |
2248 | HOSTAPD_LEVEL_DEBUG, | |
2249 | "handle_action - unknown action category %d or invalid " | |
2250 | "frame", | |
2251 | mgmt->u.action.category); | |
2252 | if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) && | |
2253 | !(mgmt->sa[0] & 0x01)) { | |
b57e086c JM |
2254 | struct ieee80211_mgmt *resp; |
2255 | ||
6fc6879b JM |
2256 | /* |
2257 | * IEEE 802.11-REVma/D9.0 - 7.3.1.11 | |
2258 | * Return the Action frame to the source without change | |
2259 | * except that MSB of the Category set to 1. | |
2260 | */ | |
2261 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action " | |
2262 | "frame back to sender"); | |
b57e086c JM |
2263 | resp = os_malloc(len); |
2264 | if (resp == NULL) | |
912b34f0 | 2265 | return 0; |
b57e086c JM |
2266 | os_memcpy(resp, mgmt, len); |
2267 | os_memcpy(resp->da, resp->sa, ETH_ALEN); | |
2268 | os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); | |
2269 | os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); | |
2270 | resp->u.action.category |= 0x80; | |
2271 | ||
41fe8b42 JM |
2272 | if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) { |
2273 | wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send " | |
2274 | "Action frame"); | |
2275 | } | |
b57e086c | 2276 | os_free(resp); |
6fc6879b | 2277 | } |
912b34f0 JM |
2278 | |
2279 | return 1; | |
6fc6879b JM |
2280 | } |
2281 | ||
2282 | ||
2283 | /** | |
2284 | * ieee802_11_mgmt - process incoming IEEE 802.11 management frames | |
2285 | * @hapd: hostapd BSS data structure (the BSS to which the management frame was | |
2286 | * sent to) | |
2287 | * @buf: management frame data (starting from IEEE 802.11 header) | |
2288 | * @len: length of frame data in octets | |
a17df5fb | 2289 | * @fi: meta data about received frame (signal level, etc.) |
6fc6879b JM |
2290 | * |
2291 | * Process all incoming IEEE 802.11 management frames. This will be called for | |
2292 | * each frame received from the kernel driver through wlan#ap interface. In | |
2293 | * addition, it can be called to re-inserted pending frames (e.g., when using | |
2294 | * external RADIUS server as an MAC ACL). | |
2295 | */ | |
912b34f0 JM |
2296 | int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len, |
2297 | struct hostapd_frame_info *fi) | |
6fc6879b | 2298 | { |
f8b1f695 | 2299 | struct ieee80211_mgmt *mgmt; |
6fc6879b | 2300 | int broadcast; |
f8b1f695 | 2301 | u16 fc, stype; |
912b34f0 | 2302 | int ret = 0; |
f8b1f695 | 2303 | |
cbcf92b4 | 2304 | if (len < 24) |
912b34f0 | 2305 | return 0; |
cbcf92b4 | 2306 | |
f8b1f695 JM |
2307 | mgmt = (struct ieee80211_mgmt *) buf; |
2308 | fc = le_to_host16(mgmt->frame_control); | |
2309 | stype = WLAN_FC_GET_STYPE(fc); | |
6fc6879b JM |
2310 | |
2311 | if (stype == WLAN_FC_STYPE_BEACON) { | |
2312 | handle_beacon(hapd, mgmt, len, fi); | |
912b34f0 | 2313 | return 1; |
6fc6879b JM |
2314 | } |
2315 | ||
6fc6879b JM |
2316 | broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff && |
2317 | mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff && | |
2318 | mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff; | |
2319 | ||
2320 | if (!broadcast && | |
3eeee931 AN |
2321 | #ifdef CONFIG_P2P |
2322 | /* Invitation responses can be sent with the peer MAC as BSSID */ | |
2323 | !((hapd->conf->p2p & P2P_GROUP_OWNER) && | |
2324 | stype == WLAN_FC_STYPE_ACTION) && | |
2325 | #endif /* CONFIG_P2P */ | |
f3e9899e BC |
2326 | #ifdef CONFIG_MESH |
2327 | !(hapd->conf->mesh & MESH_ENABLED) && | |
2328 | #endif /* CONFIG_MESH */ | |
fe2c5241 | 2329 | os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) { |
61323e70 JM |
2330 | wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address", |
2331 | MAC2STR(mgmt->bssid)); | |
912b34f0 | 2332 | return 0; |
6fc6879b JM |
2333 | } |
2334 | ||
2335 | ||
2336 | if (stype == WLAN_FC_STYPE_PROBE_REQ) { | |
baf513d6 | 2337 | handle_probe_req(hapd, mgmt, len, fi->ssi_signal); |
912b34f0 | 2338 | return 1; |
6fc6879b JM |
2339 | } |
2340 | ||
2341 | if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) { | |
2342 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, | |
2343 | HOSTAPD_LEVEL_DEBUG, | |
2344 | "MGMT: DA=" MACSTR " not our address", | |
2345 | MAC2STR(mgmt->da)); | |
912b34f0 | 2346 | return 0; |
6fc6879b JM |
2347 | } |
2348 | ||
b308a304 JM |
2349 | if (hapd->iconf->track_sta_max_num) |
2350 | sta_track_add(hapd->iface, mgmt->sa); | |
2351 | ||
6fc6879b JM |
2352 | switch (stype) { |
2353 | case WLAN_FC_STYPE_AUTH: | |
2354 | wpa_printf(MSG_DEBUG, "mgmt::auth"); | |
2355 | handle_auth(hapd, mgmt, len); | |
912b34f0 | 2356 | ret = 1; |
6fc6879b JM |
2357 | break; |
2358 | case WLAN_FC_STYPE_ASSOC_REQ: | |
2359 | wpa_printf(MSG_DEBUG, "mgmt::assoc_req"); | |
2360 | handle_assoc(hapd, mgmt, len, 0); | |
912b34f0 | 2361 | ret = 1; |
6fc6879b | 2362 | break; |
6fc6879b JM |
2363 | case WLAN_FC_STYPE_REASSOC_REQ: |
2364 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_req"); | |
2365 | handle_assoc(hapd, mgmt, len, 1); | |
912b34f0 | 2366 | ret = 1; |
6fc6879b JM |
2367 | break; |
2368 | case WLAN_FC_STYPE_DISASSOC: | |
2369 | wpa_printf(MSG_DEBUG, "mgmt::disassoc"); | |
2370 | handle_disassoc(hapd, mgmt, len); | |
912b34f0 | 2371 | ret = 1; |
6fc6879b JM |
2372 | break; |
2373 | case WLAN_FC_STYPE_DEAUTH: | |
3ec1e902 | 2374 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth"); |
6fc6879b | 2375 | handle_deauth(hapd, mgmt, len); |
912b34f0 | 2376 | ret = 1; |
6fc6879b JM |
2377 | break; |
2378 | case WLAN_FC_STYPE_ACTION: | |
2379 | wpa_printf(MSG_DEBUG, "mgmt::action"); | |
912b34f0 | 2380 | ret = handle_action(hapd, mgmt, len); |
6fc6879b JM |
2381 | break; |
2382 | default: | |
2383 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, | |
2384 | HOSTAPD_LEVEL_DEBUG, | |
2385 | "unknown mgmt frame subtype %d", stype); | |
2386 | break; | |
2387 | } | |
912b34f0 JM |
2388 | |
2389 | return ret; | |
6fc6879b JM |
2390 | } |
2391 | ||
2392 | ||
2393 | static void handle_auth_cb(struct hostapd_data *hapd, | |
f8b1f695 | 2394 | const struct ieee80211_mgmt *mgmt, |
6fc6879b JM |
2395 | size_t len, int ok) |
2396 | { | |
2397 | u16 auth_alg, auth_transaction, status_code; | |
2398 | struct sta_info *sta; | |
2399 | ||
2400 | if (!ok) { | |
2401 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, | |
2402 | HOSTAPD_LEVEL_NOTICE, | |
2403 | "did not acknowledge authentication response"); | |
2404 | return; | |
2405 | } | |
2406 | ||
2407 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { | |
61323e70 JM |
2408 | wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)", |
2409 | (unsigned long) len); | |
6fc6879b JM |
2410 | return; |
2411 | } | |
2412 | ||
2413 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
2414 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); | |
2415 | status_code = le_to_host16(mgmt->u.auth.status_code); | |
2416 | ||
2417 | sta = ap_get_sta(hapd, mgmt->da); | |
2418 | if (!sta) { | |
61323e70 JM |
2419 | wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found", |
2420 | MAC2STR(mgmt->da)); | |
6fc6879b JM |
2421 | return; |
2422 | } | |
2423 | ||
2424 | if (status_code == WLAN_STATUS_SUCCESS && | |
2425 | ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) || | |
2426 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) { | |
2427 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
2428 | HOSTAPD_LEVEL_INFO, "authenticated"); | |
2429 | sta->flags |= WLAN_STA_AUTH; | |
2430 | } | |
2431 | } | |
2432 | ||
2433 | ||
69dd2967 SM |
2434 | static void hostapd_set_wds_encryption(struct hostapd_data *hapd, |
2435 | struct sta_info *sta, | |
2436 | char *ifname_wds) | |
2437 | { | |
2438 | int i; | |
f41ded6f | 2439 | struct hostapd_ssid *ssid = &hapd->conf->ssid; |
69dd2967 SM |
2440 | |
2441 | if (hapd->conf->ieee802_1x || hapd->conf->wpa) | |
2442 | return; | |
2443 | ||
2444 | for (i = 0; i < 4; i++) { | |
2445 | if (ssid->wep.key[i] && | |
2446 | hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i, | |
2447 | i == ssid->wep.idx, NULL, 0, | |
2448 | ssid->wep.key[i], ssid->wep.len[i])) { | |
2449 | wpa_printf(MSG_WARNING, | |
2450 | "Could not set WEP keys for WDS interface; %s", | |
2451 | ifname_wds); | |
2452 | break; | |
2453 | } | |
2454 | } | |
2455 | } | |
2456 | ||
2457 | ||
6fc6879b | 2458 | static void handle_assoc_cb(struct hostapd_data *hapd, |
f8b1f695 | 2459 | const struct ieee80211_mgmt *mgmt, |
6fc6879b JM |
2460 | size_t len, int reassoc, int ok) |
2461 | { | |
2462 | u16 status; | |
2463 | struct sta_info *sta; | |
2464 | int new_assoc = 1; | |
fc4e2d95 | 2465 | struct ieee80211_ht_capabilities ht_cap; |
a9a1d0f0 | 2466 | struct ieee80211_vht_capabilities vht_cap; |
6fc6879b | 2467 | |
6fc6879b JM |
2468 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) : |
2469 | sizeof(mgmt->u.assoc_resp))) { | |
61323e70 JM |
2470 | wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)", |
2471 | reassoc, (unsigned long) len); | |
6fc6879b JM |
2472 | return; |
2473 | } | |
2474 | ||
6fc6879b JM |
2475 | sta = ap_get_sta(hapd, mgmt->da); |
2476 | if (!sta) { | |
61323e70 JM |
2477 | wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found", |
2478 | MAC2STR(mgmt->da)); | |
6fc6879b JM |
2479 | return; |
2480 | } | |
2481 | ||
22b42372 FF |
2482 | if (!ok) { |
2483 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, | |
2484 | HOSTAPD_LEVEL_DEBUG, | |
2485 | "did not acknowledge association response"); | |
2486 | sta->flags &= ~WLAN_STA_ASSOC_REQ_OK; | |
2487 | return; | |
2488 | } | |
2489 | ||
2490 | if (reassoc) | |
2491 | status = le_to_host16(mgmt->u.reassoc_resp.status_code); | |
2492 | else | |
2493 | status = le_to_host16(mgmt->u.assoc_resp.status_code); | |
2494 | ||
6fc6879b | 2495 | if (status != WLAN_STATUS_SUCCESS) |
5bdac4ab | 2496 | return; |
6fc6879b JM |
2497 | |
2498 | /* Stop previous accounting session, if one is started, and allocate | |
2499 | * new session id for the new session. */ | |
2500 | accounting_sta_stop(hapd, sta); | |
6fc6879b JM |
2501 | |
2502 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
2503 | HOSTAPD_LEVEL_INFO, | |
2fc98d02 JM |
2504 | "associated (aid %d)", |
2505 | sta->aid); | |
6fc6879b JM |
2506 | |
2507 | if (sta->flags & WLAN_STA_ASSOC) | |
2508 | new_assoc = 0; | |
2509 | sta->flags |= WLAN_STA_ASSOC; | |
3578e665 | 2510 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
a14896e8 | 2511 | if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) || |
ef580012 JM |
2512 | sta->auth_alg == WLAN_AUTH_FT) { |
2513 | /* | |
2514 | * Open, static WEP, or FT protocol; no separate authorization | |
2515 | * step. | |
2516 | */ | |
6905dcb1 | 2517 | ap_sta_set_authorized(hapd, sta, 1); |
515cf93f | 2518 | } |
6fc6879b JM |
2519 | |
2520 | if (reassoc) | |
2521 | mlme_reassociate_indication(hapd, sta); | |
2522 | else | |
2523 | mlme_associate_indication(hapd, sta); | |
2524 | ||
5d22a1d5 | 2525 | #ifdef CONFIG_IEEE80211W |
93b76319 | 2526 | sta->sa_query_timed_out = 0; |
5d22a1d5 JM |
2527 | #endif /* CONFIG_IEEE80211W */ |
2528 | ||
c140a228 JM |
2529 | /* |
2530 | * Remove the STA entry in order to make sure the STA PS state gets | |
2531 | * cleared and configuration gets updated in case of reassociation back | |
2532 | * to the same AP. | |
2533 | */ | |
51e2a27a | 2534 | hostapd_drv_sta_remove(hapd, sta->addr); |
c140a228 | 2535 | |
d45354be JM |
2536 | #ifdef CONFIG_IEEE80211N |
2537 | if (sta->flags & WLAN_STA_HT) | |
2538 | hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap); | |
2539 | #endif /* CONFIG_IEEE80211N */ | |
a9a1d0f0 JB |
2540 | #ifdef CONFIG_IEEE80211AC |
2541 | if (sta->flags & WLAN_STA_VHT) | |
2542 | hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap); | |
2543 | #endif /* CONFIG_IEEE80211AC */ | |
d45354be | 2544 | |
0e8a96a9 JM |
2545 | if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability, |
2546 | sta->supported_rates, sta->supported_rates_len, | |
2547 | sta->listen_interval, | |
d83ab1fe | 2548 | sta->flags & WLAN_STA_HT ? &ht_cap : NULL, |
a9a1d0f0 | 2549 | sta->flags & WLAN_STA_VHT ? &vht_cap : NULL, |
8a458116 | 2550 | sta->flags, sta->qosinfo, sta->vht_opmode)) { |
6fc6879b JM |
2551 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
2552 | HOSTAPD_LEVEL_NOTICE, | |
2553 | "Could not add STA to kernel driver"); | |
8666585b YAP |
2554 | |
2555 | ap_sta_disconnect(hapd, sta, sta->addr, | |
2556 | WLAN_REASON_DISASSOC_AP_BUSY); | |
2557 | ||
5bdac4ab | 2558 | return; |
6fc6879b JM |
2559 | } |
2560 | ||
69dd2967 SM |
2561 | if (sta->flags & WLAN_STA_WDS) { |
2562 | int ret; | |
2563 | char ifname_wds[IFNAMSIZ + 1]; | |
2564 | ||
2565 | ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr, | |
2566 | sta->aid, 1); | |
2567 | if (!ret) | |
2568 | hostapd_set_wds_encryption(hapd, sta, ifname_wds); | |
2569 | } | |
7826ceae | 2570 | |
6fc6879b JM |
2571 | if (sta->eapol_sm == NULL) { |
2572 | /* | |
2573 | * This STA does not use RADIUS server for EAP authentication, | |
2574 | * so bind it to the selected VLAN interface now, since the | |
2575 | * interface selection is not going to change anymore. | |
2576 | */ | |
c8e6beab | 2577 | if (ap_sta_bind_vlan(hapd, sta) < 0) |
5bdac4ab | 2578 | return; |
6fc6879b JM |
2579 | } else if (sta->vlan_id) { |
2580 | /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */ | |
c8e6beab | 2581 | if (ap_sta_bind_vlan(hapd, sta) < 0) |
5bdac4ab | 2582 | return; |
6fc6879b | 2583 | } |
eddd8010 | 2584 | |
0e8a96a9 | 2585 | hostapd_set_sta_flags(hapd, sta); |
6fc6879b JM |
2586 | |
2587 | if (sta->auth_alg == WLAN_AUTH_FT) | |
2588 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); | |
2589 | else | |
2590 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); | |
d24df7c3 | 2591 | hapd->new_assoc_sta_cb(hapd, sta, !new_assoc); |
6fc6879b JM |
2592 | |
2593 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); | |
6fc6879b JM |
2594 | } |
2595 | ||
2596 | ||
4dc03726 JM |
2597 | static void handle_deauth_cb(struct hostapd_data *hapd, |
2598 | const struct ieee80211_mgmt *mgmt, | |
2599 | size_t len, int ok) | |
2600 | { | |
2601 | struct sta_info *sta; | |
2602 | if (mgmt->da[0] & 0x01) | |
2603 | return; | |
2604 | sta = ap_get_sta(hapd, mgmt->da); | |
2605 | if (!sta) { | |
2606 | wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR | |
2607 | " not found", MAC2STR(mgmt->da)); | |
2608 | return; | |
2609 | } | |
2610 | if (ok) | |
2611 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth", | |
2612 | MAC2STR(sta->addr)); | |
2613 | else | |
2614 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " | |
2615 | "deauth", MAC2STR(sta->addr)); | |
2616 | ||
2617 | ap_sta_deauth_cb(hapd, sta); | |
2618 | } | |
2619 | ||
2620 | ||
2621 | static void handle_disassoc_cb(struct hostapd_data *hapd, | |
2622 | const struct ieee80211_mgmt *mgmt, | |
2623 | size_t len, int ok) | |
2624 | { | |
2625 | struct sta_info *sta; | |
2626 | if (mgmt->da[0] & 0x01) | |
2627 | return; | |
2628 | sta = ap_get_sta(hapd, mgmt->da); | |
2629 | if (!sta) { | |
2630 | wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR | |
2631 | " not found", MAC2STR(mgmt->da)); | |
2632 | return; | |
2633 | } | |
2634 | if (ok) | |
2635 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc", | |
2636 | MAC2STR(sta->addr)); | |
2637 | else | |
2638 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " | |
2639 | "disassoc", MAC2STR(sta->addr)); | |
2640 | ||
2641 | ap_sta_disassoc_cb(hapd, sta); | |
2642 | } | |
2643 | ||
2644 | ||
1c6e69cc JM |
2645 | /** |
2646 | * ieee802_11_mgmt_cb - Process management frame TX status callback | |
2647 | * @hapd: hostapd BSS data structure (the BSS from which the management frame | |
2648 | * was sent from) | |
2649 | * @buf: management frame data (starting from IEEE 802.11 header) | |
2650 | * @len: length of frame data in octets | |
2651 | * @stype: management frame subtype from frame control field | |
2652 | * @ok: Whether the frame was ACK'ed | |
2653 | */ | |
f8b1f695 | 2654 | void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len, |
6fc6879b JM |
2655 | u16 stype, int ok) |
2656 | { | |
f8b1f695 JM |
2657 | const struct ieee80211_mgmt *mgmt; |
2658 | mgmt = (const struct ieee80211_mgmt *) buf; | |
6fc6879b | 2659 | |
93827f45 JM |
2660 | #ifdef CONFIG_TESTING_OPTIONS |
2661 | if (hapd->ext_mgmt_frame_handling) { | |
2662 | wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d", | |
2663 | stype, ok); | |
2664 | return; | |
2665 | } | |
2666 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2667 | ||
6fc6879b JM |
2668 | switch (stype) { |
2669 | case WLAN_FC_STYPE_AUTH: | |
2670 | wpa_printf(MSG_DEBUG, "mgmt::auth cb"); | |
2671 | handle_auth_cb(hapd, mgmt, len, ok); | |
2672 | break; | |
2673 | case WLAN_FC_STYPE_ASSOC_RESP: | |
2674 | wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb"); | |
2675 | handle_assoc_cb(hapd, mgmt, len, 0, ok); | |
2676 | break; | |
2677 | case WLAN_FC_STYPE_REASSOC_RESP: | |
2678 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb"); | |
2679 | handle_assoc_cb(hapd, mgmt, len, 1, ok); | |
2680 | break; | |
2681 | case WLAN_FC_STYPE_PROBE_RESP: | |
2d8bf732 | 2682 | wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb"); |
6fc6879b JM |
2683 | break; |
2684 | case WLAN_FC_STYPE_DEAUTH: | |
4dc03726 JM |
2685 | wpa_printf(MSG_DEBUG, "mgmt::deauth cb"); |
2686 | handle_deauth_cb(hapd, mgmt, len, ok); | |
2687 | break; | |
2688 | case WLAN_FC_STYPE_DISASSOC: | |
2689 | wpa_printf(MSG_DEBUG, "mgmt::disassoc cb"); | |
2690 | handle_disassoc_cb(hapd, mgmt, len, ok); | |
6fc6879b | 2691 | break; |
5d22a1d5 JM |
2692 | case WLAN_FC_STYPE_ACTION: |
2693 | wpa_printf(MSG_DEBUG, "mgmt::action cb"); | |
2694 | break; | |
6fc6879b | 2695 | default: |
61323e70 | 2696 | wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype); |
6fc6879b JM |
2697 | break; |
2698 | } | |
2699 | } | |
2700 | ||
2701 | ||
6fc6879b JM |
2702 | int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen) |
2703 | { | |
2704 | /* TODO */ | |
2705 | return 0; | |
2706 | } | |
2707 | ||
2708 | ||
2709 | int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta, | |
2710 | char *buf, size_t buflen) | |
2711 | { | |
2712 | /* TODO */ | |
2713 | return 0; | |
2714 | } | |
2715 | ||
f8b1f695 JM |
2716 | |
2717 | void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr, | |
2718 | const u8 *buf, size_t len, int ack) | |
2719 | { | |
2720 | struct sta_info *sta; | |
2721 | struct hostapd_iface *iface = hapd->iface; | |
2722 | ||
2723 | sta = ap_get_sta(hapd, addr); | |
2724 | if (sta == NULL && iface->num_bss > 1) { | |
2725 | size_t j; | |
2726 | for (j = 0; j < iface->num_bss; j++) { | |
2727 | hapd = iface->bss[j]; | |
2728 | sta = ap_get_sta(hapd, addr); | |
2729 | if (sta) | |
2730 | break; | |
2731 | } | |
2732 | } | |
0c01d65d | 2733 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) |
f8b1f695 JM |
2734 | return; |
2735 | if (sta->flags & WLAN_STA_PENDING_POLL) { | |
2736 | wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending " | |
2737 | "activity poll", MAC2STR(sta->addr), | |
2738 | ack ? "ACKed" : "did not ACK"); | |
2739 | if (ack) | |
2740 | sta->flags &= ~WLAN_STA_PENDING_POLL; | |
2741 | } | |
2742 | ||
2743 | ieee802_1x_tx_status(hapd, sta, buf, len, ack); | |
2744 | } | |
2745 | ||
2746 | ||
dd840f79 JB |
2747 | void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst, |
2748 | const u8 *data, size_t len, int ack) | |
2749 | { | |
2750 | struct sta_info *sta; | |
2751 | struct hostapd_iface *iface = hapd->iface; | |
2752 | ||
2753 | sta = ap_get_sta(hapd, dst); | |
2754 | if (sta == NULL && iface->num_bss > 1) { | |
2755 | size_t j; | |
2756 | for (j = 0; j < iface->num_bss; j++) { | |
2757 | hapd = iface->bss[j]; | |
2758 | sta = ap_get_sta(hapd, dst); | |
2759 | if (sta) | |
2760 | break; | |
2761 | } | |
2762 | } | |
d9a38716 JM |
2763 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) { |
2764 | wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA " | |
2765 | MACSTR " that is not currently associated", | |
2766 | MAC2STR(dst)); | |
dd840f79 | 2767 | return; |
d9a38716 | 2768 | } |
dd840f79 JB |
2769 | |
2770 | ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack); | |
2771 | } | |
2772 | ||
2773 | ||
bcf24348 JB |
2774 | void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr) |
2775 | { | |
2776 | struct sta_info *sta; | |
2777 | struct hostapd_iface *iface = hapd->iface; | |
2778 | ||
2779 | sta = ap_get_sta(hapd, addr); | |
2780 | if (sta == NULL && iface->num_bss > 1) { | |
2781 | size_t j; | |
2782 | for (j = 0; j < iface->num_bss; j++) { | |
2783 | hapd = iface->bss[j]; | |
2784 | sta = ap_get_sta(hapd, addr); | |
2785 | if (sta) | |
2786 | break; | |
2787 | } | |
2788 | } | |
2789 | if (sta == NULL) | |
2790 | return; | |
2791 | if (!(sta->flags & WLAN_STA_PENDING_POLL)) | |
2792 | return; | |
2793 | ||
2794 | wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending " | |
2795 | "activity poll", MAC2STR(sta->addr)); | |
2796 | sta->flags &= ~WLAN_STA_PENDING_POLL; | |
2797 | } | |
2798 | ||
2799 | ||
fbbfcbac FF |
2800 | void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src, |
2801 | int wds) | |
f8b1f695 JM |
2802 | { |
2803 | struct sta_info *sta; | |
2804 | ||
2805 | sta = ap_get_sta(hapd, src); | |
fbbfcbac | 2806 | if (sta && (sta->flags & WLAN_STA_ASSOC)) { |
99743811 FF |
2807 | if (!hapd->conf->wds_sta) |
2808 | return; | |
2809 | ||
fbbfcbac | 2810 | if (wds && !(sta->flags & WLAN_STA_WDS)) { |
69dd2967 SM |
2811 | int ret; |
2812 | char ifname_wds[IFNAMSIZ + 1]; | |
2813 | ||
fbbfcbac FF |
2814 | wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for " |
2815 | "STA " MACSTR " (aid %u)", | |
2816 | MAC2STR(sta->addr), sta->aid); | |
2817 | sta->flags |= WLAN_STA_WDS; | |
69dd2967 SM |
2818 | ret = hostapd_set_wds_sta(hapd, ifname_wds, |
2819 | sta->addr, sta->aid, 1); | |
2820 | if (!ret) | |
2821 | hostapd_set_wds_encryption(hapd, sta, | |
2822 | ifname_wds); | |
fbbfcbac | 2823 | } |
f8b1f695 | 2824 | return; |
fbbfcbac | 2825 | } |
f8b1f695 JM |
2826 | |
2827 | wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA " | |
2828 | MACSTR, MAC2STR(src)); | |
1df492df JM |
2829 | if (src[0] & 0x01) { |
2830 | /* Broadcast bit set in SA?! Ignore the frame silently. */ | |
2831 | return; | |
2832 | } | |
2833 | ||
b8281964 JM |
2834 | if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) { |
2835 | wpa_printf(MSG_DEBUG, "Association Response to the STA has " | |
2836 | "already been sent, but no TX status yet known - " | |
2837 | "ignore Class 3 frame issue with " MACSTR, | |
2838 | MAC2STR(src)); | |
2839 | return; | |
2840 | } | |
2841 | ||
f8b1f695 | 2842 | if (sta && (sta->flags & WLAN_STA_AUTH)) |
51e2a27a | 2843 | hostapd_drv_sta_disassoc( |
f8b1f695 JM |
2844 | hapd, src, |
2845 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); | |
2846 | else | |
51e2a27a | 2847 | hostapd_drv_sta_deauth( |
f8b1f695 JM |
2848 | hapd, src, |
2849 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); | |
2850 | } | |
2851 | ||
2852 | ||
6fc6879b | 2853 | #endif /* CONFIG_NATIVE_WINDOWS */ |