2
* hostapd / EAP-Identity
3
* Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation.
9
* Alternatively, this software may be distributed under the terms of BSD
12
* See README and COPYING for more details.
21
struct eap_identity_data {
22
enum { CONTINUE, SUCCESS, FAILURE } state;
27
static void * eap_identity_init(struct eap_sm *sm)
29
struct eap_identity_data *data;
31
data = os_zalloc(sizeof(*data));
34
data->state = CONTINUE;
40
static void * eap_identity_initPickUp(struct eap_sm *sm)
42
struct eap_identity_data *data;
43
data = eap_identity_init(sm);
51
static void eap_identity_reset(struct eap_sm *sm, void *priv)
53
struct eap_identity_data *data = priv;
58
static u8 * eap_identity_buildReq(struct eap_sm *sm, void *priv, int id,
61
struct eap_identity_data *data = priv;
67
if (sm->eapol_cb->get_eap_req_id_text) {
68
req_data = sm->eapol_cb->get_eap_req_id_text(sm->eapol_ctx,
74
req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, reqDataLen,
75
req_data_len, EAP_CODE_REQUEST, id, &pos);
77
wpa_printf(MSG_ERROR, "EAP-Identity: Failed to allocate "
78
"memory for request");
79
data->state = FAILURE;
84
memcpy(pos, req_data, req_data_len);
90
static Boolean eap_identity_check(struct eap_sm *sm, void *priv,
91
u8 *respData, size_t respDataLen)
96
pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
97
respData, respDataLen, &len);
99
wpa_printf(MSG_INFO, "EAP-Identity: Invalid frame");
107
static void eap_identity_process(struct eap_sm *sm, void *priv,
108
u8 *respData, size_t respDataLen)
110
struct eap_identity_data *data = priv;
115
if (eap_identity_check(sm, data, respData, respDataLen)) {
116
wpa_printf(MSG_DEBUG, "EAP-Identity: failed to pick "
117
"up already started negotiation");
118
data->state = FAILURE;
124
pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
125
respData, respDataLen, &len);
127
return; /* Should not happen - frame already validated */
129
wpa_hexdump_ascii(MSG_DEBUG, "EAP-Identity: Peer identity", pos, len);
131
sm->identity = malloc(len);
132
if (sm->identity == NULL) {
133
data->state = FAILURE;
135
memcpy(sm->identity, pos, len);
136
sm->identity_len = len;
137
data->state = SUCCESS;
142
static Boolean eap_identity_isDone(struct eap_sm *sm, void *priv)
144
struct eap_identity_data *data = priv;
145
return data->state != CONTINUE;
149
static Boolean eap_identity_isSuccess(struct eap_sm *sm, void *priv)
151
struct eap_identity_data *data = priv;
152
return data->state == SUCCESS;
156
int eap_server_identity_register(void)
158
struct eap_method *eap;
161
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
162
EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
167
eap->init = eap_identity_init;
168
eap->initPickUp = eap_identity_initPickUp;
169
eap->reset = eap_identity_reset;
170
eap->buildReq = eap_identity_buildReq;
171
eap->check = eap_identity_check;
172
eap->process = eap_identity_process;
173
eap->isDone = eap_identity_isDone;
174
eap->isSuccess = eap_identity_isSuccess;
176
ret = eap_server_method_register(eap);
178
eap_server_method_free(eap);