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