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