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