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