blob: 985f8b787b0cb9d55ab22512c689015b532e73fa [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.1X-2004 Authenticator
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "crypto/md5.h"
14#include "crypto/crypto.h"
15#include "crypto/random.h"
16#include "common/ieee802_11_defs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#include "radius/radius.h"
18#include "radius/radius_client.h"
19#include "eap_server/eap.h"
20#include "eap_common/eap_wsc_common.h"
21#include "eapol_auth/eapol_auth_sm.h"
22#include "eapol_auth/eapol_auth_sm_i.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080023#include "p2p/p2p.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070024#include "hostapd.h"
25#include "accounting.h"
26#include "sta_info.h"
27#include "wpa_auth.h"
28#include "preauth_auth.h"
29#include "pmksa_cache_auth.h"
30#include "ap_config.h"
31#include "ap_drv_ops.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080032#include "wps_hostapd.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080033#include "hs20.h"
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080034/* FIX: Not really a good thing to require ieee802_11.h here.. (FILS) */
35#include "ieee802_11.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "ieee802_1x.h"
37
38
Dmitry Shmidtde47be72016-01-07 12:52:55 -080039#ifdef CONFIG_HS20
40static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx);
41#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042static void ieee802_1x_finished(struct hostapd_data *hapd,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080043 struct sta_info *sta, int success,
44 int remediation);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045
46
47static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
48 u8 type, const u8 *data, size_t datalen)
49{
50 u8 *buf;
51 struct ieee802_1x_hdr *xhdr;
52 size_t len;
53 int encrypt = 0;
54
55 len = sizeof(*xhdr) + datalen;
56 buf = os_zalloc(len);
57 if (buf == NULL) {
58 wpa_printf(MSG_ERROR, "malloc() failed for "
59 "ieee802_1x_send(len=%lu)",
60 (unsigned long) len);
61 return;
62 }
63
64 xhdr = (struct ieee802_1x_hdr *) buf;
65 xhdr->version = hapd->conf->eapol_version;
66 xhdr->type = type;
67 xhdr->length = host_to_be16(datalen);
68
69 if (datalen > 0 && data != NULL)
70 os_memcpy(xhdr + 1, data, datalen);
71
72 if (wpa_auth_pairwise_set(sta->wpa_sm))
73 encrypt = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080074#ifdef CONFIG_TESTING_OPTIONS
75 if (hapd->ext_eapol_frame_io) {
76 size_t hex_len = 2 * len + 1;
77 char *hex = os_malloc(hex_len);
78
79 if (hex) {
80 wpa_snprintf_hex(hex, hex_len, buf, len);
81 wpa_msg(hapd->msg_ctx, MSG_INFO,
82 "EAPOL-TX " MACSTR " %s",
83 MAC2STR(sta->addr), hex);
84 os_free(hex);
85 }
86 } else
87#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070088 if (sta->flags & WLAN_STA_PREAUTH) {
89 rsn_preauth_send(hapd, sta, buf, len);
90 } else {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080091 hostapd_drv_hapd_send_eapol(
92 hapd, sta->addr, buf, len,
93 encrypt, hostapd_sta_flags_to_drv(sta->flags));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070094 }
95
96 os_free(buf);
97}
98
99
100void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
101 struct sta_info *sta, int authorized)
102{
103 int res;
104
105 if (sta->flags & WLAN_STA_PREAUTH)
106 return;
107
108 if (authorized) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 ap_sta_set_authorized(hapd, sta, 1);
110 res = hostapd_set_authorized(hapd, sta, 1);
111 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
112 HOSTAPD_LEVEL_DEBUG, "authorizing port");
113 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 ap_sta_set_authorized(hapd, sta, 0);
115 res = hostapd_set_authorized(hapd, sta, 0);
116 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
117 HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
118 }
119
120 if (res && errno != ENOENT) {
Dmitry Shmidt96571392013-10-14 12:54:46 -0700121 wpa_printf(MSG_DEBUG, "Could not set station " MACSTR
122 " flags for kernel driver (errno=%d).",
123 MAC2STR(sta->addr), errno);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700124 }
125
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800126 if (authorized) {
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800127 os_get_reltime(&sta->connected_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700128 accounting_sta_start(hapd, sta);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800129 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700130}
131
132
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800133#ifndef CONFIG_FIPS
134#ifndef CONFIG_NO_RC4
135
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700136static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
137 struct sta_info *sta,
138 int idx, int broadcast,
139 u8 *key_data, size_t key_len)
140{
141 u8 *buf, *ekey;
142 struct ieee802_1x_hdr *hdr;
143 struct ieee802_1x_eapol_key *key;
144 size_t len, ekey_len;
145 struct eapol_state_machine *sm = sta->eapol_sm;
146
147 if (sm == NULL)
148 return;
149
150 len = sizeof(*key) + key_len;
151 buf = os_zalloc(sizeof(*hdr) + len);
152 if (buf == NULL)
153 return;
154
155 hdr = (struct ieee802_1x_hdr *) buf;
156 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
157 key->type = EAPOL_KEY_TYPE_RC4;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700158 WPA_PUT_BE16(key->key_length, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 wpa_get_ntp_timestamp(key->replay_counter);
160
161 if (random_get_bytes(key->key_iv, sizeof(key->key_iv))) {
162 wpa_printf(MSG_ERROR, "Could not get random numbers");
163 os_free(buf);
164 return;
165 }
166
167 key->key_index = idx | (broadcast ? 0 : BIT(7));
168 if (hapd->conf->eapol_key_index_workaround) {
169 /* According to some information, WinXP Supplicant seems to
170 * interpret bit7 as an indication whether the key is to be
171 * activated, so make it possible to enable workaround that
172 * sets this bit for all keys. */
173 key->key_index |= BIT(7);
174 }
175
176 /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
177 * MSK[32..63] is used to sign the message. */
178 if (sm->eap_if->eapKeyData == NULL || sm->eap_if->eapKeyDataLen < 64) {
179 wpa_printf(MSG_ERROR, "No eapKeyData available for encrypting "
180 "and signing EAPOL-Key");
181 os_free(buf);
182 return;
183 }
184 os_memcpy((u8 *) (key + 1), key_data, key_len);
185 ekey_len = sizeof(key->key_iv) + 32;
186 ekey = os_malloc(ekey_len);
187 if (ekey == NULL) {
188 wpa_printf(MSG_ERROR, "Could not encrypt key");
189 os_free(buf);
190 return;
191 }
192 os_memcpy(ekey, key->key_iv, sizeof(key->key_iv));
193 os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32);
194 rc4_skip(ekey, ekey_len, 0, (u8 *) (key + 1), key_len);
195 os_free(ekey);
196
197 /* This header is needed here for HMAC-MD5, but it will be regenerated
198 * in ieee802_1x_send() */
199 hdr->version = hapd->conf->eapol_version;
200 hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
201 hdr->length = host_to_be16(len);
202 hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len,
203 key->key_signature);
204
205 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
206 " (%s index=%d)", MAC2STR(sm->addr),
207 broadcast ? "broadcast" : "unicast", idx);
208 ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len);
209 if (sta->eapol_sm)
210 sta->eapol_sm->dot1xAuthEapolFramesTx++;
211 os_free(buf);
212}
213
214
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800215static void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700216{
217 struct eapol_authenticator *eapol = hapd->eapol_auth;
218 struct eapol_state_machine *sm = sta->eapol_sm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219
220 if (sm == NULL || !sm->eap_if->eapKeyData)
221 return;
222
223 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
224 MAC2STR(sta->addr));
225
226#ifndef CONFIG_NO_VLAN
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800227 if (sta->vlan_id > 0) {
Dmitry Shmidt5393a0f2013-08-08 11:23:34 -0700228 wpa_printf(MSG_ERROR, "Using WEP with vlans is not supported.");
229 return;
230 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700231#endif /* CONFIG_NO_VLAN */
Dmitry Shmidt5393a0f2013-08-08 11:23:34 -0700232
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700233 if (eapol->default_wep_key) {
234 ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
235 eapol->default_wep_key,
236 hapd->conf->default_wep_key_len);
237 }
238
239 if (hapd->conf->individual_wep_key_len > 0) {
240 u8 *ikey;
241 ikey = os_malloc(hapd->conf->individual_wep_key_len);
242 if (ikey == NULL ||
243 random_get_bytes(ikey, hapd->conf->individual_wep_key_len))
244 {
245 wpa_printf(MSG_ERROR, "Could not generate random "
246 "individual WEP key.");
247 os_free(ikey);
248 return;
249 }
250
251 wpa_hexdump_key(MSG_DEBUG, "Individual WEP key",
252 ikey, hapd->conf->individual_wep_key_len);
253
254 ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey,
255 hapd->conf->individual_wep_key_len);
256
257 /* TODO: set encryption in TX callback, i.e., only after STA
258 * has ACKed EAPOL-Key frame */
259 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
260 sta->addr, 0, 1, NULL, 0, ikey,
261 hapd->conf->individual_wep_key_len)) {
262 wpa_printf(MSG_ERROR, "Could not set individual WEP "
263 "encryption.");
264 }
265
266 os_free(ikey);
267 }
268}
269
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800270#endif /* CONFIG_NO_RC4 */
271#endif /* CONFIG_FIPS */
272
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273
274const char *radius_mode_txt(struct hostapd_data *hapd)
275{
276 switch (hapd->iface->conf->hw_mode) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800277 case HOSTAPD_MODE_IEEE80211AD:
278 return "802.11ad";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700279 case HOSTAPD_MODE_IEEE80211A:
280 return "802.11a";
281 case HOSTAPD_MODE_IEEE80211G:
282 return "802.11g";
283 case HOSTAPD_MODE_IEEE80211B:
284 default:
285 return "802.11b";
286 }
287}
288
289
290int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
291{
292 int i;
293 u8 rate = 0;
294
295 for (i = 0; i < sta->supported_rates_len; i++)
296 if ((sta->supported_rates[i] & 0x7f) > rate)
297 rate = sta->supported_rates[i] & 0x7f;
298
299 return rate;
300}
301
302
303#ifndef CONFIG_NO_RADIUS
304static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
305 struct eapol_state_machine *sm,
306 const u8 *eap, size_t len)
307{
308 const u8 *identity;
309 size_t identity_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800310 const struct eap_hdr *hdr = (const struct eap_hdr *) eap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311
312 if (len <= sizeof(struct eap_hdr) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800313 (hdr->code == EAP_CODE_RESPONSE &&
314 eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY) ||
315 (hdr->code == EAP_CODE_INITIATE &&
316 eap[sizeof(struct eap_hdr)] != EAP_ERP_TYPE_REAUTH) ||
317 (hdr->code != EAP_CODE_RESPONSE &&
318 hdr->code != EAP_CODE_INITIATE))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 return;
320
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800321 eap_erp_update_identity(sm->eap, eap, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700322 identity = eap_get_identity(sm->eap, &identity_len);
323 if (identity == NULL)
324 return;
325
326 /* Save station identity for future RADIUS packets */
327 os_free(sm->identity);
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700328 sm->identity = (u8 *) dup_binstr(identity, identity_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 if (sm->identity == NULL) {
330 sm->identity_len = 0;
331 return;
332 }
333
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700334 sm->identity_len = identity_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
336 HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
337 sm->dot1xAuthEapolRespIdFramesRx++;
338}
339
340
Dmitry Shmidt03658832014-08-13 11:03:49 -0700341static int add_common_radius_sta_attr_rsn(struct hostapd_data *hapd,
342 struct hostapd_radius_attr *req_attr,
343 struct sta_info *sta,
344 struct radius_msg *msg)
345{
346 u32 suite;
347 int ver, val;
348
349 ver = wpa_auth_sta_wpa_version(sta->wpa_sm);
350 val = wpa_auth_get_pairwise(sta->wpa_sm);
351 suite = wpa_cipher_to_suite(ver, val);
352 if (val != -1 &&
353 !hostapd_config_get_radius_attr(req_attr,
354 RADIUS_ATTR_WLAN_PAIRWISE_CIPHER) &&
355 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_PAIRWISE_CIPHER,
356 suite)) {
357 wpa_printf(MSG_ERROR, "Could not add WLAN-Pairwise-Cipher");
358 return -1;
359 }
360
Dmitry Shmidt41712582015-06-29 11:02:15 -0700361 suite = wpa_cipher_to_suite(((hapd->conf->wpa & 0x2) ||
362 hapd->conf->osen) ?
Dmitry Shmidt03658832014-08-13 11:03:49 -0700363 WPA_PROTO_RSN : WPA_PROTO_WPA,
364 hapd->conf->wpa_group);
365 if (!hostapd_config_get_radius_attr(req_attr,
366 RADIUS_ATTR_WLAN_GROUP_CIPHER) &&
367 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_GROUP_CIPHER,
368 suite)) {
369 wpa_printf(MSG_ERROR, "Could not add WLAN-Group-Cipher");
370 return -1;
371 }
372
373 val = wpa_auth_sta_key_mgmt(sta->wpa_sm);
374 suite = wpa_akm_to_suite(val);
375 if (val != -1 &&
376 !hostapd_config_get_radius_attr(req_attr,
377 RADIUS_ATTR_WLAN_AKM_SUITE) &&
378 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_AKM_SUITE,
379 suite)) {
380 wpa_printf(MSG_ERROR, "Could not add WLAN-AKM-Suite");
381 return -1;
382 }
383
384#ifdef CONFIG_IEEE80211W
385 if (hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
386 suite = wpa_cipher_to_suite(WPA_PROTO_RSN,
387 hapd->conf->group_mgmt_cipher);
388 if (!hostapd_config_get_radius_attr(
389 req_attr, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER) &&
390 !radius_msg_add_attr_int32(
391 msg, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER, suite)) {
392 wpa_printf(MSG_ERROR,
393 "Could not add WLAN-Group-Mgmt-Cipher");
394 return -1;
395 }
396 }
397#endif /* CONFIG_IEEE80211W */
398
399 return 0;
400}
401
402
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700403static int add_common_radius_sta_attr(struct hostapd_data *hapd,
404 struct hostapd_radius_attr *req_attr,
405 struct sta_info *sta,
406 struct radius_msg *msg)
407{
408 char buf[128];
409
410 if (!hostapd_config_get_radius_attr(req_attr,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800411 RADIUS_ATTR_SERVICE_TYPE) &&
412 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_SERVICE_TYPE,
413 RADIUS_SERVICE_TYPE_FRAMED)) {
414 wpa_printf(MSG_ERROR, "Could not add Service-Type");
415 return -1;
416 }
417
418 if (!hostapd_config_get_radius_attr(req_attr,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700419 RADIUS_ATTR_NAS_PORT) &&
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700420 sta->aid > 0 &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700421 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) {
422 wpa_printf(MSG_ERROR, "Could not add NAS-Port");
423 return -1;
424 }
425
426 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
427 MAC2STR(sta->addr));
428 buf[sizeof(buf) - 1] = '\0';
429 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
430 (u8 *) buf, os_strlen(buf))) {
431 wpa_printf(MSG_ERROR, "Could not add Calling-Station-Id");
432 return -1;
433 }
434
435 if (sta->flags & WLAN_STA_PREAUTH) {
436 os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
437 sizeof(buf));
438 } else {
439 os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s",
440 radius_sta_rate(hapd, sta) / 2,
441 (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
442 radius_mode_txt(hapd));
443 buf[sizeof(buf) - 1] = '\0';
444 }
445 if (!hostapd_config_get_radius_attr(req_attr,
446 RADIUS_ATTR_CONNECT_INFO) &&
447 !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
448 (u8 *) buf, os_strlen(buf))) {
449 wpa_printf(MSG_ERROR, "Could not add Connect-Info");
450 return -1;
451 }
452
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800453 if (sta->acct_session_id) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800454 os_snprintf(buf, sizeof(buf), "%016llX",
455 (unsigned long long) sta->acct_session_id);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800456 if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
457 (u8 *) buf, os_strlen(buf))) {
458 wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
459 return -1;
460 }
461 }
462
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800463 if ((hapd->conf->wpa & 2) &&
464 !hapd->conf->disable_pmksa_caching &&
465 sta->eapol_sm && sta->eapol_sm->acct_multi_session_id) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800466 os_snprintf(buf, sizeof(buf), "%016llX",
467 (unsigned long long)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800468 sta->eapol_sm->acct_multi_session_id);
469 if (!radius_msg_add_attr(
470 msg, RADIUS_ATTR_ACCT_MULTI_SESSION_ID,
471 (u8 *) buf, os_strlen(buf))) {
472 wpa_printf(MSG_INFO,
473 "Could not add Acct-Multi-Session-Id");
474 return -1;
475 }
476 }
477
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800478#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt03658832014-08-13 11:03:49 -0700479 if (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
480 sta->wpa_sm &&
481 (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm)) ||
482 sta->auth_alg == WLAN_AUTH_FT) &&
483 !hostapd_config_get_radius_attr(req_attr,
484 RADIUS_ATTR_MOBILITY_DOMAIN_ID) &&
485 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_MOBILITY_DOMAIN_ID,
486 WPA_GET_BE16(
487 hapd->conf->mobility_domain))) {
488 wpa_printf(MSG_ERROR, "Could not add Mobility-Domain-Id");
489 return -1;
490 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800491#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt03658832014-08-13 11:03:49 -0700492
Dmitry Shmidt41712582015-06-29 11:02:15 -0700493 if ((hapd->conf->wpa || hapd->conf->osen) && sta->wpa_sm &&
Dmitry Shmidt03658832014-08-13 11:03:49 -0700494 add_common_radius_sta_attr_rsn(hapd, req_attr, sta, msg) < 0)
495 return -1;
496
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700497 return 0;
498}
499
500
501int add_common_radius_attr(struct hostapd_data *hapd,
502 struct hostapd_radius_attr *req_attr,
503 struct sta_info *sta,
504 struct radius_msg *msg)
505{
506 char buf[128];
507 struct hostapd_radius_attr *attr;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800508 int len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700509
510 if (!hostapd_config_get_radius_attr(req_attr,
511 RADIUS_ATTR_NAS_IP_ADDRESS) &&
512 hapd->conf->own_ip_addr.af == AF_INET &&
513 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
514 (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) {
515 wpa_printf(MSG_ERROR, "Could not add NAS-IP-Address");
516 return -1;
517 }
518
519#ifdef CONFIG_IPV6
520 if (!hostapd_config_get_radius_attr(req_attr,
521 RADIUS_ATTR_NAS_IPV6_ADDRESS) &&
522 hapd->conf->own_ip_addr.af == AF_INET6 &&
523 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS,
524 (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) {
525 wpa_printf(MSG_ERROR, "Could not add NAS-IPv6-Address");
526 return -1;
527 }
528#endif /* CONFIG_IPV6 */
529
530 if (!hostapd_config_get_radius_attr(req_attr,
531 RADIUS_ATTR_NAS_IDENTIFIER) &&
532 hapd->conf->nas_identifier &&
533 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER,
534 (u8 *) hapd->conf->nas_identifier,
535 os_strlen(hapd->conf->nas_identifier))) {
536 wpa_printf(MSG_ERROR, "Could not add NAS-Identifier");
537 return -1;
538 }
539
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800540 len = os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":",
541 MAC2STR(hapd->own_addr));
542 os_memcpy(&buf[len], hapd->conf->ssid.ssid,
543 hapd->conf->ssid.ssid_len);
544 len += hapd->conf->ssid.ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700545 if (!hostapd_config_get_radius_attr(req_attr,
546 RADIUS_ATTR_CALLED_STATION_ID) &&
547 !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800548 (u8 *) buf, len)) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700549 wpa_printf(MSG_ERROR, "Could not add Called-Station-Id");
550 return -1;
551 }
552
553 if (!hostapd_config_get_radius_attr(req_attr,
554 RADIUS_ATTR_NAS_PORT_TYPE) &&
555 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
556 RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
557 wpa_printf(MSG_ERROR, "Could not add NAS-Port-Type");
558 return -1;
559 }
560
Dmitry Shmidt03658832014-08-13 11:03:49 -0700561#ifdef CONFIG_INTERWORKING
562 if (hapd->conf->interworking &&
563 !is_zero_ether_addr(hapd->conf->hessid)) {
564 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
565 MAC2STR(hapd->conf->hessid));
566 buf[sizeof(buf) - 1] = '\0';
567 if (!hostapd_config_get_radius_attr(req_attr,
568 RADIUS_ATTR_WLAN_HESSID) &&
569 !radius_msg_add_attr(msg, RADIUS_ATTR_WLAN_HESSID,
570 (u8 *) buf, os_strlen(buf))) {
571 wpa_printf(MSG_ERROR, "Could not add WLAN-HESSID");
572 return -1;
573 }
574 }
575#endif /* CONFIG_INTERWORKING */
576
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700577 if (sta && add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0)
578 return -1;
579
580 for (attr = req_attr; attr; attr = attr->next) {
581 if (!radius_msg_add_attr(msg, attr->type,
582 wpabuf_head(attr->val),
583 wpabuf_len(attr->val))) {
584 wpa_printf(MSG_ERROR, "Could not add RADIUS "
585 "attribute");
586 return -1;
587 }
588 }
589
590 return 0;
591}
592
593
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800594void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
595 struct sta_info *sta,
596 const u8 *eap, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597{
598 struct radius_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700599 struct eapol_state_machine *sm = sta->eapol_sm;
600
601 if (sm == NULL)
602 return;
603
604 ieee802_1x_learn_identity(hapd, sm, eap, len);
605
606 wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
607 "packet");
608
609 sm->radius_identifier = radius_client_get_id(hapd->radius);
610 msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
611 sm->radius_identifier);
612 if (msg == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800613 wpa_printf(MSG_INFO, "Could not create new RADIUS packet");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614 return;
615 }
616
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800617 if (radius_msg_make_authenticator(msg) < 0) {
618 wpa_printf(MSG_INFO, "Could not make Request Authenticator");
619 goto fail;
620 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621
622 if (sm->identity &&
623 !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
624 sm->identity, sm->identity_len)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800625 wpa_printf(MSG_INFO, "Could not add User-Name");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700626 goto fail;
627 }
628
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700629 if (add_common_radius_attr(hapd, hapd->conf->radius_auth_req_attr, sta,
630 msg) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700632
633 /* TODO: should probably check MTU from driver config; 2304 is max for
634 * IEEE 802.11, but use 1400 to avoid problems with too large packets
635 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700636 if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
637 RADIUS_ATTR_FRAMED_MTU) &&
638 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800639 wpa_printf(MSG_INFO, "Could not add Framed-MTU");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700640 goto fail;
641 }
642
Dmitry Shmidt41712582015-06-29 11:02:15 -0700643 if (!radius_msg_add_eap(msg, eap, len)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800644 wpa_printf(MSG_INFO, "Could not add EAP-Message");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645 goto fail;
646 }
647
648 /* State attribute must be copied if and only if this packet is
649 * Access-Request reply to the previous Access-Challenge */
650 if (sm->last_recv_radius &&
651 radius_msg_get_hdr(sm->last_recv_radius)->code ==
652 RADIUS_CODE_ACCESS_CHALLENGE) {
653 int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
654 RADIUS_ATTR_STATE);
655 if (res < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800656 wpa_printf(MSG_INFO, "Could not copy State attribute from previous Access-Challenge");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700657 goto fail;
658 }
659 if (res > 0) {
660 wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute");
661 }
662 }
663
Dmitry Shmidt04949592012-07-19 12:16:46 -0700664 if (hapd->conf->radius_request_cui) {
665 const u8 *cui;
666 size_t cui_len;
667 /* Add previously learned CUI or nul CUI to request CUI */
668 if (sm->radius_cui) {
669 cui = wpabuf_head(sm->radius_cui);
670 cui_len = wpabuf_len(sm->radius_cui);
671 } else {
672 cui = (const u8 *) "\0";
673 cui_len = 1;
674 }
675 if (!radius_msg_add_attr(msg,
676 RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
677 cui, cui_len)) {
678 wpa_printf(MSG_ERROR, "Could not add CUI");
679 goto fail;
680 }
681 }
682
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800683#ifdef CONFIG_HS20
684 if (hapd->conf->hs20) {
685 u8 ver = 1; /* Release 2 */
686 if (!radius_msg_add_wfa(
687 msg, RADIUS_VENDOR_ATTR_WFA_HS20_AP_VERSION,
688 &ver, 1)) {
689 wpa_printf(MSG_ERROR, "Could not add HS 2.0 AP "
690 "version");
691 goto fail;
692 }
693
694 if (sta->hs20_ie && wpabuf_len(sta->hs20_ie) > 0) {
695 const u8 *pos;
696 u8 buf[3];
697 u16 id;
698 pos = wpabuf_head_u8(sta->hs20_ie);
699 buf[0] = (*pos) >> 4;
700 if (((*pos) & HS20_PPS_MO_ID_PRESENT) &&
701 wpabuf_len(sta->hs20_ie) >= 3)
702 id = WPA_GET_LE16(pos + 1);
703 else
704 id = 0;
705 WPA_PUT_BE16(buf + 1, id);
706 if (!radius_msg_add_wfa(
707 msg,
708 RADIUS_VENDOR_ATTR_WFA_HS20_STA_VERSION,
709 buf, sizeof(buf))) {
710 wpa_printf(MSG_ERROR, "Could not add HS 2.0 "
711 "STA version");
712 goto fail;
713 }
714 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700715
716 if (sta->roaming_consortium &&
717 !radius_msg_add_wfa(
718 msg, RADIUS_VENDOR_ATTR_WFA_HS20_ROAMING_CONSORTIUM,
719 wpabuf_head(sta->roaming_consortium),
720 wpabuf_len(sta->roaming_consortium))) {
721 wpa_printf(MSG_ERROR,
722 "Could not add HS 2.0 Roaming Consortium");
723 goto fail;
724 }
725
726 if (hapd->conf->t_c_filename) {
727 be32 timestamp;
728
729 if (!radius_msg_add_wfa(
730 msg,
731 RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILENAME,
732 (const u8 *) hapd->conf->t_c_filename,
733 os_strlen(hapd->conf->t_c_filename))) {
734 wpa_printf(MSG_ERROR,
735 "Could not add HS 2.0 T&C Filename");
736 goto fail;
737 }
738
739 timestamp = host_to_be32(hapd->conf->t_c_timestamp);
740 if (!radius_msg_add_wfa(
741 msg,
742 RADIUS_VENDOR_ATTR_WFA_HS20_TIMESTAMP,
743 (const u8 *) &timestamp,
744 sizeof(timestamp))) {
745 wpa_printf(MSG_ERROR,
746 "Could not add HS 2.0 Timestamp");
747 goto fail;
748 }
749 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800750 }
751#endif /* CONFIG_HS20 */
752
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700753 if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr) < 0)
754 goto fail;
755
756 return;
757
758 fail:
759 radius_msg_free(msg);
760}
761#endif /* CONFIG_NO_RADIUS */
762
763
764static void handle_eap_response(struct hostapd_data *hapd,
765 struct sta_info *sta, struct eap_hdr *eap,
766 size_t len)
767{
768 u8 type, *data;
769 struct eapol_state_machine *sm = sta->eapol_sm;
770 if (sm == NULL)
771 return;
772
773 data = (u8 *) (eap + 1);
774
775 if (len < sizeof(*eap) + 1) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800776 wpa_printf(MSG_INFO, "handle_eap_response: too short response data");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700777 return;
778 }
779
780 sm->eap_type_supp = type = data[0];
781
782 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
783 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
784 "id=%d len=%d) from STA: EAP Response-%s (%d)",
785 eap->code, eap->identifier, be_to_host16(eap->length),
786 eap_server_get_name(0, type), type);
787
788 sm->dot1xAuthEapolRespFramesRx++;
789
790 wpabuf_free(sm->eap_if->eapRespData);
791 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
792 sm->eapolEap = TRUE;
793}
794
795
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800796static void handle_eap_initiate(struct hostapd_data *hapd,
797 struct sta_info *sta, struct eap_hdr *eap,
798 size_t len)
799{
800#ifdef CONFIG_ERP
801 u8 type, *data;
802 struct eapol_state_machine *sm = sta->eapol_sm;
803
804 if (sm == NULL)
805 return;
806
807 if (len < sizeof(*eap) + 1) {
808 wpa_printf(MSG_INFO,
809 "handle_eap_initiate: too short response data");
810 return;
811 }
812
813 data = (u8 *) (eap + 1);
814 type = data[0];
815
816 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
817 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
818 "id=%d len=%d) from STA: EAP Initiate type %u",
819 eap->code, eap->identifier, be_to_host16(eap->length),
820 type);
821
822 wpabuf_free(sm->eap_if->eapRespData);
823 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
824 sm->eapolEap = TRUE;
825#endif /* CONFIG_ERP */
826}
827
828
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829/* Process incoming EAP packet from Supplicant */
830static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
831 u8 *buf, size_t len)
832{
833 struct eap_hdr *eap;
834 u16 eap_len;
835
836 if (len < sizeof(*eap)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800837 wpa_printf(MSG_INFO, " too short EAP packet");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 return;
839 }
840
841 eap = (struct eap_hdr *) buf;
842
843 eap_len = be_to_host16(eap->length);
844 wpa_printf(MSG_DEBUG, "EAP: code=%d identifier=%d length=%d",
845 eap->code, eap->identifier, eap_len);
846 if (eap_len < sizeof(*eap)) {
847 wpa_printf(MSG_DEBUG, " Invalid EAP length");
848 return;
849 } else if (eap_len > len) {
850 wpa_printf(MSG_DEBUG, " Too short frame to contain this EAP "
851 "packet");
852 return;
853 } else if (eap_len < len) {
854 wpa_printf(MSG_DEBUG, " Ignoring %lu extra bytes after EAP "
855 "packet", (unsigned long) len - eap_len);
856 }
857
858 switch (eap->code) {
859 case EAP_CODE_REQUEST:
860 wpa_printf(MSG_DEBUG, " (request)");
861 return;
862 case EAP_CODE_RESPONSE:
863 wpa_printf(MSG_DEBUG, " (response)");
864 handle_eap_response(hapd, sta, eap, eap_len);
865 break;
866 case EAP_CODE_SUCCESS:
867 wpa_printf(MSG_DEBUG, " (success)");
868 return;
869 case EAP_CODE_FAILURE:
870 wpa_printf(MSG_DEBUG, " (failure)");
871 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800872 case EAP_CODE_INITIATE:
873 wpa_printf(MSG_DEBUG, " (initiate)");
874 handle_eap_initiate(hapd, sta, eap, eap_len);
875 break;
876 case EAP_CODE_FINISH:
877 wpa_printf(MSG_DEBUG, " (finish)");
878 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879 default:
880 wpa_printf(MSG_DEBUG, " (unknown code)");
881 return;
882 }
883}
884
885
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800886struct eapol_state_machine *
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700887ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta)
888{
889 int flags = 0;
890 if (sta->flags & WLAN_STA_PREAUTH)
891 flags |= EAPOL_SM_PREAUTH;
892 if (sta->wpa_sm) {
893 flags |= EAPOL_SM_USES_WPA;
894 if (wpa_auth_sta_get_pmksa(sta->wpa_sm))
895 flags |= EAPOL_SM_FROM_PMKSA_CACHE;
896 }
897 return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700898 sta->wps_ie, sta->p2p_ie, sta,
899 sta->identity, sta->radius_cui);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900}
901
902
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800903static void ieee802_1x_save_eapol(struct sta_info *sta, const u8 *buf,
904 size_t len)
905{
906 if (sta->pending_eapol_rx) {
907 wpabuf_free(sta->pending_eapol_rx->buf);
908 } else {
909 sta->pending_eapol_rx =
910 os_malloc(sizeof(*sta->pending_eapol_rx));
911 if (!sta->pending_eapol_rx)
912 return;
913 }
914
915 sta->pending_eapol_rx->buf = wpabuf_alloc_copy(buf, len);
916 if (!sta->pending_eapol_rx->buf) {
917 os_free(sta->pending_eapol_rx);
918 sta->pending_eapol_rx = NULL;
919 return;
920 }
921
922 os_get_reltime(&sta->pending_eapol_rx->rx_time);
923}
924
925
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700926/**
927 * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
928 * @hapd: hostapd BSS data
929 * @sa: Source address (sender of the EAPOL frame)
930 * @buf: EAPOL frame
931 * @len: Length of buf in octets
932 *
933 * This function is called for each incoming EAPOL frame from the interface
934 */
935void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
936 size_t len)
937{
938 struct sta_info *sta;
939 struct ieee802_1x_hdr *hdr;
940 struct ieee802_1x_eapol_key *key;
941 u16 datalen;
942 struct rsn_pmksa_cache_entry *pmksa;
943 int key_mgmt;
944
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800945 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 !hapd->conf->wps_state)
947 return;
948
949 wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
950 (unsigned long) len, MAC2STR(sa));
951 sta = ap_get_sta(hapd, sa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800952 if (!sta || (!(sta->flags & (WLAN_STA_ASSOC | WLAN_STA_PREAUTH)) &&
953 !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700954 wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
955 "associated/Pre-authenticating STA");
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800956
957 if (sta && (sta->flags & WLAN_STA_AUTH)) {
958 wpa_printf(MSG_DEBUG, "Saving EAPOL frame from " MACSTR
959 " for later use", MAC2STR(sta->addr));
960 ieee802_1x_save_eapol(sta, buf, len);
961 }
962
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700963 return;
964 }
965
966 if (len < sizeof(*hdr)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800967 wpa_printf(MSG_INFO, " too short IEEE 802.1X packet");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700968 return;
969 }
970
971 hdr = (struct ieee802_1x_hdr *) buf;
972 datalen = be_to_host16(hdr->length);
973 wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d",
974 hdr->version, hdr->type, datalen);
975
976 if (len - sizeof(*hdr) < datalen) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800977 wpa_printf(MSG_INFO, " frame too short for this IEEE 802.1X packet");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700978 if (sta->eapol_sm)
979 sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++;
980 return;
981 }
982 if (len - sizeof(*hdr) > datalen) {
983 wpa_printf(MSG_DEBUG, " ignoring %lu extra octets after "
984 "IEEE 802.1X packet",
985 (unsigned long) len - sizeof(*hdr) - datalen);
986 }
987
988 if (sta->eapol_sm) {
989 sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version;
990 sta->eapol_sm->dot1xAuthEapolFramesRx++;
991 }
992
993 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
994 if (datalen >= sizeof(struct ieee802_1x_eapol_key) &&
995 hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
996 (key->type == EAPOL_KEY_TYPE_WPA ||
997 key->type == EAPOL_KEY_TYPE_RSN)) {
998 wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr,
999 sizeof(*hdr) + datalen);
1000 return;
1001 }
1002
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001003 if (!hapd->conf->ieee802_1x && !hapd->conf->osen &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
1005 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
1006 "802.1X not enabled and WPS not used");
1007 return;
1008 }
1009
1010 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001011 if (key_mgmt != -1 &&
1012 (wpa_key_mgmt_wpa_psk(key_mgmt) || key_mgmt == WPA_KEY_MGMT_OWE ||
1013 key_mgmt == WPA_KEY_MGMT_DPP)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
1015 "STA is using PSK");
1016 return;
1017 }
1018
1019 if (!sta->eapol_sm) {
1020 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
1021 if (!sta->eapol_sm)
1022 return;
1023
1024#ifdef CONFIG_WPS
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001025 if (!hapd->conf->ieee802_1x && hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001026 u32 wflags = sta->flags & (WLAN_STA_WPS |
1027 WLAN_STA_WPS2 |
1028 WLAN_STA_MAYBE_WPS);
1029 if (wflags == WLAN_STA_MAYBE_WPS ||
1030 wflags == (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) {
1031 /*
1032 * Delay EAPOL frame transmission until a
1033 * possible WPS STA initiates the handshake
1034 * with EAPOL-Start. Only allow the wait to be
1035 * skipped if the STA is known to support WPS
1036 * 2.0.
1037 */
1038 wpa_printf(MSG_DEBUG, "WPS: Do not start "
1039 "EAPOL until EAPOL-Start is "
1040 "received");
1041 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
1042 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001043 }
1044#endif /* CONFIG_WPS */
1045
1046 sta->eapol_sm->eap_if->portEnabled = TRUE;
1047 }
1048
1049 /* since we support version 1, we can ignore version field and proceed
1050 * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
1051 /* TODO: actually, we are not version 1 anymore.. However, Version 2
1052 * does not change frame contents, so should be ok to process frames
1053 * more or less identically. Some changes might be needed for
1054 * verification of fields. */
1055
1056 switch (hdr->type) {
1057 case IEEE802_1X_TYPE_EAP_PACKET:
1058 handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen);
1059 break;
1060
1061 case IEEE802_1X_TYPE_EAPOL_START:
1062 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1063 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Start "
1064 "from STA");
1065 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
1066 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1067 if (pmksa) {
1068 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
1069 HOSTAPD_LEVEL_DEBUG, "cached PMKSA "
1070 "available - ignore it since "
1071 "STA sent EAPOL-Start");
1072 wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa);
1073 }
1074 sta->eapol_sm->eapolStart = TRUE;
1075 sta->eapol_sm->dot1xAuthEapolStartFramesRx++;
1076 eap_server_clear_identity(sta->eapol_sm->eap);
1077 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
1078 break;
1079
1080 case IEEE802_1X_TYPE_EAPOL_LOGOFF:
1081 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1082 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Logoff "
1083 "from STA");
1084 sta->acct_terminate_cause =
1085 RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1086 accounting_sta_stop(hapd, sta);
1087 sta->eapol_sm->eapolLogoff = TRUE;
1088 sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
1089 eap_server_clear_identity(sta->eapol_sm->eap);
1090 break;
1091
1092 case IEEE802_1X_TYPE_EAPOL_KEY:
1093 wpa_printf(MSG_DEBUG, " EAPOL-Key");
1094 if (!ap_sta_is_authorized(sta)) {
1095 wpa_printf(MSG_DEBUG, " Dropped key data from "
1096 "unauthorized Supplicant");
1097 break;
1098 }
1099 break;
1100
1101 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
1102 wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert");
1103 /* TODO: implement support for this; show data */
1104 break;
1105
1106 default:
1107 wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type");
1108 sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++;
1109 break;
1110 }
1111
1112 eapol_auth_step(sta->eapol_sm);
1113}
1114
1115
1116/**
1117 * ieee802_1x_new_station - Start IEEE 802.1X authentication
1118 * @hapd: hostapd BSS data
1119 * @sta: The station
1120 *
1121 * This function is called to start IEEE 802.1X authentication when a new
1122 * station completes IEEE 802.11 association.
1123 */
1124void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
1125{
1126 struct rsn_pmksa_cache_entry *pmksa;
1127 int reassoc = 1;
1128 int force_1x = 0;
1129 int key_mgmt;
1130
1131#ifdef CONFIG_WPS
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001132 if (hapd->conf->wps_state &&
1133 ((hapd->conf->wpa && (sta->flags & WLAN_STA_MAYBE_WPS)) ||
1134 (sta->flags & WLAN_STA_WPS))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135 /*
1136 * Need to enable IEEE 802.1X/EAPOL state machines for possible
1137 * WPS handshake even if IEEE 802.1X/EAPOL is not used for
1138 * authentication in this BSS.
1139 */
1140 force_1x = 1;
1141 }
1142#endif /* CONFIG_WPS */
1143
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001144 if (!force_1x && !hapd->conf->ieee802_1x && !hapd->conf->osen) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - "
1146 "802.1X not enabled or forced for WPS");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001147 /*
1148 * Clear any possible EAPOL authenticator state to support
1149 * reassociation change from WPS to PSK.
1150 */
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001151 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 return;
1153 }
1154
1155 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001156 if (key_mgmt != -1 &&
1157 (wpa_key_mgmt_wpa_psk(key_mgmt) || key_mgmt == WPA_KEY_MGMT_OWE ||
1158 key_mgmt == WPA_KEY_MGMT_DPP)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001159 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - using PSK");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001160 /*
1161 * Clear any possible EAPOL authenticator state to support
1162 * reassociation change from WPA-EAP to PSK.
1163 */
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001164 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001165 return;
1166 }
1167
1168 if (sta->eapol_sm == NULL) {
1169 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1170 HOSTAPD_LEVEL_DEBUG, "start authentication");
1171 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
1172 if (sta->eapol_sm == NULL) {
1173 hostapd_logger(hapd, sta->addr,
1174 HOSTAPD_MODULE_IEEE8021X,
1175 HOSTAPD_LEVEL_INFO,
1176 "failed to allocate state machine");
1177 return;
1178 }
1179 reassoc = 0;
1180 }
1181
1182#ifdef CONFIG_WPS
1183 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001184 if (!hapd->conf->ieee802_1x && hapd->conf->wps_state &&
1185 !(sta->flags & WLAN_STA_WPS2)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001186 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001187 * Delay EAPOL frame transmission until a possible WPS STA
1188 * initiates the handshake with EAPOL-Start. Only allow the
1189 * wait to be skipped if the STA is known to support WPS 2.0.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001190 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001191 wpa_printf(MSG_DEBUG, "WPS: Do not start EAPOL until "
1192 "EAPOL-Start is received");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001193 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
1194 }
1195#endif /* CONFIG_WPS */
1196
1197 sta->eapol_sm->eap_if->portEnabled = TRUE;
1198
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001199#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001200 if (sta->auth_alg == WLAN_AUTH_FT) {
1201 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1202 HOSTAPD_LEVEL_DEBUG,
1203 "PMK from FT - skip IEEE 802.1X/EAP");
1204 /* Setup EAPOL state machines to already authenticated state
1205 * because of existing FT information from R0KH. */
1206 sta->eapol_sm->keyRun = TRUE;
1207 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1208 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1209 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1210 sta->eapol_sm->authSuccess = TRUE;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001211 sta->eapol_sm->authFail = FALSE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001212 sta->eapol_sm->portValid = TRUE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001213 if (sta->eapol_sm->eap)
1214 eap_sm_notify_cached(sta->eapol_sm->eap);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001215 ap_sta_bind_vlan(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 return;
1217 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001218#endif /* CONFIG_IEEE80211R_AP */
1219
1220#ifdef CONFIG_FILS
1221 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
1222 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
1223 sta->auth_alg == WLAN_AUTH_FILS_PK) {
1224 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1225 HOSTAPD_LEVEL_DEBUG,
1226 "PMK from FILS - skip IEEE 802.1X/EAP");
1227 /* Setup EAPOL state machines to already authenticated state
1228 * because of existing FILS information. */
1229 sta->eapol_sm->keyRun = TRUE;
1230 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1231 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1232 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1233 sta->eapol_sm->authSuccess = TRUE;
1234 sta->eapol_sm->authFail = FALSE;
1235 sta->eapol_sm->portValid = TRUE;
1236 if (sta->eapol_sm->eap)
1237 eap_sm_notify_cached(sta->eapol_sm->eap);
1238 return;
1239 }
1240#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001241
1242 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1243 if (pmksa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1245 HOSTAPD_LEVEL_DEBUG,
1246 "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
1247 /* Setup EAPOL state machines to already authenticated state
1248 * because of existing PMKSA information in the cache. */
1249 sta->eapol_sm->keyRun = TRUE;
1250 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1251 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1252 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1253 sta->eapol_sm->authSuccess = TRUE;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001254 sta->eapol_sm->authFail = FALSE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255 if (sta->eapol_sm->eap)
1256 eap_sm_notify_cached(sta->eapol_sm->eap);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001257 pmksa_cache_to_eapol_data(hapd, pmksa, sta->eapol_sm);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001258 ap_sta_bind_vlan(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259 } else {
1260 if (reassoc) {
1261 /*
1262 * Force EAPOL state machines to start
1263 * re-authentication without having to wait for the
1264 * Supplicant to send EAPOL-Start.
1265 */
1266 sta->eapol_sm->reAuthenticate = TRUE;
1267 }
1268 eapol_auth_step(sta->eapol_sm);
1269 }
1270}
1271
1272
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001273void ieee802_1x_free_station(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001274{
1275 struct eapol_state_machine *sm = sta->eapol_sm;
1276
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001277#ifdef CONFIG_HS20
1278 eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta);
1279#endif /* CONFIG_HS20 */
1280
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08001281 if (sta->pending_eapol_rx) {
1282 wpabuf_free(sta->pending_eapol_rx->buf);
1283 os_free(sta->pending_eapol_rx);
1284 sta->pending_eapol_rx = NULL;
1285 }
1286
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001287 if (sm == NULL)
1288 return;
1289
1290 sta->eapol_sm = NULL;
1291
1292#ifndef CONFIG_NO_RADIUS
1293 radius_msg_free(sm->last_recv_radius);
1294 radius_free_class(&sm->radius_class);
1295#endif /* CONFIG_NO_RADIUS */
1296
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001297 eapol_auth_free(sm);
1298}
1299
1300
1301#ifndef CONFIG_NO_RADIUS
1302static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
1303 struct sta_info *sta)
1304{
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001305 struct wpabuf *eap;
1306 const struct eap_hdr *hdr;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001307 int eap_type = -1;
1308 char buf[64];
1309 struct radius_msg *msg;
1310 struct eapol_state_machine *sm = sta->eapol_sm;
1311
1312 if (sm == NULL || sm->last_recv_radius == NULL) {
1313 if (sm)
1314 sm->eap_if->aaaEapNoReq = TRUE;
1315 return;
1316 }
1317
1318 msg = sm->last_recv_radius;
1319
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001320 eap = radius_msg_get_eap(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001321 if (eap == NULL) {
1322 /* RFC 3579, Chap. 2.6.3:
1323 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
1324 * attribute */
1325 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1326 HOSTAPD_LEVEL_WARNING, "could not extract "
1327 "EAP-Message from RADIUS message");
1328 sm->eap_if->aaaEapNoReq = TRUE;
1329 return;
1330 }
1331
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001332 if (wpabuf_len(eap) < sizeof(*hdr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001333 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1334 HOSTAPD_LEVEL_WARNING, "too short EAP packet "
1335 "received from authentication server");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001336 wpabuf_free(eap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337 sm->eap_if->aaaEapNoReq = TRUE;
1338 return;
1339 }
1340
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001341 if (wpabuf_len(eap) > sizeof(*hdr))
1342 eap_type = (wpabuf_head_u8(eap))[sizeof(*hdr)];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001343
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001344 hdr = wpabuf_head(eap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 switch (hdr->code) {
1346 case EAP_CODE_REQUEST:
1347 if (eap_type >= 0)
1348 sm->eap_type_authsrv = eap_type;
1349 os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001350 eap_server_get_name(0, eap_type), eap_type);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001351 break;
1352 case EAP_CODE_RESPONSE:
1353 os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001354 eap_server_get_name(0, eap_type), eap_type);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001355 break;
1356 case EAP_CODE_SUCCESS:
1357 os_strlcpy(buf, "EAP Success", sizeof(buf));
1358 break;
1359 case EAP_CODE_FAILURE:
1360 os_strlcpy(buf, "EAP Failure", sizeof(buf));
1361 break;
1362 default:
1363 os_strlcpy(buf, "unknown EAP code", sizeof(buf));
1364 break;
1365 }
1366 buf[sizeof(buf) - 1] = '\0';
1367 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1368 HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
1369 "id=%d len=%d) from RADIUS server: %s",
1370 hdr->code, hdr->identifier, be_to_host16(hdr->length),
1371 buf);
1372 sm->eap_if->aaaEapReq = TRUE;
1373
1374 wpabuf_free(sm->eap_if->aaaEapReqData);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001375 sm->eap_if->aaaEapReqData = eap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001376}
1377
1378
1379static void ieee802_1x_get_keys(struct hostapd_data *hapd,
1380 struct sta_info *sta, struct radius_msg *msg,
1381 struct radius_msg *req,
1382 const u8 *shared_secret,
1383 size_t shared_secret_len)
1384{
1385 struct radius_ms_mppe_keys *keys;
1386 struct eapol_state_machine *sm = sta->eapol_sm;
1387 if (sm == NULL)
1388 return;
1389
1390 keys = radius_msg_get_ms_keys(msg, req, shared_secret,
1391 shared_secret_len);
1392
1393 if (keys && keys->send && keys->recv) {
1394 size_t len = keys->send_len + keys->recv_len;
1395 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
1396 keys->send, keys->send_len);
1397 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
1398 keys->recv, keys->recv_len);
1399
1400 os_free(sm->eap_if->aaaEapKeyData);
1401 sm->eap_if->aaaEapKeyData = os_malloc(len);
1402 if (sm->eap_if->aaaEapKeyData) {
1403 os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv,
1404 keys->recv_len);
1405 os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len,
1406 keys->send, keys->send_len);
1407 sm->eap_if->aaaEapKeyDataLen = len;
1408 sm->eap_if->aaaEapKeyAvailable = TRUE;
1409 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001410 } else {
1411 wpa_printf(MSG_DEBUG,
1412 "MS-MPPE: 1x_get_keys, could not get keys: %p send: %p recv: %p",
1413 keys, keys ? keys->send : NULL,
1414 keys ? keys->recv : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001415 }
1416
1417 if (keys) {
1418 os_free(keys->send);
1419 os_free(keys->recv);
1420 os_free(keys);
1421 }
1422}
1423
1424
1425static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
1426 struct sta_info *sta,
1427 struct radius_msg *msg)
1428{
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001429 u8 *attr_class;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001430 size_t class_len;
1431 struct eapol_state_machine *sm = sta->eapol_sm;
1432 int count, i;
1433 struct radius_attr_data *nclass;
1434 size_t nclass_count;
1435
1436 if (!hapd->conf->radius->acct_server || hapd->radius == NULL ||
1437 sm == NULL)
1438 return;
1439
1440 radius_free_class(&sm->radius_class);
1441 count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
1442 if (count <= 0)
1443 return;
1444
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001445 nclass = os_calloc(count, sizeof(struct radius_attr_data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001446 if (nclass == NULL)
1447 return;
1448
1449 nclass_count = 0;
1450
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001451 attr_class = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001452 for (i = 0; i < count; i++) {
1453 do {
1454 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001455 &attr_class, &class_len,
1456 attr_class) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457 i = count;
1458 break;
1459 }
1460 } while (class_len < 1);
1461
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001462 nclass[nclass_count].data = os_memdup(attr_class, class_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001463 if (nclass[nclass_count].data == NULL)
1464 break;
1465
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001466 nclass[nclass_count].len = class_len;
1467 nclass_count++;
1468 }
1469
1470 sm->radius_class.attr = nclass;
1471 sm->radius_class.count = nclass_count;
1472 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Stored %lu RADIUS Class "
1473 "attributes for " MACSTR,
1474 (unsigned long) sm->radius_class.count,
1475 MAC2STR(sta->addr));
1476}
1477
1478
1479/* Update sta->identity based on User-Name attribute in Access-Accept */
1480static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
1481 struct sta_info *sta,
1482 struct radius_msg *msg)
1483{
1484 u8 *buf, *identity;
1485 size_t len;
1486 struct eapol_state_machine *sm = sta->eapol_sm;
1487
1488 if (sm == NULL)
1489 return;
1490
1491 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len,
1492 NULL) < 0)
1493 return;
1494
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001495 identity = (u8 *) dup_binstr(buf, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001496 if (identity == NULL)
1497 return;
1498
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001499 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1500 HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
1501 "User-Name from Access-Accept '%s'",
1502 sm->identity ? (char *) sm->identity : "N/A",
1503 (char *) identity);
1504
1505 os_free(sm->identity);
1506 sm->identity = identity;
1507 sm->identity_len = len;
1508}
1509
1510
Dmitry Shmidt04949592012-07-19 12:16:46 -07001511/* Update CUI based on Chargeable-User-Identity attribute in Access-Accept */
1512static void ieee802_1x_update_sta_cui(struct hostapd_data *hapd,
1513 struct sta_info *sta,
1514 struct radius_msg *msg)
1515{
1516 struct eapol_state_machine *sm = sta->eapol_sm;
1517 struct wpabuf *cui;
1518 u8 *buf;
1519 size_t len;
1520
1521 if (sm == NULL)
1522 return;
1523
1524 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
1525 &buf, &len, NULL) < 0)
1526 return;
1527
1528 cui = wpabuf_alloc_copy(buf, len);
1529 if (cui == NULL)
1530 return;
1531
1532 wpabuf_free(sm->radius_cui);
1533 sm->radius_cui = cui;
1534}
1535
1536
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001537#ifdef CONFIG_HS20
1538
1539static void ieee802_1x_hs20_sub_rem(struct sta_info *sta, u8 *pos, size_t len)
1540{
1541 sta->remediation = 1;
1542 os_free(sta->remediation_url);
1543 if (len > 2) {
1544 sta->remediation_url = os_malloc(len);
1545 if (!sta->remediation_url)
1546 return;
1547 sta->remediation_method = pos[0];
1548 os_memcpy(sta->remediation_url, pos + 1, len - 1);
1549 sta->remediation_url[len - 1] = '\0';
1550 wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
1551 "for " MACSTR " - server method %u URL %s",
1552 MAC2STR(sta->addr), sta->remediation_method,
1553 sta->remediation_url);
1554 } else {
1555 sta->remediation_url = NULL;
1556 wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
1557 "for " MACSTR, MAC2STR(sta->addr));
1558 }
1559 /* TODO: assign the STA into remediation VLAN or add filtering */
1560}
1561
1562
1563static void ieee802_1x_hs20_deauth_req(struct hostapd_data *hapd,
1564 struct sta_info *sta, u8 *pos,
1565 size_t len)
1566{
1567 if (len < 3)
1568 return; /* Malformed information */
1569 sta->hs20_deauth_requested = 1;
1570 wpa_printf(MSG_DEBUG, "HS 2.0: Deauthentication request - Code %u "
1571 "Re-auth Delay %u",
1572 *pos, WPA_GET_LE16(pos + 1));
1573 wpabuf_free(sta->hs20_deauth_req);
1574 sta->hs20_deauth_req = wpabuf_alloc(len + 1);
1575 if (sta->hs20_deauth_req) {
1576 wpabuf_put_data(sta->hs20_deauth_req, pos, 3);
1577 wpabuf_put_u8(sta->hs20_deauth_req, len - 3);
1578 wpabuf_put_data(sta->hs20_deauth_req, pos + 3, len - 3);
1579 }
1580 ap_sta_session_timeout(hapd, sta, hapd->conf->hs20_deauth_req_timeout);
1581}
1582
1583
1584static void ieee802_1x_hs20_session_info(struct hostapd_data *hapd,
1585 struct sta_info *sta, u8 *pos,
1586 size_t len, int session_timeout)
1587{
1588 unsigned int swt;
1589 int warning_time, beacon_int;
1590
1591 if (len < 1)
1592 return; /* Malformed information */
1593 os_free(sta->hs20_session_info_url);
1594 sta->hs20_session_info_url = os_malloc(len);
1595 if (sta->hs20_session_info_url == NULL)
1596 return;
1597 swt = pos[0];
1598 os_memcpy(sta->hs20_session_info_url, pos + 1, len - 1);
1599 sta->hs20_session_info_url[len - 1] = '\0';
1600 wpa_printf(MSG_DEBUG, "HS 2.0: Session Information URL='%s' SWT=%u "
1601 "(session_timeout=%d)",
1602 sta->hs20_session_info_url, swt, session_timeout);
1603 if (session_timeout < 0) {
1604 wpa_printf(MSG_DEBUG, "HS 2.0: No Session-Timeout set - ignore session info URL");
1605 return;
1606 }
1607 if (swt == 255)
1608 swt = 1; /* Use one minute as the AP selected value */
1609
1610 if ((unsigned int) session_timeout < swt * 60)
1611 warning_time = 0;
1612 else
1613 warning_time = session_timeout - swt * 60;
1614
1615 beacon_int = hapd->iconf->beacon_int;
1616 if (beacon_int < 1)
1617 beacon_int = 100; /* best guess */
1618 sta->hs20_disassoc_timer = swt * 60 * 1000 / beacon_int * 125 / 128;
1619 if (sta->hs20_disassoc_timer > 65535)
1620 sta->hs20_disassoc_timer = 65535;
1621
1622 ap_sta_session_warning_timeout(hapd, sta, warning_time);
1623}
1624
Roshan Pius3a1667e2018-07-03 15:17:14 -07001625
1626static void ieee802_1x_hs20_t_c_filtering(struct hostapd_data *hapd,
1627 struct sta_info *sta, u8 *pos,
1628 size_t len)
1629{
1630 if (len < 4)
1631 return; /* Malformed information */
1632 wpa_printf(MSG_DEBUG,
1633 "HS 2.0: Terms and Conditions filtering %02x %02x %02x %02x",
1634 pos[0], pos[1], pos[2], pos[3]);
1635 hs20_t_c_filtering(hapd, sta, pos[0] & BIT(0));
1636}
1637
1638
1639static void ieee802_1x_hs20_t_c_url(struct hostapd_data *hapd,
1640 struct sta_info *sta, u8 *pos, size_t len)
1641{
1642 os_free(sta->t_c_url);
1643 sta->t_c_url = os_malloc(len + 1);
1644 if (!sta->t_c_url)
1645 return;
1646 os_memcpy(sta->t_c_url, pos, len);
1647 sta->t_c_url[len] = '\0';
1648 wpa_printf(MSG_DEBUG,
1649 "HS 2.0: Terms and Conditions URL %s", sta->t_c_url);
1650}
1651
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001652#endif /* CONFIG_HS20 */
1653
1654
1655static void ieee802_1x_check_hs20(struct hostapd_data *hapd,
1656 struct sta_info *sta,
1657 struct radius_msg *msg,
1658 int session_timeout)
1659{
1660#ifdef CONFIG_HS20
1661 u8 *buf, *pos, *end, type, sublen;
1662 size_t len;
1663
1664 buf = NULL;
1665 sta->remediation = 0;
1666 sta->hs20_deauth_requested = 0;
1667
1668 for (;;) {
1669 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_VENDOR_SPECIFIC,
1670 &buf, &len, buf) < 0)
1671 break;
1672 if (len < 6)
1673 continue;
1674 pos = buf;
1675 end = buf + len;
1676 if (WPA_GET_BE32(pos) != RADIUS_VENDOR_ID_WFA)
1677 continue;
1678 pos += 4;
1679
1680 type = *pos++;
1681 sublen = *pos++;
1682 if (sublen < 2)
1683 continue; /* invalid length */
1684 sublen -= 2; /* skip header */
1685 if (pos + sublen > end)
1686 continue; /* invalid WFA VSA */
1687
1688 switch (type) {
1689 case RADIUS_VENDOR_ATTR_WFA_HS20_SUBSCR_REMEDIATION:
1690 ieee802_1x_hs20_sub_rem(sta, pos, sublen);
1691 break;
1692 case RADIUS_VENDOR_ATTR_WFA_HS20_DEAUTH_REQ:
1693 ieee802_1x_hs20_deauth_req(hapd, sta, pos, sublen);
1694 break;
1695 case RADIUS_VENDOR_ATTR_WFA_HS20_SESSION_INFO_URL:
1696 ieee802_1x_hs20_session_info(hapd, sta, pos, sublen,
1697 session_timeout);
1698 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001699 case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILTERING:
1700 ieee802_1x_hs20_t_c_filtering(hapd, sta, pos, sublen);
1701 break;
1702 case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_URL:
1703 ieee802_1x_hs20_t_c_url(hapd, sta, pos, sublen);
1704 break;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001705 }
1706 }
1707#endif /* CONFIG_HS20 */
1708}
1709
1710
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001711struct sta_id_search {
1712 u8 identifier;
1713 struct eapol_state_machine *sm;
1714};
1715
1716
1717static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd,
1718 struct sta_info *sta,
1719 void *ctx)
1720{
1721 struct sta_id_search *id_search = ctx;
1722 struct eapol_state_machine *sm = sta->eapol_sm;
1723
1724 if (sm && sm->radius_identifier >= 0 &&
1725 sm->radius_identifier == id_search->identifier) {
1726 id_search->sm = sm;
1727 return 1;
1728 }
1729 return 0;
1730}
1731
1732
1733static struct eapol_state_machine *
1734ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
1735{
1736 struct sta_id_search id_search;
1737 id_search.identifier = identifier;
1738 id_search.sm = NULL;
1739 ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search);
1740 return id_search.sm;
1741}
1742
1743
1744/**
1745 * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
1746 * @msg: RADIUS response message
1747 * @req: RADIUS request message
1748 * @shared_secret: RADIUS shared secret
1749 * @shared_secret_len: Length of shared_secret in octets
1750 * @data: Context data (struct hostapd_data *)
1751 * Returns: Processing status
1752 */
1753static RadiusRxResult
1754ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
1755 const u8 *shared_secret, size_t shared_secret_len,
1756 void *data)
1757{
1758 struct hostapd_data *hapd = data;
1759 struct sta_info *sta;
1760 u32 session_timeout = 0, termination_action, acct_interim_interval;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001761 int session_timeout_set;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001762 u32 reason_code;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763 struct eapol_state_machine *sm;
1764 int override_eapReq = 0;
1765 struct radius_hdr *hdr = radius_msg_get_hdr(msg);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001766 struct vlan_description vlan_desc;
1767#ifndef CONFIG_NO_VLAN
1768 int *untagged, *tagged, *notempty;
1769#endif /* CONFIG_NO_VLAN */
1770
1771 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001772
1773 sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier);
1774 if (sm == NULL) {
1775 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
1776 "station for this RADIUS message");
1777 return RADIUS_RX_UNKNOWN;
1778 }
1779 sta = sm->sta;
1780
1781 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
1782 * present when packet contains an EAP-Message attribute */
1783 if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
1784 radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
1785 0) < 0 &&
1786 radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
1787 wpa_printf(MSG_DEBUG, "Allowing RADIUS Access-Reject without "
1788 "Message-Authenticator since it does not include "
1789 "EAP-Message");
1790 } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
1791 req, 1)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001792 wpa_printf(MSG_INFO, "Incoming RADIUS packet did not have correct Message-Authenticator - dropped");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001793 return RADIUS_RX_INVALID_AUTHENTICATOR;
1794 }
1795
1796 if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
1797 hdr->code != RADIUS_CODE_ACCESS_REJECT &&
1798 hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001799 wpa_printf(MSG_INFO, "Unknown RADIUS message code");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001800 return RADIUS_RX_UNKNOWN;
1801 }
1802
1803 sm->radius_identifier = -1;
1804 wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
1805 MAC2STR(sta->addr));
1806
1807 radius_msg_free(sm->last_recv_radius);
1808 sm->last_recv_radius = msg;
1809
1810 session_timeout_set =
1811 !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
1812 &session_timeout);
1813 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION,
1814 &termination_action))
1815 termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
1816
1817 if (hapd->conf->acct_interim_interval == 0 &&
1818 hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
1819 radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
1820 &acct_interim_interval) == 0) {
1821 if (acct_interim_interval < 60) {
1822 hostapd_logger(hapd, sta->addr,
1823 HOSTAPD_MODULE_IEEE8021X,
1824 HOSTAPD_LEVEL_INFO,
1825 "ignored too small "
1826 "Acct-Interim-Interval %d",
1827 acct_interim_interval);
1828 } else
1829 sta->acct_interim_interval = acct_interim_interval;
1830 }
1831
1832
1833 switch (hdr->code) {
1834 case RADIUS_CODE_ACCESS_ACCEPT:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835#ifndef CONFIG_NO_VLAN
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001836 if (hapd->conf->ssid.dynamic_vlan != DYNAMIC_VLAN_DISABLED) {
1837 notempty = &vlan_desc.notempty;
1838 untagged = &vlan_desc.untagged;
1839 tagged = vlan_desc.tagged;
1840 *notempty = !!radius_msg_get_vlanid(msg, untagged,
1841 MAX_NUM_TAGGED_VLAN,
1842 tagged);
1843 }
1844
1845 if (vlan_desc.notempty &&
1846 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
Dmitry Shmidt83474442015-04-15 13:47:09 -07001847 sta->eapol_sm->authFail = TRUE;
1848 hostapd_logger(hapd, sta->addr,
1849 HOSTAPD_MODULE_RADIUS,
1850 HOSTAPD_LEVEL_INFO,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001851 "Invalid VLAN %d%s received from RADIUS server",
1852 vlan_desc.untagged,
1853 vlan_desc.tagged[0] ? "+" : "");
1854 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
1855 ap_sta_set_vlan(hapd, sta, &vlan_desc);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001856 break;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001857 }
1858
1859 if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_REQUIRED &&
1860 !vlan_desc.notempty) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001861 sta->eapol_sm->authFail = TRUE;
1862 hostapd_logger(hapd, sta->addr,
1863 HOSTAPD_MODULE_IEEE8021X,
1864 HOSTAPD_LEVEL_INFO, "authentication "
1865 "server did not include required VLAN "
1866 "ID in Access-Accept");
1867 break;
1868 }
1869#endif /* CONFIG_NO_VLAN */
1870
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001871 if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0)
1872 break;
1873
1874#ifndef CONFIG_NO_VLAN
1875 if (sta->vlan_id > 0) {
1876 hostapd_logger(hapd, sta->addr,
1877 HOSTAPD_MODULE_RADIUS,
1878 HOSTAPD_LEVEL_INFO,
1879 "VLAN ID %d", sta->vlan_id);
1880 }
1881#endif /* CONFIG_NO_VLAN */
1882
Dmitry Shmidt83474442015-04-15 13:47:09 -07001883 if ((sta->flags & WLAN_STA_ASSOC) &&
1884 ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001885 break;
1886
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001887 sta->session_timeout_set = !!session_timeout_set;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001888 os_get_reltime(&sta->session_timeout);
1889 sta->session_timeout.sec += session_timeout;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001890
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001891 /* RFC 3580, Ch. 3.17 */
1892 if (session_timeout_set && termination_action ==
Roshan Pius3a1667e2018-07-03 15:17:14 -07001893 RADIUS_TERMINATION_ACTION_RADIUS_REQUEST)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001894 sm->reAuthPeriod = session_timeout;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001895 else if (session_timeout_set)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001896 ap_sta_session_timeout(hapd, sta, session_timeout);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001897 else
1898 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001899
1900 sm->eap_if->aaaSuccess = TRUE;
1901 override_eapReq = 1;
1902 ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret,
1903 shared_secret_len);
1904 ieee802_1x_store_radius_class(hapd, sta, msg);
1905 ieee802_1x_update_sta_identity(hapd, sta, msg);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001906 ieee802_1x_update_sta_cui(hapd, sta, msg);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001907 ieee802_1x_check_hs20(hapd, sta, msg,
1908 session_timeout_set ?
1909 (int) session_timeout : -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001910 break;
1911 case RADIUS_CODE_ACCESS_REJECT:
1912 sm->eap_if->aaaFail = TRUE;
1913 override_eapReq = 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001914 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_WLAN_REASON_CODE,
1915 &reason_code) == 0) {
1916 wpa_printf(MSG_DEBUG,
1917 "RADIUS server indicated WLAN-Reason-Code %u in Access-Reject for "
1918 MACSTR, reason_code, MAC2STR(sta->addr));
1919 sta->disconnect_reason_code = reason_code;
1920 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001921 break;
1922 case RADIUS_CODE_ACCESS_CHALLENGE:
1923 sm->eap_if->aaaEapReq = TRUE;
1924 if (session_timeout_set) {
1925 /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
1926 sm->eap_if->aaaMethodTimeout = session_timeout;
1927 hostapd_logger(hapd, sm->addr,
1928 HOSTAPD_MODULE_IEEE8021X,
1929 HOSTAPD_LEVEL_DEBUG,
1930 "using EAP timeout of %d seconds (from "
1931 "RADIUS)",
1932 sm->eap_if->aaaMethodTimeout);
1933 } else {
1934 /*
1935 * Use dynamic retransmission behavior per EAP
1936 * specification.
1937 */
1938 sm->eap_if->aaaMethodTimeout = 0;
1939 }
1940 break;
1941 }
1942
1943 ieee802_1x_decapsulate_radius(hapd, sta);
1944 if (override_eapReq)
1945 sm->eap_if->aaaEapReq = FALSE;
1946
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001947#ifdef CONFIG_FILS
1948#ifdef NEED_AP_MLME
1949 if (sta->flags & WLAN_STA_PENDING_FILS_ERP) {
1950 /* TODO: Add a PMKSA entry on success? */
1951 ieee802_11_finish_fils_auth(
1952 hapd, sta, hdr->code == RADIUS_CODE_ACCESS_ACCEPT,
1953 sm->eap_if->aaaEapReqData,
1954 sm->eap_if->aaaEapKeyData,
1955 sm->eap_if->aaaEapKeyDataLen);
1956 }
1957#endif /* NEED_AP_MLME */
1958#endif /* CONFIG_FILS */
1959
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001960 eapol_auth_step(sm);
1961
1962 return RADIUS_RX_QUEUED;
1963}
1964#endif /* CONFIG_NO_RADIUS */
1965
1966
1967void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
1968{
1969 struct eapol_state_machine *sm = sta->eapol_sm;
1970 if (sm == NULL)
1971 return;
1972
1973 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1974 HOSTAPD_LEVEL_DEBUG, "aborting authentication");
1975
1976#ifndef CONFIG_NO_RADIUS
1977 radius_msg_free(sm->last_recv_radius);
1978 sm->last_recv_radius = NULL;
1979#endif /* CONFIG_NO_RADIUS */
1980
1981 if (sm->eap_if->eapTimeout) {
1982 /*
1983 * Disconnect the STA since it did not reply to the last EAP
1984 * request and we cannot continue EAP processing (EAP-Failure
1985 * could only be sent if the EAP peer actually replied).
1986 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001987 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "EAP Timeout, STA " MACSTR,
1988 MAC2STR(sta->addr));
1989
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001990 sm->eap_if->portEnabled = FALSE;
1991 ap_sta_disconnect(hapd, sta, sta->addr,
1992 WLAN_REASON_PREV_AUTH_NOT_VALID);
1993 }
1994}
1995
1996
1997static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
1998{
1999 struct eapol_authenticator *eapol = hapd->eapol_auth;
2000
2001 if (hapd->conf->default_wep_key_len < 1)
2002 return 0;
2003
2004 os_free(eapol->default_wep_key);
2005 eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
2006 if (eapol->default_wep_key == NULL ||
2007 random_get_bytes(eapol->default_wep_key,
2008 hapd->conf->default_wep_key_len)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002009 wpa_printf(MSG_INFO, "Could not generate random WEP key");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002010 os_free(eapol->default_wep_key);
2011 eapol->default_wep_key = NULL;
2012 return -1;
2013 }
2014
2015 wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
2016 eapol->default_wep_key,
2017 hapd->conf->default_wep_key_len);
2018
2019 return 0;
2020}
2021
2022
2023static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
2024 struct sta_info *sta, void *ctx)
2025{
2026 if (sta->eapol_sm) {
2027 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
2028 eapol_auth_step(sta->eapol_sm);
2029 }
2030 return 0;
2031}
2032
2033
2034static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
2035{
2036 struct hostapd_data *hapd = eloop_ctx;
2037 struct eapol_authenticator *eapol = hapd->eapol_auth;
2038
2039 if (eapol->default_wep_key_idx >= 3)
2040 eapol->default_wep_key_idx =
2041 hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
2042 else
2043 eapol->default_wep_key_idx++;
2044
2045 wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
2046 eapol->default_wep_key_idx);
Dmitry Shmidt29333592017-01-09 12:27:11 -08002047
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002048 if (ieee802_1x_rekey_broadcast(hapd)) {
2049 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
2050 HOSTAPD_LEVEL_WARNING, "failed to generate a "
2051 "new broadcast key");
2052 os_free(eapol->default_wep_key);
2053 eapol->default_wep_key = NULL;
2054 return;
2055 }
2056
2057 /* TODO: Could setup key for RX here, but change default TX keyid only
2058 * after new broadcast key has been sent to all stations. */
2059 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
2060 broadcast_ether_addr,
2061 eapol->default_wep_key_idx, 1, NULL, 0,
2062 eapol->default_wep_key,
2063 hapd->conf->default_wep_key_len)) {
2064 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
2065 HOSTAPD_LEVEL_WARNING, "failed to configure a "
2066 "new broadcast key");
2067 os_free(eapol->default_wep_key);
2068 eapol->default_wep_key = NULL;
2069 return;
2070 }
2071
2072 ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL);
2073
2074 if (hapd->conf->wep_rekeying_period > 0) {
2075 eloop_register_timeout(hapd->conf->wep_rekeying_period, 0,
2076 ieee802_1x_rekey, hapd, NULL);
2077 }
2078}
2079
2080
2081static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
2082 const u8 *data, size_t datalen)
2083{
2084#ifdef CONFIG_WPS
2085 struct sta_info *sta = sta_ctx;
2086
2087 if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
2088 WLAN_STA_MAYBE_WPS) {
2089 const u8 *identity;
2090 size_t identity_len;
2091 struct eapol_state_machine *sm = sta->eapol_sm;
2092
2093 identity = eap_get_identity(sm->eap, &identity_len);
2094 if (identity &&
2095 ((identity_len == WSC_ID_ENROLLEE_LEN &&
2096 os_memcmp(identity, WSC_ID_ENROLLEE,
2097 WSC_ID_ENROLLEE_LEN) == 0) ||
2098 (identity_len == WSC_ID_REGISTRAR_LEN &&
2099 os_memcmp(identity, WSC_ID_REGISTRAR,
2100 WSC_ID_REGISTRAR_LEN) == 0))) {
2101 wpa_printf(MSG_DEBUG, "WPS: WLAN_STA_MAYBE_WPS -> "
2102 "WLAN_STA_WPS");
2103 sta->flags |= WLAN_STA_WPS;
2104 }
2105 }
2106#endif /* CONFIG_WPS */
2107
2108 ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
2109}
2110
2111
2112static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
2113 const u8 *data, size_t datalen)
2114{
2115#ifndef CONFIG_NO_RADIUS
2116 struct hostapd_data *hapd = ctx;
2117 struct sta_info *sta = sta_ctx;
2118
2119 ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
2120#endif /* CONFIG_NO_RADIUS */
2121}
2122
2123
2124static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002125 int preauth, int remediation)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126{
2127 struct hostapd_data *hapd = ctx;
2128 struct sta_info *sta = sta_ctx;
2129 if (preauth)
2130 rsn_preauth_finished(hapd, sta, success);
2131 else
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002132 ieee802_1x_finished(hapd, sta, success, remediation);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002133}
2134
2135
2136static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity,
2137 size_t identity_len, int phase2,
2138 struct eap_user *user)
2139{
2140 struct hostapd_data *hapd = ctx;
2141 const struct hostapd_eap_user *eap_user;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002142 int i;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002143 int rv = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002144
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002145 eap_user = hostapd_get_eap_user(hapd, identity, identity_len, phase2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002146 if (eap_user == NULL)
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002147 goto out;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002148
2149 os_memset(user, 0, sizeof(*user));
2150 user->phase2 = phase2;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002151 for (i = 0; i < EAP_MAX_METHODS; i++) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002152 user->methods[i].vendor = eap_user->methods[i].vendor;
2153 user->methods[i].method = eap_user->methods[i].method;
2154 }
2155
2156 if (eap_user->password) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002157 user->password = os_memdup(eap_user->password,
2158 eap_user->password_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002159 if (user->password == NULL)
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002160 goto out;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002161 user->password_len = eap_user->password_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002162 user->password_hash = eap_user->password_hash;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002163 if (eap_user->salt && eap_user->salt_len) {
2164 user->salt = os_memdup(eap_user->salt,
2165 eap_user->salt_len);
2166 if (!user->salt)
2167 goto out;
2168 user->salt_len = eap_user->salt_len;
2169 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002170 }
2171 user->force_version = eap_user->force_version;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002172 user->macacl = eap_user->macacl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002173 user->ttls_auth = eap_user->ttls_auth;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002174 user->remediation = eap_user->remediation;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002175 rv = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002176
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002177out:
2178 if (rv)
2179 wpa_printf(MSG_DEBUG, "%s: Failed to find user", __func__);
2180
2181 return rv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002182}
2183
2184
2185static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
2186{
2187 struct hostapd_data *hapd = ctx;
2188 struct sta_info *sta;
2189 sta = ap_get_sta(hapd, addr);
2190 if (sta == NULL || sta->eapol_sm == NULL)
2191 return 0;
2192 return 1;
2193}
2194
2195
2196static void ieee802_1x_logger(void *ctx, const u8 *addr,
2197 eapol_logger_level level, const char *txt)
2198{
2199#ifndef CONFIG_NO_HOSTAPD_LOGGER
2200 struct hostapd_data *hapd = ctx;
2201 int hlevel;
2202
2203 switch (level) {
2204 case EAPOL_LOGGER_WARNING:
2205 hlevel = HOSTAPD_LEVEL_WARNING;
2206 break;
2207 case EAPOL_LOGGER_INFO:
2208 hlevel = HOSTAPD_LEVEL_INFO;
2209 break;
2210 case EAPOL_LOGGER_DEBUG:
2211 default:
2212 hlevel = HOSTAPD_LEVEL_DEBUG;
2213 break;
2214 }
2215
2216 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
2217 txt);
2218#endif /* CONFIG_NO_HOSTAPD_LOGGER */
2219}
2220
2221
2222static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx,
2223 int authorized)
2224{
2225 struct hostapd_data *hapd = ctx;
2226 struct sta_info *sta = sta_ctx;
2227 ieee802_1x_set_sta_authorized(hapd, sta, authorized);
2228}
2229
2230
2231static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx)
2232{
2233 struct hostapd_data *hapd = ctx;
2234 struct sta_info *sta = sta_ctx;
2235 ieee802_1x_abort_auth(hapd, sta);
2236}
2237
2238
2239static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
2240{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002241#ifndef CONFIG_FIPS
2242#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002243 struct hostapd_data *hapd = ctx;
2244 struct sta_info *sta = sta_ctx;
2245 ieee802_1x_tx_key(hapd, sta);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002246#endif /* CONFIG_NO_RC4 */
2247#endif /* CONFIG_FIPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002248}
2249
2250
2251static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx,
2252 enum eapol_event type)
2253{
2254 /* struct hostapd_data *hapd = ctx; */
2255 struct sta_info *sta = sta_ctx;
2256 switch (type) {
2257 case EAPOL_AUTH_SM_CHANGE:
2258 wpa_auth_sm_notify(sta->wpa_sm);
2259 break;
2260 case EAPOL_AUTH_REAUTHENTICATE:
2261 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
2262 break;
2263 }
2264}
2265
2266
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002267#ifdef CONFIG_ERP
2268
2269static struct eap_server_erp_key *
2270ieee802_1x_erp_get_key(void *ctx, const char *keyname)
2271{
2272 struct hostapd_data *hapd = ctx;
2273 struct eap_server_erp_key *erp;
2274
2275 dl_list_for_each(erp, &hapd->erp_keys, struct eap_server_erp_key,
2276 list) {
2277 if (os_strcmp(erp->keyname_nai, keyname) == 0)
2278 return erp;
2279 }
2280
2281 return NULL;
2282}
2283
2284
2285static int ieee802_1x_erp_add_key(void *ctx, struct eap_server_erp_key *erp)
2286{
2287 struct hostapd_data *hapd = ctx;
2288
2289 dl_list_add(&hapd->erp_keys, &erp->list);
2290 return 0;
2291}
2292
2293#endif /* CONFIG_ERP */
2294
2295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002296int ieee802_1x_init(struct hostapd_data *hapd)
2297{
2298 int i;
2299 struct eapol_auth_config conf;
2300 struct eapol_auth_cb cb;
2301
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002302 dl_list_init(&hapd->erp_keys);
2303
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002304 os_memset(&conf, 0, sizeof(conf));
2305 conf.ctx = hapd;
2306 conf.eap_reauth_period = hapd->conf->eap_reauth_period;
2307 conf.wpa = hapd->conf->wpa;
2308 conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
2309 conf.eap_server = hapd->conf->eap_server;
2310 conf.ssl_ctx = hapd->ssl_ctx;
2311 conf.msg_ctx = hapd->msg_ctx;
2312 conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
2313 conf.eap_req_id_text = hapd->conf->eap_req_id_text;
2314 conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002315 conf.erp_send_reauth_start = hapd->conf->erp_send_reauth_start;
2316 conf.erp_domain = hapd->conf->erp_domain;
2317 conf.erp = hapd->conf->eap_server_erp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002318 conf.tls_session_lifetime = hapd->conf->tls_session_lifetime;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002319 conf.tls_flags = hapd->conf->tls_flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002320 conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
2321 conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
2322 conf.eap_fast_a_id_len = hapd->conf->eap_fast_a_id_len;
2323 conf.eap_fast_a_id_info = hapd->conf->eap_fast_a_id_info;
2324 conf.eap_fast_prov = hapd->conf->eap_fast_prov;
2325 conf.pac_key_lifetime = hapd->conf->pac_key_lifetime;
2326 conf.pac_key_refresh_time = hapd->conf->pac_key_refresh_time;
2327 conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
2328 conf.tnc = hapd->conf->tnc;
2329 conf.wps = hapd->wps;
2330 conf.fragment_size = hapd->conf->fragment_size;
2331 conf.pwd_group = hapd->conf->pwd_group;
Jouni Malinen87fd2792011-05-16 18:35:42 +03002332 conf.pbc_in_m1 = hapd->conf->pbc_in_m1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002333 if (hapd->conf->server_id) {
2334 conf.server_id = (const u8 *) hapd->conf->server_id;
2335 conf.server_id_len = os_strlen(hapd->conf->server_id);
2336 } else {
2337 conf.server_id = (const u8 *) "hostapd";
2338 conf.server_id_len = 7;
2339 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002340
2341 os_memset(&cb, 0, sizeof(cb));
2342 cb.eapol_send = ieee802_1x_eapol_send;
2343 cb.aaa_send = ieee802_1x_aaa_send;
2344 cb.finished = _ieee802_1x_finished;
2345 cb.get_eap_user = ieee802_1x_get_eap_user;
2346 cb.sta_entry_alive = ieee802_1x_sta_entry_alive;
2347 cb.logger = ieee802_1x_logger;
2348 cb.set_port_authorized = ieee802_1x_set_port_authorized;
2349 cb.abort_auth = _ieee802_1x_abort_auth;
2350 cb.tx_key = _ieee802_1x_tx_key;
2351 cb.eapol_event = ieee802_1x_eapol_event;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002352#ifdef CONFIG_ERP
2353 cb.erp_get_key = ieee802_1x_erp_get_key;
2354 cb.erp_add_key = ieee802_1x_erp_add_key;
2355#endif /* CONFIG_ERP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002356
2357 hapd->eapol_auth = eapol_auth_init(&conf, &cb);
2358 if (hapd->eapol_auth == NULL)
2359 return -1;
2360
2361 if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
2362 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1))
2363 return -1;
2364
2365#ifndef CONFIG_NO_RADIUS
2366 if (radius_client_register(hapd->radius, RADIUS_AUTH,
2367 ieee802_1x_receive_auth, hapd))
2368 return -1;
2369#endif /* CONFIG_NO_RADIUS */
2370
2371 if (hapd->conf->default_wep_key_len) {
2372 for (i = 0; i < 4; i++)
2373 hostapd_drv_set_key(hapd->conf->iface, hapd,
2374 WPA_ALG_NONE, NULL, i, 0, NULL, 0,
2375 NULL, 0);
2376
2377 ieee802_1x_rekey(hapd, NULL);
2378
2379 if (hapd->eapol_auth->default_wep_key == NULL)
2380 return -1;
2381 }
2382
2383 return 0;
2384}
2385
2386
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002387void ieee802_1x_erp_flush(struct hostapd_data *hapd)
2388{
2389 struct eap_server_erp_key *erp;
2390
2391 while ((erp = dl_list_first(&hapd->erp_keys, struct eap_server_erp_key,
2392 list)) != NULL) {
2393 dl_list_del(&erp->list);
2394 bin_clear_free(erp, sizeof(*erp));
2395 }
2396}
2397
2398
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002399void ieee802_1x_deinit(struct hostapd_data *hapd)
2400{
2401 eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);
2402
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002403 if (hapd->driver && hapd->drv_priv &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002404 (hapd->conf->ieee802_1x || hapd->conf->wpa))
2405 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
2406
2407 eapol_auth_deinit(hapd->eapol_auth);
2408 hapd->eapol_auth = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002409
2410 ieee802_1x_erp_flush(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002411}
2412
2413
2414int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
2415 const u8 *buf, size_t len, int ack)
2416{
2417 struct ieee80211_hdr *hdr;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418 u8 *pos;
2419 const unsigned char rfc1042_hdr[ETH_ALEN] =
2420 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
2421
2422 if (sta == NULL)
2423 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002424 if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002425 return 0;
2426
2427 hdr = (struct ieee80211_hdr *) buf;
2428 pos = (u8 *) (hdr + 1);
2429 if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0)
2430 return 0;
2431 pos += sizeof(rfc1042_hdr);
2432 if (WPA_GET_BE16(pos) != ETH_P_PAE)
2433 return 0;
2434 pos += 2;
2435
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002436 return ieee802_1x_eapol_tx_status(hapd, sta, pos, buf + len - pos,
2437 ack);
2438}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002439
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002440
2441int ieee802_1x_eapol_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
2442 const u8 *buf, int len, int ack)
2443{
2444 const struct ieee802_1x_hdr *xhdr =
2445 (const struct ieee802_1x_hdr *) buf;
2446 const u8 *pos = buf + sizeof(*xhdr);
2447 struct ieee802_1x_eapol_key *key;
2448
2449 if (len < (int) sizeof(*xhdr))
2450 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002451 wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR " TX status - version=%d "
2452 "type=%d length=%d - ack=%d",
2453 MAC2STR(sta->addr), xhdr->version, xhdr->type,
2454 be_to_host16(xhdr->length), ack);
2455
Dmitry Shmidt29333592017-01-09 12:27:11 -08002456#ifdef CONFIG_WPS
2457 if (xhdr->type == IEEE802_1X_TYPE_EAP_PACKET && ack &&
2458 (sta->flags & WLAN_STA_WPS) &&
2459 ap_sta_pending_delayed_1x_auth_fail_disconnect(hapd, sta)) {
2460 wpa_printf(MSG_DEBUG,
2461 "WPS: Indicate EAP completion on ACK for EAP-Failure");
2462 hostapd_wps_eap_completed(hapd);
2463 }
2464#endif /* CONFIG_WPS */
2465
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002466 if (xhdr->type != IEEE802_1X_TYPE_EAPOL_KEY)
2467 return 0;
2468
2469 if (pos + sizeof(struct wpa_eapol_key) <= buf + len) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002470 const struct wpa_eapol_key *wpa;
2471 wpa = (const struct wpa_eapol_key *) pos;
2472 if (wpa->type == EAPOL_KEY_TYPE_RSN ||
2473 wpa->type == EAPOL_KEY_TYPE_WPA)
2474 wpa_auth_eapol_key_tx_status(hapd->wpa_auth,
2475 sta->wpa_sm, ack);
2476 }
2477
2478 /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
2479 * or Authenticator state machines, but EAPOL-Key packets are not
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002480 * retransmitted in case of failure. Try to re-send failed EAPOL-Key
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002481 * packets couple of times because otherwise STA keys become
2482 * unsynchronized with AP. */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002483 if (!ack && pos + sizeof(*key) <= buf + len) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002484 key = (struct ieee802_1x_eapol_key *) pos;
2485 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
2486 HOSTAPD_LEVEL_DEBUG, "did not Ack EAPOL-Key "
2487 "frame (%scast index=%d)",
2488 key->key_index & BIT(7) ? "uni" : "broad",
2489 key->key_index & ~BIT(7));
2490 /* TODO: re-send EAPOL-Key couple of times (with short delay
2491 * between them?). If all attempt fail, report error and
2492 * deauthenticate STA so that it will get new keys when
2493 * authenticating again (e.g., after returning in range).
2494 * Separate limit/transmit state needed both for unicast and
2495 * broadcast keys(?) */
2496 }
2497 /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
2498 * to here and change the key only if the EAPOL-Key packet was Acked.
2499 */
2500
2501 return 1;
2502}
2503
2504
2505u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len)
2506{
2507 if (sm == NULL || sm->identity == NULL)
2508 return NULL;
2509
2510 *len = sm->identity_len;
2511 return sm->identity;
2512}
2513
2514
2515u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
2516 int idx)
2517{
2518 if (sm == NULL || sm->radius_class.attr == NULL ||
2519 idx >= (int) sm->radius_class.count)
2520 return NULL;
2521
2522 *len = sm->radius_class.attr[idx].len;
2523 return sm->radius_class.attr[idx].data;
2524}
2525
2526
Dmitry Shmidt04949592012-07-19 12:16:46 -07002527struct wpabuf * ieee802_1x_get_radius_cui(struct eapol_state_machine *sm)
2528{
2529 if (sm == NULL)
2530 return NULL;
2531 return sm->radius_cui;
2532}
2533
2534
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002535const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len)
2536{
Jouni Malinen75ecf522011-06-27 15:19:46 -07002537 *len = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002538 if (sm == NULL)
2539 return NULL;
2540
2541 *len = sm->eap_if->eapKeyDataLen;
2542 return sm->eap_if->eapKeyData;
2543}
2544
2545
2546void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm,
2547 int enabled)
2548{
2549 if (sm == NULL)
2550 return;
2551 sm->eap_if->portEnabled = enabled ? TRUE : FALSE;
2552 eapol_auth_step(sm);
2553}
2554
2555
2556void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm,
2557 int valid)
2558{
2559 if (sm == NULL)
2560 return;
2561 sm->portValid = valid ? TRUE : FALSE;
2562 eapol_auth_step(sm);
2563}
2564
2565
2566void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth)
2567{
2568 if (sm == NULL)
2569 return;
2570 if (pre_auth)
2571 sm->flags |= EAPOL_SM_PREAUTH;
2572 else
2573 sm->flags &= ~EAPOL_SM_PREAUTH;
2574}
2575
2576
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002577static const char * bool_txt(Boolean val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002578{
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002579 return val ? "TRUE" : "FALSE";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002580}
2581
2582
2583int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2584{
2585 /* TODO */
2586 return 0;
2587}
2588
2589
2590int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2591 char *buf, size_t buflen)
2592{
2593 int len = 0, ret;
2594 struct eapol_state_machine *sm = sta->eapol_sm;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002595 struct os_reltime diff;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08002596 const char *name1;
2597 const char *name2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002598
2599 if (sm == NULL)
2600 return 0;
2601
2602 ret = os_snprintf(buf + len, buflen - len,
2603 "dot1xPaePortNumber=%d\n"
2604 "dot1xPaePortProtocolVersion=%d\n"
2605 "dot1xPaePortCapabilities=1\n"
2606 "dot1xPaePortInitialize=%d\n"
2607 "dot1xPaePortReauthenticate=FALSE\n",
2608 sta->aid,
2609 EAPOL_VERSION,
2610 sm->initialize);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002611 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002612 return len;
2613 len += ret;
2614
2615 /* dot1xAuthConfigTable */
2616 ret = os_snprintf(buf + len, buflen - len,
2617 "dot1xAuthPaeState=%d\n"
2618 "dot1xAuthBackendAuthState=%d\n"
2619 "dot1xAuthAdminControlledDirections=%d\n"
2620 "dot1xAuthOperControlledDirections=%d\n"
2621 "dot1xAuthAuthControlledPortStatus=%d\n"
2622 "dot1xAuthAuthControlledPortControl=%d\n"
2623 "dot1xAuthQuietPeriod=%u\n"
2624 "dot1xAuthServerTimeout=%u\n"
2625 "dot1xAuthReAuthPeriod=%u\n"
2626 "dot1xAuthReAuthEnabled=%s\n"
2627 "dot1xAuthKeyTxEnabled=%s\n",
2628 sm->auth_pae_state + 1,
2629 sm->be_auth_state + 1,
2630 sm->adminControlledDirections,
2631 sm->operControlledDirections,
2632 sm->authPortStatus,
2633 sm->portControl,
2634 sm->quietPeriod,
2635 sm->serverTimeout,
2636 sm->reAuthPeriod,
2637 bool_txt(sm->reAuthEnabled),
2638 bool_txt(sm->keyTxEnabled));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002639 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002640 return len;
2641 len += ret;
2642
2643 /* dot1xAuthStatsTable */
2644 ret = os_snprintf(buf + len, buflen - len,
2645 "dot1xAuthEapolFramesRx=%u\n"
2646 "dot1xAuthEapolFramesTx=%u\n"
2647 "dot1xAuthEapolStartFramesRx=%u\n"
2648 "dot1xAuthEapolLogoffFramesRx=%u\n"
2649 "dot1xAuthEapolRespIdFramesRx=%u\n"
2650 "dot1xAuthEapolRespFramesRx=%u\n"
2651 "dot1xAuthEapolReqIdFramesTx=%u\n"
2652 "dot1xAuthEapolReqFramesTx=%u\n"
2653 "dot1xAuthInvalidEapolFramesRx=%u\n"
2654 "dot1xAuthEapLengthErrorFramesRx=%u\n"
2655 "dot1xAuthLastEapolFrameVersion=%u\n"
2656 "dot1xAuthLastEapolFrameSource=" MACSTR "\n",
2657 sm->dot1xAuthEapolFramesRx,
2658 sm->dot1xAuthEapolFramesTx,
2659 sm->dot1xAuthEapolStartFramesRx,
2660 sm->dot1xAuthEapolLogoffFramesRx,
2661 sm->dot1xAuthEapolRespIdFramesRx,
2662 sm->dot1xAuthEapolRespFramesRx,
2663 sm->dot1xAuthEapolReqIdFramesTx,
2664 sm->dot1xAuthEapolReqFramesTx,
2665 sm->dot1xAuthInvalidEapolFramesRx,
2666 sm->dot1xAuthEapLengthErrorFramesRx,
2667 sm->dot1xAuthLastEapolFrameVersion,
2668 MAC2STR(sm->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002669 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002670 return len;
2671 len += ret;
2672
2673 /* dot1xAuthDiagTable */
2674 ret = os_snprintf(buf + len, buflen - len,
2675 "dot1xAuthEntersConnecting=%u\n"
2676 "dot1xAuthEapLogoffsWhileConnecting=%u\n"
2677 "dot1xAuthEntersAuthenticating=%u\n"
2678 "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
2679 "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
2680 "dot1xAuthAuthFailWhileAuthenticating=%u\n"
2681 "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
2682 "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
2683 "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
2684 "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
2685 "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
2686 "dot1xAuthBackendResponses=%u\n"
2687 "dot1xAuthBackendAccessChallenges=%u\n"
2688 "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
2689 "dot1xAuthBackendAuthSuccesses=%u\n"
2690 "dot1xAuthBackendAuthFails=%u\n",
2691 sm->authEntersConnecting,
2692 sm->authEapLogoffsWhileConnecting,
2693 sm->authEntersAuthenticating,
2694 sm->authAuthSuccessesWhileAuthenticating,
2695 sm->authAuthTimeoutsWhileAuthenticating,
2696 sm->authAuthFailWhileAuthenticating,
2697 sm->authAuthEapStartsWhileAuthenticating,
2698 sm->authAuthEapLogoffWhileAuthenticating,
2699 sm->authAuthReauthsWhileAuthenticated,
2700 sm->authAuthEapStartsWhileAuthenticated,
2701 sm->authAuthEapLogoffWhileAuthenticated,
2702 sm->backendResponses,
2703 sm->backendAccessChallenges,
2704 sm->backendOtherRequestsToSupplicant,
2705 sm->backendAuthSuccesses,
2706 sm->backendAuthFails);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002707 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002708 return len;
2709 len += ret;
2710
2711 /* dot1xAuthSessionStatsTable */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002712 os_reltime_age(&sta->acct_session_start, &diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002713 ret = os_snprintf(buf + len, buflen - len,
2714 /* TODO: dot1xAuthSessionOctetsRx */
2715 /* TODO: dot1xAuthSessionOctetsTx */
2716 /* TODO: dot1xAuthSessionFramesRx */
2717 /* TODO: dot1xAuthSessionFramesTx */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002718 "dot1xAuthSessionId=%016llX\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002719 "dot1xAuthSessionAuthenticMethod=%d\n"
2720 "dot1xAuthSessionTime=%u\n"
2721 "dot1xAuthSessionTerminateCause=999\n"
2722 "dot1xAuthSessionUserName=%s\n",
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002723 (unsigned long long) sta->acct_session_id,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002724 (wpa_key_mgmt_wpa_ieee8021x(
2725 wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
2726 1 : 2,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002727 (unsigned int) diff.sec,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002728 sm->identity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002729 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002730 return len;
2731 len += ret;
2732
Dmitry Shmidtb97e4282016-02-08 10:16:07 -08002733 if (sm->acct_multi_session_id) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002734 ret = os_snprintf(buf + len, buflen - len,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002735 "authMultiSessionId=%016llX\n",
2736 (unsigned long long)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -08002737 sm->acct_multi_session_id);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002738 if (os_snprintf_error(buflen - len, ret))
2739 return len;
2740 len += ret;
2741 }
2742
Dmitry Shmidt96be6222014-02-13 10:16:51 -08002743 name1 = eap_server_get_name(0, sm->eap_type_authsrv);
2744 name2 = eap_server_get_name(0, sm->eap_type_supp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002745 ret = os_snprintf(buf + len, buflen - len,
2746 "last_eap_type_as=%d (%s)\n"
2747 "last_eap_type_sta=%d (%s)\n",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002748 sm->eap_type_authsrv, name1,
2749 sm->eap_type_supp, name2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002750 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002751 return len;
2752 len += ret;
2753
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002754 return len;
2755}
2756
2757
Dmitry Shmidtde47be72016-01-07 12:52:55 -08002758#ifdef CONFIG_HS20
2759static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx)
2760{
2761 struct hostapd_data *hapd = eloop_ctx;
2762 struct sta_info *sta = timeout_ctx;
2763
2764 if (sta->remediation) {
2765 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
2766 MACSTR " to indicate Subscription Remediation",
2767 MAC2STR(sta->addr));
2768 hs20_send_wnm_notification(hapd, sta->addr,
2769 sta->remediation_method,
2770 sta->remediation_url);
2771 os_free(sta->remediation_url);
2772 sta->remediation_url = NULL;
2773 }
2774
2775 if (sta->hs20_deauth_req) {
2776 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
2777 MACSTR " to indicate imminent deauthentication",
2778 MAC2STR(sta->addr));
2779 hs20_send_wnm_notification_deauth_req(hapd, sta->addr,
2780 sta->hs20_deauth_req);
2781 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07002782
2783 if (sta->hs20_t_c_filtering) {
2784 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
2785 MACSTR " to indicate Terms and Conditions filtering",
2786 MAC2STR(sta->addr));
2787 hs20_send_wnm_notification_t_c(hapd, sta->addr, sta->t_c_url);
2788 os_free(sta->t_c_url);
2789 sta->t_c_url = NULL;
2790 }
Dmitry Shmidtde47be72016-01-07 12:52:55 -08002791}
2792#endif /* CONFIG_HS20 */
2793
2794
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002795static void ieee802_1x_finished(struct hostapd_data *hapd,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002796 struct sta_info *sta, int success,
2797 int remediation)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002798{
2799 const u8 *key;
2800 size_t len;
2801 /* TODO: get PMKLifetime from WPA parameters */
2802 static const int dot11RSNAConfigPMKLifetime = 43200;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07002803 unsigned int session_timeout;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002804 struct os_reltime now, remaining;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002805
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002806#ifdef CONFIG_HS20
2807 if (remediation && !sta->remediation) {
2808 sta->remediation = 1;
2809 os_free(sta->remediation_url);
2810 sta->remediation_url =
2811 os_strdup(hapd->conf->subscr_remediation_url);
2812 sta->remediation_method = 1; /* SOAP-XML SPP */
2813 }
2814
Roshan Pius3a1667e2018-07-03 15:17:14 -07002815 if (success && (sta->remediation || sta->hs20_deauth_req ||
2816 sta->hs20_t_c_filtering)) {
Dmitry Shmidtde47be72016-01-07 12:52:55 -08002817 wpa_printf(MSG_DEBUG, "HS 2.0: Schedule WNM-Notification to "
2818 MACSTR " in 100 ms", MAC2STR(sta->addr));
2819 eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta);
2820 eloop_register_timeout(0, 100000, ieee802_1x_wnm_notif_send,
2821 hapd, sta);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002822 }
2823#endif /* CONFIG_HS20 */
2824
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002825 key = ieee802_1x_get_key(sta->eapol_sm, &len);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002826 if (sta->session_timeout_set) {
2827 os_get_reltime(&now);
2828 os_reltime_sub(&sta->session_timeout, &now, &remaining);
2829 session_timeout = (remaining.sec > 0) ? remaining.sec : 1;
2830 } else {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07002831 session_timeout = dot11RSNAConfigPMKLifetime;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002832 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002833 if (success && key && len >= PMK_LEN && !sta->remediation &&
2834 !sta->hs20_deauth_requested &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002835 wpa_auth_pmksa_add(sta->wpa_sm, key, len, session_timeout,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002836 sta->eapol_sm) == 0) {
2837 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
2838 HOSTAPD_LEVEL_DEBUG,
2839 "Added PMKSA cache entry (IEEE 802.1X)");
2840 }
2841
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002842 if (!success) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002843 /*
2844 * Many devices require deauthentication after WPS provisioning
2845 * and some may not be be able to do that themselves, so
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002846 * disconnect the client here. In addition, this may also
2847 * benefit IEEE 802.1X/EAPOL authentication cases, too since
2848 * the EAPOL PAE state machine would remain in HELD state for
2849 * considerable amount of time and some EAP methods, like
2850 * EAP-FAST with anonymous provisioning, may require another
2851 * EAPOL authentication to be started to complete connection.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002852 */
Dmitry Shmidt29333592017-01-09 12:27:11 -08002853 ap_sta_delayed_1x_auth_fail_disconnect(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002854 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002855}