Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / IEEE 802.11 Management |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3 | * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "utils/includes.h" |
| 10 | |
| 11 | #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" |
| 26 | #include "hostapd.h" |
| 27 | #include "beacon.h" |
| 28 | #include "ieee802_11_auth.h" |
| 29 | #include "sta_info.h" |
| 30 | #include "ieee802_1x.h" |
| 31 | #include "wpa_auth.h" |
| 32 | #include "wmm.h" |
| 33 | #include "ap_list.h" |
| 34 | #include "accounting.h" |
| 35 | #include "ap_config.h" |
| 36 | #include "ap_mlme.h" |
| 37 | #include "p2p_hostapd.h" |
| 38 | #include "ap_drv_ops.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 39 | #include "wnm_ap.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 40 | #include "ieee802_11.h" |
| 41 | |
| 42 | |
| 43 | u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid) |
| 44 | { |
| 45 | u8 *pos = eid; |
| 46 | int i, num, count; |
| 47 | |
| 48 | if (hapd->iface->current_rates == NULL) |
| 49 | return eid; |
| 50 | |
| 51 | *pos++ = WLAN_EID_SUPP_RATES; |
| 52 | num = hapd->iface->num_rates; |
| 53 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
| 54 | num++; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 55 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
| 56 | num++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 57 | if (num > 8) { |
| 58 | /* rest of the rates are encoded in Extended supported |
| 59 | * rates element */ |
| 60 | num = 8; |
| 61 | } |
| 62 | |
| 63 | *pos++ = num; |
| 64 | count = 0; |
| 65 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num; |
| 66 | i++) { |
| 67 | count++; |
| 68 | *pos = hapd->iface->current_rates[i].rate / 5; |
| 69 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) |
| 70 | *pos |= 0x80; |
| 71 | pos++; |
| 72 | } |
| 73 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 74 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) { |
| 75 | count++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 76 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) { |
| 80 | count++; |
| 81 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; |
| 82 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 83 | |
| 84 | return pos; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid) |
| 89 | { |
| 90 | u8 *pos = eid; |
| 91 | int i, num, count; |
| 92 | |
| 93 | if (hapd->iface->current_rates == NULL) |
| 94 | return eid; |
| 95 | |
| 96 | num = hapd->iface->num_rates; |
| 97 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
| 98 | num++; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 99 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
| 100 | num++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 101 | if (num <= 8) |
| 102 | return eid; |
| 103 | num -= 8; |
| 104 | |
| 105 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 106 | *pos++ = num; |
| 107 | count = 0; |
| 108 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8; |
| 109 | i++) { |
| 110 | count++; |
| 111 | if (count <= 8) |
| 112 | continue; /* already in SuppRates IE */ |
| 113 | *pos = hapd->iface->current_rates[i].rate / 5; |
| 114 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) |
| 115 | *pos |= 0x80; |
| 116 | pos++; |
| 117 | } |
| 118 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 119 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) { |
| 120 | count++; |
| 121 | if (count > 8) |
| 122 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; |
| 123 | } |
| 124 | |
| 125 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) { |
| 126 | count++; |
| 127 | if (count > 8) |
| 128 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; |
| 129 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 130 | |
| 131 | return pos; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta, |
| 136 | int probe) |
| 137 | { |
| 138 | int capab = WLAN_CAPABILITY_ESS; |
| 139 | int privacy; |
| 140 | |
| 141 | if (hapd->iface->num_sta_no_short_preamble == 0 && |
| 142 | hapd->iconf->preamble == SHORT_PREAMBLE) |
| 143 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 144 | |
| 145 | privacy = hapd->conf->ssid.wep.keys_set; |
| 146 | |
| 147 | if (hapd->conf->ieee802_1x && |
| 148 | (hapd->conf->default_wep_key_len || |
| 149 | hapd->conf->individual_wep_key_len)) |
| 150 | privacy = 1; |
| 151 | |
| 152 | if (hapd->conf->wpa) |
| 153 | privacy = 1; |
| 154 | |
| 155 | if (sta) { |
| 156 | int policy, def_klen; |
| 157 | if (probe && sta->ssid_probe) { |
| 158 | policy = sta->ssid_probe->security_policy; |
| 159 | def_klen = sta->ssid_probe->wep.default_len; |
| 160 | } else { |
| 161 | policy = sta->ssid->security_policy; |
| 162 | def_klen = sta->ssid->wep.default_len; |
| 163 | } |
| 164 | privacy = policy != SECURITY_PLAINTEXT; |
| 165 | if (policy == SECURITY_IEEE_802_1X && def_klen == 0) |
| 166 | privacy = 0; |
| 167 | } |
| 168 | |
| 169 | if (privacy) |
| 170 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 171 | |
| 172 | if (hapd->iface->current_mode && |
| 173 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G && |
| 174 | hapd->iface->num_sta_no_short_slot_time == 0) |
| 175 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 176 | |
| 177 | return capab; |
| 178 | } |
| 179 | |
| 180 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 181 | static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta, |
| 182 | u16 auth_transaction, const u8 *challenge, |
| 183 | int iswep) |
| 184 | { |
| 185 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 186 | HOSTAPD_LEVEL_DEBUG, |
| 187 | "authentication (shared key, transaction %d)", |
| 188 | auth_transaction); |
| 189 | |
| 190 | if (auth_transaction == 1) { |
| 191 | if (!sta->challenge) { |
| 192 | /* Generate a pseudo-random challenge */ |
| 193 | u8 key[8]; |
| 194 | struct os_time now; |
| 195 | int r; |
| 196 | sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN); |
| 197 | if (sta->challenge == NULL) |
| 198 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 199 | |
| 200 | os_get_time(&now); |
| 201 | r = os_random(); |
| 202 | os_memcpy(key, &now.sec, 4); |
| 203 | os_memcpy(key + 4, &r, 4); |
| 204 | rc4_skip(key, sizeof(key), 0, |
| 205 | sta->challenge, WLAN_AUTH_CHALLENGE_LEN); |
| 206 | } |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | if (auth_transaction != 3) |
| 211 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 212 | |
| 213 | /* Transaction 3 */ |
| 214 | if (!iswep || !sta->challenge || !challenge || |
| 215 | os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) { |
| 216 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 217 | HOSTAPD_LEVEL_INFO, |
| 218 | "shared key authentication - invalid " |
| 219 | "challenge-response"); |
| 220 | return WLAN_STATUS_CHALLENGE_FAIL; |
| 221 | } |
| 222 | |
| 223 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 224 | HOSTAPD_LEVEL_DEBUG, |
| 225 | "authentication OK (shared key)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 226 | sta->flags |= WLAN_STA_AUTH; |
| 227 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 228 | os_free(sta->challenge); |
| 229 | sta->challenge = NULL; |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | static void send_auth_reply(struct hostapd_data *hapd, |
| 236 | const u8 *dst, const u8 *bssid, |
| 237 | u16 auth_alg, u16 auth_transaction, u16 resp, |
| 238 | const u8 *ies, size_t ies_len) |
| 239 | { |
| 240 | struct ieee80211_mgmt *reply; |
| 241 | u8 *buf; |
| 242 | size_t rlen; |
| 243 | |
| 244 | rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len; |
| 245 | buf = os_zalloc(rlen); |
| 246 | if (buf == NULL) |
| 247 | return; |
| 248 | |
| 249 | reply = (struct ieee80211_mgmt *) buf; |
| 250 | reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 251 | WLAN_FC_STYPE_AUTH); |
| 252 | os_memcpy(reply->da, dst, ETH_ALEN); |
| 253 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); |
| 254 | os_memcpy(reply->bssid, bssid, ETH_ALEN); |
| 255 | |
| 256 | reply->u.auth.auth_alg = host_to_le16(auth_alg); |
| 257 | reply->u.auth.auth_transaction = host_to_le16(auth_transaction); |
| 258 | reply->u.auth.status_code = host_to_le16(resp); |
| 259 | |
| 260 | if (ies && ies_len) |
| 261 | os_memcpy(reply->u.auth.variable, ies, ies_len); |
| 262 | |
| 263 | wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR |
| 264 | " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)", |
| 265 | MAC2STR(dst), auth_alg, auth_transaction, |
| 266 | resp, (unsigned long) ies_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 267 | if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 268 | wpa_printf(MSG_INFO, "send_auth_reply: send"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 269 | |
| 270 | os_free(buf); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | #ifdef CONFIG_IEEE80211R |
| 275 | static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid, |
| 276 | u16 auth_transaction, u16 status, |
| 277 | const u8 *ies, size_t ies_len) |
| 278 | { |
| 279 | struct hostapd_data *hapd = ctx; |
| 280 | struct sta_info *sta; |
| 281 | |
| 282 | send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction, |
| 283 | status, ies, ies_len); |
| 284 | |
| 285 | if (status != WLAN_STATUS_SUCCESS) |
| 286 | return; |
| 287 | |
| 288 | sta = ap_get_sta(hapd, dst); |
| 289 | if (sta == NULL) |
| 290 | return; |
| 291 | |
| 292 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, |
| 293 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); |
| 294 | sta->flags |= WLAN_STA_AUTH; |
| 295 | mlme_authenticate_indication(hapd, sta); |
| 296 | } |
| 297 | #endif /* CONFIG_IEEE80211R */ |
| 298 | |
| 299 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 300 | #ifdef CONFIG_SAE |
| 301 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 302 | static struct wpabuf * auth_process_sae_commit(struct hostapd_data *hapd, |
| 303 | struct sta_info *sta) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 304 | { |
| 305 | struct wpabuf *buf; |
| 306 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 307 | if (hapd->conf->ssid.wpa_passphrase == NULL) { |
| 308 | wpa_printf(MSG_DEBUG, "SAE: No password available"); |
| 309 | return NULL; |
| 310 | } |
| 311 | |
| 312 | if (sae_prepare_commit(hapd->own_addr, sta->addr, |
| 313 | (u8 *) hapd->conf->ssid.wpa_passphrase, |
| 314 | os_strlen(hapd->conf->ssid.wpa_passphrase), |
| 315 | sta->sae) < 0) { |
| 316 | wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE"); |
| 317 | return NULL; |
| 318 | } |
| 319 | |
| 320 | if (sae_process_commit(sta->sae) < 0) { |
| 321 | wpa_printf(MSG_DEBUG, "SAE: Failed to process peer commit"); |
| 322 | return NULL; |
| 323 | } |
| 324 | |
| 325 | buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 326 | if (buf == NULL) |
| 327 | return NULL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 328 | sae_write_commit(sta->sae, buf, NULL); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 329 | |
| 330 | return buf; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd, |
| 335 | struct sta_info *sta) |
| 336 | { |
| 337 | struct wpabuf *buf; |
| 338 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 339 | buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 340 | if (buf == NULL) |
| 341 | return NULL; |
| 342 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 343 | sae_write_confirm(sta->sae, buf); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 344 | |
| 345 | return buf; |
| 346 | } |
| 347 | |
| 348 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 349 | static int use_sae_anti_clogging(struct hostapd_data *hapd) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 350 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 351 | struct sta_info *sta; |
| 352 | unsigned int open = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 353 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 354 | if (hapd->conf->sae_anti_clogging_threshold == 0) |
| 355 | return 1; |
| 356 | |
| 357 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 358 | if (!sta->sae) |
| 359 | continue; |
| 360 | if (sta->sae->state != SAE_COMMITTED && |
| 361 | sta->sae->state != SAE_CONFIRMED) |
| 362 | continue; |
| 363 | open++; |
| 364 | if (open >= hapd->conf->sae_anti_clogging_threshold) |
| 365 | return 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 368 | return 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 372 | static int check_sae_token(struct hostapd_data *hapd, const u8 *addr, |
| 373 | const u8 *token, size_t token_len) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 374 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 375 | u8 mac[SHA256_MAC_LEN]; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 376 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 377 | if (token_len != SHA256_MAC_LEN) |
| 378 | return -1; |
| 379 | if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key), |
| 380 | addr, ETH_ALEN, mac) < 0 || |
| 381 | os_memcmp(token, mac, SHA256_MAC_LEN) != 0) |
| 382 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 383 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 384 | return 0; |
| 385 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 386 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 387 | |
| 388 | static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd, |
| 389 | const u8 *addr) |
| 390 | { |
| 391 | struct wpabuf *buf; |
| 392 | u8 *token; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 393 | struct os_reltime now; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 394 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 395 | os_get_reltime(&now); |
| 396 | if (!os_reltime_initialized(&hapd->last_sae_token_key_update) || |
| 397 | os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 398 | if (random_get_bytes(hapd->sae_token_key, |
| 399 | sizeof(hapd->sae_token_key)) < 0) |
| 400 | return NULL; |
| 401 | wpa_hexdump(MSG_DEBUG, "SAE: Updated token key", |
| 402 | hapd->sae_token_key, sizeof(hapd->sae_token_key)); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 403 | hapd->last_sae_token_key_update = now; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | buf = wpabuf_alloc(SHA256_MAC_LEN); |
| 407 | if (buf == NULL) |
| 408 | return NULL; |
| 409 | |
| 410 | token = wpabuf_put(buf, SHA256_MAC_LEN); |
| 411 | hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key), |
| 412 | addr, ETH_ALEN, token); |
| 413 | |
| 414 | return buf; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
| 418 | static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta, |
| 419 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 420 | u8 auth_transaction) |
| 421 | { |
| 422 | u16 resp = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 423 | struct wpabuf *data = NULL; |
| 424 | |
| 425 | if (!sta->sae) { |
| 426 | if (auth_transaction != 1) |
| 427 | return; |
| 428 | sta->sae = os_zalloc(sizeof(*sta->sae)); |
| 429 | if (sta->sae == NULL) |
| 430 | return; |
| 431 | sta->sae->state = SAE_NOTHING; |
| 432 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 433 | |
| 434 | if (auth_transaction == 1) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 435 | const u8 *token = NULL; |
| 436 | size_t token_len = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 437 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 438 | HOSTAPD_LEVEL_DEBUG, |
| 439 | "start SAE authentication (RX commit)"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 440 | resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable, |
| 441 | ((const u8 *) mgmt) + len - |
| 442 | mgmt->u.auth.variable, &token, |
| 443 | &token_len, hapd->conf->sae_groups); |
| 444 | if (token && check_sae_token(hapd, sta->addr, token, token_len) |
| 445 | < 0) { |
| 446 | wpa_printf(MSG_DEBUG, "SAE: Drop commit message with " |
| 447 | "incorrect token from " MACSTR, |
| 448 | MAC2STR(sta->addr)); |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | if (resp == WLAN_STATUS_SUCCESS) { |
| 453 | if (!token && use_sae_anti_clogging(hapd)) { |
| 454 | wpa_printf(MSG_DEBUG, "SAE: Request anti-" |
| 455 | "clogging token from " MACSTR, |
| 456 | MAC2STR(sta->addr)); |
| 457 | data = auth_build_token_req(hapd, sta->addr); |
| 458 | resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ; |
| 459 | } else { |
| 460 | data = auth_process_sae_commit(hapd, sta); |
| 461 | if (data == NULL) |
| 462 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 463 | else |
| 464 | sta->sae->state = SAE_COMMITTED; |
| 465 | } |
| 466 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 467 | } else if (auth_transaction == 2) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 468 | if (sta->sae->state != SAE_COMMITTED) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 469 | hostapd_logger(hapd, sta->addr, |
| 470 | HOSTAPD_MODULE_IEEE80211, |
| 471 | HOSTAPD_LEVEL_DEBUG, |
| 472 | "SAE confirm before commit"); |
| 473 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame^] | 474 | goto failed; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 475 | } |
| 476 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 477 | HOSTAPD_LEVEL_DEBUG, |
| 478 | "SAE authentication (RX confirm)"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 479 | if (sae_check_confirm(sta->sae, mgmt->u.auth.variable, |
| 480 | ((u8 *) mgmt) + len - |
| 481 | mgmt->u.auth.variable) < 0) { |
| 482 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 483 | } else { |
| 484 | resp = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 485 | sta->flags |= WLAN_STA_AUTH; |
| 486 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 487 | sta->auth_alg = WLAN_AUTH_SAE; |
| 488 | mlme_authenticate_indication(hapd, sta); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 489 | |
| 490 | data = auth_build_sae_confirm(hapd, sta); |
| 491 | if (data == NULL) |
| 492 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 493 | else { |
| 494 | sta->sae->state = SAE_ACCEPTED; |
| 495 | sae_clear_temp_data(sta->sae); |
| 496 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 497 | } |
| 498 | } else { |
| 499 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 500 | HOSTAPD_LEVEL_DEBUG, |
| 501 | "unexpected SAE authentication transaction %u", |
| 502 | auth_transaction); |
| 503 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
| 504 | } |
| 505 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame^] | 506 | failed: |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 507 | sta->auth_alg = WLAN_AUTH_SAE; |
| 508 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 509 | send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE, |
| 510 | auth_transaction, resp, |
| 511 | data ? wpabuf_head(data) : (u8 *) "", |
| 512 | data ? wpabuf_len(data) : 0); |
| 513 | wpabuf_free(data); |
| 514 | } |
| 515 | #endif /* CONFIG_SAE */ |
| 516 | |
| 517 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 518 | static void handle_auth(struct hostapd_data *hapd, |
| 519 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 520 | { |
| 521 | u16 auth_alg, auth_transaction, status_code; |
| 522 | u16 resp = WLAN_STATUS_SUCCESS; |
| 523 | struct sta_info *sta = NULL; |
| 524 | int res; |
| 525 | u16 fc; |
| 526 | const u8 *challenge = NULL; |
| 527 | u32 session_timeout, acct_interim_interval; |
| 528 | int vlan_id = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 529 | struct hostapd_sta_wpa_psk_short *psk = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 530 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; |
| 531 | size_t resp_ies_len = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 532 | char *identity = NULL; |
| 533 | char *radius_cui = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 534 | |
| 535 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 536 | wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)", |
| 537 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 538 | return; |
| 539 | } |
| 540 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 541 | #ifdef CONFIG_TESTING_OPTIONS |
| 542 | if (hapd->iconf->ignore_auth_probability > 0.0d && |
| 543 | drand48() < hapd->iconf->ignore_auth_probability) { |
| 544 | wpa_printf(MSG_INFO, |
| 545 | "TESTING: ignoring auth frame from " MACSTR, |
| 546 | MAC2STR(mgmt->sa)); |
| 547 | return; |
| 548 | } |
| 549 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 550 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 551 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 552 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); |
| 553 | status_code = le_to_host16(mgmt->u.auth.status_code); |
| 554 | fc = le_to_host16(mgmt->frame_control); |
| 555 | |
| 556 | if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) + |
| 557 | 2 + WLAN_AUTH_CHALLENGE_LEN && |
| 558 | mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE && |
| 559 | mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN) |
| 560 | challenge = &mgmt->u.auth.variable[2]; |
| 561 | |
| 562 | wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d " |
| 563 | "auth_transaction=%d status_code=%d wep=%d%s", |
| 564 | MAC2STR(mgmt->sa), auth_alg, auth_transaction, |
| 565 | status_code, !!(fc & WLAN_FC_ISWEP), |
| 566 | challenge ? " challenge" : ""); |
| 567 | |
| 568 | if (hapd->tkip_countermeasures) { |
| 569 | resp = WLAN_REASON_MICHAEL_MIC_FAILURE; |
| 570 | goto fail; |
| 571 | } |
| 572 | |
| 573 | if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) && |
| 574 | auth_alg == WLAN_AUTH_OPEN) || |
| 575 | #ifdef CONFIG_IEEE80211R |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 576 | (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 577 | auth_alg == WLAN_AUTH_FT) || |
| 578 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 579 | #ifdef CONFIG_SAE |
| 580 | (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) && |
| 581 | auth_alg == WLAN_AUTH_SAE) || |
| 582 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 583 | ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) && |
| 584 | auth_alg == WLAN_AUTH_SHARED_KEY))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 585 | wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)", |
| 586 | auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 587 | resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 588 | goto fail; |
| 589 | } |
| 590 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 591 | if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 592 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 593 | wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)", |
| 594 | auth_transaction); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 595 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
| 596 | goto fail; |
| 597 | } |
| 598 | |
| 599 | if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 600 | wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate", |
| 601 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 602 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 603 | goto fail; |
| 604 | } |
| 605 | |
| 606 | res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len, |
| 607 | &session_timeout, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 608 | &acct_interim_interval, &vlan_id, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 609 | &psk, &identity, &radius_cui); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 610 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 611 | if (res == HOSTAPD_ACL_REJECT) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 612 | wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate", |
| 613 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 614 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 615 | goto fail; |
| 616 | } |
| 617 | if (res == HOSTAPD_ACL_PENDING) { |
| 618 | wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR |
| 619 | " waiting for an external authentication", |
| 620 | MAC2STR(mgmt->sa)); |
| 621 | /* Authentication code will re-send the authentication frame |
| 622 | * after it has received (and cached) information from the |
| 623 | * external source. */ |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | sta = ap_sta_add(hapd, mgmt->sa); |
| 628 | if (!sta) { |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 629 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 630 | goto fail; |
| 631 | } |
| 632 | |
| 633 | if (vlan_id > 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 634 | if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 635 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
| 636 | HOSTAPD_LEVEL_INFO, "Invalid VLAN ID " |
| 637 | "%d received from RADIUS server", |
| 638 | vlan_id); |
| 639 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 640 | goto fail; |
| 641 | } |
| 642 | sta->vlan_id = vlan_id; |
| 643 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
| 644 | HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id); |
| 645 | } |
| 646 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 647 | hostapd_free_psk_list(sta->psk); |
| 648 | if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) { |
| 649 | sta->psk = psk; |
| 650 | psk = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 651 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 652 | sta->psk = NULL; |
| 653 | } |
| 654 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 655 | sta->identity = identity; |
| 656 | identity = NULL; |
| 657 | sta->radius_cui = radius_cui; |
| 658 | radius_cui = NULL; |
| 659 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 660 | sta->flags &= ~WLAN_STA_PREAUTH; |
| 661 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); |
| 662 | |
| 663 | if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval) |
| 664 | sta->acct_interim_interval = acct_interim_interval; |
| 665 | if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT) |
| 666 | ap_sta_session_timeout(hapd, sta, session_timeout); |
| 667 | else |
| 668 | ap_sta_no_session_timeout(hapd, sta); |
| 669 | |
| 670 | switch (auth_alg) { |
| 671 | case WLAN_AUTH_OPEN: |
| 672 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 673 | HOSTAPD_LEVEL_DEBUG, |
| 674 | "authentication OK (open system)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 675 | sta->flags |= WLAN_STA_AUTH; |
| 676 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 677 | sta->auth_alg = WLAN_AUTH_OPEN; |
| 678 | mlme_authenticate_indication(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 679 | break; |
| 680 | case WLAN_AUTH_SHARED_KEY: |
| 681 | resp = auth_shared_key(hapd, sta, auth_transaction, challenge, |
| 682 | fc & WLAN_FC_ISWEP); |
| 683 | sta->auth_alg = WLAN_AUTH_SHARED_KEY; |
| 684 | mlme_authenticate_indication(hapd, sta); |
| 685 | if (sta->challenge && auth_transaction == 1) { |
| 686 | resp_ies[0] = WLAN_EID_CHALLENGE; |
| 687 | resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN; |
| 688 | os_memcpy(resp_ies + 2, sta->challenge, |
| 689 | WLAN_AUTH_CHALLENGE_LEN); |
| 690 | resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN; |
| 691 | } |
| 692 | break; |
| 693 | #ifdef CONFIG_IEEE80211R |
| 694 | case WLAN_AUTH_FT: |
| 695 | sta->auth_alg = WLAN_AUTH_FT; |
| 696 | if (sta->wpa_sm == NULL) |
| 697 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 698 | sta->addr, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 699 | if (sta->wpa_sm == NULL) { |
| 700 | wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA " |
| 701 | "state machine"); |
| 702 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 703 | goto fail; |
| 704 | } |
| 705 | wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid, |
| 706 | auth_transaction, mgmt->u.auth.variable, |
| 707 | len - IEEE80211_HDRLEN - |
| 708 | sizeof(mgmt->u.auth), |
| 709 | handle_auth_ft_finish, hapd); |
| 710 | /* handle_auth_ft_finish() callback will complete auth. */ |
| 711 | return; |
| 712 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 713 | #ifdef CONFIG_SAE |
| 714 | case WLAN_AUTH_SAE: |
| 715 | handle_auth_sae(hapd, sta, mgmt, len, auth_transaction); |
| 716 | return; |
| 717 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | fail: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 721 | os_free(identity); |
| 722 | os_free(radius_cui); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 723 | hostapd_free_psk_list(psk); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 724 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 725 | send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg, |
| 726 | auth_transaction + 1, resp, resp_ies, resp_ies_len); |
| 727 | } |
| 728 | |
| 729 | |
| 730 | static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta) |
| 731 | { |
| 732 | int i, j = 32, aid; |
| 733 | |
| 734 | /* get a unique AID */ |
| 735 | if (sta->aid > 0) { |
| 736 | wpa_printf(MSG_DEBUG, " old AID %d", sta->aid); |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | for (i = 0; i < AID_WORDS; i++) { |
| 741 | if (hapd->sta_aid[i] == (u32) -1) |
| 742 | continue; |
| 743 | for (j = 0; j < 32; j++) { |
| 744 | if (!(hapd->sta_aid[i] & BIT(j))) |
| 745 | break; |
| 746 | } |
| 747 | if (j < 32) |
| 748 | break; |
| 749 | } |
| 750 | if (j == 32) |
| 751 | return -1; |
| 752 | aid = i * 32 + j + 1; |
| 753 | if (aid > 2007) |
| 754 | return -1; |
| 755 | |
| 756 | sta->aid = aid; |
| 757 | hapd->sta_aid[i] |= BIT(j); |
| 758 | wpa_printf(MSG_DEBUG, " new AID %d", sta->aid); |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | |
| 763 | static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta, |
| 764 | const u8 *ssid_ie, size_t ssid_ie_len) |
| 765 | { |
| 766 | if (ssid_ie == NULL) |
| 767 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 768 | |
| 769 | if (ssid_ie_len != hapd->conf->ssid.ssid_len || |
| 770 | os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 771 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 772 | HOSTAPD_LEVEL_INFO, |
| 773 | "Station tried to associate with unknown SSID " |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 774 | "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 775 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 776 | } |
| 777 | |
| 778 | return WLAN_STATUS_SUCCESS; |
| 779 | } |
| 780 | |
| 781 | |
| 782 | static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta, |
| 783 | const u8 *wmm_ie, size_t wmm_ie_len) |
| 784 | { |
| 785 | sta->flags &= ~WLAN_STA_WMM; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 786 | sta->qosinfo = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 787 | if (wmm_ie && hapd->conf->wmm_enabled) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 788 | struct wmm_information_element *wmm; |
| 789 | |
| 790 | if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 791 | hostapd_logger(hapd, sta->addr, |
| 792 | HOSTAPD_MODULE_WPA, |
| 793 | HOSTAPD_LEVEL_DEBUG, |
| 794 | "invalid WMM element in association " |
| 795 | "request"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 796 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 797 | } |
| 798 | |
| 799 | sta->flags |= WLAN_STA_WMM; |
| 800 | wmm = (struct wmm_information_element *) wmm_ie; |
| 801 | sta->qosinfo = wmm->qos_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 802 | } |
| 803 | return WLAN_STATUS_SUCCESS; |
| 804 | } |
| 805 | |
| 806 | |
| 807 | static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta, |
| 808 | struct ieee802_11_elems *elems) |
| 809 | { |
| 810 | if (!elems->supp_rates) { |
| 811 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 812 | HOSTAPD_LEVEL_DEBUG, |
| 813 | "No supported rates element in AssocReq"); |
| 814 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 815 | } |
| 816 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 817 | if (elems->supp_rates_len + elems->ext_supp_rates_len > |
| 818 | sizeof(sta->supported_rates)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 819 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 820 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 821 | "Invalid supported rates element length %d+%d", |
| 822 | elems->supp_rates_len, |
| 823 | elems->ext_supp_rates_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 824 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 825 | } |
| 826 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 827 | sta->supported_rates_len = merge_byte_arrays( |
| 828 | sta->supported_rates, sizeof(sta->supported_rates), |
| 829 | elems->supp_rates, elems->supp_rates_len, |
| 830 | elems->ext_supp_rates, elems->ext_supp_rates_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 831 | |
| 832 | return WLAN_STATUS_SUCCESS; |
| 833 | } |
| 834 | |
| 835 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 836 | static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta, |
| 837 | const u8 *ext_capab_ie, size_t ext_capab_ie_len) |
| 838 | { |
| 839 | #ifdef CONFIG_INTERWORKING |
| 840 | /* check for QoS Map support */ |
| 841 | if (ext_capab_ie_len >= 5) { |
| 842 | if (ext_capab_ie[4] & 0x01) |
| 843 | sta->qos_map_enabled = 1; |
| 844 | } |
| 845 | #endif /* CONFIG_INTERWORKING */ |
| 846 | |
| 847 | return WLAN_STATUS_SUCCESS; |
| 848 | } |
| 849 | |
| 850 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 851 | static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta, |
| 852 | const u8 *ies, size_t ies_len, int reassoc) |
| 853 | { |
| 854 | struct ieee802_11_elems elems; |
| 855 | u16 resp; |
| 856 | const u8 *wpa_ie; |
| 857 | size_t wpa_ie_len; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 858 | const u8 *p2p_dev_addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 859 | |
| 860 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) { |
| 861 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 862 | HOSTAPD_LEVEL_INFO, "Station sent an invalid " |
| 863 | "association request"); |
| 864 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 865 | } |
| 866 | |
| 867 | resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len); |
| 868 | if (resp != WLAN_STATUS_SUCCESS) |
| 869 | return resp; |
| 870 | resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len); |
| 871 | if (resp != WLAN_STATUS_SUCCESS) |
| 872 | return resp; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 873 | resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len); |
| 874 | if (resp != WLAN_STATUS_SUCCESS) |
| 875 | return resp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 876 | resp = copy_supp_rates(hapd, sta, &elems); |
| 877 | if (resp != WLAN_STATUS_SUCCESS) |
| 878 | return resp; |
| 879 | #ifdef CONFIG_IEEE80211N |
| 880 | resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities, |
| 881 | elems.ht_capabilities_len); |
| 882 | if (resp != WLAN_STATUS_SUCCESS) |
| 883 | return resp; |
| 884 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && |
| 885 | !(sta->flags & WLAN_STA_HT)) { |
| 886 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 887 | HOSTAPD_LEVEL_INFO, "Station does not support " |
| 888 | "mandatory HT PHY - reject association"); |
| 889 | return WLAN_STATUS_ASSOC_DENIED_NO_HT; |
| 890 | } |
| 891 | #endif /* CONFIG_IEEE80211N */ |
| 892 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 893 | #ifdef CONFIG_IEEE80211AC |
| 894 | resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities, |
| 895 | elems.vht_capabilities_len); |
| 896 | if (resp != WLAN_STATUS_SUCCESS) |
| 897 | return resp; |
| 898 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && |
| 899 | !(sta->flags & WLAN_STA_VHT)) { |
| 900 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 901 | HOSTAPD_LEVEL_INFO, "Station does not support " |
| 902 | "mandatory VHT PHY - reject association"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 903 | return WLAN_STATUS_ASSOC_DENIED_NO_VHT; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 904 | } |
| 905 | #endif /* CONFIG_IEEE80211AC */ |
| 906 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 907 | #ifdef CONFIG_P2P |
| 908 | if (elems.p2p) { |
| 909 | wpabuf_free(sta->p2p_ie); |
| 910 | sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len, |
| 911 | P2P_IE_VENDOR_TYPE); |
| 912 | if (sta->p2p_ie) |
| 913 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); |
| 914 | } else { |
| 915 | wpabuf_free(sta->p2p_ie); |
| 916 | sta->p2p_ie = NULL; |
| 917 | } |
| 918 | #endif /* CONFIG_P2P */ |
| 919 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 920 | if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) { |
| 921 | wpa_ie = elems.rsn_ie; |
| 922 | wpa_ie_len = elems.rsn_ie_len; |
| 923 | } else if ((hapd->conf->wpa & WPA_PROTO_WPA) && |
| 924 | elems.wpa_ie) { |
| 925 | wpa_ie = elems.wpa_ie; |
| 926 | wpa_ie_len = elems.wpa_ie_len; |
| 927 | } else { |
| 928 | wpa_ie = NULL; |
| 929 | wpa_ie_len = 0; |
| 930 | } |
| 931 | |
| 932 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 933 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 934 | if (hapd->conf->wps_state && elems.wps_ie) { |
| 935 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association " |
| 936 | "Request - assume WPS is used"); |
| 937 | sta->flags |= WLAN_STA_WPS; |
| 938 | wpabuf_free(sta->wps_ie); |
| 939 | sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, |
| 940 | WPS_IE_VENDOR_TYPE); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 941 | if (sta->wps_ie && wps_is_20(sta->wps_ie)) { |
| 942 | wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0"); |
| 943 | sta->flags |= WLAN_STA_WPS2; |
| 944 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 945 | wpa_ie = NULL; |
| 946 | wpa_ie_len = 0; |
| 947 | if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) { |
| 948 | wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in " |
| 949 | "(Re)Association Request - reject"); |
| 950 | return WLAN_STATUS_INVALID_IE; |
| 951 | } |
| 952 | } else if (hapd->conf->wps_state && wpa_ie == NULL) { |
| 953 | wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in " |
| 954 | "(Re)Association Request - possible WPS use"); |
| 955 | sta->flags |= WLAN_STA_MAYBE_WPS; |
| 956 | } else |
| 957 | #endif /* CONFIG_WPS */ |
| 958 | if (hapd->conf->wpa && wpa_ie == NULL) { |
| 959 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 960 | HOSTAPD_LEVEL_INFO, |
| 961 | "No WPA/RSN IE in association request"); |
| 962 | return WLAN_STATUS_INVALID_IE; |
| 963 | } |
| 964 | |
| 965 | if (hapd->conf->wpa && wpa_ie) { |
| 966 | int res; |
| 967 | wpa_ie -= 2; |
| 968 | wpa_ie_len += 2; |
| 969 | if (sta->wpa_sm == NULL) |
| 970 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 971 | sta->addr, |
| 972 | p2p_dev_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 973 | if (sta->wpa_sm == NULL) { |
| 974 | wpa_printf(MSG_WARNING, "Failed to initialize WPA " |
| 975 | "state machine"); |
| 976 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 977 | } |
| 978 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, |
| 979 | wpa_ie, wpa_ie_len, |
| 980 | elems.mdie, elems.mdie_len); |
| 981 | if (res == WPA_INVALID_GROUP) |
| 982 | resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; |
| 983 | else if (res == WPA_INVALID_PAIRWISE) |
| 984 | resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; |
| 985 | else if (res == WPA_INVALID_AKMP) |
| 986 | resp = WLAN_STATUS_AKMP_NOT_VALID; |
| 987 | else if (res == WPA_ALLOC_FAIL) |
| 988 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 989 | #ifdef CONFIG_IEEE80211W |
| 990 | else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) |
| 991 | resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION; |
| 992 | else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) |
| 993 | resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION; |
| 994 | #endif /* CONFIG_IEEE80211W */ |
| 995 | else if (res == WPA_INVALID_MDIE) |
| 996 | resp = WLAN_STATUS_INVALID_MDIE; |
| 997 | else if (res != WPA_IE_OK) |
| 998 | resp = WLAN_STATUS_INVALID_IE; |
| 999 | if (resp != WLAN_STATUS_SUCCESS) |
| 1000 | return resp; |
| 1001 | #ifdef CONFIG_IEEE80211W |
| 1002 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && |
| 1003 | sta->sa_query_count > 0) |
| 1004 | ap_check_sa_query_timeout(hapd, sta); |
| 1005 | if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && |
| 1006 | (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) { |
| 1007 | /* |
| 1008 | * STA has already been associated with MFP and SA |
| 1009 | * Query timeout has not been reached. Reject the |
| 1010 | * association attempt temporarily and start SA Query, |
| 1011 | * if one is not pending. |
| 1012 | */ |
| 1013 | |
| 1014 | if (sta->sa_query_count == 0) |
| 1015 | ap_sta_start_sa_query(hapd, sta); |
| 1016 | |
| 1017 | return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
| 1018 | } |
| 1019 | |
| 1020 | if (wpa_auth_uses_mfp(sta->wpa_sm)) |
| 1021 | sta->flags |= WLAN_STA_MFP; |
| 1022 | else |
| 1023 | sta->flags &= ~WLAN_STA_MFP; |
| 1024 | #endif /* CONFIG_IEEE80211W */ |
| 1025 | |
| 1026 | #ifdef CONFIG_IEEE80211R |
| 1027 | if (sta->auth_alg == WLAN_AUTH_FT) { |
| 1028 | if (!reassoc) { |
| 1029 | wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried " |
| 1030 | "to use association (not " |
| 1031 | "re-association) with FT auth_alg", |
| 1032 | MAC2STR(sta->addr)); |
| 1033 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1034 | } |
| 1035 | |
| 1036 | resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies, |
| 1037 | ies_len); |
| 1038 | if (resp != WLAN_STATUS_SUCCESS) |
| 1039 | return resp; |
| 1040 | } |
| 1041 | #endif /* CONFIG_IEEE80211R */ |
| 1042 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1043 | #ifdef CONFIG_SAE |
| 1044 | if (wpa_auth_uses_sae(sta->wpa_sm) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1045 | sta->auth_alg != WLAN_AUTH_SAE && |
| 1046 | !(sta->auth_alg == WLAN_AUTH_FT && |
| 1047 | wpa_auth_uses_ft_sae(sta->wpa_sm))) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1048 | wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use " |
| 1049 | "SAE AKM after non-SAE auth_alg %u", |
| 1050 | MAC2STR(sta->addr), sta->auth_alg); |
| 1051 | return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 1052 | } |
| 1053 | #endif /* CONFIG_SAE */ |
| 1054 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1055 | #ifdef CONFIG_IEEE80211N |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1056 | if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1057 | wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) { |
| 1058 | hostapd_logger(hapd, sta->addr, |
| 1059 | HOSTAPD_MODULE_IEEE80211, |
| 1060 | HOSTAPD_LEVEL_INFO, |
| 1061 | "Station tried to use TKIP with HT " |
| 1062 | "association"); |
| 1063 | return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; |
| 1064 | } |
| 1065 | #endif /* CONFIG_IEEE80211N */ |
| 1066 | } else |
| 1067 | wpa_auth_sta_no_wpa(sta->wpa_sm); |
| 1068 | |
| 1069 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1070 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len); |
| 1071 | #endif /* CONFIG_P2P */ |
| 1072 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1073 | #ifdef CONFIG_HS20 |
| 1074 | wpabuf_free(sta->hs20_ie); |
| 1075 | if (elems.hs20 && elems.hs20_len > 4) { |
| 1076 | sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4, |
| 1077 | elems.hs20_len - 4); |
| 1078 | } else |
| 1079 | sta->hs20_ie = NULL; |
| 1080 | #endif /* CONFIG_HS20 */ |
| 1081 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1082 | return WLAN_STATUS_SUCCESS; |
| 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | static void send_deauth(struct hostapd_data *hapd, const u8 *addr, |
| 1087 | u16 reason_code) |
| 1088 | { |
| 1089 | int send_len; |
| 1090 | struct ieee80211_mgmt reply; |
| 1091 | |
| 1092 | os_memset(&reply, 0, sizeof(reply)); |
| 1093 | reply.frame_control = |
| 1094 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH); |
| 1095 | os_memcpy(reply.da, addr, ETH_ALEN); |
| 1096 | os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN); |
| 1097 | os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN); |
| 1098 | |
| 1099 | send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth); |
| 1100 | reply.u.deauth.reason_code = host_to_le16(reason_code); |
| 1101 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1102 | if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1103 | wpa_printf(MSG_INFO, "Failed to send deauth: %s", |
| 1104 | strerror(errno)); |
| 1105 | } |
| 1106 | |
| 1107 | |
| 1108 | static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta, |
| 1109 | u16 status_code, int reassoc, const u8 *ies, |
| 1110 | size_t ies_len) |
| 1111 | { |
| 1112 | int send_len; |
| 1113 | u8 buf[sizeof(struct ieee80211_mgmt) + 1024]; |
| 1114 | struct ieee80211_mgmt *reply; |
| 1115 | u8 *p; |
| 1116 | |
| 1117 | os_memset(buf, 0, sizeof(buf)); |
| 1118 | reply = (struct ieee80211_mgmt *) buf; |
| 1119 | reply->frame_control = |
| 1120 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 1121 | (reassoc ? WLAN_FC_STYPE_REASSOC_RESP : |
| 1122 | WLAN_FC_STYPE_ASSOC_RESP)); |
| 1123 | os_memcpy(reply->da, sta->addr, ETH_ALEN); |
| 1124 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); |
| 1125 | os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN); |
| 1126 | |
| 1127 | send_len = IEEE80211_HDRLEN; |
| 1128 | send_len += sizeof(reply->u.assoc_resp); |
| 1129 | reply->u.assoc_resp.capab_info = |
| 1130 | host_to_le16(hostapd_own_capab_info(hapd, sta, 0)); |
| 1131 | reply->u.assoc_resp.status_code = host_to_le16(status_code); |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame^] | 1132 | 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] | 1133 | /* Supported rates */ |
| 1134 | p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable); |
| 1135 | /* Extended supported rates */ |
| 1136 | p = hostapd_eid_ext_supp_rates(hapd, p); |
| 1137 | |
| 1138 | #ifdef CONFIG_IEEE80211R |
| 1139 | if (status_code == WLAN_STATUS_SUCCESS) { |
| 1140 | /* IEEE 802.11r: Mobility Domain Information, Fast BSS |
| 1141 | * Transition Information, RSN, [RIC Response] */ |
| 1142 | p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p, |
| 1143 | buf + sizeof(buf) - p, |
| 1144 | sta->auth_alg, ies, ies_len); |
| 1145 | } |
| 1146 | #endif /* CONFIG_IEEE80211R */ |
| 1147 | |
| 1148 | #ifdef CONFIG_IEEE80211W |
| 1149 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY) |
| 1150 | p = hostapd_eid_assoc_comeback_time(hapd, sta, p); |
| 1151 | #endif /* CONFIG_IEEE80211W */ |
| 1152 | |
| 1153 | #ifdef CONFIG_IEEE80211N |
| 1154 | p = hostapd_eid_ht_capabilities(hapd, p); |
| 1155 | p = hostapd_eid_ht_operation(hapd, p); |
| 1156 | #endif /* CONFIG_IEEE80211N */ |
| 1157 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1158 | #ifdef CONFIG_IEEE80211AC |
| 1159 | p = hostapd_eid_vht_capabilities(hapd, p); |
| 1160 | p = hostapd_eid_vht_operation(hapd, p); |
| 1161 | #endif /* CONFIG_IEEE80211AC */ |
| 1162 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1163 | p = hostapd_eid_ext_capab(hapd, p); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1164 | p = hostapd_eid_bss_max_idle_period(hapd, p); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1165 | if (sta->qos_map_enabled) |
| 1166 | p = hostapd_eid_qos_map_set(hapd, p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1167 | |
| 1168 | if (sta->flags & WLAN_STA_WMM) |
| 1169 | p = hostapd_eid_wmm(hapd, p); |
| 1170 | |
| 1171 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1172 | if ((sta->flags & WLAN_STA_WPS) || |
| 1173 | ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1174 | struct wpabuf *wps = wps_build_assoc_resp_ie(); |
| 1175 | if (wps) { |
| 1176 | os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps)); |
| 1177 | p += wpabuf_len(wps); |
| 1178 | wpabuf_free(wps); |
| 1179 | } |
| 1180 | } |
| 1181 | #endif /* CONFIG_WPS */ |
| 1182 | |
| 1183 | #ifdef CONFIG_P2P |
| 1184 | if (sta->p2p_ie) { |
| 1185 | struct wpabuf *p2p_resp_ie; |
| 1186 | enum p2p_status_code status; |
| 1187 | switch (status_code) { |
| 1188 | case WLAN_STATUS_SUCCESS: |
| 1189 | status = P2P_SC_SUCCESS; |
| 1190 | break; |
| 1191 | case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA: |
| 1192 | status = P2P_SC_FAIL_LIMIT_REACHED; |
| 1193 | break; |
| 1194 | default: |
| 1195 | status = P2P_SC_FAIL_INVALID_PARAMS; |
| 1196 | break; |
| 1197 | } |
| 1198 | p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status); |
| 1199 | if (p2p_resp_ie) { |
| 1200 | os_memcpy(p, wpabuf_head(p2p_resp_ie), |
| 1201 | wpabuf_len(p2p_resp_ie)); |
| 1202 | p += wpabuf_len(p2p_resp_ie); |
| 1203 | wpabuf_free(p2p_resp_ie); |
| 1204 | } |
| 1205 | } |
| 1206 | #endif /* CONFIG_P2P */ |
| 1207 | |
| 1208 | #ifdef CONFIG_P2P_MANAGER |
| 1209 | if (hapd->conf->p2p & P2P_MANAGE) |
| 1210 | p = hostapd_eid_p2p_manage(hapd, p); |
| 1211 | #endif /* CONFIG_P2P_MANAGER */ |
| 1212 | |
| 1213 | send_len += p - reply->u.assoc_resp.variable; |
| 1214 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1215 | if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1216 | wpa_printf(MSG_INFO, "Failed to send assoc resp: %s", |
| 1217 | strerror(errno)); |
| 1218 | } |
| 1219 | |
| 1220 | |
| 1221 | static void handle_assoc(struct hostapd_data *hapd, |
| 1222 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 1223 | int reassoc) |
| 1224 | { |
| 1225 | u16 capab_info, listen_interval; |
| 1226 | u16 resp = WLAN_STATUS_SUCCESS; |
| 1227 | const u8 *pos; |
| 1228 | int left, i; |
| 1229 | struct sta_info *sta; |
| 1230 | |
| 1231 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) : |
| 1232 | sizeof(mgmt->u.assoc_req))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1233 | wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)", |
| 1234 | reassoc, (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1235 | return; |
| 1236 | } |
| 1237 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1238 | #ifdef CONFIG_TESTING_OPTIONS |
| 1239 | if (reassoc) { |
| 1240 | if (hapd->iconf->ignore_reassoc_probability > 0.0d && |
| 1241 | drand48() < hapd->iconf->ignore_reassoc_probability) { |
| 1242 | wpa_printf(MSG_INFO, |
| 1243 | "TESTING: ignoring reassoc request from " |
| 1244 | MACSTR, MAC2STR(mgmt->sa)); |
| 1245 | return; |
| 1246 | } |
| 1247 | } else { |
| 1248 | if (hapd->iconf->ignore_assoc_probability > 0.0d && |
| 1249 | drand48() < hapd->iconf->ignore_assoc_probability) { |
| 1250 | wpa_printf(MSG_INFO, |
| 1251 | "TESTING: ignoring assoc request from " |
| 1252 | MACSTR, MAC2STR(mgmt->sa)); |
| 1253 | return; |
| 1254 | } |
| 1255 | } |
| 1256 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1257 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1258 | if (reassoc) { |
| 1259 | capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info); |
| 1260 | listen_interval = le_to_host16( |
| 1261 | mgmt->u.reassoc_req.listen_interval); |
| 1262 | wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR |
| 1263 | " capab_info=0x%02x listen_interval=%d current_ap=" |
| 1264 | MACSTR, |
| 1265 | MAC2STR(mgmt->sa), capab_info, listen_interval, |
| 1266 | MAC2STR(mgmt->u.reassoc_req.current_ap)); |
| 1267 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req)); |
| 1268 | pos = mgmt->u.reassoc_req.variable; |
| 1269 | } else { |
| 1270 | capab_info = le_to_host16(mgmt->u.assoc_req.capab_info); |
| 1271 | listen_interval = le_to_host16( |
| 1272 | mgmt->u.assoc_req.listen_interval); |
| 1273 | wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR |
| 1274 | " capab_info=0x%02x listen_interval=%d", |
| 1275 | MAC2STR(mgmt->sa), capab_info, listen_interval); |
| 1276 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req)); |
| 1277 | pos = mgmt->u.assoc_req.variable; |
| 1278 | } |
| 1279 | |
| 1280 | sta = ap_get_sta(hapd, mgmt->sa); |
| 1281 | #ifdef CONFIG_IEEE80211R |
| 1282 | if (sta && sta->auth_alg == WLAN_AUTH_FT && |
| 1283 | (sta->flags & WLAN_STA_AUTH) == 0) { |
| 1284 | wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate " |
| 1285 | "prior to authentication since it is using " |
| 1286 | "over-the-DS FT", MAC2STR(mgmt->sa)); |
| 1287 | } else |
| 1288 | #endif /* CONFIG_IEEE80211R */ |
| 1289 | if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) { |
| 1290 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 1291 | HOSTAPD_LEVEL_INFO, "Station tried to " |
| 1292 | "associate before authentication " |
| 1293 | "(aid=%d flags=0x%x)", |
| 1294 | sta ? sta->aid : -1, |
| 1295 | sta ? sta->flags : 0); |
| 1296 | send_deauth(hapd, mgmt->sa, |
| 1297 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); |
| 1298 | return; |
| 1299 | } |
| 1300 | |
| 1301 | if (hapd->tkip_countermeasures) { |
| 1302 | resp = WLAN_REASON_MICHAEL_MIC_FAILURE; |
| 1303 | goto fail; |
| 1304 | } |
| 1305 | |
| 1306 | if (listen_interval > hapd->conf->max_listen_interval) { |
| 1307 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 1308 | HOSTAPD_LEVEL_DEBUG, |
| 1309 | "Too large Listen Interval (%d)", |
| 1310 | listen_interval); |
| 1311 | resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE; |
| 1312 | goto fail; |
| 1313 | } |
| 1314 | |
| 1315 | /* followed by SSID and Supported rates; and HT capabilities if 802.11n |
| 1316 | * is used */ |
| 1317 | resp = check_assoc_ies(hapd, sta, pos, left, reassoc); |
| 1318 | if (resp != WLAN_STATUS_SUCCESS) |
| 1319 | goto fail; |
| 1320 | |
| 1321 | if (hostapd_get_aid(hapd, sta) < 0) { |
| 1322 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 1323 | HOSTAPD_LEVEL_INFO, "No room for more AIDs"); |
| 1324 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 1325 | goto fail; |
| 1326 | } |
| 1327 | |
| 1328 | sta->capability = capab_info; |
| 1329 | sta->listen_interval = listen_interval; |
| 1330 | |
| 1331 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 1332 | sta->flags |= WLAN_STA_NONERP; |
| 1333 | for (i = 0; i < sta->supported_rates_len; i++) { |
| 1334 | if ((sta->supported_rates[i] & 0x7f) > 22) { |
| 1335 | sta->flags &= ~WLAN_STA_NONERP; |
| 1336 | break; |
| 1337 | } |
| 1338 | } |
| 1339 | if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) { |
| 1340 | sta->nonerp_set = 1; |
| 1341 | hapd->iface->num_sta_non_erp++; |
| 1342 | if (hapd->iface->num_sta_non_erp == 1) |
| 1343 | ieee802_11_set_beacons(hapd->iface); |
| 1344 | } |
| 1345 | |
| 1346 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) && |
| 1347 | !sta->no_short_slot_time_set) { |
| 1348 | sta->no_short_slot_time_set = 1; |
| 1349 | hapd->iface->num_sta_no_short_slot_time++; |
| 1350 | if (hapd->iface->current_mode->mode == |
| 1351 | HOSTAPD_MODE_IEEE80211G && |
| 1352 | hapd->iface->num_sta_no_short_slot_time == 1) |
| 1353 | ieee802_11_set_beacons(hapd->iface); |
| 1354 | } |
| 1355 | |
| 1356 | if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 1357 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; |
| 1358 | else |
| 1359 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; |
| 1360 | |
| 1361 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && |
| 1362 | !sta->no_short_preamble_set) { |
| 1363 | sta->no_short_preamble_set = 1; |
| 1364 | hapd->iface->num_sta_no_short_preamble++; |
| 1365 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G |
| 1366 | && hapd->iface->num_sta_no_short_preamble == 1) |
| 1367 | ieee802_11_set_beacons(hapd->iface); |
| 1368 | } |
| 1369 | |
| 1370 | #ifdef CONFIG_IEEE80211N |
| 1371 | update_ht_state(hapd, sta); |
| 1372 | #endif /* CONFIG_IEEE80211N */ |
| 1373 | |
| 1374 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1375 | HOSTAPD_LEVEL_DEBUG, |
| 1376 | "association OK (aid %d)", sta->aid); |
| 1377 | /* Station will be marked associated, after it acknowledges AssocResp |
| 1378 | */ |
| 1379 | sta->flags |= WLAN_STA_ASSOC_REQ_OK; |
| 1380 | |
| 1381 | #ifdef CONFIG_IEEE80211W |
| 1382 | if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) { |
| 1383 | wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out " |
| 1384 | "SA Query procedure", reassoc ? "re" : ""); |
| 1385 | /* TODO: Send a protected Disassociate frame to the STA using |
| 1386 | * the old key and Reason Code "Previous Authentication no |
| 1387 | * longer valid". Make sure this is only sent protected since |
| 1388 | * unprotected frame would be received by the STA that is now |
| 1389 | * trying to associate. |
| 1390 | */ |
| 1391 | } |
| 1392 | #endif /* CONFIG_IEEE80211W */ |
| 1393 | |
| 1394 | if (reassoc) { |
| 1395 | os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap, |
| 1396 | ETH_ALEN); |
| 1397 | } |
| 1398 | |
| 1399 | if (sta->last_assoc_req) |
| 1400 | os_free(sta->last_assoc_req); |
| 1401 | sta->last_assoc_req = os_malloc(len); |
| 1402 | if (sta->last_assoc_req) |
| 1403 | os_memcpy(sta->last_assoc_req, mgmt, len); |
| 1404 | |
| 1405 | /* Make sure that the previously registered inactivity timer will not |
| 1406 | * remove the STA immediately. */ |
| 1407 | sta->timeout_next = STA_NULLFUNC; |
| 1408 | |
| 1409 | fail: |
| 1410 | send_assoc_resp(hapd, sta, resp, reassoc, pos, left); |
| 1411 | } |
| 1412 | |
| 1413 | |
| 1414 | static void handle_disassoc(struct hostapd_data *hapd, |
| 1415 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 1416 | { |
| 1417 | struct sta_info *sta; |
| 1418 | |
| 1419 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1420 | wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)", |
| 1421 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1422 | return; |
| 1423 | } |
| 1424 | |
| 1425 | wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d", |
| 1426 | MAC2STR(mgmt->sa), |
| 1427 | le_to_host16(mgmt->u.disassoc.reason_code)); |
| 1428 | |
| 1429 | sta = ap_get_sta(hapd, mgmt->sa); |
| 1430 | if (sta == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1431 | wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated", |
| 1432 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1433 | return; |
| 1434 | } |
| 1435 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1436 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1437 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1438 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); |
| 1439 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1440 | HOSTAPD_LEVEL_INFO, "disassociated"); |
| 1441 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 1442 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 1443 | /* Stop Accounting and IEEE 802.1X sessions, but leave the STA |
| 1444 | * authenticated. */ |
| 1445 | accounting_sta_stop(hapd, sta); |
| 1446 | ieee802_1x_free_station(sta); |
| 1447 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 1448 | |
| 1449 | if (sta->timeout_next == STA_NULLFUNC || |
| 1450 | sta->timeout_next == STA_DISASSOC) { |
| 1451 | sta->timeout_next = STA_DEAUTH; |
| 1452 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 1453 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, |
| 1454 | hapd, sta); |
| 1455 | } |
| 1456 | |
| 1457 | mlme_disassociate_indication( |
| 1458 | hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code)); |
| 1459 | } |
| 1460 | |
| 1461 | |
| 1462 | static void handle_deauth(struct hostapd_data *hapd, |
| 1463 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 1464 | { |
| 1465 | struct sta_info *sta; |
| 1466 | |
| 1467 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1468 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short " |
| 1469 | "payload (len=%lu)", (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1470 | return; |
| 1471 | } |
| 1472 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1473 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1474 | " reason_code=%d", |
| 1475 | MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code)); |
| 1476 | |
| 1477 | sta = ap_get_sta(hapd, mgmt->sa); |
| 1478 | if (sta == NULL) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1479 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying " |
| 1480 | "to deauthenticate, but it is not authenticated", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1481 | MAC2STR(mgmt->sa)); |
| 1482 | return; |
| 1483 | } |
| 1484 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1485 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1486 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | |
| 1487 | WLAN_STA_ASSOC_REQ_OK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1488 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
| 1489 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1490 | HOSTAPD_LEVEL_DEBUG, "deauthenticated"); |
| 1491 | mlme_deauthenticate_indication( |
| 1492 | hapd, sta, le_to_host16(mgmt->u.deauth.reason_code)); |
| 1493 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 1494 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 1495 | ap_free_sta(hapd, sta); |
| 1496 | } |
| 1497 | |
| 1498 | |
| 1499 | static void handle_beacon(struct hostapd_data *hapd, |
| 1500 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 1501 | struct hostapd_frame_info *fi) |
| 1502 | { |
| 1503 | struct ieee802_11_elems elems; |
| 1504 | |
| 1505 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1506 | wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)", |
| 1507 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1508 | return; |
| 1509 | } |
| 1510 | |
| 1511 | (void) ieee802_11_parse_elems(mgmt->u.beacon.variable, |
| 1512 | len - (IEEE80211_HDRLEN + |
| 1513 | sizeof(mgmt->u.beacon)), &elems, |
| 1514 | 0); |
| 1515 | |
| 1516 | ap_list_process_beacon(hapd->iface, mgmt, &elems, fi); |
| 1517 | } |
| 1518 | |
| 1519 | |
| 1520 | #ifdef CONFIG_IEEE80211W |
| 1521 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1522 | static int hostapd_sa_query_action(struct hostapd_data *hapd, |
| 1523 | const struct ieee80211_mgmt *mgmt, |
| 1524 | size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1525 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1526 | const u8 *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1527 | |
| 1528 | end = mgmt->u.action.u.sa_query_resp.trans_id + |
| 1529 | WLAN_SA_QUERY_TR_ID_LEN; |
| 1530 | if (((u8 *) mgmt) + len < end) { |
| 1531 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action " |
| 1532 | "frame (len=%lu)", (unsigned long) len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1533 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1536 | ieee802_11_sa_query_action(hapd, mgmt->sa, |
| 1537 | mgmt->u.action.u.sa_query_resp.action, |
| 1538 | mgmt->u.action.u.sa_query_resp.trans_id); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1539 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | |
| 1543 | static int robust_action_frame(u8 category) |
| 1544 | { |
| 1545 | return category != WLAN_ACTION_PUBLIC && |
| 1546 | category != WLAN_ACTION_HT; |
| 1547 | } |
| 1548 | #endif /* CONFIG_IEEE80211W */ |
| 1549 | |
| 1550 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1551 | static int handle_action(struct hostapd_data *hapd, |
| 1552 | const struct ieee80211_mgmt *mgmt, size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1553 | { |
| 1554 | struct sta_info *sta; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1555 | sta = ap_get_sta(hapd, mgmt->sa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1556 | |
| 1557 | if (len < IEEE80211_HDRLEN + 1) { |
| 1558 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 1559 | HOSTAPD_LEVEL_DEBUG, |
| 1560 | "handle_action - too short payload (len=%lu)", |
| 1561 | (unsigned long) len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1562 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1565 | if (mgmt->u.action.category != WLAN_ACTION_PUBLIC && |
| 1566 | (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) { |
| 1567 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action " |
| 1568 | "frame (category=%u) from unassociated STA " MACSTR, |
| 1569 | MAC2STR(mgmt->sa), mgmt->u.action.category); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1570 | return 0; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1571 | } |
| 1572 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1573 | #ifdef CONFIG_IEEE80211W |
| 1574 | if (sta && (sta->flags & WLAN_STA_MFP) && |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 1575 | !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) && |
| 1576 | robust_action_frame(mgmt->u.action.category)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1577 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 1578 | HOSTAPD_LEVEL_DEBUG, |
| 1579 | "Dropped unprotected Robust Action frame from " |
| 1580 | "an MFP STA"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1581 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1582 | } |
| 1583 | #endif /* CONFIG_IEEE80211W */ |
| 1584 | |
| 1585 | switch (mgmt->u.action.category) { |
| 1586 | #ifdef CONFIG_IEEE80211R |
| 1587 | case WLAN_ACTION_FT: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1588 | if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, |
| 1589 | len - IEEE80211_HDRLEN)) |
| 1590 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1591 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1592 | #endif /* CONFIG_IEEE80211R */ |
| 1593 | case WLAN_ACTION_WMM: |
| 1594 | hostapd_wmm_action(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1595 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1596 | #ifdef CONFIG_IEEE80211W |
| 1597 | case WLAN_ACTION_SA_QUERY: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1598 | return hostapd_sa_query_action(hapd, mgmt, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1599 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1600 | #ifdef CONFIG_WNM |
| 1601 | case WLAN_ACTION_WNM: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1602 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, len); |
| 1603 | return 1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1604 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1605 | case WLAN_ACTION_PUBLIC: |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 1606 | case WLAN_ACTION_PROTECTED_DUAL: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1607 | if (hapd->public_action_cb) { |
| 1608 | hapd->public_action_cb(hapd->public_action_cb_ctx, |
| 1609 | (u8 *) mgmt, len, |
| 1610 | hapd->iface->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1611 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1612 | if (hapd->public_action_cb2) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1613 | hapd->public_action_cb2(hapd->public_action_cb2_ctx, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1614 | (u8 *) mgmt, len, |
| 1615 | hapd->iface->freq); |
| 1616 | } |
| 1617 | if (hapd->public_action_cb || hapd->public_action_cb2) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1618 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1619 | break; |
| 1620 | case WLAN_ACTION_VENDOR_SPECIFIC: |
| 1621 | if (hapd->vendor_action_cb) { |
| 1622 | if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx, |
| 1623 | (u8 *) mgmt, len, |
| 1624 | hapd->iface->freq) == 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1625 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1626 | } |
| 1627 | break; |
| 1628 | } |
| 1629 | |
| 1630 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 1631 | HOSTAPD_LEVEL_DEBUG, |
| 1632 | "handle_action - unknown action category %d or invalid " |
| 1633 | "frame", |
| 1634 | mgmt->u.action.category); |
| 1635 | if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) && |
| 1636 | !(mgmt->sa[0] & 0x01)) { |
| 1637 | struct ieee80211_mgmt *resp; |
| 1638 | |
| 1639 | /* |
| 1640 | * IEEE 802.11-REVma/D9.0 - 7.3.1.11 |
| 1641 | * Return the Action frame to the source without change |
| 1642 | * except that MSB of the Category set to 1. |
| 1643 | */ |
| 1644 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action " |
| 1645 | "frame back to sender"); |
| 1646 | resp = os_malloc(len); |
| 1647 | if (resp == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1648 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1649 | os_memcpy(resp, mgmt, len); |
| 1650 | os_memcpy(resp->da, resp->sa, ETH_ALEN); |
| 1651 | os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); |
| 1652 | os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); |
| 1653 | resp->u.action.category |= 0x80; |
| 1654 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1655 | if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) { |
| 1656 | wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send " |
| 1657 | "Action frame"); |
| 1658 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1659 | os_free(resp); |
| 1660 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1661 | |
| 1662 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | |
| 1666 | /** |
| 1667 | * ieee802_11_mgmt - process incoming IEEE 802.11 management frames |
| 1668 | * @hapd: hostapd BSS data structure (the BSS to which the management frame was |
| 1669 | * sent to) |
| 1670 | * @buf: management frame data (starting from IEEE 802.11 header) |
| 1671 | * @len: length of frame data in octets |
| 1672 | * @fi: meta data about received frame (signal level, etc.) |
| 1673 | * |
| 1674 | * Process all incoming IEEE 802.11 management frames. This will be called for |
| 1675 | * each frame received from the kernel driver through wlan#ap interface. In |
| 1676 | * addition, it can be called to re-inserted pending frames (e.g., when using |
| 1677 | * external RADIUS server as an MAC ACL). |
| 1678 | */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1679 | int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len, |
| 1680 | struct hostapd_frame_info *fi) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1681 | { |
| 1682 | struct ieee80211_mgmt *mgmt; |
| 1683 | int broadcast; |
| 1684 | u16 fc, stype; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1685 | int ret = 0; |
| 1686 | |
| 1687 | #ifdef CONFIG_TESTING_OPTIONS |
| 1688 | if (hapd->ext_mgmt_frame_handling) { |
| 1689 | size_t hex_len = 2 * len + 1; |
| 1690 | char *hex = os_malloc(hex_len); |
| 1691 | if (hex) { |
| 1692 | wpa_snprintf_hex(hex, hex_len, buf, len); |
| 1693 | wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex); |
| 1694 | os_free(hex); |
| 1695 | } |
| 1696 | return 1; |
| 1697 | } |
| 1698 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1699 | |
| 1700 | if (len < 24) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1701 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1702 | |
| 1703 | mgmt = (struct ieee80211_mgmt *) buf; |
| 1704 | fc = le_to_host16(mgmt->frame_control); |
| 1705 | stype = WLAN_FC_GET_STYPE(fc); |
| 1706 | |
| 1707 | if (stype == WLAN_FC_STYPE_BEACON) { |
| 1708 | handle_beacon(hapd, mgmt, len, fi); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1709 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff && |
| 1713 | mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff && |
| 1714 | mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff; |
| 1715 | |
| 1716 | if (!broadcast && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1717 | #ifdef CONFIG_P2P |
| 1718 | /* Invitation responses can be sent with the peer MAC as BSSID */ |
| 1719 | !((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 1720 | stype == WLAN_FC_STYPE_ACTION) && |
| 1721 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1722 | os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1723 | wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address", |
| 1724 | MAC2STR(mgmt->bssid)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1725 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | |
| 1729 | if (stype == WLAN_FC_STYPE_PROBE_REQ) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1730 | handle_probe_req(hapd, mgmt, len, fi->ssi_signal); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1731 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) { |
| 1735 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 1736 | HOSTAPD_LEVEL_DEBUG, |
| 1737 | "MGMT: DA=" MACSTR " not our address", |
| 1738 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1739 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | switch (stype) { |
| 1743 | case WLAN_FC_STYPE_AUTH: |
| 1744 | wpa_printf(MSG_DEBUG, "mgmt::auth"); |
| 1745 | handle_auth(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1746 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1747 | break; |
| 1748 | case WLAN_FC_STYPE_ASSOC_REQ: |
| 1749 | wpa_printf(MSG_DEBUG, "mgmt::assoc_req"); |
| 1750 | handle_assoc(hapd, mgmt, len, 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1751 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1752 | break; |
| 1753 | case WLAN_FC_STYPE_REASSOC_REQ: |
| 1754 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_req"); |
| 1755 | handle_assoc(hapd, mgmt, len, 1); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1756 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1757 | break; |
| 1758 | case WLAN_FC_STYPE_DISASSOC: |
| 1759 | wpa_printf(MSG_DEBUG, "mgmt::disassoc"); |
| 1760 | handle_disassoc(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1761 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1762 | break; |
| 1763 | case WLAN_FC_STYPE_DEAUTH: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1764 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1765 | handle_deauth(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1766 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1767 | break; |
| 1768 | case WLAN_FC_STYPE_ACTION: |
| 1769 | wpa_printf(MSG_DEBUG, "mgmt::action"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1770 | ret = handle_action(hapd, mgmt, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1771 | break; |
| 1772 | default: |
| 1773 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 1774 | HOSTAPD_LEVEL_DEBUG, |
| 1775 | "unknown mgmt frame subtype %d", stype); |
| 1776 | break; |
| 1777 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1778 | |
| 1779 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | |
| 1783 | static void handle_auth_cb(struct hostapd_data *hapd, |
| 1784 | const struct ieee80211_mgmt *mgmt, |
| 1785 | size_t len, int ok) |
| 1786 | { |
| 1787 | u16 auth_alg, auth_transaction, status_code; |
| 1788 | struct sta_info *sta; |
| 1789 | |
| 1790 | if (!ok) { |
| 1791 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, |
| 1792 | HOSTAPD_LEVEL_NOTICE, |
| 1793 | "did not acknowledge authentication response"); |
| 1794 | return; |
| 1795 | } |
| 1796 | |
| 1797 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1798 | wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)", |
| 1799 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1800 | return; |
| 1801 | } |
| 1802 | |
| 1803 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 1804 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); |
| 1805 | status_code = le_to_host16(mgmt->u.auth.status_code); |
| 1806 | |
| 1807 | sta = ap_get_sta(hapd, mgmt->da); |
| 1808 | if (!sta) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1809 | wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found", |
| 1810 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1811 | return; |
| 1812 | } |
| 1813 | |
| 1814 | if (status_code == WLAN_STATUS_SUCCESS && |
| 1815 | ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) || |
| 1816 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) { |
| 1817 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1818 | HOSTAPD_LEVEL_INFO, "authenticated"); |
| 1819 | sta->flags |= WLAN_STA_AUTH; |
| 1820 | } |
| 1821 | } |
| 1822 | |
| 1823 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1824 | static void hostapd_set_wds_encryption(struct hostapd_data *hapd, |
| 1825 | struct sta_info *sta, |
| 1826 | char *ifname_wds) |
| 1827 | { |
| 1828 | int i; |
| 1829 | struct hostapd_ssid *ssid = sta->ssid; |
| 1830 | |
| 1831 | if (hapd->conf->ieee802_1x || hapd->conf->wpa) |
| 1832 | return; |
| 1833 | |
| 1834 | for (i = 0; i < 4; i++) { |
| 1835 | if (ssid->wep.key[i] && |
| 1836 | hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i, |
| 1837 | i == ssid->wep.idx, NULL, 0, |
| 1838 | ssid->wep.key[i], ssid->wep.len[i])) { |
| 1839 | wpa_printf(MSG_WARNING, |
| 1840 | "Could not set WEP keys for WDS interface; %s", |
| 1841 | ifname_wds); |
| 1842 | break; |
| 1843 | } |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1848 | static void handle_assoc_cb(struct hostapd_data *hapd, |
| 1849 | const struct ieee80211_mgmt *mgmt, |
| 1850 | size_t len, int reassoc, int ok) |
| 1851 | { |
| 1852 | u16 status; |
| 1853 | struct sta_info *sta; |
| 1854 | int new_assoc = 1; |
| 1855 | struct ieee80211_ht_capabilities ht_cap; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1856 | struct ieee80211_vht_capabilities vht_cap; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1857 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1858 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) : |
| 1859 | sizeof(mgmt->u.assoc_resp))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1860 | wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)", |
| 1861 | reassoc, (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1862 | return; |
| 1863 | } |
| 1864 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1865 | sta = ap_get_sta(hapd, mgmt->da); |
| 1866 | if (!sta) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1867 | wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found", |
| 1868 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1869 | return; |
| 1870 | } |
| 1871 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 1872 | if (!ok) { |
| 1873 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, |
| 1874 | HOSTAPD_LEVEL_DEBUG, |
| 1875 | "did not acknowledge association response"); |
| 1876 | sta->flags &= ~WLAN_STA_ASSOC_REQ_OK; |
| 1877 | return; |
| 1878 | } |
| 1879 | |
| 1880 | if (reassoc) |
| 1881 | status = le_to_host16(mgmt->u.reassoc_resp.status_code); |
| 1882 | else |
| 1883 | status = le_to_host16(mgmt->u.assoc_resp.status_code); |
| 1884 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1885 | if (status != WLAN_STATUS_SUCCESS) |
| 1886 | goto fail; |
| 1887 | |
| 1888 | /* Stop previous accounting session, if one is started, and allocate |
| 1889 | * new session id for the new session. */ |
| 1890 | accounting_sta_stop(hapd, sta); |
| 1891 | |
| 1892 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1893 | HOSTAPD_LEVEL_INFO, |
| 1894 | "associated (aid %d)", |
| 1895 | sta->aid); |
| 1896 | |
| 1897 | if (sta->flags & WLAN_STA_ASSOC) |
| 1898 | new_assoc = 0; |
| 1899 | sta->flags |= WLAN_STA_ASSOC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1900 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1901 | if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) || |
| 1902 | sta->auth_alg == WLAN_AUTH_FT) { |
| 1903 | /* |
| 1904 | * Open, static WEP, or FT protocol; no separate authorization |
| 1905 | * step. |
| 1906 | */ |
| 1907 | ap_sta_set_authorized(hapd, sta, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | if (reassoc) |
| 1911 | mlme_reassociate_indication(hapd, sta); |
| 1912 | else |
| 1913 | mlme_associate_indication(hapd, sta); |
| 1914 | |
| 1915 | #ifdef CONFIG_IEEE80211W |
| 1916 | sta->sa_query_timed_out = 0; |
| 1917 | #endif /* CONFIG_IEEE80211W */ |
| 1918 | |
| 1919 | /* |
| 1920 | * Remove the STA entry in order to make sure the STA PS state gets |
| 1921 | * cleared and configuration gets updated in case of reassociation back |
| 1922 | * to the same AP. |
| 1923 | */ |
| 1924 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 1925 | |
| 1926 | #ifdef CONFIG_IEEE80211N |
| 1927 | if (sta->flags & WLAN_STA_HT) |
| 1928 | hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap); |
| 1929 | #endif /* CONFIG_IEEE80211N */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1930 | #ifdef CONFIG_IEEE80211AC |
| 1931 | if (sta->flags & WLAN_STA_VHT) |
| 1932 | hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap); |
| 1933 | #endif /* CONFIG_IEEE80211AC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1934 | |
| 1935 | if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability, |
| 1936 | sta->supported_rates, sta->supported_rates_len, |
| 1937 | sta->listen_interval, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1938 | sta->flags & WLAN_STA_HT ? &ht_cap : NULL, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1939 | sta->flags & WLAN_STA_VHT ? &vht_cap : NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1940 | sta->flags, sta->qosinfo)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1941 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1942 | HOSTAPD_LEVEL_NOTICE, |
| 1943 | "Could not add STA to kernel driver"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1944 | |
| 1945 | ap_sta_disconnect(hapd, sta, sta->addr, |
| 1946 | WLAN_REASON_DISASSOC_AP_BUSY); |
| 1947 | |
| 1948 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1951 | if (sta->flags & WLAN_STA_WDS) { |
| 1952 | int ret; |
| 1953 | char ifname_wds[IFNAMSIZ + 1]; |
| 1954 | |
| 1955 | ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr, |
| 1956 | sta->aid, 1); |
| 1957 | if (!ret) |
| 1958 | hostapd_set_wds_encryption(hapd, sta, ifname_wds); |
| 1959 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1960 | |
| 1961 | if (sta->eapol_sm == NULL) { |
| 1962 | /* |
| 1963 | * This STA does not use RADIUS server for EAP authentication, |
| 1964 | * so bind it to the selected VLAN interface now, since the |
| 1965 | * interface selection is not going to change anymore. |
| 1966 | */ |
| 1967 | if (ap_sta_bind_vlan(hapd, sta, 0) < 0) |
| 1968 | goto fail; |
| 1969 | } else if (sta->vlan_id) { |
| 1970 | /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */ |
| 1971 | if (ap_sta_bind_vlan(hapd, sta, 0) < 0) |
| 1972 | goto fail; |
| 1973 | } |
| 1974 | |
| 1975 | hostapd_set_sta_flags(hapd, sta); |
| 1976 | |
| 1977 | if (sta->auth_alg == WLAN_AUTH_FT) |
| 1978 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); |
| 1979 | else |
| 1980 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); |
| 1981 | hapd->new_assoc_sta_cb(hapd, sta, !new_assoc); |
| 1982 | |
| 1983 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); |
| 1984 | |
| 1985 | fail: |
| 1986 | /* Copy of the association request is not needed anymore */ |
| 1987 | if (sta->last_assoc_req) { |
| 1988 | os_free(sta->last_assoc_req); |
| 1989 | sta->last_assoc_req = NULL; |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1994 | static void handle_deauth_cb(struct hostapd_data *hapd, |
| 1995 | const struct ieee80211_mgmt *mgmt, |
| 1996 | size_t len, int ok) |
| 1997 | { |
| 1998 | struct sta_info *sta; |
| 1999 | if (mgmt->da[0] & 0x01) |
| 2000 | return; |
| 2001 | sta = ap_get_sta(hapd, mgmt->da); |
| 2002 | if (!sta) { |
| 2003 | wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR |
| 2004 | " not found", MAC2STR(mgmt->da)); |
| 2005 | return; |
| 2006 | } |
| 2007 | if (ok) |
| 2008 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth", |
| 2009 | MAC2STR(sta->addr)); |
| 2010 | else |
| 2011 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " |
| 2012 | "deauth", MAC2STR(sta->addr)); |
| 2013 | |
| 2014 | ap_sta_deauth_cb(hapd, sta); |
| 2015 | } |
| 2016 | |
| 2017 | |
| 2018 | static void handle_disassoc_cb(struct hostapd_data *hapd, |
| 2019 | const struct ieee80211_mgmt *mgmt, |
| 2020 | size_t len, int ok) |
| 2021 | { |
| 2022 | struct sta_info *sta; |
| 2023 | if (mgmt->da[0] & 0x01) |
| 2024 | return; |
| 2025 | sta = ap_get_sta(hapd, mgmt->da); |
| 2026 | if (!sta) { |
| 2027 | wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR |
| 2028 | " not found", MAC2STR(mgmt->da)); |
| 2029 | return; |
| 2030 | } |
| 2031 | if (ok) |
| 2032 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc", |
| 2033 | MAC2STR(sta->addr)); |
| 2034 | else |
| 2035 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " |
| 2036 | "disassoc", MAC2STR(sta->addr)); |
| 2037 | |
| 2038 | ap_sta_disassoc_cb(hapd, sta); |
| 2039 | } |
| 2040 | |
| 2041 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2042 | /** |
| 2043 | * ieee802_11_mgmt_cb - Process management frame TX status callback |
| 2044 | * @hapd: hostapd BSS data structure (the BSS from which the management frame |
| 2045 | * was sent from) |
| 2046 | * @buf: management frame data (starting from IEEE 802.11 header) |
| 2047 | * @len: length of frame data in octets |
| 2048 | * @stype: management frame subtype from frame control field |
| 2049 | * @ok: Whether the frame was ACK'ed |
| 2050 | */ |
| 2051 | void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len, |
| 2052 | u16 stype, int ok) |
| 2053 | { |
| 2054 | const struct ieee80211_mgmt *mgmt; |
| 2055 | mgmt = (const struct ieee80211_mgmt *) buf; |
| 2056 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2057 | #ifdef CONFIG_TESTING_OPTIONS |
| 2058 | if (hapd->ext_mgmt_frame_handling) { |
| 2059 | wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d", |
| 2060 | stype, ok); |
| 2061 | return; |
| 2062 | } |
| 2063 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2064 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2065 | switch (stype) { |
| 2066 | case WLAN_FC_STYPE_AUTH: |
| 2067 | wpa_printf(MSG_DEBUG, "mgmt::auth cb"); |
| 2068 | handle_auth_cb(hapd, mgmt, len, ok); |
| 2069 | break; |
| 2070 | case WLAN_FC_STYPE_ASSOC_RESP: |
| 2071 | wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb"); |
| 2072 | handle_assoc_cb(hapd, mgmt, len, 0, ok); |
| 2073 | break; |
| 2074 | case WLAN_FC_STYPE_REASSOC_RESP: |
| 2075 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb"); |
| 2076 | handle_assoc_cb(hapd, mgmt, len, 1, ok); |
| 2077 | break; |
| 2078 | case WLAN_FC_STYPE_PROBE_RESP: |
| 2079 | wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb"); |
| 2080 | break; |
| 2081 | case WLAN_FC_STYPE_DEAUTH: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2082 | wpa_printf(MSG_DEBUG, "mgmt::deauth cb"); |
| 2083 | handle_deauth_cb(hapd, mgmt, len, ok); |
| 2084 | break; |
| 2085 | case WLAN_FC_STYPE_DISASSOC: |
| 2086 | wpa_printf(MSG_DEBUG, "mgmt::disassoc cb"); |
| 2087 | handle_disassoc_cb(hapd, mgmt, len, ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2088 | break; |
| 2089 | case WLAN_FC_STYPE_ACTION: |
| 2090 | wpa_printf(MSG_DEBUG, "mgmt::action cb"); |
| 2091 | break; |
| 2092 | default: |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2093 | wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2094 | break; |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | |
| 2099 | int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen) |
| 2100 | { |
| 2101 | /* TODO */ |
| 2102 | return 0; |
| 2103 | } |
| 2104 | |
| 2105 | |
| 2106 | int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta, |
| 2107 | char *buf, size_t buflen) |
| 2108 | { |
| 2109 | /* TODO */ |
| 2110 | return 0; |
| 2111 | } |
| 2112 | |
| 2113 | |
| 2114 | void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr, |
| 2115 | const u8 *buf, size_t len, int ack) |
| 2116 | { |
| 2117 | struct sta_info *sta; |
| 2118 | struct hostapd_iface *iface = hapd->iface; |
| 2119 | |
| 2120 | sta = ap_get_sta(hapd, addr); |
| 2121 | if (sta == NULL && iface->num_bss > 1) { |
| 2122 | size_t j; |
| 2123 | for (j = 0; j < iface->num_bss; j++) { |
| 2124 | hapd = iface->bss[j]; |
| 2125 | sta = ap_get_sta(hapd, addr); |
| 2126 | if (sta) |
| 2127 | break; |
| 2128 | } |
| 2129 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2130 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2131 | return; |
| 2132 | if (sta->flags & WLAN_STA_PENDING_POLL) { |
| 2133 | wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending " |
| 2134 | "activity poll", MAC2STR(sta->addr), |
| 2135 | ack ? "ACKed" : "did not ACK"); |
| 2136 | if (ack) |
| 2137 | sta->flags &= ~WLAN_STA_PENDING_POLL; |
| 2138 | } |
| 2139 | |
| 2140 | ieee802_1x_tx_status(hapd, sta, buf, len, ack); |
| 2141 | } |
| 2142 | |
| 2143 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2144 | void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst, |
| 2145 | const u8 *data, size_t len, int ack) |
| 2146 | { |
| 2147 | struct sta_info *sta; |
| 2148 | struct hostapd_iface *iface = hapd->iface; |
| 2149 | |
| 2150 | sta = ap_get_sta(hapd, dst); |
| 2151 | if (sta == NULL && iface->num_bss > 1) { |
| 2152 | size_t j; |
| 2153 | for (j = 0; j < iface->num_bss; j++) { |
| 2154 | hapd = iface->bss[j]; |
| 2155 | sta = ap_get_sta(hapd, dst); |
| 2156 | if (sta) |
| 2157 | break; |
| 2158 | } |
| 2159 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2160 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) { |
| 2161 | wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA " |
| 2162 | MACSTR " that is not currently associated", |
| 2163 | MAC2STR(dst)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2164 | return; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2165 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2166 | |
| 2167 | ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack); |
| 2168 | } |
| 2169 | |
| 2170 | |
| 2171 | void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr) |
| 2172 | { |
| 2173 | struct sta_info *sta; |
| 2174 | struct hostapd_iface *iface = hapd->iface; |
| 2175 | |
| 2176 | sta = ap_get_sta(hapd, addr); |
| 2177 | if (sta == NULL && iface->num_bss > 1) { |
| 2178 | size_t j; |
| 2179 | for (j = 0; j < iface->num_bss; j++) { |
| 2180 | hapd = iface->bss[j]; |
| 2181 | sta = ap_get_sta(hapd, addr); |
| 2182 | if (sta) |
| 2183 | break; |
| 2184 | } |
| 2185 | } |
| 2186 | if (sta == NULL) |
| 2187 | return; |
| 2188 | if (!(sta->flags & WLAN_STA_PENDING_POLL)) |
| 2189 | return; |
| 2190 | |
| 2191 | wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending " |
| 2192 | "activity poll", MAC2STR(sta->addr)); |
| 2193 | sta->flags &= ~WLAN_STA_PENDING_POLL; |
| 2194 | } |
| 2195 | |
| 2196 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2197 | void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src, |
| 2198 | int wds) |
| 2199 | { |
| 2200 | struct sta_info *sta; |
| 2201 | |
| 2202 | sta = ap_get_sta(hapd, src); |
| 2203 | if (sta && (sta->flags & WLAN_STA_ASSOC)) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2204 | if (!hapd->conf->wds_sta) |
| 2205 | return; |
| 2206 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2207 | if (wds && !(sta->flags & WLAN_STA_WDS)) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2208 | int ret; |
| 2209 | char ifname_wds[IFNAMSIZ + 1]; |
| 2210 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2211 | wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for " |
| 2212 | "STA " MACSTR " (aid %u)", |
| 2213 | MAC2STR(sta->addr), sta->aid); |
| 2214 | sta->flags |= WLAN_STA_WDS; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2215 | ret = hostapd_set_wds_sta(hapd, ifname_wds, |
| 2216 | sta->addr, sta->aid, 1); |
| 2217 | if (!ret) |
| 2218 | hostapd_set_wds_encryption(hapd, sta, |
| 2219 | ifname_wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2220 | } |
| 2221 | return; |
| 2222 | } |
| 2223 | |
| 2224 | wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA " |
| 2225 | MACSTR, MAC2STR(src)); |
| 2226 | if (src[0] & 0x01) { |
| 2227 | /* Broadcast bit set in SA?! Ignore the frame silently. */ |
| 2228 | return; |
| 2229 | } |
| 2230 | |
| 2231 | if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) { |
| 2232 | wpa_printf(MSG_DEBUG, "Association Response to the STA has " |
| 2233 | "already been sent, but no TX status yet known - " |
| 2234 | "ignore Class 3 frame issue with " MACSTR, |
| 2235 | MAC2STR(src)); |
| 2236 | return; |
| 2237 | } |
| 2238 | |
| 2239 | if (sta && (sta->flags & WLAN_STA_AUTH)) |
| 2240 | hostapd_drv_sta_disassoc( |
| 2241 | hapd, src, |
| 2242 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); |
| 2243 | else |
| 2244 | hostapd_drv_sta_deauth( |
| 2245 | hapd, src, |
| 2246 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); |
| 2247 | } |
| 2248 | |
| 2249 | |
| 2250 | #endif /* CONFIG_NATIVE_WINDOWS */ |