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