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