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