blob: f5666035adaa1ba18776fe593825796fb919e06f [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 Shmidt8d520ff2011-05-09 14:06:53 -070034#include "ieee802_1x.h"
35
36
37static void ieee802_1x_finished(struct hostapd_data *hapd,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080038 struct sta_info *sta, int success,
39 int remediation);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040
41
42static void ieee802_1x_send(struct hostapd_data *hapd, struct sta_info *sta,
43 u8 type, const u8 *data, size_t datalen)
44{
45 u8 *buf;
46 struct ieee802_1x_hdr *xhdr;
47 size_t len;
48 int encrypt = 0;
49
50 len = sizeof(*xhdr) + datalen;
51 buf = os_zalloc(len);
52 if (buf == NULL) {
53 wpa_printf(MSG_ERROR, "malloc() failed for "
54 "ieee802_1x_send(len=%lu)",
55 (unsigned long) len);
56 return;
57 }
58
59 xhdr = (struct ieee802_1x_hdr *) buf;
60 xhdr->version = hapd->conf->eapol_version;
61 xhdr->type = type;
62 xhdr->length = host_to_be16(datalen);
63
64 if (datalen > 0 && data != NULL)
65 os_memcpy(xhdr + 1, data, datalen);
66
67 if (wpa_auth_pairwise_set(sta->wpa_sm))
68 encrypt = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080069#ifdef CONFIG_TESTING_OPTIONS
70 if (hapd->ext_eapol_frame_io) {
71 size_t hex_len = 2 * len + 1;
72 char *hex = os_malloc(hex_len);
73
74 if (hex) {
75 wpa_snprintf_hex(hex, hex_len, buf, len);
76 wpa_msg(hapd->msg_ctx, MSG_INFO,
77 "EAPOL-TX " MACSTR " %s",
78 MAC2STR(sta->addr), hex);
79 os_free(hex);
80 }
81 } else
82#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083 if (sta->flags & WLAN_STA_PREAUTH) {
84 rsn_preauth_send(hapd, sta, buf, len);
85 } else {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080086 hostapd_drv_hapd_send_eapol(
87 hapd, sta->addr, buf, len,
88 encrypt, hostapd_sta_flags_to_drv(sta->flags));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089 }
90
91 os_free(buf);
92}
93
94
95void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
96 struct sta_info *sta, int authorized)
97{
98 int res;
99
100 if (sta->flags & WLAN_STA_PREAUTH)
101 return;
102
103 if (authorized) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 ap_sta_set_authorized(hapd, sta, 1);
105 res = hostapd_set_authorized(hapd, sta, 1);
106 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
107 HOSTAPD_LEVEL_DEBUG, "authorizing port");
108 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 ap_sta_set_authorized(hapd, sta, 0);
110 res = hostapd_set_authorized(hapd, sta, 0);
111 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
112 HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
113 }
114
115 if (res && errno != ENOENT) {
Dmitry Shmidt96571392013-10-14 12:54:46 -0700116 wpa_printf(MSG_DEBUG, "Could not set station " MACSTR
117 " flags for kernel driver (errno=%d).",
118 MAC2STR(sta->addr), errno);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700119 }
120
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800121 if (authorized) {
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800122 os_get_reltime(&sta->connected_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700123 accounting_sta_start(hapd, sta);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800124 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700125}
126
127
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800128#ifndef CONFIG_FIPS
129#ifndef CONFIG_NO_RC4
130
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700131static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
132 struct sta_info *sta,
133 int idx, int broadcast,
134 u8 *key_data, size_t key_len)
135{
136 u8 *buf, *ekey;
137 struct ieee802_1x_hdr *hdr;
138 struct ieee802_1x_eapol_key *key;
139 size_t len, ekey_len;
140 struct eapol_state_machine *sm = sta->eapol_sm;
141
142 if (sm == NULL)
143 return;
144
145 len = sizeof(*key) + key_len;
146 buf = os_zalloc(sizeof(*hdr) + len);
147 if (buf == NULL)
148 return;
149
150 hdr = (struct ieee802_1x_hdr *) buf;
151 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
152 key->type = EAPOL_KEY_TYPE_RC4;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700153 WPA_PUT_BE16(key->key_length, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154 wpa_get_ntp_timestamp(key->replay_counter);
155
156 if (random_get_bytes(key->key_iv, sizeof(key->key_iv))) {
157 wpa_printf(MSG_ERROR, "Could not get random numbers");
158 os_free(buf);
159 return;
160 }
161
162 key->key_index = idx | (broadcast ? 0 : BIT(7));
163 if (hapd->conf->eapol_key_index_workaround) {
164 /* According to some information, WinXP Supplicant seems to
165 * interpret bit7 as an indication whether the key is to be
166 * activated, so make it possible to enable workaround that
167 * sets this bit for all keys. */
168 key->key_index |= BIT(7);
169 }
170
171 /* Key is encrypted using "Key-IV + MSK[0..31]" as the RC4-key and
172 * MSK[32..63] is used to sign the message. */
173 if (sm->eap_if->eapKeyData == NULL || sm->eap_if->eapKeyDataLen < 64) {
174 wpa_printf(MSG_ERROR, "No eapKeyData available for encrypting "
175 "and signing EAPOL-Key");
176 os_free(buf);
177 return;
178 }
179 os_memcpy((u8 *) (key + 1), key_data, key_len);
180 ekey_len = sizeof(key->key_iv) + 32;
181 ekey = os_malloc(ekey_len);
182 if (ekey == NULL) {
183 wpa_printf(MSG_ERROR, "Could not encrypt key");
184 os_free(buf);
185 return;
186 }
187 os_memcpy(ekey, key->key_iv, sizeof(key->key_iv));
188 os_memcpy(ekey + sizeof(key->key_iv), sm->eap_if->eapKeyData, 32);
189 rc4_skip(ekey, ekey_len, 0, (u8 *) (key + 1), key_len);
190 os_free(ekey);
191
192 /* This header is needed here for HMAC-MD5, but it will be regenerated
193 * in ieee802_1x_send() */
194 hdr->version = hapd->conf->eapol_version;
195 hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
196 hdr->length = host_to_be16(len);
197 hmac_md5(sm->eap_if->eapKeyData + 32, 32, buf, sizeof(*hdr) + len,
198 key->key_signature);
199
200 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key to " MACSTR
201 " (%s index=%d)", MAC2STR(sm->addr),
202 broadcast ? "broadcast" : "unicast", idx);
203 ieee802_1x_send(hapd, sta, IEEE802_1X_TYPE_EAPOL_KEY, (u8 *) key, len);
204 if (sta->eapol_sm)
205 sta->eapol_sm->dot1xAuthEapolFramesTx++;
206 os_free(buf);
207}
208
209
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800210static void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211{
212 struct eapol_authenticator *eapol = hapd->eapol_auth;
213 struct eapol_state_machine *sm = sta->eapol_sm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214
215 if (sm == NULL || !sm->eap_if->eapKeyData)
216 return;
217
218 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
219 MAC2STR(sta->addr));
220
221#ifndef CONFIG_NO_VLAN
Dmitry Shmidt5393a0f2013-08-08 11:23:34 -0700222 if (sta->vlan_id > 0 && sta->vlan_id <= MAX_VLAN_ID) {
223 wpa_printf(MSG_ERROR, "Using WEP with vlans is not supported.");
224 return;
225 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226#endif /* CONFIG_NO_VLAN */
Dmitry Shmidt5393a0f2013-08-08 11:23:34 -0700227
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228 if (eapol->default_wep_key) {
229 ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
230 eapol->default_wep_key,
231 hapd->conf->default_wep_key_len);
232 }
233
234 if (hapd->conf->individual_wep_key_len > 0) {
235 u8 *ikey;
236 ikey = os_malloc(hapd->conf->individual_wep_key_len);
237 if (ikey == NULL ||
238 random_get_bytes(ikey, hapd->conf->individual_wep_key_len))
239 {
240 wpa_printf(MSG_ERROR, "Could not generate random "
241 "individual WEP key.");
242 os_free(ikey);
243 return;
244 }
245
246 wpa_hexdump_key(MSG_DEBUG, "Individual WEP key",
247 ikey, hapd->conf->individual_wep_key_len);
248
249 ieee802_1x_tx_key_one(hapd, sta, 0, 0, ikey,
250 hapd->conf->individual_wep_key_len);
251
252 /* TODO: set encryption in TX callback, i.e., only after STA
253 * has ACKed EAPOL-Key frame */
254 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
255 sta->addr, 0, 1, NULL, 0, ikey,
256 hapd->conf->individual_wep_key_len)) {
257 wpa_printf(MSG_ERROR, "Could not set individual WEP "
258 "encryption.");
259 }
260
261 os_free(ikey);
262 }
263}
264
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800265#endif /* CONFIG_NO_RC4 */
266#endif /* CONFIG_FIPS */
267
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268
269const char *radius_mode_txt(struct hostapd_data *hapd)
270{
271 switch (hapd->iface->conf->hw_mode) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800272 case HOSTAPD_MODE_IEEE80211AD:
273 return "802.11ad";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700274 case HOSTAPD_MODE_IEEE80211A:
275 return "802.11a";
276 case HOSTAPD_MODE_IEEE80211G:
277 return "802.11g";
278 case HOSTAPD_MODE_IEEE80211B:
279 default:
280 return "802.11b";
281 }
282}
283
284
285int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
286{
287 int i;
288 u8 rate = 0;
289
290 for (i = 0; i < sta->supported_rates_len; i++)
291 if ((sta->supported_rates[i] & 0x7f) > rate)
292 rate = sta->supported_rates[i] & 0x7f;
293
294 return rate;
295}
296
297
298#ifndef CONFIG_NO_RADIUS
299static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
300 struct eapol_state_machine *sm,
301 const u8 *eap, size_t len)
302{
303 const u8 *identity;
304 size_t identity_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800305 const struct eap_hdr *hdr = (const struct eap_hdr *) eap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700306
307 if (len <= sizeof(struct eap_hdr) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800308 (hdr->code == EAP_CODE_RESPONSE &&
309 eap[sizeof(struct eap_hdr)] != EAP_TYPE_IDENTITY) ||
310 (hdr->code == EAP_CODE_INITIATE &&
311 eap[sizeof(struct eap_hdr)] != EAP_ERP_TYPE_REAUTH) ||
312 (hdr->code != EAP_CODE_RESPONSE &&
313 hdr->code != EAP_CODE_INITIATE))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314 return;
315
316 identity = eap_get_identity(sm->eap, &identity_len);
317 if (identity == NULL)
318 return;
319
320 /* Save station identity for future RADIUS packets */
321 os_free(sm->identity);
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700322 sm->identity = (u8 *) dup_binstr(identity, identity_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323 if (sm->identity == NULL) {
324 sm->identity_len = 0;
325 return;
326 }
327
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328 sm->identity_len = identity_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
330 HOSTAPD_LEVEL_DEBUG, "STA identity '%s'", sm->identity);
331 sm->dot1xAuthEapolRespIdFramesRx++;
332}
333
334
Dmitry Shmidt03658832014-08-13 11:03:49 -0700335static int add_common_radius_sta_attr_rsn(struct hostapd_data *hapd,
336 struct hostapd_radius_attr *req_attr,
337 struct sta_info *sta,
338 struct radius_msg *msg)
339{
340 u32 suite;
341 int ver, val;
342
343 ver = wpa_auth_sta_wpa_version(sta->wpa_sm);
344 val = wpa_auth_get_pairwise(sta->wpa_sm);
345 suite = wpa_cipher_to_suite(ver, val);
346 if (val != -1 &&
347 !hostapd_config_get_radius_attr(req_attr,
348 RADIUS_ATTR_WLAN_PAIRWISE_CIPHER) &&
349 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_PAIRWISE_CIPHER,
350 suite)) {
351 wpa_printf(MSG_ERROR, "Could not add WLAN-Pairwise-Cipher");
352 return -1;
353 }
354
Dmitry Shmidt41712582015-06-29 11:02:15 -0700355 suite = wpa_cipher_to_suite(((hapd->conf->wpa & 0x2) ||
356 hapd->conf->osen) ?
Dmitry Shmidt03658832014-08-13 11:03:49 -0700357 WPA_PROTO_RSN : WPA_PROTO_WPA,
358 hapd->conf->wpa_group);
359 if (!hostapd_config_get_radius_attr(req_attr,
360 RADIUS_ATTR_WLAN_GROUP_CIPHER) &&
361 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_GROUP_CIPHER,
362 suite)) {
363 wpa_printf(MSG_ERROR, "Could not add WLAN-Group-Cipher");
364 return -1;
365 }
366
367 val = wpa_auth_sta_key_mgmt(sta->wpa_sm);
368 suite = wpa_akm_to_suite(val);
369 if (val != -1 &&
370 !hostapd_config_get_radius_attr(req_attr,
371 RADIUS_ATTR_WLAN_AKM_SUITE) &&
372 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_WLAN_AKM_SUITE,
373 suite)) {
374 wpa_printf(MSG_ERROR, "Could not add WLAN-AKM-Suite");
375 return -1;
376 }
377
378#ifdef CONFIG_IEEE80211W
379 if (hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
380 suite = wpa_cipher_to_suite(WPA_PROTO_RSN,
381 hapd->conf->group_mgmt_cipher);
382 if (!hostapd_config_get_radius_attr(
383 req_attr, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER) &&
384 !radius_msg_add_attr_int32(
385 msg, RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER, suite)) {
386 wpa_printf(MSG_ERROR,
387 "Could not add WLAN-Group-Mgmt-Cipher");
388 return -1;
389 }
390 }
391#endif /* CONFIG_IEEE80211W */
392
393 return 0;
394}
395
396
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700397static int add_common_radius_sta_attr(struct hostapd_data *hapd,
398 struct hostapd_radius_attr *req_attr,
399 struct sta_info *sta,
400 struct radius_msg *msg)
401{
402 char buf[128];
403
404 if (!hostapd_config_get_radius_attr(req_attr,
405 RADIUS_ATTR_NAS_PORT) &&
406 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT, sta->aid)) {
407 wpa_printf(MSG_ERROR, "Could not add NAS-Port");
408 return -1;
409 }
410
411 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
412 MAC2STR(sta->addr));
413 buf[sizeof(buf) - 1] = '\0';
414 if (!radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
415 (u8 *) buf, os_strlen(buf))) {
416 wpa_printf(MSG_ERROR, "Could not add Calling-Station-Id");
417 return -1;
418 }
419
420 if (sta->flags & WLAN_STA_PREAUTH) {
421 os_strlcpy(buf, "IEEE 802.11i Pre-Authentication",
422 sizeof(buf));
423 } else {
424 os_snprintf(buf, sizeof(buf), "CONNECT %d%sMbps %s",
425 radius_sta_rate(hapd, sta) / 2,
426 (radius_sta_rate(hapd, sta) & 1) ? ".5" : "",
427 radius_mode_txt(hapd));
428 buf[sizeof(buf) - 1] = '\0';
429 }
430 if (!hostapd_config_get_radius_attr(req_attr,
431 RADIUS_ATTR_CONNECT_INFO) &&
432 !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
433 (u8 *) buf, os_strlen(buf))) {
434 wpa_printf(MSG_ERROR, "Could not add Connect-Info");
435 return -1;
436 }
437
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800438 if (sta->acct_session_id_hi || sta->acct_session_id_lo) {
439 os_snprintf(buf, sizeof(buf), "%08X-%08X",
440 sta->acct_session_id_hi, sta->acct_session_id_lo);
441 if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
442 (u8 *) buf, os_strlen(buf))) {
443 wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
444 return -1;
445 }
446 }
447
Dmitry Shmidt03658832014-08-13 11:03:49 -0700448#ifdef CONFIG_IEEE80211R
449 if (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
450 sta->wpa_sm &&
451 (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm)) ||
452 sta->auth_alg == WLAN_AUTH_FT) &&
453 !hostapd_config_get_radius_attr(req_attr,
454 RADIUS_ATTR_MOBILITY_DOMAIN_ID) &&
455 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_MOBILITY_DOMAIN_ID,
456 WPA_GET_BE16(
457 hapd->conf->mobility_domain))) {
458 wpa_printf(MSG_ERROR, "Could not add Mobility-Domain-Id");
459 return -1;
460 }
461#endif /* CONFIG_IEEE80211R */
462
Dmitry Shmidt41712582015-06-29 11:02:15 -0700463 if ((hapd->conf->wpa || hapd->conf->osen) && sta->wpa_sm &&
Dmitry Shmidt03658832014-08-13 11:03:49 -0700464 add_common_radius_sta_attr_rsn(hapd, req_attr, sta, msg) < 0)
465 return -1;
466
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700467 return 0;
468}
469
470
471int add_common_radius_attr(struct hostapd_data *hapd,
472 struct hostapd_radius_attr *req_attr,
473 struct sta_info *sta,
474 struct radius_msg *msg)
475{
476 char buf[128];
477 struct hostapd_radius_attr *attr;
478
479 if (!hostapd_config_get_radius_attr(req_attr,
480 RADIUS_ATTR_NAS_IP_ADDRESS) &&
481 hapd->conf->own_ip_addr.af == AF_INET &&
482 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
483 (u8 *) &hapd->conf->own_ip_addr.u.v4, 4)) {
484 wpa_printf(MSG_ERROR, "Could not add NAS-IP-Address");
485 return -1;
486 }
487
488#ifdef CONFIG_IPV6
489 if (!hostapd_config_get_radius_attr(req_attr,
490 RADIUS_ATTR_NAS_IPV6_ADDRESS) &&
491 hapd->conf->own_ip_addr.af == AF_INET6 &&
492 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IPV6_ADDRESS,
493 (u8 *) &hapd->conf->own_ip_addr.u.v6, 16)) {
494 wpa_printf(MSG_ERROR, "Could not add NAS-IPv6-Address");
495 return -1;
496 }
497#endif /* CONFIG_IPV6 */
498
499 if (!hostapd_config_get_radius_attr(req_attr,
500 RADIUS_ATTR_NAS_IDENTIFIER) &&
501 hapd->conf->nas_identifier &&
502 !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IDENTIFIER,
503 (u8 *) hapd->conf->nas_identifier,
504 os_strlen(hapd->conf->nas_identifier))) {
505 wpa_printf(MSG_ERROR, "Could not add NAS-Identifier");
506 return -1;
507 }
508
509 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT ":%s",
510 MAC2STR(hapd->own_addr),
511 wpa_ssid_txt(hapd->conf->ssid.ssid,
512 hapd->conf->ssid.ssid_len));
513 buf[sizeof(buf) - 1] = '\0';
514 if (!hostapd_config_get_radius_attr(req_attr,
515 RADIUS_ATTR_CALLED_STATION_ID) &&
516 !radius_msg_add_attr(msg, RADIUS_ATTR_CALLED_STATION_ID,
517 (u8 *) buf, os_strlen(buf))) {
518 wpa_printf(MSG_ERROR, "Could not add Called-Station-Id");
519 return -1;
520 }
521
522 if (!hostapd_config_get_radius_attr(req_attr,
523 RADIUS_ATTR_NAS_PORT_TYPE) &&
524 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
525 RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
526 wpa_printf(MSG_ERROR, "Could not add NAS-Port-Type");
527 return -1;
528 }
529
Dmitry Shmidt03658832014-08-13 11:03:49 -0700530#ifdef CONFIG_INTERWORKING
531 if (hapd->conf->interworking &&
532 !is_zero_ether_addr(hapd->conf->hessid)) {
533 os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
534 MAC2STR(hapd->conf->hessid));
535 buf[sizeof(buf) - 1] = '\0';
536 if (!hostapd_config_get_radius_attr(req_attr,
537 RADIUS_ATTR_WLAN_HESSID) &&
538 !radius_msg_add_attr(msg, RADIUS_ATTR_WLAN_HESSID,
539 (u8 *) buf, os_strlen(buf))) {
540 wpa_printf(MSG_ERROR, "Could not add WLAN-HESSID");
541 return -1;
542 }
543 }
544#endif /* CONFIG_INTERWORKING */
545
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700546 if (sta && add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0)
547 return -1;
548
549 for (attr = req_attr; attr; attr = attr->next) {
550 if (!radius_msg_add_attr(msg, attr->type,
551 wpabuf_head(attr->val),
552 wpabuf_len(attr->val))) {
553 wpa_printf(MSG_ERROR, "Could not add RADIUS "
554 "attribute");
555 return -1;
556 }
557 }
558
559 return 0;
560}
561
562
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
564 struct sta_info *sta,
565 const u8 *eap, size_t len)
566{
567 struct radius_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700568 struct eapol_state_machine *sm = sta->eapol_sm;
569
570 if (sm == NULL)
571 return;
572
573 ieee802_1x_learn_identity(hapd, sm, eap, len);
574
575 wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
576 "packet");
577
578 sm->radius_identifier = radius_client_get_id(hapd->radius);
579 msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
580 sm->radius_identifier);
581 if (msg == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800582 wpa_printf(MSG_INFO, "Could not create new RADIUS packet");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700583 return;
584 }
585
586 radius_msg_make_authenticator(msg, (u8 *) sta, sizeof(*sta));
587
588 if (sm->identity &&
589 !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
590 sm->identity, sm->identity_len)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800591 wpa_printf(MSG_INFO, "Could not add User-Name");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 goto fail;
593 }
594
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700595 if (add_common_radius_attr(hapd, hapd->conf->radius_auth_req_attr, sta,
596 msg) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598
599 /* TODO: should probably check MTU from driver config; 2304 is max for
600 * IEEE 802.11, but use 1400 to avoid problems with too large packets
601 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700602 if (!hostapd_config_get_radius_attr(hapd->conf->radius_auth_req_attr,
603 RADIUS_ATTR_FRAMED_MTU) &&
604 !radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800605 wpa_printf(MSG_INFO, "Could not add Framed-MTU");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700606 goto fail;
607 }
608
Dmitry Shmidt41712582015-06-29 11:02:15 -0700609 if (!radius_msg_add_eap(msg, eap, len)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800610 wpa_printf(MSG_INFO, "Could not add EAP-Message");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700611 goto fail;
612 }
613
614 /* State attribute must be copied if and only if this packet is
615 * Access-Request reply to the previous Access-Challenge */
616 if (sm->last_recv_radius &&
617 radius_msg_get_hdr(sm->last_recv_radius)->code ==
618 RADIUS_CODE_ACCESS_CHALLENGE) {
619 int res = radius_msg_copy_attr(msg, sm->last_recv_radius,
620 RADIUS_ATTR_STATE);
621 if (res < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800622 wpa_printf(MSG_INFO, "Could not copy State attribute from previous Access-Challenge");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700623 goto fail;
624 }
625 if (res > 0) {
626 wpa_printf(MSG_DEBUG, "Copied RADIUS State Attribute");
627 }
628 }
629
Dmitry Shmidt04949592012-07-19 12:16:46 -0700630 if (hapd->conf->radius_request_cui) {
631 const u8 *cui;
632 size_t cui_len;
633 /* Add previously learned CUI or nul CUI to request CUI */
634 if (sm->radius_cui) {
635 cui = wpabuf_head(sm->radius_cui);
636 cui_len = wpabuf_len(sm->radius_cui);
637 } else {
638 cui = (const u8 *) "\0";
639 cui_len = 1;
640 }
641 if (!radius_msg_add_attr(msg,
642 RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
643 cui, cui_len)) {
644 wpa_printf(MSG_ERROR, "Could not add CUI");
645 goto fail;
646 }
647 }
648
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800649#ifdef CONFIG_HS20
650 if (hapd->conf->hs20) {
651 u8 ver = 1; /* Release 2 */
652 if (!radius_msg_add_wfa(
653 msg, RADIUS_VENDOR_ATTR_WFA_HS20_AP_VERSION,
654 &ver, 1)) {
655 wpa_printf(MSG_ERROR, "Could not add HS 2.0 AP "
656 "version");
657 goto fail;
658 }
659
660 if (sta->hs20_ie && wpabuf_len(sta->hs20_ie) > 0) {
661 const u8 *pos;
662 u8 buf[3];
663 u16 id;
664 pos = wpabuf_head_u8(sta->hs20_ie);
665 buf[0] = (*pos) >> 4;
666 if (((*pos) & HS20_PPS_MO_ID_PRESENT) &&
667 wpabuf_len(sta->hs20_ie) >= 3)
668 id = WPA_GET_LE16(pos + 1);
669 else
670 id = 0;
671 WPA_PUT_BE16(buf + 1, id);
672 if (!radius_msg_add_wfa(
673 msg,
674 RADIUS_VENDOR_ATTR_WFA_HS20_STA_VERSION,
675 buf, sizeof(buf))) {
676 wpa_printf(MSG_ERROR, "Could not add HS 2.0 "
677 "STA version");
678 goto fail;
679 }
680 }
681 }
682#endif /* CONFIG_HS20 */
683
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 if (radius_client_send(hapd->radius, msg, RADIUS_AUTH, sta->addr) < 0)
685 goto fail;
686
687 return;
688
689 fail:
690 radius_msg_free(msg);
691}
692#endif /* CONFIG_NO_RADIUS */
693
694
695static void handle_eap_response(struct hostapd_data *hapd,
696 struct sta_info *sta, struct eap_hdr *eap,
697 size_t len)
698{
699 u8 type, *data;
700 struct eapol_state_machine *sm = sta->eapol_sm;
701 if (sm == NULL)
702 return;
703
704 data = (u8 *) (eap + 1);
705
706 if (len < sizeof(*eap) + 1) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800707 wpa_printf(MSG_INFO, "handle_eap_response: too short response data");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700708 return;
709 }
710
711 sm->eap_type_supp = type = data[0];
712
713 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
714 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
715 "id=%d len=%d) from STA: EAP Response-%s (%d)",
716 eap->code, eap->identifier, be_to_host16(eap->length),
717 eap_server_get_name(0, type), type);
718
719 sm->dot1xAuthEapolRespFramesRx++;
720
721 wpabuf_free(sm->eap_if->eapRespData);
722 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
723 sm->eapolEap = TRUE;
724}
725
726
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800727static void handle_eap_initiate(struct hostapd_data *hapd,
728 struct sta_info *sta, struct eap_hdr *eap,
729 size_t len)
730{
731#ifdef CONFIG_ERP
732 u8 type, *data;
733 struct eapol_state_machine *sm = sta->eapol_sm;
734
735 if (sm == NULL)
736 return;
737
738 if (len < sizeof(*eap) + 1) {
739 wpa_printf(MSG_INFO,
740 "handle_eap_initiate: too short response data");
741 return;
742 }
743
744 data = (u8 *) (eap + 1);
745 type = data[0];
746
747 hostapd_logger(hapd, sm->addr, HOSTAPD_MODULE_IEEE8021X,
748 HOSTAPD_LEVEL_DEBUG, "received EAP packet (code=%d "
749 "id=%d len=%d) from STA: EAP Initiate type %u",
750 eap->code, eap->identifier, be_to_host16(eap->length),
751 type);
752
753 wpabuf_free(sm->eap_if->eapRespData);
754 sm->eap_if->eapRespData = wpabuf_alloc_copy(eap, len);
755 sm->eapolEap = TRUE;
756#endif /* CONFIG_ERP */
757}
758
759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760/* Process incoming EAP packet from Supplicant */
761static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
762 u8 *buf, size_t len)
763{
764 struct eap_hdr *eap;
765 u16 eap_len;
766
767 if (len < sizeof(*eap)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800768 wpa_printf(MSG_INFO, " too short EAP packet");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 return;
770 }
771
772 eap = (struct eap_hdr *) buf;
773
774 eap_len = be_to_host16(eap->length);
775 wpa_printf(MSG_DEBUG, "EAP: code=%d identifier=%d length=%d",
776 eap->code, eap->identifier, eap_len);
777 if (eap_len < sizeof(*eap)) {
778 wpa_printf(MSG_DEBUG, " Invalid EAP length");
779 return;
780 } else if (eap_len > len) {
781 wpa_printf(MSG_DEBUG, " Too short frame to contain this EAP "
782 "packet");
783 return;
784 } else if (eap_len < len) {
785 wpa_printf(MSG_DEBUG, " Ignoring %lu extra bytes after EAP "
786 "packet", (unsigned long) len - eap_len);
787 }
788
789 switch (eap->code) {
790 case EAP_CODE_REQUEST:
791 wpa_printf(MSG_DEBUG, " (request)");
792 return;
793 case EAP_CODE_RESPONSE:
794 wpa_printf(MSG_DEBUG, " (response)");
795 handle_eap_response(hapd, sta, eap, eap_len);
796 break;
797 case EAP_CODE_SUCCESS:
798 wpa_printf(MSG_DEBUG, " (success)");
799 return;
800 case EAP_CODE_FAILURE:
801 wpa_printf(MSG_DEBUG, " (failure)");
802 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800803 case EAP_CODE_INITIATE:
804 wpa_printf(MSG_DEBUG, " (initiate)");
805 handle_eap_initiate(hapd, sta, eap, eap_len);
806 break;
807 case EAP_CODE_FINISH:
808 wpa_printf(MSG_DEBUG, " (finish)");
809 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 default:
811 wpa_printf(MSG_DEBUG, " (unknown code)");
812 return;
813 }
814}
815
816
817static struct eapol_state_machine *
818ieee802_1x_alloc_eapol_sm(struct hostapd_data *hapd, struct sta_info *sta)
819{
820 int flags = 0;
821 if (sta->flags & WLAN_STA_PREAUTH)
822 flags |= EAPOL_SM_PREAUTH;
823 if (sta->wpa_sm) {
824 flags |= EAPOL_SM_USES_WPA;
825 if (wpa_auth_sta_get_pmksa(sta->wpa_sm))
826 flags |= EAPOL_SM_FROM_PMKSA_CACHE;
827 }
828 return eapol_auth_alloc(hapd->eapol_auth, sta->addr, flags,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700829 sta->wps_ie, sta->p2p_ie, sta,
830 sta->identity, sta->radius_cui);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700831}
832
833
834/**
835 * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
836 * @hapd: hostapd BSS data
837 * @sa: Source address (sender of the EAPOL frame)
838 * @buf: EAPOL frame
839 * @len: Length of buf in octets
840 *
841 * This function is called for each incoming EAPOL frame from the interface
842 */
843void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
844 size_t len)
845{
846 struct sta_info *sta;
847 struct ieee802_1x_hdr *hdr;
848 struct ieee802_1x_eapol_key *key;
849 u16 datalen;
850 struct rsn_pmksa_cache_entry *pmksa;
851 int key_mgmt;
852
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800853 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700854 !hapd->conf->wps_state)
855 return;
856
857 wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
858 (unsigned long) len, MAC2STR(sa));
859 sta = ap_get_sta(hapd, sa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800860 if (!sta || (!(sta->flags & (WLAN_STA_ASSOC | WLAN_STA_PREAUTH)) &&
861 !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862 wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
863 "associated/Pre-authenticating STA");
864 return;
865 }
866
867 if (len < sizeof(*hdr)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800868 wpa_printf(MSG_INFO, " too short IEEE 802.1X packet");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869 return;
870 }
871
872 hdr = (struct ieee802_1x_hdr *) buf;
873 datalen = be_to_host16(hdr->length);
874 wpa_printf(MSG_DEBUG, " IEEE 802.1X: version=%d type=%d length=%d",
875 hdr->version, hdr->type, datalen);
876
877 if (len - sizeof(*hdr) < datalen) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800878 wpa_printf(MSG_INFO, " frame too short for this IEEE 802.1X packet");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879 if (sta->eapol_sm)
880 sta->eapol_sm->dot1xAuthEapLengthErrorFramesRx++;
881 return;
882 }
883 if (len - sizeof(*hdr) > datalen) {
884 wpa_printf(MSG_DEBUG, " ignoring %lu extra octets after "
885 "IEEE 802.1X packet",
886 (unsigned long) len - sizeof(*hdr) - datalen);
887 }
888
889 if (sta->eapol_sm) {
890 sta->eapol_sm->dot1xAuthLastEapolFrameVersion = hdr->version;
891 sta->eapol_sm->dot1xAuthEapolFramesRx++;
892 }
893
894 key = (struct ieee802_1x_eapol_key *) (hdr + 1);
895 if (datalen >= sizeof(struct ieee802_1x_eapol_key) &&
896 hdr->type == IEEE802_1X_TYPE_EAPOL_KEY &&
897 (key->type == EAPOL_KEY_TYPE_WPA ||
898 key->type == EAPOL_KEY_TYPE_RSN)) {
899 wpa_receive(hapd->wpa_auth, sta->wpa_sm, (u8 *) hdr,
900 sizeof(*hdr) + datalen);
901 return;
902 }
903
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800904 if (!hapd->conf->ieee802_1x && !hapd->conf->osen &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
906 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
907 "802.1X not enabled and WPS not used");
908 return;
909 }
910
911 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
912 if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
913 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore EAPOL message - "
914 "STA is using PSK");
915 return;
916 }
917
918 if (!sta->eapol_sm) {
919 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
920 if (!sta->eapol_sm)
921 return;
922
923#ifdef CONFIG_WPS
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800924 if (!hapd->conf->ieee802_1x && hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800925 u32 wflags = sta->flags & (WLAN_STA_WPS |
926 WLAN_STA_WPS2 |
927 WLAN_STA_MAYBE_WPS);
928 if (wflags == WLAN_STA_MAYBE_WPS ||
929 wflags == (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) {
930 /*
931 * Delay EAPOL frame transmission until a
932 * possible WPS STA initiates the handshake
933 * with EAPOL-Start. Only allow the wait to be
934 * skipped if the STA is known to support WPS
935 * 2.0.
936 */
937 wpa_printf(MSG_DEBUG, "WPS: Do not start "
938 "EAPOL until EAPOL-Start is "
939 "received");
940 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
941 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700942 }
943#endif /* CONFIG_WPS */
944
945 sta->eapol_sm->eap_if->portEnabled = TRUE;
946 }
947
948 /* since we support version 1, we can ignore version field and proceed
949 * as specified in version 1 standard [IEEE Std 802.1X-2001, 7.5.5] */
950 /* TODO: actually, we are not version 1 anymore.. However, Version 2
951 * does not change frame contents, so should be ok to process frames
952 * more or less identically. Some changes might be needed for
953 * verification of fields. */
954
955 switch (hdr->type) {
956 case IEEE802_1X_TYPE_EAP_PACKET:
957 handle_eap(hapd, sta, (u8 *) (hdr + 1), datalen);
958 break;
959
960 case IEEE802_1X_TYPE_EAPOL_START:
961 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
962 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Start "
963 "from STA");
964 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
965 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
966 if (pmksa) {
967 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
968 HOSTAPD_LEVEL_DEBUG, "cached PMKSA "
969 "available - ignore it since "
970 "STA sent EAPOL-Start");
971 wpa_auth_sta_clear_pmksa(sta->wpa_sm, pmksa);
972 }
973 sta->eapol_sm->eapolStart = TRUE;
974 sta->eapol_sm->dot1xAuthEapolStartFramesRx++;
975 eap_server_clear_identity(sta->eapol_sm->eap);
976 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
977 break;
978
979 case IEEE802_1X_TYPE_EAPOL_LOGOFF:
980 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
981 HOSTAPD_LEVEL_DEBUG, "received EAPOL-Logoff "
982 "from STA");
983 sta->acct_terminate_cause =
984 RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
985 accounting_sta_stop(hapd, sta);
986 sta->eapol_sm->eapolLogoff = TRUE;
987 sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
988 eap_server_clear_identity(sta->eapol_sm->eap);
989 break;
990
991 case IEEE802_1X_TYPE_EAPOL_KEY:
992 wpa_printf(MSG_DEBUG, " EAPOL-Key");
993 if (!ap_sta_is_authorized(sta)) {
994 wpa_printf(MSG_DEBUG, " Dropped key data from "
995 "unauthorized Supplicant");
996 break;
997 }
998 break;
999
1000 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
1001 wpa_printf(MSG_DEBUG, " EAPOL-Encapsulated-ASF-Alert");
1002 /* TODO: implement support for this; show data */
1003 break;
1004
1005 default:
1006 wpa_printf(MSG_DEBUG, " unknown IEEE 802.1X packet type");
1007 sta->eapol_sm->dot1xAuthInvalidEapolFramesRx++;
1008 break;
1009 }
1010
1011 eapol_auth_step(sta->eapol_sm);
1012}
1013
1014
1015/**
1016 * ieee802_1x_new_station - Start IEEE 802.1X authentication
1017 * @hapd: hostapd BSS data
1018 * @sta: The station
1019 *
1020 * This function is called to start IEEE 802.1X authentication when a new
1021 * station completes IEEE 802.11 association.
1022 */
1023void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
1024{
1025 struct rsn_pmksa_cache_entry *pmksa;
1026 int reassoc = 1;
1027 int force_1x = 0;
1028 int key_mgmt;
1029
1030#ifdef CONFIG_WPS
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001031 if (hapd->conf->wps_state &&
1032 ((hapd->conf->wpa && (sta->flags & WLAN_STA_MAYBE_WPS)) ||
1033 (sta->flags & WLAN_STA_WPS))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 /*
1035 * Need to enable IEEE 802.1X/EAPOL state machines for possible
1036 * WPS handshake even if IEEE 802.1X/EAPOL is not used for
1037 * authentication in this BSS.
1038 */
1039 force_1x = 1;
1040 }
1041#endif /* CONFIG_WPS */
1042
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001043 if (!force_1x && !hapd->conf->ieee802_1x && !hapd->conf->osen) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001044 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - "
1045 "802.1X not enabled or forced for WPS");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001046 /*
1047 * Clear any possible EAPOL authenticator state to support
1048 * reassociation change from WPS to PSK.
1049 */
1050 ieee802_1x_free_station(sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001051 return;
1052 }
1053
1054 key_mgmt = wpa_auth_sta_key_mgmt(sta->wpa_sm);
1055 if (key_mgmt != -1 && wpa_key_mgmt_wpa_psk(key_mgmt)) {
1056 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Ignore STA - using PSK");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001057 /*
1058 * Clear any possible EAPOL authenticator state to support
1059 * reassociation change from WPA-EAP to PSK.
1060 */
1061 ieee802_1x_free_station(sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001062 return;
1063 }
1064
1065 if (sta->eapol_sm == NULL) {
1066 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1067 HOSTAPD_LEVEL_DEBUG, "start authentication");
1068 sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta);
1069 if (sta->eapol_sm == NULL) {
1070 hostapd_logger(hapd, sta->addr,
1071 HOSTAPD_MODULE_IEEE8021X,
1072 HOSTAPD_LEVEL_INFO,
1073 "failed to allocate state machine");
1074 return;
1075 }
1076 reassoc = 0;
1077 }
1078
1079#ifdef CONFIG_WPS
1080 sta->eapol_sm->flags &= ~EAPOL_SM_WAIT_START;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001081 if (!hapd->conf->ieee802_1x && hapd->conf->wps_state &&
1082 !(sta->flags & WLAN_STA_WPS2)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001084 * Delay EAPOL frame transmission until a possible WPS STA
1085 * initiates the handshake with EAPOL-Start. Only allow the
1086 * wait to be skipped if the STA is known to support WPS 2.0.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001088 wpa_printf(MSG_DEBUG, "WPS: Do not start EAPOL until "
1089 "EAPOL-Start is received");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001090 sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
1091 }
1092#endif /* CONFIG_WPS */
1093
1094 sta->eapol_sm->eap_if->portEnabled = TRUE;
1095
1096#ifdef CONFIG_IEEE80211R
1097 if (sta->auth_alg == WLAN_AUTH_FT) {
1098 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1099 HOSTAPD_LEVEL_DEBUG,
1100 "PMK from FT - skip IEEE 802.1X/EAP");
1101 /* Setup EAPOL state machines to already authenticated state
1102 * because of existing FT information from R0KH. */
1103 sta->eapol_sm->keyRun = TRUE;
1104 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1105 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1106 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1107 sta->eapol_sm->authSuccess = TRUE;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001108 sta->eapol_sm->authFail = FALSE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001109 sta->eapol_sm->portValid = TRUE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 if (sta->eapol_sm->eap)
1111 eap_sm_notify_cached(sta->eapol_sm->eap);
1112 /* TODO: get vlan_id from R0KH using RRB message */
1113 return;
1114 }
1115#endif /* CONFIG_IEEE80211R */
1116
1117 pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1118 if (pmksa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001119 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1120 HOSTAPD_LEVEL_DEBUG,
1121 "PMK from PMKSA cache - skip IEEE 802.1X/EAP");
1122 /* Setup EAPOL state machines to already authenticated state
1123 * because of existing PMKSA information in the cache. */
1124 sta->eapol_sm->keyRun = TRUE;
1125 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1126 sta->eapol_sm->auth_pae_state = AUTH_PAE_AUTHENTICATING;
1127 sta->eapol_sm->be_auth_state = BE_AUTH_SUCCESS;
1128 sta->eapol_sm->authSuccess = TRUE;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001129 sta->eapol_sm->authFail = FALSE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130 if (sta->eapol_sm->eap)
1131 eap_sm_notify_cached(sta->eapol_sm->eap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132 pmksa_cache_to_eapol_data(pmksa, sta->eapol_sm);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001133 ap_sta_bind_vlan(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001134 } else {
1135 if (reassoc) {
1136 /*
1137 * Force EAPOL state machines to start
1138 * re-authentication without having to wait for the
1139 * Supplicant to send EAPOL-Start.
1140 */
1141 sta->eapol_sm->reAuthenticate = TRUE;
1142 }
1143 eapol_auth_step(sta->eapol_sm);
1144 }
1145}
1146
1147
1148void ieee802_1x_free_station(struct sta_info *sta)
1149{
1150 struct eapol_state_machine *sm = sta->eapol_sm;
1151
1152 if (sm == NULL)
1153 return;
1154
1155 sta->eapol_sm = NULL;
1156
1157#ifndef CONFIG_NO_RADIUS
1158 radius_msg_free(sm->last_recv_radius);
1159 radius_free_class(&sm->radius_class);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001160 wpabuf_free(sm->radius_cui);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001161#endif /* CONFIG_NO_RADIUS */
1162
1163 os_free(sm->identity);
1164 eapol_auth_free(sm);
1165}
1166
1167
1168#ifndef CONFIG_NO_RADIUS
1169static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
1170 struct sta_info *sta)
1171{
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001172 struct wpabuf *eap;
1173 const struct eap_hdr *hdr;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001174 int eap_type = -1;
1175 char buf[64];
1176 struct radius_msg *msg;
1177 struct eapol_state_machine *sm = sta->eapol_sm;
1178
1179 if (sm == NULL || sm->last_recv_radius == NULL) {
1180 if (sm)
1181 sm->eap_if->aaaEapNoReq = TRUE;
1182 return;
1183 }
1184
1185 msg = sm->last_recv_radius;
1186
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001187 eap = radius_msg_get_eap(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001188 if (eap == NULL) {
1189 /* RFC 3579, Chap. 2.6.3:
1190 * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
1191 * attribute */
1192 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1193 HOSTAPD_LEVEL_WARNING, "could not extract "
1194 "EAP-Message from RADIUS message");
1195 sm->eap_if->aaaEapNoReq = TRUE;
1196 return;
1197 }
1198
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001199 if (wpabuf_len(eap) < sizeof(*hdr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001200 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1201 HOSTAPD_LEVEL_WARNING, "too short EAP packet "
1202 "received from authentication server");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001203 wpabuf_free(eap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001204 sm->eap_if->aaaEapNoReq = TRUE;
1205 return;
1206 }
1207
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001208 if (wpabuf_len(eap) > sizeof(*hdr))
1209 eap_type = (wpabuf_head_u8(eap))[sizeof(*hdr)];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001210
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001211 hdr = wpabuf_head(eap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001212 switch (hdr->code) {
1213 case EAP_CODE_REQUEST:
1214 if (eap_type >= 0)
1215 sm->eap_type_authsrv = eap_type;
1216 os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001217 eap_server_get_name(0, eap_type), eap_type);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001218 break;
1219 case EAP_CODE_RESPONSE:
1220 os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001221 eap_server_get_name(0, eap_type), eap_type);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 break;
1223 case EAP_CODE_SUCCESS:
1224 os_strlcpy(buf, "EAP Success", sizeof(buf));
1225 break;
1226 case EAP_CODE_FAILURE:
1227 os_strlcpy(buf, "EAP Failure", sizeof(buf));
1228 break;
1229 default:
1230 os_strlcpy(buf, "unknown EAP code", sizeof(buf));
1231 break;
1232 }
1233 buf[sizeof(buf) - 1] = '\0';
1234 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1235 HOSTAPD_LEVEL_DEBUG, "decapsulated EAP packet (code=%d "
1236 "id=%d len=%d) from RADIUS server: %s",
1237 hdr->code, hdr->identifier, be_to_host16(hdr->length),
1238 buf);
1239 sm->eap_if->aaaEapReq = TRUE;
1240
1241 wpabuf_free(sm->eap_if->aaaEapReqData);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001242 sm->eap_if->aaaEapReqData = eap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001243}
1244
1245
1246static void ieee802_1x_get_keys(struct hostapd_data *hapd,
1247 struct sta_info *sta, struct radius_msg *msg,
1248 struct radius_msg *req,
1249 const u8 *shared_secret,
1250 size_t shared_secret_len)
1251{
1252 struct radius_ms_mppe_keys *keys;
1253 struct eapol_state_machine *sm = sta->eapol_sm;
1254 if (sm == NULL)
1255 return;
1256
1257 keys = radius_msg_get_ms_keys(msg, req, shared_secret,
1258 shared_secret_len);
1259
1260 if (keys && keys->send && keys->recv) {
1261 size_t len = keys->send_len + keys->recv_len;
1262 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
1263 keys->send, keys->send_len);
1264 wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
1265 keys->recv, keys->recv_len);
1266
1267 os_free(sm->eap_if->aaaEapKeyData);
1268 sm->eap_if->aaaEapKeyData = os_malloc(len);
1269 if (sm->eap_if->aaaEapKeyData) {
1270 os_memcpy(sm->eap_if->aaaEapKeyData, keys->recv,
1271 keys->recv_len);
1272 os_memcpy(sm->eap_if->aaaEapKeyData + keys->recv_len,
1273 keys->send, keys->send_len);
1274 sm->eap_if->aaaEapKeyDataLen = len;
1275 sm->eap_if->aaaEapKeyAvailable = TRUE;
1276 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001277 } else {
1278 wpa_printf(MSG_DEBUG,
1279 "MS-MPPE: 1x_get_keys, could not get keys: %p send: %p recv: %p",
1280 keys, keys ? keys->send : NULL,
1281 keys ? keys->recv : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001282 }
1283
1284 if (keys) {
1285 os_free(keys->send);
1286 os_free(keys->recv);
1287 os_free(keys);
1288 }
1289}
1290
1291
1292static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
1293 struct sta_info *sta,
1294 struct radius_msg *msg)
1295{
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001296 u8 *attr_class;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001297 size_t class_len;
1298 struct eapol_state_machine *sm = sta->eapol_sm;
1299 int count, i;
1300 struct radius_attr_data *nclass;
1301 size_t nclass_count;
1302
1303 if (!hapd->conf->radius->acct_server || hapd->radius == NULL ||
1304 sm == NULL)
1305 return;
1306
1307 radius_free_class(&sm->radius_class);
1308 count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
1309 if (count <= 0)
1310 return;
1311
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001312 nclass = os_calloc(count, sizeof(struct radius_attr_data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001313 if (nclass == NULL)
1314 return;
1315
1316 nclass_count = 0;
1317
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001318 attr_class = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319 for (i = 0; i < count; i++) {
1320 do {
1321 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CLASS,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001322 &attr_class, &class_len,
1323 attr_class) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001324 i = count;
1325 break;
1326 }
1327 } while (class_len < 1);
1328
1329 nclass[nclass_count].data = os_malloc(class_len);
1330 if (nclass[nclass_count].data == NULL)
1331 break;
1332
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001333 os_memcpy(nclass[nclass_count].data, attr_class, class_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001334 nclass[nclass_count].len = class_len;
1335 nclass_count++;
1336 }
1337
1338 sm->radius_class.attr = nclass;
1339 sm->radius_class.count = nclass_count;
1340 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Stored %lu RADIUS Class "
1341 "attributes for " MACSTR,
1342 (unsigned long) sm->radius_class.count,
1343 MAC2STR(sta->addr));
1344}
1345
1346
1347/* Update sta->identity based on User-Name attribute in Access-Accept */
1348static void ieee802_1x_update_sta_identity(struct hostapd_data *hapd,
1349 struct sta_info *sta,
1350 struct radius_msg *msg)
1351{
1352 u8 *buf, *identity;
1353 size_t len;
1354 struct eapol_state_machine *sm = sta->eapol_sm;
1355
1356 if (sm == NULL)
1357 return;
1358
1359 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_USER_NAME, &buf, &len,
1360 NULL) < 0)
1361 return;
1362
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001363 identity = (u8 *) dup_binstr(buf, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001364 if (identity == NULL)
1365 return;
1366
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001367 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1368 HOSTAPD_LEVEL_DEBUG, "old identity '%s' updated with "
1369 "User-Name from Access-Accept '%s'",
1370 sm->identity ? (char *) sm->identity : "N/A",
1371 (char *) identity);
1372
1373 os_free(sm->identity);
1374 sm->identity = identity;
1375 sm->identity_len = len;
1376}
1377
1378
Dmitry Shmidt04949592012-07-19 12:16:46 -07001379/* Update CUI based on Chargeable-User-Identity attribute in Access-Accept */
1380static void ieee802_1x_update_sta_cui(struct hostapd_data *hapd,
1381 struct sta_info *sta,
1382 struct radius_msg *msg)
1383{
1384 struct eapol_state_machine *sm = sta->eapol_sm;
1385 struct wpabuf *cui;
1386 u8 *buf;
1387 size_t len;
1388
1389 if (sm == NULL)
1390 return;
1391
1392 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_CHARGEABLE_USER_IDENTITY,
1393 &buf, &len, NULL) < 0)
1394 return;
1395
1396 cui = wpabuf_alloc_copy(buf, len);
1397 if (cui == NULL)
1398 return;
1399
1400 wpabuf_free(sm->radius_cui);
1401 sm->radius_cui = cui;
1402}
1403
1404
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001405#ifdef CONFIG_HS20
1406
1407static void ieee802_1x_hs20_sub_rem(struct sta_info *sta, u8 *pos, size_t len)
1408{
1409 sta->remediation = 1;
1410 os_free(sta->remediation_url);
1411 if (len > 2) {
1412 sta->remediation_url = os_malloc(len);
1413 if (!sta->remediation_url)
1414 return;
1415 sta->remediation_method = pos[0];
1416 os_memcpy(sta->remediation_url, pos + 1, len - 1);
1417 sta->remediation_url[len - 1] = '\0';
1418 wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
1419 "for " MACSTR " - server method %u URL %s",
1420 MAC2STR(sta->addr), sta->remediation_method,
1421 sta->remediation_url);
1422 } else {
1423 sta->remediation_url = NULL;
1424 wpa_printf(MSG_DEBUG, "HS 2.0: Subscription remediation needed "
1425 "for " MACSTR, MAC2STR(sta->addr));
1426 }
1427 /* TODO: assign the STA into remediation VLAN or add filtering */
1428}
1429
1430
1431static void ieee802_1x_hs20_deauth_req(struct hostapd_data *hapd,
1432 struct sta_info *sta, u8 *pos,
1433 size_t len)
1434{
1435 if (len < 3)
1436 return; /* Malformed information */
1437 sta->hs20_deauth_requested = 1;
1438 wpa_printf(MSG_DEBUG, "HS 2.0: Deauthentication request - Code %u "
1439 "Re-auth Delay %u",
1440 *pos, WPA_GET_LE16(pos + 1));
1441 wpabuf_free(sta->hs20_deauth_req);
1442 sta->hs20_deauth_req = wpabuf_alloc(len + 1);
1443 if (sta->hs20_deauth_req) {
1444 wpabuf_put_data(sta->hs20_deauth_req, pos, 3);
1445 wpabuf_put_u8(sta->hs20_deauth_req, len - 3);
1446 wpabuf_put_data(sta->hs20_deauth_req, pos + 3, len - 3);
1447 }
1448 ap_sta_session_timeout(hapd, sta, hapd->conf->hs20_deauth_req_timeout);
1449}
1450
1451
1452static void ieee802_1x_hs20_session_info(struct hostapd_data *hapd,
1453 struct sta_info *sta, u8 *pos,
1454 size_t len, int session_timeout)
1455{
1456 unsigned int swt;
1457 int warning_time, beacon_int;
1458
1459 if (len < 1)
1460 return; /* Malformed information */
1461 os_free(sta->hs20_session_info_url);
1462 sta->hs20_session_info_url = os_malloc(len);
1463 if (sta->hs20_session_info_url == NULL)
1464 return;
1465 swt = pos[0];
1466 os_memcpy(sta->hs20_session_info_url, pos + 1, len - 1);
1467 sta->hs20_session_info_url[len - 1] = '\0';
1468 wpa_printf(MSG_DEBUG, "HS 2.0: Session Information URL='%s' SWT=%u "
1469 "(session_timeout=%d)",
1470 sta->hs20_session_info_url, swt, session_timeout);
1471 if (session_timeout < 0) {
1472 wpa_printf(MSG_DEBUG, "HS 2.0: No Session-Timeout set - ignore session info URL");
1473 return;
1474 }
1475 if (swt == 255)
1476 swt = 1; /* Use one minute as the AP selected value */
1477
1478 if ((unsigned int) session_timeout < swt * 60)
1479 warning_time = 0;
1480 else
1481 warning_time = session_timeout - swt * 60;
1482
1483 beacon_int = hapd->iconf->beacon_int;
1484 if (beacon_int < 1)
1485 beacon_int = 100; /* best guess */
1486 sta->hs20_disassoc_timer = swt * 60 * 1000 / beacon_int * 125 / 128;
1487 if (sta->hs20_disassoc_timer > 65535)
1488 sta->hs20_disassoc_timer = 65535;
1489
1490 ap_sta_session_warning_timeout(hapd, sta, warning_time);
1491}
1492
1493#endif /* CONFIG_HS20 */
1494
1495
1496static void ieee802_1x_check_hs20(struct hostapd_data *hapd,
1497 struct sta_info *sta,
1498 struct radius_msg *msg,
1499 int session_timeout)
1500{
1501#ifdef CONFIG_HS20
1502 u8 *buf, *pos, *end, type, sublen;
1503 size_t len;
1504
1505 buf = NULL;
1506 sta->remediation = 0;
1507 sta->hs20_deauth_requested = 0;
1508
1509 for (;;) {
1510 if (radius_msg_get_attr_ptr(msg, RADIUS_ATTR_VENDOR_SPECIFIC,
1511 &buf, &len, buf) < 0)
1512 break;
1513 if (len < 6)
1514 continue;
1515 pos = buf;
1516 end = buf + len;
1517 if (WPA_GET_BE32(pos) != RADIUS_VENDOR_ID_WFA)
1518 continue;
1519 pos += 4;
1520
1521 type = *pos++;
1522 sublen = *pos++;
1523 if (sublen < 2)
1524 continue; /* invalid length */
1525 sublen -= 2; /* skip header */
1526 if (pos + sublen > end)
1527 continue; /* invalid WFA VSA */
1528
1529 switch (type) {
1530 case RADIUS_VENDOR_ATTR_WFA_HS20_SUBSCR_REMEDIATION:
1531 ieee802_1x_hs20_sub_rem(sta, pos, sublen);
1532 break;
1533 case RADIUS_VENDOR_ATTR_WFA_HS20_DEAUTH_REQ:
1534 ieee802_1x_hs20_deauth_req(hapd, sta, pos, sublen);
1535 break;
1536 case RADIUS_VENDOR_ATTR_WFA_HS20_SESSION_INFO_URL:
1537 ieee802_1x_hs20_session_info(hapd, sta, pos, sublen,
1538 session_timeout);
1539 break;
1540 }
1541 }
1542#endif /* CONFIG_HS20 */
1543}
1544
1545
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001546struct sta_id_search {
1547 u8 identifier;
1548 struct eapol_state_machine *sm;
1549};
1550
1551
1552static int ieee802_1x_select_radius_identifier(struct hostapd_data *hapd,
1553 struct sta_info *sta,
1554 void *ctx)
1555{
1556 struct sta_id_search *id_search = ctx;
1557 struct eapol_state_machine *sm = sta->eapol_sm;
1558
1559 if (sm && sm->radius_identifier >= 0 &&
1560 sm->radius_identifier == id_search->identifier) {
1561 id_search->sm = sm;
1562 return 1;
1563 }
1564 return 0;
1565}
1566
1567
1568static struct eapol_state_machine *
1569ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
1570{
1571 struct sta_id_search id_search;
1572 id_search.identifier = identifier;
1573 id_search.sm = NULL;
1574 ap_for_each_sta(hapd, ieee802_1x_select_radius_identifier, &id_search);
1575 return id_search.sm;
1576}
1577
1578
1579/**
1580 * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
1581 * @msg: RADIUS response message
1582 * @req: RADIUS request message
1583 * @shared_secret: RADIUS shared secret
1584 * @shared_secret_len: Length of shared_secret in octets
1585 * @data: Context data (struct hostapd_data *)
1586 * Returns: Processing status
1587 */
1588static RadiusRxResult
1589ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
1590 const u8 *shared_secret, size_t shared_secret_len,
1591 void *data)
1592{
1593 struct hostapd_data *hapd = data;
1594 struct sta_info *sta;
1595 u32 session_timeout = 0, termination_action, acct_interim_interval;
Dmitry Shmidt83474442015-04-15 13:47:09 -07001596 int session_timeout_set, vlan_id = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001597 struct eapol_state_machine *sm;
1598 int override_eapReq = 0;
1599 struct radius_hdr *hdr = radius_msg_get_hdr(msg);
1600
1601 sm = ieee802_1x_search_radius_identifier(hapd, hdr->identifier);
1602 if (sm == NULL) {
1603 wpa_printf(MSG_DEBUG, "IEEE 802.1X: Could not find matching "
1604 "station for this RADIUS message");
1605 return RADIUS_RX_UNKNOWN;
1606 }
1607 sta = sm->sta;
1608
1609 /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
1610 * present when packet contains an EAP-Message attribute */
1611 if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
1612 radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
1613 0) < 0 &&
1614 radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
1615 wpa_printf(MSG_DEBUG, "Allowing RADIUS Access-Reject without "
1616 "Message-Authenticator since it does not include "
1617 "EAP-Message");
1618 } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
1619 req, 1)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001620 wpa_printf(MSG_INFO, "Incoming RADIUS packet did not have correct Message-Authenticator - dropped");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621 return RADIUS_RX_INVALID_AUTHENTICATOR;
1622 }
1623
1624 if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
1625 hdr->code != RADIUS_CODE_ACCESS_REJECT &&
1626 hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001627 wpa_printf(MSG_INFO, "Unknown RADIUS message code");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001628 return RADIUS_RX_UNKNOWN;
1629 }
1630
1631 sm->radius_identifier = -1;
1632 wpa_printf(MSG_DEBUG, "RADIUS packet matching with station " MACSTR,
1633 MAC2STR(sta->addr));
1634
1635 radius_msg_free(sm->last_recv_radius);
1636 sm->last_recv_radius = msg;
1637
1638 session_timeout_set =
1639 !radius_msg_get_attr_int32(msg, RADIUS_ATTR_SESSION_TIMEOUT,
1640 &session_timeout);
1641 if (radius_msg_get_attr_int32(msg, RADIUS_ATTR_TERMINATION_ACTION,
1642 &termination_action))
1643 termination_action = RADIUS_TERMINATION_ACTION_DEFAULT;
1644
1645 if (hapd->conf->acct_interim_interval == 0 &&
1646 hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
1647 radius_msg_get_attr_int32(msg, RADIUS_ATTR_ACCT_INTERIM_INTERVAL,
1648 &acct_interim_interval) == 0) {
1649 if (acct_interim_interval < 60) {
1650 hostapd_logger(hapd, sta->addr,
1651 HOSTAPD_MODULE_IEEE8021X,
1652 HOSTAPD_LEVEL_INFO,
1653 "ignored too small "
1654 "Acct-Interim-Interval %d",
1655 acct_interim_interval);
1656 } else
1657 sta->acct_interim_interval = acct_interim_interval;
1658 }
1659
1660
1661 switch (hdr->code) {
1662 case RADIUS_CODE_ACCESS_ACCEPT:
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001663 if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED)
Dmitry Shmidt83474442015-04-15 13:47:09 -07001664 vlan_id = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001665#ifndef CONFIG_NO_VLAN
Dmitry Shmidt83474442015-04-15 13:47:09 -07001666 else
1667 vlan_id = radius_msg_get_vlanid(msg);
1668 if (vlan_id > 0 &&
1669 hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001670 hostapd_logger(hapd, sta->addr,
1671 HOSTAPD_MODULE_RADIUS,
1672 HOSTAPD_LEVEL_INFO,
Dmitry Shmidt83474442015-04-15 13:47:09 -07001673 "VLAN ID %d", vlan_id);
1674 } else if (vlan_id > 0) {
1675 sta->eapol_sm->authFail = TRUE;
1676 hostapd_logger(hapd, sta->addr,
1677 HOSTAPD_MODULE_RADIUS,
1678 HOSTAPD_LEVEL_INFO,
1679 "Invalid VLAN ID %d received from RADIUS server",
1680 vlan_id);
1681 break;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001682 } else if (hapd->conf->ssid.dynamic_vlan ==
1683 DYNAMIC_VLAN_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001684 sta->eapol_sm->authFail = TRUE;
1685 hostapd_logger(hapd, sta->addr,
1686 HOSTAPD_MODULE_IEEE8021X,
1687 HOSTAPD_LEVEL_INFO, "authentication "
1688 "server did not include required VLAN "
1689 "ID in Access-Accept");
1690 break;
1691 }
1692#endif /* CONFIG_NO_VLAN */
1693
Dmitry Shmidt83474442015-04-15 13:47:09 -07001694 sta->vlan_id = vlan_id;
1695 if ((sta->flags & WLAN_STA_ASSOC) &&
1696 ap_sta_bind_vlan(hapd, sta) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697 break;
1698
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001699 sta->session_timeout_set = !!session_timeout_set;
1700 sta->session_timeout = session_timeout;
1701
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001702 /* RFC 3580, Ch. 3.17 */
1703 if (session_timeout_set && termination_action ==
1704 RADIUS_TERMINATION_ACTION_RADIUS_REQUEST) {
1705 sm->reAuthPeriod = session_timeout;
1706 } else if (session_timeout_set)
1707 ap_sta_session_timeout(hapd, sta, session_timeout);
1708
1709 sm->eap_if->aaaSuccess = TRUE;
1710 override_eapReq = 1;
1711 ieee802_1x_get_keys(hapd, sta, msg, req, shared_secret,
1712 shared_secret_len);
1713 ieee802_1x_store_radius_class(hapd, sta, msg);
1714 ieee802_1x_update_sta_identity(hapd, sta, msg);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001715 ieee802_1x_update_sta_cui(hapd, sta, msg);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001716 ieee802_1x_check_hs20(hapd, sta, msg,
1717 session_timeout_set ?
1718 (int) session_timeout : -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001719 break;
1720 case RADIUS_CODE_ACCESS_REJECT:
1721 sm->eap_if->aaaFail = TRUE;
1722 override_eapReq = 1;
1723 break;
1724 case RADIUS_CODE_ACCESS_CHALLENGE:
1725 sm->eap_if->aaaEapReq = TRUE;
1726 if (session_timeout_set) {
1727 /* RFC 2869, Ch. 2.3.2; RFC 3580, Ch. 3.17 */
1728 sm->eap_if->aaaMethodTimeout = session_timeout;
1729 hostapd_logger(hapd, sm->addr,
1730 HOSTAPD_MODULE_IEEE8021X,
1731 HOSTAPD_LEVEL_DEBUG,
1732 "using EAP timeout of %d seconds (from "
1733 "RADIUS)",
1734 sm->eap_if->aaaMethodTimeout);
1735 } else {
1736 /*
1737 * Use dynamic retransmission behavior per EAP
1738 * specification.
1739 */
1740 sm->eap_if->aaaMethodTimeout = 0;
1741 }
1742 break;
1743 }
1744
1745 ieee802_1x_decapsulate_radius(hapd, sta);
1746 if (override_eapReq)
1747 sm->eap_if->aaaEapReq = FALSE;
1748
1749 eapol_auth_step(sm);
1750
1751 return RADIUS_RX_QUEUED;
1752}
1753#endif /* CONFIG_NO_RADIUS */
1754
1755
1756void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
1757{
1758 struct eapol_state_machine *sm = sta->eapol_sm;
1759 if (sm == NULL)
1760 return;
1761
1762 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
1763 HOSTAPD_LEVEL_DEBUG, "aborting authentication");
1764
1765#ifndef CONFIG_NO_RADIUS
1766 radius_msg_free(sm->last_recv_radius);
1767 sm->last_recv_radius = NULL;
1768#endif /* CONFIG_NO_RADIUS */
1769
1770 if (sm->eap_if->eapTimeout) {
1771 /*
1772 * Disconnect the STA since it did not reply to the last EAP
1773 * request and we cannot continue EAP processing (EAP-Failure
1774 * could only be sent if the EAP peer actually replied).
1775 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001776 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "EAP Timeout, STA " MACSTR,
1777 MAC2STR(sta->addr));
1778
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001779 sm->eap_if->portEnabled = FALSE;
1780 ap_sta_disconnect(hapd, sta, sta->addr,
1781 WLAN_REASON_PREV_AUTH_NOT_VALID);
1782 }
1783}
1784
1785
1786static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
1787{
1788 struct eapol_authenticator *eapol = hapd->eapol_auth;
1789
1790 if (hapd->conf->default_wep_key_len < 1)
1791 return 0;
1792
1793 os_free(eapol->default_wep_key);
1794 eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
1795 if (eapol->default_wep_key == NULL ||
1796 random_get_bytes(eapol->default_wep_key,
1797 hapd->conf->default_wep_key_len)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001798 wpa_printf(MSG_INFO, "Could not generate random WEP key");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001799 os_free(eapol->default_wep_key);
1800 eapol->default_wep_key = NULL;
1801 return -1;
1802 }
1803
1804 wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
1805 eapol->default_wep_key,
1806 hapd->conf->default_wep_key_len);
1807
1808 return 0;
1809}
1810
1811
1812static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
1813 struct sta_info *sta, void *ctx)
1814{
1815 if (sta->eapol_sm) {
1816 sta->eapol_sm->eap_if->eapKeyAvailable = TRUE;
1817 eapol_auth_step(sta->eapol_sm);
1818 }
1819 return 0;
1820}
1821
1822
1823static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
1824{
1825 struct hostapd_data *hapd = eloop_ctx;
1826 struct eapol_authenticator *eapol = hapd->eapol_auth;
1827
1828 if (eapol->default_wep_key_idx >= 3)
1829 eapol->default_wep_key_idx =
1830 hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
1831 else
1832 eapol->default_wep_key_idx++;
1833
1834 wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
1835 eapol->default_wep_key_idx);
1836
1837 if (ieee802_1x_rekey_broadcast(hapd)) {
1838 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
1839 HOSTAPD_LEVEL_WARNING, "failed to generate a "
1840 "new broadcast key");
1841 os_free(eapol->default_wep_key);
1842 eapol->default_wep_key = NULL;
1843 return;
1844 }
1845
1846 /* TODO: Could setup key for RX here, but change default TX keyid only
1847 * after new broadcast key has been sent to all stations. */
1848 if (hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
1849 broadcast_ether_addr,
1850 eapol->default_wep_key_idx, 1, NULL, 0,
1851 eapol->default_wep_key,
1852 hapd->conf->default_wep_key_len)) {
1853 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
1854 HOSTAPD_LEVEL_WARNING, "failed to configure a "
1855 "new broadcast key");
1856 os_free(eapol->default_wep_key);
1857 eapol->default_wep_key = NULL;
1858 return;
1859 }
1860
1861 ap_for_each_sta(hapd, ieee802_1x_sta_key_available, NULL);
1862
1863 if (hapd->conf->wep_rekeying_period > 0) {
1864 eloop_register_timeout(hapd->conf->wep_rekeying_period, 0,
1865 ieee802_1x_rekey, hapd, NULL);
1866 }
1867}
1868
1869
1870static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
1871 const u8 *data, size_t datalen)
1872{
1873#ifdef CONFIG_WPS
1874 struct sta_info *sta = sta_ctx;
1875
1876 if ((sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)) ==
1877 WLAN_STA_MAYBE_WPS) {
1878 const u8 *identity;
1879 size_t identity_len;
1880 struct eapol_state_machine *sm = sta->eapol_sm;
1881
1882 identity = eap_get_identity(sm->eap, &identity_len);
1883 if (identity &&
1884 ((identity_len == WSC_ID_ENROLLEE_LEN &&
1885 os_memcmp(identity, WSC_ID_ENROLLEE,
1886 WSC_ID_ENROLLEE_LEN) == 0) ||
1887 (identity_len == WSC_ID_REGISTRAR_LEN &&
1888 os_memcmp(identity, WSC_ID_REGISTRAR,
1889 WSC_ID_REGISTRAR_LEN) == 0))) {
1890 wpa_printf(MSG_DEBUG, "WPS: WLAN_STA_MAYBE_WPS -> "
1891 "WLAN_STA_WPS");
1892 sta->flags |= WLAN_STA_WPS;
1893 }
1894 }
1895#endif /* CONFIG_WPS */
1896
1897 ieee802_1x_send(ctx, sta_ctx, type, data, datalen);
1898}
1899
1900
1901static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
1902 const u8 *data, size_t datalen)
1903{
1904#ifndef CONFIG_NO_RADIUS
1905 struct hostapd_data *hapd = ctx;
1906 struct sta_info *sta = sta_ctx;
1907
1908 ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
1909#endif /* CONFIG_NO_RADIUS */
1910}
1911
1912
1913static void _ieee802_1x_finished(void *ctx, void *sta_ctx, int success,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001914 int preauth, int remediation)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001915{
1916 struct hostapd_data *hapd = ctx;
1917 struct sta_info *sta = sta_ctx;
1918 if (preauth)
1919 rsn_preauth_finished(hapd, sta, success);
1920 else
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001921 ieee802_1x_finished(hapd, sta, success, remediation);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001922}
1923
1924
1925static int ieee802_1x_get_eap_user(void *ctx, const u8 *identity,
1926 size_t identity_len, int phase2,
1927 struct eap_user *user)
1928{
1929 struct hostapd_data *hapd = ctx;
1930 const struct hostapd_eap_user *eap_user;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001931 int i;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001932 int rv = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001933
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001934 eap_user = hostapd_get_eap_user(hapd, identity, identity_len, phase2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001935 if (eap_user == NULL)
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001936 goto out;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001937
1938 os_memset(user, 0, sizeof(*user));
1939 user->phase2 = phase2;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001940 for (i = 0; i < EAP_MAX_METHODS; i++) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001941 user->methods[i].vendor = eap_user->methods[i].vendor;
1942 user->methods[i].method = eap_user->methods[i].method;
1943 }
1944
1945 if (eap_user->password) {
1946 user->password = os_malloc(eap_user->password_len);
1947 if (user->password == NULL)
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001948 goto out;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001949 os_memcpy(user->password, eap_user->password,
1950 eap_user->password_len);
1951 user->password_len = eap_user->password_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001952 user->password_hash = eap_user->password_hash;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001953 }
1954 user->force_version = eap_user->force_version;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001955 user->macacl = eap_user->macacl;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001956 user->ttls_auth = eap_user->ttls_auth;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001957 user->remediation = eap_user->remediation;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001958 rv = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001959
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001960out:
1961 if (rv)
1962 wpa_printf(MSG_DEBUG, "%s: Failed to find user", __func__);
1963
1964 return rv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001965}
1966
1967
1968static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
1969{
1970 struct hostapd_data *hapd = ctx;
1971 struct sta_info *sta;
1972 sta = ap_get_sta(hapd, addr);
1973 if (sta == NULL || sta->eapol_sm == NULL)
1974 return 0;
1975 return 1;
1976}
1977
1978
1979static void ieee802_1x_logger(void *ctx, const u8 *addr,
1980 eapol_logger_level level, const char *txt)
1981{
1982#ifndef CONFIG_NO_HOSTAPD_LOGGER
1983 struct hostapd_data *hapd = ctx;
1984 int hlevel;
1985
1986 switch (level) {
1987 case EAPOL_LOGGER_WARNING:
1988 hlevel = HOSTAPD_LEVEL_WARNING;
1989 break;
1990 case EAPOL_LOGGER_INFO:
1991 hlevel = HOSTAPD_LEVEL_INFO;
1992 break;
1993 case EAPOL_LOGGER_DEBUG:
1994 default:
1995 hlevel = HOSTAPD_LEVEL_DEBUG;
1996 break;
1997 }
1998
1999 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
2000 txt);
2001#endif /* CONFIG_NO_HOSTAPD_LOGGER */
2002}
2003
2004
2005static void ieee802_1x_set_port_authorized(void *ctx, void *sta_ctx,
2006 int authorized)
2007{
2008 struct hostapd_data *hapd = ctx;
2009 struct sta_info *sta = sta_ctx;
2010 ieee802_1x_set_sta_authorized(hapd, sta, authorized);
2011}
2012
2013
2014static void _ieee802_1x_abort_auth(void *ctx, void *sta_ctx)
2015{
2016 struct hostapd_data *hapd = ctx;
2017 struct sta_info *sta = sta_ctx;
2018 ieee802_1x_abort_auth(hapd, sta);
2019}
2020
2021
2022static void _ieee802_1x_tx_key(void *ctx, void *sta_ctx)
2023{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002024#ifndef CONFIG_FIPS
2025#ifndef CONFIG_NO_RC4
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002026 struct hostapd_data *hapd = ctx;
2027 struct sta_info *sta = sta_ctx;
2028 ieee802_1x_tx_key(hapd, sta);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002029#endif /* CONFIG_NO_RC4 */
2030#endif /* CONFIG_FIPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002031}
2032
2033
2034static void ieee802_1x_eapol_event(void *ctx, void *sta_ctx,
2035 enum eapol_event type)
2036{
2037 /* struct hostapd_data *hapd = ctx; */
2038 struct sta_info *sta = sta_ctx;
2039 switch (type) {
2040 case EAPOL_AUTH_SM_CHANGE:
2041 wpa_auth_sm_notify(sta->wpa_sm);
2042 break;
2043 case EAPOL_AUTH_REAUTHENTICATE:
2044 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH_EAPOL);
2045 break;
2046 }
2047}
2048
2049
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002050#ifdef CONFIG_ERP
2051
2052static struct eap_server_erp_key *
2053ieee802_1x_erp_get_key(void *ctx, const char *keyname)
2054{
2055 struct hostapd_data *hapd = ctx;
2056 struct eap_server_erp_key *erp;
2057
2058 dl_list_for_each(erp, &hapd->erp_keys, struct eap_server_erp_key,
2059 list) {
2060 if (os_strcmp(erp->keyname_nai, keyname) == 0)
2061 return erp;
2062 }
2063
2064 return NULL;
2065}
2066
2067
2068static int ieee802_1x_erp_add_key(void *ctx, struct eap_server_erp_key *erp)
2069{
2070 struct hostapd_data *hapd = ctx;
2071
2072 dl_list_add(&hapd->erp_keys, &erp->list);
2073 return 0;
2074}
2075
2076#endif /* CONFIG_ERP */
2077
2078
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002079int ieee802_1x_init(struct hostapd_data *hapd)
2080{
2081 int i;
2082 struct eapol_auth_config conf;
2083 struct eapol_auth_cb cb;
2084
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002085 dl_list_init(&hapd->erp_keys);
2086
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002087 os_memset(&conf, 0, sizeof(conf));
2088 conf.ctx = hapd;
2089 conf.eap_reauth_period = hapd->conf->eap_reauth_period;
2090 conf.wpa = hapd->conf->wpa;
2091 conf.individual_wep_key_len = hapd->conf->individual_wep_key_len;
2092 conf.eap_server = hapd->conf->eap_server;
2093 conf.ssl_ctx = hapd->ssl_ctx;
2094 conf.msg_ctx = hapd->msg_ctx;
2095 conf.eap_sim_db_priv = hapd->eap_sim_db_priv;
2096 conf.eap_req_id_text = hapd->conf->eap_req_id_text;
2097 conf.eap_req_id_text_len = hapd->conf->eap_req_id_text_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002098 conf.erp_send_reauth_start = hapd->conf->erp_send_reauth_start;
2099 conf.erp_domain = hapd->conf->erp_domain;
2100 conf.erp = hapd->conf->eap_server_erp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002101 conf.tls_session_lifetime = hapd->conf->tls_session_lifetime;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002102 conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
2103 conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
2104 conf.eap_fast_a_id_len = hapd->conf->eap_fast_a_id_len;
2105 conf.eap_fast_a_id_info = hapd->conf->eap_fast_a_id_info;
2106 conf.eap_fast_prov = hapd->conf->eap_fast_prov;
2107 conf.pac_key_lifetime = hapd->conf->pac_key_lifetime;
2108 conf.pac_key_refresh_time = hapd->conf->pac_key_refresh_time;
2109 conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
2110 conf.tnc = hapd->conf->tnc;
2111 conf.wps = hapd->wps;
2112 conf.fragment_size = hapd->conf->fragment_size;
2113 conf.pwd_group = hapd->conf->pwd_group;
Jouni Malinen87fd2792011-05-16 18:35:42 +03002114 conf.pbc_in_m1 = hapd->conf->pbc_in_m1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002115 if (hapd->conf->server_id) {
2116 conf.server_id = (const u8 *) hapd->conf->server_id;
2117 conf.server_id_len = os_strlen(hapd->conf->server_id);
2118 } else {
2119 conf.server_id = (const u8 *) "hostapd";
2120 conf.server_id_len = 7;
2121 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002122
2123 os_memset(&cb, 0, sizeof(cb));
2124 cb.eapol_send = ieee802_1x_eapol_send;
2125 cb.aaa_send = ieee802_1x_aaa_send;
2126 cb.finished = _ieee802_1x_finished;
2127 cb.get_eap_user = ieee802_1x_get_eap_user;
2128 cb.sta_entry_alive = ieee802_1x_sta_entry_alive;
2129 cb.logger = ieee802_1x_logger;
2130 cb.set_port_authorized = ieee802_1x_set_port_authorized;
2131 cb.abort_auth = _ieee802_1x_abort_auth;
2132 cb.tx_key = _ieee802_1x_tx_key;
2133 cb.eapol_event = ieee802_1x_eapol_event;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002134#ifdef CONFIG_ERP
2135 cb.erp_get_key = ieee802_1x_erp_get_key;
2136 cb.erp_add_key = ieee802_1x_erp_add_key;
2137#endif /* CONFIG_ERP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002138
2139 hapd->eapol_auth = eapol_auth_init(&conf, &cb);
2140 if (hapd->eapol_auth == NULL)
2141 return -1;
2142
2143 if ((hapd->conf->ieee802_1x || hapd->conf->wpa) &&
2144 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1))
2145 return -1;
2146
2147#ifndef CONFIG_NO_RADIUS
2148 if (radius_client_register(hapd->radius, RADIUS_AUTH,
2149 ieee802_1x_receive_auth, hapd))
2150 return -1;
2151#endif /* CONFIG_NO_RADIUS */
2152
2153 if (hapd->conf->default_wep_key_len) {
2154 for (i = 0; i < 4; i++)
2155 hostapd_drv_set_key(hapd->conf->iface, hapd,
2156 WPA_ALG_NONE, NULL, i, 0, NULL, 0,
2157 NULL, 0);
2158
2159 ieee802_1x_rekey(hapd, NULL);
2160
2161 if (hapd->eapol_auth->default_wep_key == NULL)
2162 return -1;
2163 }
2164
2165 return 0;
2166}
2167
2168
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002169void ieee802_1x_erp_flush(struct hostapd_data *hapd)
2170{
2171 struct eap_server_erp_key *erp;
2172
2173 while ((erp = dl_list_first(&hapd->erp_keys, struct eap_server_erp_key,
2174 list)) != NULL) {
2175 dl_list_del(&erp->list);
2176 bin_clear_free(erp, sizeof(*erp));
2177 }
2178}
2179
2180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002181void ieee802_1x_deinit(struct hostapd_data *hapd)
2182{
2183 eloop_cancel_timeout(ieee802_1x_rekey, hapd, NULL);
2184
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002185 if (hapd->driver && hapd->drv_priv &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186 (hapd->conf->ieee802_1x || hapd->conf->wpa))
2187 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
2188
2189 eapol_auth_deinit(hapd->eapol_auth);
2190 hapd->eapol_auth = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002191
2192 ieee802_1x_erp_flush(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002193}
2194
2195
2196int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
2197 const u8 *buf, size_t len, int ack)
2198{
2199 struct ieee80211_hdr *hdr;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002200 u8 *pos;
2201 const unsigned char rfc1042_hdr[ETH_ALEN] =
2202 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
2203
2204 if (sta == NULL)
2205 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002206 if (len < sizeof(*hdr) + sizeof(rfc1042_hdr) + 2)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002207 return 0;
2208
2209 hdr = (struct ieee80211_hdr *) buf;
2210 pos = (u8 *) (hdr + 1);
2211 if (os_memcmp(pos, rfc1042_hdr, sizeof(rfc1042_hdr)) != 0)
2212 return 0;
2213 pos += sizeof(rfc1042_hdr);
2214 if (WPA_GET_BE16(pos) != ETH_P_PAE)
2215 return 0;
2216 pos += 2;
2217
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002218 return ieee802_1x_eapol_tx_status(hapd, sta, pos, buf + len - pos,
2219 ack);
2220}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002221
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002222
2223int ieee802_1x_eapol_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
2224 const u8 *buf, int len, int ack)
2225{
2226 const struct ieee802_1x_hdr *xhdr =
2227 (const struct ieee802_1x_hdr *) buf;
2228 const u8 *pos = buf + sizeof(*xhdr);
2229 struct ieee802_1x_eapol_key *key;
2230
2231 if (len < (int) sizeof(*xhdr))
2232 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002233 wpa_printf(MSG_DEBUG, "IEEE 802.1X: " MACSTR " TX status - version=%d "
2234 "type=%d length=%d - ack=%d",
2235 MAC2STR(sta->addr), xhdr->version, xhdr->type,
2236 be_to_host16(xhdr->length), ack);
2237
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002238 if (xhdr->type != IEEE802_1X_TYPE_EAPOL_KEY)
2239 return 0;
2240
2241 if (pos + sizeof(struct wpa_eapol_key) <= buf + len) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242 const struct wpa_eapol_key *wpa;
2243 wpa = (const struct wpa_eapol_key *) pos;
2244 if (wpa->type == EAPOL_KEY_TYPE_RSN ||
2245 wpa->type == EAPOL_KEY_TYPE_WPA)
2246 wpa_auth_eapol_key_tx_status(hapd->wpa_auth,
2247 sta->wpa_sm, ack);
2248 }
2249
2250 /* EAPOL EAP-Packet packets are eventually re-sent by either Supplicant
2251 * or Authenticator state machines, but EAPOL-Key packets are not
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002252 * retransmitted in case of failure. Try to re-send failed EAPOL-Key
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002253 * packets couple of times because otherwise STA keys become
2254 * unsynchronized with AP. */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002255 if (!ack && pos + sizeof(*key) <= buf + len) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002256 key = (struct ieee802_1x_eapol_key *) pos;
2257 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
2258 HOSTAPD_LEVEL_DEBUG, "did not Ack EAPOL-Key "
2259 "frame (%scast index=%d)",
2260 key->key_index & BIT(7) ? "uni" : "broad",
2261 key->key_index & ~BIT(7));
2262 /* TODO: re-send EAPOL-Key couple of times (with short delay
2263 * between them?). If all attempt fail, report error and
2264 * deauthenticate STA so that it will get new keys when
2265 * authenticating again (e.g., after returning in range).
2266 * Separate limit/transmit state needed both for unicast and
2267 * broadcast keys(?) */
2268 }
2269 /* TODO: could move unicast key configuration from ieee802_1x_tx_key()
2270 * to here and change the key only if the EAPOL-Key packet was Acked.
2271 */
2272
2273 return 1;
2274}
2275
2276
2277u8 * ieee802_1x_get_identity(struct eapol_state_machine *sm, size_t *len)
2278{
2279 if (sm == NULL || sm->identity == NULL)
2280 return NULL;
2281
2282 *len = sm->identity_len;
2283 return sm->identity;
2284}
2285
2286
2287u8 * ieee802_1x_get_radius_class(struct eapol_state_machine *sm, size_t *len,
2288 int idx)
2289{
2290 if (sm == NULL || sm->radius_class.attr == NULL ||
2291 idx >= (int) sm->radius_class.count)
2292 return NULL;
2293
2294 *len = sm->radius_class.attr[idx].len;
2295 return sm->radius_class.attr[idx].data;
2296}
2297
2298
Dmitry Shmidt04949592012-07-19 12:16:46 -07002299struct wpabuf * ieee802_1x_get_radius_cui(struct eapol_state_machine *sm)
2300{
2301 if (sm == NULL)
2302 return NULL;
2303 return sm->radius_cui;
2304}
2305
2306
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002307const u8 * ieee802_1x_get_key(struct eapol_state_machine *sm, size_t *len)
2308{
Jouni Malinen75ecf522011-06-27 15:19:46 -07002309 *len = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002310 if (sm == NULL)
2311 return NULL;
2312
2313 *len = sm->eap_if->eapKeyDataLen;
2314 return sm->eap_if->eapKeyData;
2315}
2316
2317
2318void ieee802_1x_notify_port_enabled(struct eapol_state_machine *sm,
2319 int enabled)
2320{
2321 if (sm == NULL)
2322 return;
2323 sm->eap_if->portEnabled = enabled ? TRUE : FALSE;
2324 eapol_auth_step(sm);
2325}
2326
2327
2328void ieee802_1x_notify_port_valid(struct eapol_state_machine *sm,
2329 int valid)
2330{
2331 if (sm == NULL)
2332 return;
2333 sm->portValid = valid ? TRUE : FALSE;
2334 eapol_auth_step(sm);
2335}
2336
2337
2338void ieee802_1x_notify_pre_auth(struct eapol_state_machine *sm, int pre_auth)
2339{
2340 if (sm == NULL)
2341 return;
2342 if (pre_auth)
2343 sm->flags |= EAPOL_SM_PREAUTH;
2344 else
2345 sm->flags &= ~EAPOL_SM_PREAUTH;
2346}
2347
2348
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002349static const char * bool_txt(Boolean val)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002350{
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002351 return val ? "TRUE" : "FALSE";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002352}
2353
2354
2355int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2356{
2357 /* TODO */
2358 return 0;
2359}
2360
2361
2362int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2363 char *buf, size_t buflen)
2364{
2365 int len = 0, ret;
2366 struct eapol_state_machine *sm = sta->eapol_sm;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002367 struct os_reltime diff;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08002368 const char *name1;
2369 const char *name2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002370
2371 if (sm == NULL)
2372 return 0;
2373
2374 ret = os_snprintf(buf + len, buflen - len,
2375 "dot1xPaePortNumber=%d\n"
2376 "dot1xPaePortProtocolVersion=%d\n"
2377 "dot1xPaePortCapabilities=1\n"
2378 "dot1xPaePortInitialize=%d\n"
2379 "dot1xPaePortReauthenticate=FALSE\n",
2380 sta->aid,
2381 EAPOL_VERSION,
2382 sm->initialize);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002383 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384 return len;
2385 len += ret;
2386
2387 /* dot1xAuthConfigTable */
2388 ret = os_snprintf(buf + len, buflen - len,
2389 "dot1xAuthPaeState=%d\n"
2390 "dot1xAuthBackendAuthState=%d\n"
2391 "dot1xAuthAdminControlledDirections=%d\n"
2392 "dot1xAuthOperControlledDirections=%d\n"
2393 "dot1xAuthAuthControlledPortStatus=%d\n"
2394 "dot1xAuthAuthControlledPortControl=%d\n"
2395 "dot1xAuthQuietPeriod=%u\n"
2396 "dot1xAuthServerTimeout=%u\n"
2397 "dot1xAuthReAuthPeriod=%u\n"
2398 "dot1xAuthReAuthEnabled=%s\n"
2399 "dot1xAuthKeyTxEnabled=%s\n",
2400 sm->auth_pae_state + 1,
2401 sm->be_auth_state + 1,
2402 sm->adminControlledDirections,
2403 sm->operControlledDirections,
2404 sm->authPortStatus,
2405 sm->portControl,
2406 sm->quietPeriod,
2407 sm->serverTimeout,
2408 sm->reAuthPeriod,
2409 bool_txt(sm->reAuthEnabled),
2410 bool_txt(sm->keyTxEnabled));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002411 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002412 return len;
2413 len += ret;
2414
2415 /* dot1xAuthStatsTable */
2416 ret = os_snprintf(buf + len, buflen - len,
2417 "dot1xAuthEapolFramesRx=%u\n"
2418 "dot1xAuthEapolFramesTx=%u\n"
2419 "dot1xAuthEapolStartFramesRx=%u\n"
2420 "dot1xAuthEapolLogoffFramesRx=%u\n"
2421 "dot1xAuthEapolRespIdFramesRx=%u\n"
2422 "dot1xAuthEapolRespFramesRx=%u\n"
2423 "dot1xAuthEapolReqIdFramesTx=%u\n"
2424 "dot1xAuthEapolReqFramesTx=%u\n"
2425 "dot1xAuthInvalidEapolFramesRx=%u\n"
2426 "dot1xAuthEapLengthErrorFramesRx=%u\n"
2427 "dot1xAuthLastEapolFrameVersion=%u\n"
2428 "dot1xAuthLastEapolFrameSource=" MACSTR "\n",
2429 sm->dot1xAuthEapolFramesRx,
2430 sm->dot1xAuthEapolFramesTx,
2431 sm->dot1xAuthEapolStartFramesRx,
2432 sm->dot1xAuthEapolLogoffFramesRx,
2433 sm->dot1xAuthEapolRespIdFramesRx,
2434 sm->dot1xAuthEapolRespFramesRx,
2435 sm->dot1xAuthEapolReqIdFramesTx,
2436 sm->dot1xAuthEapolReqFramesTx,
2437 sm->dot1xAuthInvalidEapolFramesRx,
2438 sm->dot1xAuthEapLengthErrorFramesRx,
2439 sm->dot1xAuthLastEapolFrameVersion,
2440 MAC2STR(sm->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002441 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002442 return len;
2443 len += ret;
2444
2445 /* dot1xAuthDiagTable */
2446 ret = os_snprintf(buf + len, buflen - len,
2447 "dot1xAuthEntersConnecting=%u\n"
2448 "dot1xAuthEapLogoffsWhileConnecting=%u\n"
2449 "dot1xAuthEntersAuthenticating=%u\n"
2450 "dot1xAuthAuthSuccessesWhileAuthenticating=%u\n"
2451 "dot1xAuthAuthTimeoutsWhileAuthenticating=%u\n"
2452 "dot1xAuthAuthFailWhileAuthenticating=%u\n"
2453 "dot1xAuthAuthEapStartsWhileAuthenticating=%u\n"
2454 "dot1xAuthAuthEapLogoffWhileAuthenticating=%u\n"
2455 "dot1xAuthAuthReauthsWhileAuthenticated=%u\n"
2456 "dot1xAuthAuthEapStartsWhileAuthenticated=%u\n"
2457 "dot1xAuthAuthEapLogoffWhileAuthenticated=%u\n"
2458 "dot1xAuthBackendResponses=%u\n"
2459 "dot1xAuthBackendAccessChallenges=%u\n"
2460 "dot1xAuthBackendOtherRequestsToSupplicant=%u\n"
2461 "dot1xAuthBackendAuthSuccesses=%u\n"
2462 "dot1xAuthBackendAuthFails=%u\n",
2463 sm->authEntersConnecting,
2464 sm->authEapLogoffsWhileConnecting,
2465 sm->authEntersAuthenticating,
2466 sm->authAuthSuccessesWhileAuthenticating,
2467 sm->authAuthTimeoutsWhileAuthenticating,
2468 sm->authAuthFailWhileAuthenticating,
2469 sm->authAuthEapStartsWhileAuthenticating,
2470 sm->authAuthEapLogoffWhileAuthenticating,
2471 sm->authAuthReauthsWhileAuthenticated,
2472 sm->authAuthEapStartsWhileAuthenticated,
2473 sm->authAuthEapLogoffWhileAuthenticated,
2474 sm->backendResponses,
2475 sm->backendAccessChallenges,
2476 sm->backendOtherRequestsToSupplicant,
2477 sm->backendAuthSuccesses,
2478 sm->backendAuthFails);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002479 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002480 return len;
2481 len += ret;
2482
2483 /* dot1xAuthSessionStatsTable */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002484 os_reltime_age(&sta->acct_session_start, &diff);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002485 ret = os_snprintf(buf + len, buflen - len,
2486 /* TODO: dot1xAuthSessionOctetsRx */
2487 /* TODO: dot1xAuthSessionOctetsTx */
2488 /* TODO: dot1xAuthSessionFramesRx */
2489 /* TODO: dot1xAuthSessionFramesTx */
2490 "dot1xAuthSessionId=%08X-%08X\n"
2491 "dot1xAuthSessionAuthenticMethod=%d\n"
2492 "dot1xAuthSessionTime=%u\n"
2493 "dot1xAuthSessionTerminateCause=999\n"
2494 "dot1xAuthSessionUserName=%s\n",
2495 sta->acct_session_id_hi, sta->acct_session_id_lo,
2496 (wpa_key_mgmt_wpa_ieee8021x(
2497 wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
2498 1 : 2,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002499 (unsigned int) diff.sec,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002500 sm->identity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002501 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002502 return len;
2503 len += ret;
2504
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002505 if (sm->acct_multi_session_id_hi) {
2506 ret = os_snprintf(buf + len, buflen - len,
2507 "authMultiSessionId=%08X+%08X\n",
2508 sm->acct_multi_session_id_hi,
2509 sm->acct_multi_session_id_lo);
2510 if (os_snprintf_error(buflen - len, ret))
2511 return len;
2512 len += ret;
2513 }
2514
Dmitry Shmidt96be6222014-02-13 10:16:51 -08002515 name1 = eap_server_get_name(0, sm->eap_type_authsrv);
2516 name2 = eap_server_get_name(0, sm->eap_type_supp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002517 ret = os_snprintf(buf + len, buflen - len,
2518 "last_eap_type_as=%d (%s)\n"
2519 "last_eap_type_sta=%d (%s)\n",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002520 sm->eap_type_authsrv, name1,
2521 sm->eap_type_supp, name2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002522 if (os_snprintf_error(buflen - len, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002523 return len;
2524 len += ret;
2525
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002526 return len;
2527}
2528
2529
2530static void ieee802_1x_finished(struct hostapd_data *hapd,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002531 struct sta_info *sta, int success,
2532 int remediation)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002533{
2534 const u8 *key;
2535 size_t len;
2536 /* TODO: get PMKLifetime from WPA parameters */
2537 static const int dot11RSNAConfigPMKLifetime = 43200;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07002538 unsigned int session_timeout;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002539
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002540#ifdef CONFIG_HS20
2541 if (remediation && !sta->remediation) {
2542 sta->remediation = 1;
2543 os_free(sta->remediation_url);
2544 sta->remediation_url =
2545 os_strdup(hapd->conf->subscr_remediation_url);
2546 sta->remediation_method = 1; /* SOAP-XML SPP */
2547 }
2548
2549 if (success) {
2550 if (sta->remediation) {
2551 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification "
2552 "to " MACSTR " to indicate Subscription "
2553 "Remediation",
2554 MAC2STR(sta->addr));
2555 hs20_send_wnm_notification(hapd, sta->addr,
2556 sta->remediation_method,
2557 sta->remediation_url);
2558 os_free(sta->remediation_url);
2559 sta->remediation_url = NULL;
2560 }
2561
2562 if (sta->hs20_deauth_req) {
2563 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification "
2564 "to " MACSTR " to indicate imminent "
2565 "deauthentication", MAC2STR(sta->addr));
2566 hs20_send_wnm_notification_deauth_req(
2567 hapd, sta->addr, sta->hs20_deauth_req);
2568 }
2569 }
2570#endif /* CONFIG_HS20 */
2571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002572 key = ieee802_1x_get_key(sta->eapol_sm, &len);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07002573 if (sta->session_timeout_set)
2574 session_timeout = sta->session_timeout;
2575 else
2576 session_timeout = dot11RSNAConfigPMKLifetime;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002577 if (success && key && len >= PMK_LEN && !sta->remediation &&
2578 !sta->hs20_deauth_requested &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002579 wpa_auth_pmksa_add(sta->wpa_sm, key, len, session_timeout,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002580 sta->eapol_sm) == 0) {
2581 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_WPA,
2582 HOSTAPD_LEVEL_DEBUG,
2583 "Added PMKSA cache entry (IEEE 802.1X)");
2584 }
2585
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002586 if (!success) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002587 /*
2588 * Many devices require deauthentication after WPS provisioning
2589 * and some may not be be able to do that themselves, so
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002590 * disconnect the client here. In addition, this may also
2591 * benefit IEEE 802.1X/EAPOL authentication cases, too since
2592 * the EAPOL PAE state machine would remain in HELD state for
2593 * considerable amount of time and some EAP methods, like
2594 * EAP-FAST with anonymous provisioning, may require another
2595 * EAPOL authentication to be started to complete connection.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002596 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002597 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "IEEE 802.1X: Force "
2598 "disconnection after EAP-Failure");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002599 /* Add a small sleep to increase likelihood of previously
2600 * requested EAP-Failure TX getting out before this should the
2601 * driver reorder operations.
2602 */
2603 os_sleep(0, 10000);
2604 ap_sta_disconnect(hapd, sta, sta->addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002605 WLAN_REASON_IEEE_802_1X_AUTH_FAILED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002606 hostapd_wps_eap_completed(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002607 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002608}