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