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