Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / IEEE 802.11 Management |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2014, 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 | #ifndef CONFIG_NATIVE_WINDOWS |
| 12 | |
| 13 | #include "utils/common.h" |
| 14 | #include "utils/eloop.h" |
| 15 | #include "crypto/crypto.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 16 | #include "crypto/sha256.h" |
| 17 | #include "crypto/random.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 18 | #include "common/ieee802_11_defs.h" |
| 19 | #include "common/ieee802_11_common.h" |
| 20 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 21 | #include "common/sae.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include "radius/radius.h" |
| 23 | #include "radius/radius_client.h" |
| 24 | #include "p2p/p2p.h" |
| 25 | #include "wps/wps.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 26 | #include "fst/fst.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 27 | #include "hostapd.h" |
| 28 | #include "beacon.h" |
| 29 | #include "ieee802_11_auth.h" |
| 30 | #include "sta_info.h" |
| 31 | #include "ieee802_1x.h" |
| 32 | #include "wpa_auth.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 33 | #include "pmksa_cache_auth.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | #include "wmm.h" |
| 35 | #include "ap_list.h" |
| 36 | #include "accounting.h" |
| 37 | #include "ap_config.h" |
| 38 | #include "ap_mlme.h" |
| 39 | #include "p2p_hostapd.h" |
| 40 | #include "ap_drv_ops.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 41 | #include "wnm_ap.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 42 | #include "hw_features.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 43 | #include "ieee802_11.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 44 | #include "dfs.h" |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 45 | #include "mbo_ap.h" |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 46 | #include "rrm.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 47 | |
| 48 | |
| 49 | u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid) |
| 50 | { |
| 51 | u8 *pos = eid; |
| 52 | int i, num, count; |
| 53 | |
| 54 | if (hapd->iface->current_rates == NULL) |
| 55 | return eid; |
| 56 | |
| 57 | *pos++ = WLAN_EID_SUPP_RATES; |
| 58 | num = hapd->iface->num_rates; |
| 59 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
| 60 | num++; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 61 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
| 62 | num++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 63 | if (num > 8) { |
| 64 | /* rest of the rates are encoded in Extended supported |
| 65 | * rates element */ |
| 66 | num = 8; |
| 67 | } |
| 68 | |
| 69 | *pos++ = num; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 70 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num; |
| 71 | i++) { |
| 72 | count++; |
| 73 | *pos = hapd->iface->current_rates[i].rate / 5; |
| 74 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) |
| 75 | *pos |= 0x80; |
| 76 | pos++; |
| 77 | } |
| 78 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 79 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) { |
| 80 | count++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 81 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) { |
| 85 | count++; |
| 86 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; |
| 87 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 88 | |
| 89 | return pos; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid) |
| 94 | { |
| 95 | u8 *pos = eid; |
| 96 | int i, num, count; |
| 97 | |
| 98 | if (hapd->iface->current_rates == NULL) |
| 99 | return eid; |
| 100 | |
| 101 | num = hapd->iface->num_rates; |
| 102 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
| 103 | num++; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 104 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
| 105 | num++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 106 | if (num <= 8) |
| 107 | return eid; |
| 108 | num -= 8; |
| 109 | |
| 110 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 111 | *pos++ = num; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 112 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8; |
| 113 | i++) { |
| 114 | count++; |
| 115 | if (count <= 8) |
| 116 | continue; /* already in SuppRates IE */ |
| 117 | *pos = hapd->iface->current_rates[i].rate / 5; |
| 118 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) |
| 119 | *pos |= 0x80; |
| 120 | pos++; |
| 121 | } |
| 122 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 123 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) { |
| 124 | count++; |
| 125 | if (count > 8) |
| 126 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; |
| 127 | } |
| 128 | |
| 129 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) { |
| 130 | count++; |
| 131 | if (count > 8) |
| 132 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; |
| 133 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 134 | |
| 135 | return pos; |
| 136 | } |
| 137 | |
| 138 | |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 139 | u16 hostapd_own_capab_info(struct hostapd_data *hapd) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 140 | { |
| 141 | int capab = WLAN_CAPABILITY_ESS; |
| 142 | int privacy; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 143 | int dfs; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 144 | int i; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 145 | |
| 146 | /* Check if any of configured channels require DFS */ |
| 147 | dfs = hostapd_is_dfs_required(hapd->iface); |
| 148 | if (dfs < 0) { |
| 149 | wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d", |
| 150 | dfs); |
| 151 | dfs = 0; |
| 152 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 153 | |
| 154 | if (hapd->iface->num_sta_no_short_preamble == 0 && |
| 155 | hapd->iconf->preamble == SHORT_PREAMBLE) |
| 156 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 157 | |
| 158 | privacy = hapd->conf->ssid.wep.keys_set; |
| 159 | |
| 160 | if (hapd->conf->ieee802_1x && |
| 161 | (hapd->conf->default_wep_key_len || |
| 162 | hapd->conf->individual_wep_key_len)) |
| 163 | privacy = 1; |
| 164 | |
| 165 | if (hapd->conf->wpa) |
| 166 | privacy = 1; |
| 167 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 168 | #ifdef CONFIG_HS20 |
| 169 | if (hapd->conf->osen) |
| 170 | privacy = 1; |
| 171 | #endif /* CONFIG_HS20 */ |
| 172 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 173 | if (privacy) |
| 174 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 175 | |
| 176 | if (hapd->iface->current_mode && |
| 177 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G && |
| 178 | hapd->iface->num_sta_no_short_slot_time == 0) |
| 179 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 180 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 181 | /* |
| 182 | * Currently, Spectrum Management capability bit is set when directly |
| 183 | * requested in configuration by spectrum_mgmt_required or when AP is |
| 184 | * running on DFS channel. |
| 185 | * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit |
| 186 | */ |
| 187 | if (hapd->iface->current_mode && |
| 188 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A && |
| 189 | (hapd->iconf->spectrum_mgmt_required || dfs)) |
| 190 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 191 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 192 | for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) { |
| 193 | if (hapd->conf->radio_measurements[i]) { |
| 194 | capab |= IEEE80211_CAP_RRM; |
| 195 | break; |
| 196 | } |
| 197 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 198 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 199 | return capab; |
| 200 | } |
| 201 | |
| 202 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 203 | #ifndef CONFIG_NO_RC4 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 204 | static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta, |
| 205 | u16 auth_transaction, const u8 *challenge, |
| 206 | int iswep) |
| 207 | { |
| 208 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 209 | HOSTAPD_LEVEL_DEBUG, |
| 210 | "authentication (shared key, transaction %d)", |
| 211 | auth_transaction); |
| 212 | |
| 213 | if (auth_transaction == 1) { |
| 214 | if (!sta->challenge) { |
| 215 | /* Generate a pseudo-random challenge */ |
| 216 | u8 key[8]; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 217 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 218 | sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN); |
| 219 | if (sta->challenge == NULL) |
| 220 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 221 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 222 | if (os_get_random(key, sizeof(key)) < 0) { |
| 223 | os_free(sta->challenge); |
| 224 | sta->challenge = NULL; |
| 225 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 226 | } |
| 227 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 228 | rc4_skip(key, sizeof(key), 0, |
| 229 | sta->challenge, WLAN_AUTH_CHALLENGE_LEN); |
| 230 | } |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | if (auth_transaction != 3) |
| 235 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 236 | |
| 237 | /* Transaction 3 */ |
| 238 | if (!iswep || !sta->challenge || !challenge || |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 239 | os_memcmp_const(sta->challenge, challenge, |
| 240 | WLAN_AUTH_CHALLENGE_LEN)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 241 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 242 | HOSTAPD_LEVEL_INFO, |
| 243 | "shared key authentication - invalid " |
| 244 | "challenge-response"); |
| 245 | return WLAN_STATUS_CHALLENGE_FAIL; |
| 246 | } |
| 247 | |
| 248 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 249 | HOSTAPD_LEVEL_DEBUG, |
| 250 | "authentication OK (shared key)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 251 | sta->flags |= WLAN_STA_AUTH; |
| 252 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 253 | os_free(sta->challenge); |
| 254 | sta->challenge = NULL; |
| 255 | |
| 256 | return 0; |
| 257 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 258 | #endif /* CONFIG_NO_RC4 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 259 | |
| 260 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 261 | static int send_auth_reply(struct hostapd_data *hapd, |
| 262 | const u8 *dst, const u8 *bssid, |
| 263 | u16 auth_alg, u16 auth_transaction, u16 resp, |
| 264 | const u8 *ies, size_t ies_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 265 | { |
| 266 | struct ieee80211_mgmt *reply; |
| 267 | u8 *buf; |
| 268 | size_t rlen; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 269 | int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 270 | |
| 271 | rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len; |
| 272 | buf = os_zalloc(rlen); |
| 273 | if (buf == NULL) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 274 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 275 | |
| 276 | reply = (struct ieee80211_mgmt *) buf; |
| 277 | reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 278 | WLAN_FC_STYPE_AUTH); |
| 279 | os_memcpy(reply->da, dst, ETH_ALEN); |
| 280 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); |
| 281 | os_memcpy(reply->bssid, bssid, ETH_ALEN); |
| 282 | |
| 283 | reply->u.auth.auth_alg = host_to_le16(auth_alg); |
| 284 | reply->u.auth.auth_transaction = host_to_le16(auth_transaction); |
| 285 | reply->u.auth.status_code = host_to_le16(resp); |
| 286 | |
| 287 | if (ies && ies_len) |
| 288 | os_memcpy(reply->u.auth.variable, ies, ies_len); |
| 289 | |
| 290 | wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR |
| 291 | " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)", |
| 292 | MAC2STR(dst), auth_alg, auth_transaction, |
| 293 | resp, (unsigned long) ies_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 294 | if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 295 | wpa_printf(MSG_INFO, "send_auth_reply: send failed"); |
| 296 | else |
| 297 | reply_res = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 298 | |
| 299 | os_free(buf); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 300 | |
| 301 | return reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | |
| 305 | #ifdef CONFIG_IEEE80211R |
| 306 | static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid, |
| 307 | u16 auth_transaction, u16 status, |
| 308 | const u8 *ies, size_t ies_len) |
| 309 | { |
| 310 | struct hostapd_data *hapd = ctx; |
| 311 | struct sta_info *sta; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 312 | int reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 313 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 314 | reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, |
| 315 | auth_transaction, status, ies, ies_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 316 | |
| 317 | sta = ap_get_sta(hapd, dst); |
| 318 | if (sta == NULL) |
| 319 | return; |
| 320 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 321 | if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS || |
| 322 | status != WLAN_STATUS_SUCCESS)) { |
| 323 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 324 | sta->added_unassoc = 0; |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | if (status != WLAN_STATUS_SUCCESS) |
| 329 | return; |
| 330 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 331 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, |
| 332 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); |
| 333 | sta->flags |= WLAN_STA_AUTH; |
| 334 | mlme_authenticate_indication(hapd, sta); |
| 335 | } |
| 336 | #endif /* CONFIG_IEEE80211R */ |
| 337 | |
| 338 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 339 | #ifdef CONFIG_SAE |
| 340 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 341 | #define dot11RSNASAESync 5 /* attempts */ |
| 342 | |
| 343 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 344 | static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd, |
| 345 | struct sta_info *sta, int update) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 346 | { |
| 347 | struct wpabuf *buf; |
| 348 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 349 | if (hapd->conf->ssid.wpa_passphrase == NULL) { |
| 350 | wpa_printf(MSG_DEBUG, "SAE: No password available"); |
| 351 | return NULL; |
| 352 | } |
| 353 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 354 | if (update && |
| 355 | sae_prepare_commit(hapd->own_addr, sta->addr, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 356 | (u8 *) hapd->conf->ssid.wpa_passphrase, |
| 357 | os_strlen(hapd->conf->ssid.wpa_passphrase), |
| 358 | sta->sae) < 0) { |
| 359 | wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE"); |
| 360 | return NULL; |
| 361 | } |
| 362 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 363 | buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 364 | if (buf == NULL) |
| 365 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 366 | sae_write_commit(sta->sae, buf, sta->sae->tmp ? |
| 367 | sta->sae->tmp->anti_clogging_token : NULL); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 368 | |
| 369 | return buf; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd, |
| 374 | struct sta_info *sta) |
| 375 | { |
| 376 | struct wpabuf *buf; |
| 377 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 378 | buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 379 | if (buf == NULL) |
| 380 | return NULL; |
| 381 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 382 | sae_write_confirm(sta->sae, buf); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 383 | |
| 384 | return buf; |
| 385 | } |
| 386 | |
| 387 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 388 | static int auth_sae_send_commit(struct hostapd_data *hapd, |
| 389 | struct sta_info *sta, |
| 390 | const u8 *bssid, int update) |
| 391 | { |
| 392 | struct wpabuf *data; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 393 | int reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 394 | |
| 395 | data = auth_build_sae_commit(hapd, sta, update); |
| 396 | if (data == NULL) |
| 397 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 398 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 399 | reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1, |
| 400 | WLAN_STATUS_SUCCESS, wpabuf_head(data), |
| 401 | wpabuf_len(data)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 402 | |
| 403 | wpabuf_free(data); |
| 404 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 405 | return reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | |
| 409 | static int auth_sae_send_confirm(struct hostapd_data *hapd, |
| 410 | struct sta_info *sta, |
| 411 | const u8 *bssid) |
| 412 | { |
| 413 | struct wpabuf *data; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 414 | int reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 415 | |
| 416 | data = auth_build_sae_confirm(hapd, sta); |
| 417 | if (data == NULL) |
| 418 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 419 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 420 | reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2, |
| 421 | WLAN_STATUS_SUCCESS, wpabuf_head(data), |
| 422 | wpabuf_len(data)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 423 | |
| 424 | wpabuf_free(data); |
| 425 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 426 | return reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 430 | static int use_sae_anti_clogging(struct hostapd_data *hapd) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 431 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 432 | struct sta_info *sta; |
| 433 | unsigned int open = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 434 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 435 | if (hapd->conf->sae_anti_clogging_threshold == 0) |
| 436 | return 1; |
| 437 | |
| 438 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 439 | if (!sta->sae) |
| 440 | continue; |
| 441 | if (sta->sae->state != SAE_COMMITTED && |
| 442 | sta->sae->state != SAE_CONFIRMED) |
| 443 | continue; |
| 444 | open++; |
| 445 | if (open >= hapd->conf->sae_anti_clogging_threshold) |
| 446 | return 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 449 | return 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 453 | static int check_sae_token(struct hostapd_data *hapd, const u8 *addr, |
| 454 | const u8 *token, size_t token_len) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 455 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 456 | u8 mac[SHA256_MAC_LEN]; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 457 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 458 | if (token_len != SHA256_MAC_LEN) |
| 459 | return -1; |
| 460 | if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key), |
| 461 | addr, ETH_ALEN, mac) < 0 || |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 462 | os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 463 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 464 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 465 | return 0; |
| 466 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 467 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 468 | |
| 469 | static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 470 | int group, const u8 *addr) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 471 | { |
| 472 | struct wpabuf *buf; |
| 473 | u8 *token; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 474 | struct os_reltime now; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 475 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 476 | os_get_reltime(&now); |
| 477 | if (!os_reltime_initialized(&hapd->last_sae_token_key_update) || |
| 478 | os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 479 | if (random_get_bytes(hapd->sae_token_key, |
| 480 | sizeof(hapd->sae_token_key)) < 0) |
| 481 | return NULL; |
| 482 | wpa_hexdump(MSG_DEBUG, "SAE: Updated token key", |
| 483 | hapd->sae_token_key, sizeof(hapd->sae_token_key)); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 484 | hapd->last_sae_token_key_update = now; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 487 | buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 488 | if (buf == NULL) |
| 489 | return NULL; |
| 490 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 491 | wpabuf_put_le16(buf, group); /* Finite Cyclic Group */ |
| 492 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 493 | token = wpabuf_put(buf, SHA256_MAC_LEN); |
| 494 | hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key), |
| 495 | addr, ETH_ALEN, token); |
| 496 | |
| 497 | return buf; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 501 | static int sae_check_big_sync(struct sta_info *sta) |
| 502 | { |
| 503 | if (sta->sae->sync > dot11RSNASAESync) { |
| 504 | sta->sae->state = SAE_NOTHING; |
| 505 | sta->sae->sync = 0; |
| 506 | return -1; |
| 507 | } |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | |
| 512 | static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data) |
| 513 | { |
| 514 | struct hostapd_data *hapd = eloop_ctx; |
| 515 | struct sta_info *sta = eloop_data; |
| 516 | int ret; |
| 517 | |
| 518 | if (sae_check_big_sync(sta)) |
| 519 | return; |
| 520 | sta->sae->sync++; |
| 521 | |
| 522 | switch (sta->sae->state) { |
| 523 | case SAE_COMMITTED: |
| 524 | ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 525 | eloop_register_timeout(0, |
| 526 | hapd->dot11RSNASAERetransPeriod * 1000, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 527 | auth_sae_retransmit_timer, hapd, sta); |
| 528 | break; |
| 529 | case SAE_CONFIRMED: |
| 530 | ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 531 | eloop_register_timeout(0, |
| 532 | hapd->dot11RSNASAERetransPeriod * 1000, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 533 | auth_sae_retransmit_timer, hapd, sta); |
| 534 | break; |
| 535 | default: |
| 536 | ret = -1; |
| 537 | break; |
| 538 | } |
| 539 | |
| 540 | if (ret != WLAN_STATUS_SUCCESS) |
| 541 | wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret); |
| 542 | } |
| 543 | |
| 544 | |
| 545 | void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta) |
| 546 | { |
| 547 | eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta); |
| 548 | } |
| 549 | |
| 550 | |
| 551 | static void sae_set_retransmit_timer(struct hostapd_data *hapd, |
| 552 | struct sta_info *sta) |
| 553 | { |
| 554 | if (!(hapd->conf->mesh & MESH_ENABLED)) |
| 555 | return; |
| 556 | |
| 557 | eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 558 | eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 559 | auth_sae_retransmit_timer, hapd, sta); |
| 560 | } |
| 561 | |
| 562 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 563 | void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta) |
| 564 | { |
| 565 | sta->flags |= WLAN_STA_AUTH; |
| 566 | sta->auth_alg = WLAN_AUTH_SAE; |
| 567 | mlme_authenticate_indication(hapd, sta); |
| 568 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 569 | sta->sae->state = SAE_ACCEPTED; |
| 570 | wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr, |
| 571 | sta->sae->pmk, sta->sae->pmkid); |
| 572 | } |
| 573 | |
| 574 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 575 | static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta, |
| 576 | const u8 *bssid, u8 auth_transaction) |
| 577 | { |
| 578 | int ret; |
| 579 | |
| 580 | if (auth_transaction != 1 && auth_transaction != 2) |
| 581 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 582 | |
| 583 | switch (sta->sae->state) { |
| 584 | case SAE_NOTHING: |
| 585 | if (auth_transaction == 1) { |
| 586 | ret = auth_sae_send_commit(hapd, sta, bssid, 1); |
| 587 | if (ret) |
| 588 | return ret; |
| 589 | sta->sae->state = SAE_COMMITTED; |
| 590 | |
| 591 | if (sae_process_commit(sta->sae) < 0) |
| 592 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 593 | |
| 594 | /* |
| 595 | * In mesh case, both Commit and Confirm can be sent |
| 596 | * immediately. In infrastructure BSS, only a single |
| 597 | * Authentication frame (Commit) is expected from the AP |
| 598 | * here and the second one (Confirm) will be sent once |
| 599 | * the STA has sent its second Authentication frame |
| 600 | * (Confirm). |
| 601 | */ |
| 602 | if (hapd->conf->mesh & MESH_ENABLED) { |
| 603 | /* |
| 604 | * Send both Commit and Confirm immediately |
| 605 | * based on SAE finite state machine |
| 606 | * Nothing -> Confirm transition. |
| 607 | */ |
| 608 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 609 | if (ret) |
| 610 | return ret; |
| 611 | sta->sae->state = SAE_CONFIRMED; |
| 612 | } else { |
| 613 | /* |
| 614 | * For infrastructure BSS, send only the Commit |
| 615 | * message now to get alternating sequence of |
| 616 | * Authentication frames between the AP and STA. |
| 617 | * Confirm will be sent in |
| 618 | * Commited -> Confirmed/Accepted transition |
| 619 | * when receiving Confirm from STA. |
| 620 | */ |
| 621 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 622 | sta->sae->sync = 0; |
| 623 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 624 | } else { |
| 625 | hostapd_logger(hapd, sta->addr, |
| 626 | HOSTAPD_MODULE_IEEE80211, |
| 627 | HOSTAPD_LEVEL_DEBUG, |
| 628 | "SAE confirm before commit"); |
| 629 | } |
| 630 | break; |
| 631 | case SAE_COMMITTED: |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 632 | sae_clear_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 633 | if (auth_transaction == 1) { |
| 634 | if (sae_process_commit(sta->sae) < 0) |
| 635 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 636 | |
| 637 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 638 | if (ret) |
| 639 | return ret; |
| 640 | sta->sae->state = SAE_CONFIRMED; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 641 | sta->sae->sync = 0; |
| 642 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 643 | } else if (hapd->conf->mesh & MESH_ENABLED) { |
| 644 | /* |
| 645 | * In mesh case, follow SAE finite state machine and |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 646 | * send Commit now, if sync count allows. |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 647 | */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 648 | if (sae_check_big_sync(sta)) |
| 649 | return WLAN_STATUS_SUCCESS; |
| 650 | sta->sae->sync++; |
| 651 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 652 | ret = auth_sae_send_commit(hapd, sta, bssid, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 653 | if (ret) |
| 654 | return ret; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 655 | |
| 656 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 657 | } else { |
| 658 | /* |
| 659 | * For instructure BSS, send the postponed Confirm from |
| 660 | * Nothing -> Confirmed transition that was reduced to |
| 661 | * Nothing -> Committed above. |
| 662 | */ |
| 663 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 664 | if (ret) |
| 665 | return ret; |
| 666 | |
| 667 | sta->sae->state = SAE_CONFIRMED; |
| 668 | |
| 669 | /* |
| 670 | * Since this was triggered on Confirm RX, run another |
| 671 | * step to get to Accepted without waiting for |
| 672 | * additional events. |
| 673 | */ |
| 674 | return sae_sm_step(hapd, sta, bssid, auth_transaction); |
| 675 | } |
| 676 | break; |
| 677 | case SAE_CONFIRMED: |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 678 | sae_clear_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 679 | if (auth_transaction == 1) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 680 | if (sae_check_big_sync(sta)) |
| 681 | return WLAN_STATUS_SUCCESS; |
| 682 | sta->sae->sync++; |
| 683 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 684 | ret = auth_sae_send_commit(hapd, sta, bssid, 1); |
| 685 | if (ret) |
| 686 | return ret; |
| 687 | |
| 688 | if (sae_process_commit(sta->sae) < 0) |
| 689 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 690 | |
| 691 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 692 | if (ret) |
| 693 | return ret; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 694 | |
| 695 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 696 | } else { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 697 | sae_accept_sta(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 698 | } |
| 699 | break; |
| 700 | case SAE_ACCEPTED: |
| 701 | if (auth_transaction == 1) { |
| 702 | wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR |
| 703 | ") doing reauthentication", |
| 704 | MAC2STR(sta->addr)); |
| 705 | ap_free_sta(hapd, sta); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 706 | wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 707 | } else { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 708 | if (sae_check_big_sync(sta)) |
| 709 | return WLAN_STATUS_SUCCESS; |
| 710 | sta->sae->sync++; |
| 711 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 712 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 713 | sae_clear_temp_data(sta->sae); |
| 714 | if (ret) |
| 715 | return ret; |
| 716 | } |
| 717 | break; |
| 718 | default: |
| 719 | wpa_printf(MSG_ERROR, "SAE: invalid state %d", |
| 720 | sta->sae->state); |
| 721 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 722 | } |
| 723 | return WLAN_STATUS_SUCCESS; |
| 724 | } |
| 725 | |
| 726 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 727 | static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta, |
| 728 | const struct ieee80211_mgmt *mgmt, size_t len, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 729 | u16 auth_transaction, u16 status_code) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 730 | { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 731 | int resp = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 732 | struct wpabuf *data = NULL; |
| 733 | |
| 734 | if (!sta->sae) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 735 | if (auth_transaction != 1 || |
| 736 | status_code != WLAN_STATUS_SUCCESS) { |
| 737 | resp = -1; |
| 738 | goto remove_sta; |
| 739 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 740 | sta->sae = os_zalloc(sizeof(*sta->sae)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 741 | if (!sta->sae) { |
| 742 | resp = -1; |
| 743 | goto remove_sta; |
| 744 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 745 | sta->sae->state = SAE_NOTHING; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 746 | sta->sae->sync = 0; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 747 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 748 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 749 | if (sta->mesh_sae_pmksa_caching) { |
| 750 | wpa_printf(MSG_DEBUG, |
| 751 | "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication"); |
| 752 | wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr); |
| 753 | sta->mesh_sae_pmksa_caching = 0; |
| 754 | } |
| 755 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 756 | if (auth_transaction == 1) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 757 | const u8 *token = NULL, *pos, *end; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 758 | size_t token_len = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 759 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 760 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 761 | "start SAE authentication (RX commit, status=%u)", |
| 762 | status_code); |
| 763 | |
| 764 | if ((hapd->conf->mesh & MESH_ENABLED) && |
| 765 | status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ && |
| 766 | sta->sae->tmp) { |
| 767 | pos = mgmt->u.auth.variable; |
| 768 | end = ((const u8 *) mgmt) + len; |
| 769 | if (pos + sizeof(le16) > end) { |
| 770 | wpa_printf(MSG_ERROR, |
| 771 | "SAE: Too short anti-clogging token request"); |
| 772 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 773 | goto reply; |
| 774 | } |
| 775 | resp = sae_group_allowed(sta->sae, |
| 776 | hapd->conf->sae_groups, |
| 777 | WPA_GET_LE16(pos)); |
| 778 | if (resp != WLAN_STATUS_SUCCESS) { |
| 779 | wpa_printf(MSG_ERROR, |
| 780 | "SAE: Invalid group in anti-clogging token request"); |
| 781 | goto reply; |
| 782 | } |
| 783 | pos += sizeof(le16); |
| 784 | |
| 785 | wpabuf_free(sta->sae->tmp->anti_clogging_token); |
| 786 | sta->sae->tmp->anti_clogging_token = |
| 787 | wpabuf_alloc_copy(pos, end - pos); |
| 788 | if (sta->sae->tmp->anti_clogging_token == NULL) { |
| 789 | wpa_printf(MSG_ERROR, |
| 790 | "SAE: Failed to alloc for anti-clogging token"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 791 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 792 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | /* |
| 796 | * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code |
| 797 | * is 76, a new Commit Message shall be constructed |
| 798 | * with the Anti-Clogging Token from the received |
| 799 | * Authentication frame, and the commit-scalar and |
| 800 | * COMMIT-ELEMENT previously sent. |
| 801 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 802 | resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0); |
| 803 | if (resp != WLAN_STATUS_SUCCESS) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 804 | wpa_printf(MSG_ERROR, |
| 805 | "SAE: Failed to send commit message"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 806 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 807 | } |
| 808 | sta->sae->state = SAE_COMMITTED; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 809 | sta->sae->sync = 0; |
| 810 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 811 | return; |
| 812 | } |
| 813 | |
| 814 | if (status_code != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 815 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 816 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 817 | resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable, |
| 818 | ((const u8 *) mgmt) + len - |
| 819 | mgmt->u.auth.variable, &token, |
| 820 | &token_len, hapd->conf->sae_groups); |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 821 | if (resp == SAE_SILENTLY_DISCARD) { |
| 822 | wpa_printf(MSG_DEBUG, |
| 823 | "SAE: Drop commit message from " MACSTR " due to reflection attack", |
| 824 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 825 | goto remove_sta; |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 826 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 827 | if (token && check_sae_token(hapd, sta->addr, token, token_len) |
| 828 | < 0) { |
| 829 | wpa_printf(MSG_DEBUG, "SAE: Drop commit message with " |
| 830 | "incorrect token from " MACSTR, |
| 831 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 832 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 833 | goto remove_sta; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 834 | } |
| 835 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 836 | if (resp != WLAN_STATUS_SUCCESS) |
| 837 | goto reply; |
| 838 | |
| 839 | if (!token && use_sae_anti_clogging(hapd)) { |
| 840 | wpa_printf(MSG_DEBUG, |
| 841 | "SAE: Request anti-clogging token from " |
| 842 | MACSTR, MAC2STR(sta->addr)); |
| 843 | data = auth_build_token_req(hapd, sta->sae->group, |
| 844 | sta->addr); |
| 845 | resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ; |
| 846 | if (hapd->conf->mesh & MESH_ENABLED) |
| 847 | sta->sae->state = SAE_NOTHING; |
| 848 | goto reply; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 849 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 850 | |
| 851 | resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 852 | } else if (auth_transaction == 2) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 853 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 854 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 855 | "SAE authentication (RX confirm, status=%u)", |
| 856 | status_code); |
| 857 | if (status_code != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 858 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 859 | if (sta->sae->state >= SAE_CONFIRMED || |
| 860 | !(hapd->conf->mesh & MESH_ENABLED)) { |
| 861 | if (sae_check_confirm(sta->sae, mgmt->u.auth.variable, |
| 862 | ((u8 *) mgmt) + len - |
| 863 | mgmt->u.auth.variable) < 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 864 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 865 | goto reply; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 866 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 867 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 868 | resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 869 | } else { |
| 870 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 871 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 872 | "unexpected SAE authentication transaction %u (status=%u)", |
| 873 | auth_transaction, status_code); |
| 874 | if (status_code != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 875 | goto remove_sta; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 876 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
| 877 | } |
| 878 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 879 | reply: |
| 880 | if (resp != WLAN_STATUS_SUCCESS) { |
| 881 | send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE, |
| 882 | auth_transaction, resp, |
| 883 | data ? wpabuf_head(data) : (u8 *) "", |
| 884 | data ? wpabuf_len(data) : 0); |
| 885 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 886 | |
| 887 | remove_sta: |
| 888 | if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS || |
| 889 | status_code != WLAN_STATUS_SUCCESS)) { |
| 890 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 891 | sta->added_unassoc = 0; |
| 892 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 893 | wpabuf_free(data); |
| 894 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 895 | |
| 896 | |
| 897 | /** |
| 898 | * auth_sae_init_committed - Send COMMIT and start SAE in committed state |
| 899 | * @hapd: BSS data for the device initiating the authentication |
| 900 | * @sta: the peer to which commit authentication frame is sent |
| 901 | * |
| 902 | * This function implements Init event handling (IEEE Std 802.11-2012, |
| 903 | * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the |
| 904 | * sta->sae structure should be initialized appropriately via a call to |
| 905 | * sae_prepare_commit(). |
| 906 | */ |
| 907 | int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta) |
| 908 | { |
| 909 | int ret; |
| 910 | |
| 911 | if (!sta->sae || !sta->sae->tmp) |
| 912 | return -1; |
| 913 | |
| 914 | if (sta->sae->state != SAE_NOTHING) |
| 915 | return -1; |
| 916 | |
| 917 | ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0); |
| 918 | if (ret) |
| 919 | return -1; |
| 920 | |
| 921 | sta->sae->state = SAE_COMMITTED; |
| 922 | sta->sae->sync = 0; |
| 923 | sae_set_retransmit_timer(hapd, sta); |
| 924 | |
| 925 | return 0; |
| 926 | } |
| 927 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 928 | #endif /* CONFIG_SAE */ |
| 929 | |
| 930 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 931 | static void handle_auth(struct hostapd_data *hapd, |
| 932 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 933 | { |
| 934 | u16 auth_alg, auth_transaction, status_code; |
| 935 | u16 resp = WLAN_STATUS_SUCCESS; |
| 936 | struct sta_info *sta = NULL; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 937 | int res, reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 938 | u16 fc; |
| 939 | const u8 *challenge = NULL; |
| 940 | u32 session_timeout, acct_interim_interval; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 941 | struct vlan_description vlan_id; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 942 | struct hostapd_sta_wpa_psk_short *psk = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 943 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; |
| 944 | size_t resp_ies_len = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 945 | char *identity = NULL; |
| 946 | char *radius_cui = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 947 | u16 seq_ctrl; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 948 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 949 | os_memset(&vlan_id, 0, sizeof(vlan_id)); |
| 950 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 951 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 952 | wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)", |
| 953 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 954 | return; |
| 955 | } |
| 956 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 957 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 958 | if (hapd->iconf->ignore_auth_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 959 | drand48() < hapd->iconf->ignore_auth_probability) { |
| 960 | wpa_printf(MSG_INFO, |
| 961 | "TESTING: ignoring auth frame from " MACSTR, |
| 962 | MAC2STR(mgmt->sa)); |
| 963 | return; |
| 964 | } |
| 965 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 966 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 967 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 968 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); |
| 969 | status_code = le_to_host16(mgmt->u.auth.status_code); |
| 970 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 971 | seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 972 | |
| 973 | if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) + |
| 974 | 2 + WLAN_AUTH_CHALLENGE_LEN && |
| 975 | mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE && |
| 976 | mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN) |
| 977 | challenge = &mgmt->u.auth.variable[2]; |
| 978 | |
| 979 | wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d " |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 980 | "auth_transaction=%d status_code=%d wep=%d%s " |
| 981 | "seq_ctrl=0x%x%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 982 | MAC2STR(mgmt->sa), auth_alg, auth_transaction, |
| 983 | status_code, !!(fc & WLAN_FC_ISWEP), |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 984 | challenge ? " challenge" : "", |
| 985 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 986 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 987 | #ifdef CONFIG_NO_RC4 |
| 988 | if (auth_alg == WLAN_AUTH_SHARED_KEY) { |
| 989 | wpa_printf(MSG_INFO, |
| 990 | "Unsupported authentication algorithm (%d)", |
| 991 | auth_alg); |
| 992 | resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 993 | goto fail; |
| 994 | } |
| 995 | #endif /* CONFIG_NO_RC4 */ |
| 996 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 997 | if (hapd->tkip_countermeasures) { |
| 998 | resp = WLAN_REASON_MICHAEL_MIC_FAILURE; |
| 999 | goto fail; |
| 1000 | } |
| 1001 | |
| 1002 | if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) && |
| 1003 | auth_alg == WLAN_AUTH_OPEN) || |
| 1004 | #ifdef CONFIG_IEEE80211R |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1005 | (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1006 | auth_alg == WLAN_AUTH_FT) || |
| 1007 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1008 | #ifdef CONFIG_SAE |
| 1009 | (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) && |
| 1010 | auth_alg == WLAN_AUTH_SAE) || |
| 1011 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1012 | ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) && |
| 1013 | auth_alg == WLAN_AUTH_SHARED_KEY))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1014 | wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)", |
| 1015 | auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1016 | resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 1017 | goto fail; |
| 1018 | } |
| 1019 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1020 | if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1021 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1022 | wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)", |
| 1023 | auth_transaction); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1024 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
| 1025 | goto fail; |
| 1026 | } |
| 1027 | |
| 1028 | if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1029 | wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate", |
| 1030 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1031 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1032 | goto fail; |
| 1033 | } |
| 1034 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1035 | if (hapd->conf->no_auth_if_seen_on) { |
| 1036 | struct hostapd_data *other; |
| 1037 | |
| 1038 | other = sta_track_seen_on(hapd->iface, mgmt->sa, |
| 1039 | hapd->conf->no_auth_if_seen_on); |
| 1040 | if (other) { |
| 1041 | u8 *pos; |
| 1042 | u32 info; |
| 1043 | u8 op_class, channel, phytype; |
| 1044 | |
| 1045 | wpa_printf(MSG_DEBUG, "%s: Reject authentication from " |
| 1046 | MACSTR " since STA has been seen on %s", |
| 1047 | hapd->conf->iface, MAC2STR(mgmt->sa), |
| 1048 | hapd->conf->no_auth_if_seen_on); |
| 1049 | |
| 1050 | resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION; |
| 1051 | pos = &resp_ies[0]; |
| 1052 | *pos++ = WLAN_EID_NEIGHBOR_REPORT; |
| 1053 | *pos++ = 13; |
| 1054 | os_memcpy(pos, other->own_addr, ETH_ALEN); |
| 1055 | pos += ETH_ALEN; |
| 1056 | info = 0; /* TODO: BSSID Information */ |
| 1057 | WPA_PUT_LE32(pos, info); |
| 1058 | pos += 4; |
| 1059 | if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD) |
| 1060 | phytype = 8; /* dmg */ |
| 1061 | else if (other->iconf->ieee80211ac) |
| 1062 | phytype = 9; /* vht */ |
| 1063 | else if (other->iconf->ieee80211n) |
| 1064 | phytype = 7; /* ht */ |
| 1065 | else if (other->iconf->hw_mode == |
| 1066 | HOSTAPD_MODE_IEEE80211A) |
| 1067 | phytype = 4; /* ofdm */ |
| 1068 | else if (other->iconf->hw_mode == |
| 1069 | HOSTAPD_MODE_IEEE80211G) |
| 1070 | phytype = 6; /* erp */ |
| 1071 | else |
| 1072 | phytype = 5; /* hrdsss */ |
| 1073 | if (ieee80211_freq_to_channel_ext( |
| 1074 | hostapd_hw_get_freq(other, |
| 1075 | other->iconf->channel), |
| 1076 | other->iconf->secondary_channel, |
| 1077 | other->iconf->ieee80211ac, |
| 1078 | &op_class, &channel) == NUM_HOSTAPD_MODES) { |
| 1079 | op_class = 0; |
| 1080 | channel = other->iconf->channel; |
| 1081 | } |
| 1082 | *pos++ = op_class; |
| 1083 | *pos++ = channel; |
| 1084 | *pos++ = phytype; |
| 1085 | resp_ies_len = pos - &resp_ies[0]; |
| 1086 | goto fail; |
| 1087 | } |
| 1088 | } |
| 1089 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1090 | res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len, |
| 1091 | &session_timeout, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1092 | &acct_interim_interval, &vlan_id, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1093 | &psk, &identity, &radius_cui); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1094 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1095 | if (res == HOSTAPD_ACL_REJECT) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1096 | wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate", |
| 1097 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1098 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1099 | goto fail; |
| 1100 | } |
| 1101 | if (res == HOSTAPD_ACL_PENDING) { |
| 1102 | wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR |
| 1103 | " waiting for an external authentication", |
| 1104 | MAC2STR(mgmt->sa)); |
| 1105 | /* Authentication code will re-send the authentication frame |
| 1106 | * after it has received (and cached) information from the |
| 1107 | * external source. */ |
| 1108 | return; |
| 1109 | } |
| 1110 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1111 | sta = ap_get_sta(hapd, mgmt->sa); |
| 1112 | if (sta) { |
| 1113 | if ((fc & WLAN_FC_RETRY) && |
| 1114 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && |
| 1115 | sta->last_seq_ctrl == seq_ctrl && |
| 1116 | sta->last_subtype == WLAN_FC_STYPE_AUTH) { |
| 1117 | hostapd_logger(hapd, sta->addr, |
| 1118 | HOSTAPD_MODULE_IEEE80211, |
| 1119 | HOSTAPD_LEVEL_DEBUG, |
| 1120 | "Drop repeated authentication frame seq_ctrl=0x%x", |
| 1121 | seq_ctrl); |
| 1122 | return; |
| 1123 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1124 | #ifdef CONFIG_MESH |
| 1125 | if ((hapd->conf->mesh & MESH_ENABLED) && |
| 1126 | sta->plink_state == PLINK_BLOCKED) { |
| 1127 | wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR |
| 1128 | " is blocked - drop Authentication frame", |
| 1129 | MAC2STR(mgmt->sa)); |
| 1130 | return; |
| 1131 | } |
| 1132 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1133 | } else { |
| 1134 | #ifdef CONFIG_MESH |
| 1135 | if (hapd->conf->mesh & MESH_ENABLED) { |
| 1136 | /* if the mesh peer is not available, we don't do auth. |
| 1137 | */ |
| 1138 | wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1139 | " not yet known - drop Authentication frame", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1140 | MAC2STR(mgmt->sa)); |
| 1141 | /* |
| 1142 | * Save a copy of the frame so that it can be processed |
| 1143 | * if a new peer entry is added shortly after this. |
| 1144 | */ |
| 1145 | wpabuf_free(hapd->mesh_pending_auth); |
| 1146 | hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len); |
| 1147 | os_get_reltime(&hapd->mesh_pending_auth_time); |
| 1148 | return; |
| 1149 | } |
| 1150 | #endif /* CONFIG_MESH */ |
| 1151 | |
| 1152 | sta = ap_sta_add(hapd, mgmt->sa); |
| 1153 | if (!sta) { |
| 1154 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 1155 | goto fail; |
| 1156 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1157 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1158 | sta->last_seq_ctrl = seq_ctrl; |
| 1159 | sta->last_subtype = WLAN_FC_STYPE_AUTH; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1160 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1161 | if (vlan_id.notempty && |
| 1162 | !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) { |
| 1163 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
| 1164 | HOSTAPD_LEVEL_INFO, |
| 1165 | "Invalid VLAN %d%s received from RADIUS server", |
| 1166 | vlan_id.untagged, |
| 1167 | vlan_id.tagged[0] ? "+" : ""); |
| 1168 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1169 | goto fail; |
| 1170 | } |
| 1171 | if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) { |
| 1172 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1173 | goto fail; |
| 1174 | } |
| 1175 | if (sta->vlan_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1176 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
| 1177 | HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1178 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1179 | hostapd_free_psk_list(sta->psk); |
| 1180 | if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) { |
| 1181 | sta->psk = psk; |
| 1182 | psk = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1183 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1184 | sta->psk = NULL; |
| 1185 | } |
| 1186 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1187 | sta->identity = identity; |
| 1188 | identity = NULL; |
| 1189 | sta->radius_cui = radius_cui; |
| 1190 | radius_cui = NULL; |
| 1191 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1192 | sta->flags &= ~WLAN_STA_PREAUTH; |
| 1193 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); |
| 1194 | |
| 1195 | if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval) |
| 1196 | sta->acct_interim_interval = acct_interim_interval; |
| 1197 | if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT) |
| 1198 | ap_sta_session_timeout(hapd, sta, session_timeout); |
| 1199 | else |
| 1200 | ap_sta_no_session_timeout(hapd, sta); |
| 1201 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1202 | /* |
| 1203 | * If the driver supports full AP client state, add a station to the |
| 1204 | * driver before sending authentication reply to make sure the driver |
| 1205 | * has resources, and not to go through the entire authentication and |
| 1206 | * association handshake, and fail it at the end. |
| 1207 | * |
| 1208 | * If this is not the first transaction, in a multi-step authentication |
| 1209 | * algorithm, the station already exists in the driver |
| 1210 | * (sta->added_unassoc = 1) so skip it. |
| 1211 | * |
| 1212 | * In mesh mode, the station was already added to the driver when the |
| 1213 | * NEW_PEER_CANDIDATE event is received. |
| 1214 | */ |
| 1215 | if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) && |
| 1216 | !(hapd->conf->mesh & MESH_ENABLED) && |
| 1217 | !(sta->added_unassoc)) { |
| 1218 | /* |
| 1219 | * If a station that is already associated to the AP, is trying |
| 1220 | * to authenticate again, remove the STA entry, in order to make |
| 1221 | * sure the STA PS state gets cleared and configuration gets |
| 1222 | * updated. To handle this, station's added_unassoc flag is |
| 1223 | * cleared once the station has completed association. |
| 1224 | */ |
| 1225 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 1226 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH | |
| 1227 | WLAN_STA_AUTHORIZED); |
| 1228 | |
| 1229 | if (hostapd_sta_add(hapd, sta->addr, 0, 0, 0, 0, 0, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1230 | NULL, NULL, sta->flags, 0, 0, 0, 0)) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1231 | hostapd_logger(hapd, sta->addr, |
| 1232 | HOSTAPD_MODULE_IEEE80211, |
| 1233 | HOSTAPD_LEVEL_NOTICE, |
| 1234 | "Could not add STA to kernel driver"); |
| 1235 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 1236 | goto fail; |
| 1237 | } |
| 1238 | |
| 1239 | sta->added_unassoc = 1; |
| 1240 | } |
| 1241 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1242 | switch (auth_alg) { |
| 1243 | case WLAN_AUTH_OPEN: |
| 1244 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1245 | HOSTAPD_LEVEL_DEBUG, |
| 1246 | "authentication OK (open system)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1247 | sta->flags |= WLAN_STA_AUTH; |
| 1248 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 1249 | sta->auth_alg = WLAN_AUTH_OPEN; |
| 1250 | mlme_authenticate_indication(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1251 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1252 | #ifndef CONFIG_NO_RC4 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1253 | case WLAN_AUTH_SHARED_KEY: |
| 1254 | resp = auth_shared_key(hapd, sta, auth_transaction, challenge, |
| 1255 | fc & WLAN_FC_ISWEP); |
| 1256 | sta->auth_alg = WLAN_AUTH_SHARED_KEY; |
| 1257 | mlme_authenticate_indication(hapd, sta); |
| 1258 | if (sta->challenge && auth_transaction == 1) { |
| 1259 | resp_ies[0] = WLAN_EID_CHALLENGE; |
| 1260 | resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN; |
| 1261 | os_memcpy(resp_ies + 2, sta->challenge, |
| 1262 | WLAN_AUTH_CHALLENGE_LEN); |
| 1263 | resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN; |
| 1264 | } |
| 1265 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1266 | #endif /* CONFIG_NO_RC4 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1267 | #ifdef CONFIG_IEEE80211R |
| 1268 | case WLAN_AUTH_FT: |
| 1269 | sta->auth_alg = WLAN_AUTH_FT; |
| 1270 | if (sta->wpa_sm == NULL) |
| 1271 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1272 | sta->addr, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1273 | if (sta->wpa_sm == NULL) { |
| 1274 | wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA " |
| 1275 | "state machine"); |
| 1276 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1277 | goto fail; |
| 1278 | } |
| 1279 | wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid, |
| 1280 | auth_transaction, mgmt->u.auth.variable, |
| 1281 | len - IEEE80211_HDRLEN - |
| 1282 | sizeof(mgmt->u.auth), |
| 1283 | handle_auth_ft_finish, hapd); |
| 1284 | /* handle_auth_ft_finish() callback will complete auth. */ |
| 1285 | return; |
| 1286 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1287 | #ifdef CONFIG_SAE |
| 1288 | case WLAN_AUTH_SAE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1289 | #ifdef CONFIG_MESH |
| 1290 | if (status_code == WLAN_STATUS_SUCCESS && |
| 1291 | hapd->conf->mesh & MESH_ENABLED) { |
| 1292 | if (sta->wpa_sm == NULL) |
| 1293 | sta->wpa_sm = |
| 1294 | wpa_auth_sta_init(hapd->wpa_auth, |
| 1295 | sta->addr, NULL); |
| 1296 | if (sta->wpa_sm == NULL) { |
| 1297 | wpa_printf(MSG_DEBUG, |
| 1298 | "SAE: Failed to initialize WPA state machine"); |
| 1299 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1300 | goto fail; |
| 1301 | } |
| 1302 | } |
| 1303 | #endif /* CONFIG_MESH */ |
| 1304 | handle_auth_sae(hapd, sta, mgmt, len, auth_transaction, |
| 1305 | status_code); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1306 | return; |
| 1307 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | fail: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1311 | os_free(identity); |
| 1312 | os_free(radius_cui); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1313 | hostapd_free_psk_list(psk); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1314 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1315 | reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg, |
| 1316 | auth_transaction + 1, resp, resp_ies, |
| 1317 | resp_ies_len); |
| 1318 | |
| 1319 | if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS || |
| 1320 | reply_res != WLAN_STATUS_SUCCESS)) { |
| 1321 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 1322 | sta->added_unassoc = 0; |
| 1323 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1327 | int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1328 | { |
| 1329 | int i, j = 32, aid; |
| 1330 | |
| 1331 | /* get a unique AID */ |
| 1332 | if (sta->aid > 0) { |
| 1333 | wpa_printf(MSG_DEBUG, " old AID %d", sta->aid); |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
| 1337 | for (i = 0; i < AID_WORDS; i++) { |
| 1338 | if (hapd->sta_aid[i] == (u32) -1) |
| 1339 | continue; |
| 1340 | for (j = 0; j < 32; j++) { |
| 1341 | if (!(hapd->sta_aid[i] & BIT(j))) |
| 1342 | break; |
| 1343 | } |
| 1344 | if (j < 32) |
| 1345 | break; |
| 1346 | } |
| 1347 | if (j == 32) |
| 1348 | return -1; |
| 1349 | aid = i * 32 + j + 1; |
| 1350 | if (aid > 2007) |
| 1351 | return -1; |
| 1352 | |
| 1353 | sta->aid = aid; |
| 1354 | hapd->sta_aid[i] |= BIT(j); |
| 1355 | wpa_printf(MSG_DEBUG, " new AID %d", sta->aid); |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
| 1359 | |
| 1360 | static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta, |
| 1361 | const u8 *ssid_ie, size_t ssid_ie_len) |
| 1362 | { |
| 1363 | if (ssid_ie == NULL) |
| 1364 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1365 | |
| 1366 | if (ssid_ie_len != hapd->conf->ssid.ssid_len || |
| 1367 | os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1368 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1369 | HOSTAPD_LEVEL_INFO, |
| 1370 | "Station tried to associate with unknown SSID " |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 1371 | "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1372 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1373 | } |
| 1374 | |
| 1375 | return WLAN_STATUS_SUCCESS; |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta, |
| 1380 | const u8 *wmm_ie, size_t wmm_ie_len) |
| 1381 | { |
| 1382 | sta->flags &= ~WLAN_STA_WMM; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1383 | sta->qosinfo = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1384 | if (wmm_ie && hapd->conf->wmm_enabled) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1385 | struct wmm_information_element *wmm; |
| 1386 | |
| 1387 | if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1388 | hostapd_logger(hapd, sta->addr, |
| 1389 | HOSTAPD_MODULE_WPA, |
| 1390 | HOSTAPD_LEVEL_DEBUG, |
| 1391 | "invalid WMM element in association " |
| 1392 | "request"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1393 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1394 | } |
| 1395 | |
| 1396 | sta->flags |= WLAN_STA_WMM; |
| 1397 | wmm = (struct wmm_information_element *) wmm_ie; |
| 1398 | sta->qosinfo = wmm->qos_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1399 | } |
| 1400 | return WLAN_STATUS_SUCCESS; |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta, |
| 1405 | struct ieee802_11_elems *elems) |
| 1406 | { |
| 1407 | if (!elems->supp_rates) { |
| 1408 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1409 | HOSTAPD_LEVEL_DEBUG, |
| 1410 | "No supported rates element in AssocReq"); |
| 1411 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1412 | } |
| 1413 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1414 | if (elems->supp_rates_len + elems->ext_supp_rates_len > |
| 1415 | sizeof(sta->supported_rates)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1416 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1417 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1418 | "Invalid supported rates element length %d+%d", |
| 1419 | elems->supp_rates_len, |
| 1420 | elems->ext_supp_rates_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1421 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1422 | } |
| 1423 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1424 | sta->supported_rates_len = merge_byte_arrays( |
| 1425 | sta->supported_rates, sizeof(sta->supported_rates), |
| 1426 | elems->supp_rates, elems->supp_rates_len, |
| 1427 | elems->ext_supp_rates, elems->ext_supp_rates_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1428 | |
| 1429 | return WLAN_STATUS_SUCCESS; |
| 1430 | } |
| 1431 | |
| 1432 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1433 | static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta, |
| 1434 | const u8 *ext_capab_ie, size_t ext_capab_ie_len) |
| 1435 | { |
| 1436 | #ifdef CONFIG_INTERWORKING |
| 1437 | /* check for QoS Map support */ |
| 1438 | if (ext_capab_ie_len >= 5) { |
| 1439 | if (ext_capab_ie[4] & 0x01) |
| 1440 | sta->qos_map_enabled = 1; |
| 1441 | } |
| 1442 | #endif /* CONFIG_INTERWORKING */ |
| 1443 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1444 | if (ext_capab_ie_len > 0) |
| 1445 | sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2)); |
| 1446 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1447 | return WLAN_STATUS_SUCCESS; |
| 1448 | } |
| 1449 | |
| 1450 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1451 | static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta, |
| 1452 | const u8 *ies, size_t ies_len, int reassoc) |
| 1453 | { |
| 1454 | struct ieee802_11_elems elems; |
| 1455 | u16 resp; |
| 1456 | const u8 *wpa_ie; |
| 1457 | size_t wpa_ie_len; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1458 | const u8 *p2p_dev_addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1459 | |
| 1460 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) { |
| 1461 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1462 | HOSTAPD_LEVEL_INFO, "Station sent an invalid " |
| 1463 | "association request"); |
| 1464 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1465 | } |
| 1466 | |
| 1467 | resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len); |
| 1468 | if (resp != WLAN_STATUS_SUCCESS) |
| 1469 | return resp; |
| 1470 | resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len); |
| 1471 | if (resp != WLAN_STATUS_SUCCESS) |
| 1472 | return resp; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1473 | resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len); |
| 1474 | if (resp != WLAN_STATUS_SUCCESS) |
| 1475 | return resp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1476 | resp = copy_supp_rates(hapd, sta, &elems); |
| 1477 | if (resp != WLAN_STATUS_SUCCESS) |
| 1478 | return resp; |
| 1479 | #ifdef CONFIG_IEEE80211N |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1480 | resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1481 | if (resp != WLAN_STATUS_SUCCESS) |
| 1482 | return resp; |
| 1483 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && |
| 1484 | !(sta->flags & WLAN_STA_HT)) { |
| 1485 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1486 | HOSTAPD_LEVEL_INFO, "Station does not support " |
| 1487 | "mandatory HT PHY - reject association"); |
| 1488 | return WLAN_STATUS_ASSOC_DENIED_NO_HT; |
| 1489 | } |
| 1490 | #endif /* CONFIG_IEEE80211N */ |
| 1491 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1492 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1493 | if (hapd->iconf->ieee80211ac) { |
| 1494 | resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities); |
| 1495 | if (resp != WLAN_STATUS_SUCCESS) |
| 1496 | return resp; |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 1497 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1498 | resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif); |
| 1499 | if (resp != WLAN_STATUS_SUCCESS) |
| 1500 | return resp; |
| 1501 | } |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 1502 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1503 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && |
| 1504 | !(sta->flags & WLAN_STA_VHT)) { |
| 1505 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1506 | HOSTAPD_LEVEL_INFO, "Station does not support " |
| 1507 | "mandatory VHT PHY - reject association"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1508 | return WLAN_STATUS_ASSOC_DENIED_NO_VHT; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1509 | } |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1510 | |
| 1511 | if (hapd->conf->vendor_vht && !elems.vht_capabilities) { |
| 1512 | resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht, |
| 1513 | elems.vendor_vht_len); |
| 1514 | if (resp != WLAN_STATUS_SUCCESS) |
| 1515 | return resp; |
| 1516 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1517 | #endif /* CONFIG_IEEE80211AC */ |
| 1518 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1519 | #ifdef CONFIG_P2P |
| 1520 | if (elems.p2p) { |
| 1521 | wpabuf_free(sta->p2p_ie); |
| 1522 | sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len, |
| 1523 | P2P_IE_VENDOR_TYPE); |
| 1524 | if (sta->p2p_ie) |
| 1525 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); |
| 1526 | } else { |
| 1527 | wpabuf_free(sta->p2p_ie); |
| 1528 | sta->p2p_ie = NULL; |
| 1529 | } |
| 1530 | #endif /* CONFIG_P2P */ |
| 1531 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1532 | if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) { |
| 1533 | wpa_ie = elems.rsn_ie; |
| 1534 | wpa_ie_len = elems.rsn_ie_len; |
| 1535 | } else if ((hapd->conf->wpa & WPA_PROTO_WPA) && |
| 1536 | elems.wpa_ie) { |
| 1537 | wpa_ie = elems.wpa_ie; |
| 1538 | wpa_ie_len = elems.wpa_ie_len; |
| 1539 | } else { |
| 1540 | wpa_ie = NULL; |
| 1541 | wpa_ie_len = 0; |
| 1542 | } |
| 1543 | |
| 1544 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1545 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1546 | if (hapd->conf->wps_state && elems.wps_ie) { |
| 1547 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association " |
| 1548 | "Request - assume WPS is used"); |
| 1549 | sta->flags |= WLAN_STA_WPS; |
| 1550 | wpabuf_free(sta->wps_ie); |
| 1551 | sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, |
| 1552 | WPS_IE_VENDOR_TYPE); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1553 | if (sta->wps_ie && wps_is_20(sta->wps_ie)) { |
| 1554 | wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0"); |
| 1555 | sta->flags |= WLAN_STA_WPS2; |
| 1556 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1557 | wpa_ie = NULL; |
| 1558 | wpa_ie_len = 0; |
| 1559 | if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) { |
| 1560 | wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in " |
| 1561 | "(Re)Association Request - reject"); |
| 1562 | return WLAN_STATUS_INVALID_IE; |
| 1563 | } |
| 1564 | } else if (hapd->conf->wps_state && wpa_ie == NULL) { |
| 1565 | wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in " |
| 1566 | "(Re)Association Request - possible WPS use"); |
| 1567 | sta->flags |= WLAN_STA_MAYBE_WPS; |
| 1568 | } else |
| 1569 | #endif /* CONFIG_WPS */ |
| 1570 | if (hapd->conf->wpa && wpa_ie == NULL) { |
| 1571 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1572 | HOSTAPD_LEVEL_INFO, |
| 1573 | "No WPA/RSN IE in association request"); |
| 1574 | return WLAN_STATUS_INVALID_IE; |
| 1575 | } |
| 1576 | |
| 1577 | if (hapd->conf->wpa && wpa_ie) { |
| 1578 | int res; |
| 1579 | wpa_ie -= 2; |
| 1580 | wpa_ie_len += 2; |
| 1581 | if (sta->wpa_sm == NULL) |
| 1582 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1583 | sta->addr, |
| 1584 | p2p_dev_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1585 | if (sta->wpa_sm == NULL) { |
| 1586 | wpa_printf(MSG_WARNING, "Failed to initialize WPA " |
| 1587 | "state machine"); |
| 1588 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1589 | } |
| 1590 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, |
| 1591 | wpa_ie, wpa_ie_len, |
| 1592 | elems.mdie, elems.mdie_len); |
| 1593 | if (res == WPA_INVALID_GROUP) |
| 1594 | resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; |
| 1595 | else if (res == WPA_INVALID_PAIRWISE) |
| 1596 | resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; |
| 1597 | else if (res == WPA_INVALID_AKMP) |
| 1598 | resp = WLAN_STATUS_AKMP_NOT_VALID; |
| 1599 | else if (res == WPA_ALLOC_FAIL) |
| 1600 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1601 | #ifdef CONFIG_IEEE80211W |
| 1602 | else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) |
| 1603 | resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION; |
| 1604 | else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) |
| 1605 | resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION; |
| 1606 | #endif /* CONFIG_IEEE80211W */ |
| 1607 | else if (res == WPA_INVALID_MDIE) |
| 1608 | resp = WLAN_STATUS_INVALID_MDIE; |
| 1609 | else if (res != WPA_IE_OK) |
| 1610 | resp = WLAN_STATUS_INVALID_IE; |
| 1611 | if (resp != WLAN_STATUS_SUCCESS) |
| 1612 | return resp; |
| 1613 | #ifdef CONFIG_IEEE80211W |
| 1614 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && |
| 1615 | sta->sa_query_count > 0) |
| 1616 | ap_check_sa_query_timeout(hapd, sta); |
| 1617 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && |
| 1618 | (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) { |
| 1619 | /* |
| 1620 | * STA has already been associated with MFP and SA |
| 1621 | * Query timeout has not been reached. Reject the |
| 1622 | * association attempt temporarily and start SA Query, |
| 1623 | * if one is not pending. |
| 1624 | */ |
| 1625 | |
| 1626 | if (sta->sa_query_count == 0) |
| 1627 | ap_sta_start_sa_query(hapd, sta); |
| 1628 | |
| 1629 | return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
| 1630 | } |
| 1631 | |
| 1632 | if (wpa_auth_uses_mfp(sta->wpa_sm)) |
| 1633 | sta->flags |= WLAN_STA_MFP; |
| 1634 | else |
| 1635 | sta->flags &= ~WLAN_STA_MFP; |
| 1636 | #endif /* CONFIG_IEEE80211W */ |
| 1637 | |
| 1638 | #ifdef CONFIG_IEEE80211R |
| 1639 | if (sta->auth_alg == WLAN_AUTH_FT) { |
| 1640 | if (!reassoc) { |
| 1641 | wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried " |
| 1642 | "to use association (not " |
| 1643 | "re-association) with FT auth_alg", |
| 1644 | MAC2STR(sta->addr)); |
| 1645 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1646 | } |
| 1647 | |
| 1648 | resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies, |
| 1649 | ies_len); |
| 1650 | if (resp != WLAN_STATUS_SUCCESS) |
| 1651 | return resp; |
| 1652 | } |
| 1653 | #endif /* CONFIG_IEEE80211R */ |
| 1654 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1655 | #ifdef CONFIG_SAE |
| 1656 | if (wpa_auth_uses_sae(sta->wpa_sm) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1657 | sta->auth_alg == WLAN_AUTH_OPEN) { |
| 1658 | struct rsn_pmksa_cache_entry *sa; |
| 1659 | sa = wpa_auth_sta_get_pmksa(sta->wpa_sm); |
| 1660 | if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) { |
| 1661 | wpa_printf(MSG_DEBUG, |
| 1662 | "SAE: No PMKSA cache entry found for " |
| 1663 | MACSTR, MAC2STR(sta->addr)); |
| 1664 | return WLAN_STATUS_INVALID_PMKID; |
| 1665 | } |
| 1666 | wpa_printf(MSG_DEBUG, "SAE: " MACSTR |
| 1667 | " using PMKSA caching", MAC2STR(sta->addr)); |
| 1668 | } else if (wpa_auth_uses_sae(sta->wpa_sm) && |
| 1669 | sta->auth_alg != WLAN_AUTH_SAE && |
| 1670 | !(sta->auth_alg == WLAN_AUTH_FT && |
| 1671 | wpa_auth_uses_ft_sae(sta->wpa_sm))) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1672 | wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use " |
| 1673 | "SAE AKM after non-SAE auth_alg %u", |
| 1674 | MAC2STR(sta->addr), sta->auth_alg); |
| 1675 | return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 1676 | } |
| 1677 | #endif /* CONFIG_SAE */ |
| 1678 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1679 | #ifdef CONFIG_IEEE80211N |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1680 | if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1681 | wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) { |
| 1682 | hostapd_logger(hapd, sta->addr, |
| 1683 | HOSTAPD_MODULE_IEEE80211, |
| 1684 | HOSTAPD_LEVEL_INFO, |
| 1685 | "Station tried to use TKIP with HT " |
| 1686 | "association"); |
| 1687 | return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; |
| 1688 | } |
| 1689 | #endif /* CONFIG_IEEE80211N */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1690 | #ifdef CONFIG_HS20 |
| 1691 | } else if (hapd->conf->osen) { |
| 1692 | if (elems.osen == NULL) { |
| 1693 | hostapd_logger( |
| 1694 | hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1695 | HOSTAPD_LEVEL_INFO, |
| 1696 | "No HS 2.0 OSEN element in association request"); |
| 1697 | return WLAN_STATUS_INVALID_IE; |
| 1698 | } |
| 1699 | |
| 1700 | wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association"); |
| 1701 | if (sta->wpa_sm == NULL) |
| 1702 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
| 1703 | sta->addr, NULL); |
| 1704 | if (sta->wpa_sm == NULL) { |
| 1705 | wpa_printf(MSG_WARNING, "Failed to initialize WPA " |
| 1706 | "state machine"); |
| 1707 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1708 | } |
| 1709 | if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm, |
| 1710 | elems.osen - 2, elems.osen_len + 2) < 0) |
| 1711 | return WLAN_STATUS_INVALID_IE; |
| 1712 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1713 | } else |
| 1714 | wpa_auth_sta_no_wpa(sta->wpa_sm); |
| 1715 | |
| 1716 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1717 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len); |
| 1718 | #endif /* CONFIG_P2P */ |
| 1719 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1720 | #ifdef CONFIG_HS20 |
| 1721 | wpabuf_free(sta->hs20_ie); |
| 1722 | if (elems.hs20 && elems.hs20_len > 4) { |
| 1723 | sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4, |
| 1724 | elems.hs20_len - 4); |
| 1725 | } else |
| 1726 | sta->hs20_ie = NULL; |
| 1727 | #endif /* CONFIG_HS20 */ |
| 1728 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1729 | #ifdef CONFIG_FST |
| 1730 | wpabuf_free(sta->mb_ies); |
| 1731 | if (hapd->iface->fst) |
| 1732 | sta->mb_ies = mb_ies_by_info(&elems.mb_ies); |
| 1733 | else |
| 1734 | sta->mb_ies = NULL; |
| 1735 | #endif /* CONFIG_FST */ |
| 1736 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1737 | #ifdef CONFIG_MBO |
| 1738 | mbo_ap_check_sta_assoc(hapd, sta, &elems); |
| 1739 | |
| 1740 | if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) && |
| 1741 | elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) && |
| 1742 | hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { |
| 1743 | wpa_printf(MSG_INFO, |
| 1744 | "MBO: Reject WPA2 association without PMF"); |
| 1745 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1746 | } |
| 1747 | #endif /* CONFIG_MBO */ |
| 1748 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1749 | ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes, |
| 1750 | elems.supp_op_classes_len); |
| 1751 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1752 | if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) && |
| 1753 | elems.rrm_enabled && |
| 1754 | elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa)) |
| 1755 | os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled, |
| 1756 | sizeof(sta->rrm_enabled_capa)); |
| 1757 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1758 | return WLAN_STATUS_SUCCESS; |
| 1759 | } |
| 1760 | |
| 1761 | |
| 1762 | static void send_deauth(struct hostapd_data *hapd, const u8 *addr, |
| 1763 | u16 reason_code) |
| 1764 | { |
| 1765 | int send_len; |
| 1766 | struct ieee80211_mgmt reply; |
| 1767 | |
| 1768 | os_memset(&reply, 0, sizeof(reply)); |
| 1769 | reply.frame_control = |
| 1770 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH); |
| 1771 | os_memcpy(reply.da, addr, ETH_ALEN); |
| 1772 | os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN); |
| 1773 | os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN); |
| 1774 | |
| 1775 | send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth); |
| 1776 | reply.u.deauth.reason_code = host_to_le16(reason_code); |
| 1777 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1778 | if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1779 | wpa_printf(MSG_INFO, "Failed to send deauth: %s", |
| 1780 | strerror(errno)); |
| 1781 | } |
| 1782 | |
| 1783 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1784 | static int add_associated_sta(struct hostapd_data *hapd, |
| 1785 | struct sta_info *sta) |
| 1786 | { |
| 1787 | struct ieee80211_ht_capabilities ht_cap; |
| 1788 | struct ieee80211_vht_capabilities vht_cap; |
| 1789 | |
| 1790 | /* |
| 1791 | * Remove the STA entry to ensure the STA PS state gets cleared and |
| 1792 | * configuration gets updated. This is relevant for cases, such as |
| 1793 | * FT-over-the-DS, where a station re-associates back to the same AP but |
| 1794 | * skips the authentication flow, or if working with a driver that |
| 1795 | * does not support full AP client state. |
| 1796 | */ |
| 1797 | if (!sta->added_unassoc) |
| 1798 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 1799 | |
| 1800 | #ifdef CONFIG_IEEE80211N |
| 1801 | if (sta->flags & WLAN_STA_HT) |
| 1802 | hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap); |
| 1803 | #endif /* CONFIG_IEEE80211N */ |
| 1804 | #ifdef CONFIG_IEEE80211AC |
| 1805 | if (sta->flags & WLAN_STA_VHT) |
| 1806 | hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap); |
| 1807 | #endif /* CONFIG_IEEE80211AC */ |
| 1808 | |
| 1809 | /* |
| 1810 | * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags |
| 1811 | * will be set when the ACK frame for the (Re)Association Response frame |
| 1812 | * is processed (TX status driver event). |
| 1813 | */ |
| 1814 | if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability, |
| 1815 | sta->supported_rates, sta->supported_rates_len, |
| 1816 | sta->listen_interval, |
| 1817 | sta->flags & WLAN_STA_HT ? &ht_cap : NULL, |
| 1818 | sta->flags & WLAN_STA_VHT ? &vht_cap : NULL, |
| 1819 | sta->flags | WLAN_STA_ASSOC, sta->qosinfo, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1820 | sta->vht_opmode, sta->p2p_ie ? 1 : 0, |
| 1821 | sta->added_unassoc)) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1822 | hostapd_logger(hapd, sta->addr, |
| 1823 | HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE, |
| 1824 | "Could not %s STA to kernel driver", |
| 1825 | sta->added_unassoc ? "set" : "add"); |
| 1826 | |
| 1827 | if (sta->added_unassoc) { |
| 1828 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 1829 | sta->added_unassoc = 0; |
| 1830 | } |
| 1831 | |
| 1832 | return -1; |
| 1833 | } |
| 1834 | |
| 1835 | sta->added_unassoc = 0; |
| 1836 | |
| 1837 | return 0; |
| 1838 | } |
| 1839 | |
| 1840 | |
| 1841 | static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta, |
| 1842 | u16 status_code, int reassoc, const u8 *ies, |
| 1843 | size_t ies_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1844 | { |
| 1845 | int send_len; |
| 1846 | u8 buf[sizeof(struct ieee80211_mgmt) + 1024]; |
| 1847 | struct ieee80211_mgmt *reply; |
| 1848 | u8 *p; |
| 1849 | |
| 1850 | os_memset(buf, 0, sizeof(buf)); |
| 1851 | reply = (struct ieee80211_mgmt *) buf; |
| 1852 | reply->frame_control = |
| 1853 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 1854 | (reassoc ? WLAN_FC_STYPE_REASSOC_RESP : |
| 1855 | WLAN_FC_STYPE_ASSOC_RESP)); |
| 1856 | os_memcpy(reply->da, sta->addr, ETH_ALEN); |
| 1857 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); |
| 1858 | os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN); |
| 1859 | |
| 1860 | send_len = IEEE80211_HDRLEN; |
| 1861 | send_len += sizeof(reply->u.assoc_resp); |
| 1862 | reply->u.assoc_resp.capab_info = |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1863 | host_to_le16(hostapd_own_capab_info(hapd)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1864 | reply->u.assoc_resp.status_code = host_to_le16(status_code); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 1865 | reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1866 | /* Supported rates */ |
| 1867 | p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable); |
| 1868 | /* Extended supported rates */ |
| 1869 | p = hostapd_eid_ext_supp_rates(hapd, p); |
| 1870 | |
| 1871 | #ifdef CONFIG_IEEE80211R |
| 1872 | if (status_code == WLAN_STATUS_SUCCESS) { |
| 1873 | /* IEEE 802.11r: Mobility Domain Information, Fast BSS |
| 1874 | * Transition Information, RSN, [RIC Response] */ |
| 1875 | p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p, |
| 1876 | buf + sizeof(buf) - p, |
| 1877 | sta->auth_alg, ies, ies_len); |
| 1878 | } |
| 1879 | #endif /* CONFIG_IEEE80211R */ |
| 1880 | |
| 1881 | #ifdef CONFIG_IEEE80211W |
| 1882 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY) |
| 1883 | p = hostapd_eid_assoc_comeback_time(hapd, sta, p); |
| 1884 | #endif /* CONFIG_IEEE80211W */ |
| 1885 | |
| 1886 | #ifdef CONFIG_IEEE80211N |
| 1887 | p = hostapd_eid_ht_capabilities(hapd, p); |
| 1888 | p = hostapd_eid_ht_operation(hapd, p); |
| 1889 | #endif /* CONFIG_IEEE80211N */ |
| 1890 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1891 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1892 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) { |
| 1893 | p = hostapd_eid_vht_capabilities(hapd, p); |
| 1894 | p = hostapd_eid_vht_operation(hapd, p); |
| 1895 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1896 | #endif /* CONFIG_IEEE80211AC */ |
| 1897 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1898 | p = hostapd_eid_ext_capab(hapd, p); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1899 | p = hostapd_eid_bss_max_idle_period(hapd, p); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1900 | if (sta->qos_map_enabled) |
| 1901 | p = hostapd_eid_qos_map_set(hapd, p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1902 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1903 | #ifdef CONFIG_FST |
| 1904 | if (hapd->iface->fst_ies) { |
| 1905 | os_memcpy(p, wpabuf_head(hapd->iface->fst_ies), |
| 1906 | wpabuf_len(hapd->iface->fst_ies)); |
| 1907 | p += wpabuf_len(hapd->iface->fst_ies); |
| 1908 | } |
| 1909 | #endif /* CONFIG_FST */ |
| 1910 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1911 | #ifdef CONFIG_IEEE80211AC |
| 1912 | if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT)) |
| 1913 | p = hostapd_eid_vendor_vht(hapd, p); |
| 1914 | #endif /* CONFIG_IEEE80211AC */ |
| 1915 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1916 | if (sta->flags & WLAN_STA_WMM) |
| 1917 | p = hostapd_eid_wmm(hapd, p); |
| 1918 | |
| 1919 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1920 | if ((sta->flags & WLAN_STA_WPS) || |
| 1921 | ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1922 | struct wpabuf *wps = wps_build_assoc_resp_ie(); |
| 1923 | if (wps) { |
| 1924 | os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps)); |
| 1925 | p += wpabuf_len(wps); |
| 1926 | wpabuf_free(wps); |
| 1927 | } |
| 1928 | } |
| 1929 | #endif /* CONFIG_WPS */ |
| 1930 | |
| 1931 | #ifdef CONFIG_P2P |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1932 | if (sta->p2p_ie && hapd->p2p_group) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1933 | struct wpabuf *p2p_resp_ie; |
| 1934 | enum p2p_status_code status; |
| 1935 | switch (status_code) { |
| 1936 | case WLAN_STATUS_SUCCESS: |
| 1937 | status = P2P_SC_SUCCESS; |
| 1938 | break; |
| 1939 | case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA: |
| 1940 | status = P2P_SC_FAIL_LIMIT_REACHED; |
| 1941 | break; |
| 1942 | default: |
| 1943 | status = P2P_SC_FAIL_INVALID_PARAMS; |
| 1944 | break; |
| 1945 | } |
| 1946 | p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status); |
| 1947 | if (p2p_resp_ie) { |
| 1948 | os_memcpy(p, wpabuf_head(p2p_resp_ie), |
| 1949 | wpabuf_len(p2p_resp_ie)); |
| 1950 | p += wpabuf_len(p2p_resp_ie); |
| 1951 | wpabuf_free(p2p_resp_ie); |
| 1952 | } |
| 1953 | } |
| 1954 | #endif /* CONFIG_P2P */ |
| 1955 | |
| 1956 | #ifdef CONFIG_P2P_MANAGER |
| 1957 | if (hapd->conf->p2p & P2P_MANAGE) |
| 1958 | p = hostapd_eid_p2p_manage(hapd, p); |
| 1959 | #endif /* CONFIG_P2P_MANAGER */ |
| 1960 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1961 | p = hostapd_eid_mbo(hapd, p, buf + sizeof(buf) - p); |
| 1962 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1963 | if (hapd->conf->assocresp_elements && |
| 1964 | (size_t) (buf + sizeof(buf) - p) >= |
| 1965 | wpabuf_len(hapd->conf->assocresp_elements)) { |
| 1966 | os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements), |
| 1967 | wpabuf_len(hapd->conf->assocresp_elements)); |
| 1968 | p += wpabuf_len(hapd->conf->assocresp_elements); |
| 1969 | } |
| 1970 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1971 | send_len += p - reply->u.assoc_resp.variable; |
| 1972 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1973 | if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1974 | wpa_printf(MSG_INFO, "Failed to send assoc resp: %s", |
| 1975 | strerror(errno)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1976 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1977 | } |
| 1978 | |
| 1979 | return WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | |
| 1983 | static void handle_assoc(struct hostapd_data *hapd, |
| 1984 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 1985 | int reassoc) |
| 1986 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1987 | u16 capab_info, listen_interval, seq_ctrl, fc; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1988 | u16 resp = WLAN_STATUS_SUCCESS, reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1989 | const u8 *pos; |
| 1990 | int left, i; |
| 1991 | struct sta_info *sta; |
| 1992 | |
| 1993 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) : |
| 1994 | sizeof(mgmt->u.assoc_req))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1995 | wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)", |
| 1996 | reassoc, (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1997 | return; |
| 1998 | } |
| 1999 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2000 | #ifdef CONFIG_TESTING_OPTIONS |
| 2001 | if (reassoc) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2002 | if (hapd->iconf->ignore_reassoc_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2003 | drand48() < hapd->iconf->ignore_reassoc_probability) { |
| 2004 | wpa_printf(MSG_INFO, |
| 2005 | "TESTING: ignoring reassoc request from " |
| 2006 | MACSTR, MAC2STR(mgmt->sa)); |
| 2007 | return; |
| 2008 | } |
| 2009 | } else { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2010 | if (hapd->iconf->ignore_assoc_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2011 | drand48() < hapd->iconf->ignore_assoc_probability) { |
| 2012 | wpa_printf(MSG_INFO, |
| 2013 | "TESTING: ignoring assoc request from " |
| 2014 | MACSTR, MAC2STR(mgmt->sa)); |
| 2015 | return; |
| 2016 | } |
| 2017 | } |
| 2018 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2019 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2020 | fc = le_to_host16(mgmt->frame_control); |
| 2021 | seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
| 2022 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2023 | if (reassoc) { |
| 2024 | capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info); |
| 2025 | listen_interval = le_to_host16( |
| 2026 | mgmt->u.reassoc_req.listen_interval); |
| 2027 | wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR |
| 2028 | " capab_info=0x%02x listen_interval=%d current_ap=" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2029 | MACSTR " seq_ctrl=0x%x%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2030 | MAC2STR(mgmt->sa), capab_info, listen_interval, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2031 | MAC2STR(mgmt->u.reassoc_req.current_ap), |
| 2032 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2033 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req)); |
| 2034 | pos = mgmt->u.reassoc_req.variable; |
| 2035 | } else { |
| 2036 | capab_info = le_to_host16(mgmt->u.assoc_req.capab_info); |
| 2037 | listen_interval = le_to_host16( |
| 2038 | mgmt->u.assoc_req.listen_interval); |
| 2039 | wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2040 | " capab_info=0x%02x listen_interval=%d " |
| 2041 | "seq_ctrl=0x%x%s", |
| 2042 | MAC2STR(mgmt->sa), capab_info, listen_interval, |
| 2043 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2044 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req)); |
| 2045 | pos = mgmt->u.assoc_req.variable; |
| 2046 | } |
| 2047 | |
| 2048 | sta = ap_get_sta(hapd, mgmt->sa); |
| 2049 | #ifdef CONFIG_IEEE80211R |
| 2050 | if (sta && sta->auth_alg == WLAN_AUTH_FT && |
| 2051 | (sta->flags & WLAN_STA_AUTH) == 0) { |
| 2052 | wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate " |
| 2053 | "prior to authentication since it is using " |
| 2054 | "over-the-DS FT", MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2055 | |
| 2056 | /* |
| 2057 | * Mark station as authenticated, to avoid adding station |
| 2058 | * entry in the driver as associated and not authenticated |
| 2059 | */ |
| 2060 | sta->flags |= WLAN_STA_AUTH; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2061 | } else |
| 2062 | #endif /* CONFIG_IEEE80211R */ |
| 2063 | if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) { |
| 2064 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 2065 | HOSTAPD_LEVEL_INFO, "Station tried to " |
| 2066 | "associate before authentication " |
| 2067 | "(aid=%d flags=0x%x)", |
| 2068 | sta ? sta->aid : -1, |
| 2069 | sta ? sta->flags : 0); |
| 2070 | send_deauth(hapd, mgmt->sa, |
| 2071 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); |
| 2072 | return; |
| 2073 | } |
| 2074 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2075 | if ((fc & WLAN_FC_RETRY) && |
| 2076 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && |
| 2077 | sta->last_seq_ctrl == seq_ctrl && |
| 2078 | sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ : |
| 2079 | WLAN_FC_STYPE_ASSOC_REQ) { |
| 2080 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2081 | HOSTAPD_LEVEL_DEBUG, |
| 2082 | "Drop repeated association frame seq_ctrl=0x%x", |
| 2083 | seq_ctrl); |
| 2084 | return; |
| 2085 | } |
| 2086 | sta->last_seq_ctrl = seq_ctrl; |
| 2087 | sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ : |
| 2088 | WLAN_FC_STYPE_ASSOC_REQ; |
| 2089 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2090 | if (hapd->tkip_countermeasures) { |
| 2091 | resp = WLAN_REASON_MICHAEL_MIC_FAILURE; |
| 2092 | goto fail; |
| 2093 | } |
| 2094 | |
| 2095 | if (listen_interval > hapd->conf->max_listen_interval) { |
| 2096 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 2097 | HOSTAPD_LEVEL_DEBUG, |
| 2098 | "Too large Listen Interval (%d)", |
| 2099 | listen_interval); |
| 2100 | resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE; |
| 2101 | goto fail; |
| 2102 | } |
| 2103 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2104 | #ifdef CONFIG_MBO |
| 2105 | if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) { |
| 2106 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 2107 | goto fail; |
| 2108 | } |
| 2109 | #endif /* CONFIG_MBO */ |
| 2110 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2111 | /* |
| 2112 | * sta->capability is used in check_assoc_ies() for RRM enabled |
| 2113 | * capability element. |
| 2114 | */ |
| 2115 | sta->capability = capab_info; |
| 2116 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2117 | /* followed by SSID and Supported rates; and HT capabilities if 802.11n |
| 2118 | * is used */ |
| 2119 | resp = check_assoc_ies(hapd, sta, pos, left, reassoc); |
| 2120 | if (resp != WLAN_STATUS_SUCCESS) |
| 2121 | goto fail; |
| 2122 | |
| 2123 | if (hostapd_get_aid(hapd, sta) < 0) { |
| 2124 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 2125 | HOSTAPD_LEVEL_INFO, "No room for more AIDs"); |
| 2126 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 2127 | goto fail; |
| 2128 | } |
| 2129 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2130 | sta->listen_interval = listen_interval; |
| 2131 | |
| 2132 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 2133 | sta->flags |= WLAN_STA_NONERP; |
| 2134 | for (i = 0; i < sta->supported_rates_len; i++) { |
| 2135 | if ((sta->supported_rates[i] & 0x7f) > 22) { |
| 2136 | sta->flags &= ~WLAN_STA_NONERP; |
| 2137 | break; |
| 2138 | } |
| 2139 | } |
| 2140 | if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) { |
| 2141 | sta->nonerp_set = 1; |
| 2142 | hapd->iface->num_sta_non_erp++; |
| 2143 | if (hapd->iface->num_sta_non_erp == 1) |
| 2144 | ieee802_11_set_beacons(hapd->iface); |
| 2145 | } |
| 2146 | |
| 2147 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) && |
| 2148 | !sta->no_short_slot_time_set) { |
| 2149 | sta->no_short_slot_time_set = 1; |
| 2150 | hapd->iface->num_sta_no_short_slot_time++; |
| 2151 | if (hapd->iface->current_mode->mode == |
| 2152 | HOSTAPD_MODE_IEEE80211G && |
| 2153 | hapd->iface->num_sta_no_short_slot_time == 1) |
| 2154 | ieee802_11_set_beacons(hapd->iface); |
| 2155 | } |
| 2156 | |
| 2157 | if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 2158 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; |
| 2159 | else |
| 2160 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; |
| 2161 | |
| 2162 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && |
| 2163 | !sta->no_short_preamble_set) { |
| 2164 | sta->no_short_preamble_set = 1; |
| 2165 | hapd->iface->num_sta_no_short_preamble++; |
| 2166 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G |
| 2167 | && hapd->iface->num_sta_no_short_preamble == 1) |
| 2168 | ieee802_11_set_beacons(hapd->iface); |
| 2169 | } |
| 2170 | |
| 2171 | #ifdef CONFIG_IEEE80211N |
| 2172 | update_ht_state(hapd, sta); |
| 2173 | #endif /* CONFIG_IEEE80211N */ |
| 2174 | |
| 2175 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2176 | HOSTAPD_LEVEL_DEBUG, |
| 2177 | "association OK (aid %d)", sta->aid); |
| 2178 | /* Station will be marked associated, after it acknowledges AssocResp |
| 2179 | */ |
| 2180 | sta->flags |= WLAN_STA_ASSOC_REQ_OK; |
| 2181 | |
| 2182 | #ifdef CONFIG_IEEE80211W |
| 2183 | if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) { |
| 2184 | wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out " |
| 2185 | "SA Query procedure", reassoc ? "re" : ""); |
| 2186 | /* TODO: Send a protected Disassociate frame to the STA using |
| 2187 | * the old key and Reason Code "Previous Authentication no |
| 2188 | * longer valid". Make sure this is only sent protected since |
| 2189 | * unprotected frame would be received by the STA that is now |
| 2190 | * trying to associate. |
| 2191 | */ |
| 2192 | } |
| 2193 | #endif /* CONFIG_IEEE80211W */ |
| 2194 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2195 | /* Make sure that the previously registered inactivity timer will not |
| 2196 | * remove the STA immediately. */ |
| 2197 | sta->timeout_next = STA_NULLFUNC; |
| 2198 | |
| 2199 | fail: |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2200 | /* |
| 2201 | * In case of a successful response, add the station to the driver. |
| 2202 | * Otherwise, the kernel may ignore Data frames before we process the |
| 2203 | * ACK frame (TX status). In case of a failure, this station will be |
| 2204 | * removed. |
| 2205 | * |
| 2206 | * Note that this is not compliant with the IEEE 802.11 standard that |
| 2207 | * states that a non-AP station should transition into the |
| 2208 | * authenticated/associated state only after the station acknowledges |
| 2209 | * the (Re)Association Response frame. However, still do this as: |
| 2210 | * |
| 2211 | * 1. In case the station does not acknowledge the (Re)Association |
| 2212 | * Response frame, it will be removed. |
| 2213 | * 2. Data frames will be dropped in the kernel until the station is |
| 2214 | * set into authorized state, and there are no significant known |
| 2215 | * issues with processing other non-Data Class 3 frames during this |
| 2216 | * window. |
| 2217 | */ |
| 2218 | if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta)) |
| 2219 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 2220 | |
| 2221 | reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left); |
| 2222 | |
| 2223 | /* |
| 2224 | * Remove the station in case tranmission of a success response fails |
| 2225 | * (the STA was added associated to the driver) or if the station was |
| 2226 | * previously added unassociated. |
| 2227 | */ |
| 2228 | if ((reply_res != WLAN_STATUS_SUCCESS && |
| 2229 | resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) { |
| 2230 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 2231 | sta->added_unassoc = 0; |
| 2232 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | |
| 2236 | static void handle_disassoc(struct hostapd_data *hapd, |
| 2237 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 2238 | { |
| 2239 | struct sta_info *sta; |
| 2240 | |
| 2241 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2242 | wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)", |
| 2243 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2244 | return; |
| 2245 | } |
| 2246 | |
| 2247 | wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d", |
| 2248 | MAC2STR(mgmt->sa), |
| 2249 | le_to_host16(mgmt->u.disassoc.reason_code)); |
| 2250 | |
| 2251 | sta = ap_get_sta(hapd, mgmt->sa); |
| 2252 | if (sta == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2253 | wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated", |
| 2254 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2255 | return; |
| 2256 | } |
| 2257 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2258 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2259 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2260 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2261 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); |
| 2262 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2263 | HOSTAPD_LEVEL_INFO, "disassociated"); |
| 2264 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 2265 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 2266 | /* Stop Accounting and IEEE 802.1X sessions, but leave the STA |
| 2267 | * authenticated. */ |
| 2268 | accounting_sta_stop(hapd, sta); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 2269 | ieee802_1x_free_station(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2270 | if (sta->ipaddr) |
| 2271 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
| 2272 | ap_sta_ip6addr_del(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2273 | hostapd_drv_sta_remove(hapd, sta->addr); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2274 | sta->added_unassoc = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2275 | |
| 2276 | if (sta->timeout_next == STA_NULLFUNC || |
| 2277 | sta->timeout_next == STA_DISASSOC) { |
| 2278 | sta->timeout_next = STA_DEAUTH; |
| 2279 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 2280 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, |
| 2281 | hapd, sta); |
| 2282 | } |
| 2283 | |
| 2284 | mlme_disassociate_indication( |
| 2285 | hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code)); |
| 2286 | } |
| 2287 | |
| 2288 | |
| 2289 | static void handle_deauth(struct hostapd_data *hapd, |
| 2290 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 2291 | { |
| 2292 | struct sta_info *sta; |
| 2293 | |
| 2294 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2295 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short " |
| 2296 | "payload (len=%lu)", (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2297 | return; |
| 2298 | } |
| 2299 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2300 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2301 | " reason_code=%d", |
| 2302 | MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code)); |
| 2303 | |
| 2304 | sta = ap_get_sta(hapd, mgmt->sa); |
| 2305 | if (sta == NULL) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2306 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying " |
| 2307 | "to deauthenticate, but it is not authenticated", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2308 | MAC2STR(mgmt->sa)); |
| 2309 | return; |
| 2310 | } |
| 2311 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2312 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2313 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2314 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | |
| 2315 | WLAN_STA_ASSOC_REQ_OK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2316 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
| 2317 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2318 | HOSTAPD_LEVEL_DEBUG, "deauthenticated"); |
| 2319 | mlme_deauthenticate_indication( |
| 2320 | hapd, sta, le_to_host16(mgmt->u.deauth.reason_code)); |
| 2321 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 2322 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 2323 | ap_free_sta(hapd, sta); |
| 2324 | } |
| 2325 | |
| 2326 | |
| 2327 | static void handle_beacon(struct hostapd_data *hapd, |
| 2328 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 2329 | struct hostapd_frame_info *fi) |
| 2330 | { |
| 2331 | struct ieee802_11_elems elems; |
| 2332 | |
| 2333 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2334 | wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)", |
| 2335 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2336 | return; |
| 2337 | } |
| 2338 | |
| 2339 | (void) ieee802_11_parse_elems(mgmt->u.beacon.variable, |
| 2340 | len - (IEEE80211_HDRLEN + |
| 2341 | sizeof(mgmt->u.beacon)), &elems, |
| 2342 | 0); |
| 2343 | |
| 2344 | ap_list_process_beacon(hapd->iface, mgmt, &elems, fi); |
| 2345 | } |
| 2346 | |
| 2347 | |
| 2348 | #ifdef CONFIG_IEEE80211W |
| 2349 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2350 | static int hostapd_sa_query_action(struct hostapd_data *hapd, |
| 2351 | const struct ieee80211_mgmt *mgmt, |
| 2352 | size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2353 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2354 | const u8 *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2355 | |
| 2356 | end = mgmt->u.action.u.sa_query_resp.trans_id + |
| 2357 | WLAN_SA_QUERY_TR_ID_LEN; |
| 2358 | if (((u8 *) mgmt) + len < end) { |
| 2359 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action " |
| 2360 | "frame (len=%lu)", (unsigned long) len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2361 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2364 | ieee802_11_sa_query_action(hapd, mgmt->sa, |
| 2365 | mgmt->u.action.u.sa_query_resp.action, |
| 2366 | mgmt->u.action.u.sa_query_resp.trans_id); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2367 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | |
| 2371 | static int robust_action_frame(u8 category) |
| 2372 | { |
| 2373 | return category != WLAN_ACTION_PUBLIC && |
| 2374 | category != WLAN_ACTION_HT; |
| 2375 | } |
| 2376 | #endif /* CONFIG_IEEE80211W */ |
| 2377 | |
| 2378 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2379 | static int handle_action(struct hostapd_data *hapd, |
| 2380 | const struct ieee80211_mgmt *mgmt, size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | { |
| 2382 | struct sta_info *sta; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2383 | sta = ap_get_sta(hapd, mgmt->sa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2384 | |
| 2385 | if (len < IEEE80211_HDRLEN + 1) { |
| 2386 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 2387 | HOSTAPD_LEVEL_DEBUG, |
| 2388 | "handle_action - too short payload (len=%lu)", |
| 2389 | (unsigned long) len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2390 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2391 | } |
| 2392 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2393 | if (mgmt->u.action.category != WLAN_ACTION_PUBLIC && |
| 2394 | (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) { |
| 2395 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action " |
| 2396 | "frame (category=%u) from unassociated STA " MACSTR, |
| 2397 | MAC2STR(mgmt->sa), mgmt->u.action.category); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2398 | return 0; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2399 | } |
| 2400 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2401 | #ifdef CONFIG_IEEE80211W |
| 2402 | if (sta && (sta->flags & WLAN_STA_MFP) && |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2403 | !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) && |
| 2404 | robust_action_frame(mgmt->u.action.category)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2405 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 2406 | HOSTAPD_LEVEL_DEBUG, |
| 2407 | "Dropped unprotected Robust Action frame from " |
| 2408 | "an MFP STA"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2409 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2410 | } |
| 2411 | #endif /* CONFIG_IEEE80211W */ |
| 2412 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2413 | if (sta) { |
| 2414 | u16 fc = le_to_host16(mgmt->frame_control); |
| 2415 | u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
| 2416 | |
| 2417 | if ((fc & WLAN_FC_RETRY) && |
| 2418 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && |
| 2419 | sta->last_seq_ctrl == seq_ctrl && |
| 2420 | sta->last_subtype == WLAN_FC_STYPE_ACTION) { |
| 2421 | hostapd_logger(hapd, sta->addr, |
| 2422 | HOSTAPD_MODULE_IEEE80211, |
| 2423 | HOSTAPD_LEVEL_DEBUG, |
| 2424 | "Drop repeated action frame seq_ctrl=0x%x", |
| 2425 | seq_ctrl); |
| 2426 | return 1; |
| 2427 | } |
| 2428 | |
| 2429 | sta->last_seq_ctrl = seq_ctrl; |
| 2430 | sta->last_subtype = WLAN_FC_STYPE_ACTION; |
| 2431 | } |
| 2432 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2433 | switch (mgmt->u.action.category) { |
| 2434 | #ifdef CONFIG_IEEE80211R |
| 2435 | case WLAN_ACTION_FT: |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2436 | if (!sta || |
| 2437 | wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2438 | len - IEEE80211_HDRLEN)) |
| 2439 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2440 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2441 | #endif /* CONFIG_IEEE80211R */ |
| 2442 | case WLAN_ACTION_WMM: |
| 2443 | hostapd_wmm_action(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2444 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2445 | #ifdef CONFIG_IEEE80211W |
| 2446 | case WLAN_ACTION_SA_QUERY: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2447 | return hostapd_sa_query_action(hapd, mgmt, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2448 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2449 | #ifdef CONFIG_WNM |
| 2450 | case WLAN_ACTION_WNM: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2451 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, len); |
| 2452 | return 1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2453 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2454 | #ifdef CONFIG_FST |
| 2455 | case WLAN_ACTION_FST: |
| 2456 | if (hapd->iface->fst) |
| 2457 | fst_rx_action(hapd->iface->fst, mgmt, len); |
| 2458 | else |
| 2459 | wpa_printf(MSG_DEBUG, |
| 2460 | "FST: Ignore FST Action frame - no FST attached"); |
| 2461 | return 1; |
| 2462 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2463 | case WLAN_ACTION_PUBLIC: |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2464 | case WLAN_ACTION_PROTECTED_DUAL: |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2465 | #ifdef CONFIG_IEEE80211N |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 2466 | if (len >= IEEE80211_HDRLEN + 2 && |
| 2467 | mgmt->u.action.u.public_action.action == |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2468 | WLAN_PA_20_40_BSS_COEX) { |
| 2469 | wpa_printf(MSG_DEBUG, |
| 2470 | "HT20/40 coex mgmt frame received from STA " |
| 2471 | MACSTR, MAC2STR(mgmt->sa)); |
| 2472 | hostapd_2040_coex_action(hapd, mgmt, len); |
| 2473 | } |
| 2474 | #endif /* CONFIG_IEEE80211N */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2475 | if (hapd->public_action_cb) { |
| 2476 | hapd->public_action_cb(hapd->public_action_cb_ctx, |
| 2477 | (u8 *) mgmt, len, |
| 2478 | hapd->iface->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2479 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2480 | if (hapd->public_action_cb2) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2481 | hapd->public_action_cb2(hapd->public_action_cb2_ctx, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2482 | (u8 *) mgmt, len, |
| 2483 | hapd->iface->freq); |
| 2484 | } |
| 2485 | if (hapd->public_action_cb || hapd->public_action_cb2) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2486 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2487 | break; |
| 2488 | case WLAN_ACTION_VENDOR_SPECIFIC: |
| 2489 | if (hapd->vendor_action_cb) { |
| 2490 | if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx, |
| 2491 | (u8 *) mgmt, len, |
| 2492 | hapd->iface->freq) == 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2493 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2494 | } |
| 2495 | break; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2496 | case WLAN_ACTION_RADIO_MEASUREMENT: |
| 2497 | hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len); |
| 2498 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 2502 | HOSTAPD_LEVEL_DEBUG, |
| 2503 | "handle_action - unknown action category %d or invalid " |
| 2504 | "frame", |
| 2505 | mgmt->u.action.category); |
| 2506 | if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) && |
| 2507 | !(mgmt->sa[0] & 0x01)) { |
| 2508 | struct ieee80211_mgmt *resp; |
| 2509 | |
| 2510 | /* |
| 2511 | * IEEE 802.11-REVma/D9.0 - 7.3.1.11 |
| 2512 | * Return the Action frame to the source without change |
| 2513 | * except that MSB of the Category set to 1. |
| 2514 | */ |
| 2515 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action " |
| 2516 | "frame back to sender"); |
| 2517 | resp = os_malloc(len); |
| 2518 | if (resp == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2519 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2520 | os_memcpy(resp, mgmt, len); |
| 2521 | os_memcpy(resp->da, resp->sa, ETH_ALEN); |
| 2522 | os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); |
| 2523 | os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); |
| 2524 | resp->u.action.category |= 0x80; |
| 2525 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2526 | if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) { |
| 2527 | wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send " |
| 2528 | "Action frame"); |
| 2529 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2530 | os_free(resp); |
| 2531 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2532 | |
| 2533 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | |
| 2537 | /** |
| 2538 | * ieee802_11_mgmt - process incoming IEEE 802.11 management frames |
| 2539 | * @hapd: hostapd BSS data structure (the BSS to which the management frame was |
| 2540 | * sent to) |
| 2541 | * @buf: management frame data (starting from IEEE 802.11 header) |
| 2542 | * @len: length of frame data in octets |
| 2543 | * @fi: meta data about received frame (signal level, etc.) |
| 2544 | * |
| 2545 | * Process all incoming IEEE 802.11 management frames. This will be called for |
| 2546 | * each frame received from the kernel driver through wlan#ap interface. In |
| 2547 | * addition, it can be called to re-inserted pending frames (e.g., when using |
| 2548 | * external RADIUS server as an MAC ACL). |
| 2549 | */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2550 | int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len, |
| 2551 | struct hostapd_frame_info *fi) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2552 | { |
| 2553 | struct ieee80211_mgmt *mgmt; |
| 2554 | int broadcast; |
| 2555 | u16 fc, stype; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2556 | int ret = 0; |
| 2557 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2558 | if (len < 24) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2559 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2560 | |
| 2561 | mgmt = (struct ieee80211_mgmt *) buf; |
| 2562 | fc = le_to_host16(mgmt->frame_control); |
| 2563 | stype = WLAN_FC_GET_STYPE(fc); |
| 2564 | |
| 2565 | if (stype == WLAN_FC_STYPE_BEACON) { |
| 2566 | handle_beacon(hapd, mgmt, len, fi); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2567 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff && |
| 2571 | mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff && |
| 2572 | mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff; |
| 2573 | |
| 2574 | if (!broadcast && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2575 | #ifdef CONFIG_P2P |
| 2576 | /* Invitation responses can be sent with the peer MAC as BSSID */ |
| 2577 | !((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 2578 | stype == WLAN_FC_STYPE_ACTION) && |
| 2579 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2580 | #ifdef CONFIG_MESH |
| 2581 | !(hapd->conf->mesh & MESH_ENABLED) && |
| 2582 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2583 | os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2584 | wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address", |
| 2585 | MAC2STR(mgmt->bssid)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2586 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | |
| 2590 | if (stype == WLAN_FC_STYPE_PROBE_REQ) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2591 | handle_probe_req(hapd, mgmt, len, fi->ssi_signal); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2592 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) { |
| 2596 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 2597 | HOSTAPD_LEVEL_DEBUG, |
| 2598 | "MGMT: DA=" MACSTR " not our address", |
| 2599 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2600 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2601 | } |
| 2602 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2603 | if (hapd->iconf->track_sta_max_num) |
| 2604 | sta_track_add(hapd->iface, mgmt->sa); |
| 2605 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2606 | switch (stype) { |
| 2607 | case WLAN_FC_STYPE_AUTH: |
| 2608 | wpa_printf(MSG_DEBUG, "mgmt::auth"); |
| 2609 | handle_auth(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2610 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2611 | break; |
| 2612 | case WLAN_FC_STYPE_ASSOC_REQ: |
| 2613 | wpa_printf(MSG_DEBUG, "mgmt::assoc_req"); |
| 2614 | handle_assoc(hapd, mgmt, len, 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2615 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2616 | break; |
| 2617 | case WLAN_FC_STYPE_REASSOC_REQ: |
| 2618 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_req"); |
| 2619 | handle_assoc(hapd, mgmt, len, 1); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2620 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2621 | break; |
| 2622 | case WLAN_FC_STYPE_DISASSOC: |
| 2623 | wpa_printf(MSG_DEBUG, "mgmt::disassoc"); |
| 2624 | handle_disassoc(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2625 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2626 | break; |
| 2627 | case WLAN_FC_STYPE_DEAUTH: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2628 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2629 | handle_deauth(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2630 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2631 | break; |
| 2632 | case WLAN_FC_STYPE_ACTION: |
| 2633 | wpa_printf(MSG_DEBUG, "mgmt::action"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2634 | ret = handle_action(hapd, mgmt, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2635 | break; |
| 2636 | default: |
| 2637 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 2638 | HOSTAPD_LEVEL_DEBUG, |
| 2639 | "unknown mgmt frame subtype %d", stype); |
| 2640 | break; |
| 2641 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2642 | |
| 2643 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | |
| 2647 | static void handle_auth_cb(struct hostapd_data *hapd, |
| 2648 | const struct ieee80211_mgmt *mgmt, |
| 2649 | size_t len, int ok) |
| 2650 | { |
| 2651 | u16 auth_alg, auth_transaction, status_code; |
| 2652 | struct sta_info *sta; |
| 2653 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2654 | sta = ap_get_sta(hapd, mgmt->da); |
| 2655 | if (!sta) { |
| 2656 | wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found", |
| 2657 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2658 | return; |
| 2659 | } |
| 2660 | |
| 2661 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 2662 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); |
| 2663 | status_code = le_to_host16(mgmt->u.auth.status_code); |
| 2664 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2665 | if (!ok) { |
| 2666 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, |
| 2667 | HOSTAPD_LEVEL_NOTICE, |
| 2668 | "did not acknowledge authentication response"); |
| 2669 | goto fail; |
| 2670 | } |
| 2671 | |
| 2672 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |
| 2673 | wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)", |
| 2674 | (unsigned long) len); |
| 2675 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | if (status_code == WLAN_STATUS_SUCCESS && |
| 2679 | ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) || |
| 2680 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) { |
| 2681 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2682 | HOSTAPD_LEVEL_INFO, "authenticated"); |
| 2683 | sta->flags |= WLAN_STA_AUTH; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2684 | if (sta->added_unassoc) |
| 2685 | hostapd_set_sta_flags(hapd, sta); |
| 2686 | return; |
| 2687 | } |
| 2688 | |
| 2689 | fail: |
| 2690 | if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) { |
| 2691 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 2692 | sta->added_unassoc = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2697 | static void hostapd_set_wds_encryption(struct hostapd_data *hapd, |
| 2698 | struct sta_info *sta, |
| 2699 | char *ifname_wds) |
| 2700 | { |
| 2701 | int i; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 2702 | struct hostapd_ssid *ssid = &hapd->conf->ssid; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2703 | |
| 2704 | if (hapd->conf->ieee802_1x || hapd->conf->wpa) |
| 2705 | return; |
| 2706 | |
| 2707 | for (i = 0; i < 4; i++) { |
| 2708 | if (ssid->wep.key[i] && |
| 2709 | hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i, |
| 2710 | i == ssid->wep.idx, NULL, 0, |
| 2711 | ssid->wep.key[i], ssid->wep.len[i])) { |
| 2712 | wpa_printf(MSG_WARNING, |
| 2713 | "Could not set WEP keys for WDS interface; %s", |
| 2714 | ifname_wds); |
| 2715 | break; |
| 2716 | } |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2721 | static void handle_assoc_cb(struct hostapd_data *hapd, |
| 2722 | const struct ieee80211_mgmt *mgmt, |
| 2723 | size_t len, int reassoc, int ok) |
| 2724 | { |
| 2725 | u16 status; |
| 2726 | struct sta_info *sta; |
| 2727 | int new_assoc = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2728 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2729 | sta = ap_get_sta(hapd, mgmt->da); |
| 2730 | if (!sta) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2731 | wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found", |
| 2732 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2733 | return; |
| 2734 | } |
| 2735 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2736 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) : |
| 2737 | sizeof(mgmt->u.assoc_resp))) { |
| 2738 | wpa_printf(MSG_INFO, |
| 2739 | "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)", |
| 2740 | reassoc, (unsigned long) len); |
| 2741 | hostapd_drv_sta_remove(hapd, sta->addr); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2742 | return; |
| 2743 | } |
| 2744 | |
| 2745 | if (reassoc) |
| 2746 | status = le_to_host16(mgmt->u.reassoc_resp.status_code); |
| 2747 | else |
| 2748 | status = le_to_host16(mgmt->u.assoc_resp.status_code); |
| 2749 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2750 | if (!ok) { |
| 2751 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, |
| 2752 | HOSTAPD_LEVEL_DEBUG, |
| 2753 | "did not acknowledge association response"); |
| 2754 | sta->flags &= ~WLAN_STA_ASSOC_REQ_OK; |
| 2755 | /* The STA is added only in case of SUCCESS */ |
| 2756 | if (status == WLAN_STATUS_SUCCESS) |
| 2757 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 2758 | |
| 2759 | return; |
| 2760 | } |
| 2761 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2762 | if (status != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2763 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2764 | |
| 2765 | /* Stop previous accounting session, if one is started, and allocate |
| 2766 | * new session id for the new session. */ |
| 2767 | accounting_sta_stop(hapd, sta); |
| 2768 | |
| 2769 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2770 | HOSTAPD_LEVEL_INFO, |
| 2771 | "associated (aid %d)", |
| 2772 | sta->aid); |
| 2773 | |
| 2774 | if (sta->flags & WLAN_STA_ASSOC) |
| 2775 | new_assoc = 0; |
| 2776 | sta->flags |= WLAN_STA_ASSOC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2777 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2778 | if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2779 | sta->auth_alg == WLAN_AUTH_FT) { |
| 2780 | /* |
| 2781 | * Open, static WEP, or FT protocol; no separate authorization |
| 2782 | * step. |
| 2783 | */ |
| 2784 | ap_sta_set_authorized(hapd, sta, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | if (reassoc) |
| 2788 | mlme_reassociate_indication(hapd, sta); |
| 2789 | else |
| 2790 | mlme_associate_indication(hapd, sta); |
| 2791 | |
| 2792 | #ifdef CONFIG_IEEE80211W |
| 2793 | sta->sa_query_timed_out = 0; |
| 2794 | #endif /* CONFIG_IEEE80211W */ |
| 2795 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2796 | if (sta->flags & WLAN_STA_WDS) { |
| 2797 | int ret; |
| 2798 | char ifname_wds[IFNAMSIZ + 1]; |
| 2799 | |
| 2800 | ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr, |
| 2801 | sta->aid, 1); |
| 2802 | if (!ret) |
| 2803 | hostapd_set_wds_encryption(hapd, sta, ifname_wds); |
| 2804 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2805 | |
| 2806 | if (sta->eapol_sm == NULL) { |
| 2807 | /* |
| 2808 | * This STA does not use RADIUS server for EAP authentication, |
| 2809 | * so bind it to the selected VLAN interface now, since the |
| 2810 | * interface selection is not going to change anymore. |
| 2811 | */ |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 2812 | if (ap_sta_bind_vlan(hapd, sta) < 0) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2813 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2814 | } else if (sta->vlan_id) { |
| 2815 | /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */ |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 2816 | if (ap_sta_bind_vlan(hapd, sta) < 0) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2817 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | hostapd_set_sta_flags(hapd, sta); |
| 2821 | |
| 2822 | if (sta->auth_alg == WLAN_AUTH_FT) |
| 2823 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); |
| 2824 | else |
| 2825 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); |
| 2826 | hapd->new_assoc_sta_cb(hapd, sta, !new_assoc); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2827 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 2828 | |
| 2829 | if (sta->pending_eapol_rx) { |
| 2830 | struct os_reltime now, age; |
| 2831 | |
| 2832 | os_get_reltime(&now); |
| 2833 | os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age); |
| 2834 | if (age.sec == 0 && age.usec < 200000) { |
| 2835 | wpa_printf(MSG_DEBUG, |
| 2836 | "Process pending EAPOL frame that was received from " MACSTR " just before association notification", |
| 2837 | MAC2STR(sta->addr)); |
| 2838 | ieee802_1x_receive( |
| 2839 | hapd, mgmt->da, |
| 2840 | wpabuf_head(sta->pending_eapol_rx->buf), |
| 2841 | wpabuf_len(sta->pending_eapol_rx->buf)); |
| 2842 | } |
| 2843 | wpabuf_free(sta->pending_eapol_rx->buf); |
| 2844 | os_free(sta->pending_eapol_rx); |
| 2845 | sta->pending_eapol_rx = NULL; |
| 2846 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2850 | static void handle_deauth_cb(struct hostapd_data *hapd, |
| 2851 | const struct ieee80211_mgmt *mgmt, |
| 2852 | size_t len, int ok) |
| 2853 | { |
| 2854 | struct sta_info *sta; |
| 2855 | if (mgmt->da[0] & 0x01) |
| 2856 | return; |
| 2857 | sta = ap_get_sta(hapd, mgmt->da); |
| 2858 | if (!sta) { |
| 2859 | wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR |
| 2860 | " not found", MAC2STR(mgmt->da)); |
| 2861 | return; |
| 2862 | } |
| 2863 | if (ok) |
| 2864 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth", |
| 2865 | MAC2STR(sta->addr)); |
| 2866 | else |
| 2867 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " |
| 2868 | "deauth", MAC2STR(sta->addr)); |
| 2869 | |
| 2870 | ap_sta_deauth_cb(hapd, sta); |
| 2871 | } |
| 2872 | |
| 2873 | |
| 2874 | static void handle_disassoc_cb(struct hostapd_data *hapd, |
| 2875 | const struct ieee80211_mgmt *mgmt, |
| 2876 | size_t len, int ok) |
| 2877 | { |
| 2878 | struct sta_info *sta; |
| 2879 | if (mgmt->da[0] & 0x01) |
| 2880 | return; |
| 2881 | sta = ap_get_sta(hapd, mgmt->da); |
| 2882 | if (!sta) { |
| 2883 | wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR |
| 2884 | " not found", MAC2STR(mgmt->da)); |
| 2885 | return; |
| 2886 | } |
| 2887 | if (ok) |
| 2888 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc", |
| 2889 | MAC2STR(sta->addr)); |
| 2890 | else |
| 2891 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " |
| 2892 | "disassoc", MAC2STR(sta->addr)); |
| 2893 | |
| 2894 | ap_sta_disassoc_cb(hapd, sta); |
| 2895 | } |
| 2896 | |
| 2897 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2898 | /** |
| 2899 | * ieee802_11_mgmt_cb - Process management frame TX status callback |
| 2900 | * @hapd: hostapd BSS data structure (the BSS from which the management frame |
| 2901 | * was sent from) |
| 2902 | * @buf: management frame data (starting from IEEE 802.11 header) |
| 2903 | * @len: length of frame data in octets |
| 2904 | * @stype: management frame subtype from frame control field |
| 2905 | * @ok: Whether the frame was ACK'ed |
| 2906 | */ |
| 2907 | void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len, |
| 2908 | u16 stype, int ok) |
| 2909 | { |
| 2910 | const struct ieee80211_mgmt *mgmt; |
| 2911 | mgmt = (const struct ieee80211_mgmt *) buf; |
| 2912 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2913 | #ifdef CONFIG_TESTING_OPTIONS |
| 2914 | if (hapd->ext_mgmt_frame_handling) { |
| 2915 | wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d", |
| 2916 | stype, ok); |
| 2917 | return; |
| 2918 | } |
| 2919 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2920 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2921 | switch (stype) { |
| 2922 | case WLAN_FC_STYPE_AUTH: |
| 2923 | wpa_printf(MSG_DEBUG, "mgmt::auth cb"); |
| 2924 | handle_auth_cb(hapd, mgmt, len, ok); |
| 2925 | break; |
| 2926 | case WLAN_FC_STYPE_ASSOC_RESP: |
| 2927 | wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb"); |
| 2928 | handle_assoc_cb(hapd, mgmt, len, 0, ok); |
| 2929 | break; |
| 2930 | case WLAN_FC_STYPE_REASSOC_RESP: |
| 2931 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb"); |
| 2932 | handle_assoc_cb(hapd, mgmt, len, 1, ok); |
| 2933 | break; |
| 2934 | case WLAN_FC_STYPE_PROBE_RESP: |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2935 | wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2936 | break; |
| 2937 | case WLAN_FC_STYPE_DEAUTH: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2938 | wpa_printf(MSG_DEBUG, "mgmt::deauth cb"); |
| 2939 | handle_deauth_cb(hapd, mgmt, len, ok); |
| 2940 | break; |
| 2941 | case WLAN_FC_STYPE_DISASSOC: |
| 2942 | wpa_printf(MSG_DEBUG, "mgmt::disassoc cb"); |
| 2943 | handle_disassoc_cb(hapd, mgmt, len, ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2944 | break; |
| 2945 | case WLAN_FC_STYPE_ACTION: |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2946 | wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2947 | break; |
| 2948 | default: |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2949 | wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2950 | break; |
| 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | |
| 2955 | int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen) |
| 2956 | { |
| 2957 | /* TODO */ |
| 2958 | return 0; |
| 2959 | } |
| 2960 | |
| 2961 | |
| 2962 | int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta, |
| 2963 | char *buf, size_t buflen) |
| 2964 | { |
| 2965 | /* TODO */ |
| 2966 | return 0; |
| 2967 | } |
| 2968 | |
| 2969 | |
| 2970 | void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr, |
| 2971 | const u8 *buf, size_t len, int ack) |
| 2972 | { |
| 2973 | struct sta_info *sta; |
| 2974 | struct hostapd_iface *iface = hapd->iface; |
| 2975 | |
| 2976 | sta = ap_get_sta(hapd, addr); |
| 2977 | if (sta == NULL && iface->num_bss > 1) { |
| 2978 | size_t j; |
| 2979 | for (j = 0; j < iface->num_bss; j++) { |
| 2980 | hapd = iface->bss[j]; |
| 2981 | sta = ap_get_sta(hapd, addr); |
| 2982 | if (sta) |
| 2983 | break; |
| 2984 | } |
| 2985 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2986 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2987 | return; |
| 2988 | if (sta->flags & WLAN_STA_PENDING_POLL) { |
| 2989 | wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending " |
| 2990 | "activity poll", MAC2STR(sta->addr), |
| 2991 | ack ? "ACKed" : "did not ACK"); |
| 2992 | if (ack) |
| 2993 | sta->flags &= ~WLAN_STA_PENDING_POLL; |
| 2994 | } |
| 2995 | |
| 2996 | ieee802_1x_tx_status(hapd, sta, buf, len, ack); |
| 2997 | } |
| 2998 | |
| 2999 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3000 | void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst, |
| 3001 | const u8 *data, size_t len, int ack) |
| 3002 | { |
| 3003 | struct sta_info *sta; |
| 3004 | struct hostapd_iface *iface = hapd->iface; |
| 3005 | |
| 3006 | sta = ap_get_sta(hapd, dst); |
| 3007 | if (sta == NULL && iface->num_bss > 1) { |
| 3008 | size_t j; |
| 3009 | for (j = 0; j < iface->num_bss; j++) { |
| 3010 | hapd = iface->bss[j]; |
| 3011 | sta = ap_get_sta(hapd, dst); |
| 3012 | if (sta) |
| 3013 | break; |
| 3014 | } |
| 3015 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3016 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) { |
| 3017 | wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA " |
| 3018 | MACSTR " that is not currently associated", |
| 3019 | MAC2STR(dst)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3020 | return; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3021 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3022 | |
| 3023 | ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack); |
| 3024 | } |
| 3025 | |
| 3026 | |
| 3027 | void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr) |
| 3028 | { |
| 3029 | struct sta_info *sta; |
| 3030 | struct hostapd_iface *iface = hapd->iface; |
| 3031 | |
| 3032 | sta = ap_get_sta(hapd, addr); |
| 3033 | if (sta == NULL && iface->num_bss > 1) { |
| 3034 | size_t j; |
| 3035 | for (j = 0; j < iface->num_bss; j++) { |
| 3036 | hapd = iface->bss[j]; |
| 3037 | sta = ap_get_sta(hapd, addr); |
| 3038 | if (sta) |
| 3039 | break; |
| 3040 | } |
| 3041 | } |
| 3042 | if (sta == NULL) |
| 3043 | return; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3044 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR, |
| 3045 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3046 | if (!(sta->flags & WLAN_STA_PENDING_POLL)) |
| 3047 | return; |
| 3048 | |
| 3049 | wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending " |
| 3050 | "activity poll", MAC2STR(sta->addr)); |
| 3051 | sta->flags &= ~WLAN_STA_PENDING_POLL; |
| 3052 | } |
| 3053 | |
| 3054 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3055 | void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src, |
| 3056 | int wds) |
| 3057 | { |
| 3058 | struct sta_info *sta; |
| 3059 | |
| 3060 | sta = ap_get_sta(hapd, src); |
| 3061 | if (sta && (sta->flags & WLAN_STA_ASSOC)) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 3062 | if (!hapd->conf->wds_sta) |
| 3063 | return; |
| 3064 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3065 | if (wds && !(sta->flags & WLAN_STA_WDS)) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3066 | int ret; |
| 3067 | char ifname_wds[IFNAMSIZ + 1]; |
| 3068 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3069 | wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for " |
| 3070 | "STA " MACSTR " (aid %u)", |
| 3071 | MAC2STR(sta->addr), sta->aid); |
| 3072 | sta->flags |= WLAN_STA_WDS; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3073 | ret = hostapd_set_wds_sta(hapd, ifname_wds, |
| 3074 | sta->addr, sta->aid, 1); |
| 3075 | if (!ret) |
| 3076 | hostapd_set_wds_encryption(hapd, sta, |
| 3077 | ifname_wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3078 | } |
| 3079 | return; |
| 3080 | } |
| 3081 | |
| 3082 | wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA " |
| 3083 | MACSTR, MAC2STR(src)); |
| 3084 | if (src[0] & 0x01) { |
| 3085 | /* Broadcast bit set in SA?! Ignore the frame silently. */ |
| 3086 | return; |
| 3087 | } |
| 3088 | |
| 3089 | if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) { |
| 3090 | wpa_printf(MSG_DEBUG, "Association Response to the STA has " |
| 3091 | "already been sent, but no TX status yet known - " |
| 3092 | "ignore Class 3 frame issue with " MACSTR, |
| 3093 | MAC2STR(src)); |
| 3094 | return; |
| 3095 | } |
| 3096 | |
| 3097 | if (sta && (sta->flags & WLAN_STA_AUTH)) |
| 3098 | hostapd_drv_sta_disassoc( |
| 3099 | hapd, src, |
| 3100 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); |
| 3101 | else |
| 3102 | hostapd_drv_sta_deauth( |
| 3103 | hapd, src, |
| 3104 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); |
| 3105 | } |
| 3106 | |
| 3107 | |
| 3108 | #endif /* CONFIG_NATIVE_WINDOWS */ |