]>
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" |
10ec6a5f | 18 | #include "common/dpp.h" |
898b6d58 | 19 | #include "common/sae.h" |
41cac481 | 20 | #include "common/hw_features_common.h" |
bbb921da | 21 | #include "crypto/random.h" |
ef796391 | 22 | #include "p2p/p2p.h" |
54f489be | 23 | #include "wps/wps.h" |
037378ff | 24 | #include "fst/fst.h" |
d32d94db | 25 | #include "wnm_ap.h" |
6226e38d JM |
26 | #include "hostapd.h" |
27 | #include "ieee802_11.h" | |
0603bcb7 | 28 | #include "ieee802_11_auth.h" |
6226e38d JM |
29 | #include "sta_info.h" |
30 | #include "accounting.h" | |
31 | #include "tkip_countermeasures.h" | |
6226e38d JM |
32 | #include "ieee802_1x.h" |
33 | #include "wpa_auth.h" | |
6226e38d | 34 | #include "wps_hostapd.h" |
51e2a27a | 35 | #include "ap_drv_ops.h" |
8b06c1ed | 36 | #include "ap_config.h" |
fa61bff6 | 37 | #include "ap_mlme.h" |
1b487b8b | 38 | #include "hw_features.h" |
e76da505 | 39 | #include "dfs.h" |
9c47f6a2 | 40 | #include "beacon.h" |
6332aaf3 | 41 | #include "mbo_ap.h" |
9c2b8204 | 42 | #include "dpp_hostapd.h" |
8b5ddda5 | 43 | #include "fils_hlp.h" |
6ca4949a | 44 | #include "neighbor_db.h" |
8b5ddda5 JM |
45 | |
46 | ||
47 | #ifdef CONFIG_FILS | |
48 | void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd, | |
49 | struct sta_info *sta) | |
50 | { | |
51 | u16 reply_res = WLAN_STATUS_SUCCESS; | |
52 | struct ieee802_11_elems elems; | |
53 | u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf; | |
54 | int new_assoc; | |
55 | ||
56 | wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR, | |
57 | __func__, MAC2STR(sta->addr)); | |
58 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); | |
59 | if (!sta->fils_pending_assoc_req) | |
60 | return; | |
61 | ||
62 | ieee802_11_parse_elems(sta->fils_pending_assoc_req, | |
63 | sta->fils_pending_assoc_req_len, &elems, 0); | |
64 | if (!elems.fils_session) { | |
65 | wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element", | |
66 | __func__); | |
67 | return; | |
68 | } | |
69 | ||
70 | p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p, | |
71 | elems.fils_session, | |
72 | sta->fils_hlp_resp); | |
73 | ||
74 | reply_res = hostapd_sta_assoc(hapd, sta->addr, | |
75 | sta->fils_pending_assoc_is_reassoc, | |
76 | WLAN_STATUS_SUCCESS, | |
77 | buf, p - buf); | |
78 | ap_sta_set_authorized(hapd, sta, 1); | |
79 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; | |
80 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; | |
81 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; | |
82 | hostapd_set_sta_flags(hapd, sta); | |
83 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS); | |
84 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); | |
85 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); | |
86 | os_free(sta->fils_pending_assoc_req); | |
87 | sta->fils_pending_assoc_req = NULL; | |
88 | sta->fils_pending_assoc_req_len = 0; | |
89 | wpabuf_free(sta->fils_hlp_resp); | |
90 | sta->fils_hlp_resp = NULL; | |
91 | wpabuf_free(sta->hlp_dhcp_discover); | |
92 | sta->hlp_dhcp_discover = NULL; | |
93 | fils_hlp_deinit(hapd); | |
94 | ||
95 | /* | |
96 | * Remove the station in case transmission of a success response fails | |
97 | * (the STA was added associated to the driver) or if the station was | |
98 | * previously added unassociated. | |
99 | */ | |
100 | if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) { | |
101 | hostapd_drv_sta_remove(hapd, sta->addr); | |
102 | sta->added_unassoc = 0; | |
103 | } | |
104 | } | |
105 | #endif /* CONFIG_FILS */ | |
b5b969e9 JM |
106 | |
107 | ||
b5b969e9 | 108 | int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr, |
2bb20281 | 109 | const u8 *req_ies, size_t req_ies_len, int reassoc) |
b5b969e9 JM |
110 | { |
111 | struct sta_info *sta; | |
ca57d5f5 JM |
112 | int new_assoc; |
113 | enum wpa_validate_result res; | |
c41a1095 | 114 | struct ieee802_11_elems elems; |
2bb20281 JM |
115 | const u8 *ie; |
116 | size_t ielen; | |
88b32a99 SP |
117 | u8 buf[sizeof(struct ieee80211_mgmt) + 1024]; |
118 | u8 *p = buf; | |
08a74e6a | 119 | u16 reason = WLAN_REASON_UNSPECIFIED; |
88b32a99 | 120 | u16 status = WLAN_STATUS_SUCCESS; |
94ddef3e | 121 | const u8 *p2p_dev_addr = NULL; |
b5b969e9 | 122 | |
68532a9c JM |
123 | if (addr == NULL) { |
124 | /* | |
125 | * This could potentially happen with unexpected event from the | |
126 | * driver wrapper. This was seen at least in one case where the | |
127 | * driver ended up being set to station mode while hostapd was | |
128 | * running, so better make sure we stop processing such an | |
129 | * event here. | |
130 | */ | |
48b06c17 JM |
131 | wpa_printf(MSG_DEBUG, |
132 | "hostapd_notif_assoc: Skip event with no address"); | |
68532a9c JM |
133 | return -1; |
134 | } | |
d86d66dc JM |
135 | |
136 | if (is_multicast_ether_addr(addr) || | |
137 | is_zero_ether_addr(addr) || | |
138 | os_memcmp(addr, hapd->own_addr, ETH_ALEN) == 0) { | |
139 | /* Do not process any frames with unexpected/invalid SA so that | |
140 | * we do not add any state for unexpected STA addresses or end | |
141 | * up sending out frames to unexpected destination. */ | |
142 | wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR | |
143 | " in received indication - ignore this indication silently", | |
144 | __func__, MAC2STR(addr)); | |
145 | return 0; | |
146 | } | |
147 | ||
bbb921da | 148 | random_add_randomness(addr, ETH_ALEN); |
68532a9c | 149 | |
b5b969e9 JM |
150 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
151 | HOSTAPD_LEVEL_INFO, "associated"); | |
152 | ||
2bb20281 | 153 | ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0); |
c41a1095 JM |
154 | if (elems.wps_ie) { |
155 | ie = elems.wps_ie - 2; | |
156 | ielen = elems.wps_ie_len + 2; | |
157 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq"); | |
158 | } else if (elems.rsn_ie) { | |
159 | ie = elems.rsn_ie - 2; | |
160 | ielen = elems.rsn_ie_len + 2; | |
161 | wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq"); | |
162 | } else if (elems.wpa_ie) { | |
163 | ie = elems.wpa_ie - 2; | |
164 | ielen = elems.wpa_ie_len + 2; | |
165 | wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq"); | |
a14896e8 JM |
166 | #ifdef CONFIG_HS20 |
167 | } else if (elems.osen) { | |
168 | ie = elems.osen - 2; | |
169 | ielen = elems.osen_len + 2; | |
170 | wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq"); | |
171 | #endif /* CONFIG_HS20 */ | |
c41a1095 JM |
172 | } else { |
173 | ie = NULL; | |
174 | ielen = 0; | |
48b06c17 JM |
175 | wpa_printf(MSG_DEBUG, |
176 | "STA did not include WPS/RSN/WPA IE in (Re)AssocReq"); | |
c41a1095 JM |
177 | } |
178 | ||
b5b969e9 JM |
179 | sta = ap_get_sta(hapd, addr); |
180 | if (sta) { | |
4331263b | 181 | ap_sta_no_session_timeout(hapd, sta); |
b5b969e9 | 182 | accounting_sta_stop(hapd, sta); |
c72bd6d4 JM |
183 | |
184 | /* | |
185 | * Make sure that the previously registered inactivity timer | |
186 | * will not remove the STA immediately. | |
187 | */ | |
188 | sta->timeout_next = STA_NULLFUNC; | |
b5b969e9 JM |
189 | } else { |
190 | sta = ap_sta_add(hapd, addr); | |
8bd0fc0e JM |
191 | if (sta == NULL) { |
192 | hostapd_drv_sta_disassoc(hapd, addr, | |
193 | WLAN_REASON_DISASSOC_AP_BUSY); | |
b5b969e9 | 194 | return -1; |
8bd0fc0e | 195 | } |
b5b969e9 | 196 | } |
17f6b900 | 197 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
b5b969e9 | 198 | |
bb4e19e3 SD |
199 | /* |
200 | * ACL configurations to the drivers (implementing AP SME and ACL | |
201 | * offload) without hostapd's knowledge, can result in a disconnection | |
202 | * though the driver accepts the connection. Skip the hostapd check for | |
203 | * ACL if the driver supports ACL offload to avoid potentially | |
204 | * conflicting ACL rules. | |
205 | */ | |
206 | if (hapd->iface->drv_max_acl_mac_addrs == 0 && | |
207 | hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) { | |
0603bcb7 AN |
208 | wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect", |
209 | MAC2STR(addr)); | |
210 | reason = WLAN_REASON_UNSPECIFIED; | |
211 | goto fail; | |
212 | } | |
213 | ||
b305c684 JM |
214 | #ifdef CONFIG_P2P |
215 | if (elems.p2p) { | |
216 | wpabuf_free(sta->p2p_ie); | |
2bb20281 | 217 | sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, |
b305c684 | 218 | P2P_IE_VENDOR_TYPE); |
94ddef3e JM |
219 | if (sta->p2p_ie) |
220 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); | |
b305c684 JM |
221 | } |
222 | #endif /* CONFIG_P2P */ | |
223 | ||
9c47f6a2 PX |
224 | #ifdef NEED_AP_MLME |
225 | if (elems.ht_capabilities && | |
9c47f6a2 PX |
226 | (hapd->iface->conf->ht_capab & |
227 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { | |
228 | struct ieee80211_ht_capabilities *ht_cap = | |
229 | (struct ieee80211_ht_capabilities *) | |
230 | elems.ht_capabilities; | |
231 | ||
232 | if (le_to_host16(ht_cap->ht_capabilities_info) & | |
233 | HT_CAP_INFO_40MHZ_INTOLERANT) | |
234 | ht40_intolerant_add(hapd->iface, sta); | |
235 | } | |
236 | #endif /* NEED_AP_MLME */ | |
9c47f6a2 | 237 | |
c551700f KP |
238 | #ifdef CONFIG_INTERWORKING |
239 | if (elems.ext_capab && elems.ext_capab_len > 4) { | |
240 | if (elems.ext_capab[4] & 0x01) | |
241 | sta->qos_map_enabled = 1; | |
242 | } | |
243 | #endif /* CONFIG_INTERWORKING */ | |
244 | ||
f403dcd6 JM |
245 | #ifdef CONFIG_HS20 |
246 | wpabuf_free(sta->hs20_ie); | |
247 | if (elems.hs20 && elems.hs20_len > 4) { | |
248 | sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4, | |
249 | elems.hs20_len - 4); | |
250 | } else | |
251 | sta->hs20_ie = NULL; | |
67cca346 JM |
252 | |
253 | wpabuf_free(sta->roaming_consortium); | |
254 | if (elems.roaming_cons_sel) | |
255 | sta->roaming_consortium = wpabuf_alloc_copy( | |
256 | elems.roaming_cons_sel + 4, | |
257 | elems.roaming_cons_sel_len - 4); | |
258 | else | |
259 | sta->roaming_consortium = NULL; | |
f403dcd6 JM |
260 | #endif /* CONFIG_HS20 */ |
261 | ||
ae667c08 AN |
262 | #ifdef CONFIG_FST |
263 | wpabuf_free(sta->mb_ies); | |
264 | if (hapd->iface->fst) | |
265 | sta->mb_ies = mb_ies_by_info(&elems.mb_ies); | |
266 | else | |
267 | sta->mb_ies = NULL; | |
268 | #endif /* CONFIG_FST */ | |
269 | ||
6332aaf3 JM |
270 | mbo_ap_check_sta_assoc(hapd, sta, &elems); |
271 | ||
adf0478e JM |
272 | ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes, |
273 | elems.supp_op_classes_len); | |
274 | ||
b5b969e9 JM |
275 | if (hapd->conf->wpa) { |
276 | if (ie == NULL || ielen == 0) { | |
633d4469 | 277 | #ifdef CONFIG_WPS |
b5b969e9 | 278 | if (hapd->conf->wps_state) { |
48b06c17 JM |
279 | wpa_printf(MSG_DEBUG, |
280 | "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use"); | |
b5b969e9 JM |
281 | sta->flags |= WLAN_STA_MAYBE_WPS; |
282 | goto skip_wpa_check; | |
283 | } | |
633d4469 | 284 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
285 | |
286 | wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA"); | |
63dc0f9c HW |
287 | reason = WLAN_REASON_INVALID_IE; |
288 | status = WLAN_STATUS_INVALID_IE; | |
289 | goto fail; | |
b5b969e9 | 290 | } |
633d4469 | 291 | #ifdef CONFIG_WPS |
b5b969e9 JM |
292 | if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 && |
293 | os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) { | |
17f6b900 | 294 | struct wpabuf *wps; |
48b06c17 | 295 | |
b5b969e9 | 296 | sta->flags |= WLAN_STA_WPS; |
17f6b900 JM |
297 | wps = ieee802_11_vendor_ie_concat(ie, ielen, |
298 | WPS_IE_VENDOR_TYPE); | |
299 | if (wps) { | |
300 | if (wps_is_20(wps)) { | |
48b06c17 JM |
301 | wpa_printf(MSG_DEBUG, |
302 | "WPS: STA supports WPS 2.0"); | |
17f6b900 JM |
303 | sta->flags |= WLAN_STA_WPS2; |
304 | } | |
305 | wpabuf_free(wps); | |
306 | } | |
b5b969e9 JM |
307 | goto skip_wpa_check; |
308 | } | |
633d4469 | 309 | #endif /* CONFIG_WPS */ |
b5b969e9 JM |
310 | |
311 | if (sta->wpa_sm == NULL) | |
312 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
94ddef3e JM |
313 | sta->addr, |
314 | p2p_dev_addr); | |
b5b969e9 | 315 | if (sta->wpa_sm == NULL) { |
48b06c17 JM |
316 | wpa_printf(MSG_ERROR, |
317 | "Failed to initialize WPA state machine"); | |
b5b969e9 JM |
318 | return -1; |
319 | } | |
320 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, | |
2c129a1b | 321 | hapd->iface->freq, |
88b32a99 | 322 | ie, ielen, |
d3516cad JM |
323 | elems.rsnxe ? elems.rsnxe - 2 : NULL, |
324 | elems.rsnxe ? elems.rsnxe_len + 2 : 0, | |
09368515 JM |
325 | elems.mdie, elems.mdie_len, |
326 | elems.owe_dh, elems.owe_dh_len); | |
ca57d5f5 JM |
327 | reason = WLAN_REASON_INVALID_IE; |
328 | status = WLAN_STATUS_INVALID_IE; | |
329 | switch (res) { | |
330 | case WPA_IE_OK: | |
331 | reason = WLAN_REASON_UNSPECIFIED; | |
332 | status = WLAN_STATUS_SUCCESS; | |
333 | break; | |
334 | case WPA_INVALID_IE: | |
335 | reason = WLAN_REASON_INVALID_IE; | |
336 | status = WLAN_STATUS_INVALID_IE; | |
337 | break; | |
338 | case WPA_INVALID_GROUP: | |
339 | reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; | |
340 | status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; | |
341 | break; | |
342 | case WPA_INVALID_PAIRWISE: | |
343 | reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID; | |
344 | status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; | |
345 | break; | |
346 | case WPA_INVALID_AKMP: | |
347 | reason = WLAN_REASON_AKMP_NOT_VALID; | |
348 | status = WLAN_STATUS_AKMP_NOT_VALID; | |
349 | break; | |
350 | case WPA_NOT_ENABLED: | |
351 | reason = WLAN_REASON_INVALID_IE; | |
352 | status = WLAN_STATUS_INVALID_IE; | |
353 | break; | |
354 | case WPA_ALLOC_FAIL: | |
355 | reason = WLAN_REASON_UNSPECIFIED; | |
356 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
357 | break; | |
358 | case WPA_MGMT_FRAME_PROTECTION_VIOLATION: | |
359 | reason = WLAN_REASON_INVALID_IE; | |
360 | status = WLAN_STATUS_INVALID_IE; | |
361 | break; | |
362 | case WPA_INVALID_MGMT_GROUP_CIPHER: | |
363 | reason = WLAN_REASON_CIPHER_SUITE_REJECTED; | |
364 | status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; | |
365 | break; | |
366 | case WPA_INVALID_MDIE: | |
367 | reason = WLAN_REASON_INVALID_MDE; | |
368 | status = WLAN_STATUS_INVALID_MDIE; | |
369 | break; | |
370 | case WPA_INVALID_PROTO: | |
371 | reason = WLAN_REASON_INVALID_IE; | |
372 | status = WLAN_STATUS_INVALID_IE; | |
373 | break; | |
374 | case WPA_INVALID_PMKID: | |
375 | reason = WLAN_REASON_INVALID_PMKID; | |
376 | status = WLAN_STATUS_INVALID_PMKID; | |
377 | break; | |
7c021dec JM |
378 | case WPA_DENIED_OTHER_REASON: |
379 | reason = WLAN_REASON_UNSPECIFIED; | |
380 | status = WLAN_STATUS_ASSOC_DENIED_UNSPEC; | |
381 | break; | |
ca57d5f5 JM |
382 | } |
383 | if (status != WLAN_STATUS_SUCCESS) { | |
48b06c17 JM |
384 | wpa_printf(MSG_DEBUG, |
385 | "WPA/RSN information element rejected? (res %u)", | |
386 | res); | |
b5b969e9 | 387 | wpa_hexdump(MSG_DEBUG, "IE", ie, ielen); |
08a74e6a | 388 | goto fail; |
b5b969e9 | 389 | } |
7d2ed8ba | 390 | |
edb28006 AK |
391 | if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) == |
392 | (WLAN_STA_ASSOC | WLAN_STA_MFP) && | |
393 | !sta->sa_query_timed_out && | |
7d9c0cd3 MP |
394 | sta->sa_query_count > 0) |
395 | ap_check_sa_query_timeout(hapd, sta); | |
edb28006 AK |
396 | if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) == |
397 | (WLAN_STA_ASSOC | WLAN_STA_MFP) && | |
398 | !sta->sa_query_timed_out && | |
7d9c0cd3 MP |
399 | (sta->auth_alg != WLAN_AUTH_FT)) { |
400 | /* | |
401 | * STA has already been associated with MFP and SA | |
402 | * Query timeout has not been reached. Reject the | |
403 | * association attempt temporarily and start SA Query, | |
404 | * if one is not pending. | |
405 | */ | |
406 | ||
407 | if (sta->sa_query_count == 0) | |
408 | ap_sta_start_sa_query(hapd, sta); | |
409 | ||
7d9c0cd3 MP |
410 | status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
411 | ||
412 | p = hostapd_eid_assoc_comeback_time(hapd, sta, p); | |
413 | ||
414 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, | |
415 | p - buf); | |
7d9c0cd3 MP |
416 | return 0; |
417 | } | |
418 | ||
419 | if (wpa_auth_uses_mfp(sta->wpa_sm)) | |
420 | sta->flags |= WLAN_STA_MFP; | |
421 | else | |
422 | sta->flags &= ~WLAN_STA_MFP; | |
7d9c0cd3 | 423 | |
4ec1fd8e | 424 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 SP |
425 | if (sta->auth_alg == WLAN_AUTH_FT) { |
426 | status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies, | |
427 | req_ies_len); | |
428 | if (status != WLAN_STATUS_SUCCESS) { | |
429 | if (status == WLAN_STATUS_INVALID_PMKID) | |
430 | reason = WLAN_REASON_INVALID_IE; | |
431 | if (status == WLAN_STATUS_INVALID_MDIE) | |
432 | reason = WLAN_REASON_INVALID_IE; | |
433 | if (status == WLAN_STATUS_INVALID_FTIE) | |
434 | reason = WLAN_REASON_INVALID_IE; | |
435 | goto fail; | |
436 | } | |
437 | } | |
4ec1fd8e | 438 | #endif /* CONFIG_IEEE80211R_AP */ |
898b6d58 JM |
439 | #ifdef CONFIG_SAE |
440 | if (hapd->conf->sae_pwe == 2 && | |
441 | sta->auth_alg == WLAN_AUTH_SAE && | |
442 | sta->sae && sta->sae->tmp && !sta->sae->tmp->h2e && | |
443 | elems.rsnxe && elems.rsnxe_len >= 1 && | |
444 | (elems.rsnxe[0] & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) { | |
445 | wpa_printf(MSG_INFO, "SAE: " MACSTR | |
446 | " indicates support for SAE H2E, but did not use it", | |
447 | MAC2STR(sta->addr)); | |
448 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
449 | reason = WLAN_REASON_UNSPECIFIED; | |
450 | goto fail; | |
451 | } | |
452 | #endif /* CONFIG_SAE */ | |
a9aca28b | 453 | } else if (hapd->conf->wps_state) { |
633d4469 | 454 | #ifdef CONFIG_WPS |
17f6b900 | 455 | struct wpabuf *wps; |
48b06c17 | 456 | |
2bb20281 JM |
457 | if (req_ies) |
458 | wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, | |
fa15d405 JM |
459 | WPS_IE_VENDOR_TYPE); |
460 | else | |
461 | wps = NULL; | |
54f489be | 462 | #ifdef CONFIG_WPS_STRICT |
fa15d405 | 463 | if (wps && wps_validate_assoc_req(wps) < 0) { |
08a74e6a | 464 | reason = WLAN_REASON_INVALID_IE; |
88b32a99 | 465 | status = WLAN_STATUS_INVALID_IE; |
fa15d405 | 466 | wpabuf_free(wps); |
08a74e6a | 467 | goto fail; |
54f489be | 468 | } |
54f489be | 469 | #endif /* CONFIG_WPS_STRICT */ |
fa15d405 | 470 | if (wps) { |
a9aca28b | 471 | sta->flags |= WLAN_STA_WPS; |
fa15d405 | 472 | if (wps_is_20(wps)) { |
48b06c17 JM |
473 | wpa_printf(MSG_DEBUG, |
474 | "WPS: STA supports WPS 2.0"); | |
17f6b900 JM |
475 | sta->flags |= WLAN_STA_WPS2; |
476 | } | |
a9aca28b JM |
477 | } else |
478 | sta->flags |= WLAN_STA_MAYBE_WPS; | |
17f6b900 | 479 | wpabuf_free(wps); |
633d4469 | 480 | #endif /* CONFIG_WPS */ |
a14896e8 JM |
481 | #ifdef CONFIG_HS20 |
482 | } else if (hapd->conf->osen) { | |
483 | if (elems.osen == NULL) { | |
484 | hostapd_logger( | |
485 | hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
486 | HOSTAPD_LEVEL_INFO, | |
487 | "No HS 2.0 OSEN element in association request"); | |
488 | return WLAN_STATUS_INVALID_IE; | |
489 | } | |
490 | ||
491 | wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association"); | |
492 | if (sta->wpa_sm == NULL) | |
493 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
494 | sta->addr, NULL); | |
495 | if (sta->wpa_sm == NULL) { | |
48b06c17 JM |
496 | wpa_printf(MSG_WARNING, |
497 | "Failed to initialize WPA state machine"); | |
a14896e8 JM |
498 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
499 | } | |
500 | if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm, | |
501 | elems.osen - 2, elems.osen_len + 2) < 0) | |
502 | return WLAN_STATUS_INVALID_IE; | |
503 | #endif /* CONFIG_HS20 */ | |
b5b969e9 | 504 | } |
7b26238d JM |
505 | #ifdef CONFIG_WPS |
506 | skip_wpa_check: | |
507 | #endif /* CONFIG_WPS */ | |
4c572281 JM |
508 | |
509 | #ifdef CONFIG_MBO | |
510 | if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) && | |
511 | elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) && | |
512 | hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { | |
513 | wpa_printf(MSG_INFO, | |
514 | "MBO: Reject WPA2 association without PMF"); | |
515 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
516 | } | |
517 | #endif /* CONFIG_MBO */ | |
518 | ||
4ec1fd8e | 519 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 | 520 | p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf), |
b7366a94 JM |
521 | sta->auth_alg, req_ies, req_ies_len, |
522 | !elems.rsnxe); | |
2cf36d60 JM |
523 | if (!p) { |
524 | wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs"); | |
525 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
526 | } | |
cc20edc9 | 527 | #endif /* CONFIG_IEEE80211R_AP */ |
88b32a99 | 528 | |
fa61bff6 JM |
529 | #ifdef CONFIG_FILS |
530 | if (sta->auth_alg == WLAN_AUTH_FILS_SK || | |
531 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || | |
532 | sta->auth_alg == WLAN_AUTH_FILS_PK) { | |
8b5ddda5 JM |
533 | int delay_assoc = 0; |
534 | ||
3de1566d PX |
535 | if (!req_ies) |
536 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
537 | ||
fa61bff6 JM |
538 | if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies, |
539 | req_ies_len, | |
540 | sta->fils_session)) { | |
541 | wpa_printf(MSG_DEBUG, | |
542 | "FILS: Session validation failed"); | |
543 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
544 | } | |
545 | ||
546 | res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies, | |
547 | req_ies_len); | |
548 | if (res < 0) { | |
549 | wpa_printf(MSG_DEBUG, | |
550 | "FILS: Key Confirm validation failed"); | |
551 | return WLAN_STATUS_UNSPECIFIED_FAILURE; | |
552 | } | |
553 | ||
8b5ddda5 | 554 | if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) { |
fa61bff6 | 555 | wpa_printf(MSG_DEBUG, |
8b5ddda5 JM |
556 | "FILS: Delaying Assoc Response (HLP)"); |
557 | delay_assoc = 1; | |
558 | } else { | |
559 | wpa_printf(MSG_DEBUG, | |
560 | "FILS: Going ahead with Assoc Response (no HLP)"); | |
561 | } | |
562 | ||
563 | if (sta) { | |
564 | wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup"); | |
565 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); | |
566 | os_free(sta->fils_pending_assoc_req); | |
567 | sta->fils_pending_assoc_req = NULL; | |
568 | sta->fils_pending_assoc_req_len = 0; | |
569 | wpabuf_free(sta->fils_hlp_resp); | |
570 | sta->fils_hlp_resp = NULL; | |
571 | sta->fils_drv_assoc_finish = 0; | |
fa61bff6 JM |
572 | } |
573 | ||
8b5ddda5 JM |
574 | if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) { |
575 | u8 *req_tmp; | |
576 | ||
577 | req_tmp = os_malloc(req_ies_len); | |
578 | if (!req_tmp) { | |
579 | wpa_printf(MSG_DEBUG, | |
580 | "FILS: buffer allocation failed for assoc req"); | |
581 | goto fail; | |
582 | } | |
583 | os_memcpy(req_tmp, req_ies, req_ies_len); | |
584 | sta->fils_pending_assoc_req = req_tmp; | |
585 | sta->fils_pending_assoc_req_len = req_ies_len; | |
586 | sta->fils_pending_assoc_is_reassoc = reassoc; | |
587 | sta->fils_drv_assoc_finish = 1; | |
588 | wpa_printf(MSG_DEBUG, | |
589 | "FILS: Waiting for HLP processing before sending (Re)Association Response frame to " | |
590 | MACSTR, MAC2STR(sta->addr)); | |
591 | eloop_register_timeout( | |
592 | 0, hapd->conf->fils_hlp_wait_time * 1024, | |
593 | fils_hlp_timeout, hapd, sta); | |
594 | return 0; | |
595 | } | |
fa61bff6 | 596 | p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p, |
8b5ddda5 JM |
597 | elems.fils_session, |
598 | sta->fils_hlp_resp); | |
fa61bff6 JM |
599 | wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)", |
600 | buf, p - buf); | |
601 | } | |
602 | #endif /* CONFIG_FILS */ | |
603 | ||
33c8bbd8 AKP |
604 | #ifdef CONFIG_OWE |
605 | if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && | |
606 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE && | |
607 | elems.owe_dh) { | |
04ded82e JM |
608 | u8 *npos; |
609 | ||
79ce2d51 AP |
610 | npos = owe_assoc_req_process(hapd, sta, |
611 | elems.owe_dh, elems.owe_dh_len, | |
612 | p, sizeof(buf) - (p - buf), | |
e7d8842e | 613 | &status); |
a4668c68 AP |
614 | if (npos) |
615 | p = npos; | |
e7d8842e | 616 | |
a4668c68 | 617 | if (!npos && |
e7d8842e | 618 | status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) { |
a4668c68 AP |
619 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, |
620 | p - buf); | |
621 | return 0; | |
622 | } | |
623 | ||
e7d8842e | 624 | if (!npos || status != WLAN_STATUS_SUCCESS) |
33c8bbd8 AKP |
625 | goto fail; |
626 | } | |
627 | #endif /* CONFIG_OWE */ | |
628 | ||
10ec6a5f JM |
629 | #ifdef CONFIG_DPP2 |
630 | dpp_pfs_free(sta->dpp_pfs); | |
631 | sta->dpp_pfs = NULL; | |
632 | ||
633 | if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) && | |
634 | hapd->conf->dpp_netaccesskey && sta->wpa_sm && | |
635 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP && | |
636 | elems.owe_dh) { | |
637 | sta->dpp_pfs = dpp_pfs_init( | |
638 | wpabuf_head(hapd->conf->dpp_netaccesskey), | |
639 | wpabuf_len(hapd->conf->dpp_netaccesskey)); | |
640 | if (!sta->dpp_pfs) { | |
641 | wpa_printf(MSG_DEBUG, | |
642 | "DPP: Could not initialize PFS"); | |
643 | /* Try to continue without PFS */ | |
644 | goto pfs_fail; | |
645 | } | |
646 | ||
647 | if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh, | |
648 | elems.owe_dh_len) < 0) { | |
649 | dpp_pfs_free(sta->dpp_pfs); | |
650 | sta->dpp_pfs = NULL; | |
651 | reason = WLAN_REASON_UNSPECIFIED; | |
652 | goto fail; | |
653 | } | |
654 | } | |
655 | ||
656 | wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ? | |
657 | sta->dpp_pfs->secret : NULL); | |
658 | pfs_fail: | |
659 | #endif /* CONFIG_DPP2 */ | |
660 | ||
fae7e64a O |
661 | if (elems.rrm_enabled && |
662 | elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa)) | |
663 | os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled, | |
664 | sizeof(sta->rrm_enabled_capa)); | |
665 | ||
33c8bbd8 | 666 | #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE) |
88b32a99 | 667 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); |
e4474c1c | 668 | |
cc20edc9 JM |
669 | if (sta->auth_alg == WLAN_AUTH_FT || |
670 | sta->auth_alg == WLAN_AUTH_FILS_SK || | |
671 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || | |
672 | sta->auth_alg == WLAN_AUTH_FILS_PK) | |
e4474c1c | 673 | ap_sta_set_authorized(hapd, sta, 1); |
cc20edc9 | 674 | #else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */ |
88b32a99 SP |
675 | /* Keep compiler silent about unused variables */ |
676 | if (status) { | |
677 | } | |
cc20edc9 | 678 | #endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */ |
88b32a99 | 679 | |
b5b969e9 JM |
680 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; |
681 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; | |
3578e665 | 682 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
88b32a99 | 683 | |
e4474c1c DPS |
684 | hostapd_set_sta_flags(hapd, sta); |
685 | ||
88b32a99 SP |
686 | if (reassoc && (sta->auth_alg == WLAN_AUTH_FT)) |
687 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); | |
957bff83 JM |
688 | #ifdef CONFIG_FILS |
689 | else if (sta->auth_alg == WLAN_AUTH_FILS_SK || | |
690 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || | |
691 | sta->auth_alg == WLAN_AUTH_FILS_PK) | |
692 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS); | |
693 | #endif /* CONFIG_FILS */ | |
88b32a99 SP |
694 | else |
695 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); | |
b5b969e9 JM |
696 | |
697 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); | |
698 | ||
699 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); | |
700 | ||
ef796391 | 701 | #ifdef CONFIG_P2P |
99c01af9 JM |
702 | if (req_ies) { |
703 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, | |
704 | req_ies, req_ies_len); | |
705 | } | |
ef796391 JM |
706 | #endif /* CONFIG_P2P */ |
707 | ||
b5b969e9 | 708 | return 0; |
08a74e6a JM |
709 | |
710 | fail: | |
4ec1fd8e | 711 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 | 712 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); |
4ec1fd8e | 713 | #endif /* CONFIG_IEEE80211R_AP */ |
08a74e6a JM |
714 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); |
715 | ap_free_sta(hapd, sta); | |
716 | return -1; | |
b5b969e9 JM |
717 | } |
718 | ||
719 | ||
720 | void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr) | |
721 | { | |
722 | struct sta_info *sta; | |
723 | ||
83e843e8 JM |
724 | if (addr == NULL) { |
725 | /* | |
726 | * This could potentially happen with unexpected event from the | |
727 | * driver wrapper. This was seen at least in one case where the | |
728 | * driver ended up reporting a station mode event while hostapd | |
729 | * was running, so better make sure we stop processing such an | |
730 | * event here. | |
731 | */ | |
48b06c17 JM |
732 | wpa_printf(MSG_DEBUG, |
733 | "hostapd_notif_disassoc: Skip event with no address"); | |
1f4c7b6b | 734 | return; |
83e843e8 JM |
735 | } |
736 | ||
b5b969e9 JM |
737 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
738 | HOSTAPD_LEVEL_INFO, "disassociated"); | |
739 | ||
740 | sta = ap_get_sta(hapd, addr); | |
741 | if (sta == NULL) { | |
48b06c17 JM |
742 | wpa_printf(MSG_DEBUG, |
743 | "Disassociation notification for unknown STA " | |
744 | MACSTR, MAC2STR(addr)); | |
b5b969e9 JM |
745 | return; |
746 | } | |
747 | ||
ae055af4 | 748 | ap_sta_set_authorized(hapd, sta, 0); |
b5b969e9 | 749 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
b7275a81 | 750 | hostapd_set_sta_flags(hapd, sta); |
b5b969e9 JM |
751 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); |
752 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; | |
753 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
754 | ap_free_sta(hapd, sta); | |
755 | } | |
756 | ||
757 | ||
0d7e5a3a JB |
758 | void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr) |
759 | { | |
760 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
761 | ||
d58c3bd8 | 762 | if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer) |
0d7e5a3a JB |
763 | return; |
764 | ||
765 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, | |
48b06c17 JM |
766 | HOSTAPD_LEVEL_INFO, |
767 | "disconnected due to excessive missing ACKs"); | |
0d7e5a3a | 768 | hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK); |
5f99d962 | 769 | ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK); |
0d7e5a3a JB |
770 | } |
771 | ||
772 | ||
ec2b5173 T |
773 | void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr, |
774 | enum smps_mode smps_mode, | |
775 | enum chan_width chan_width, u8 rx_nss) | |
776 | { | |
777 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
778 | const char *txt; | |
779 | ||
780 | if (!sta) | |
781 | return; | |
782 | ||
783 | switch (smps_mode) { | |
784 | case SMPS_AUTOMATIC: | |
785 | txt = "automatic"; | |
786 | break; | |
787 | case SMPS_OFF: | |
788 | txt = "off"; | |
789 | break; | |
790 | case SMPS_DYNAMIC: | |
791 | txt = "dynamic"; | |
792 | break; | |
793 | case SMPS_STATIC: | |
794 | txt = "static"; | |
795 | break; | |
796 | default: | |
797 | txt = NULL; | |
798 | break; | |
799 | } | |
800 | if (txt) { | |
801 | wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED | |
802 | MACSTR " %s", MAC2STR(addr), txt); | |
803 | } | |
804 | ||
805 | switch (chan_width) { | |
806 | case CHAN_WIDTH_20_NOHT: | |
807 | txt = "20(no-HT)"; | |
808 | break; | |
809 | case CHAN_WIDTH_20: | |
810 | txt = "20"; | |
811 | break; | |
812 | case CHAN_WIDTH_40: | |
813 | txt = "40"; | |
814 | break; | |
815 | case CHAN_WIDTH_80: | |
816 | txt = "80"; | |
817 | break; | |
818 | case CHAN_WIDTH_80P80: | |
819 | txt = "80+80"; | |
820 | break; | |
821 | case CHAN_WIDTH_160: | |
822 | txt = "160"; | |
823 | break; | |
824 | default: | |
825 | txt = NULL; | |
826 | break; | |
827 | } | |
828 | if (txt) { | |
829 | wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED | |
830 | MACSTR " %s", MAC2STR(addr), txt); | |
831 | } | |
832 | ||
833 | if (rx_nss != 0xff) { | |
834 | wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED | |
835 | MACSTR " %d", MAC2STR(addr), rx_nss); | |
836 | } | |
837 | } | |
838 | ||
839 | ||
1b487b8b | 840 | void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht, |
95f556f3 OD |
841 | int offset, int width, int cf1, int cf2, |
842 | int finished) | |
1b487b8b | 843 | { |
f91e68e9 MV |
844 | /* TODO: If OCV is enabled deauth STAs that don't perform a SA Query */ |
845 | ||
c7803a02 | 846 | #ifdef NEED_AP_MLME |
d308a44f LC |
847 | int channel, chwidth, is_dfs; |
848 | u8 seg0_idx = 0, seg1_idx = 0; | |
6ca4949a | 849 | size_t i; |
1b487b8b TP |
850 | |
851 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
2f06bcb3 | 852 | HOSTAPD_LEVEL_INFO, |
95f556f3 OD |
853 | "driver %s channel switch: freq=%d, ht=%d, vht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d", |
854 | finished ? "had" : "starting", | |
bda9c085 SM |
855 | freq, ht, hapd->iconf->ch_switch_vht_config, offset, |
856 | width, channel_width_to_string(width), cf1, cf2); | |
1b487b8b | 857 | |
c3805fb6 JM |
858 | if (!hapd->iface->current_mode) { |
859 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
860 | HOSTAPD_LEVEL_WARNING, | |
861 | "ignore channel switch since the interface is not yet ready"); | |
862 | return; | |
863 | } | |
864 | ||
1b487b8b TP |
865 | hapd->iface->freq = freq; |
866 | ||
867 | channel = hostapd_hw_get_channel(hapd, freq); | |
868 | if (!channel) { | |
869 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
48b06c17 JM |
870 | HOSTAPD_LEVEL_WARNING, |
871 | "driver switched to bad channel!"); | |
1b487b8b TP |
872 | return; |
873 | } | |
874 | ||
8d1fdde7 JD |
875 | switch (width) { |
876 | case CHAN_WIDTH_80: | |
464dcfd0 | 877 | chwidth = CHANWIDTH_80MHZ; |
8d1fdde7 JD |
878 | break; |
879 | case CHAN_WIDTH_80P80: | |
464dcfd0 | 880 | chwidth = CHANWIDTH_80P80MHZ; |
8d1fdde7 JD |
881 | break; |
882 | case CHAN_WIDTH_160: | |
464dcfd0 | 883 | chwidth = CHANWIDTH_160MHZ; |
8d1fdde7 JD |
884 | break; |
885 | case CHAN_WIDTH_20_NOHT: | |
886 | case CHAN_WIDTH_20: | |
887 | case CHAN_WIDTH_40: | |
888 | default: | |
464dcfd0 | 889 | chwidth = CHANWIDTH_USE_HT; |
8d1fdde7 JD |
890 | break; |
891 | } | |
892 | ||
893 | switch (hapd->iface->current_mode->mode) { | |
894 | case HOSTAPD_MODE_IEEE80211A: | |
895 | if (cf1 > 5000) | |
896 | seg0_idx = (cf1 - 5000) / 5; | |
897 | if (cf2 > 5000) | |
898 | seg1_idx = (cf2 - 5000) / 5; | |
899 | break; | |
900 | default: | |
d308a44f LC |
901 | ieee80211_freq_to_chan(cf1, &seg0_idx); |
902 | ieee80211_freq_to_chan(cf2, &seg1_idx); | |
8d1fdde7 JD |
903 | break; |
904 | } | |
905 | ||
1b487b8b TP |
906 | hapd->iconf->channel = channel; |
907 | hapd->iconf->ieee80211n = ht; | |
bda9c085 | 908 | if (!ht) { |
5de74818 | 909 | hapd->iconf->ieee80211ac = 0; |
bda9c085 SM |
910 | } else if (hapd->iconf->ch_switch_vht_config) { |
911 | /* CHAN_SWITCH VHT config */ | |
912 | if (hapd->iconf->ch_switch_vht_config & | |
913 | CH_SWITCH_VHT_ENABLED) | |
914 | hapd->iconf->ieee80211ac = 1; | |
915 | else if (hapd->iconf->ch_switch_vht_config & | |
916 | CH_SWITCH_VHT_DISABLED) | |
917 | hapd->iconf->ieee80211ac = 0; | |
918 | } | |
919 | hapd->iconf->ch_switch_vht_config = 0; | |
920 | ||
1b487b8b | 921 | hapd->iconf->secondary_channel = offset; |
c6b7ac07 JC |
922 | hostapd_set_oper_chwidth(hapd->iconf, chwidth); |
923 | hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx); | |
924 | hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx); | |
bf281c12 | 925 | |
d239ab39 | 926 | is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features, |
927 | hapd->iface->num_hw_features); | |
1e2aaffb | 928 | |
95f556f3 OD |
929 | wpa_msg(hapd->msg_ctx, MSG_INFO, |
930 | "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d dfs=%d", | |
931 | finished ? WPA_EVENT_CHANNEL_SWITCH : | |
932 | WPA_EVENT_CHANNEL_SWITCH_STARTED, | |
933 | freq, ht, offset, channel_width_to_string(width), | |
934 | cf1, cf2, is_dfs); | |
935 | if (!finished) | |
936 | return; | |
937 | ||
6782b684 MK |
938 | if (hapd->csa_in_progress && |
939 | freq == hapd->cs_freq_params.freq) { | |
bf281c12 | 940 | hostapd_cleanup_cs_params(hapd); |
6782b684 | 941 | ieee802_11_set_beacon(hapd); |
bf281c12 | 942 | |
1e2aaffb AK |
943 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED |
944 | "freq=%d dfs=%d", freq, is_dfs); | |
945 | } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) { | |
946 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED | |
947 | "freq=%d dfs=%d", freq, is_dfs); | |
91498a12 SM |
948 | } else if (is_dfs && |
949 | hostapd_is_dfs_required(hapd->iface) && | |
950 | !hostapd_is_dfs_chan_available(hapd->iface) && | |
951 | !hapd->iface->cac_started) { | |
952 | hostapd_disable_iface(hapd->iface); | |
953 | hostapd_enable_iface(hapd->iface); | |
bf281c12 | 954 | } |
6ca4949a MT |
955 | |
956 | for (i = 0; i < hapd->iface->num_bss; i++) | |
957 | hostapd_neighbor_set_own_report(hapd->iface->bss[i]); | |
c7803a02 | 958 | #endif /* NEED_AP_MLME */ |
1b487b8b TP |
959 | } |
960 | ||
961 | ||
3140803b RM |
962 | void hostapd_event_connect_failed_reason(struct hostapd_data *hapd, |
963 | const u8 *addr, int reason_code) | |
964 | { | |
965 | switch (reason_code) { | |
966 | case MAX_CLIENT_REACHED: | |
967 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR, | |
968 | MAC2STR(addr)); | |
969 | break; | |
970 | case BLOCKED_CLIENT: | |
971 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR, | |
972 | MAC2STR(addr)); | |
973 | break; | |
974 | } | |
975 | } | |
976 | ||
977 | ||
16689c7c | 978 | #ifdef CONFIG_ACS |
d9909717 TB |
979 | void hostapd_acs_channel_selected(struct hostapd_data *hapd, |
980 | struct acs_selected_channels *acs_res) | |
16689c7c | 981 | { |
3784c058 | 982 | int ret, i; |
e1d00d47 | 983 | int err = 0; |
41cac481 | 984 | struct hostapd_channel_data *pri_chan; |
16689c7c PX |
985 | |
986 | if (hapd->iconf->channel) { | |
987 | wpa_printf(MSG_INFO, "ACS: Channel was already set to %d", | |
988 | hapd->iconf->channel); | |
989 | return; | |
990 | } | |
991 | ||
59e33b4a AB |
992 | hapd->iface->freq = acs_res->pri_freq; |
993 | ||
3784c058 PX |
994 | if (!hapd->iface->current_mode) { |
995 | for (i = 0; i < hapd->iface->num_hw_features; i++) { | |
996 | struct hostapd_hw_modes *mode = | |
997 | &hapd->iface->hw_features[i]; | |
998 | ||
999 | if (mode->mode == acs_res->hw_mode) { | |
59e33b4a AB |
1000 | if (hapd->iface->freq > 0 && |
1001 | !hw_get_chan(mode->mode, | |
1002 | hapd->iface->freq, | |
1003 | hapd->iface->hw_features, | |
1004 | hapd->iface->num_hw_features)) | |
1005 | continue; | |
3784c058 PX |
1006 | hapd->iface->current_mode = mode; |
1007 | break; | |
1008 | } | |
1009 | } | |
1010 | if (!hapd->iface->current_mode) { | |
1011 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, | |
1012 | HOSTAPD_LEVEL_WARNING, | |
1013 | "driver selected to bad hw_mode"); | |
e1d00d47 PX |
1014 | err = 1; |
1015 | goto out; | |
3784c058 PX |
1016 | } |
1017 | } | |
1018 | ||
41cac481 | 1019 | if (!acs_res->pri_freq) { |
16689c7c PX |
1020 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
1021 | HOSTAPD_LEVEL_WARNING, | |
1022 | "driver switched to bad channel"); | |
e1d00d47 PX |
1023 | err = 1; |
1024 | goto out; | |
16689c7c | 1025 | } |
41cac481 AB |
1026 | pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode, |
1027 | acs_res->pri_freq, NULL, | |
1028 | hapd->iface->hw_features, | |
1029 | hapd->iface->num_hw_features); | |
1030 | if (!pri_chan) { | |
1031 | wpa_printf(MSG_ERROR, | |
1032 | "ACS: Could not determine primary channel number from pri_freq %u", | |
1033 | acs_res->pri_freq); | |
1034 | err = 1; | |
1035 | goto out; | |
1036 | } | |
16689c7c | 1037 | |
41cac481 | 1038 | hapd->iconf->channel = pri_chan->chan; |
857d9422 | 1039 | hapd->iconf->acs = 1; |
16689c7c | 1040 | |
41cac481 | 1041 | if (acs_res->sec_freq == 0) |
16689c7c | 1042 | hapd->iconf->secondary_channel = 0; |
41cac481 | 1043 | else if (acs_res->sec_freq < acs_res->pri_freq) |
16689c7c | 1044 | hapd->iconf->secondary_channel = -1; |
41cac481 | 1045 | else if (acs_res->sec_freq > acs_res->pri_freq) |
16689c7c PX |
1046 | hapd->iconf->secondary_channel = 1; |
1047 | else { | |
1048 | wpa_printf(MSG_ERROR, "Invalid secondary channel!"); | |
e1d00d47 PX |
1049 | err = 1; |
1050 | goto out; | |
16689c7c PX |
1051 | } |
1052 | ||
e520de8d NS |
1053 | hapd->iconf->edmg_channel = acs_res->edmg_channel; |
1054 | ||
1d2c45ec | 1055 | if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) { |
857d9422 | 1056 | /* set defaults for backwards compatibility */ |
c6b7ac07 JC |
1057 | hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0); |
1058 | hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0); | |
1059 | hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_USE_HT); | |
4bf78a79 VK |
1060 | if (acs_res->ch_width == 40) { |
1061 | if (is_6ghz_freq(acs_res->pri_freq)) | |
c6b7ac07 JC |
1062 | hostapd_set_oper_centr_freq_seg0_idx( |
1063 | hapd->iconf, | |
1064 | acs_res->vht_seg0_center_ch); | |
4bf78a79 VK |
1065 | } else if (acs_res->ch_width == 80) { |
1066 | hostapd_set_oper_centr_freq_seg0_idx( | |
1067 | hapd->iconf, acs_res->vht_seg0_center_ch); | |
1068 | if (acs_res->vht_seg1_center_ch == 0) { | |
c6b7ac07 | 1069 | hostapd_set_oper_chwidth(hapd->iconf, |
4bf78a79 | 1070 | CHANWIDTH_80MHZ); |
857d9422 | 1071 | } else { |
4bf78a79 VK |
1072 | hostapd_set_oper_chwidth(hapd->iconf, |
1073 | CHANWIDTH_80P80MHZ); | |
c6b7ac07 JC |
1074 | hostapd_set_oper_centr_freq_seg1_idx( |
1075 | hapd->iconf, | |
1076 | acs_res->vht_seg1_center_ch); | |
857d9422 | 1077 | } |
4bf78a79 VK |
1078 | } else if (acs_res->ch_width == 160) { |
1079 | hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_160MHZ); | |
1080 | hostapd_set_oper_centr_freq_seg0_idx( | |
1081 | hapd->iconf, acs_res->vht_seg1_center_ch); | |
857d9422 MM |
1082 | } |
1083 | } | |
1084 | ||
e1d00d47 PX |
1085 | out: |
1086 | ret = hostapd_acs_completed(hapd->iface, err); | |
16689c7c PX |
1087 | if (ret) { |
1088 | wpa_printf(MSG_ERROR, | |
1089 | "ACS: Possibly channel configuration is invalid"); | |
1090 | } | |
1091 | } | |
1092 | #endif /* CONFIG_ACS */ | |
1093 | ||
1094 | ||
04a85e44 | 1095 | int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da, |
baf513d6 JB |
1096 | const u8 *bssid, const u8 *ie, size_t ie_len, |
1097 | int ssi_signal) | |
e67b55fb JM |
1098 | { |
1099 | size_t i; | |
1100 | int ret = 0; | |
1101 | ||
b211f3eb JM |
1102 | if (sa == NULL || ie == NULL) |
1103 | return -1; | |
1104 | ||
1105 | random_add_randomness(sa, ETH_ALEN); | |
e67b55fb JM |
1106 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) { |
1107 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, | |
baf513d6 JB |
1108 | sa, da, bssid, ie, ie_len, |
1109 | ssi_signal) > 0) { | |
e67b55fb JM |
1110 | ret = 1; |
1111 | break; | |
1112 | } | |
1113 | } | |
1114 | return ret; | |
1115 | } | |
1116 | ||
1117 | ||
5c61a282 JM |
1118 | #ifdef HOSTAPD |
1119 | ||
4ec1fd8e | 1120 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 SP |
1121 | static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst, |
1122 | const u8 *bssid, | |
1123 | u16 auth_transaction, u16 status, | |
1124 | const u8 *ies, size_t ies_len) | |
1125 | { | |
1126 | struct hostapd_data *hapd = ctx; | |
1127 | struct sta_info *sta; | |
1128 | ||
1129 | sta = ap_get_sta(hapd, dst); | |
1130 | if (sta == NULL) | |
1131 | return; | |
1132 | ||
1133 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, | |
1134 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); | |
1135 | sta->flags |= WLAN_STA_AUTH; | |
1136 | ||
1137 | hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len); | |
1138 | } | |
4ec1fd8e | 1139 | #endif /* CONFIG_IEEE80211R_AP */ |
88b32a99 SP |
1140 | |
1141 | ||
fa61bff6 JM |
1142 | #ifdef CONFIG_FILS |
1143 | static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd, | |
1144 | struct sta_info *sta, u16 resp, | |
1145 | struct wpabuf *data, int pub) | |
1146 | { | |
1147 | if (resp == WLAN_STATUS_SUCCESS) { | |
1148 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
1149 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)"); | |
1150 | sta->flags |= WLAN_STA_AUTH; | |
1151 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); | |
1152 | sta->auth_alg = WLAN_AUTH_FILS_SK; | |
1153 | mlme_authenticate_indication(hapd, sta); | |
1154 | } else { | |
1155 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
1156 | HOSTAPD_LEVEL_DEBUG, | |
1157 | "authentication failed (FILS)"); | |
1158 | } | |
1159 | ||
1160 | hostapd_sta_auth(hapd, sta->addr, 2, resp, | |
1161 | data ? wpabuf_head(data) : NULL, | |
1162 | data ? wpabuf_len(data) : 0); | |
1163 | wpabuf_free(data); | |
1164 | } | |
1165 | #endif /* CONFIG_FILS */ | |
1166 | ||
1167 | ||
88b32a99 SP |
1168 | static void hostapd_notif_auth(struct hostapd_data *hapd, |
1169 | struct auth_info *rx_auth) | |
1170 | { | |
1171 | struct sta_info *sta; | |
1172 | u16 status = WLAN_STATUS_SUCCESS; | |
1173 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; | |
1174 | size_t resp_ies_len = 0; | |
1175 | ||
1176 | sta = ap_get_sta(hapd, rx_auth->peer); | |
1177 | if (!sta) { | |
1178 | sta = ap_sta_add(hapd, rx_auth->peer); | |
1179 | if (sta == NULL) { | |
728d9717 | 1180 | status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
88b32a99 SP |
1181 | goto fail; |
1182 | } | |
1183 | } | |
1184 | sta->flags &= ~WLAN_STA_PREAUTH; | |
1185 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); | |
4ec1fd8e | 1186 | #ifdef CONFIG_IEEE80211R_AP |
88b32a99 SP |
1187 | if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) { |
1188 | sta->auth_alg = WLAN_AUTH_FT; | |
1189 | if (sta->wpa_sm == NULL) | |
1190 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, | |
94ddef3e | 1191 | sta->addr, NULL); |
88b32a99 | 1192 | if (sta->wpa_sm == NULL) { |
48b06c17 JM |
1193 | wpa_printf(MSG_DEBUG, |
1194 | "FT: Failed to initialize WPA state machine"); | |
88b32a99 SP |
1195 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
1196 | goto fail; | |
1197 | } | |
1198 | wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid, | |
1199 | rx_auth->auth_transaction, rx_auth->ies, | |
1200 | rx_auth->ies_len, | |
1201 | hostapd_notify_auth_ft_finish, hapd); | |
1202 | return; | |
1203 | } | |
4ec1fd8e | 1204 | #endif /* CONFIG_IEEE80211R_AP */ |
fa61bff6 JM |
1205 | |
1206 | #ifdef CONFIG_FILS | |
1207 | if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) { | |
1208 | sta->auth_alg = WLAN_AUTH_FILS_SK; | |
1209 | handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len, | |
1210 | rx_auth->auth_type, rx_auth->auth_transaction, | |
1211 | rx_auth->status_code, | |
1212 | hostapd_notify_auth_fils_finish); | |
1213 | return; | |
1214 | } | |
1215 | #endif /* CONFIG_FILS */ | |
1216 | ||
88b32a99 SP |
1217 | fail: |
1218 | hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1, | |
1219 | status, resp_ies, resp_ies_len); | |
1220 | } | |
1221 | ||
1222 | ||
4d379be4 | 1223 | #ifndef NEED_AP_MLME |
88b32a99 | 1224 | static void hostapd_action_rx(struct hostapd_data *hapd, |
dbfb8e82 | 1225 | struct rx_mgmt *drv_mgmt) |
88b32a99 | 1226 | { |
dbfb8e82 | 1227 | struct ieee80211_mgmt *mgmt; |
88b32a99 | 1228 | struct sta_info *sta; |
dbfb8e82 JM |
1229 | size_t plen __maybe_unused; |
1230 | u16 fc; | |
e0785ebb | 1231 | u8 *action __maybe_unused; |
dbfb8e82 | 1232 | |
e0785ebb | 1233 | if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1) |
dbfb8e82 JM |
1234 | return; |
1235 | ||
002edb63 | 1236 | plen = drv_mgmt->frame_len - IEEE80211_HDRLEN; |
dbfb8e82 JM |
1237 | |
1238 | mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame; | |
1239 | fc = le_to_host16(mgmt->frame_control); | |
1240 | if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) | |
1241 | return; /* handled by the driver */ | |
88b32a99 | 1242 | |
e0785ebb JM |
1243 | action = (u8 *) &mgmt->u.action.u; |
1244 | wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR | |
1245 | " da " MACSTR " plen %d", | |
1246 | mgmt->u.action.category, *action, | |
1247 | MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen); | |
7d9c0cd3 | 1248 | |
dbfb8e82 | 1249 | sta = ap_get_sta(hapd, mgmt->sa); |
88b32a99 SP |
1250 | if (sta == NULL) { |
1251 | wpa_printf(MSG_DEBUG, "%s: station not found", __func__); | |
1252 | return; | |
1253 | } | |
4ec1fd8e | 1254 | #ifdef CONFIG_IEEE80211R_AP |
dbfb8e82 | 1255 | if (mgmt->u.action.category == WLAN_ACTION_FT) { |
002edb63 JM |
1256 | wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen); |
1257 | return; | |
88b32a99 | 1258 | } |
4ec1fd8e | 1259 | #endif /* CONFIG_IEEE80211R_AP */ |
700b3f39 | 1260 | if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) { |
f9da7505 | 1261 | ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len); |
700b3f39 | 1262 | return; |
7d9c0cd3 | 1263 | } |
b5bf84ba | 1264 | #ifdef CONFIG_WNM_AP |
dbfb8e82 JM |
1265 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { |
1266 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len); | |
cc833a23 | 1267 | return; |
d32d94db | 1268 | } |
b5bf84ba | 1269 | #endif /* CONFIG_WNM_AP */ |
037378ff AN |
1270 | #ifdef CONFIG_FST |
1271 | if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) { | |
1272 | fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len); | |
1273 | return; | |
1274 | } | |
1275 | #endif /* CONFIG_FST */ | |
9c2b8204 | 1276 | #ifdef CONFIG_DPP |
002edb63 | 1277 | if (plen >= 2 + 4 && |
9c2b8204 JM |
1278 | mgmt->u.action.u.vs_public_action.action == |
1279 | WLAN_PA_VENDOR_SPECIFIC && | |
1280 | WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) == | |
1281 | OUI_WFA && | |
1282 | mgmt->u.action.u.vs_public_action.variable[0] == | |
1283 | DPP_OUI_TYPE) { | |
1284 | const u8 *pos, *end; | |
1285 | ||
dc4d271c | 1286 | pos = mgmt->u.action.u.vs_public_action.oui; |
9c2b8204 JM |
1287 | end = drv_mgmt->frame + drv_mgmt->frame_len; |
1288 | hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos, | |
1289 | drv_mgmt->freq); | |
1290 | return; | |
1291 | } | |
1292 | #endif /* CONFIG_DPP */ | |
88b32a99 | 1293 | } |
4d379be4 | 1294 | #endif /* NEED_AP_MLME */ |
88b32a99 SP |
1295 | |
1296 | ||
fe6bdb77 | 1297 | #ifdef NEED_AP_MLME |
f8b1f695 | 1298 | |
f8b1f695 JM |
1299 | #define HAPD_BROADCAST ((struct hostapd_data *) -1) |
1300 | ||
1301 | static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface, | |
1302 | const u8 *bssid) | |
1303 | { | |
1304 | size_t i; | |
1305 | ||
1306 | if (bssid == NULL) | |
1307 | return NULL; | |
1308 | if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff && | |
1309 | bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff) | |
1310 | return HAPD_BROADCAST; | |
1311 | ||
1312 | for (i = 0; i < iface->num_bss; i++) { | |
1313 | if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) | |
1314 | return iface->bss[i]; | |
1315 | } | |
1316 | ||
1317 | return NULL; | |
1318 | } | |
1319 | ||
1320 | ||
1321 | static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, | |
9b90955e JB |
1322 | const u8 *bssid, const u8 *addr, |
1323 | int wds) | |
f8b1f695 | 1324 | { |
9b90955e | 1325 | hapd = get_hapd_bssid(hapd->iface, bssid); |
f8b1f695 JM |
1326 | if (hapd == NULL || hapd == HAPD_BROADCAST) |
1327 | return; | |
1328 | ||
9b90955e | 1329 | ieee802_11_rx_from_unknown(hapd, addr, wds); |
f8b1f695 JM |
1330 | } |
1331 | ||
1332 | ||
912b34f0 | 1333 | static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt) |
b5b969e9 | 1334 | { |
4b9841d3 | 1335 | struct hostapd_iface *iface = hapd->iface; |
b57e086c | 1336 | const struct ieee80211_hdr *hdr; |
4b9841d3 | 1337 | const u8 *bssid; |
2a8b7416 | 1338 | struct hostapd_frame_info fi; |
912b34f0 | 1339 | int ret; |
4b9841d3 | 1340 | |
5f7e1c06 JM |
1341 | #ifdef CONFIG_TESTING_OPTIONS |
1342 | if (hapd->ext_mgmt_frame_handling) { | |
1343 | size_t hex_len = 2 * rx_mgmt->frame_len + 1; | |
1344 | char *hex = os_malloc(hex_len); | |
48b06c17 | 1345 | |
5f7e1c06 JM |
1346 | if (hex) { |
1347 | wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame, | |
1348 | rx_mgmt->frame_len); | |
1349 | wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex); | |
1350 | os_free(hex); | |
1351 | } | |
1352 | return 1; | |
1353 | } | |
1354 | #endif /* CONFIG_TESTING_OPTIONS */ | |
1355 | ||
2a8b7416 JM |
1356 | hdr = (const struct ieee80211_hdr *) rx_mgmt->frame; |
1357 | bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len); | |
4b9841d3 | 1358 | if (bssid == NULL) |
912b34f0 | 1359 | return 0; |
4b9841d3 JM |
1360 | |
1361 | hapd = get_hapd_bssid(iface, bssid); | |
1362 | if (hapd == NULL) { | |
48b06c17 | 1363 | u16 fc = le_to_host16(hdr->frame_control); |
4b9841d3 JM |
1364 | |
1365 | /* | |
1366 | * Drop frames to unknown BSSIDs except for Beacon frames which | |
1367 | * could be used to update neighbor information. | |
1368 | */ | |
1369 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
1370 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
1371 | hapd = iface->bss[0]; | |
1372 | else | |
912b34f0 | 1373 | return 0; |
4b9841d3 JM |
1374 | } |
1375 | ||
2a8b7416 | 1376 | os_memset(&fi, 0, sizeof(fi)); |
c5cc7a59 | 1377 | fi.freq = rx_mgmt->freq; |
2a8b7416 JM |
1378 | fi.datarate = rx_mgmt->datarate; |
1379 | fi.ssi_signal = rx_mgmt->ssi_signal; | |
1380 | ||
4b9841d3 JM |
1381 | if (hapd == HAPD_BROADCAST) { |
1382 | size_t i; | |
48b06c17 | 1383 | |
912b34f0 JM |
1384 | ret = 0; |
1385 | for (i = 0; i < iface->num_bss; i++) { | |
1d91f504 SW |
1386 | /* if bss is set, driver will call this function for |
1387 | * each bss individually. */ | |
1388 | if (rx_mgmt->drv_priv && | |
1389 | (iface->bss[i]->drv_priv != rx_mgmt->drv_priv)) | |
1390 | continue; | |
1391 | ||
912b34f0 JM |
1392 | if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame, |
1393 | rx_mgmt->frame_len, &fi) > 0) | |
1394 | ret = 1; | |
1395 | } | |
4b9841d3 | 1396 | } else |
912b34f0 JM |
1397 | ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, |
1398 | &fi); | |
bbb921da JM |
1399 | |
1400 | random_add_randomness(&fi, sizeof(fi)); | |
912b34f0 JM |
1401 | |
1402 | return ret; | |
b5b969e9 JM |
1403 | } |
1404 | ||
1405 | ||
f8b1f695 JM |
1406 | static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf, |
1407 | size_t len, u16 stype, int ok) | |
b5b969e9 | 1408 | { |
4b9841d3 | 1409 | struct ieee80211_hdr *hdr; |
6996ff7b | 1410 | struct hostapd_data *orig_hapd = hapd; |
48b06c17 | 1411 | |
4b9841d3 JM |
1412 | hdr = (struct ieee80211_hdr *) buf; |
1413 | hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len)); | |
6996ff7b | 1414 | if (!hapd) |
4b9841d3 | 1415 | return; |
6996ff7b JM |
1416 | if (hapd == HAPD_BROADCAST) { |
1417 | if (stype != WLAN_FC_STYPE_ACTION || len <= 25 || | |
1418 | buf[24] != WLAN_ACTION_PUBLIC) | |
1419 | return; | |
1420 | hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2); | |
1421 | if (!hapd || hapd == HAPD_BROADCAST) | |
1422 | return; | |
1423 | /* | |
1424 | * Allow processing of TX status for a Public Action frame that | |
1425 | * used wildcard BBSID. | |
1426 | */ | |
1427 | } | |
b5b969e9 JM |
1428 | ieee802_11_mgmt_cb(hapd, buf, len, stype, ok); |
1429 | } | |
f82ef4d8 | 1430 | |
f8b1f695 | 1431 | #endif /* NEED_AP_MLME */ |
ad1e68e6 JM |
1432 | |
1433 | ||
a8e0505b JM |
1434 | static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr) |
1435 | { | |
1436 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
48b06c17 | 1437 | |
a8e0505b JM |
1438 | if (sta) |
1439 | return 0; | |
1440 | ||
1441 | wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR | |
1442 | " - adding a new STA", MAC2STR(addr)); | |
1443 | sta = ap_sta_add(hapd, addr); | |
1444 | if (sta) { | |
1445 | hostapd_new_assoc_sta(hapd, sta, 0); | |
1446 | } else { | |
1447 | wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR, | |
1448 | MAC2STR(addr)); | |
1449 | return -1; | |
1450 | } | |
1451 | ||
1452 | return 0; | |
1453 | } | |
1454 | ||
1455 | ||
1456 | static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, | |
1457 | const u8 *data, size_t data_len) | |
1458 | { | |
1459 | struct hostapd_iface *iface = hapd->iface; | |
f826635c | 1460 | struct sta_info *sta; |
a8e0505b JM |
1461 | size_t j; |
1462 | ||
1463 | for (j = 0; j < iface->num_bss; j++) { | |
48b06c17 JM |
1464 | sta = ap_get_sta(iface->bss[j], src); |
1465 | if (sta && sta->flags & WLAN_STA_ASSOC) { | |
1466 | hapd = iface->bss[j]; | |
1467 | break; | |
a8e0505b JM |
1468 | } |
1469 | } | |
1470 | ||
1471 | ieee802_1x_receive(hapd, src, data, data_len); | |
1472 | } | |
1473 | ||
96bc5086 TB |
1474 | #endif /* HOSTAPD */ |
1475 | ||
a8e0505b | 1476 | |
499c37b7 NJ |
1477 | static struct hostapd_channel_data * |
1478 | hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq) | |
1479 | { | |
1480 | int i; | |
1481 | struct hostapd_channel_data *chan; | |
1482 | ||
1483 | for (i = 0; i < mode->num_channels; i++) { | |
1484 | chan = &mode->channels[i]; | |
1485 | if ((unsigned int) chan->freq == freq) | |
1486 | return chan; | |
1487 | } | |
1488 | ||
1489 | return NULL; | |
1490 | } | |
1491 | ||
1492 | ||
0185007c MK |
1493 | static struct hostapd_channel_data * hostapd_get_mode_channel( |
1494 | struct hostapd_iface *iface, unsigned int freq) | |
1495 | { | |
1496 | int i; | |
1497 | struct hostapd_channel_data *chan; | |
1498 | ||
499c37b7 NJ |
1499 | for (i = 0; i < iface->num_hw_features; i++) { |
1500 | if (hostapd_hw_skip_mode(iface, &iface->hw_features[i])) | |
1501 | continue; | |
1502 | chan = hostapd_get_mode_chan(&iface->hw_features[i], freq); | |
1503 | if (chan) | |
0185007c MK |
1504 | return chan; |
1505 | } | |
1506 | ||
1507 | return NULL; | |
1508 | } | |
1509 | ||
1510 | ||
1511 | static void hostapd_update_nf(struct hostapd_iface *iface, | |
1512 | struct hostapd_channel_data *chan, | |
1513 | struct freq_survey *survey) | |
1514 | { | |
1515 | if (!iface->chans_surveyed) { | |
1516 | chan->min_nf = survey->nf; | |
1517 | iface->lowest_nf = survey->nf; | |
1518 | } else { | |
1519 | if (dl_list_empty(&chan->survey_list)) | |
1520 | chan->min_nf = survey->nf; | |
1521 | else if (survey->nf < chan->min_nf) | |
1522 | chan->min_nf = survey->nf; | |
1523 | if (survey->nf < iface->lowest_nf) | |
1524 | iface->lowest_nf = survey->nf; | |
1525 | } | |
1526 | } | |
1527 | ||
1528 | ||
ec8f36af KP |
1529 | static void hostapd_single_channel_get_survey(struct hostapd_iface *iface, |
1530 | struct survey_results *survey_res) | |
1531 | { | |
1532 | struct hostapd_channel_data *chan; | |
1533 | struct freq_survey *survey; | |
1534 | u64 divisor, dividend; | |
1535 | ||
1536 | survey = dl_list_first(&survey_res->survey_list, struct freq_survey, | |
1537 | list); | |
1538 | if (!survey || !survey->freq) | |
1539 | return; | |
1540 | ||
1541 | chan = hostapd_get_mode_channel(iface, survey->freq); | |
1542 | if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED) | |
1543 | return; | |
1544 | ||
48b06c17 JM |
1545 | wpa_printf(MSG_DEBUG, |
1546 | "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)", | |
ec8f36af KP |
1547 | survey->freq, |
1548 | (unsigned long int) survey->channel_time, | |
1549 | (unsigned long int) survey->channel_time_busy); | |
1550 | ||
1551 | if (survey->channel_time > iface->last_channel_time && | |
1552 | survey->channel_time > survey->channel_time_busy) { | |
1553 | dividend = survey->channel_time_busy - | |
1554 | iface->last_channel_time_busy; | |
1555 | divisor = survey->channel_time - iface->last_channel_time; | |
1556 | ||
1557 | iface->channel_utilization = dividend * 255 / divisor; | |
1558 | wpa_printf(MSG_DEBUG, "Channel Utilization: %d", | |
1559 | iface->channel_utilization); | |
1560 | } | |
1561 | iface->last_channel_time = survey->channel_time; | |
1562 | iface->last_channel_time_busy = survey->channel_time_busy; | |
1563 | } | |
1564 | ||
1565 | ||
96bc5086 TB |
1566 | void hostapd_event_get_survey(struct hostapd_iface *iface, |
1567 | struct survey_results *survey_results) | |
0185007c | 1568 | { |
0185007c MK |
1569 | struct freq_survey *survey, *tmp; |
1570 | struct hostapd_channel_data *chan; | |
1571 | ||
1572 | if (dl_list_empty(&survey_results->survey_list)) { | |
1573 | wpa_printf(MSG_DEBUG, "No survey data received"); | |
1574 | return; | |
1575 | } | |
1576 | ||
ec8f36af KP |
1577 | if (survey_results->freq_filter) { |
1578 | hostapd_single_channel_get_survey(iface, survey_results); | |
1579 | return; | |
1580 | } | |
1581 | ||
0185007c MK |
1582 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
1583 | struct freq_survey, list) { | |
1584 | chan = hostapd_get_mode_channel(iface, survey->freq); | |
1585 | if (!chan) | |
1586 | continue; | |
1587 | if (chan->flag & HOSTAPD_CHAN_DISABLED) | |
1588 | continue; | |
1589 | ||
1590 | dl_list_del(&survey->list); | |
1591 | dl_list_add_tail(&chan->survey_list, &survey->list); | |
1592 | ||
1593 | hostapd_update_nf(iface, chan, survey); | |
1594 | ||
1595 | iface->chans_surveyed++; | |
1596 | } | |
1597 | } | |
1598 | ||
1599 | ||
96bc5086 | 1600 | #ifdef HOSTAPD |
e76da505 JD |
1601 | #ifdef NEED_AP_MLME |
1602 | ||
5841958f MK |
1603 | static void hostapd_event_iface_unavailable(struct hostapd_data *hapd) |
1604 | { | |
1605 | wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped", | |
1606 | hapd->conf->iface); | |
1607 | ||
1608 | if (hapd->csa_in_progress) { | |
1609 | wpa_printf(MSG_INFO, "CSA failed (%s was stopped)", | |
1610 | hapd->conf->iface); | |
1611 | hostapd_switch_channel_fallback(hapd->iface, | |
1612 | &hapd->cs_freq_params); | |
1613 | } | |
1614 | } | |
1615 | ||
1616 | ||
e76da505 JD |
1617 | static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd, |
1618 | struct dfs_event *radar) | |
1619 | { | |
e76da505 | 1620 | wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq); |
dc036d9e | 1621 | hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1622 | radar->chan_offset, radar->chan_width, |
1623 | radar->cf1, radar->cf2); | |
e76da505 JD |
1624 | } |
1625 | ||
1626 | ||
7cbb5f1a VT |
1627 | static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd, |
1628 | struct dfs_event *radar) | |
1629 | { | |
1630 | wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq); | |
1631 | hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled, | |
1632 | radar->chan_offset, radar->chan_width, | |
1633 | radar->cf1, radar->cf2); | |
1634 | } | |
1635 | ||
1636 | ||
e76da505 JD |
1637 | static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd, |
1638 | struct dfs_event *radar) | |
1639 | { | |
1640 | wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq); | |
dc036d9e | 1641 | hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1642 | radar->chan_offset, radar->chan_width, |
1643 | radar->cf1, radar->cf2); | |
e76da505 JD |
1644 | } |
1645 | ||
1646 | ||
1647 | static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd, | |
1648 | struct dfs_event *radar) | |
1649 | { | |
1650 | wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq); | |
dc036d9e | 1651 | hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1652 | radar->chan_offset, radar->chan_width, |
1653 | radar->cf1, radar->cf2); | |
e76da505 JD |
1654 | } |
1655 | ||
1656 | ||
1657 | static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd, | |
1658 | struct dfs_event *radar) | |
1659 | { | |
1660 | wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq); | |
dc036d9e | 1661 | hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled, |
58b73e3d JD |
1662 | radar->chan_offset, radar->chan_width, |
1663 | radar->cf1, radar->cf2); | |
e76da505 JD |
1664 | } |
1665 | ||
c13578c3 AK |
1666 | |
1667 | static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd, | |
1668 | struct dfs_event *radar) | |
1669 | { | |
1670 | wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq); | |
1671 | hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled, | |
1672 | radar->chan_offset, radar->chan_width, | |
1673 | radar->cf1, radar->cf2); | |
1674 | } | |
1675 | ||
e76da505 JD |
1676 | #endif /* NEED_AP_MLME */ |
1677 | ||
1678 | ||
1952b626 BP |
1679 | static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd, |
1680 | int istatus, | |
1681 | const char *ifname, | |
1682 | const u8 *addr) | |
1683 | { | |
1684 | struct sta_info *sta = ap_get_sta(hapd, addr); | |
1685 | ||
1686 | if (sta) { | |
1687 | os_free(sta->ifname_wds); | |
1688 | if (istatus == INTERFACE_ADDED) | |
1689 | sta->ifname_wds = os_strdup(ifname); | |
1690 | else | |
1691 | sta->ifname_wds = NULL; | |
1692 | } | |
1693 | ||
1694 | wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR, | |
1695 | istatus == INTERFACE_ADDED ? | |
1696 | WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED, | |
1697 | ifname, MAC2STR(addr)); | |
1698 | } | |
1699 | ||
1700 | ||
ef60f012 LD |
1701 | #ifdef CONFIG_OWE |
1702 | static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd, | |
1703 | const u8 *peer, const u8 *ie, | |
1704 | size_t ie_len) | |
1705 | { | |
1706 | u16 status; | |
1707 | struct sta_info *sta; | |
1708 | struct ieee802_11_elems elems; | |
1709 | ||
1710 | if (!hapd || !hapd->wpa_auth) { | |
1711 | wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context"); | |
1712 | return -1; | |
1713 | } | |
1714 | if (!peer) { | |
1715 | wpa_printf(MSG_DEBUG, "OWE: Peer unknown"); | |
1716 | return -1; | |
1717 | } | |
1718 | if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) { | |
1719 | wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured"); | |
1720 | status = WLAN_STATUS_AKMP_NOT_VALID; | |
1721 | goto err; | |
1722 | } | |
1723 | if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) { | |
1724 | wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for " | |
1725 | MACSTR, MAC2STR(peer)); | |
1726 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1727 | goto err; | |
1728 | } | |
1729 | status = owe_validate_request(hapd, peer, elems.rsn_ie, | |
1730 | elems.rsn_ie_len, | |
1731 | elems.owe_dh, elems.owe_dh_len); | |
1732 | if (status != WLAN_STATUS_SUCCESS) | |
1733 | goto err; | |
1734 | ||
1735 | sta = ap_get_sta(hapd, peer); | |
1736 | if (sta) { | |
1737 | ap_sta_no_session_timeout(hapd, sta); | |
1738 | accounting_sta_stop(hapd, sta); | |
1739 | ||
1740 | /* | |
1741 | * Make sure that the previously registered inactivity timer | |
1742 | * will not remove the STA immediately. | |
1743 | */ | |
1744 | sta->timeout_next = STA_NULLFUNC; | |
1745 | } else { | |
1746 | sta = ap_sta_add(hapd, peer); | |
1747 | if (!sta) { | |
1748 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1749 | goto err; | |
1750 | } | |
1751 | } | |
1752 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); | |
1753 | ||
1754 | status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie, | |
1755 | elems.rsn_ie_len, elems.owe_dh, | |
1756 | elems.owe_dh_len); | |
1757 | if (status != WLAN_STATUS_SUCCESS) | |
1758 | ap_free_sta(hapd, sta); | |
1759 | ||
1760 | return 0; | |
1761 | err: | |
1762 | hostapd_drv_update_dh_ie(hapd, peer, status, NULL, 0); | |
1763 | return 0; | |
1764 | } | |
1765 | #endif /* CONFIG_OWE */ | |
1766 | ||
1767 | ||
9646a8ab | 1768 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
ad1e68e6 JM |
1769 | union wpa_event_data *data) |
1770 | { | |
1771 | struct hostapd_data *hapd = ctx; | |
74781dfc JM |
1772 | #ifndef CONFIG_NO_STDOUT_DEBUG |
1773 | int level = MSG_DEBUG; | |
ad1e68e6 | 1774 | |
34caf71a | 1775 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame && |
74781dfc JM |
1776 | data->rx_mgmt.frame_len >= 24) { |
1777 | const struct ieee80211_hdr *hdr; | |
1778 | u16 fc; | |
48b06c17 | 1779 | |
74781dfc JM |
1780 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; |
1781 | fc = le_to_host16(hdr->frame_control); | |
1782 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
1783 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
1784 | level = MSG_EXCESSIVE; | |
cc2ada86 JM |
1785 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
1786 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ) | |
1787 | level = MSG_EXCESSIVE; | |
74781dfc JM |
1788 | } |
1789 | ||
1790 | wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received", | |
e26cd1a1 | 1791 | event_to_string(event), event); |
74781dfc | 1792 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
e26cd1a1 | 1793 | |
ad1e68e6 JM |
1794 | switch (event) { |
1795 | case EVENT_MICHAEL_MIC_FAILURE: | |
1796 | michael_mic_failure(hapd, data->michael_mic_failure.src, 1); | |
1797 | break; | |
1798 | case EVENT_SCAN_RESULTS: | |
1799 | if (hapd->iface->scan_cb) | |
1800 | hapd->iface->scan_cb(hapd->iface); | |
1801 | break; | |
fcf0f87d | 1802 | case EVENT_WPS_BUTTON_PUSHED: |
d601247c | 1803 | hostapd_wps_button_pushed(hapd, NULL); |
fcf0f87d | 1804 | break; |
f8b1f695 JM |
1805 | #ifdef NEED_AP_MLME |
1806 | case EVENT_TX_STATUS: | |
1807 | switch (data->tx_status.type) { | |
1808 | case WLAN_FC_TYPE_MGMT: | |
1809 | hostapd_mgmt_tx_cb(hapd, data->tx_status.data, | |
1810 | data->tx_status.data_len, | |
1811 | data->tx_status.stype, | |
1812 | data->tx_status.ack); | |
1813 | break; | |
1814 | case WLAN_FC_TYPE_DATA: | |
1815 | hostapd_tx_status(hapd, data->tx_status.dst, | |
1816 | data->tx_status.data, | |
1817 | data->tx_status.data_len, | |
1818 | data->tx_status.ack); | |
1819 | break; | |
1820 | } | |
1821 | break; | |
dd840f79 JB |
1822 | case EVENT_EAPOL_TX_STATUS: |
1823 | hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst, | |
1824 | data->eapol_tx_status.data, | |
1825 | data->eapol_tx_status.data_len, | |
1826 | data->eapol_tx_status.ack); | |
1827 | break; | |
bcf24348 JB |
1828 | case EVENT_DRIVER_CLIENT_POLL_OK: |
1829 | hostapd_client_poll_ok(hapd, data->client_poll.addr); | |
1830 | break; | |
f8b1f695 | 1831 | case EVENT_RX_FROM_UNKNOWN: |
9b90955e JB |
1832 | hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid, |
1833 | data->rx_from_unknown.addr, | |
1834 | data->rx_from_unknown.wds); | |
f8b1f695 | 1835 | break; |
dbfb8e82 | 1836 | #endif /* NEED_AP_MLME */ |
f8b1f695 | 1837 | case EVENT_RX_MGMT: |
c0333c8d JM |
1838 | if (!data->rx_mgmt.frame) |
1839 | break; | |
dbfb8e82 | 1840 | #ifdef NEED_AP_MLME |
4d379be4 JM |
1841 | hostapd_mgmt_rx(hapd, &data->rx_mgmt); |
1842 | #else /* NEED_AP_MLME */ | |
dbfb8e82 | 1843 | hostapd_action_rx(hapd, &data->rx_mgmt); |
4d379be4 | 1844 | #endif /* NEED_AP_MLME */ |
dbfb8e82 | 1845 | break; |
a0e0d3bb | 1846 | case EVENT_RX_PROBE_REQ: |
b211f3eb JM |
1847 | if (data->rx_probe_req.sa == NULL || |
1848 | data->rx_probe_req.ie == NULL) | |
1849 | break; | |
a0e0d3bb | 1850 | hostapd_probe_req_rx(hapd, data->rx_probe_req.sa, |
04a85e44 JM |
1851 | data->rx_probe_req.da, |
1852 | data->rx_probe_req.bssid, | |
a0e0d3bb | 1853 | data->rx_probe_req.ie, |
baf513d6 JB |
1854 | data->rx_probe_req.ie_len, |
1855 | data->rx_probe_req.ssi_signal); | |
a0e0d3bb | 1856 | break; |
a70a5d6d | 1857 | case EVENT_NEW_STA: |
a8e0505b JM |
1858 | hostapd_event_new_sta(hapd, data->new_sta.addr); |
1859 | break; | |
1860 | case EVENT_EAPOL_RX: | |
1861 | hostapd_event_eapol_rx(hapd, data->eapol_rx.src, | |
1862 | data->eapol_rx.data, | |
1863 | data->eapol_rx.data_len); | |
1864 | break; | |
1d041bec | 1865 | case EVENT_ASSOC: |
04a258e7 JM |
1866 | if (!data) |
1867 | return; | |
1d041bec JM |
1868 | hostapd_notif_assoc(hapd, data->assoc_info.addr, |
1869 | data->assoc_info.req_ies, | |
39b08b5f SP |
1870 | data->assoc_info.req_ies_len, |
1871 | data->assoc_info.reassoc); | |
1d041bec | 1872 | break; |
ef60f012 LD |
1873 | #ifdef CONFIG_OWE |
1874 | case EVENT_UPDATE_DH: | |
1875 | if (!data) | |
1876 | return; | |
1877 | hostapd_notif_update_dh_ie(hapd, data->update_dh.peer, | |
1878 | data->update_dh.ie, | |
1879 | data->update_dh.ie_len); | |
1880 | break; | |
1881 | #endif /* CONFIG_OWE */ | |
1d041bec JM |
1882 | case EVENT_DISASSOC: |
1883 | if (data) | |
1884 | hostapd_notif_disassoc(hapd, data->disassoc_info.addr); | |
1885 | break; | |
1886 | case EVENT_DEAUTH: | |
1887 | if (data) | |
1888 | hostapd_notif_disassoc(hapd, data->deauth_info.addr); | |
1889 | break; | |
0d7e5a3a JB |
1890 | case EVENT_STATION_LOW_ACK: |
1891 | if (!data) | |
1892 | break; | |
1893 | hostapd_event_sta_low_ack(hapd, data->low_ack.addr); | |
1894 | break; | |
88b32a99 SP |
1895 | case EVENT_AUTH: |
1896 | hostapd_notif_auth(hapd, &data->auth); | |
1897 | break; | |
95f556f3 | 1898 | case EVENT_CH_SWITCH_STARTED: |
1b487b8b TP |
1899 | case EVENT_CH_SWITCH: |
1900 | if (!data) | |
1901 | break; | |
1902 | hostapd_event_ch_switch(hapd, data->ch_switch.freq, | |
1903 | data->ch_switch.ht_enabled, | |
8d1fdde7 JD |
1904 | data->ch_switch.ch_offset, |
1905 | data->ch_switch.ch_width, | |
1906 | data->ch_switch.cf1, | |
95f556f3 OD |
1907 | data->ch_switch.cf2, |
1908 | event == EVENT_CH_SWITCH); | |
1b487b8b | 1909 | break; |
3140803b RM |
1910 | case EVENT_CONNECT_FAILED_REASON: |
1911 | if (!data) | |
1912 | break; | |
1913 | hostapd_event_connect_failed_reason( | |
1914 | hapd, data->connect_failed_reason.addr, | |
1915 | data->connect_failed_reason.code); | |
1916 | break; | |
0185007c | 1917 | case EVENT_SURVEY: |
96bc5086 | 1918 | hostapd_event_get_survey(hapd->iface, &data->survey_results); |
0185007c | 1919 | break; |
e76da505 | 1920 | #ifdef NEED_AP_MLME |
5841958f MK |
1921 | case EVENT_INTERFACE_UNAVAILABLE: |
1922 | hostapd_event_iface_unavailable(hapd); | |
1923 | break; | |
e76da505 JD |
1924 | case EVENT_DFS_RADAR_DETECTED: |
1925 | if (!data) | |
1926 | break; | |
1927 | hostapd_event_dfs_radar_detected(hapd, &data->dfs_event); | |
1928 | break; | |
7cbb5f1a VT |
1929 | case EVENT_DFS_PRE_CAC_EXPIRED: |
1930 | if (!data) | |
1931 | break; | |
1932 | hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event); | |
1933 | break; | |
e76da505 JD |
1934 | case EVENT_DFS_CAC_FINISHED: |
1935 | if (!data) | |
1936 | break; | |
1937 | hostapd_event_dfs_cac_finished(hapd, &data->dfs_event); | |
1938 | break; | |
1939 | case EVENT_DFS_CAC_ABORTED: | |
1940 | if (!data) | |
1941 | break; | |
1942 | hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event); | |
1943 | break; | |
1944 | case EVENT_DFS_NOP_FINISHED: | |
1945 | if (!data) | |
1946 | break; | |
1947 | hostapd_event_dfs_nop_finished(hapd, &data->dfs_event); | |
1948 | break; | |
1949 | case EVENT_CHANNEL_LIST_CHANGED: | |
1950 | /* channel list changed (regulatory?), update channel list */ | |
1951 | /* TODO: check this. hostapd_get_hw_features() initializes | |
1952 | * too much stuff. */ | |
1953 | /* hostapd_get_hw_features(hapd->iface); */ | |
795baf77 AS |
1954 | hostapd_channel_list_updated( |
1955 | hapd->iface, data->channel_list_changed.initiator); | |
e76da505 | 1956 | break; |
c13578c3 AK |
1957 | case EVENT_DFS_CAC_STARTED: |
1958 | if (!data) | |
1959 | break; | |
1960 | hostapd_event_dfs_cac_started(hapd, &data->dfs_event); | |
1961 | break; | |
e76da505 | 1962 | #endif /* NEED_AP_MLME */ |
ab93fdeb JM |
1963 | case EVENT_INTERFACE_ENABLED: |
1964 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED); | |
f33c8606 JM |
1965 | if (hapd->disabled && hapd->started) { |
1966 | hapd->disabled = 0; | |
1967 | /* | |
1968 | * Try to re-enable interface if the driver stopped it | |
1969 | * when the interface got disabled. | |
1970 | */ | |
567df550 HW |
1971 | if (hapd->wpa_auth) |
1972 | wpa_auth_reconfig_group_keys(hapd->wpa_auth); | |
1973 | else | |
1974 | hostapd_reconfig_encryption(hapd); | |
f33c8606 JM |
1975 | hapd->reenable_beacon = 1; |
1976 | ieee802_11_set_beacon(hapd); | |
10de40c0 ZK |
1977 | #ifdef NEED_AP_MLME |
1978 | } else if (hapd->disabled && hapd->iface->cac_started) { | |
1979 | wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC"); | |
1980 | hostapd_handle_dfs(hapd->iface); | |
1981 | #endif /* NEED_AP_MLME */ | |
f33c8606 | 1982 | } |
ab93fdeb JM |
1983 | break; |
1984 | case EVENT_INTERFACE_DISABLED: | |
c165cb40 | 1985 | hostapd_free_stas(hapd); |
ab93fdeb | 1986 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED); |
f33c8606 | 1987 | hapd->disabled = 1; |
ab93fdeb | 1988 | break; |
16689c7c PX |
1989 | #ifdef CONFIG_ACS |
1990 | case EVENT_ACS_CHANNEL_SELECTED: | |
857d9422 MM |
1991 | hostapd_acs_channel_selected(hapd, |
1992 | &data->acs_selected_channels); | |
16689c7c PX |
1993 | break; |
1994 | #endif /* CONFIG_ACS */ | |
ec2b5173 T |
1995 | case EVENT_STATION_OPMODE_CHANGED: |
1996 | hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr, | |
1997 | data->sta_opmode.smps_mode, | |
1998 | data->sta_opmode.chan_width, | |
1999 | data->sta_opmode.rx_nss); | |
2000 | break; | |
1952b626 BP |
2001 | case EVENT_WDS_STA_INTERFACE_STATUS: |
2002 | hostapd_event_wds_sta_interface_status( | |
2003 | hapd, data->wds_sta_interface.istatus, | |
2004 | data->wds_sta_interface.ifname, | |
2005 | data->wds_sta_interface.sta_addr); | |
2006 | break; | |
ad1e68e6 JM |
2007 | default: |
2008 | wpa_printf(MSG_DEBUG, "Unknown event %d", event); | |
2009 | break; | |
2010 | } | |
2011 | } | |
f8b1f695 | 2012 | |
45e3fc72 RM |
2013 | |
2014 | void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event, | |
2015 | union wpa_event_data *data) | |
2016 | { | |
2017 | struct hapd_interfaces *interfaces = ctx; | |
2018 | struct hostapd_data *hapd; | |
2019 | ||
2020 | if (event != EVENT_INTERFACE_STATUS) | |
2021 | return; | |
2022 | ||
2023 | hapd = hostapd_get_iface(interfaces, data->interface_status.ifname); | |
2024 | if (hapd && hapd->driver && hapd->driver->get_ifindex && | |
2025 | hapd->drv_priv) { | |
2026 | unsigned int ifindex; | |
2027 | ||
2028 | ifindex = hapd->driver->get_ifindex(hapd->drv_priv); | |
2029 | if (ifindex != data->interface_status.ifindex) { | |
2030 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, | |
2031 | "interface status ifindex %d mismatch (%d)", | |
2032 | ifindex, data->interface_status.ifindex); | |
2033 | return; | |
2034 | } | |
2035 | } | |
2036 | if (hapd) | |
2037 | wpa_supplicant_event(hapd, event, data); | |
2038 | } | |
2039 | ||
f8b1f695 | 2040 | #endif /* HOSTAPD */ |