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; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 120 | u16 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; |
| 609 | |
| 610 | npos = owe_assoc_req_process(hapd, sta, |
| 611 | elems.owe_dh, elems.owe_dh_len, |
| 612 | p, sizeof(buf) - (p - buf), |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 613 | &status); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 614 | if (npos) |
| 615 | p = npos; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 616 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 617 | if (!npos && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 618 | status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 619 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, |
| 620 | p - buf); |
| 621 | return 0; |
| 622 | } |
| 623 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 624 | if (!npos || status != WLAN_STATUS_SUCCESS) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 625 | goto fail; |
| 626 | } |
| 627 | #endif /* CONFIG_OWE */ |
| 628 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 629 | #ifdef CONFIG_DPP2 |
| 630 | dpp_pfs_free(sta->dpp_pfs); |
| 631 | sta->dpp_pfs = NULL; |
| 632 | |
| 633 | if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) && |
| 634 | hapd->conf->dpp_netaccesskey && sta->wpa_sm && |
| 635 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP && |
| 636 | elems.owe_dh) { |
| 637 | sta->dpp_pfs = dpp_pfs_init( |
| 638 | wpabuf_head(hapd->conf->dpp_netaccesskey), |
| 639 | wpabuf_len(hapd->conf->dpp_netaccesskey)); |
| 640 | if (!sta->dpp_pfs) { |
| 641 | wpa_printf(MSG_DEBUG, |
| 642 | "DPP: Could not initialize PFS"); |
| 643 | /* Try to continue without PFS */ |
| 644 | goto pfs_fail; |
| 645 | } |
| 646 | |
| 647 | if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh, |
| 648 | elems.owe_dh_len) < 0) { |
| 649 | dpp_pfs_free(sta->dpp_pfs); |
| 650 | sta->dpp_pfs = NULL; |
| 651 | reason = WLAN_REASON_UNSPECIFIED; |
| 652 | goto fail; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ? |
| 657 | sta->dpp_pfs->secret : NULL); |
| 658 | pfs_fail: |
| 659 | #endif /* CONFIG_DPP2 */ |
| 660 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 661 | if (elems.rrm_enabled && |
| 662 | elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa)) |
| 663 | os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled, |
| 664 | sizeof(sta->rrm_enabled_capa)); |
| 665 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 666 | #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 667 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 668 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 669 | if (sta->auth_alg == WLAN_AUTH_FT || |
| 670 | sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 671 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 672 | sta->auth_alg == WLAN_AUTH_FILS_PK) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 673 | ap_sta_set_authorized(hapd, sta, 1); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 674 | #else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 675 | /* Keep compiler silent about unused variables */ |
| 676 | if (status) { |
| 677 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 678 | #endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 679 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 680 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; |
| 681 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 682 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 683 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 684 | hostapd_set_sta_flags(hapd, sta); |
| 685 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 686 | if (reassoc && (sta->auth_alg == WLAN_AUTH_FT)) |
| 687 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 688 | #ifdef CONFIG_FILS |
| 689 | else if (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 690 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 691 | sta->auth_alg == WLAN_AUTH_FILS_PK) |
| 692 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS); |
| 693 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 694 | else |
| 695 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 696 | |
| 697 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); |
| 698 | |
| 699 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); |
| 700 | |
| 701 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 702 | if (req_ies) { |
| 703 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, |
| 704 | req_ies, req_ies_len); |
| 705 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 706 | #endif /* CONFIG_P2P */ |
| 707 | |
| 708 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 709 | |
| 710 | fail: |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 711 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 712 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 713 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 714 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); |
| 715 | ap_free_sta(hapd, sta); |
| 716 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | |
| 720 | void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr) |
| 721 | { |
| 722 | struct sta_info *sta; |
| 723 | |
| 724 | if (addr == NULL) { |
| 725 | /* |
| 726 | * This could potentially happen with unexpected event from the |
| 727 | * driver wrapper. This was seen at least in one case where the |
| 728 | * driver ended up reporting a station mode event while hostapd |
| 729 | * was running, so better make sure we stop processing such an |
| 730 | * event here. |
| 731 | */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 732 | wpa_printf(MSG_DEBUG, |
| 733 | "hostapd_notif_disassoc: Skip event with no address"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 734 | return; |
| 735 | } |
| 736 | |
| 737 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
| 738 | HOSTAPD_LEVEL_INFO, "disassociated"); |
| 739 | |
| 740 | sta = ap_get_sta(hapd, addr); |
| 741 | if (sta == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 742 | wpa_printf(MSG_DEBUG, |
| 743 | "Disassociation notification for unknown STA " |
| 744 | MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 745 | return; |
| 746 | } |
| 747 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 748 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 749 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 750 | hostapd_set_sta_flags(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 751 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); |
| 752 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 753 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 754 | ap_free_sta(hapd, sta); |
| 755 | } |
| 756 | |
| 757 | |
| 758 | void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr) |
| 759 | { |
| 760 | struct sta_info *sta = ap_get_sta(hapd, addr); |
| 761 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 762 | if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 763 | return; |
| 764 | |
| 765 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 766 | HOSTAPD_LEVEL_INFO, |
| 767 | "disconnected due to excessive missing ACKs"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 768 | hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 769 | ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 773 | void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr, |
| 774 | enum smps_mode smps_mode, |
| 775 | enum chan_width chan_width, u8 rx_nss) |
| 776 | { |
| 777 | struct sta_info *sta = ap_get_sta(hapd, addr); |
| 778 | const char *txt; |
| 779 | |
| 780 | if (!sta) |
| 781 | return; |
| 782 | |
| 783 | switch (smps_mode) { |
| 784 | case SMPS_AUTOMATIC: |
| 785 | txt = "automatic"; |
| 786 | break; |
| 787 | case SMPS_OFF: |
| 788 | txt = "off"; |
| 789 | break; |
| 790 | case SMPS_DYNAMIC: |
| 791 | txt = "dynamic"; |
| 792 | break; |
| 793 | case SMPS_STATIC: |
| 794 | txt = "static"; |
| 795 | break; |
| 796 | default: |
| 797 | txt = NULL; |
| 798 | break; |
| 799 | } |
| 800 | if (txt) { |
| 801 | wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED |
| 802 | MACSTR " %s", MAC2STR(addr), txt); |
| 803 | } |
| 804 | |
| 805 | switch (chan_width) { |
| 806 | case CHAN_WIDTH_20_NOHT: |
| 807 | txt = "20(no-HT)"; |
| 808 | break; |
| 809 | case CHAN_WIDTH_20: |
| 810 | txt = "20"; |
| 811 | break; |
| 812 | case CHAN_WIDTH_40: |
| 813 | txt = "40"; |
| 814 | break; |
| 815 | case CHAN_WIDTH_80: |
| 816 | txt = "80"; |
| 817 | break; |
| 818 | case CHAN_WIDTH_80P80: |
| 819 | txt = "80+80"; |
| 820 | break; |
| 821 | case CHAN_WIDTH_160: |
| 822 | txt = "160"; |
| 823 | break; |
| 824 | default: |
| 825 | txt = NULL; |
| 826 | break; |
| 827 | } |
| 828 | if (txt) { |
| 829 | wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED |
| 830 | MACSTR " %s", MAC2STR(addr), txt); |
| 831 | } |
| 832 | |
| 833 | if (rx_nss != 0xff) { |
| 834 | wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED |
| 835 | MACSTR " %d", MAC2STR(addr), rx_nss); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 840 | 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] | 841 | int offset, int width, int cf1, int cf2, |
| 842 | int finished) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 843 | { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 844 | /* TODO: If OCV is enabled deauth STAs that don't perform a SA Query */ |
| 845 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 846 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 847 | int channel, chwidth, is_dfs; |
| 848 | u8 seg0_idx = 0, seg1_idx = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 849 | size_t i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 850 | |
| 851 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 852 | HOSTAPD_LEVEL_INFO, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 853 | "driver %s channel switch: freq=%d, ht=%d, vht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d", |
| 854 | finished ? "had" : "starting", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 855 | freq, ht, hapd->iconf->ch_switch_vht_config, offset, |
| 856 | width, channel_width_to_string(width), cf1, cf2); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 857 | |
Hai Shalom | 1dc4d20 | 2019-04-29 16:22:27 -0700 | [diff] [blame] | 858 | if (!hapd->iface->current_mode) { |
| 859 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 860 | HOSTAPD_LEVEL_WARNING, |
| 861 | "ignore channel switch since the interface is not yet ready"); |
| 862 | return; |
| 863 | } |
| 864 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 865 | hapd->iface->freq = freq; |
| 866 | |
| 867 | channel = hostapd_hw_get_channel(hapd, freq); |
| 868 | if (!channel) { |
| 869 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 870 | HOSTAPD_LEVEL_WARNING, |
| 871 | "driver switched to bad channel!"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 872 | return; |
| 873 | } |
| 874 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 875 | switch (width) { |
| 876 | case CHAN_WIDTH_80: |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 877 | chwidth = CHANWIDTH_80MHZ; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 878 | break; |
| 879 | case CHAN_WIDTH_80P80: |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 880 | chwidth = CHANWIDTH_80P80MHZ; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 881 | break; |
| 882 | case CHAN_WIDTH_160: |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 883 | chwidth = CHANWIDTH_160MHZ; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 884 | break; |
| 885 | case CHAN_WIDTH_20_NOHT: |
| 886 | case CHAN_WIDTH_20: |
| 887 | case CHAN_WIDTH_40: |
| 888 | default: |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 889 | chwidth = CHANWIDTH_USE_HT; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 890 | break; |
| 891 | } |
| 892 | |
| 893 | switch (hapd->iface->current_mode->mode) { |
| 894 | case HOSTAPD_MODE_IEEE80211A: |
| 895 | if (cf1 > 5000) |
| 896 | seg0_idx = (cf1 - 5000) / 5; |
| 897 | if (cf2 > 5000) |
| 898 | seg1_idx = (cf2 - 5000) / 5; |
| 899 | break; |
| 900 | default: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 901 | ieee80211_freq_to_chan(cf1, &seg0_idx); |
| 902 | ieee80211_freq_to_chan(cf2, &seg1_idx); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 903 | break; |
| 904 | } |
| 905 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 906 | hapd->iconf->channel = channel; |
| 907 | hapd->iconf->ieee80211n = ht; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 908 | if (!ht) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 909 | hapd->iconf->ieee80211ac = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 910 | } else if (hapd->iconf->ch_switch_vht_config) { |
| 911 | /* CHAN_SWITCH VHT config */ |
| 912 | if (hapd->iconf->ch_switch_vht_config & |
| 913 | CH_SWITCH_VHT_ENABLED) |
| 914 | hapd->iconf->ieee80211ac = 1; |
| 915 | else if (hapd->iconf->ch_switch_vht_config & |
| 916 | CH_SWITCH_VHT_DISABLED) |
| 917 | hapd->iconf->ieee80211ac = 0; |
| 918 | } |
| 919 | hapd->iconf->ch_switch_vht_config = 0; |
| 920 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 921 | hapd->iconf->secondary_channel = offset; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 922 | hostapd_set_oper_chwidth(hapd->iconf, chwidth); |
| 923 | hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx); |
| 924 | hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 925 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 926 | is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features, |
| 927 | hapd->iface->num_hw_features); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 928 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 929 | wpa_msg(hapd->msg_ctx, MSG_INFO, |
| 930 | "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d dfs=%d", |
| 931 | finished ? WPA_EVENT_CHANNEL_SWITCH : |
| 932 | WPA_EVENT_CHANNEL_SWITCH_STARTED, |
| 933 | freq, ht, offset, channel_width_to_string(width), |
| 934 | cf1, cf2, is_dfs); |
| 935 | if (!finished) |
| 936 | return; |
| 937 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 938 | if (hapd->csa_in_progress && |
| 939 | freq == hapd->cs_freq_params.freq) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 940 | hostapd_cleanup_cs_params(hapd); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 941 | ieee802_11_set_beacon(hapd); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 942 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 943 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED |
| 944 | "freq=%d dfs=%d", freq, is_dfs); |
| 945 | } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) { |
| 946 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED |
| 947 | "freq=%d dfs=%d", freq, is_dfs); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 948 | } else if (is_dfs && |
| 949 | hostapd_is_dfs_required(hapd->iface) && |
| 950 | !hostapd_is_dfs_chan_available(hapd->iface) && |
| 951 | !hapd->iface->cac_started) { |
| 952 | hostapd_disable_iface(hapd->iface); |
| 953 | hostapd_enable_iface(hapd->iface); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 954 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 955 | |
| 956 | for (i = 0; i < hapd->iface->num_bss; i++) |
| 957 | hostapd_neighbor_set_own_report(hapd->iface->bss[i]); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 958 | #endif /* NEED_AP_MLME */ |
| 959 | } |
| 960 | |
| 961 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 962 | void hostapd_event_connect_failed_reason(struct hostapd_data *hapd, |
| 963 | const u8 *addr, int reason_code) |
| 964 | { |
| 965 | switch (reason_code) { |
| 966 | case MAX_CLIENT_REACHED: |
| 967 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR, |
| 968 | MAC2STR(addr)); |
| 969 | break; |
| 970 | case BLOCKED_CLIENT: |
| 971 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR, |
| 972 | MAC2STR(addr)); |
| 973 | break; |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 978 | #ifdef CONFIG_ACS |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 979 | void hostapd_acs_channel_selected(struct hostapd_data *hapd, |
| 980 | struct acs_selected_channels *acs_res) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 981 | { |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 982 | int ret, i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 983 | int err = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 984 | struct hostapd_channel_data *pri_chan; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 985 | |
| 986 | if (hapd->iconf->channel) { |
| 987 | wpa_printf(MSG_INFO, "ACS: Channel was already set to %d", |
| 988 | hapd->iconf->channel); |
| 989 | return; |
| 990 | } |
| 991 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 992 | hapd->iface->freq = acs_res->pri_freq; |
| 993 | |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 994 | if (!hapd->iface->current_mode) { |
| 995 | for (i = 0; i < hapd->iface->num_hw_features; i++) { |
| 996 | struct hostapd_hw_modes *mode = |
| 997 | &hapd->iface->hw_features[i]; |
| 998 | |
| 999 | if (mode->mode == acs_res->hw_mode) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1000 | if (hapd->iface->freq > 0 && |
| 1001 | !hw_get_chan(mode->mode, |
| 1002 | hapd->iface->freq, |
| 1003 | hapd->iface->hw_features, |
| 1004 | hapd->iface->num_hw_features)) |
| 1005 | continue; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 1006 | hapd->iface->current_mode = mode; |
| 1007 | break; |
| 1008 | } |
| 1009 | } |
| 1010 | if (!hapd->iface->current_mode) { |
| 1011 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 1012 | HOSTAPD_LEVEL_WARNING, |
| 1013 | "driver selected to bad hw_mode"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1014 | err = 1; |
| 1015 | goto out; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1019 | if (!acs_res->pri_freq) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1020 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 1021 | HOSTAPD_LEVEL_WARNING, |
| 1022 | "driver switched to bad channel"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1023 | err = 1; |
| 1024 | goto out; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1025 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1026 | pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode, |
| 1027 | acs_res->pri_freq, NULL, |
| 1028 | hapd->iface->hw_features, |
| 1029 | hapd->iface->num_hw_features); |
| 1030 | if (!pri_chan) { |
| 1031 | wpa_printf(MSG_ERROR, |
| 1032 | "ACS: Could not determine primary channel number from pri_freq %u", |
| 1033 | acs_res->pri_freq); |
| 1034 | err = 1; |
| 1035 | goto out; |
| 1036 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1037 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1038 | hapd->iconf->channel = pri_chan->chan; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1039 | hapd->iconf->acs = 1; |
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 | if (acs_res->sec_freq == 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1042 | hapd->iconf->secondary_channel = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1043 | else if (acs_res->sec_freq < acs_res->pri_freq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1044 | hapd->iconf->secondary_channel = -1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1045 | else if (acs_res->sec_freq > acs_res->pri_freq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1046 | hapd->iconf->secondary_channel = 1; |
| 1047 | else { |
| 1048 | wpa_printf(MSG_ERROR, "Invalid secondary channel!"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1049 | err = 1; |
| 1050 | goto out; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1053 | hapd->iconf->edmg_channel = acs_res->edmg_channel; |
| 1054 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1055 | if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) { |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1056 | /* set defaults for backwards compatibility */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1057 | hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0); |
| 1058 | hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0); |
| 1059 | hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_USE_HT); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1060 | if (acs_res->ch_width == 40) { |
| 1061 | if (is_6ghz_freq(acs_res->pri_freq)) |
| 1062 | hostapd_set_oper_centr_freq_seg0_idx( |
| 1063 | hapd->iconf, |
| 1064 | acs_res->vht_seg0_center_ch); |
| 1065 | } else if (acs_res->ch_width == 80) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1066 | hostapd_set_oper_centr_freq_seg0_idx( |
| 1067 | hapd->iconf, acs_res->vht_seg0_center_ch); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1068 | if (acs_res->vht_seg1_center_ch == 0) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1069 | hostapd_set_oper_chwidth(hapd->iconf, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1070 | CHANWIDTH_80MHZ); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1071 | } else { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1072 | hostapd_set_oper_chwidth(hapd->iconf, |
| 1073 | CHANWIDTH_80P80MHZ); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1074 | hostapd_set_oper_centr_freq_seg1_idx( |
| 1075 | hapd->iconf, |
| 1076 | acs_res->vht_seg1_center_ch); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1077 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1078 | } else if (acs_res->ch_width == 160) { |
| 1079 | hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_160MHZ); |
| 1080 | hostapd_set_oper_centr_freq_seg0_idx( |
| 1081 | hapd->iconf, acs_res->vht_seg1_center_ch); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1085 | out: |
| 1086 | ret = hostapd_acs_completed(hapd->iface, err); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1087 | if (ret) { |
| 1088 | wpa_printf(MSG_ERROR, |
| 1089 | "ACS: Possibly channel configuration is invalid"); |
| 1090 | } |
| 1091 | } |
| 1092 | #endif /* CONFIG_ACS */ |
| 1093 | |
| 1094 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1095 | 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] | 1096 | const u8 *bssid, const u8 *ie, size_t ie_len, |
| 1097 | int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1098 | { |
| 1099 | size_t i; |
| 1100 | int ret = 0; |
| 1101 | |
| 1102 | if (sa == NULL || ie == NULL) |
| 1103 | return -1; |
| 1104 | |
| 1105 | random_add_randomness(sa, ETH_ALEN); |
| 1106 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) { |
| 1107 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1108 | sa, da, bssid, ie, ie_len, |
| 1109 | ssi_signal) > 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1110 | ret = 1; |
| 1111 | break; |
| 1112 | } |
| 1113 | } |
| 1114 | return ret; |
| 1115 | } |
| 1116 | |
| 1117 | |
| 1118 | #ifdef HOSTAPD |
| 1119 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1120 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1121 | static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst, |
| 1122 | const u8 *bssid, |
| 1123 | u16 auth_transaction, u16 status, |
| 1124 | const u8 *ies, size_t ies_len) |
| 1125 | { |
| 1126 | struct hostapd_data *hapd = ctx; |
| 1127 | struct sta_info *sta; |
| 1128 | |
| 1129 | sta = ap_get_sta(hapd, dst); |
| 1130 | if (sta == NULL) |
| 1131 | return; |
| 1132 | |
| 1133 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, |
| 1134 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); |
| 1135 | sta->flags |= WLAN_STA_AUTH; |
| 1136 | |
| 1137 | hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len); |
| 1138 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1139 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1140 | |
| 1141 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1142 | #ifdef CONFIG_FILS |
| 1143 | static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd, |
| 1144 | struct sta_info *sta, u16 resp, |
| 1145 | struct wpabuf *data, int pub) |
| 1146 | { |
| 1147 | if (resp == WLAN_STATUS_SUCCESS) { |
| 1148 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1149 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)"); |
| 1150 | sta->flags |= WLAN_STA_AUTH; |
| 1151 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 1152 | sta->auth_alg = WLAN_AUTH_FILS_SK; |
| 1153 | mlme_authenticate_indication(hapd, sta); |
| 1154 | } else { |
| 1155 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1156 | HOSTAPD_LEVEL_DEBUG, |
| 1157 | "authentication failed (FILS)"); |
| 1158 | } |
| 1159 | |
| 1160 | hostapd_sta_auth(hapd, sta->addr, 2, resp, |
| 1161 | data ? wpabuf_head(data) : NULL, |
| 1162 | data ? wpabuf_len(data) : 0); |
| 1163 | wpabuf_free(data); |
| 1164 | } |
| 1165 | #endif /* CONFIG_FILS */ |
| 1166 | |
| 1167 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1168 | static void hostapd_notif_auth(struct hostapd_data *hapd, |
| 1169 | struct auth_info *rx_auth) |
| 1170 | { |
| 1171 | struct sta_info *sta; |
| 1172 | u16 status = WLAN_STATUS_SUCCESS; |
| 1173 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; |
| 1174 | size_t resp_ies_len = 0; |
| 1175 | |
| 1176 | sta = ap_get_sta(hapd, rx_auth->peer); |
| 1177 | if (!sta) { |
| 1178 | sta = ap_sta_add(hapd, rx_auth->peer); |
| 1179 | if (sta == NULL) { |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 1180 | status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1181 | goto fail; |
| 1182 | } |
| 1183 | } |
| 1184 | sta->flags &= ~WLAN_STA_PREAUTH; |
| 1185 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1186 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1187 | if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) { |
| 1188 | sta->auth_alg = WLAN_AUTH_FT; |
| 1189 | if (sta->wpa_sm == NULL) |
| 1190 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1191 | sta->addr, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1192 | if (sta->wpa_sm == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1193 | wpa_printf(MSG_DEBUG, |
| 1194 | "FT: Failed to initialize WPA state machine"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1195 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1196 | goto fail; |
| 1197 | } |
| 1198 | wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid, |
| 1199 | rx_auth->auth_transaction, rx_auth->ies, |
| 1200 | rx_auth->ies_len, |
| 1201 | hostapd_notify_auth_ft_finish, hapd); |
| 1202 | return; |
| 1203 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1204 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1205 | |
| 1206 | #ifdef CONFIG_FILS |
| 1207 | if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) { |
| 1208 | sta->auth_alg = WLAN_AUTH_FILS_SK; |
| 1209 | handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len, |
| 1210 | rx_auth->auth_type, rx_auth->auth_transaction, |
| 1211 | rx_auth->status_code, |
| 1212 | hostapd_notify_auth_fils_finish); |
| 1213 | return; |
| 1214 | } |
| 1215 | #endif /* CONFIG_FILS */ |
| 1216 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1217 | fail: |
| 1218 | hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1, |
| 1219 | status, resp_ies, resp_ies_len); |
| 1220 | } |
| 1221 | |
| 1222 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1223 | #ifndef NEED_AP_MLME |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1224 | static void hostapd_action_rx(struct hostapd_data *hapd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1225 | struct rx_mgmt *drv_mgmt) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1226 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1227 | struct ieee80211_mgmt *mgmt; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1228 | struct sta_info *sta; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1229 | size_t plen __maybe_unused; |
| 1230 | u16 fc; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1231 | u8 *action __maybe_unused; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1232 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1233 | if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1234 | return; |
| 1235 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1236 | plen = drv_mgmt->frame_len - IEEE80211_HDRLEN; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1237 | |
| 1238 | mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame; |
| 1239 | fc = le_to_host16(mgmt->frame_control); |
| 1240 | if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) |
| 1241 | return; /* handled by the driver */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1242 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1243 | action = (u8 *) &mgmt->u.action.u; |
| 1244 | wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR |
| 1245 | " da " MACSTR " plen %d", |
| 1246 | mgmt->u.action.category, *action, |
| 1247 | MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1248 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1249 | sta = ap_get_sta(hapd, mgmt->sa); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1250 | if (sta == NULL) { |
| 1251 | wpa_printf(MSG_DEBUG, "%s: station not found", __func__); |
| 1252 | return; |
| 1253 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1254 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1255 | if (mgmt->u.action.category == WLAN_ACTION_FT) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1256 | wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen); |
| 1257 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1258 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1259 | #endif /* CONFIG_IEEE80211R_AP */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1260 | if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1261 | ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1262 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1263 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1264 | #ifdef CONFIG_WNM_AP |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1265 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { |
| 1266 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1267 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1268 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1269 | #endif /* CONFIG_WNM_AP */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1270 | #ifdef CONFIG_FST |
| 1271 | if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) { |
| 1272 | fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len); |
| 1273 | return; |
| 1274 | } |
| 1275 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1276 | #ifdef CONFIG_DPP |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1277 | if (plen >= 2 + 4 && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1278 | mgmt->u.action.u.vs_public_action.action == |
| 1279 | WLAN_PA_VENDOR_SPECIFIC && |
| 1280 | WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) == |
| 1281 | OUI_WFA && |
| 1282 | mgmt->u.action.u.vs_public_action.variable[0] == |
| 1283 | DPP_OUI_TYPE) { |
| 1284 | const u8 *pos, *end; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1285 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1286 | pos = mgmt->u.action.u.vs_public_action.oui; |
| 1287 | end = drv_mgmt->frame + drv_mgmt->frame_len; |
| 1288 | hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos, |
| 1289 | drv_mgmt->freq); |
| 1290 | return; |
| 1291 | } |
| 1292 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1293 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1294 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1295 | |
| 1296 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1297 | #ifdef NEED_AP_MLME |
| 1298 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1299 | #define HAPD_BROADCAST ((struct hostapd_data *) -1) |
| 1300 | |
| 1301 | static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface, |
| 1302 | const u8 *bssid) |
| 1303 | { |
| 1304 | size_t i; |
| 1305 | |
| 1306 | if (bssid == NULL) |
| 1307 | return NULL; |
| 1308 | if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff && |
| 1309 | bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff) |
| 1310 | return HAPD_BROADCAST; |
| 1311 | |
| 1312 | for (i = 0; i < iface->num_bss; i++) { |
| 1313 | if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) |
| 1314 | return iface->bss[i]; |
| 1315 | } |
| 1316 | |
| 1317 | return NULL; |
| 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1322 | const u8 *bssid, const u8 *addr, |
| 1323 | int wds) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1324 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1325 | hapd = get_hapd_bssid(hapd->iface, bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1326 | if (hapd == NULL || hapd == HAPD_BROADCAST) |
| 1327 | return; |
| 1328 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1329 | ieee802_11_rx_from_unknown(hapd, addr, wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1333 | 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] | 1334 | { |
| 1335 | struct hostapd_iface *iface = hapd->iface; |
| 1336 | const struct ieee80211_hdr *hdr; |
| 1337 | const u8 *bssid; |
| 1338 | struct hostapd_frame_info fi; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1339 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1340 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 1341 | #ifdef CONFIG_TESTING_OPTIONS |
| 1342 | if (hapd->ext_mgmt_frame_handling) { |
| 1343 | size_t hex_len = 2 * rx_mgmt->frame_len + 1; |
| 1344 | char *hex = os_malloc(hex_len); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1345 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 1346 | if (hex) { |
| 1347 | wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame, |
| 1348 | rx_mgmt->frame_len); |
| 1349 | wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex); |
| 1350 | os_free(hex); |
| 1351 | } |
| 1352 | return 1; |
| 1353 | } |
| 1354 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1355 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1356 | hdr = (const struct ieee80211_hdr *) rx_mgmt->frame; |
| 1357 | bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len); |
| 1358 | if (bssid == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1359 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1360 | |
| 1361 | hapd = get_hapd_bssid(iface, bssid); |
| 1362 | if (hapd == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1363 | u16 fc = le_to_host16(hdr->frame_control); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1364 | |
| 1365 | /* |
| 1366 | * Drop frames to unknown BSSIDs except for Beacon frames which |
| 1367 | * could be used to update neighbor information. |
| 1368 | */ |
| 1369 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 1370 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) |
| 1371 | hapd = iface->bss[0]; |
| 1372 | else |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1373 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | os_memset(&fi, 0, sizeof(fi)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1377 | fi.freq = rx_mgmt->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1378 | fi.datarate = rx_mgmt->datarate; |
| 1379 | fi.ssi_signal = rx_mgmt->ssi_signal; |
| 1380 | |
| 1381 | if (hapd == HAPD_BROADCAST) { |
| 1382 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1383 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1384 | ret = 0; |
| 1385 | for (i = 0; i < iface->num_bss; i++) { |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1386 | /* if bss is set, driver will call this function for |
| 1387 | * each bss individually. */ |
| 1388 | if (rx_mgmt->drv_priv && |
| 1389 | (iface->bss[i]->drv_priv != rx_mgmt->drv_priv)) |
| 1390 | continue; |
| 1391 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1392 | if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame, |
| 1393 | rx_mgmt->frame_len, &fi) > 0) |
| 1394 | ret = 1; |
| 1395 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1396 | } else |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1397 | ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, |
| 1398 | &fi); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1399 | |
| 1400 | random_add_randomness(&fi, sizeof(fi)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1401 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1402 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1406 | static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf, |
| 1407 | size_t len, u16 stype, int ok) |
| 1408 | { |
| 1409 | struct ieee80211_hdr *hdr; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1410 | struct hostapd_data *orig_hapd = hapd; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1411 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1412 | hdr = (struct ieee80211_hdr *) buf; |
| 1413 | hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len)); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1414 | if (!hapd) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1415 | return; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1416 | if (hapd == HAPD_BROADCAST) { |
| 1417 | if (stype != WLAN_FC_STYPE_ACTION || len <= 25 || |
| 1418 | buf[24] != WLAN_ACTION_PUBLIC) |
| 1419 | return; |
| 1420 | hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2); |
| 1421 | if (!hapd || hapd == HAPD_BROADCAST) |
| 1422 | return; |
| 1423 | /* |
| 1424 | * Allow processing of TX status for a Public Action frame that |
| 1425 | * used wildcard BBSID. |
| 1426 | */ |
| 1427 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1428 | ieee802_11_mgmt_cb(hapd, buf, len, stype, ok); |
| 1429 | } |
| 1430 | |
| 1431 | #endif /* NEED_AP_MLME */ |
| 1432 | |
| 1433 | |
| 1434 | static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr) |
| 1435 | { |
| 1436 | struct sta_info *sta = ap_get_sta(hapd, addr); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1437 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1438 | if (sta) |
| 1439 | return 0; |
| 1440 | |
| 1441 | wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR |
| 1442 | " - adding a new STA", MAC2STR(addr)); |
| 1443 | sta = ap_sta_add(hapd, addr); |
| 1444 | if (sta) { |
| 1445 | hostapd_new_assoc_sta(hapd, sta, 0); |
| 1446 | } else { |
| 1447 | wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR, |
| 1448 | MAC2STR(addr)); |
| 1449 | return -1; |
| 1450 | } |
| 1451 | |
| 1452 | return 0; |
| 1453 | } |
| 1454 | |
| 1455 | |
| 1456 | static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, |
| 1457 | const u8 *data, size_t data_len) |
| 1458 | { |
| 1459 | struct hostapd_iface *iface = hapd->iface; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1460 | struct sta_info *sta; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1461 | size_t j; |
| 1462 | |
| 1463 | for (j = 0; j < iface->num_bss; j++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1464 | sta = ap_get_sta(iface->bss[j], src); |
| 1465 | if (sta && sta->flags & WLAN_STA_ASSOC) { |
| 1466 | hapd = iface->bss[j]; |
| 1467 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | ieee802_1x_receive(hapd, src, data, data_len); |
| 1472 | } |
| 1473 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 1474 | #endif /* HOSTAPD */ |
| 1475 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1476 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1477 | static struct hostapd_channel_data * |
| 1478 | hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq) |
| 1479 | { |
| 1480 | int i; |
| 1481 | struct hostapd_channel_data *chan; |
| 1482 | |
| 1483 | for (i = 0; i < mode->num_channels; i++) { |
| 1484 | chan = &mode->channels[i]; |
| 1485 | if ((unsigned int) chan->freq == freq) |
| 1486 | return chan; |
| 1487 | } |
| 1488 | |
| 1489 | return NULL; |
| 1490 | } |
| 1491 | |
| 1492 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1493 | static struct hostapd_channel_data * hostapd_get_mode_channel( |
| 1494 | struct hostapd_iface *iface, unsigned int freq) |
| 1495 | { |
| 1496 | int i; |
| 1497 | struct hostapd_channel_data *chan; |
| 1498 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1499 | for (i = 0; i < iface->num_hw_features; i++) { |
| 1500 | if (hostapd_hw_skip_mode(iface, &iface->hw_features[i])) |
| 1501 | continue; |
| 1502 | chan = hostapd_get_mode_chan(&iface->hw_features[i], freq); |
| 1503 | if (chan) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1504 | return chan; |
| 1505 | } |
| 1506 | |
| 1507 | return NULL; |
| 1508 | } |
| 1509 | |
| 1510 | |
| 1511 | static void hostapd_update_nf(struct hostapd_iface *iface, |
| 1512 | struct hostapd_channel_data *chan, |
| 1513 | struct freq_survey *survey) |
| 1514 | { |
| 1515 | if (!iface->chans_surveyed) { |
| 1516 | chan->min_nf = survey->nf; |
| 1517 | iface->lowest_nf = survey->nf; |
| 1518 | } else { |
| 1519 | if (dl_list_empty(&chan->survey_list)) |
| 1520 | chan->min_nf = survey->nf; |
| 1521 | else if (survey->nf < chan->min_nf) |
| 1522 | chan->min_nf = survey->nf; |
| 1523 | if (survey->nf < iface->lowest_nf) |
| 1524 | iface->lowest_nf = survey->nf; |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1529 | static void hostapd_single_channel_get_survey(struct hostapd_iface *iface, |
| 1530 | struct survey_results *survey_res) |
| 1531 | { |
| 1532 | struct hostapd_channel_data *chan; |
| 1533 | struct freq_survey *survey; |
| 1534 | u64 divisor, dividend; |
| 1535 | |
| 1536 | survey = dl_list_first(&survey_res->survey_list, struct freq_survey, |
| 1537 | list); |
| 1538 | if (!survey || !survey->freq) |
| 1539 | return; |
| 1540 | |
| 1541 | chan = hostapd_get_mode_channel(iface, survey->freq); |
| 1542 | if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED) |
| 1543 | return; |
| 1544 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1545 | wpa_printf(MSG_DEBUG, |
| 1546 | "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1547 | survey->freq, |
| 1548 | (unsigned long int) survey->channel_time, |
| 1549 | (unsigned long int) survey->channel_time_busy); |
| 1550 | |
| 1551 | if (survey->channel_time > iface->last_channel_time && |
| 1552 | survey->channel_time > survey->channel_time_busy) { |
| 1553 | dividend = survey->channel_time_busy - |
| 1554 | iface->last_channel_time_busy; |
| 1555 | divisor = survey->channel_time - iface->last_channel_time; |
| 1556 | |
| 1557 | iface->channel_utilization = dividend * 255 / divisor; |
| 1558 | wpa_printf(MSG_DEBUG, "Channel Utilization: %d", |
| 1559 | iface->channel_utilization); |
| 1560 | } |
| 1561 | iface->last_channel_time = survey->channel_time; |
| 1562 | iface->last_channel_time_busy = survey->channel_time_busy; |
| 1563 | } |
| 1564 | |
| 1565 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 1566 | void hostapd_event_get_survey(struct hostapd_iface *iface, |
| 1567 | struct survey_results *survey_results) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1568 | { |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1569 | struct freq_survey *survey, *tmp; |
| 1570 | struct hostapd_channel_data *chan; |
| 1571 | |
| 1572 | if (dl_list_empty(&survey_results->survey_list)) { |
| 1573 | wpa_printf(MSG_DEBUG, "No survey data received"); |
| 1574 | return; |
| 1575 | } |
| 1576 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1577 | if (survey_results->freq_filter) { |
| 1578 | hostapd_single_channel_get_survey(iface, survey_results); |
| 1579 | return; |
| 1580 | } |
| 1581 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1582 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 1583 | struct freq_survey, list) { |
| 1584 | chan = hostapd_get_mode_channel(iface, survey->freq); |
| 1585 | if (!chan) |
| 1586 | continue; |
| 1587 | if (chan->flag & HOSTAPD_CHAN_DISABLED) |
| 1588 | continue; |
| 1589 | |
| 1590 | dl_list_del(&survey->list); |
| 1591 | dl_list_add_tail(&chan->survey_list, &survey->list); |
| 1592 | |
| 1593 | hostapd_update_nf(iface, chan, survey); |
| 1594 | |
| 1595 | iface->chans_surveyed++; |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 1600 | #ifdef HOSTAPD |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1601 | #ifdef NEED_AP_MLME |
| 1602 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 1603 | static void hostapd_event_iface_unavailable(struct hostapd_data *hapd) |
| 1604 | { |
| 1605 | wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped", |
| 1606 | hapd->conf->iface); |
| 1607 | |
| 1608 | if (hapd->csa_in_progress) { |
| 1609 | wpa_printf(MSG_INFO, "CSA failed (%s was stopped)", |
| 1610 | hapd->conf->iface); |
| 1611 | hostapd_switch_channel_fallback(hapd->iface, |
| 1612 | &hapd->cs_freq_params); |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1617 | static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd, |
| 1618 | struct dfs_event *radar) |
| 1619 | { |
| 1620 | wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1621 | hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1622 | radar->chan_offset, radar->chan_width, |
| 1623 | radar->cf1, radar->cf2); |
| 1624 | } |
| 1625 | |
| 1626 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1627 | static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd, |
| 1628 | struct dfs_event *radar) |
| 1629 | { |
| 1630 | wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq); |
| 1631 | hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled, |
| 1632 | radar->chan_offset, radar->chan_width, |
| 1633 | radar->cf1, radar->cf2); |
| 1634 | } |
| 1635 | |
| 1636 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1637 | static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd, |
| 1638 | struct dfs_event *radar) |
| 1639 | { |
| 1640 | wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1641 | hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1642 | radar->chan_offset, radar->chan_width, |
| 1643 | radar->cf1, radar->cf2); |
| 1644 | } |
| 1645 | |
| 1646 | |
| 1647 | static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd, |
| 1648 | struct dfs_event *radar) |
| 1649 | { |
| 1650 | wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1651 | hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1652 | radar->chan_offset, radar->chan_width, |
| 1653 | radar->cf1, radar->cf2); |
| 1654 | } |
| 1655 | |
| 1656 | |
| 1657 | static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd, |
| 1658 | struct dfs_event *radar) |
| 1659 | { |
| 1660 | wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1661 | hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1662 | radar->chan_offset, radar->chan_width, |
| 1663 | radar->cf1, radar->cf2); |
| 1664 | } |
| 1665 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1666 | |
| 1667 | static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd, |
| 1668 | struct dfs_event *radar) |
| 1669 | { |
| 1670 | wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq); |
| 1671 | hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled, |
| 1672 | radar->chan_offset, radar->chan_width, |
| 1673 | radar->cf1, radar->cf2); |
| 1674 | } |
| 1675 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1676 | #endif /* NEED_AP_MLME */ |
| 1677 | |
| 1678 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1679 | static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd, |
| 1680 | int istatus, |
| 1681 | const char *ifname, |
| 1682 | const u8 *addr) |
| 1683 | { |
| 1684 | struct sta_info *sta = ap_get_sta(hapd, addr); |
| 1685 | |
| 1686 | if (sta) { |
| 1687 | os_free(sta->ifname_wds); |
| 1688 | if (istatus == INTERFACE_ADDED) |
| 1689 | sta->ifname_wds = os_strdup(ifname); |
| 1690 | else |
| 1691 | sta->ifname_wds = NULL; |
| 1692 | } |
| 1693 | |
| 1694 | wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR, |
| 1695 | istatus == INTERFACE_ADDED ? |
| 1696 | WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED, |
| 1697 | ifname, MAC2STR(addr)); |
| 1698 | } |
| 1699 | |
| 1700 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1701 | #ifdef CONFIG_OWE |
| 1702 | static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd, |
| 1703 | const u8 *peer, const u8 *ie, |
| 1704 | size_t ie_len) |
| 1705 | { |
| 1706 | u16 status; |
| 1707 | struct sta_info *sta; |
| 1708 | struct ieee802_11_elems elems; |
| 1709 | |
| 1710 | if (!hapd || !hapd->wpa_auth) { |
| 1711 | wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context"); |
| 1712 | return -1; |
| 1713 | } |
| 1714 | if (!peer) { |
| 1715 | wpa_printf(MSG_DEBUG, "OWE: Peer unknown"); |
| 1716 | return -1; |
| 1717 | } |
| 1718 | if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) { |
| 1719 | wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured"); |
| 1720 | status = WLAN_STATUS_AKMP_NOT_VALID; |
| 1721 | goto err; |
| 1722 | } |
| 1723 | if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) { |
| 1724 | wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for " |
| 1725 | MACSTR, MAC2STR(peer)); |
| 1726 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1727 | goto err; |
| 1728 | } |
| 1729 | status = owe_validate_request(hapd, peer, elems.rsn_ie, |
| 1730 | elems.rsn_ie_len, |
| 1731 | elems.owe_dh, elems.owe_dh_len); |
| 1732 | if (status != WLAN_STATUS_SUCCESS) |
| 1733 | goto err; |
| 1734 | |
| 1735 | sta = ap_get_sta(hapd, peer); |
| 1736 | if (sta) { |
| 1737 | ap_sta_no_session_timeout(hapd, sta); |
| 1738 | accounting_sta_stop(hapd, sta); |
| 1739 | |
| 1740 | /* |
| 1741 | * Make sure that the previously registered inactivity timer |
| 1742 | * will not remove the STA immediately. |
| 1743 | */ |
| 1744 | sta->timeout_next = STA_NULLFUNC; |
| 1745 | } else { |
| 1746 | sta = ap_sta_add(hapd, peer); |
| 1747 | if (!sta) { |
| 1748 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1749 | goto err; |
| 1750 | } |
| 1751 | } |
| 1752 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
| 1753 | |
| 1754 | status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie, |
| 1755 | elems.rsn_ie_len, elems.owe_dh, |
| 1756 | elems.owe_dh_len); |
| 1757 | if (status != WLAN_STATUS_SUCCESS) |
| 1758 | ap_free_sta(hapd, sta); |
| 1759 | |
| 1760 | return 0; |
| 1761 | err: |
| 1762 | hostapd_drv_update_dh_ie(hapd, peer, status, NULL, 0); |
| 1763 | return 0; |
| 1764 | } |
| 1765 | #endif /* CONFIG_OWE */ |
| 1766 | |
| 1767 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1768 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
| 1769 | union wpa_event_data *data) |
| 1770 | { |
| 1771 | struct hostapd_data *hapd = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1772 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 1773 | int level = MSG_DEBUG; |
| 1774 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1775 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1776 | data->rx_mgmt.frame_len >= 24) { |
| 1777 | const struct ieee80211_hdr *hdr; |
| 1778 | u16 fc; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1779 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1780 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; |
| 1781 | fc = le_to_host16(hdr->frame_control); |
| 1782 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 1783 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) |
| 1784 | level = MSG_EXCESSIVE; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1785 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 1786 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ) |
| 1787 | level = MSG_EXCESSIVE; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received", |
| 1791 | event_to_string(event), event); |
| 1792 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1793 | |
| 1794 | switch (event) { |
| 1795 | case EVENT_MICHAEL_MIC_FAILURE: |
| 1796 | michael_mic_failure(hapd, data->michael_mic_failure.src, 1); |
| 1797 | break; |
| 1798 | case EVENT_SCAN_RESULTS: |
| 1799 | if (hapd->iface->scan_cb) |
| 1800 | hapd->iface->scan_cb(hapd->iface); |
| 1801 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1802 | case EVENT_WPS_BUTTON_PUSHED: |
| 1803 | hostapd_wps_button_pushed(hapd, NULL); |
| 1804 | break; |
| 1805 | #ifdef NEED_AP_MLME |
| 1806 | case EVENT_TX_STATUS: |
| 1807 | switch (data->tx_status.type) { |
| 1808 | case WLAN_FC_TYPE_MGMT: |
| 1809 | hostapd_mgmt_tx_cb(hapd, data->tx_status.data, |
| 1810 | data->tx_status.data_len, |
| 1811 | data->tx_status.stype, |
| 1812 | data->tx_status.ack); |
| 1813 | break; |
| 1814 | case WLAN_FC_TYPE_DATA: |
| 1815 | hostapd_tx_status(hapd, data->tx_status.dst, |
| 1816 | data->tx_status.data, |
| 1817 | data->tx_status.data_len, |
| 1818 | data->tx_status.ack); |
| 1819 | break; |
| 1820 | } |
| 1821 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1822 | case EVENT_EAPOL_TX_STATUS: |
| 1823 | hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst, |
| 1824 | data->eapol_tx_status.data, |
| 1825 | data->eapol_tx_status.data_len, |
| 1826 | data->eapol_tx_status.ack); |
| 1827 | break; |
| 1828 | case EVENT_DRIVER_CLIENT_POLL_OK: |
| 1829 | hostapd_client_poll_ok(hapd, data->client_poll.addr); |
| 1830 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1831 | case EVENT_RX_FROM_UNKNOWN: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1832 | hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid, |
| 1833 | data->rx_from_unknown.addr, |
| 1834 | data->rx_from_unknown.wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1835 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1836 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1837 | case EVENT_RX_MGMT: |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1838 | if (!data->rx_mgmt.frame) |
| 1839 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1840 | #ifdef NEED_AP_MLME |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1841 | hostapd_mgmt_rx(hapd, &data->rx_mgmt); |
| 1842 | #else /* NEED_AP_MLME */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1843 | hostapd_action_rx(hapd, &data->rx_mgmt); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1844 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1845 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1846 | case EVENT_RX_PROBE_REQ: |
| 1847 | if (data->rx_probe_req.sa == NULL || |
| 1848 | data->rx_probe_req.ie == NULL) |
| 1849 | break; |
| 1850 | hostapd_probe_req_rx(hapd, data->rx_probe_req.sa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1851 | data->rx_probe_req.da, |
| 1852 | data->rx_probe_req.bssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1853 | data->rx_probe_req.ie, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1854 | data->rx_probe_req.ie_len, |
| 1855 | data->rx_probe_req.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1856 | break; |
| 1857 | case EVENT_NEW_STA: |
| 1858 | hostapd_event_new_sta(hapd, data->new_sta.addr); |
| 1859 | break; |
| 1860 | case EVENT_EAPOL_RX: |
| 1861 | hostapd_event_eapol_rx(hapd, data->eapol_rx.src, |
| 1862 | data->eapol_rx.data, |
| 1863 | data->eapol_rx.data_len); |
| 1864 | break; |
| 1865 | case EVENT_ASSOC: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1866 | if (!data) |
| 1867 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1868 | hostapd_notif_assoc(hapd, data->assoc_info.addr, |
| 1869 | data->assoc_info.req_ies, |
| 1870 | data->assoc_info.req_ies_len, |
| 1871 | data->assoc_info.reassoc); |
| 1872 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1873 | #ifdef CONFIG_OWE |
| 1874 | case EVENT_UPDATE_DH: |
| 1875 | if (!data) |
| 1876 | return; |
| 1877 | hostapd_notif_update_dh_ie(hapd, data->update_dh.peer, |
| 1878 | data->update_dh.ie, |
| 1879 | data->update_dh.ie_len); |
| 1880 | break; |
| 1881 | #endif /* CONFIG_OWE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1882 | case EVENT_DISASSOC: |
| 1883 | if (data) |
| 1884 | hostapd_notif_disassoc(hapd, data->disassoc_info.addr); |
| 1885 | break; |
| 1886 | case EVENT_DEAUTH: |
| 1887 | if (data) |
| 1888 | hostapd_notif_disassoc(hapd, data->deauth_info.addr); |
| 1889 | break; |
| 1890 | case EVENT_STATION_LOW_ACK: |
| 1891 | if (!data) |
| 1892 | break; |
| 1893 | hostapd_event_sta_low_ack(hapd, data->low_ack.addr); |
| 1894 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1895 | case EVENT_AUTH: |
| 1896 | hostapd_notif_auth(hapd, &data->auth); |
| 1897 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1898 | case EVENT_CH_SWITCH_STARTED: |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1899 | case EVENT_CH_SWITCH: |
| 1900 | if (!data) |
| 1901 | break; |
| 1902 | hostapd_event_ch_switch(hapd, data->ch_switch.freq, |
| 1903 | data->ch_switch.ht_enabled, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1904 | data->ch_switch.ch_offset, |
| 1905 | data->ch_switch.ch_width, |
| 1906 | data->ch_switch.cf1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1907 | data->ch_switch.cf2, |
| 1908 | event == EVENT_CH_SWITCH); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1909 | break; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1910 | case EVENT_CONNECT_FAILED_REASON: |
| 1911 | if (!data) |
| 1912 | break; |
| 1913 | hostapd_event_connect_failed_reason( |
| 1914 | hapd, data->connect_failed_reason.addr, |
| 1915 | data->connect_failed_reason.code); |
| 1916 | break; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1917 | case EVENT_SURVEY: |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 1918 | hostapd_event_get_survey(hapd->iface, &data->survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1919 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1920 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 1921 | case EVENT_INTERFACE_UNAVAILABLE: |
| 1922 | hostapd_event_iface_unavailable(hapd); |
| 1923 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1924 | case EVENT_DFS_RADAR_DETECTED: |
| 1925 | if (!data) |
| 1926 | break; |
| 1927 | hostapd_event_dfs_radar_detected(hapd, &data->dfs_event); |
| 1928 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1929 | case EVENT_DFS_PRE_CAC_EXPIRED: |
| 1930 | if (!data) |
| 1931 | break; |
| 1932 | hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event); |
| 1933 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1934 | case EVENT_DFS_CAC_FINISHED: |
| 1935 | if (!data) |
| 1936 | break; |
| 1937 | hostapd_event_dfs_cac_finished(hapd, &data->dfs_event); |
| 1938 | break; |
| 1939 | case EVENT_DFS_CAC_ABORTED: |
| 1940 | if (!data) |
| 1941 | break; |
| 1942 | hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event); |
| 1943 | break; |
| 1944 | case EVENT_DFS_NOP_FINISHED: |
| 1945 | if (!data) |
| 1946 | break; |
| 1947 | hostapd_event_dfs_nop_finished(hapd, &data->dfs_event); |
| 1948 | break; |
| 1949 | case EVENT_CHANNEL_LIST_CHANGED: |
| 1950 | /* channel list changed (regulatory?), update channel list */ |
| 1951 | /* TODO: check this. hostapd_get_hw_features() initializes |
| 1952 | * too much stuff. */ |
| 1953 | /* hostapd_get_hw_features(hapd->iface); */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1954 | hostapd_channel_list_updated( |
| 1955 | hapd->iface, data->channel_list_changed.initiator); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1956 | break; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1957 | case EVENT_DFS_CAC_STARTED: |
| 1958 | if (!data) |
| 1959 | break; |
| 1960 | hostapd_event_dfs_cac_started(hapd, &data->dfs_event); |
| 1961 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1962 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1963 | case EVENT_INTERFACE_ENABLED: |
| 1964 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1965 | if (hapd->disabled && hapd->started) { |
| 1966 | hapd->disabled = 0; |
| 1967 | /* |
| 1968 | * Try to re-enable interface if the driver stopped it |
| 1969 | * when the interface got disabled. |
| 1970 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 1971 | if (hapd->wpa_auth) |
| 1972 | wpa_auth_reconfig_group_keys(hapd->wpa_auth); |
| 1973 | else |
| 1974 | hostapd_reconfig_encryption(hapd); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1975 | hapd->reenable_beacon = 1; |
| 1976 | ieee802_11_set_beacon(hapd); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1977 | #ifdef NEED_AP_MLME |
| 1978 | } else if (hapd->disabled && hapd->iface->cac_started) { |
| 1979 | wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC"); |
| 1980 | hostapd_handle_dfs(hapd->iface); |
| 1981 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1982 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1983 | break; |
| 1984 | case EVENT_INTERFACE_DISABLED: |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1985 | hostapd_free_stas(hapd); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1986 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1987 | hapd->disabled = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1988 | break; |
| 1989 | #ifdef CONFIG_ACS |
| 1990 | case EVENT_ACS_CHANNEL_SELECTED: |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1991 | hostapd_acs_channel_selected(hapd, |
| 1992 | &data->acs_selected_channels); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1993 | break; |
| 1994 | #endif /* CONFIG_ACS */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1995 | case EVENT_STATION_OPMODE_CHANGED: |
| 1996 | hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr, |
| 1997 | data->sta_opmode.smps_mode, |
| 1998 | data->sta_opmode.chan_width, |
| 1999 | data->sta_opmode.rx_nss); |
| 2000 | break; |
| 2001 | case EVENT_WDS_STA_INTERFACE_STATUS: |
| 2002 | hostapd_event_wds_sta_interface_status( |
| 2003 | hapd, data->wds_sta_interface.istatus, |
| 2004 | data->wds_sta_interface.ifname, |
| 2005 | data->wds_sta_interface.sta_addr); |
| 2006 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2007 | default: |
| 2008 | wpa_printf(MSG_DEBUG, "Unknown event %d", event); |
| 2009 | break; |
| 2010 | } |
| 2011 | } |
| 2012 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 2013 | |
| 2014 | void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event, |
| 2015 | union wpa_event_data *data) |
| 2016 | { |
| 2017 | struct hapd_interfaces *interfaces = ctx; |
| 2018 | struct hostapd_data *hapd; |
| 2019 | |
| 2020 | if (event != EVENT_INTERFACE_STATUS) |
| 2021 | return; |
| 2022 | |
| 2023 | hapd = hostapd_get_iface(interfaces, data->interface_status.ifname); |
| 2024 | if (hapd && hapd->driver && hapd->driver->get_ifindex && |
| 2025 | hapd->drv_priv) { |
| 2026 | unsigned int ifindex; |
| 2027 | |
| 2028 | ifindex = hapd->driver->get_ifindex(hapd->drv_priv); |
| 2029 | if (ifindex != data->interface_status.ifindex) { |
| 2030 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 2031 | "interface status ifindex %d mismatch (%d)", |
| 2032 | ifindex, data->interface_status.ifindex); |
| 2033 | return; |
| 2034 | } |
| 2035 | } |
| 2036 | if (hapd) |
| 2037 | wpa_supplicant_event(hapd, event, data); |
| 2038 | } |
| 2039 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2040 | #endif /* HOSTAPD */ |