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