]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/ap/ieee802_1x.c
macsec: Do not change eapol_version for non-MACsec cases in hostapd
[thirdparty/hostap.git] / src / ap / ieee802_1x.c
1 /*
2 * hostapd / IEEE 802.1X-2004 Authenticator
3 * Copyright (c) 2002-2019, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
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"
17 #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"
23 #include "p2p/p2p.h"
24 #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"
32 #include "wps_hostapd.h"
33 #include "hs20.h"
34 /* FIX: Not really a good thing to require ieee802_11.h here.. (FILS) */
35 #include "ieee802_11.h"
36 #include "ieee802_1x.h"
37 #include "wpa_auth_kay.h"
38
39
40 #ifdef CONFIG_HS20
41 static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx);
42 #endif /* CONFIG_HS20 */
43 static void ieee802_1x_finished(struct hostapd_data *hapd,
44 struct sta_info *sta, int success,
45 int remediation);
46
47
48 static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
49 u8 type, const u8 *data, size_t datalen)
50 {
51 u8 *buf;
52 struct ieee802_1x_hdr *xhdr;
53 size_t len;
54 int encrypt = 0;
55
56 len = sizeof(*xhdr) + datalen;
57 buf = os_zalloc(len);
58 if (buf == NULL) {
59 wpa_printf(MSG_ERROR, "malloc() failed for "
60 "ieee802_1x_send(len=%lu)",
61 (unsigned long) len);
62 return;
63 }
64
65 xhdr = (struct ieee802_1x_hdr *) buf;
66 xhdr->version = hapd->conf->eapol_version;
67 #ifdef CONFIG_MACSEC
68 if (xhdr->version > 2 && hapd->conf->macsec_policy == 0)
69 xhdr->version = 2;
70 #endif /* CONFIG_MACSEC */
71 xhdr->type = type;
72 xhdr->length = host_to_be16(datalen);
73
74 if (datalen > 0 && data != NULL)
75 os_memcpy(xhdr + 1, data, datalen);
76
77 if (wpa_auth_pairwise_set(sta->wpa_sm))
78 encrypt = 1;
79 #ifdef CONFIG_TESTING_OPTIONS
80 if (hapd->ext_eapol_frame_io) {
81 size_t hex_len = 2 * len + 1;
82 char *hex = os_malloc(hex_len);
83
84 if (hex) {
85 wpa_snprintf_hex(hex, hex_len, buf, len);
86 wpa_msg(hapd->msg_ctx, MSG_INFO,
87 "EAPOL-TX " MACSTR " %s",
88 MAC2STR(sta->addr), hex);
89 os_free(hex);
90 }
91 } else
92 #endif /* CONFIG_TESTING_OPTIONS */
93 if (sta->flags & WLAN_STA_PREAUTH) {
94 rsn_preauth_send(hapd, sta, buf, len);
95 } else {
96 hostapd_drv_hapd_send_eapol(
97 hapd, sta->addr, buf, len,
98 encrypt, hostapd_sta_flags_to_drv(sta->flags));
99 }
100
101 os_free(buf);
102 }
103
104
105 void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
106 struct sta_info *sta, int authorized)
107 {
108 int res;
109
110 if (sta->flags & WLAN_STA_PREAUTH)
111 return;
112
113 if (authorized) {
114 ap_sta_set_authorized(hapd, sta, 1);
115 res = hostapd_set_authorized(hapd, sta, 1);
116 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
117 HOSTAPD_LEVEL_DEBUG, "authorizing port");
118 } else {
119 ap_sta_set_authorized(hapd, sta, 0);
120 res = hostapd_set_authorized(hapd, sta, 0);
121 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
122 HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
123 }
124
125 if (res && errno != ENOENT) {
126 wpa_printf(MSG_DEBUG, "Could not set station " MACSTR
127 " flags for kernel driver (errno=%d).",
128 MAC2STR(sta->addr), errno);
129 }
130
131 if (authorized) {
132 os_get_reltime(&sta->connected_time);
133 accounting_sta_start(hapd, sta);
134 }
135 }
136
137
138 #ifndef CONFIG_FIPS
139 #ifndef CONFIG_NO_RC4
140
141 static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
142 struct sta_info *sta,
143 int idx, int broadcast,
144 u8 *key_data, size_t key_len)
145 {
146 u8 *buf, *ekey;
147 struct ieee802_1x_hdr *hdr;
148 struct ieee802_1x_eapol_key *key;
149 size_t len, ekey_len;
150 struct eapol_state_machine *sm = sta->eapol_sm;
151
152 if (sm == NULL)
153 return;
154
155 len = sizeof(*key) + key_len;
156 buf = os_zalloc(sizeof(*hdr) + len);
157 if (buf == NULL)
158 return;
159
160 hdr = (struct ieee802_1x_hdr *) buf;
161 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
162 key->type = EAPOL_KEY_TYPE_RC4;
163 WPA_PUT_BE16(key->key_length, key_len);
164 wpa_get_ntp_timestamp(key->replay_counter);
165 if (os_memcmp(key->replay_counter,
166 hapd->last_1x_eapol_key_replay_counter,
167 IEEE8021X_REPLAY_COUNTER_LEN) <= 0) {
168 /* NTP timestamp did not increment from last EAPOL-Key frame;
169 * use previously used value + 1 instead. */
170 inc_byte_array(hapd->last_1x_eapol_key_replay_counter,
171 IEEE8021X_REPLAY_COUNTER_LEN);
172 os_memcpy(key->replay_counter,
173 hapd->last_1x_eapol_key_replay_counter,
174 IEEE8021X_REPLAY_COUNTER_LEN);
175 } else {
176 os_memcpy(hapd->last_1x_eapol_key_replay_counter,
177 key->replay_counter,
178 IEEE8021X_REPLAY_COUNTER_LEN);
179 }
180
181 if (random_get_bytes(key->key_iv, sizeof(key->key_iv))) {
182 wpa_printf(MSG_ERROR, "Could not get random numbers");
183 os_free(buf);
184 return;
185 }
186
187 key->key_index = idx | (broadcast ? 0 : BIT(7));
188 if (hapd->conf->eapol_key_index_workaround) {
189 /* According to some information, WinXP Supplicant seems to
190 * interpret bit7 as an indication whether the key is to be
191 * activated, so make it possible to enable workaround that
192 * sets this bit for all keys. */
193 key->key_index |= BIT(7);
194 }
195
196 /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
197 * MSK[32..63] is used to sign the message. */
198 if (sm->eap_if->eapKeyData == NULL || sm->eap_if->eapKeyDataLen < 64) {
199 wpa_printf(MSG_ERROR, "No eapKeyData available for encrypting "
200 "and signing EAPOL-Key");
201 os_free(buf);
202 return;
203 }
204 os_memcpy((u8 *) (key + 1), key_data, key_len);
205 ekey_len = sizeof(key->key_iv) + 32;
206 ekey = os_malloc(ekey_len);
207 if (ekey == NULL) {
208 wpa_printf(MSG_ERROR, "Could not encrypt key");
209 os_free(buf);
210 return;
211 }
212 os_memcpy(ekey, key->key_iv, sizeof(key->key_iv));
213 os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32);
214 rc4_skip(ekey, ekey_len, 0, (u8 *) (key + 1), key_len);
215 os_free(ekey);
216
217 /* This header is needed here for HMAC-MD5, but it will be regenerated
218 * in ieee802_1x_send() */
219 hdr->version = hapd->conf->eapol_version;
220 #ifdef CONFIG_MACSEC
221 if (hdr->version > 2)
222 hdr->version = 2;
223 #endif /* CONFIG_MACSEC */
224 hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
225 hdr->length = host_to_be16(len);
226 hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len,
227 key->key_signature);
228
229 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
230 " (%s index=%d)", MAC2STR(sm->addr),
231 broadcast ? "broadcast" : "unicast", idx);
232 ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len);
233 if (sta->eapol_sm)
234 sta->eapol_sm->dot1xAuthEapolFramesTx++;
235 os_free(buf);
236 }
237
238
239 static void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
240 {
241 struct eapol_authenticator *eapol = hapd->eapol_auth;
242 struct eapol_state_machine *sm = sta->eapol_sm;
243
244 if (sm == NULL || !sm->eap_if->eapKeyData)
245 return;
246
247 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
248 MAC2STR(sta->addr));
249
250 #ifndef CONFIG_NO_VLAN
251 if (sta->vlan_id > 0) {
252 wpa_printf(MSG_ERROR, "Using WEP with vlans is not supported.");
253 return;
254 }
255 #endif /* CONFIG_NO_VLAN */
256
257 if (eapol->default_wep_key) {
258 ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
259 eapol->default_wep_key,
260 hapd->conf->default_wep_key_len);
261 }
262
263 if (hapd->conf->individual_wep_key_len > 0) {
264 u8 *ikey;
265 ikey = os_malloc(hapd->conf->individual_wep_key_len);
266 if (ikey == NULL ||
267 random_get_bytes(ikey, hapd->conf->individual_wep_key_len))
268 {
269 wpa_printf(MSG_ERROR, "Could not generate random "
270 "individual WEP key.");
271 os_free(ikey);
272 return;
273 }
274
275 wpa_hexdump_key(MSG_DEBUG, "Individual WEP key",
276 ikey, hapd->conf->individual_wep_key_len);
277
278 ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey,
279 hapd->conf->individual_wep_key_len);
280
281 /* TODO: set encryption in TX callback, i.e., only after STA
282 * has ACKed EAPOL-Key frame */
283 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
284 sta->addr, 0, 1, NULL, 0, ikey,
285 hapd->conf->individual_wep_key_len)) {
286 wpa_printf(MSG_ERROR, "Could not set individual WEP "
287 "encryption.");
288 }
289
290 os_free(ikey);
291 }
292 }
293
294 #endif /* CONFIG_NO_RC4 */
295 #endif /* CONFIG_FIPS */
296
297
298 const char *radius_mode_txt(struct hostapd_data *hapd)
299 {
300 switch (hapd->iface->conf->hw_mode) {
301 case HOSTAPD_MODE_IEEE80211AD:
302 return "802.11ad";
303 case HOSTAPD_MODE_IEEE80211A:
304 return "802.11a";
305 case HOSTAPD_MODE_IEEE80211G:
306 return "802.11g";
307 case HOSTAPD_MODE_IEEE80211B:
308 default:
309 return "802.11b";
310 }
311 }
312
313
314 int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
315 {
316 int i;
317 u8 rate = 0;
318
319 for (i = 0; i < sta->supported_rates_len; i++)
320 if ((sta->supported_rates[i] & 0x7f) > rate)
321 rate = sta->supported_rates[i] & 0x7f;
322
323 return rate;
324 }
325
326
327 #ifndef CONFIG_NO_RADIUS
328 static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
329 struct eapol_state_machine *sm,
330 const u8 *eap, size_t len)
331 {
332 const u8 *identity;
333 size_t identity_len;
334 const struct eap_hdr *hdr = (const struct eap_hdr *) eap;
335
336 if (len <= sizeof(struct eap_hdr) ||
337 (hdr->code == EAP_CODE_RESPONSE &&
338 eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY) ||
339 (hdr->code == EAP_CODE_INITIATE &&
340 eap[sizeof(struct eap_hdr)] != EAP_ERP_TYPE_REAUTH) ||
341 (hdr->code != EAP_CODE_RESPONSE &&
342 hdr->code != EAP_CODE_INITIATE))
343 return;
344
345 eap_erp_update_identity(sm->eap, eap, len);
346 identity = eap_get_identity(sm->eap, &identity_len);
347 if (identity == NULL)
348 return;
349
350 /* Save station identity for future RADIUS packets */
351 os_free(sm->identity);
352 sm->identity = (u8 *) dup_binstr(identity, identity_len);
353 if (sm->identity == NULL) {
354 sm->identity_len = 0;
355 return;
356 }
357
358 sm->identity_len = identity_len;
359 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
360 HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
361 sm->dot1xAuthEapolRespIdFramesRx++;
362 }
363
364
365 static int add_common_radius_sta_attr_rsn(struct hostapd_data *hapd,
366 struct hostapd_radius_attr *req_attr,
367 struct sta_info *sta,
368 struct radius_msg *msg)
369 {
370 u32 suite;
371 int ver, val;
372
373 ver = wpa_auth_sta_wpa_version(sta->wpa_sm);
374 val = wpa_auth_get_pairwise(sta->wpa_sm);
375 suite = wpa_cipher_to_suite(ver, val);
376 if (val != -1 &&
377 !hostapd_config_get_radius_attr(req_attr,
378 RADIUS_ATTR_WLAN_PAIRWISE_CIPHER) &&
379 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_PAIRWISE_CIPHER,
380 suite)) {
381 wpa_printf(MSG_ERROR, "Could not add WLAN-Pairwise-Cipher");
382 return -1;
383 }
384
385 suite = wpa_cipher_to_suite(((hapd->conf->wpa & 0x2) ||
386 hapd->conf->osen) ?
387 WPA_PROTO_RSN : WPA_PROTO_WPA,
388 hapd->conf->wpa_group);
389 if (!hostapd_config_get_radius_attr(req_attr,
390 RADIUS_ATTR_WLAN_GROUP_CIPHER) &&
391 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_GROUP_CIPHER,
392 suite)) {
393 wpa_printf(MSG_ERROR, "Could not add WLAN-Group-Cipher");
394 return -1;
395 }
396
397 val = wpa_auth_sta_key_mgmt(sta->wpa_sm);
398 suite = wpa_akm_to_suite(val);
399 if (val != -1 &&
400 !hostapd_config_get_radius_attr(req_attr,
401 RADIUS_ATTR_WLAN_AKM_SUITE) &&
402 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_AKM_SUITE,
403 suite)) {
404 wpa_printf(MSG_ERROR, "Could not add WLAN-AKM-Suite");
405 return -1;
406 }
407
408 #ifdef CONFIG_IEEE80211W
409 if (hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
410 suite = wpa_cipher_to_suite(WPA_PROTO_RSN,
411 hapd->conf->group_mgmt_cipher);
412 if (!hostapd_config_get_radius_attr(
413 req_attr, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER) &&
414 !radius_msg_add_attr_int32(
415 msg, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER, suite)) {
416 wpa_printf(MSG_ERROR,
417 "Could not add WLAN-Group-Mgmt-Cipher");
418 return -1;
419 }
420 }
421 #endif /* CONFIG_IEEE80211W */
422
423 return 0;
424 }
425
426
427 static int add_common_radius_sta_attr(struct hostapd_data *hapd,
428 struct hostapd_radius_attr *req_attr,
429 struct sta_info *sta,
430 struct radius_msg *msg)
431 {
432 char buf[128];
433
434 if (!hostapd_config_get_radius_attr(req_attr,
435 RADIUS_ATTR_SERVICE_TYPE) &&
436 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_SERVICE_TYPE,
437 RADIUS_SERVICE_TYPE_FRAMED)) {
438 wpa_printf(MSG_ERROR, "Could not add Service-Type");
439 return -1;
440 }
441
442 if (!hostapd_config_get_radius_attr(req_attr,
443 RADIUS_ATTR_NAS_PORT) &&
444 sta->aid > 0 &&
445 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) {
446 wpa_printf(MSG_ERROR, "Could not add NAS-Port");
447 return -1;
448 }
449
450 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
451 MAC2STR(sta->addr));
452 buf[sizeof(buf) - 1] = '\0';
453 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
454 (u8 *) buf, os_strlen(buf))) {
455 wpa_printf(MSG_ERROR, "Could not add Calling-Station-Id");
456 return -1;
457 }
458
459 if (sta->flags & WLAN_STA_PREAUTH) {
460 os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
461 sizeof(buf));
462 } else {
463 os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s",
464 radius_sta_rate(hapd, sta) / 2,
465 (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
466 radius_mode_txt(hapd));
467 buf[sizeof(buf) - 1] = '\0';
468 }
469 if (!hostapd_config_get_radius_attr(req_attr,
470 RADIUS_ATTR_CONNECT_INFO) &&
471 !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
472 (u8 *) buf, os_strlen(buf))) {
473 wpa_printf(MSG_ERROR, "Could not add Connect-Info");
474 return -1;
475 }
476
477 if (sta->acct_session_id) {
478 os_snprintf(buf, sizeof(buf), "%016llX",
479 (unsigned long long) sta->acct_session_id);
480 if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
481 (u8 *) buf, os_strlen(buf))) {
482 wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
483 return -1;
484 }
485 }
486
487 if ((hapd->conf->wpa & 2) &&
488 !hapd->conf->disable_pmksa_caching &&
489 sta->eapol_sm && sta->eapol_sm->acct_multi_session_id) {
490 os_snprintf(buf, sizeof(buf), "%016llX",
491 (unsigned long long)
492 sta->eapol_sm->acct_multi_session_id);
493 if (!radius_msg_add_attr(
494 msg, RADIUS_ATTR_ACCT_MULTI_SESSION_ID,
495 (u8 *) buf, os_strlen(buf))) {
496 wpa_printf(MSG_INFO,
497 "Could not add Acct-Multi-Session-Id");
498 return -1;
499 }
500 }
501
502 #ifdef CONFIG_IEEE80211R_AP
503 if (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
504 sta->wpa_sm &&
505 (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm)) ||
506 sta->auth_alg == WLAN_AUTH_FT) &&
507 !hostapd_config_get_radius_attr(req_attr,
508 RADIUS_ATTR_MOBILITY_DOMAIN_ID) &&
509 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_MOBILITY_DOMAIN_ID,
510 WPA_GET_BE16(
511 hapd->conf->mobility_domain))) {
512 wpa_printf(MSG_ERROR, "Could not add Mobility-Domain-Id");
513 return -1;
514 }
515 #endif /* CONFIG_IEEE80211R_AP */
516
517 if ((hapd->conf->wpa || hapd->conf->osen) && sta->wpa_sm &&
518 add_common_radius_sta_attr_rsn(hapd, req_attr, sta, msg) < 0)
519 return -1;
520
521 return 0;
522 }
523
524
525 int add_common_radius_attr(struct hostapd_data *hapd,
526 struct hostapd_radius_attr *req_attr,
527 struct sta_info *sta,
528 struct radius_msg *msg)
529 {
530 char buf[128];
531 struct hostapd_radius_attr *attr;
532 int len;
533
534 if (!hostapd_config_get_radius_attr(req_attr,
535 RADIUS_ATTR_NAS_IP_ADDRESS) &&
536 hapd->conf->own_ip_addr.af == AF_INET &&
537 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
538 (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) {
539 wpa_printf(MSG_ERROR, "Could not add NAS-IP-Address");
540 return -1;
541 }
542
543 #ifdef CONFIG_IPV6
544 if (!hostapd_config_get_radius_attr(req_attr,
545 RADIUS_ATTR_NAS_IPV6_ADDRESS) &&
546 hapd->conf->own_ip_addr.af == AF_INET6 &&
547 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS,
548 (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) {
549 wpa_printf(MSG_ERROR, "Could not add NAS-IPv6-Address");
550 return -1;
551 }
552 #endif /* CONFIG_IPV6 */
553
554 if (!hostapd_config_get_radius_attr(req_attr,
555 RADIUS_ATTR_NAS_IDENTIFIER) &&
556 hapd->conf->nas_identifier &&
557 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER,
558 (u8 *) hapd->conf->nas_identifier,
559 os_strlen(hapd->conf->nas_identifier))) {
560 wpa_printf(MSG_ERROR, "Could not add NAS-Identifier");
561 return -1;
562 }
563
564 len = os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":",
565 MAC2STR(hapd->own_addr));
566 os_memcpy(&buf[len], hapd->conf->ssid.ssid,
567 hapd->conf->ssid.ssid_len);
568 len += hapd->conf->ssid.ssid_len;
569 if (!hostapd_config_get_radius_attr(req_attr,
570 RADIUS_ATTR_CALLED_STATION_ID) &&
571 !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
572 (u8 *) buf, len)) {
573 wpa_printf(MSG_ERROR, "Could not add Called-Station-Id");
574 return -1;
575 }
576
577 if (!hostapd_config_get_radius_attr(req_attr,
578 RADIUS_ATTR_NAS_PORT_TYPE) &&
579 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
580 RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
581 wpa_printf(MSG_ERROR, "Could not add NAS-Port-Type");
582 return -1;
583 }
584
585 #ifdef CONFIG_INTERWORKING
586 if (hapd->conf->interworking &&
587 !is_zero_ether_addr(hapd->conf->hessid)) {
588 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
589 MAC2STR(hapd->conf->hessid));
590 buf[sizeof(buf) - 1] = '\0';
591 if (!hostapd_config_get_radius_attr(req_attr,
592 RADIUS_ATTR_WLAN_HESSID) &&
593 !radius_msg_add_attr(msg, RADIUS_ATTR_WLAN_HESSID,
594 (u8 *) buf, os_strlen(buf))) {
595 wpa_printf(MSG_ERROR, "Could not add WLAN-HESSID");
596 return -1;
597 }
598 }
599 #endif /* CONFIG_INTERWORKING */
600
601 if (sta && add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0)
602 return -1;
603
604 for (attr = req_attr; attr; attr = attr->next) {
605 if (!radius_msg_add_attr(msg, attr->type,
606 wpabuf_head(attr->val),
607 wpabuf_len(attr->val))) {
608 wpa_printf(MSG_ERROR, "Could not add RADIUS "
609 "attribute");
610 return -1;
611 }
612 }
613
614 return 0;
615 }
616
617
618 void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
619 struct sta_info *sta,
620 const u8 *eap, size_t len)
621 {
622 struct radius_msg *msg;
623 struct eapol_state_machine *sm = sta->eapol_sm;
624
625 if (sm == NULL)
626 return;
627
628 ieee802_1x_learn_identity(hapd, sm, eap, len);
629
630 wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
631 "packet");
632
633 sm->radius_identifier = radius_client_get_id(hapd->radius);
634 msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
635 sm->radius_identifier);
636 if (msg == NULL) {
637 wpa_printf(MSG_INFO, "Could not create new RADIUS packet");
638 return;
639 }
640
641 if (radius_msg_make_authenticator(msg) < 0) {
642 wpa_printf(MSG_INFO, "Could not make Request Authenticator");
643 goto fail;
644 }
645
646 if (sm->identity &&
647 !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
648 sm->identity, sm->identity_len)) {
649 wpa_printf(MSG_INFO, "Could not add User-Name");
650 goto fail;
651 }
652
653 if (add_common_radius_attr(hapd, hapd->conf->radius_auth_req_attr, sta,
654 msg) < 0)
655 goto fail;
656
657 /* TODO: should probably check MTU from driver config; 2304 is max for
658 * IEEE 802.11, but use 1400 to avoid problems with too large packets
659 */
660 if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
661 RADIUS_ATTR_FRAMED_MTU) &&
662 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
663 wpa_printf(MSG_INFO, "Could not add Framed-MTU");
664 goto fail;
665 }
666
667 if (!radius_msg_add_eap(msg, eap, len)) {
668 wpa_printf(MSG_INFO, "Could not add EAP-Message");
669 goto fail;
670 }
671
672 /* State attribute must be copied if and only if this packet is
673 * Access-Request reply to the previous Access-Challenge */
674 if (sm->last_recv_radius &&
675 radius_msg_get_hdr(sm->last_recv_radius)->code ==
676 RADIUS_CODE_ACCESS_CHALLENGE) {
677 int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
678 RADIUS_ATTR_STATE);
679 if (res < 0) {
680 wpa_printf(MSG_INFO, "Could not copy State attribute from previous Access-Challenge");
681 goto fail;
682 }
683 if (res > 0) {
684 wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute");
685 }
686 }
687
688 if (hapd->conf->radius_request_cui) {
689 const u8 *cui;
690 size_t cui_len;
691 /* Add previously learned CUI or nul CUI to request CUI */
692 if (sm->radius_cui) {
693 cui = wpabuf_head(sm->radius_cui);
694 cui_len = wpabuf_len(sm->radius_cui);
695 } else {
696 cui = (const u8 *) "\0";
697 cui_len = 1;
698 }
699 if (!radius_msg_add_attr(msg,
700 RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
701 cui, cui_len)) {
702 wpa_printf(MSG_ERROR, "Could not add CUI");
703 goto fail;
704 }
705 }
706
707 #ifdef CONFIG_HS20
708 if (hapd->conf->hs20) {
709 u8 ver = hapd->conf->hs20_release - 1;
710
711 if (!radius_msg_add_wfa(
712 msg, RADIUS_VENDOR_ATTR_WFA_HS20_AP_VERSION,
713 &ver, 1)) {
714 wpa_printf(MSG_ERROR, "Could not add HS 2.0 AP "
715 "version");
716 goto fail;
717 }
718
719 if (sta->hs20_ie && wpabuf_len(sta->hs20_ie) > 0) {
720 const u8 *pos;
721 u8 buf[3];
722 u16 id;
723 pos = wpabuf_head_u8(sta->hs20_ie);
724 buf[0] = (*pos) >> 4;
725 if (((*pos) & HS20_PPS_MO_ID_PRESENT) &&
726 wpabuf_len(sta->hs20_ie) >= 3)
727 id = WPA_GET_LE16(pos + 1);
728 else
729 id = 0;
730 WPA_PUT_BE16(buf + 1, id);
731 if (!radius_msg_add_wfa(
732 msg,
733 RADIUS_VENDOR_ATTR_WFA_HS20_STA_VERSION,
734 buf, sizeof(buf))) {
735 wpa_printf(MSG_ERROR, "Could not add HS 2.0 "
736 "STA version");
737 goto fail;
738 }
739 }
740
741 if (sta->roaming_consortium &&
742 !radius_msg_add_wfa(
743 msg, RADIUS_VENDOR_ATTR_WFA_HS20_ROAMING_CONSORTIUM,
744 wpabuf_head(sta->roaming_consortium),
745 wpabuf_len(sta->roaming_consortium))) {
746 wpa_printf(MSG_ERROR,
747 "Could not add HS 2.0 Roaming Consortium");
748 goto fail;
749 }
750
751 if (hapd->conf->t_c_filename) {
752 be32 timestamp;
753
754 if (!radius_msg_add_wfa(
755 msg,
756 RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILENAME,
757 (const u8 *) hapd->conf->t_c_filename,
758 os_strlen(hapd->conf->t_c_filename))) {
759 wpa_printf(MSG_ERROR,
760 "Could not add HS 2.0 T&C Filename");
761 goto fail;
762 }
763
764 timestamp = host_to_be32(hapd->conf->t_c_timestamp);
765 if (!radius_msg_add_wfa(
766 msg,
767 RADIUS_VENDOR_ATTR_WFA_HS20_TIMESTAMP,
768 (const u8 *) &timestamp,
769 sizeof(timestamp))) {
770 wpa_printf(MSG_ERROR,
771 "Could not add HS 2.0 Timestamp");
772 goto fail;
773 }
774 }
775 }
776 #endif /* CONFIG_HS20 */
777
778 if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr) < 0)
779 goto fail;
780
781 return;
782
783 fail:
784 radius_msg_free(msg);
785 }
786 #endif /* CONFIG_NO_RADIUS */
787
788
789 static void handle_eap_response(struct hostapd_data *hapd,
790 struct sta_info *sta, struct eap_hdr *eap,
791 size_t len)
792 {
793 u8 type, *data;
794 struct eapol_state_machine *sm = sta->eapol_sm;
795 if (sm == NULL)
796 return;
797
798 data = (u8 *) (eap + 1);
799
800 if (len < sizeof(*eap) + 1) {
801 wpa_printf(MSG_INFO, "handle_eap_response: too short response data");
802 return;
803 }
804
805 sm->eap_type_supp = type = data[0];
806
807 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
808 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
809 "id=%d len=%d) from STA: EAP Response-%s (%d)",
810 eap->code, eap->identifier, be_to_host16(eap->length),
811 eap_server_get_name(0, type), type);
812
813 sm->dot1xAuthEapolRespFramesRx++;
814
815 wpabuf_free(sm->eap_if->eapRespData);
816 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
817 sm->eapolEap = TRUE;
818 }
819
820
821 static void handle_eap_initiate(struct hostapd_data *hapd,
822 struct sta_info *sta, struct eap_hdr *eap,
823 size_t len)
824 {
825 #ifdef CONFIG_ERP
826 u8 type, *data;
827 struct eapol_state_machine *sm = sta->eapol_sm;
828
829 if (sm == NULL)
830 return;
831
832 if (len < sizeof(*eap) + 1) {
833 wpa_printf(MSG_INFO,
834 "handle_eap_initiate: too short response data");
835 return;
836 }
837
838 data = (u8 *) (eap + 1);
839 type = data[0];
840
841 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
842 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
843 "id=%d len=%d) from STA: EAP Initiate type %u",
844 eap->code, eap->identifier, be_to_host16(eap->length),
845 type);
846
847 wpabuf_free(sm->eap_if->eapRespData);
848 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
849 sm->eapolEap = TRUE;
850 #endif /* CONFIG_ERP */
851 }
852
853
854 /* Process incoming EAP packet from Supplicant */
855 static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
856 u8 *buf, size_t len)
857 {
858 struct eap_hdr *eap;
859 u16 eap_len;
860
861 if (len < sizeof(*eap)) {
862 wpa_printf(MSG_INFO, " too short EAP packet");
863 return;
864 }
865
866 eap = (struct eap_hdr *) buf;
867
868 eap_len = be_to_host16(eap->length);
869 wpa_printf(MSG_DEBUG, "EAP: code=%d identifier=%d length=%d",
870 eap->code, eap->identifier, eap_len);
871 if (eap_len < sizeof(*eap)) {
872 wpa_printf(MSG_DEBUG, " Invalid EAP length");
873 return;
874 } else if (eap_len > len) {
875 wpa_printf(MSG_DEBUG, " Too short frame to contain this EAP "
876 "packet");
877 return;
878 } else if (eap_len < len) {
879 wpa_printf(MSG_DEBUG, " Ignoring %lu extra bytes after EAP "
880 "packet", (unsigned long) len - eap_len);
881 }
882
883 switch (eap->code) {
884 case EAP_CODE_REQUEST:
885 wpa_printf(MSG_DEBUG, " (request)");
886 return;
887 case EAP_CODE_RESPONSE:
888 wpa_printf(MSG_DEBUG, " (response)");
889 handle_eap_response(hapd, sta, eap, eap_len);
890 break;
891 case EAP_CODE_SUCCESS:
892 wpa_printf(MSG_DEBUG, " (success)");
893 return;
894 case EAP_CODE_FAILURE:
895 wpa_printf(MSG_DEBUG, " (failure)");
896 return;
897 case EAP_CODE_INITIATE:
898 wpa_printf(MSG_DEBUG, " (initiate)");
899 handle_eap_initiate(hapd, sta, eap, eap_len);
900 break;
901 case EAP_CODE_FINISH:
902 wpa_printf(MSG_DEBUG, " (finish)");
903 break;
904 default:
905 wpa_printf(MSG_DEBUG, " (unknown code)");
906 return;
907 }
908 }
909
910
911 struct eapol_state_machine *
912 ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta)
913 {
914 int flags = 0;
915 if (sta->flags & WLAN_STA_PREAUTH)
916 flags |= EAPOL_SM_PREAUTH;
917 if (sta->wpa_sm) {
918 flags |= EAPOL_SM_USES_WPA;
919 if (wpa_auth_sta_get_pmksa(sta->wpa_sm))
920 flags |= EAPOL_SM_FROM_PMKSA_CACHE;
921 }
922 return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags,
923 sta->wps_ie, sta->p2p_ie, sta,
924 sta->identity, sta->radius_cui);
925 }
926
927
928 static void ieee802_1x_save_eapol(struct sta_info *sta, const u8 *buf,
929 size_t len)
930 {
931 if (sta->pending_eapol_rx) {
932 wpabuf_free(sta->pending_eapol_rx->buf);
933 } else {
934 sta->pending_eapol_rx =
935 os_malloc(sizeof(*sta->pending_eapol_rx));
936 if (!sta->pending_eapol_rx)
937 return;
938 }
939
940 sta->pending_eapol_rx->buf = wpabuf_alloc_copy(buf, len);
941 if (!sta->pending_eapol_rx->buf) {
942 os_free(sta->pending_eapol_rx);
943 sta->pending_eapol_rx = NULL;
944 return;
945 }
946
947 os_get_reltime(&sta->pending_eapol_rx->rx_time);
948 }
949
950
951 /**
952 * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
953 * @hapd: hostapd BSS data
954 * @sa: Source address (sender of the EAPOL frame)
955 * @buf: EAPOL frame
956 * @len: Length of buf in octets
957 *
958 * This function is called for each incoming EAPOL frame from the interface
959 */
960 void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
961 size_t len)
962 {
963 struct sta_info *sta;
964 struct ieee802_1x_hdr *hdr;
965 struct ieee802_1x_eapol_key *key;
966 u16 datalen;
967 struct rsn_pmksa_cache_entry *pmksa;
968 int key_mgmt;
969
970 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen &&
971 !hapd->conf->wps_state)
972 return;
973
974 wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
975 (unsigned long) len, MAC2STR(sa));
976 sta = ap_get_sta(hapd, sa);
977 if (!sta || (!(sta->flags & (WLAN_STA_ASSOC | WLAN_STA_PREAUTH)) &&
978 !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED))) {
979 wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
980 "associated/Pre-authenticating STA");
981
982 if (sta && (sta->flags & WLAN_STA_AUTH)) {
983 wpa_printf(MSG_DEBUG, "Saving EAPOL frame from " MACSTR
984 " for later use", MAC2STR(sta->addr));
985 ieee802_1x_save_eapol(sta, buf, len);
986 }
987
988 return;
989 }
990
991 if (len < sizeof(*hdr)) {
992 wpa_printf(MSG_INFO, " too short IEEE 802.1X packet");
993 return;
994 }
995
996 hdr = (struct ieee802_1x_hdr *) buf;
997 datalen = be_to_host16(hdr->length);
998 wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d",
999 hdr->version, hdr->type, datalen);
1000
1001 if (len - sizeof(*hdr) < datalen) {
1002 wpa_printf(MSG_INFO, " frame too short for this IEEE 802.1X packet");
1003 if (sta->eapol_sm)
1004 sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++;
1005 return;
1006 }
1007 if (len - sizeof(*hdr) > datalen) {
1008 wpa_printf(MSG_DEBUG, " ignoring %lu extra octets after "
1009 "IEEE 802.1X packet",
1010 (unsigned long) len - sizeof(*hdr) - datalen);
1011 }
1012
1013 if (sta->eapol_sm) {
1014 sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version;
1015 sta->eapol_sm->dot1xAuthEapolFramesRx++;
1016 }
1017
1018 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
1019 if (datalen >= sizeof(struct ieee802_1x_eapol_key) &&
1020 hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
1021 (key->type == EAPOL_KEY_TYPE_WPA ||
1022 key->type == EAPOL_KEY_TYPE_RSN)) {
1023 wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr,
1024 sizeof(*hdr) + datalen);
1025 return;
1026 }
1027
1028 if (!hapd->conf->ieee802_1x && !hapd->conf->osen &&
1029 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
1030 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
1031 "802.1X not enabled and WPS not used");
1032 return;
1033 }
1034
1035 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
1036 if (key_mgmt != -1 &&
1037 (wpa_key_mgmt_wpa_psk(key_mgmt) || key_mgmt == WPA_KEY_MGMT_OWE ||
1038 key_mgmt == WPA_KEY_MGMT_DPP)) {
1039 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
1040 "STA is using PSK");
1041 return;
1042 }
1043
1044 if (!sta->eapol_sm) {
1045 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
1046 if (!sta->eapol_sm)
1047 return;
1048
1049 #ifdef CONFIG_WPS
1050 if (!hapd->conf->ieee802_1x && hapd->conf->wps_state) {
1051 u32 wflags = sta->flags & (WLAN_STA_WPS |
1052 WLAN_STA_WPS2 |
1053 WLAN_STA_MAYBE_WPS);
1054 if (wflags == WLAN_STA_MAYBE_WPS ||
1055 wflags == (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) {
1056 /*
1057 * Delay EAPOL frame transmission until a
1058 * possible WPS STA initiates the handshake
1059 * with EAPOL-Start. Only allow the wait to be
1060 * skipped if the STA is known to support WPS
1061 * 2.0.
1062 */
1063 wpa_printf(MSG_DEBUG, "WPS: Do not start "
1064 "EAPOL until EAPOL-Start is "
1065 "received");
1066 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
1067 }
1068 }
1069 #endif /* CONFIG_WPS */
1070
1071 sta->eapol_sm->eap_if->portEnabled = TRUE;
1072 }
1073
1074 /* since we support version 1, we can ignore version field and proceed
1075 * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
1076 /* TODO: actually, we are not version 1 anymore.. However, Version 2
1077 * does not change frame contents, so should be ok to process frames
1078 * more or less identically. Some changes might be needed for
1079 * verification of fields. */
1080
1081 switch (hdr->type) {
1082 case IEEE802_1X_TYPE_EAP_PACKET:
1083 handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen);
1084 break;
1085
1086 case IEEE802_1X_TYPE_EAPOL_START:
1087 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1088 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Start "
1089 "from STA");
1090 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
1091 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1092 if (pmksa) {
1093 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
1094 HOSTAPD_LEVEL_DEBUG, "cached PMKSA "
1095 "available - ignore it since "
1096 "STA sent EAPOL-Start");
1097 wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa);
1098 }
1099 sta->eapol_sm->eapolStart = TRUE;
1100 sta->eapol_sm->dot1xAuthEapolStartFramesRx++;
1101 eap_server_clear_identity(sta->eapol_sm->eap);
1102 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
1103 break;
1104
1105 case IEEE802_1X_TYPE_EAPOL_LOGOFF:
1106 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1107 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Logoff "
1108 "from STA");
1109 sta->acct_terminate_cause =
1110 RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1111 accounting_sta_stop(hapd, sta);
1112 sta->eapol_sm->eapolLogoff = TRUE;
1113 sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
1114 eap_server_clear_identity(sta->eapol_sm->eap);
1115 break;
1116
1117 case IEEE802_1X_TYPE_EAPOL_KEY:
1118 wpa_printf(MSG_DEBUG, " EAPOL-Key");
1119 if (!ap_sta_is_authorized(sta)) {
1120 wpa_printf(MSG_DEBUG, " Dropped key data from "
1121 "unauthorized Supplicant");
1122 break;
1123 }
1124 break;
1125
1126 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
1127 wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert");
1128 /* TODO: implement support for this; show data */
1129 break;
1130
1131 #ifdef CONFIG_MACSEC
1132 case IEEE802_1X_TYPE_EAPOL_MKA:
1133 wpa_printf(MSG_EXCESSIVE,
1134 "EAPOL type %d will be handled by MKA", hdr->type);
1135 break;
1136 #endif /* CONFIG_MACSEC */
1137
1138 default:
1139 wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type");
1140 sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++;
1141 break;
1142 }
1143
1144 eapol_auth_step(sta->eapol_sm);
1145 }
1146
1147
1148 /**
1149 * ieee802_1x_new_station - Start IEEE 802.1X authentication
1150 * @hapd: hostapd BSS data
1151 * @sta: The station
1152 *
1153 * This function is called to start IEEE 802.1X authentication when a new
1154 * station completes IEEE 802.11 association.
1155 */
1156 void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
1157 {
1158 struct rsn_pmksa_cache_entry *pmksa;
1159 int reassoc = 1;
1160 int force_1x = 0;
1161 int key_mgmt;
1162
1163 #ifdef CONFIG_WPS
1164 if (hapd->conf->wps_state &&
1165 ((hapd->conf->wpa && (sta->flags & WLAN_STA_MAYBE_WPS)) ||
1166 (sta->flags & WLAN_STA_WPS))) {
1167 /*
1168 * Need to enable IEEE 802.1X/EAPOL state machines for possible
1169 * WPS handshake even if IEEE 802.1X/EAPOL is not used for
1170 * authentication in this BSS.
1171 */
1172 force_1x = 1;
1173 }
1174 #endif /* CONFIG_WPS */
1175
1176 if (!force_1x && !hapd->conf->ieee802_1x && !hapd->conf->osen) {
1177 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - "
1178 "802.1X not enabled or forced for WPS");
1179 /*
1180 * Clear any possible EAPOL authenticator state to support
1181 * reassociation change from WPS to PSK.
1182 */
1183 ieee802_1x_free_station(hapd, sta);
1184 return;
1185 }
1186
1187 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
1188 if (key_mgmt != -1 &&
1189 (wpa_key_mgmt_wpa_psk(key_mgmt) || key_mgmt == WPA_KEY_MGMT_OWE ||
1190 key_mgmt == WPA_KEY_MGMT_DPP)) {
1191 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - using PSK");
1192 /*
1193 * Clear any possible EAPOL authenticator state to support
1194 * reassociation change from WPA-EAP to PSK.
1195 */
1196 ieee802_1x_free_station(hapd, sta);
1197 return;
1198 }
1199
1200 if (sta->eapol_sm == NULL) {
1201 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1202 HOSTAPD_LEVEL_DEBUG, "start authentication");
1203 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
1204 if (sta->eapol_sm == NULL) {
1205 hostapd_logger(hapd, sta->addr,
1206 HOSTAPD_MODULE_IEEE8021X,
1207 HOSTAPD_LEVEL_INFO,
1208 "failed to allocate state machine");
1209 return;
1210 }
1211 reassoc = 0;
1212 }
1213
1214 #ifdef CONFIG_WPS
1215 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
1216 if (!hapd->conf->ieee802_1x && hapd->conf->wps_state &&
1217 !(sta->flags & WLAN_STA_WPS2)) {
1218 /*
1219 * Delay EAPOL frame transmission until a possible WPS STA
1220 * initiates the handshake with EAPOL-Start. Only allow the
1221 * wait to be skipped if the STA is known to support WPS 2.0.
1222 */
1223 wpa_printf(MSG_DEBUG, "WPS: Do not start EAPOL until "
1224 "EAPOL-Start is received");
1225 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
1226 }
1227 #endif /* CONFIG_WPS */
1228
1229 sta->eapol_sm->eap_if->portEnabled = TRUE;
1230
1231 #ifdef CONFIG_IEEE80211R_AP
1232 if (sta->auth_alg == WLAN_AUTH_FT) {
1233 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1234 HOSTAPD_LEVEL_DEBUG,
1235 "PMK from FT - skip IEEE 802.1X/EAP");
1236 /* Setup EAPOL state machines to already authenticated state
1237 * because of existing FT information from R0KH. */
1238 sta->eapol_sm->keyRun = TRUE;
1239 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1240 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1241 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1242 sta->eapol_sm->authSuccess = TRUE;
1243 sta->eapol_sm->authFail = FALSE;
1244 sta->eapol_sm->portValid = TRUE;
1245 if (sta->eapol_sm->eap)
1246 eap_sm_notify_cached(sta->eapol_sm->eap);
1247 ap_sta_bind_vlan(hapd, sta);
1248 return;
1249 }
1250 #endif /* CONFIG_IEEE80211R_AP */
1251
1252 #ifdef CONFIG_FILS
1253 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
1254 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
1255 sta->auth_alg == WLAN_AUTH_FILS_PK) {
1256 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1257 HOSTAPD_LEVEL_DEBUG,
1258 "PMK from FILS - skip IEEE 802.1X/EAP");
1259 /* Setup EAPOL state machines to already authenticated state
1260 * because of existing FILS information. */
1261 sta->eapol_sm->keyRun = TRUE;
1262 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1263 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1264 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1265 sta->eapol_sm->authSuccess = TRUE;
1266 sta->eapol_sm->authFail = FALSE;
1267 sta->eapol_sm->portValid = TRUE;
1268 if (sta->eapol_sm->eap)
1269 eap_sm_notify_cached(sta->eapol_sm->eap);
1270 wpa_auth_set_ptk_rekey_timer(sta->wpa_sm);
1271 return;
1272 }
1273 #endif /* CONFIG_FILS */
1274
1275 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1276 if (pmksa) {
1277 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1278 HOSTAPD_LEVEL_DEBUG,
1279 "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
1280 /* Setup EAPOL state machines to already authenticated state
1281 * because of existing PMKSA information in the cache. */
1282 sta->eapol_sm->keyRun = TRUE;
1283 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1284 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1285 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1286 sta->eapol_sm->authSuccess = TRUE;
1287 sta->eapol_sm->authFail = FALSE;
1288 if (sta->eapol_sm->eap)
1289 eap_sm_notify_cached(sta->eapol_sm->eap);
1290 pmksa_cache_to_eapol_data(hapd, pmksa, sta->eapol_sm);
1291 ap_sta_bind_vlan(hapd, sta);
1292 } else {
1293 if (reassoc) {
1294 /*
1295 * Force EAPOL state machines to start
1296 * re-authentication without having to wait for the
1297 * Supplicant to send EAPOL-Start.
1298 */
1299 sta->eapol_sm->reAuthenticate = TRUE;
1300 }
1301 eapol_auth_step(sta->eapol_sm);
1302 }
1303 }
1304
1305
1306 void ieee802_1x_free_station(struct hostapd_data *hapd, struct sta_info *sta)
1307 {
1308 struct eapol_state_machine *sm = sta->eapol_sm;
1309
1310 #ifdef CONFIG_HS20
1311 eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta);
1312 #endif /* CONFIG_HS20 */
1313
1314 if (sta->pending_eapol_rx) {
1315 wpabuf_free(sta->pending_eapol_rx->buf);
1316 os_free(sta->pending_eapol_rx);
1317 sta->pending_eapol_rx = NULL;
1318 }
1319
1320 if (sm == NULL)
1321 return;
1322
1323 sta->eapol_sm = NULL;
1324
1325 #ifndef CONFIG_NO_RADIUS
1326 radius_msg_free(sm->last_recv_radius);
1327 radius_free_class(&sm->radius_class);
1328 #endif /* CONFIG_NO_RADIUS */
1329
1330 eapol_auth_free(sm);
1331 }
1332
1333
1334 #ifndef CONFIG_NO_RADIUS
1335 static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
1336 struct sta_info *sta)
1337 {
1338 struct wpabuf *eap;
1339 const struct eap_hdr *hdr;
1340 int eap_type = -1;
1341 char buf[64];
1342 struct radius_msg *msg;
1343 struct eapol_state_machine *sm = sta->eapol_sm;
1344
1345 if (sm == NULL || sm->last_recv_radius == NULL) {
1346 if (sm)
1347 sm->eap_if->aaaEapNoReq = TRUE;
1348 return;
1349 }
1350
1351 msg = sm->last_recv_radius;
1352
1353 eap = radius_msg_get_eap(msg);
1354 if (eap == NULL) {
1355 /* RFC 3579, Chap. 2.6.3:
1356 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
1357 * attribute */
1358 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1359 HOSTAPD_LEVEL_WARNING, "could not extract "
1360 "EAP-Message from RADIUS message");
1361 sm->eap_if->aaaEapNoReq = TRUE;
1362 return;
1363 }
1364
1365 if (wpabuf_len(eap) < sizeof(*hdr)) {
1366 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1367 HOSTAPD_LEVEL_WARNING, "too short EAP packet "
1368 "received from authentication server");
1369 wpabuf_free(eap);
1370 sm->eap_if->aaaEapNoReq = TRUE;
1371 return;
1372 }
1373
1374 if (wpabuf_len(eap) > sizeof(*hdr))
1375 eap_type = (wpabuf_head_u8(eap))[sizeof(*hdr)];
1376
1377 hdr = wpabuf_head(eap);
1378 switch (hdr->code) {
1379 case EAP_CODE_REQUEST:
1380 if (eap_type >= 0)
1381 sm->eap_type_authsrv = eap_type;
1382 os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
1383 eap_server_get_name(0, eap_type), eap_type);
1384 break;
1385 case EAP_CODE_RESPONSE:
1386 os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
1387 eap_server_get_name(0, eap_type), eap_type);
1388 break;
1389 case EAP_CODE_SUCCESS:
1390 os_strlcpy(buf, "EAP Success", sizeof(buf));
1391 break;
1392 case EAP_CODE_FAILURE:
1393 os_strlcpy(buf, "EAP Failure", sizeof(buf));
1394 break;
1395 default:
1396 os_strlcpy(buf, "unknown EAP code", sizeof(buf));
1397 break;
1398 }
1399 buf[sizeof(buf) - 1] = '\0';
1400 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1401 HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
1402 "id=%d len=%d) from RADIUS server: %s",
1403 hdr->code, hdr->identifier, be_to_host16(hdr->length),
1404 buf);
1405 sm->eap_if->aaaEapReq = TRUE;
1406
1407 wpabuf_free(sm->eap_if->aaaEapReqData);
1408 sm->eap_if->aaaEapReqData = eap;
1409 }
1410
1411
1412 static void ieee802_1x_get_keys(struct hostapd_data *hapd,
1413 struct sta_info *sta, struct radius_msg *msg,
1414 struct radius_msg *req,
1415 const u8 *shared_secret,
1416 size_t shared_secret_len)
1417 {
1418 struct radius_ms_mppe_keys *keys;
1419 u8 *buf;
1420 size_t len;
1421 struct eapol_state_machine *sm = sta->eapol_sm;
1422 if (sm == NULL)
1423 return;
1424
1425 keys = radius_msg_get_ms_keys(msg, req, shared_secret,
1426 shared_secret_len);
1427
1428 if (keys && keys->send && keys->recv) {
1429 size_t len = keys->send_len + keys->recv_len;
1430 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
1431 keys->send, keys->send_len);
1432 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
1433 keys->recv, keys->recv_len);
1434
1435 os_free(sm->eap_if->aaaEapKeyData);
1436 sm->eap_if->aaaEapKeyData = os_malloc(len);
1437 if (sm->eap_if->aaaEapKeyData) {
1438 os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv,
1439 keys->recv_len);
1440 os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len,
1441 keys->send, keys->send_len);
1442 sm->eap_if->aaaEapKeyDataLen = len;
1443 sm->eap_if->aaaEapKeyAvailable = TRUE;
1444 }
1445 } else {
1446 wpa_printf(MSG_DEBUG,
1447 "MS-MPPE: 1x_get_keys, could not get keys: %p send: %p recv: %p",
1448 keys, keys ? keys->send : NULL,
1449 keys ? keys->recv : NULL);
1450 }
1451
1452 if (keys) {
1453 os_free(keys->send);
1454 os_free(keys->recv);
1455 os_free(keys);
1456 }
1457
1458 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_EAP_KEY_NAME, &buf, &len,
1459 NULL) == 0) {
1460 os_free(sm->eap_if->eapSessionId);
1461 sm->eap_if->eapSessionId = os_memdup(buf, len);
1462 if (sm->eap_if->eapSessionId) {
1463 sm->eap_if->eapSessionIdLen = len;
1464 wpa_hexdump(MSG_DEBUG, "EAP-Key Name",
1465 sm->eap_if->eapSessionId,
1466 sm->eap_if->eapSessionIdLen);
1467 }
1468 } else {
1469 sm->eap_if->eapSessionIdLen = 0;
1470 }
1471 }
1472
1473
1474 static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
1475 struct sta_info *sta,
1476 struct radius_msg *msg)
1477 {
1478 u8 *attr_class;
1479 size_t class_len;
1480 struct eapol_state_machine *sm = sta->eapol_sm;
1481 int count, i;
1482 struct radius_attr_data *nclass;
1483 size_t nclass_count;
1484
1485 if (!hapd->conf->radius->acct_server || hapd->radius == NULL ||
1486 sm == NULL)
1487 return;
1488
1489 radius_free_class(&sm->radius_class);
1490 count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
1491 if (count <= 0)
1492 return;
1493
1494 nclass = os_calloc(count, sizeof(struct radius_attr_data));
1495 if (nclass == NULL)
1496 return;
1497
1498 nclass_count = 0;
1499
1500 attr_class = NULL;
1501 for (i = 0; i < count; i++) {
1502 do {
1503 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS,
1504 &attr_class, &class_len,
1505 attr_class) < 0) {
1506 i = count;
1507 break;
1508 }
1509 } while (class_len < 1);
1510
1511 nclass[nclass_count].data = os_memdup(attr_class, class_len);
1512 if (nclass[nclass_count].data == NULL)
1513 break;
1514
1515 nclass[nclass_count].len = class_len;
1516 nclass_count++;
1517 }
1518
1519 sm->radius_class.attr = nclass;
1520 sm->radius_class.count = nclass_count;
1521 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Stored %lu RADIUS Class "
1522 "attributes for " MACSTR,
1523 (unsigned long) sm->radius_class.count,
1524 MAC2STR(sta->addr));
1525 }
1526
1527
1528 /* Update sta->identity based on User-Name attribute in Access-Accept */
1529 static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
1530 struct sta_info *sta,
1531 struct radius_msg *msg)
1532 {
1533 u8 *buf, *identity;
1534 size_t len;
1535 struct eapol_state_machine *sm = sta->eapol_sm;
1536
1537 if (sm == NULL)
1538 return;
1539
1540 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len,
1541 NULL) < 0)
1542 return;
1543
1544 identity = (u8 *) dup_binstr(buf, len);
1545 if (identity == NULL)
1546 return;
1547
1548 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1549 HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
1550 "User-Name from Access-Accept '%s'",
1551 sm->identity ? (char *) sm->identity : "N/A",
1552 (char *) identity);
1553
1554 os_free(sm->identity);
1555 sm->identity = identity;
1556 sm->identity_len = len;
1557 }
1558
1559
1560 /* Update CUI based on Chargeable-User-Identity attribute in Access-Accept */
1561 static void ieee802_1x_update_sta_cui(struct hostapd_data *hapd,
1562 struct sta_info *sta,
1563 struct radius_msg *msg)
1564 {
1565 struct eapol_state_machine *sm = sta->eapol_sm;
1566 struct wpabuf *cui;
1567 u8 *buf;
1568 size_t len;
1569
1570 if (sm == NULL)
1571 return;
1572
1573 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
1574 &buf, &len, NULL) < 0)
1575 return;
1576
1577 cui = wpabuf_alloc_copy(buf, len);
1578 if (cui == NULL)
1579 return;
1580
1581 wpabuf_free(sm->radius_cui);
1582 sm->radius_cui = cui;
1583 }
1584
1585
1586 #ifdef CONFIG_HS20
1587
1588 static void ieee802_1x_hs20_sub_rem(struct sta_info *sta, u8 *pos, size_t len)
1589 {
1590 sta->remediation = 1;
1591 os_free(sta->remediation_url);
1592 if (len > 2) {
1593 sta->remediation_url = os_malloc(len);
1594 if (!sta->remediation_url)
1595 return;
1596 sta->remediation_method = pos[0];
1597 os_memcpy(sta->remediation_url, pos + 1, len - 1);
1598 sta->remediation_url[len - 1] = '\0';
1599 wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
1600 "for " MACSTR " - server method %u URL %s",
1601 MAC2STR(sta->addr), sta->remediation_method,
1602 sta->remediation_url);
1603 } else {
1604 sta->remediation_url = NULL;
1605 wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
1606 "for " MACSTR, MAC2STR(sta->addr));
1607 }
1608 /* TODO: assign the STA into remediation VLAN or add filtering */
1609 }
1610
1611
1612 static void ieee802_1x_hs20_deauth_req(struct hostapd_data *hapd,
1613 struct sta_info *sta, u8 *pos,
1614 size_t len)
1615 {
1616 if (len < 3)
1617 return; /* Malformed information */
1618 sta->hs20_deauth_requested = 1;
1619 wpa_printf(MSG_DEBUG, "HS 2.0: Deauthentication request - Code %u "
1620 "Re-auth Delay %u",
1621 *pos, WPA_GET_LE16(pos + 1));
1622 wpabuf_free(sta->hs20_deauth_req);
1623 sta->hs20_deauth_req = wpabuf_alloc(len + 1);
1624 if (sta->hs20_deauth_req) {
1625 wpabuf_put_data(sta->hs20_deauth_req, pos, 3);
1626 wpabuf_put_u8(sta->hs20_deauth_req, len - 3);
1627 wpabuf_put_data(sta->hs20_deauth_req, pos + 3, len - 3);
1628 }
1629 ap_sta_session_timeout(hapd, sta, hapd->conf->hs20_deauth_req_timeout);
1630 }
1631
1632
1633 static void ieee802_1x_hs20_session_info(struct hostapd_data *hapd,
1634 struct sta_info *sta, u8 *pos,
1635 size_t len, int session_timeout)
1636 {
1637 unsigned int swt;
1638 int warning_time, beacon_int;
1639
1640 if (len < 1)
1641 return; /* Malformed information */
1642 os_free(sta->hs20_session_info_url);
1643 sta->hs20_session_info_url = os_malloc(len);
1644 if (sta->hs20_session_info_url == NULL)
1645 return;
1646 swt = pos[0];
1647 os_memcpy(sta->hs20_session_info_url, pos + 1, len - 1);
1648 sta->hs20_session_info_url[len - 1] = '\0';
1649 wpa_printf(MSG_DEBUG, "HS 2.0: Session Information URL='%s' SWT=%u "
1650 "(session_timeout=%d)",
1651 sta->hs20_session_info_url, swt, session_timeout);
1652 if (session_timeout < 0) {
1653 wpa_printf(MSG_DEBUG, "HS 2.0: No Session-Timeout set - ignore session info URL");
1654 return;
1655 }
1656 if (swt == 255)
1657 swt = 1; /* Use one minute as the AP selected value */
1658
1659 if ((unsigned int) session_timeout < swt * 60)
1660 warning_time = 0;
1661 else
1662 warning_time = session_timeout - swt * 60;
1663
1664 beacon_int = hapd->iconf->beacon_int;
1665 if (beacon_int < 1)
1666 beacon_int = 100; /* best guess */
1667 sta->hs20_disassoc_timer = swt * 60 * 1000 / beacon_int * 125 / 128;
1668 if (sta->hs20_disassoc_timer > 65535)
1669 sta->hs20_disassoc_timer = 65535;
1670
1671 ap_sta_session_warning_timeout(hapd, sta, warning_time);
1672 }
1673
1674
1675 static void ieee802_1x_hs20_t_c_filtering(struct hostapd_data *hapd,
1676 struct sta_info *sta, u8 *pos,
1677 size_t len)
1678 {
1679 if (len < 4)
1680 return; /* Malformed information */
1681 wpa_printf(MSG_DEBUG,
1682 "HS 2.0: Terms and Conditions filtering %02x %02x %02x %02x",
1683 pos[0], pos[1], pos[2], pos[3]);
1684 hs20_t_c_filtering(hapd, sta, pos[0] & BIT(0));
1685 }
1686
1687
1688 static void ieee802_1x_hs20_t_c_url(struct hostapd_data *hapd,
1689 struct sta_info *sta, u8 *pos, size_t len)
1690 {
1691 os_free(sta->t_c_url);
1692 sta->t_c_url = os_malloc(len + 1);
1693 if (!sta->t_c_url)
1694 return;
1695 os_memcpy(sta->t_c_url, pos, len);
1696 sta->t_c_url[len] = '\0';
1697 wpa_printf(MSG_DEBUG,
1698 "HS 2.0: Terms and Conditions URL %s", sta->t_c_url);
1699 }
1700
1701 #endif /* CONFIG_HS20 */
1702
1703
1704 static void ieee802_1x_check_hs20(struct hostapd_data *hapd,
1705 struct sta_info *sta,
1706 struct radius_msg *msg,
1707 int session_timeout)
1708 {
1709 #ifdef CONFIG_HS20
1710 u8 *buf, *pos, *end, type, sublen;
1711 size_t len;
1712
1713 buf = NULL;
1714 sta->remediation = 0;
1715 sta->hs20_deauth_requested = 0;
1716
1717 for (;;) {
1718 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_VENDOR_SPECIFIC,
1719 &buf, &len, buf) < 0)
1720 break;
1721 if (len < 6)
1722 continue;
1723 pos = buf;
1724 end = buf + len;
1725 if (WPA_GET_BE32(pos) != RADIUS_VENDOR_ID_WFA)
1726 continue;
1727 pos += 4;
1728
1729 type = *pos++;
1730 sublen = *pos++;
1731 if (sublen < 2)
1732 continue; /* invalid length */
1733 sublen -= 2; /* skip header */
1734 if (pos + sublen > end)
1735 continue; /* invalid WFA VSA */
1736
1737 switch (type) {
1738 case RADIUS_VENDOR_ATTR_WFA_HS20_SUBSCR_REMEDIATION:
1739 ieee802_1x_hs20_sub_rem(sta, pos, sublen);
1740 break;
1741 case RADIUS_VENDOR_ATTR_WFA_HS20_DEAUTH_REQ:
1742 ieee802_1x_hs20_deauth_req(hapd, sta, pos, sublen);
1743 break;
1744 case RADIUS_VENDOR_ATTR_WFA_HS20_SESSION_INFO_URL:
1745 ieee802_1x_hs20_session_info(hapd, sta, pos, sublen,
1746 session_timeout);
1747 break;
1748 case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_FILTERING:
1749 ieee802_1x_hs20_t_c_filtering(hapd, sta, pos, sublen);
1750 break;
1751 case RADIUS_VENDOR_ATTR_WFA_HS20_T_C_URL:
1752 ieee802_1x_hs20_t_c_url(hapd, sta, pos, sublen);
1753 break;
1754 }
1755 }
1756 #endif /* CONFIG_HS20 */
1757 }
1758
1759
1760 struct sta_id_search {
1761 u8 identifier;
1762 struct eapol_state_machine *sm;
1763 };
1764
1765
1766 static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd,
1767 struct sta_info *sta,
1768 void *ctx)
1769 {
1770 struct sta_id_search *id_search = ctx;
1771 struct eapol_state_machine *sm = sta->eapol_sm;
1772
1773 if (sm && sm->radius_identifier >= 0 &&
1774 sm->radius_identifier == id_search->identifier) {
1775 id_search->sm = sm;
1776 return 1;
1777 }
1778 return 0;
1779 }
1780
1781
1782 static struct eapol_state_machine *
1783 ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
1784 {
1785 struct sta_id_search id_search;
1786 id_search.identifier = identifier;
1787 id_search.sm = NULL;
1788 ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search);
1789 return id_search.sm;
1790 }
1791
1792
1793 #ifndef CONFIG_NO_VLAN
1794 static int ieee802_1x_update_vlan(struct radius_msg *msg,
1795 struct hostapd_data *hapd,
1796 struct sta_info *sta)
1797 {
1798 struct vlan_description vlan_desc;
1799
1800 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
1801 vlan_desc.notempty = !!radius_msg_get_vlanid(msg, &vlan_desc.untagged,
1802 MAX_NUM_TAGGED_VLAN,
1803 vlan_desc.tagged);
1804
1805 if (vlan_desc.notempty &&
1806 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
1807 sta->eapol_sm->authFail = TRUE;
1808 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1809 HOSTAPD_LEVEL_INFO,
1810 "Invalid VLAN %d%s received from RADIUS server",
1811 vlan_desc.untagged,
1812 vlan_desc.tagged[0] ? "+" : "");
1813 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
1814 ap_sta_set_vlan(hapd, sta, &vlan_desc);
1815 return -1;
1816 }
1817
1818 if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_REQUIRED &&
1819 !vlan_desc.notempty) {
1820 sta->eapol_sm->authFail = TRUE;
1821 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1822 HOSTAPD_LEVEL_INFO,
1823 "authentication server did not include required VLAN ID in Access-Accept");
1824 return -1;
1825 }
1826
1827 return ap_sta_set_vlan(hapd, sta, &vlan_desc);
1828 }
1829 #endif /* CONFIG_NO_VLAN */
1830
1831
1832 /**
1833 * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
1834 * @msg: RADIUS response message
1835 * @req: RADIUS request message
1836 * @shared_secret: RADIUS shared secret
1837 * @shared_secret_len: Length of shared_secret in octets
1838 * @data: Context data (struct hostapd_data *)
1839 * Returns: Processing status
1840 */
1841 static RadiusRxResult
1842 ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
1843 const u8 *shared_secret, size_t shared_secret_len,
1844 void *data)
1845 {
1846 struct hostapd_data *hapd = data;
1847 struct sta_info *sta;
1848 u32 session_timeout = 0, termination_action, acct_interim_interval;
1849 int session_timeout_set;
1850 u32 reason_code;
1851 struct eapol_state_machine *sm;
1852 int override_eapReq = 0;
1853 struct radius_hdr *hdr = radius_msg_get_hdr(msg);
1854
1855 sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier);
1856 if (sm == NULL) {
1857 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
1858 "station for this RADIUS message");
1859 return RADIUS_RX_UNKNOWN;
1860 }
1861 sta = sm->sta;
1862
1863 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
1864 * present when packet contains an EAP-Message attribute */
1865 if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
1866 radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
1867 0) < 0 &&
1868 radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
1869 wpa_printf(MSG_DEBUG, "Allowing RADIUS Access-Reject without "
1870 "Message-Authenticator since it does not include "
1871 "EAP-Message");
1872 } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
1873 req, 1)) {
1874 wpa_printf(MSG_INFO, "Incoming RADIUS packet did not have correct Message-Authenticator - dropped");
1875 return RADIUS_RX_INVALID_AUTHENTICATOR;
1876 }
1877
1878 if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
1879 hdr->code != RADIUS_CODE_ACCESS_REJECT &&
1880 hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
1881 wpa_printf(MSG_INFO, "Unknown RADIUS message code");
1882 return RADIUS_RX_UNKNOWN;
1883 }
1884
1885 sm->radius_identifier = -1;
1886 wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
1887 MAC2STR(sta->addr));
1888
1889 radius_msg_free(sm->last_recv_radius);
1890 sm->last_recv_radius = msg;
1891
1892 session_timeout_set =
1893 !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
1894 &session_timeout);
1895 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION,
1896 &termination_action))
1897 termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
1898
1899 if (hapd->conf->acct_interim_interval == 0 &&
1900 hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
1901 radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
1902 &acct_interim_interval) == 0) {
1903 if (acct_interim_interval < 60) {
1904 hostapd_logger(hapd, sta->addr,
1905 HOSTAPD_MODULE_IEEE8021X,
1906 HOSTAPD_LEVEL_INFO,
1907 "ignored too small "
1908 "Acct-Interim-Interval %d",
1909 acct_interim_interval);
1910 } else
1911 sta->acct_interim_interval = acct_interim_interval;
1912 }
1913
1914
1915 switch (hdr->code) {
1916 case RADIUS_CODE_ACCESS_ACCEPT:
1917 #ifndef CONFIG_NO_VLAN
1918 if (hapd->conf->ssid.dynamic_vlan != DYNAMIC_VLAN_DISABLED &&
1919 ieee802_1x_update_vlan(msg, hapd, sta) < 0)
1920 break;
1921
1922 if (sta->vlan_id > 0) {
1923 hostapd_logger(hapd, sta->addr,
1924 HOSTAPD_MODULE_RADIUS,
1925 HOSTAPD_LEVEL_INFO,
1926 "VLAN ID %d", sta->vlan_id);
1927 }
1928
1929 if ((sta->flags & WLAN_STA_ASSOC) &&
1930 ap_sta_bind_vlan(hapd, sta) < 0)
1931 break;
1932 #endif /* CONFIG_NO_VLAN */
1933
1934 sta->session_timeout_set = !!session_timeout_set;
1935 os_get_reltime(&sta->session_timeout);
1936 sta->session_timeout.sec += session_timeout;
1937
1938 /* RFC 3580, Ch. 3.17 */
1939 if (session_timeout_set && termination_action ==
1940 RADIUS_TERMINATION_ACTION_RADIUS_REQUEST)
1941 sm->reAuthPeriod = session_timeout;
1942 else if (session_timeout_set)
1943 ap_sta_session_timeout(hapd, sta, session_timeout);
1944 else
1945 ap_sta_no_session_timeout(hapd, sta);
1946
1947 sm->eap_if->aaaSuccess = TRUE;
1948 override_eapReq = 1;
1949 ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret,
1950 shared_secret_len);
1951 ieee802_1x_store_radius_class(hapd, sta, msg);
1952 ieee802_1x_update_sta_identity(hapd, sta, msg);
1953 ieee802_1x_update_sta_cui(hapd, sta, msg);
1954 ieee802_1x_check_hs20(hapd, sta, msg,
1955 session_timeout_set ?
1956 (int) session_timeout : -1);
1957 break;
1958 case RADIUS_CODE_ACCESS_REJECT:
1959 sm->eap_if->aaaFail = TRUE;
1960 override_eapReq = 1;
1961 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_WLAN_REASON_CODE,
1962 &reason_code) == 0) {
1963 wpa_printf(MSG_DEBUG,
1964 "RADIUS server indicated WLAN-Reason-Code %u in Access-Reject for "
1965 MACSTR, reason_code, MAC2STR(sta->addr));
1966 sta->disconnect_reason_code = reason_code;
1967 }
1968 break;
1969 case RADIUS_CODE_ACCESS_CHALLENGE:
1970 sm->eap_if->aaaEapReq = TRUE;
1971 if (session_timeout_set) {
1972 /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
1973 sm->eap_if->aaaMethodTimeout = session_timeout;
1974 hostapd_logger(hapd, sm->addr,
1975 HOSTAPD_MODULE_IEEE8021X,
1976 HOSTAPD_LEVEL_DEBUG,
1977 "using EAP timeout of %d seconds (from "
1978 "RADIUS)",
1979 sm->eap_if->aaaMethodTimeout);
1980 } else {
1981 /*
1982 * Use dynamic retransmission behavior per EAP
1983 * specification.
1984 */
1985 sm->eap_if->aaaMethodTimeout = 0;
1986 }
1987 break;
1988 }
1989
1990 ieee802_1x_decapsulate_radius(hapd, sta);
1991 if (override_eapReq)
1992 sm->eap_if->aaaEapReq = FALSE;
1993
1994 #ifdef CONFIG_FILS
1995 #ifdef NEED_AP_MLME
1996 if (sta->flags & WLAN_STA_PENDING_FILS_ERP) {
1997 /* TODO: Add a PMKSA entry on success? */
1998 ieee802_11_finish_fils_auth(
1999 hapd, sta, hdr->code == RADIUS_CODE_ACCESS_ACCEPT,
2000 sm->eap_if->aaaEapReqData,
2001 sm->eap_if->aaaEapKeyData,
2002 sm->eap_if->aaaEapKeyDataLen);
2003 }
2004 #endif /* NEED_AP_MLME */
2005 #endif /* CONFIG_FILS */
2006
2007 eapol_auth_step(sm);
2008
2009 return RADIUS_RX_QUEUED;
2010 }
2011 #endif /* CONFIG_NO_RADIUS */
2012
2013
2014 void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
2015 {
2016 struct eapol_state_machine *sm = sta->eapol_sm;
2017 if (sm == NULL)
2018 return;
2019
2020 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
2021 HOSTAPD_LEVEL_DEBUG, "aborting authentication");
2022
2023 #ifndef CONFIG_NO_RADIUS
2024 radius_msg_free(sm->last_recv_radius);
2025 sm->last_recv_radius = NULL;
2026 #endif /* CONFIG_NO_RADIUS */
2027
2028 if (sm->eap_if->eapTimeout) {
2029 /*
2030 * Disconnect the STA since it did not reply to the last EAP
2031 * request and we cannot continue EAP processing (EAP-Failure
2032 * could only be sent if the EAP peer actually replied).
2033 */
2034 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "EAP Timeout, STA " MACSTR,
2035 MAC2STR(sta->addr));
2036
2037 sm->eap_if->portEnabled = FALSE;
2038 ap_sta_disconnect(hapd, sta, sta->addr,
2039 WLAN_REASON_PREV_AUTH_NOT_VALID);
2040 }
2041 }
2042
2043
2044 static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
2045 {
2046 struct eapol_authenticator *eapol = hapd->eapol_auth;
2047
2048 if (hapd->conf->default_wep_key_len < 1)
2049 return 0;
2050
2051 os_free(eapol->default_wep_key);
2052 eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
2053 if (eapol->default_wep_key == NULL ||
2054 random_get_bytes(eapol->default_wep_key,
2055 hapd->conf->default_wep_key_len)) {
2056 wpa_printf(MSG_INFO, "Could not generate random WEP key");
2057 os_free(eapol->default_wep_key);
2058 eapol->default_wep_key = NULL;
2059 return -1;
2060 }
2061
2062 wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
2063 eapol->default_wep_key,
2064 hapd->conf->default_wep_key_len);
2065
2066 return 0;
2067 }
2068
2069
2070 static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
2071 struct sta_info *sta, void *ctx)
2072 {
2073 if (sta->eapol_sm) {
2074 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
2075 eapol_auth_step(sta->eapol_sm);
2076 }
2077 return 0;
2078 }
2079
2080
2081 static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
2082 {
2083 struct hostapd_data *hapd = eloop_ctx;
2084 struct eapol_authenticator *eapol = hapd->eapol_auth;
2085
2086 if (eapol->default_wep_key_idx >= 3)
2087 eapol->default_wep_key_idx =
2088 hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
2089 else
2090 eapol->default_wep_key_idx++;
2091
2092 wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
2093 eapol->default_wep_key_idx);
2094
2095 if (ieee802_1x_rekey_broadcast(hapd)) {
2096 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
2097 HOSTAPD_LEVEL_WARNING, "failed to generate a "
2098 "new broadcast key");
2099 os_free(eapol->default_wep_key);
2100 eapol->default_wep_key = NULL;
2101 return;
2102 }
2103
2104 /* TODO: Could setup key for RX here, but change default TX keyid only
2105 * after new broadcast key has been sent to all stations. */
2106 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
2107 broadcast_ether_addr,
2108 eapol->default_wep_key_idx, 1, NULL, 0,
2109 eapol->default_wep_key,
2110 hapd->conf->default_wep_key_len)) {
2111 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
2112 HOSTAPD_LEVEL_WARNING, "failed to configure a "
2113 "new broadcast key");
2114 os_free(eapol->default_wep_key);
2115 eapol->default_wep_key = NULL;
2116 return;
2117 }
2118
2119 ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL);
2120
2121 if (hapd->conf->wep_rekeying_period > 0) {
2122 eloop_register_timeout(hapd->conf->wep_rekeying_period, 0,
2123 ieee802_1x_rekey, hapd, NULL);
2124 }
2125 }
2126
2127
2128 static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
2129 const u8 *data, size_t datalen)
2130 {
2131 #ifdef CONFIG_WPS
2132 struct sta_info *sta = sta_ctx;
2133
2134 if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
2135 WLAN_STA_MAYBE_WPS) {
2136 const u8 *identity;
2137 size_t identity_len;
2138 struct eapol_state_machine *sm = sta->eapol_sm;
2139
2140 identity = eap_get_identity(sm->eap, &identity_len);
2141 if (identity &&
2142 ((identity_len == WSC_ID_ENROLLEE_LEN &&
2143 os_memcmp(identity, WSC_ID_ENROLLEE,
2144 WSC_ID_ENROLLEE_LEN) == 0) ||
2145 (identity_len == WSC_ID_REGISTRAR_LEN &&
2146 os_memcmp(identity, WSC_ID_REGISTRAR,
2147 WSC_ID_REGISTRAR_LEN) == 0))) {
2148 wpa_printf(MSG_DEBUG, "WPS: WLAN_STA_MAYBE_WPS -> "
2149 "WLAN_STA_WPS");
2150 sta->flags |= WLAN_STA_WPS;
2151 }
2152 }
2153 #endif /* CONFIG_WPS */
2154
2155 ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
2156 }
2157
2158
2159 static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
2160 const u8 *data, size_t datalen)
2161 {
2162 #ifndef CONFIG_NO_RADIUS
2163 struct hostapd_data *hapd = ctx;
2164 struct sta_info *sta = sta_ctx;
2165
2166 ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
2167 #endif /* CONFIG_NO_RADIUS */
2168 }
2169
2170
2171 static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success,
2172 int preauth, int remediation)
2173 {
2174 struct hostapd_data *hapd = ctx;
2175 struct sta_info *sta = sta_ctx;
2176 if (preauth)
2177 rsn_preauth_finished(hapd, sta, success);
2178 else
2179 ieee802_1x_finished(hapd, sta, success, remediation);
2180 }
2181
2182
2183 static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity,
2184 size_t identity_len, int phase2,
2185 struct eap_user *user)
2186 {
2187 struct hostapd_data *hapd = ctx;
2188 const struct hostapd_eap_user *eap_user;
2189 int i;
2190 int rv = -1;
2191
2192 eap_user = hostapd_get_eap_user(hapd, identity, identity_len, phase2);
2193 if (eap_user == NULL)
2194 goto out;
2195
2196 os_memset(user, 0, sizeof(*user));
2197 user->phase2 = phase2;
2198 for (i = 0; i < EAP_MAX_METHODS; i++) {
2199 user->methods[i].vendor = eap_user->methods[i].vendor;
2200 user->methods[i].method = eap_user->methods[i].method;
2201 }
2202
2203 if (eap_user->password) {
2204 user->password = os_memdup(eap_user->password,
2205 eap_user->password_len);
2206 if (user->password == NULL)
2207 goto out;
2208 user->password_len = eap_user->password_len;
2209 user->password_hash = eap_user->password_hash;
2210 if (eap_user->salt && eap_user->salt_len) {
2211 user->salt = os_memdup(eap_user->salt,
2212 eap_user->salt_len);
2213 if (!user->salt)
2214 goto out;
2215 user->salt_len = eap_user->salt_len;
2216 }
2217 }
2218 user->force_version = eap_user->force_version;
2219 user->macacl = eap_user->macacl;
2220 user->ttls_auth = eap_user->ttls_auth;
2221 user->remediation = eap_user->remediation;
2222 rv = 0;
2223
2224 out:
2225 if (rv)
2226 wpa_printf(MSG_DEBUG, "%s: Failed to find user", __func__);
2227
2228 return rv;
2229 }
2230
2231
2232 static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
2233 {
2234 struct hostapd_data *hapd = ctx;
2235 struct sta_info *sta;
2236 sta = ap_get_sta(hapd, addr);
2237 if (sta == NULL || sta->eapol_sm == NULL)
2238 return 0;
2239 return 1;
2240 }
2241
2242
2243 static void ieee802_1x_logger(void *ctx, const u8 *addr,
2244 eapol_logger_level level, const char *txt)
2245 {
2246 #ifndef CONFIG_NO_HOSTAPD_LOGGER
2247 struct hostapd_data *hapd = ctx;
2248 int hlevel;
2249
2250 switch (level) {
2251 case EAPOL_LOGGER_WARNING:
2252 hlevel = HOSTAPD_LEVEL_WARNING;
2253 break;
2254 case EAPOL_LOGGER_INFO:
2255 hlevel = HOSTAPD_LEVEL_INFO;
2256 break;
2257 case EAPOL_LOGGER_DEBUG:
2258 default:
2259 hlevel = HOSTAPD_LEVEL_DEBUG;
2260 break;
2261 }
2262
2263 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
2264 txt);
2265 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
2266 }
2267
2268
2269 static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx,
2270 int authorized)
2271 {
2272 struct hostapd_data *hapd = ctx;
2273 struct sta_info *sta = sta_ctx;
2274 ieee802_1x_set_sta_authorized(hapd, sta, authorized);
2275 }
2276
2277
2278 static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx)
2279 {
2280 struct hostapd_data *hapd = ctx;
2281 struct sta_info *sta = sta_ctx;
2282 ieee802_1x_abort_auth(hapd, sta);
2283 }
2284
2285
2286 static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
2287 {
2288 #ifndef CONFIG_FIPS
2289 #ifndef CONFIG_NO_RC4
2290 struct hostapd_data *hapd = ctx;
2291 struct sta_info *sta = sta_ctx;
2292 ieee802_1x_tx_key(hapd, sta);
2293 #endif /* CONFIG_NO_RC4 */
2294 #endif /* CONFIG_FIPS */
2295 }
2296
2297
2298 static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx,
2299 enum eapol_event type)
2300 {
2301 /* struct hostapd_data *hapd = ctx; */
2302 struct sta_info *sta = sta_ctx;
2303 switch (type) {
2304 case EAPOL_AUTH_SM_CHANGE:
2305 wpa_auth_sm_notify(sta->wpa_sm);
2306 break;
2307 case EAPOL_AUTH_REAUTHENTICATE:
2308 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
2309 break;
2310 }
2311 }
2312
2313
2314 #ifdef CONFIG_ERP
2315
2316 static struct eap_server_erp_key *
2317 ieee802_1x_erp_get_key(void *ctx, const char *keyname)
2318 {
2319 struct hostapd_data *hapd = ctx;
2320 struct eap_server_erp_key *erp;
2321
2322 dl_list_for_each(erp, &hapd->erp_keys, struct eap_server_erp_key,
2323 list) {
2324 if (os_strcmp(erp->keyname_nai, keyname) == 0)
2325 return erp;
2326 }
2327
2328 return NULL;
2329 }
2330
2331
2332 static int ieee802_1x_erp_add_key(void *ctx, struct eap_server_erp_key *erp)
2333 {
2334 struct hostapd_data *hapd = ctx;
2335
2336 dl_list_add(&hapd->erp_keys, &erp->list);
2337 return 0;
2338 }
2339
2340 #endif /* CONFIG_ERP */
2341
2342
2343 int ieee802_1x_init(struct hostapd_data *hapd)
2344 {
2345 int i;
2346 struct eapol_auth_config conf;
2347 struct eapol_auth_cb cb;
2348
2349 dl_list_init(&hapd->erp_keys);
2350
2351 os_memset(&conf, 0, sizeof(conf));
2352 conf.ctx = hapd;
2353 conf.eap_reauth_period = hapd->conf->eap_reauth_period;
2354 conf.wpa = hapd->conf->wpa;
2355 conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
2356 conf.eap_server = hapd->conf->eap_server;
2357 conf.ssl_ctx = hapd->ssl_ctx;
2358 conf.msg_ctx = hapd->msg_ctx;
2359 conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
2360 conf.eap_req_id_text = hapd->conf->eap_req_id_text;
2361 conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
2362 conf.erp_send_reauth_start = hapd->conf->erp_send_reauth_start;
2363 conf.erp_domain = hapd->conf->erp_domain;
2364 conf.erp = hapd->conf->eap_server_erp;
2365 conf.tls_session_lifetime = hapd->conf->tls_session_lifetime;
2366 conf.tls_flags = hapd->conf->tls_flags;
2367 conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
2368 conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
2369 conf.eap_fast_a_id_len = hapd->conf->eap_fast_a_id_len;
2370 conf.eap_fast_a_id_info = hapd->conf->eap_fast_a_id_info;
2371 conf.eap_fast_prov = hapd->conf->eap_fast_prov;
2372 conf.pac_key_lifetime = hapd->conf->pac_key_lifetime;
2373 conf.pac_key_refresh_time = hapd->conf->pac_key_refresh_time;
2374 conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
2375 conf.tnc = hapd->conf->tnc;
2376 conf.wps = hapd->wps;
2377 conf.fragment_size = hapd->conf->fragment_size;
2378 conf.pwd_group = hapd->conf->pwd_group;
2379 conf.pbc_in_m1 = hapd->conf->pbc_in_m1;
2380 if (hapd->conf->server_id) {
2381 conf.server_id = (const u8 *) hapd->conf->server_id;
2382 conf.server_id_len = os_strlen(hapd->conf->server_id);
2383 } else {
2384 conf.server_id = (const u8 *) "hostapd";
2385 conf.server_id_len = 7;
2386 }
2387
2388 os_memset(&cb, 0, sizeof(cb));
2389 cb.eapol_send = ieee802_1x_eapol_send;
2390 cb.aaa_send = ieee802_1x_aaa_send;
2391 cb.finished = _ieee802_1x_finished;
2392 cb.get_eap_user = ieee802_1x_get_eap_user;
2393 cb.sta_entry_alive = ieee802_1x_sta_entry_alive;
2394 cb.logger = ieee802_1x_logger;
2395 cb.set_port_authorized = ieee802_1x_set_port_authorized;
2396 cb.abort_auth = _ieee802_1x_abort_auth;
2397 cb.tx_key = _ieee802_1x_tx_key;
2398 cb.eapol_event = ieee802_1x_eapol_event;
2399 #ifdef CONFIG_ERP
2400 cb.erp_get_key = ieee802_1x_erp_get_key;
2401 cb.erp_add_key = ieee802_1x_erp_add_key;
2402 #endif /* CONFIG_ERP */
2403
2404 hapd->eapol_auth = eapol_auth_init(&conf, &cb);
2405 if (hapd->eapol_auth == NULL)
2406 return -1;
2407
2408 if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
2409 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1))
2410 return -1;
2411
2412 #ifndef CONFIG_NO_RADIUS
2413 if (radius_client_register(hapd->radius, RADIUS_AUTH,
2414 ieee802_1x_receive_auth, hapd))
2415 return -1;
2416 #endif /* CONFIG_NO_RADIUS */
2417
2418 if (hapd->conf->default_wep_key_len) {
2419 for (i = 0; i < 4; i++)
2420 hostapd_drv_set_key(hapd->conf->iface, hapd,
2421 WPA_ALG_NONE, NULL, i, 0, NULL, 0,
2422 NULL, 0);
2423
2424 ieee802_1x_rekey(hapd, NULL);
2425
2426 if (hapd->eapol_auth->default_wep_key == NULL)
2427 return -1;
2428 }
2429
2430 return 0;
2431 }
2432
2433
2434 void ieee802_1x_erp_flush(struct hostapd_data *hapd)
2435 {
2436 struct eap_server_erp_key *erp;
2437
2438 while ((erp = dl_list_first(&hapd->erp_keys, struct eap_server_erp_key,
2439 list)) != NULL) {
2440 dl_list_del(&erp->list);
2441 bin_clear_free(erp, sizeof(*erp));
2442 }
2443 }
2444
2445
2446 void ieee802_1x_deinit(struct hostapd_data *hapd)
2447 {
2448 eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);
2449
2450 if (hapd->driver && hapd->drv_priv &&
2451 (hapd->conf->ieee802_1x || hapd->conf->wpa))
2452 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
2453
2454 eapol_auth_deinit(hapd->eapol_auth);
2455 hapd->eapol_auth = NULL;
2456
2457 ieee802_1x_erp_flush(hapd);
2458 }
2459
2460
2461 int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
2462 const u8 *buf, size_t len, int ack)
2463 {
2464 struct ieee80211_hdr *hdr;
2465 u8 *pos;
2466 const unsigned char rfc1042_hdr[ETH_ALEN] =
2467 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
2468
2469 if (sta == NULL)
2470 return -1;
2471 if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2)
2472 return 0;
2473
2474 hdr = (struct ieee80211_hdr *) buf;
2475 pos = (u8 *) (hdr + 1);
2476 if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0)
2477 return 0;
2478 pos += sizeof(rfc1042_hdr);
2479 if (WPA_GET_BE16(pos) != ETH_P_PAE)
2480 return 0;
2481 pos += 2;
2482
2483 return ieee802_1x_eapol_tx_status(hapd, sta, pos, buf + len - pos,
2484 ack);
2485 }
2486
2487
2488 int ieee802_1x_eapol_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
2489 const u8 *buf, int len, int ack)
2490 {
2491 const struct ieee802_1x_hdr *xhdr =
2492 (const struct ieee802_1x_hdr *) buf;
2493 const u8 *pos = buf + sizeof(*xhdr);
2494 struct ieee802_1x_eapol_key *key;
2495
2496 if (len < (int) sizeof(*xhdr))
2497 return 0;
2498 wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR " TX status - version=%d "
2499 "type=%d length=%d - ack=%d",
2500 MAC2STR(sta->addr), xhdr->version, xhdr->type,
2501 be_to_host16(xhdr->length), ack);
2502
2503 #ifdef CONFIG_WPS
2504 if (xhdr->type == IEEE802_1X_TYPE_EAP_PACKET && ack &&
2505 (sta->flags & WLAN_STA_WPS) &&
2506 ap_sta_pending_delayed_1x_auth_fail_disconnect(hapd, sta)) {
2507 wpa_printf(MSG_DEBUG,
2508 "WPS: Indicate EAP completion on ACK for EAP-Failure");
2509 hostapd_wps_eap_completed(hapd);
2510 }
2511 #endif /* CONFIG_WPS */
2512
2513 if (xhdr->type != IEEE802_1X_TYPE_EAPOL_KEY)
2514 return 0;
2515
2516 if (pos + sizeof(struct wpa_eapol_key) <= buf + len) {
2517 const struct wpa_eapol_key *wpa;
2518 wpa = (const struct wpa_eapol_key *) pos;
2519 if (wpa->type == EAPOL_KEY_TYPE_RSN ||
2520 wpa->type == EAPOL_KEY_TYPE_WPA)
2521 wpa_auth_eapol_key_tx_status(hapd->wpa_auth,
2522 sta->wpa_sm, ack);
2523 }
2524
2525 /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
2526 * or Authenticator state machines, but EAPOL-Key packets are not
2527 * retransmitted in case of failure. Try to re-send failed EAPOL-Key
2528 * packets couple of times because otherwise STA keys become
2529 * unsynchronized with AP. */
2530 if (!ack && pos + sizeof(*key) <= buf + len) {
2531 key = (struct ieee802_1x_eapol_key *) pos;
2532 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
2533 HOSTAPD_LEVEL_DEBUG, "did not Ack EAPOL-Key "
2534 "frame (%scast index=%d)",
2535 key->key_index & BIT(7) ? "uni" : "broad",
2536 key->key_index & ~BIT(7));
2537 /* TODO: re-send EAPOL-Key couple of times (with short delay
2538 * between them?). If all attempt fail, report error and
2539 * deauthenticate STA so that it will get new keys when
2540 * authenticating again (e.g., after returning in range).
2541 * Separate limit/transmit state needed both for unicast and
2542 * broadcast keys(?) */
2543 }
2544 /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
2545 * to here and change the key only if the EAPOL-Key packet was Acked.
2546 */
2547
2548 return 1;
2549 }
2550
2551
2552 u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len)
2553 {
2554 if (sm == NULL || sm->identity == NULL)
2555 return NULL;
2556
2557 *len = sm->identity_len;
2558 return sm->identity;
2559 }
2560
2561
2562 u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
2563 int idx)
2564 {
2565 if (sm == NULL || sm->radius_class.attr == NULL ||
2566 idx >= (int) sm->radius_class.count)
2567 return NULL;
2568
2569 *len = sm->radius_class.attr[idx].len;
2570 return sm->radius_class.attr[idx].data;
2571 }
2572
2573
2574 struct wpabuf * ieee802_1x_get_radius_cui(struct eapol_state_machine *sm)
2575 {
2576 if (sm == NULL)
2577 return NULL;
2578 return sm->radius_cui;
2579 }
2580
2581
2582 const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len)
2583 {
2584 *len = 0;
2585 if (sm == NULL)
2586 return NULL;
2587
2588 *len = sm->eap_if->eapKeyDataLen;
2589 return sm->eap_if->eapKeyData;
2590 }
2591
2592
2593 #ifdef CONFIG_MACSEC
2594 const u8 * ieee802_1x_get_session_id(struct eapol_state_machine *sm,
2595 size_t *len)
2596 {
2597 *len = 0;
2598 if (!sm || !sm->eap_if)
2599 return NULL;
2600
2601 *len = sm->eap_if->eapSessionIdLen;
2602 return sm->eap_if->eapSessionId;
2603 }
2604 #endif /* CONFIG_MACSEC */
2605
2606
2607 void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm,
2608 int enabled)
2609 {
2610 if (sm == NULL)
2611 return;
2612 sm->eap_if->portEnabled = enabled ? TRUE : FALSE;
2613 eapol_auth_step(sm);
2614 }
2615
2616
2617 void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm,
2618 int valid)
2619 {
2620 if (sm == NULL)
2621 return;
2622 sm->portValid = valid ? TRUE : FALSE;
2623 eapol_auth_step(sm);
2624 }
2625
2626
2627 void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth)
2628 {
2629 if (sm == NULL)
2630 return;
2631 if (pre_auth)
2632 sm->flags |= EAPOL_SM_PREAUTH;
2633 else
2634 sm->flags &= ~EAPOL_SM_PREAUTH;
2635 }
2636
2637
2638 static const char * bool_txt(Boolean val)
2639 {
2640 return val ? "TRUE" : "FALSE";
2641 }
2642
2643
2644 int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2645 {
2646 /* TODO */
2647 return 0;
2648 }
2649
2650
2651 int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2652 char *buf, size_t buflen)
2653 {
2654 int len = 0, ret;
2655 struct eapol_state_machine *sm = sta->eapol_sm;
2656 struct os_reltime diff;
2657 const char *name1;
2658 const char *name2;
2659 char *identity_buf = NULL;
2660
2661 if (sm == NULL)
2662 return 0;
2663
2664 ret = os_snprintf(buf + len, buflen - len,
2665 "dot1xPaePortNumber=%d\n"
2666 "dot1xPaePortProtocolVersion=%d\n"
2667 "dot1xPaePortCapabilities=1\n"
2668 "dot1xPaePortInitialize=%d\n"
2669 "dot1xPaePortReauthenticate=FALSE\n",
2670 sta->aid,
2671 EAPOL_VERSION,
2672 sm->initialize);
2673 if (os_snprintf_error(buflen - len, ret))
2674 return len;
2675 len += ret;
2676
2677 /* dot1xAuthConfigTable */
2678 ret = os_snprintf(buf + len, buflen - len,
2679 "dot1xAuthPaeState=%d\n"
2680 "dot1xAuthBackendAuthState=%d\n"
2681 "dot1xAuthAdminControlledDirections=%d\n"
2682 "dot1xAuthOperControlledDirections=%d\n"
2683 "dot1xAuthAuthControlledPortStatus=%d\n"
2684 "dot1xAuthAuthControlledPortControl=%d\n"
2685 "dot1xAuthQuietPeriod=%u\n"
2686 "dot1xAuthServerTimeout=%u\n"
2687 "dot1xAuthReAuthPeriod=%u\n"
2688 "dot1xAuthReAuthEnabled=%s\n"
2689 "dot1xAuthKeyTxEnabled=%s\n",
2690 sm->auth_pae_state + 1,
2691 sm->be_auth_state + 1,
2692 sm->adminControlledDirections,
2693 sm->operControlledDirections,
2694 sm->authPortStatus,
2695 sm->portControl,
2696 sm->quietPeriod,
2697 sm->serverTimeout,
2698 sm->reAuthPeriod,
2699 bool_txt(sm->reAuthEnabled),
2700 bool_txt(sm->keyTxEnabled));
2701 if (os_snprintf_error(buflen - len, ret))
2702 return len;
2703 len += ret;
2704
2705 /* dot1xAuthStatsTable */
2706 ret = os_snprintf(buf + len, buflen - len,
2707 "dot1xAuthEapolFramesRx=%u\n"
2708 "dot1xAuthEapolFramesTx=%u\n"
2709 "dot1xAuthEapolStartFramesRx=%u\n"
2710 "dot1xAuthEapolLogoffFramesRx=%u\n"
2711 "dot1xAuthEapolRespIdFramesRx=%u\n"
2712 "dot1xAuthEapolRespFramesRx=%u\n"
2713 "dot1xAuthEapolReqIdFramesTx=%u\n"
2714 "dot1xAuthEapolReqFramesTx=%u\n"
2715 "dot1xAuthInvalidEapolFramesRx=%u\n"
2716 "dot1xAuthEapLengthErrorFramesRx=%u\n"
2717 "dot1xAuthLastEapolFrameVersion=%u\n"
2718 "dot1xAuthLastEapolFrameSource=" MACSTR "\n",
2719 sm->dot1xAuthEapolFramesRx,
2720 sm->dot1xAuthEapolFramesTx,
2721 sm->dot1xAuthEapolStartFramesRx,
2722 sm->dot1xAuthEapolLogoffFramesRx,
2723 sm->dot1xAuthEapolRespIdFramesRx,
2724 sm->dot1xAuthEapolRespFramesRx,
2725 sm->dot1xAuthEapolReqIdFramesTx,
2726 sm->dot1xAuthEapolReqFramesTx,
2727 sm->dot1xAuthInvalidEapolFramesRx,
2728 sm->dot1xAuthEapLengthErrorFramesRx,
2729 sm->dot1xAuthLastEapolFrameVersion,
2730 MAC2STR(sm->addr));
2731 if (os_snprintf_error(buflen - len, ret))
2732 return len;
2733 len += ret;
2734
2735 /* dot1xAuthDiagTable */
2736 ret = os_snprintf(buf + len, buflen - len,
2737 "dot1xAuthEntersConnecting=%u\n"
2738 "dot1xAuthEapLogoffsWhileConnecting=%u\n"
2739 "dot1xAuthEntersAuthenticating=%u\n"
2740 "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
2741 "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
2742 "dot1xAuthAuthFailWhileAuthenticating=%u\n"
2743 "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
2744 "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
2745 "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
2746 "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
2747 "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
2748 "dot1xAuthBackendResponses=%u\n"
2749 "dot1xAuthBackendAccessChallenges=%u\n"
2750 "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
2751 "dot1xAuthBackendAuthSuccesses=%u\n"
2752 "dot1xAuthBackendAuthFails=%u\n",
2753 sm->authEntersConnecting,
2754 sm->authEapLogoffsWhileConnecting,
2755 sm->authEntersAuthenticating,
2756 sm->authAuthSuccessesWhileAuthenticating,
2757 sm->authAuthTimeoutsWhileAuthenticating,
2758 sm->authAuthFailWhileAuthenticating,
2759 sm->authAuthEapStartsWhileAuthenticating,
2760 sm->authAuthEapLogoffWhileAuthenticating,
2761 sm->authAuthReauthsWhileAuthenticated,
2762 sm->authAuthEapStartsWhileAuthenticated,
2763 sm->authAuthEapLogoffWhileAuthenticated,
2764 sm->backendResponses,
2765 sm->backendAccessChallenges,
2766 sm->backendOtherRequestsToSupplicant,
2767 sm->backendAuthSuccesses,
2768 sm->backendAuthFails);
2769 if (os_snprintf_error(buflen - len, ret))
2770 return len;
2771 len += ret;
2772
2773 /* dot1xAuthSessionStatsTable */
2774 os_reltime_age(&sta->acct_session_start, &diff);
2775 if (sm->eap && !sm->identity) {
2776 const u8 *id;
2777 size_t id_len;
2778
2779 id = eap_get_identity(sm->eap, &id_len);
2780 if (id)
2781 identity_buf = dup_binstr(id, id_len);
2782 }
2783 ret = os_snprintf(buf + len, buflen - len,
2784 /* TODO: dot1xAuthSessionOctetsRx */
2785 /* TODO: dot1xAuthSessionOctetsTx */
2786 /* TODO: dot1xAuthSessionFramesRx */
2787 /* TODO: dot1xAuthSessionFramesTx */
2788 "dot1xAuthSessionId=%016llX\n"
2789 "dot1xAuthSessionAuthenticMethod=%d\n"
2790 "dot1xAuthSessionTime=%u\n"
2791 "dot1xAuthSessionTerminateCause=999\n"
2792 "dot1xAuthSessionUserName=%s\n",
2793 (unsigned long long) sta->acct_session_id,
2794 (wpa_key_mgmt_wpa_ieee8021x(
2795 wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
2796 1 : 2,
2797 (unsigned int) diff.sec,
2798 sm->identity ? (char *) sm->identity :
2799 (identity_buf ? identity_buf : "N/A"));
2800 os_free(identity_buf);
2801 if (os_snprintf_error(buflen - len, ret))
2802 return len;
2803 len += ret;
2804
2805 if (sm->acct_multi_session_id) {
2806 ret = os_snprintf(buf + len, buflen - len,
2807 "authMultiSessionId=%016llX\n",
2808 (unsigned long long)
2809 sm->acct_multi_session_id);
2810 if (os_snprintf_error(buflen - len, ret))
2811 return len;
2812 len += ret;
2813 }
2814
2815 name1 = eap_server_get_name(0, sm->eap_type_authsrv);
2816 name2 = eap_server_get_name(0, sm->eap_type_supp);
2817 ret = os_snprintf(buf + len, buflen - len,
2818 "last_eap_type_as=%d (%s)\n"
2819 "last_eap_type_sta=%d (%s)\n",
2820 sm->eap_type_authsrv, name1,
2821 sm->eap_type_supp, name2);
2822 if (os_snprintf_error(buflen - len, ret))
2823 return len;
2824 len += ret;
2825
2826 return len;
2827 }
2828
2829
2830 #ifdef CONFIG_HS20
2831 static void ieee802_1x_wnm_notif_send(void *eloop_ctx, void *timeout_ctx)
2832 {
2833 struct hostapd_data *hapd = eloop_ctx;
2834 struct sta_info *sta = timeout_ctx;
2835
2836 if (sta->remediation) {
2837 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
2838 MACSTR " to indicate Subscription Remediation",
2839 MAC2STR(sta->addr));
2840 hs20_send_wnm_notification(hapd, sta->addr,
2841 sta->remediation_method,
2842 sta->remediation_url);
2843 os_free(sta->remediation_url);
2844 sta->remediation_url = NULL;
2845 }
2846
2847 if (sta->hs20_deauth_req) {
2848 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
2849 MACSTR " to indicate imminent deauthentication",
2850 MAC2STR(sta->addr));
2851 hs20_send_wnm_notification_deauth_req(hapd, sta->addr,
2852 sta->hs20_deauth_req);
2853 }
2854
2855 if (sta->hs20_t_c_filtering) {
2856 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to "
2857 MACSTR " to indicate Terms and Conditions filtering",
2858 MAC2STR(sta->addr));
2859 hs20_send_wnm_notification_t_c(hapd, sta->addr, sta->t_c_url);
2860 os_free(sta->t_c_url);
2861 sta->t_c_url = NULL;
2862 }
2863 }
2864 #endif /* CONFIG_HS20 */
2865
2866
2867 static void ieee802_1x_finished(struct hostapd_data *hapd,
2868 struct sta_info *sta, int success,
2869 int remediation)
2870 {
2871 const u8 *key;
2872 size_t len;
2873 /* TODO: get PMKLifetime from WPA parameters */
2874 static const int dot11RSNAConfigPMKLifetime = 43200;
2875 unsigned int session_timeout;
2876 struct os_reltime now, remaining;
2877
2878 #ifdef CONFIG_HS20
2879 if (remediation && !sta->remediation) {
2880 sta->remediation = 1;
2881 os_free(sta->remediation_url);
2882 sta->remediation_url =
2883 os_strdup(hapd->conf->subscr_remediation_url);
2884 sta->remediation_method = 1; /* SOAP-XML SPP */
2885 }
2886
2887 if (success && (sta->remediation || sta->hs20_deauth_req ||
2888 sta->hs20_t_c_filtering)) {
2889 wpa_printf(MSG_DEBUG, "HS 2.0: Schedule WNM-Notification to "
2890 MACSTR " in 100 ms", MAC2STR(sta->addr));
2891 eloop_cancel_timeout(ieee802_1x_wnm_notif_send, hapd, sta);
2892 eloop_register_timeout(0, 100000, ieee802_1x_wnm_notif_send,
2893 hapd, sta);
2894 }
2895 #endif /* CONFIG_HS20 */
2896
2897 #ifdef CONFIG_MACSEC
2898 ieee802_1x_notify_create_actor_hapd(hapd, sta);
2899 #endif /* CONFIG_MACSEC */
2900
2901 key = ieee802_1x_get_key(sta->eapol_sm, &len);
2902 if (sta->session_timeout_set) {
2903 os_get_reltime(&now);
2904 os_reltime_sub(&sta->session_timeout, &now, &remaining);
2905 session_timeout = (remaining.sec > 0) ? remaining.sec : 1;
2906 } else {
2907 session_timeout = dot11RSNAConfigPMKLifetime;
2908 }
2909 if (success && key && len >= PMK_LEN && !sta->remediation &&
2910 !sta->hs20_deauth_requested &&
2911 wpa_auth_pmksa_add(sta->wpa_sm, key, len, session_timeout,
2912 sta->eapol_sm) == 0) {
2913 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
2914 HOSTAPD_LEVEL_DEBUG,
2915 "Added PMKSA cache entry (IEEE 802.1X)");
2916 }
2917
2918 if (!success) {
2919 /*
2920 * Many devices require deauthentication after WPS provisioning
2921 * and some may not be be able to do that themselves, so
2922 * disconnect the client here. In addition, this may also
2923 * benefit IEEE 802.1X/EAPOL authentication cases, too since
2924 * the EAPOL PAE state machine would remain in HELD state for
2925 * considerable amount of time and some EAP methods, like
2926 * EAP-FAST with anonymous provisioning, may require another
2927 * EAPOL authentication to be started to complete connection.
2928 */
2929 ap_sta_delayed_1x_auth_fail_disconnect(hapd, sta);
2930 }
2931 }