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