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