]>
Commit | Line | Data |
---|---|---|
b5b969e9 JM |
1 | /* |
2 | * hostapd / Callback functions for driver wrappers | |
94ddef3e | 3 | * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi> |
b5b969e9 | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
b5b969e9 JM |
7 | */ |
8 | ||
6226e38d | 9 | #include "utils/includes.h" |
b5b969e9 | 10 | |
6226e38d | 11 | #include "utils/common.h" |
9c47f6a2 | 12 | #include "utils/eloop.h" |
b5b969e9 | 13 | #include "radius/radius.h" |
6e6e8c31 | 14 | #include "drivers/driver.h" |
81f4f619 | 15 | #include "common/ieee802_11_defs.h" |
c41a1095 | 16 | #include "common/ieee802_11_common.h" |
3140803b | 17 | #include "common/wpa_ctrl.h" |
bbb921da | 18 | #include "crypto/random.h" |
ef796391 | 19 | #include "p2p/p2p.h" |
54f489be | 20 | #include "wps/wps.h" |
037378ff | 21 | #include "fst/fst.h" |
d32d94db | 22 | #include "wnm_ap.h" |
6226e38d JM |
23 | #include "hostapd.h" |
24 | #include "ieee802_11.h" | |
0603bcb7 | 25 | #include "ieee802_11_auth.h" |
6226e38d JM |
26 | #include "sta_info.h" |
27 | #include "accounting.h" | |
28 | #include "tkip_countermeasures.h" | |
6226e38d JM |
29 | #include "ieee802_1x.h" |
30 | #include "wpa_auth.h" | |
6226e38d | 31 | #include "wps_hostapd.h" |
51e2a27a | 32 | #include "ap_drv_ops.h" |
8b06c1ed | 33 | #include "ap_config.h" |
fa61bff6 | 34 | #include "ap_mlme.h" |
1b487b8b | 35 | #include "hw_features.h" |
e76da505 | 36 | #include "dfs.h" |
9c47f6a2 | 37 | #include "beacon.h" |
6332aaf3 | 38 | #include "mbo_ap.h" |
9c2b8204 | 39 | #include "dpp_hostapd.h" |
8b5ddda5 JM |
40 | #include "fils_hlp.h" |
41 | ||
42 | ||
43 | #ifdef CONFIG_FILS | |
44 | void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd, | |
45 | struct sta_info *sta) | |
46 | { | |
47 | u16 reply_res = WLAN_STATUS_SUCCESS; | |
48 | struct ieee802_11_elems elems; | |
49 | u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf; | |
50 | int new_assoc; | |
51 | ||
52 | wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR, | |
53 | __func__, MAC2STR(sta->addr)); | |
54 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); | |
55 | if (!sta->fils_pending_assoc_req) | |
56 | return; | |
57 | ||
58 | ieee802_11_parse_elems(sta->fils_pending_assoc_req, | |
59 | sta->fils_pending_assoc_req_len, &elems, 0); | |
60 | if (!elems.fils_session) { | |
61 | wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element", | |
62 | __func__); | |
63 | return; | |
64 | } | |
65 | ||
66 | p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p, | |
67 | elems.fils_session, | |
68 | sta->fils_hlp_resp); | |
69 | ||
70 | reply_res = hostapd_sta_assoc(hapd, sta->addr, | |
71 | sta->fils_pending_assoc_is_reassoc, | |
72 | WLAN_STATUS_SUCCESS, | |
73 | buf, p - buf); | |
74 | ap_sta_set_authorized(hapd, sta, 1); | |
75 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; | |
76 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; | |
77 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; | |
78 | hostapd_set_sta_flags(hapd, sta); | |
79 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS); | |
80 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); | |
81 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); | |
82 | os_free(sta->fils_pending_assoc_req); | |
83 | sta->fils_pending_assoc_req = NULL; | |
84 | sta->fils_pending_assoc_req_len = 0; | |
85 | wpabuf_free(sta->fils_hlp_resp); | |
86 | sta->fils_hlp_resp = NULL; | |
87 | wpabuf_free(sta->hlp_dhcp_discover); | |
88 | sta->hlp_dhcp_discover = NULL; | |
89 | fils_hlp_deinit(hapd); | |
90 | ||
91 | /* | |
92 | * Remove the station in case transmission of a success response fails | |
93 | * (the STA was added associated to the driver) or if the station was | |
94 | * previously added unassociated. | |
95 | */ | |
96 | if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) { | |
97 | hostapd_drv_sta_remove(hapd, sta->addr); | |
98 | sta->added_unassoc = 0; | |
99 | } | |
100 | } | |
101 | #endif /* CONFIG_FILS */ | |
b5b969e9 JM |
102 | |
103 | ||
b5b969e9 | 104 | int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr, |
2bb20281 | 105 | const u8 *req_ies, size_t req_ies_len, int reassoc) |
b5b969e9 JM |
106 | { |
107 | struct sta_info *sta; | |
108 | int new_assoc, res; | |
c41a1095 | 109 | struct ieee802_11_elems elems; |
2bb20281 JM |
110 | const u8 *ie; |
111 | size_t ielen; | |
4ec1fd8e | 112 | #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_IEEE80211W) |
88b32a99 SP |
113 | u8 buf[sizeof(struct ieee80211_mgmt) + 1024]; |
114 | u8 *p = buf; | |
4ec1fd8e | 115 | #endif /* CONFIG_IEEE80211R_AP || CONFIG_IEEE80211W */ |
08a74e6a | 116 | u16 reason = WLAN_REASON_UNSPECIFIED; |
88b32a99 | 117 | u16 status = WLAN_STATUS_SUCCESS; |
94ddef3e | 118 | const u8 *p2p_dev_addr = NULL; |
b5b969e9 | 119 | |
68532a9c JM |
120 | if (addr == NULL) { |
121 | /* | |
122 | * This could potentially happen with unexpected event from the | |
123 | * driver wrapper. This was seen at least in one case where the | |
124 | * driver ended up being set to station mode while hostapd was | |
125 | * running, so better make sure we stop processing such an | |
126 | * event here. | |
127 | */ | |
48b06c17 JM |
128 | wpa_printf(MSG_DEBUG, |
129 | "hostapd_notif_assoc: Skip event with no address"); | |
68532a9c JM |
130 | return -1; |
131 | } | |
bbb921da | 132 | random_add_randomness(addr, ETH_ALEN); |
68532a9c | 133 | |
b5b969e9 JM |
134 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
135 | HOSTAPD_LEVEL_INFO, "associated"); | |
136 | ||
2bb20281 | 137 | ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0); |
c41a1095 JM |
138 | if (elems.wps_ie) { |
139 | ie = elems.wps_ie - 2; | |
140 | ielen = elems.wps_ie_len + 2; | |
141 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq"); | |
142 | } else if (elems.rsn_ie) { | |
143 | ie = elems.rsn_ie - 2; | |
144 | ielen = elems.rsn_ie_len + 2; | |
145 | wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq"); | |
146 | } else if (elems.wpa_ie) { | |
147 | ie = elems.wpa_ie - 2; | |
148 | ielen = elems.wpa_ie_len + 2; | |
149 | wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq"); | |
a14896e8 JM |
150 | #ifdef CONFIG_HS20 |
151 | } else if (elems.osen) { | |
152 | ie = elems.osen - 2; | |
153 | ielen = elems.osen_len + 2; | |
154 | wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq"); | |
155 | #endif /* CONFIG_HS20 */ | |
c41a1095 JM |
156 | } else { |
157 | ie = NULL; | |
158 | ielen = 0; | |
48b06c17 JM |
159 | wpa_printf(MSG_DEBUG, |
160 | "STA did not include WPS/RSN/WPA IE in (Re)AssocReq"); | |
c41a1095 JM |
161 | } |
162 | ||
b5b969e9 JM |
163 | sta = ap_get_sta(hapd, addr); |
164 | if (sta) { | |
4331263b | 165 | ap_sta_no_session_timeout(hapd, sta); |
b5b969e9 | 166 | accounting_sta_stop(hapd, sta); |
c72bd6d4 JM |
167 | |
168 | /* | |
169 | * Make sure that the previously registered inactivity timer | |
170 | * will not remove the STA immediately. | |
171 | */ | |
172 | sta->timeout_next = STA_NULLFUNC; | |
b5b969e9 JM |
173 | } else { |
174 | sta = ap_sta_add(hapd, addr); | |
8bd0fc0e JM |
175 | if (sta == NULL) { |
176 | hostapd_drv_sta_disassoc(hapd, addr, | |
177 | WLAN_REASON_DISASSOC_AP_BUSY); | |
b5b969e9 | 178 | return -1; |
8bd0fc0e | 179 | } |
b5b969e9 | 180 | } |
17f6b900 | 181 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
b5b969e9 | 182 | |
bb4e19e3 SD |
183 | /* |
184 | * ACL configurations to the drivers (implementing AP SME and ACL | |
185 | * offload) without hostapd's knowledge, can result in a disconnection | |
186 | * though the driver accepts the connection. Skip the hostapd check for | |
187 | * ACL if the driver supports ACL offload to avoid potentially | |
188 | * conflicting ACL rules. | |
189 | */ | |
190 | if (hapd->iface->drv_max_acl_mac_addrs == 0 && | |
191 | hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) { | |
0603bcb7 AN |
192 | wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect", |
193 | MAC2STR(addr)); | |
194 | reason = WLAN_REASON_UNSPECIFIED; | |
195 | goto fail; | |
196 | } | |
197 | ||
b305c684 JM |
198 | #ifdef CONFIG_P2P |
199 | if (elems.p2p) { | |
200 | wpabuf_free(sta->p2p_ie); | |
2bb20281 | 201 | sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, |
b305c684 | 202 | P2P_IE_VENDOR_TYPE); |
94ddef3e JM |
203 | if (sta->p2p_ie) |
204 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); | |
b305c684 JM |
205 | } |
206 | #endif /* CONFIG_P2P */ | |
207 | ||
9c47f6a2 PX |
208 | #ifdef CONFIG_IEEE80211N |
209 | #ifdef NEED_AP_MLME | |
210 | if (elems.ht_capabilities && | |
9c47f6a2 PX |
211 | (hapd->iface->conf->ht_capab & |
212 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { | |
213 | struct ieee80211_ht_capabilities *ht_cap = | |
214 | (struct ieee80211_ht_capabilities *) | |
215 | elems.ht_capabilities; | |
216 | ||
217 | if (le_to_host16(ht_cap->ht_capabilities_info) & | |
218 | HT_CAP_INFO_40MHZ_INTOLERANT) | |
219 | ht40_intolerant_add(hapd->iface, sta); | |
220 | } | |
221 | #endif /* NEED_AP_MLME */ | |
222 | #endif /* CONFIG_IEEE80211N */ | |
223 | ||
c551700f KP |
224 | #ifdef CONFIG_INTERWORKING |
225 | if (elems.ext_capab && elems.ext_capab_len > 4) { | |
226 | if (elems.ext_capab[4] & 0x01) | |
227 | sta->qos_map_enabled = 1; | |
228 | } | |
229 | #endif /* CONFIG_INTERWORKING */ | |
230 | ||
f403dcd6 JM |
231 | #ifdef CONFIG_HS20 |
232 | wpabuf_free(sta->hs20_ie); | |
233 | if (elems.hs20 && elems.hs20_len > 4) { | |
234 | sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4, | |
235 | elems.hs20_len - 4); | |
236 | } else | |
237 | sta->hs20_ie = NULL; | |
238 | #endif /* CONFIG_HS20 */ | |
239 | ||
ae667c08 AN |
240 | #ifdef CONFIG_FST |
241 | wpabuf_free(sta->mb_ies); | |
242 | if (hapd->iface->fst) | |
243 | sta->mb_ies = mb_ies_by_info(&elems.mb_ies); | |
244 | else | |
245 | sta->mb_ies = NULL; | |
246 | #endif /* CONFIG_FST */ | |
247 | ||
6332aaf3 JM |
248 | mbo_ap_check_sta_assoc(hapd, sta, &elems); |
249 | ||
adf0478e JM |
250 | ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes, |
251 | elems.supp_op_classes_len); | |
252 | ||
b5b969e9 JM |
253 | if (hapd->conf->wpa) { |
254 | if (ie == NULL || ielen == 0) { | |
633d4469 | 255 | #ifdef CONFIG_WPS |
b5b969e9 | 256 | if (hapd->conf->wps_state) { |
48b06c17 JM |
257 | wpa_printf(MSG_DEBUG, |
258 | "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use"); | |
b5b969e9 JM |
259 | sta->flags |= WLAN_STA_MAYBE_WPS; |
260 | goto skip_wpa_check; | |
261 | } | |
633d4469 | 262 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
263 | |
264 | wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA"); | |
265 | return -1; | |
266 | } | |
633d4469 | 267 | #ifdef CONFIG_WPS |
b5b969e9 JM |
268 | if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 && |
269 | os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) { | |
17f6b900 | 270 | struct wpabuf *wps; |
48b06c17 | 271 | |
b5b969e9 | 272 | sta->flags |= WLAN_STA_WPS; |
17f6b900 JM |
273 | wps = ieee802_11_vendor_ie_concat(ie, ielen, |
274 | WPS_IE_VENDOR_TYPE); | |
275 | if (wps) { | |
276 | if (wps_is_20(wps)) { | |
48b06c17 JM |
277 | wpa_printf(MSG_DEBUG, |
278 | "WPS: STA supports WPS 2.0"); | |
17f6b900 JM |
279 | sta->flags |= WLAN_STA_WPS2; |
280 | } | |
281 | wpabuf_free(wps); | |
282 | } | |
b5b969e9 JM |
283 | goto skip_wpa_check; |
284 | } | |
633d4469 | 285 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
286 | |
287 | if (sta->wpa_sm == NULL) | |
288 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
94ddef3e JM |
289 | sta->addr, |
290 | p2p_dev_addr); | |
b5b969e9 | 291 | if (sta->wpa_sm == NULL) { |
48b06c17 JM |
292 | wpa_printf(MSG_ERROR, |
293 | "Failed to initialize WPA state machine"); | |
b5b969e9 JM |
294 | return -1; |
295 | } | |
296 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, | |
88b32a99 | 297 | ie, ielen, |
09368515 JM |
298 | elems.mdie, elems.mdie_len, |
299 | elems.owe_dh, elems.owe_dh_len); | |
b5b969e9 | 300 | if (res != WPA_IE_OK) { |
48b06c17 JM |
301 | wpa_printf(MSG_DEBUG, |
302 | "WPA/RSN information element rejected? (res %u)", | |
303 | res); | |
b5b969e9 | 304 | wpa_hexdump(MSG_DEBUG, "IE", ie, ielen); |
88b32a99 | 305 | if (res == WPA_INVALID_GROUP) { |
08a74e6a | 306 | reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; |
88b32a99 SP |
307 | status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; |
308 | } else if (res == WPA_INVALID_PAIRWISE) { | |
08a74e6a | 309 | reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID; |
88b32a99 SP |
310 | status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; |
311 | } else if (res == WPA_INVALID_AKMP) { | |
08a74e6a | 312 | reason = WLAN_REASON_AKMP_NOT_VALID; |
88b32a99 SP |
313 | status = WLAN_STATUS_AKMP_NOT_VALID; |
314 | } | |
355d36a7 | 315 | #ifdef CONFIG_IEEE80211W |
88b32a99 | 316 | else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) { |
08a74e6a | 317 | reason = WLAN_REASON_INVALID_IE; |
88b32a99 SP |
318 | status = WLAN_STATUS_INVALID_IE; |
319 | } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) { | |
08a74e6a | 320 | reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; |
88b32a99 SP |
321 | status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; |
322 | } | |
355d36a7 | 323 | #endif /* CONFIG_IEEE80211W */ |
88b32a99 | 324 | else { |
08a74e6a | 325 | reason = WLAN_REASON_INVALID_IE; |
88b32a99 SP |
326 | status = WLAN_STATUS_INVALID_IE; |
327 | } | |
08a74e6a | 328 | goto fail; |
b5b969e9 | 329 | } |
7d9c0cd3 MP |
330 | #ifdef CONFIG_IEEE80211W |
331 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && | |
332 | sta->sa_query_count > 0) | |
333 | ap_check_sa_query_timeout(hapd, sta); | |
334 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && | |
335 | (sta->auth_alg != WLAN_AUTH_FT)) { | |
336 | /* | |
337 | * STA has already been associated with MFP and SA | |
338 | * Query timeout has not been reached. Reject the | |
339 | * association attempt temporarily and start SA Query, | |
340 | * if one is not pending. | |
341 | */ | |
342 | ||
343 | if (sta->sa_query_count == 0) | |
344 | ap_sta_start_sa_query(hapd, sta); | |
345 | ||
7d9c0cd3 MP |
346 | status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
347 | ||
348 | p = hostapd_eid_assoc_comeback_time(hapd, sta, p); | |
349 | ||
350 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, | |
351 | p - buf); | |
7d9c0cd3 MP |
352 | return 0; |
353 | } | |
354 | ||
355 | if (wpa_auth_uses_mfp(sta->wpa_sm)) | |
356 | sta->flags |= WLAN_STA_MFP; | |
357 | else | |
358 | sta->flags &= ~WLAN_STA_MFP; | |
359 | #endif /* CONFIG_IEEE80211W */ | |
360 | ||
4ec1fd8e | 361 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 SP |
362 | if (sta->auth_alg == WLAN_AUTH_FT) { |
363 | status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies, | |
364 | req_ies_len); | |
365 | if (status != WLAN_STATUS_SUCCESS) { | |
366 | if (status == WLAN_STATUS_INVALID_PMKID) | |
367 | reason = WLAN_REASON_INVALID_IE; | |
368 | if (status == WLAN_STATUS_INVALID_MDIE) | |
369 | reason = WLAN_REASON_INVALID_IE; | |
370 | if (status == WLAN_STATUS_INVALID_FTIE) | |
371 | reason = WLAN_REASON_INVALID_IE; | |
372 | goto fail; | |
373 | } | |
374 | } | |
4ec1fd8e | 375 | #endif /* CONFIG_IEEE80211R_AP */ |
a9aca28b | 376 | } else if (hapd->conf->wps_state) { |
633d4469 | 377 | #ifdef CONFIG_WPS |
17f6b900 | 378 | struct wpabuf *wps; |
48b06c17 | 379 | |
2bb20281 JM |
380 | if (req_ies) |
381 | wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, | |
fa15d405 JM |
382 | WPS_IE_VENDOR_TYPE); |
383 | else | |
384 | wps = NULL; | |
54f489be | 385 | #ifdef CONFIG_WPS_STRICT |
fa15d405 | 386 | if (wps && wps_validate_assoc_req(wps) < 0) { |
08a74e6a | 387 | reason = WLAN_REASON_INVALID_IE; |
88b32a99 | 388 | status = WLAN_STATUS_INVALID_IE; |
fa15d405 | 389 | wpabuf_free(wps); |
08a74e6a | 390 | goto fail; |
54f489be | 391 | } |
54f489be | 392 | #endif /* CONFIG_WPS_STRICT */ |
fa15d405 | 393 | if (wps) { |
a9aca28b | 394 | sta->flags |= WLAN_STA_WPS; |
fa15d405 | 395 | if (wps_is_20(wps)) { |
48b06c17 JM |
396 | wpa_printf(MSG_DEBUG, |
397 | "WPS: STA supports WPS 2.0"); | |
17f6b900 JM |
398 | sta->flags |= WLAN_STA_WPS2; |
399 | } | |
a9aca28b JM |
400 | } else |
401 | sta->flags |= WLAN_STA_MAYBE_WPS; | |
17f6b900 | 402 | wpabuf_free(wps); |
633d4469 | 403 | #endif /* CONFIG_WPS */ |
a14896e8 JM |
404 | #ifdef CONFIG_HS20 |
405 | } else if (hapd->conf->osen) { | |
406 | if (elems.osen == NULL) { | |
407 | hostapd_logger( | |
408 | hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
409 | HOSTAPD_LEVEL_INFO, | |
410 | "No HS 2.0 OSEN element in association request"); | |
411 | return WLAN_STATUS_INVALID_IE; | |
412 | } | |
413 | ||
414 | wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association"); | |
415 | if (sta->wpa_sm == NULL) | |
416 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
417 | sta->addr, NULL); | |
418 | if (sta->wpa_sm == NULL) { | |
48b06c17 JM |
419 | wpa_printf(MSG_WARNING, |
420 | "Failed to initialize WPA state machine"); | |
a14896e8 JM |
421 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
422 | } | |
423 | if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm, | |
424 | elems.osen - 2, elems.osen_len + 2) < 0) | |
425 | return WLAN_STATUS_INVALID_IE; | |
426 | #endif /* CONFIG_HS20 */ | |
b5b969e9 | 427 | } |
4c572281 JM |
428 | |
429 | #ifdef CONFIG_MBO | |
430 | if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) && | |
431 | elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) && | |
432 | hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { | |
433 | wpa_printf(MSG_INFO, | |
434 | "MBO: Reject WPA2 association without PMF"); | |
435 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
436 | } | |
437 | #endif /* CONFIG_MBO */ | |
438 | ||
633d4469 | 439 | #ifdef CONFIG_WPS |
b5b969e9 | 440 | skip_wpa_check: |
633d4469 | 441 | #endif /* CONFIG_WPS */ |
b5b969e9 | 442 | |
4ec1fd8e | 443 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 SP |
444 | p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf), |
445 | sta->auth_alg, req_ies, req_ies_len); | |
cc20edc9 | 446 | #endif /* CONFIG_IEEE80211R_AP */ |
88b32a99 | 447 | |
fa61bff6 JM |
448 | #ifdef CONFIG_FILS |
449 | if (sta->auth_alg == WLAN_AUTH_FILS_SK || | |
450 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || | |
451 | sta->auth_alg == WLAN_AUTH_FILS_PK) { | |
8b5ddda5 JM |
452 | int delay_assoc = 0; |
453 | ||
fa61bff6 JM |
454 | if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies, |
455 | req_ies_len, | |
456 | sta->fils_session)) { | |
457 | wpa_printf(MSG_DEBUG, | |
458 | "FILS: Session validation failed"); | |
459 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
460 | } | |
461 | ||
462 | res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies, | |
463 | req_ies_len); | |
464 | if (res < 0) { | |
465 | wpa_printf(MSG_DEBUG, | |
466 | "FILS: Key Confirm validation failed"); | |
467 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
468 | } | |
469 | ||
8b5ddda5 | 470 | if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) { |
fa61bff6 | 471 | wpa_printf(MSG_DEBUG, |
8b5ddda5 JM |
472 | "FILS: Delaying Assoc Response (HLP)"); |
473 | delay_assoc = 1; | |
474 | } else { | |
475 | wpa_printf(MSG_DEBUG, | |
476 | "FILS: Going ahead with Assoc Response (no HLP)"); | |
477 | } | |
478 | ||
479 | if (sta) { | |
480 | wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup"); | |
481 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); | |
482 | os_free(sta->fils_pending_assoc_req); | |
483 | sta->fils_pending_assoc_req = NULL; | |
484 | sta->fils_pending_assoc_req_len = 0; | |
485 | wpabuf_free(sta->fils_hlp_resp); | |
486 | sta->fils_hlp_resp = NULL; | |
487 | sta->fils_drv_assoc_finish = 0; | |
fa61bff6 JM |
488 | } |
489 | ||
8b5ddda5 JM |
490 | if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) { |
491 | u8 *req_tmp; | |
492 | ||
493 | req_tmp = os_malloc(req_ies_len); | |
494 | if (!req_tmp) { | |
495 | wpa_printf(MSG_DEBUG, | |
496 | "FILS: buffer allocation failed for assoc req"); | |
497 | goto fail; | |
498 | } | |
499 | os_memcpy(req_tmp, req_ies, req_ies_len); | |
500 | sta->fils_pending_assoc_req = req_tmp; | |
501 | sta->fils_pending_assoc_req_len = req_ies_len; | |
502 | sta->fils_pending_assoc_is_reassoc = reassoc; | |
503 | sta->fils_drv_assoc_finish = 1; | |
504 | wpa_printf(MSG_DEBUG, | |
505 | "FILS: Waiting for HLP processing before sending (Re)Association Response frame to " | |
506 | MACSTR, MAC2STR(sta->addr)); | |
507 | eloop_register_timeout( | |
508 | 0, hapd->conf->fils_hlp_wait_time * 1024, | |
509 | fils_hlp_timeout, hapd, sta); | |
510 | return 0; | |
511 | } | |
fa61bff6 | 512 | p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p, |
8b5ddda5 JM |
513 | elems.fils_session, |
514 | sta->fils_hlp_resp); | |
fa61bff6 JM |
515 | wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)", |
516 | buf, p - buf); | |
517 | } | |
518 | #endif /* CONFIG_FILS */ | |
519 | ||
cc20edc9 | 520 | #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) |
88b32a99 | 521 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); |
e4474c1c | 522 | |
cc20edc9 JM |
523 | if (sta->auth_alg == WLAN_AUTH_FT || |
524 | sta->auth_alg == WLAN_AUTH_FILS_SK || | |
525 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || | |
526 | sta->auth_alg == WLAN_AUTH_FILS_PK) | |
e4474c1c | 527 | ap_sta_set_authorized(hapd, sta, 1); |
cc20edc9 | 528 | #else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */ |
88b32a99 SP |
529 | /* Keep compiler silent about unused variables */ |
530 | if (status) { | |
531 | } | |
cc20edc9 | 532 | #endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */ |
88b32a99 | 533 | |
b5b969e9 JM |
534 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; |
535 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; | |
3578e665 | 536 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
88b32a99 | 537 | |
e4474c1c DPS |
538 | hostapd_set_sta_flags(hapd, sta); |
539 | ||
88b32a99 SP |
540 | if (reassoc && (sta->auth_alg == WLAN_AUTH_FT)) |
541 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); | |
957bff83 JM |
542 | #ifdef CONFIG_FILS |
543 | else if (sta->auth_alg == WLAN_AUTH_FILS_SK || | |
544 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || | |
545 | sta->auth_alg == WLAN_AUTH_FILS_PK) | |
546 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS); | |
547 | #endif /* CONFIG_FILS */ | |
88b32a99 SP |
548 | else |
549 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); | |
b5b969e9 JM |
550 | |
551 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); | |
552 | ||
553 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); | |
554 | ||
ef796391 | 555 | #ifdef CONFIG_P2P |
99c01af9 JM |
556 | if (req_ies) { |
557 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, | |
558 | req_ies, req_ies_len); | |
559 | } | |
ef796391 JM |
560 | #endif /* CONFIG_P2P */ |
561 | ||
b5b969e9 | 562 | return 0; |
08a74e6a JM |
563 | |
564 | fail: | |
4ec1fd8e | 565 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 | 566 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); |
4ec1fd8e | 567 | #endif /* CONFIG_IEEE80211R_AP */ |
08a74e6a JM |
568 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); |
569 | ap_free_sta(hapd, sta); | |
570 | return -1; | |
b5b969e9 JM |
571 | } |
572 | ||
573 | ||
574 | void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr) | |
575 | { | |
576 | struct sta_info *sta; | |
577 | ||
83e843e8 JM |
578 | if (addr == NULL) { |
579 | /* | |
580 | * This could potentially happen with unexpected event from the | |
581 | * driver wrapper. This was seen at least in one case where the | |
582 | * driver ended up reporting a station mode event while hostapd | |
583 | * was running, so better make sure we stop processing such an | |
584 | * event here. | |
585 | */ | |
48b06c17 JM |
586 | wpa_printf(MSG_DEBUG, |
587 | "hostapd_notif_disassoc: Skip event with no address"); | |
1f4c7b6b | 588 | return; |
83e843e8 JM |
589 | } |
590 | ||
b5b969e9 JM |
591 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
592 | HOSTAPD_LEVEL_INFO, "disassociated"); | |
593 | ||
594 | sta = ap_get_sta(hapd, addr); | |
595 | if (sta == NULL) { | |
48b06c17 JM |
596 | wpa_printf(MSG_DEBUG, |
597 | "Disassociation notification for unknown STA " | |
598 | MACSTR, MAC2STR(addr)); | |
b5b969e9 JM |
599 | return; |
600 | } | |
601 | ||
ae055af4 | 602 | ap_sta_set_authorized(hapd, sta, 0); |
b5b969e9 JM |
603 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
604 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); | |
605 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; | |
606 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
607 | ap_free_sta(hapd, sta); | |
608 | } | |
609 | ||
610 | ||
0d7e5a3a JB |
611 | void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr) |
612 | { | |
613 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
614 | ||
615 | if (!sta || !hapd->conf->disassoc_low_ack) | |
616 | return; | |
617 | ||
618 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, | |
48b06c17 JM |
619 | HOSTAPD_LEVEL_INFO, |
620 | "disconnected due to excessive missing ACKs"); | |
0d7e5a3a | 621 | hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK); |
5f99d962 | 622 | ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK); |
0d7e5a3a JB |
623 | } |
624 | ||
625 | ||
1b487b8b | 626 | void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht, |
8d1fdde7 | 627 | int offset, int width, int cf1, int cf2) |
1b487b8b | 628 | { |
c7803a02 | 629 | #ifdef NEED_AP_MLME |
d308a44f LC |
630 | int channel, chwidth, is_dfs; |
631 | u8 seg0_idx = 0, seg1_idx = 0; | |
1b487b8b TP |
632 | |
633 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
2f06bcb3 JM |
634 | HOSTAPD_LEVEL_INFO, |
635 | "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d", | |
636 | freq, ht, offset, width, channel_width_to_string(width), | |
637 | cf1, cf2); | |
1b487b8b TP |
638 | |
639 | hapd->iface->freq = freq; | |
640 | ||
641 | channel = hostapd_hw_get_channel(hapd, freq); | |
642 | if (!channel) { | |
643 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
48b06c17 JM |
644 | HOSTAPD_LEVEL_WARNING, |
645 | "driver switched to bad channel!"); | |
1b487b8b TP |
646 | return; |
647 | } | |
648 | ||
8d1fdde7 JD |
649 | switch (width) { |
650 | case CHAN_WIDTH_80: | |
651 | chwidth = VHT_CHANWIDTH_80MHZ; | |
652 | break; | |
653 | case CHAN_WIDTH_80P80: | |
654 | chwidth = VHT_CHANWIDTH_80P80MHZ; | |
655 | break; | |
656 | case CHAN_WIDTH_160: | |
657 | chwidth = VHT_CHANWIDTH_160MHZ; | |
658 | break; | |
659 | case CHAN_WIDTH_20_NOHT: | |
660 | case CHAN_WIDTH_20: | |
661 | case CHAN_WIDTH_40: | |
662 | default: | |
663 | chwidth = VHT_CHANWIDTH_USE_HT; | |
664 | break; | |
665 | } | |
666 | ||
667 | switch (hapd->iface->current_mode->mode) { | |
668 | case HOSTAPD_MODE_IEEE80211A: | |
669 | if (cf1 > 5000) | |
670 | seg0_idx = (cf1 - 5000) / 5; | |
671 | if (cf2 > 5000) | |
672 | seg1_idx = (cf2 - 5000) / 5; | |
673 | break; | |
674 | default: | |
d308a44f LC |
675 | ieee80211_freq_to_chan(cf1, &seg0_idx); |
676 | ieee80211_freq_to_chan(cf2, &seg1_idx); | |
8d1fdde7 JD |
677 | break; |
678 | } | |
679 | ||
1b487b8b TP |
680 | hapd->iconf->channel = channel; |
681 | hapd->iconf->ieee80211n = ht; | |
5de74818 JM |
682 | if (!ht) |
683 | hapd->iconf->ieee80211ac = 0; | |
1b487b8b | 684 | hapd->iconf->secondary_channel = offset; |
8d1fdde7 JD |
685 | hapd->iconf->vht_oper_chwidth = chwidth; |
686 | hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx; | |
687 | hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx; | |
bf281c12 | 688 | |
1e2aaffb AK |
689 | is_dfs = ieee80211_is_dfs(freq); |
690 | ||
6782b684 MK |
691 | if (hapd->csa_in_progress && |
692 | freq == hapd->cs_freq_params.freq) { | |
bf281c12 | 693 | hostapd_cleanup_cs_params(hapd); |
6782b684 | 694 | ieee802_11_set_beacon(hapd); |
bf281c12 | 695 | |
1e2aaffb AK |
696 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED |
697 | "freq=%d dfs=%d", freq, is_dfs); | |
698 | } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) { | |
699 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED | |
700 | "freq=%d dfs=%d", freq, is_dfs); | |
bf281c12 | 701 | } |
c7803a02 | 702 | #endif /* NEED_AP_MLME */ |
1b487b8b TP |
703 | } |
704 | ||
705 | ||
3140803b RM |
706 | void hostapd_event_connect_failed_reason(struct hostapd_data *hapd, |
707 | const u8 *addr, int reason_code) | |
708 | { | |
709 | switch (reason_code) { | |
710 | case MAX_CLIENT_REACHED: | |
711 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR, | |
712 | MAC2STR(addr)); | |
713 | break; | |
714 | case BLOCKED_CLIENT: | |
715 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR, | |
716 | MAC2STR(addr)); | |
717 | break; | |
718 | } | |
719 | } | |
720 | ||
721 | ||
16689c7c | 722 | #ifdef CONFIG_ACS |
d9909717 TB |
723 | void hostapd_acs_channel_selected(struct hostapd_data *hapd, |
724 | struct acs_selected_channels *acs_res) | |
16689c7c | 725 | { |
3784c058 | 726 | int ret, i; |
e1d00d47 | 727 | int err = 0; |
16689c7c PX |
728 | |
729 | if (hapd->iconf->channel) { | |
730 | wpa_printf(MSG_INFO, "ACS: Channel was already set to %d", | |
731 | hapd->iconf->channel); | |
732 | return; | |
733 | } | |
734 | ||
3784c058 PX |
735 | if (!hapd->iface->current_mode) { |
736 | for (i = 0; i < hapd->iface->num_hw_features; i++) { | |
737 | struct hostapd_hw_modes *mode = | |
738 | &hapd->iface->hw_features[i]; | |
739 | ||
740 | if (mode->mode == acs_res->hw_mode) { | |
741 | hapd->iface->current_mode = mode; | |
742 | break; | |
743 | } | |
744 | } | |
745 | if (!hapd->iface->current_mode) { | |
746 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
747 | HOSTAPD_LEVEL_WARNING, | |
748 | "driver selected to bad hw_mode"); | |
e1d00d47 PX |
749 | err = 1; |
750 | goto out; | |
3784c058 PX |
751 | } |
752 | } | |
753 | ||
857d9422 | 754 | hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel); |
16689c7c | 755 | |
857d9422 | 756 | if (!acs_res->pri_channel) { |
16689c7c PX |
757 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
758 | HOSTAPD_LEVEL_WARNING, | |
759 | "driver switched to bad channel"); | |
e1d00d47 PX |
760 | err = 1; |
761 | goto out; | |
16689c7c PX |
762 | } |
763 | ||
857d9422 MM |
764 | hapd->iconf->channel = acs_res->pri_channel; |
765 | hapd->iconf->acs = 1; | |
16689c7c | 766 | |
857d9422 | 767 | if (acs_res->sec_channel == 0) |
16689c7c | 768 | hapd->iconf->secondary_channel = 0; |
857d9422 | 769 | else if (acs_res->sec_channel < acs_res->pri_channel) |
16689c7c | 770 | hapd->iconf->secondary_channel = -1; |
857d9422 | 771 | else if (acs_res->sec_channel > acs_res->pri_channel) |
16689c7c PX |
772 | hapd->iconf->secondary_channel = 1; |
773 | else { | |
774 | wpa_printf(MSG_ERROR, "Invalid secondary channel!"); | |
e1d00d47 PX |
775 | err = 1; |
776 | goto out; | |
16689c7c PX |
777 | } |
778 | ||
857d9422 MM |
779 | if (hapd->iface->conf->ieee80211ac) { |
780 | /* set defaults for backwards compatibility */ | |
781 | hapd->iconf->vht_oper_centr_freq_seg1_idx = 0; | |
782 | hapd->iconf->vht_oper_centr_freq_seg0_idx = 0; | |
783 | hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT; | |
784 | if (acs_res->ch_width == 80) { | |
785 | hapd->iconf->vht_oper_centr_freq_seg0_idx = | |
786 | acs_res->vht_seg0_center_ch; | |
787 | hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ; | |
788 | } else if (acs_res->ch_width == 160) { | |
789 | if (acs_res->vht_seg1_center_ch == 0) { | |
790 | hapd->iconf->vht_oper_centr_freq_seg0_idx = | |
791 | acs_res->vht_seg0_center_ch; | |
792 | hapd->iconf->vht_oper_chwidth = | |
793 | VHT_CHANWIDTH_160MHZ; | |
794 | } else { | |
795 | hapd->iconf->vht_oper_centr_freq_seg0_idx = | |
796 | acs_res->vht_seg0_center_ch; | |
797 | hapd->iconf->vht_oper_centr_freq_seg1_idx = | |
798 | acs_res->vht_seg1_center_ch; | |
799 | hapd->iconf->vht_oper_chwidth = | |
800 | VHT_CHANWIDTH_80P80MHZ; | |
801 | } | |
802 | } | |
803 | } | |
804 | ||
e1d00d47 PX |
805 | out: |
806 | ret = hostapd_acs_completed(hapd->iface, err); | |
16689c7c PX |
807 | if (ret) { |
808 | wpa_printf(MSG_ERROR, | |
809 | "ACS: Possibly channel configuration is invalid"); | |
810 | } | |
811 | } | |
812 | #endif /* CONFIG_ACS */ | |
813 | ||
814 | ||
04a85e44 | 815 | int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da, |
baf513d6 JB |
816 | const u8 *bssid, const u8 *ie, size_t ie_len, |
817 | int ssi_signal) | |
e67b55fb JM |
818 | { |
819 | size_t i; | |
820 | int ret = 0; | |
821 | ||
b211f3eb JM |
822 | if (sa == NULL || ie == NULL) |
823 | return -1; | |
824 | ||
825 | random_add_randomness(sa, ETH_ALEN); | |
e67b55fb JM |
826 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) { |
827 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, | |
baf513d6 JB |
828 | sa, da, bssid, ie, ie_len, |
829 | ssi_signal) > 0) { | |
e67b55fb JM |
830 | ret = 1; |
831 | break; | |
832 | } | |
833 | } | |
834 | return ret; | |
835 | } | |
836 | ||
837 | ||
5c61a282 JM |
838 | #ifdef HOSTAPD |
839 | ||
4ec1fd8e | 840 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 SP |
841 | static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst, |
842 | const u8 *bssid, | |
843 | u16 auth_transaction, u16 status, | |
844 | const u8 *ies, size_t ies_len) | |
845 | { | |
846 | struct hostapd_data *hapd = ctx; | |
847 | struct sta_info *sta; | |
848 | ||
849 | sta = ap_get_sta(hapd, dst); | |
850 | if (sta == NULL) | |
851 | return; | |
852 | ||
853 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, | |
854 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); | |
855 | sta->flags |= WLAN_STA_AUTH; | |
856 | ||
857 | hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len); | |
858 | } | |
4ec1fd8e | 859 | #endif /* CONFIG_IEEE80211R_AP */ |
88b32a99 SP |
860 | |
861 | ||
fa61bff6 JM |
862 | #ifdef CONFIG_FILS |
863 | static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd, | |
864 | struct sta_info *sta, u16 resp, | |
865 | struct wpabuf *data, int pub) | |
866 | { | |
867 | if (resp == WLAN_STATUS_SUCCESS) { | |
868 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
869 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)"); | |
870 | sta->flags |= WLAN_STA_AUTH; | |
871 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); | |
872 | sta->auth_alg = WLAN_AUTH_FILS_SK; | |
873 | mlme_authenticate_indication(hapd, sta); | |
874 | } else { | |
875 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
876 | HOSTAPD_LEVEL_DEBUG, | |
877 | "authentication failed (FILS)"); | |
878 | } | |
879 | ||
880 | hostapd_sta_auth(hapd, sta->addr, 2, resp, | |
881 | data ? wpabuf_head(data) : NULL, | |
882 | data ? wpabuf_len(data) : 0); | |
883 | wpabuf_free(data); | |
884 | } | |
885 | #endif /* CONFIG_FILS */ | |
886 | ||
887 | ||
88b32a99 SP |
888 | static void hostapd_notif_auth(struct hostapd_data *hapd, |
889 | struct auth_info *rx_auth) | |
890 | { | |
891 | struct sta_info *sta; | |
892 | u16 status = WLAN_STATUS_SUCCESS; | |
893 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; | |
894 | size_t resp_ies_len = 0; | |
895 | ||
896 | sta = ap_get_sta(hapd, rx_auth->peer); | |
897 | if (!sta) { | |
898 | sta = ap_sta_add(hapd, rx_auth->peer); | |
899 | if (sta == NULL) { | |
728d9717 | 900 | status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
88b32a99 SP |
901 | goto fail; |
902 | } | |
903 | } | |
904 | sta->flags &= ~WLAN_STA_PREAUTH; | |
905 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); | |
4ec1fd8e | 906 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 SP |
907 | if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) { |
908 | sta->auth_alg = WLAN_AUTH_FT; | |
909 | if (sta->wpa_sm == NULL) | |
910 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
94ddef3e | 911 | sta->addr, NULL); |
88b32a99 | 912 | if (sta->wpa_sm == NULL) { |
48b06c17 JM |
913 | wpa_printf(MSG_DEBUG, |
914 | "FT: Failed to initialize WPA state machine"); | |
88b32a99 SP |
915 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
916 | goto fail; | |
917 | } | |
918 | wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid, | |
919 | rx_auth->auth_transaction, rx_auth->ies, | |
920 | rx_auth->ies_len, | |
921 | hostapd_notify_auth_ft_finish, hapd); | |
922 | return; | |
923 | } | |
4ec1fd8e | 924 | #endif /* CONFIG_IEEE80211R_AP */ |
fa61bff6 JM |
925 | |
926 | #ifdef CONFIG_FILS | |
927 | if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) { | |
928 | sta->auth_alg = WLAN_AUTH_FILS_SK; | |
929 | handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len, | |
930 | rx_auth->auth_type, rx_auth->auth_transaction, | |
931 | rx_auth->status_code, | |
932 | hostapd_notify_auth_fils_finish); | |
933 | return; | |
934 | } | |
935 | #endif /* CONFIG_FILS */ | |
936 | ||
88b32a99 SP |
937 | fail: |
938 | hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1, | |
939 | status, resp_ies, resp_ies_len); | |
940 | } | |
941 | ||
942 | ||
943 | static void hostapd_action_rx(struct hostapd_data *hapd, | |
dbfb8e82 | 944 | struct rx_mgmt *drv_mgmt) |
88b32a99 | 945 | { |
dbfb8e82 | 946 | struct ieee80211_mgmt *mgmt; |
88b32a99 | 947 | struct sta_info *sta; |
dbfb8e82 JM |
948 | size_t plen __maybe_unused; |
949 | u16 fc; | |
950 | ||
951 | if (drv_mgmt->frame_len < 24 + 1) | |
952 | return; | |
953 | ||
954 | plen = drv_mgmt->frame_len - 24 - 1; | |
955 | ||
956 | mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame; | |
957 | fc = le_to_host16(mgmt->frame_control); | |
958 | if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) | |
959 | return; /* handled by the driver */ | |
88b32a99 | 960 | |
48b06c17 | 961 | wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d", |
dbfb8e82 | 962 | mgmt->u.action.category, (int) plen); |
7d9c0cd3 | 963 | |
dbfb8e82 | 964 | sta = ap_get_sta(hapd, mgmt->sa); |
88b32a99 SP |
965 | if (sta == NULL) { |
966 | wpa_printf(MSG_DEBUG, "%s: station not found", __func__); | |
967 | return; | |
968 | } | |
4ec1fd8e | 969 | #ifdef CONFIG_IEEE80211R_AP |
dbfb8e82 JM |
970 | if (mgmt->u.action.category == WLAN_ACTION_FT) { |
971 | const u8 *payload = drv_mgmt->frame + 24 + 1; | |
48b06c17 | 972 | |
dbfb8e82 | 973 | wpa_ft_action_rx(sta->wpa_sm, payload, plen); |
88b32a99 | 974 | } |
4ec1fd8e | 975 | #endif /* CONFIG_IEEE80211R_AP */ |
7d9c0cd3 | 976 | #ifdef CONFIG_IEEE80211W |
dbfb8e82 JM |
977 | if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) { |
978 | ieee802_11_sa_query_action( | |
979 | hapd, mgmt->sa, | |
980 | mgmt->u.action.u.sa_query_resp.action, | |
981 | mgmt->u.action.u.sa_query_resp.trans_id); | |
7d9c0cd3 MP |
982 | } |
983 | #endif /* CONFIG_IEEE80211W */ | |
b5bf84ba | 984 | #ifdef CONFIG_WNM_AP |
dbfb8e82 JM |
985 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { |
986 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len); | |
d32d94db | 987 | } |
b5bf84ba | 988 | #endif /* CONFIG_WNM_AP */ |
037378ff AN |
989 | #ifdef CONFIG_FST |
990 | if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) { | |
991 | fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len); | |
992 | return; | |
993 | } | |
994 | #endif /* CONFIG_FST */ | |
9c2b8204 JM |
995 | #ifdef CONFIG_DPP |
996 | if (plen >= 1 + 4 && | |
997 | mgmt->u.action.u.vs_public_action.action == | |
998 | WLAN_PA_VENDOR_SPECIFIC && | |
999 | WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) == | |
1000 | OUI_WFA && | |
1001 | mgmt->u.action.u.vs_public_action.variable[0] == | |
1002 | DPP_OUI_TYPE) { | |
1003 | const u8 *pos, *end; | |
1004 | ||
1005 | pos = &mgmt->u.action.u.vs_public_action.variable[1]; | |
1006 | end = drv_mgmt->frame + drv_mgmt->frame_len; | |
1007 | hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos, | |
1008 | drv_mgmt->freq); | |
1009 | return; | |
1010 | } | |
1011 | #endif /* CONFIG_DPP */ | |
88b32a99 SP |
1012 | } |
1013 | ||
1014 | ||
fe6bdb77 | 1015 | #ifdef NEED_AP_MLME |
f8b1f695 | 1016 | |
f8b1f695 JM |
1017 | #define HAPD_BROADCAST ((struct hostapd_data *) -1) |
1018 | ||
1019 | static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface, | |
1020 | const u8 *bssid) | |
1021 | { | |
1022 | size_t i; | |
1023 | ||
1024 | if (bssid == NULL) | |
1025 | return NULL; | |
1026 | if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff && | |
1027 | bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff) | |
1028 | return HAPD_BROADCAST; | |
1029 | ||
1030 | for (i = 0; i < iface->num_bss; i++) { | |
1031 | if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) | |
1032 | return iface->bss[i]; | |
1033 | } | |
1034 | ||
1035 | return NULL; | |
1036 | } | |
1037 | ||
1038 | ||
1039 | static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, | |
9b90955e JB |
1040 | const u8 *bssid, const u8 *addr, |
1041 | int wds) | |
f8b1f695 | 1042 | { |
9b90955e | 1043 | hapd = get_hapd_bssid(hapd->iface, bssid); |
f8b1f695 JM |
1044 | if (hapd == NULL || hapd == HAPD_BROADCAST) |
1045 | return; | |
1046 | ||
9b90955e | 1047 | ieee802_11_rx_from_unknown(hapd, addr, wds); |
f8b1f695 JM |
1048 | } |
1049 | ||
1050 | ||
912b34f0 | 1051 | static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt) |
b5b969e9 | 1052 | { |
4b9841d3 | 1053 | struct hostapd_iface *iface = hapd->iface; |
b57e086c | 1054 | const struct ieee80211_hdr *hdr; |
4b9841d3 | 1055 | const u8 *bssid; |
2a8b7416 | 1056 | struct hostapd_frame_info fi; |
912b34f0 | 1057 | int ret; |
4b9841d3 | 1058 | |
5f7e1c06 JM |
1059 | #ifdef CONFIG_TESTING_OPTIONS |
1060 | if (hapd->ext_mgmt_frame_handling) { | |
1061 | size_t hex_len = 2 * rx_mgmt->frame_len + 1; | |
1062 | char *hex = os_malloc(hex_len); | |
48b06c17 | 1063 | |
5f7e1c06 JM |
1064 | if (hex) { |
1065 | wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame, | |
1066 | rx_mgmt->frame_len); | |
1067 | wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex); | |
1068 | os_free(hex); | |
1069 | } | |
1070 | return 1; | |
1071 | } | |
1072 | #endif /* CONFIG_TESTING_OPTIONS */ | |
1073 | ||
2a8b7416 JM |
1074 | hdr = (const struct ieee80211_hdr *) rx_mgmt->frame; |
1075 | bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len); | |
4b9841d3 | 1076 | if (bssid == NULL) |
912b34f0 | 1077 | return 0; |
4b9841d3 JM |
1078 | |
1079 | hapd = get_hapd_bssid(iface, bssid); | |
1080 | if (hapd == NULL) { | |
48b06c17 | 1081 | u16 fc = le_to_host16(hdr->frame_control); |
4b9841d3 JM |
1082 | |
1083 | /* | |
1084 | * Drop frames to unknown BSSIDs except for Beacon frames which | |
1085 | * could be used to update neighbor information. | |
1086 | */ | |
1087 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
1088 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
1089 | hapd = iface->bss[0]; | |
1090 | else | |
912b34f0 | 1091 | return 0; |
4b9841d3 JM |
1092 | } |
1093 | ||
2a8b7416 JM |
1094 | os_memset(&fi, 0, sizeof(fi)); |
1095 | fi.datarate = rx_mgmt->datarate; | |
1096 | fi.ssi_signal = rx_mgmt->ssi_signal; | |
1097 | ||
4b9841d3 JM |
1098 | if (hapd == HAPD_BROADCAST) { |
1099 | size_t i; | |
48b06c17 | 1100 | |
912b34f0 JM |
1101 | ret = 0; |
1102 | for (i = 0; i < iface->num_bss; i++) { | |
1d91f504 SW |
1103 | /* if bss is set, driver will call this function for |
1104 | * each bss individually. */ | |
1105 | if (rx_mgmt->drv_priv && | |
1106 | (iface->bss[i]->drv_priv != rx_mgmt->drv_priv)) | |
1107 | continue; | |
1108 | ||
912b34f0 JM |
1109 | if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame, |
1110 | rx_mgmt->frame_len, &fi) > 0) | |
1111 | ret = 1; | |
1112 | } | |
4b9841d3 | 1113 | } else |
912b34f0 JM |
1114 | ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, |
1115 | &fi); | |
bbb921da JM |
1116 | |
1117 | random_add_randomness(&fi, sizeof(fi)); | |
912b34f0 JM |
1118 | |
1119 | return ret; | |
b5b969e9 JM |
1120 | } |
1121 | ||
1122 | ||
f8b1f695 JM |
1123 | static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf, |
1124 | size_t len, u16 stype, int ok) | |
b5b969e9 | 1125 | { |
4b9841d3 | 1126 | struct ieee80211_hdr *hdr; |
6996ff7b | 1127 | struct hostapd_data *orig_hapd = hapd; |
48b06c17 | 1128 | |
4b9841d3 JM |
1129 | hdr = (struct ieee80211_hdr *) buf; |
1130 | hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len)); | |
6996ff7b | 1131 | if (!hapd) |
4b9841d3 | 1132 | return; |
6996ff7b JM |
1133 | if (hapd == HAPD_BROADCAST) { |
1134 | if (stype != WLAN_FC_STYPE_ACTION || len <= 25 || | |
1135 | buf[24] != WLAN_ACTION_PUBLIC) | |
1136 | return; | |
1137 | hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2); | |
1138 | if (!hapd || hapd == HAPD_BROADCAST) | |
1139 | return; | |
1140 | /* | |
1141 | * Allow processing of TX status for a Public Action frame that | |
1142 | * used wildcard BBSID. | |
1143 | */ | |
1144 | } | |
b5b969e9 JM |
1145 | ieee802_11_mgmt_cb(hapd, buf, len, stype, ok); |
1146 | } | |
f82ef4d8 | 1147 | |
f8b1f695 | 1148 | #endif /* NEED_AP_MLME */ |
ad1e68e6 JM |
1149 | |
1150 | ||
a8e0505b JM |
1151 | static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr) |
1152 | { | |
1153 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
48b06c17 | 1154 | |
a8e0505b JM |
1155 | if (sta) |
1156 | return 0; | |
1157 | ||
1158 | wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR | |
1159 | " - adding a new STA", MAC2STR(addr)); | |
1160 | sta = ap_sta_add(hapd, addr); | |
1161 | if (sta) { | |
1162 | hostapd_new_assoc_sta(hapd, sta, 0); | |
1163 | } else { | |
1164 | wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR, | |
1165 | MAC2STR(addr)); | |
1166 | return -1; | |
1167 | } | |
1168 | ||
1169 | return 0; | |
1170 | } | |
1171 | ||
1172 | ||
1173 | static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, | |
1174 | const u8 *data, size_t data_len) | |
1175 | { | |
1176 | struct hostapd_iface *iface = hapd->iface; | |
f826635c | 1177 | struct sta_info *sta; |
a8e0505b JM |
1178 | size_t j; |
1179 | ||
1180 | for (j = 0; j < iface->num_bss; j++) { | |
48b06c17 JM |
1181 | sta = ap_get_sta(iface->bss[j], src); |
1182 | if (sta && sta->flags & WLAN_STA_ASSOC) { | |
1183 | hapd = iface->bss[j]; | |
1184 | break; | |
a8e0505b JM |
1185 | } |
1186 | } | |
1187 | ||
1188 | ieee802_1x_receive(hapd, src, data, data_len); | |
1189 | } | |
1190 | ||
96bc5086 TB |
1191 | #endif /* HOSTAPD */ |
1192 | ||
a8e0505b | 1193 | |
0185007c MK |
1194 | static struct hostapd_channel_data * hostapd_get_mode_channel( |
1195 | struct hostapd_iface *iface, unsigned int freq) | |
1196 | { | |
1197 | int i; | |
1198 | struct hostapd_channel_data *chan; | |
1199 | ||
1200 | for (i = 0; i < iface->current_mode->num_channels; i++) { | |
1201 | chan = &iface->current_mode->channels[i]; | |
0185007c MK |
1202 | if ((unsigned int) chan->freq == freq) |
1203 | return chan; | |
1204 | } | |
1205 | ||
1206 | return NULL; | |
1207 | } | |
1208 | ||
1209 | ||
1210 | static void hostapd_update_nf(struct hostapd_iface *iface, | |
1211 | struct hostapd_channel_data *chan, | |
1212 | struct freq_survey *survey) | |
1213 | { | |
1214 | if (!iface->chans_surveyed) { | |
1215 | chan->min_nf = survey->nf; | |
1216 | iface->lowest_nf = survey->nf; | |
1217 | } else { | |
1218 | if (dl_list_empty(&chan->survey_list)) | |
1219 | chan->min_nf = survey->nf; | |
1220 | else if (survey->nf < chan->min_nf) | |
1221 | chan->min_nf = survey->nf; | |
1222 | if (survey->nf < iface->lowest_nf) | |
1223 | iface->lowest_nf = survey->nf; | |
1224 | } | |
1225 | } | |
1226 | ||
1227 | ||
ec8f36af KP |
1228 | static void hostapd_single_channel_get_survey(struct hostapd_iface *iface, |
1229 | struct survey_results *survey_res) | |
1230 | { | |
1231 | struct hostapd_channel_data *chan; | |
1232 | struct freq_survey *survey; | |
1233 | u64 divisor, dividend; | |
1234 | ||
1235 | survey = dl_list_first(&survey_res->survey_list, struct freq_survey, | |
1236 | list); | |
1237 | if (!survey || !survey->freq) | |
1238 | return; | |
1239 | ||
1240 | chan = hostapd_get_mode_channel(iface, survey->freq); | |
1241 | if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED) | |
1242 | return; | |
1243 | ||
48b06c17 JM |
1244 | wpa_printf(MSG_DEBUG, |
1245 | "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)", | |
ec8f36af KP |
1246 | survey->freq, |
1247 | (unsigned long int) survey->channel_time, | |
1248 | (unsigned long int) survey->channel_time_busy); | |
1249 | ||
1250 | if (survey->channel_time > iface->last_channel_time && | |
1251 | survey->channel_time > survey->channel_time_busy) { | |
1252 | dividend = survey->channel_time_busy - | |
1253 | iface->last_channel_time_busy; | |
1254 | divisor = survey->channel_time - iface->last_channel_time; | |
1255 | ||
1256 | iface->channel_utilization = dividend * 255 / divisor; | |
1257 | wpa_printf(MSG_DEBUG, "Channel Utilization: %d", | |
1258 | iface->channel_utilization); | |
1259 | } | |
1260 | iface->last_channel_time = survey->channel_time; | |
1261 | iface->last_channel_time_busy = survey->channel_time_busy; | |
1262 | } | |
1263 | ||
1264 | ||
96bc5086 TB |
1265 | void hostapd_event_get_survey(struct hostapd_iface *iface, |
1266 | struct survey_results *survey_results) | |
0185007c | 1267 | { |
0185007c MK |
1268 | struct freq_survey *survey, *tmp; |
1269 | struct hostapd_channel_data *chan; | |
1270 | ||
1271 | if (dl_list_empty(&survey_results->survey_list)) { | |
1272 | wpa_printf(MSG_DEBUG, "No survey data received"); | |
1273 | return; | |
1274 | } | |
1275 | ||
ec8f36af KP |
1276 | if (survey_results->freq_filter) { |
1277 | hostapd_single_channel_get_survey(iface, survey_results); | |
1278 | return; | |
1279 | } | |
1280 | ||
0185007c MK |
1281 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
1282 | struct freq_survey, list) { | |
1283 | chan = hostapd_get_mode_channel(iface, survey->freq); | |
1284 | if (!chan) | |
1285 | continue; | |
1286 | if (chan->flag & HOSTAPD_CHAN_DISABLED) | |
1287 | continue; | |
1288 | ||
1289 | dl_list_del(&survey->list); | |
1290 | dl_list_add_tail(&chan->survey_list, &survey->list); | |
1291 | ||
1292 | hostapd_update_nf(iface, chan, survey); | |
1293 | ||
1294 | iface->chans_surveyed++; | |
1295 | } | |
1296 | } | |
1297 | ||
1298 | ||
96bc5086 | 1299 | #ifdef HOSTAPD |
e76da505 JD |
1300 | #ifdef NEED_AP_MLME |
1301 | ||
5841958f MK |
1302 | static void hostapd_event_iface_unavailable(struct hostapd_data *hapd) |
1303 | { | |
1304 | wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped", | |
1305 | hapd->conf->iface); | |
1306 | ||
1307 | if (hapd->csa_in_progress) { | |
1308 | wpa_printf(MSG_INFO, "CSA failed (%s was stopped)", | |
1309 | hapd->conf->iface); | |
1310 | hostapd_switch_channel_fallback(hapd->iface, | |
1311 | &hapd->cs_freq_params); | |
1312 | } | |
1313 | } | |
1314 | ||
1315 | ||
e76da505 JD |
1316 | static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd, |
1317 | struct dfs_event *radar) | |
1318 | { | |
e76da505 | 1319 | wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq); |
dc036d9e | 1320 | hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1321 | radar->chan_offset, radar->chan_width, |
1322 | radar->cf1, radar->cf2); | |
e76da505 JD |
1323 | } |
1324 | ||
1325 | ||
7cbb5f1a VT |
1326 | static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd, |
1327 | struct dfs_event *radar) | |
1328 | { | |
1329 | wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq); | |
1330 | hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled, | |
1331 | radar->chan_offset, radar->chan_width, | |
1332 | radar->cf1, radar->cf2); | |
1333 | } | |
1334 | ||
1335 | ||
e76da505 JD |
1336 | static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd, |
1337 | struct dfs_event *radar) | |
1338 | { | |
1339 | wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq); | |
dc036d9e | 1340 | hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1341 | radar->chan_offset, radar->chan_width, |
1342 | radar->cf1, radar->cf2); | |
e76da505 JD |
1343 | } |
1344 | ||
1345 | ||
1346 | static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd, | |
1347 | struct dfs_event *radar) | |
1348 | { | |
1349 | wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq); | |
dc036d9e | 1350 | hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1351 | radar->chan_offset, radar->chan_width, |
1352 | radar->cf1, radar->cf2); | |
e76da505 JD |
1353 | } |
1354 | ||
1355 | ||
1356 | static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd, | |
1357 | struct dfs_event *radar) | |
1358 | { | |
1359 | wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq); | |
dc036d9e | 1360 | hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1361 | radar->chan_offset, radar->chan_width, |
1362 | radar->cf1, radar->cf2); | |
e76da505 JD |
1363 | } |
1364 | ||
c13578c3 AK |
1365 | |
1366 | static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd, | |
1367 | struct dfs_event *radar) | |
1368 | { | |
1369 | wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq); | |
1370 | hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled, | |
1371 | radar->chan_offset, radar->chan_width, | |
1372 | radar->cf1, radar->cf2); | |
1373 | } | |
1374 | ||
e76da505 JD |
1375 | #endif /* NEED_AP_MLME */ |
1376 | ||
1377 | ||
9646a8ab | 1378 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
ad1e68e6 JM |
1379 | union wpa_event_data *data) |
1380 | { | |
1381 | struct hostapd_data *hapd = ctx; | |
74781dfc JM |
1382 | #ifndef CONFIG_NO_STDOUT_DEBUG |
1383 | int level = MSG_DEBUG; | |
ad1e68e6 | 1384 | |
34caf71a | 1385 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame && |
74781dfc JM |
1386 | data->rx_mgmt.frame_len >= 24) { |
1387 | const struct ieee80211_hdr *hdr; | |
1388 | u16 fc; | |
48b06c17 | 1389 | |
74781dfc JM |
1390 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; |
1391 | fc = le_to_host16(hdr->frame_control); | |
1392 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
1393 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
1394 | level = MSG_EXCESSIVE; | |
cc2ada86 JM |
1395 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
1396 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ) | |
1397 | level = MSG_EXCESSIVE; | |
74781dfc JM |
1398 | } |
1399 | ||
1400 | wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received", | |
e26cd1a1 | 1401 | event_to_string(event), event); |
74781dfc | 1402 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
e26cd1a1 | 1403 | |
ad1e68e6 JM |
1404 | switch (event) { |
1405 | case EVENT_MICHAEL_MIC_FAILURE: | |
1406 | michael_mic_failure(hapd, data->michael_mic_failure.src, 1); | |
1407 | break; | |
1408 | case EVENT_SCAN_RESULTS: | |
1409 | if (hapd->iface->scan_cb) | |
1410 | hapd->iface->scan_cb(hapd->iface); | |
1411 | break; | |
fcf0f87d | 1412 | case EVENT_WPS_BUTTON_PUSHED: |
d601247c | 1413 | hostapd_wps_button_pushed(hapd, NULL); |
fcf0f87d | 1414 | break; |
f8b1f695 JM |
1415 | #ifdef NEED_AP_MLME |
1416 | case EVENT_TX_STATUS: | |
1417 | switch (data->tx_status.type) { | |
1418 | case WLAN_FC_TYPE_MGMT: | |
1419 | hostapd_mgmt_tx_cb(hapd, data->tx_status.data, | |
1420 | data->tx_status.data_len, | |
1421 | data->tx_status.stype, | |
1422 | data->tx_status.ack); | |
1423 | break; | |
1424 | case WLAN_FC_TYPE_DATA: | |
1425 | hostapd_tx_status(hapd, data->tx_status.dst, | |
1426 | data->tx_status.data, | |
1427 | data->tx_status.data_len, | |
1428 | data->tx_status.ack); | |
1429 | break; | |
1430 | } | |
1431 | break; | |
dd840f79 JB |
1432 | case EVENT_EAPOL_TX_STATUS: |
1433 | hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst, | |
1434 | data->eapol_tx_status.data, | |
1435 | data->eapol_tx_status.data_len, | |
1436 | data->eapol_tx_status.ack); | |
1437 | break; | |
bcf24348 JB |
1438 | case EVENT_DRIVER_CLIENT_POLL_OK: |
1439 | hostapd_client_poll_ok(hapd, data->client_poll.addr); | |
1440 | break; | |
f8b1f695 | 1441 | case EVENT_RX_FROM_UNKNOWN: |
9b90955e JB |
1442 | hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid, |
1443 | data->rx_from_unknown.addr, | |
1444 | data->rx_from_unknown.wds); | |
f8b1f695 | 1445 | break; |
dbfb8e82 | 1446 | #endif /* NEED_AP_MLME */ |
f8b1f695 | 1447 | case EVENT_RX_MGMT: |
c0333c8d JM |
1448 | if (!data->rx_mgmt.frame) |
1449 | break; | |
dbfb8e82 JM |
1450 | #ifdef NEED_AP_MLME |
1451 | if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0) | |
1452 | break; | |
f8b1f695 | 1453 | #endif /* NEED_AP_MLME */ |
dbfb8e82 JM |
1454 | hostapd_action_rx(hapd, &data->rx_mgmt); |
1455 | break; | |
a0e0d3bb | 1456 | case EVENT_RX_PROBE_REQ: |
b211f3eb JM |
1457 | if (data->rx_probe_req.sa == NULL || |
1458 | data->rx_probe_req.ie == NULL) | |
1459 | break; | |
a0e0d3bb | 1460 | hostapd_probe_req_rx(hapd, data->rx_probe_req.sa, |
04a85e44 JM |
1461 | data->rx_probe_req.da, |
1462 | data->rx_probe_req.bssid, | |
a0e0d3bb | 1463 | data->rx_probe_req.ie, |
baf513d6 JB |
1464 | data->rx_probe_req.ie_len, |
1465 | data->rx_probe_req.ssi_signal); | |
a0e0d3bb | 1466 | break; |
a70a5d6d | 1467 | case EVENT_NEW_STA: |
a8e0505b JM |
1468 | hostapd_event_new_sta(hapd, data->new_sta.addr); |
1469 | break; | |
1470 | case EVENT_EAPOL_RX: | |
1471 | hostapd_event_eapol_rx(hapd, data->eapol_rx.src, | |
1472 | data->eapol_rx.data, | |
1473 | data->eapol_rx.data_len); | |
1474 | break; | |
1d041bec | 1475 | case EVENT_ASSOC: |
04a258e7 JM |
1476 | if (!data) |
1477 | return; | |
1d041bec JM |
1478 | hostapd_notif_assoc(hapd, data->assoc_info.addr, |
1479 | data->assoc_info.req_ies, | |
39b08b5f SP |
1480 | data->assoc_info.req_ies_len, |
1481 | data->assoc_info.reassoc); | |
1d041bec JM |
1482 | break; |
1483 | case EVENT_DISASSOC: | |
1484 | if (data) | |
1485 | hostapd_notif_disassoc(hapd, data->disassoc_info.addr); | |
1486 | break; | |
1487 | case EVENT_DEAUTH: | |
1488 | if (data) | |
1489 | hostapd_notif_disassoc(hapd, data->deauth_info.addr); | |
1490 | break; | |
0d7e5a3a JB |
1491 | case EVENT_STATION_LOW_ACK: |
1492 | if (!data) | |
1493 | break; | |
1494 | hostapd_event_sta_low_ack(hapd, data->low_ack.addr); | |
1495 | break; | |
88b32a99 SP |
1496 | case EVENT_AUTH: |
1497 | hostapd_notif_auth(hapd, &data->auth); | |
1498 | break; | |
1b487b8b TP |
1499 | case EVENT_CH_SWITCH: |
1500 | if (!data) | |
1501 | break; | |
1502 | hostapd_event_ch_switch(hapd, data->ch_switch.freq, | |
1503 | data->ch_switch.ht_enabled, | |
8d1fdde7 JD |
1504 | data->ch_switch.ch_offset, |
1505 | data->ch_switch.ch_width, | |
1506 | data->ch_switch.cf1, | |
1507 | data->ch_switch.cf2); | |
1b487b8b | 1508 | break; |
3140803b RM |
1509 | case EVENT_CONNECT_FAILED_REASON: |
1510 | if (!data) | |
1511 | break; | |
1512 | hostapd_event_connect_failed_reason( | |
1513 | hapd, data->connect_failed_reason.addr, | |
1514 | data->connect_failed_reason.code); | |
1515 | break; | |
0185007c | 1516 | case EVENT_SURVEY: |
96bc5086 | 1517 | hostapd_event_get_survey(hapd->iface, &data->survey_results); |
0185007c | 1518 | break; |
e76da505 | 1519 | #ifdef NEED_AP_MLME |
5841958f MK |
1520 | case EVENT_INTERFACE_UNAVAILABLE: |
1521 | hostapd_event_iface_unavailable(hapd); | |
1522 | break; | |
e76da505 JD |
1523 | case EVENT_DFS_RADAR_DETECTED: |
1524 | if (!data) | |
1525 | break; | |
1526 | hostapd_event_dfs_radar_detected(hapd, &data->dfs_event); | |
1527 | break; | |
7cbb5f1a VT |
1528 | case EVENT_DFS_PRE_CAC_EXPIRED: |
1529 | if (!data) | |
1530 | break; | |
1531 | hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event); | |
1532 | break; | |
e76da505 JD |
1533 | case EVENT_DFS_CAC_FINISHED: |
1534 | if (!data) | |
1535 | break; | |
1536 | hostapd_event_dfs_cac_finished(hapd, &data->dfs_event); | |
1537 | break; | |
1538 | case EVENT_DFS_CAC_ABORTED: | |
1539 | if (!data) | |
1540 | break; | |
1541 | hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event); | |
1542 | break; | |
1543 | case EVENT_DFS_NOP_FINISHED: | |
1544 | if (!data) | |
1545 | break; | |
1546 | hostapd_event_dfs_nop_finished(hapd, &data->dfs_event); | |
1547 | break; | |
1548 | case EVENT_CHANNEL_LIST_CHANGED: | |
1549 | /* channel list changed (regulatory?), update channel list */ | |
1550 | /* TODO: check this. hostapd_get_hw_features() initializes | |
1551 | * too much stuff. */ | |
1552 | /* hostapd_get_hw_features(hapd->iface); */ | |
795baf77 AS |
1553 | hostapd_channel_list_updated( |
1554 | hapd->iface, data->channel_list_changed.initiator); | |
e76da505 | 1555 | break; |
c13578c3 AK |
1556 | case EVENT_DFS_CAC_STARTED: |
1557 | if (!data) | |
1558 | break; | |
1559 | hostapd_event_dfs_cac_started(hapd, &data->dfs_event); | |
1560 | break; | |
e76da505 | 1561 | #endif /* NEED_AP_MLME */ |
ab93fdeb JM |
1562 | case EVENT_INTERFACE_ENABLED: |
1563 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED); | |
f33c8606 JM |
1564 | if (hapd->disabled && hapd->started) { |
1565 | hapd->disabled = 0; | |
1566 | /* | |
1567 | * Try to re-enable interface if the driver stopped it | |
1568 | * when the interface got disabled. | |
1569 | */ | |
34782730 | 1570 | wpa_auth_reconfig_group_keys(hapd->wpa_auth); |
f33c8606 JM |
1571 | hapd->reenable_beacon = 1; |
1572 | ieee802_11_set_beacon(hapd); | |
1573 | } | |
ab93fdeb JM |
1574 | break; |
1575 | case EVENT_INTERFACE_DISABLED: | |
c165cb40 | 1576 | hostapd_free_stas(hapd); |
ab93fdeb | 1577 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED); |
f33c8606 | 1578 | hapd->disabled = 1; |
ab93fdeb | 1579 | break; |
16689c7c PX |
1580 | #ifdef CONFIG_ACS |
1581 | case EVENT_ACS_CHANNEL_SELECTED: | |
857d9422 MM |
1582 | hostapd_acs_channel_selected(hapd, |
1583 | &data->acs_selected_channels); | |
16689c7c PX |
1584 | break; |
1585 | #endif /* CONFIG_ACS */ | |
ad1e68e6 JM |
1586 | default: |
1587 | wpa_printf(MSG_DEBUG, "Unknown event %d", event); | |
1588 | break; | |
1589 | } | |
1590 | } | |
f8b1f695 | 1591 | |
45e3fc72 RM |
1592 | |
1593 | void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event, | |
1594 | union wpa_event_data *data) | |
1595 | { | |
1596 | struct hapd_interfaces *interfaces = ctx; | |
1597 | struct hostapd_data *hapd; | |
1598 | ||
1599 | if (event != EVENT_INTERFACE_STATUS) | |
1600 | return; | |
1601 | ||
1602 | hapd = hostapd_get_iface(interfaces, data->interface_status.ifname); | |
1603 | if (hapd && hapd->driver && hapd->driver->get_ifindex && | |
1604 | hapd->drv_priv) { | |
1605 | unsigned int ifindex; | |
1606 | ||
1607 | ifindex = hapd->driver->get_ifindex(hapd->drv_priv); | |
1608 | if (ifindex != data->interface_status.ifindex) { | |
1609 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, | |
1610 | "interface status ifindex %d mismatch (%d)", | |
1611 | ifindex, data->interface_status.ifindex); | |
1612 | return; | |
1613 | } | |
1614 | } | |
1615 | if (hapd) | |
1616 | wpa_supplicant_event(hapd, event, data); | |
1617 | } | |
1618 | ||
f8b1f695 | 1619 | #endif /* HOSTAPD */ |