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.
22 struct eap_identity_data {
23 enum { CONTINUE, SUCCESS, FAILURE } state;
28 static void * eap_identity_init(struct eap_sm *sm)
30 struct eap_identity_data *data;
32 data = wpa_zalloc(sizeof(*data));
35 data->state = CONTINUE;
41 static void * eap_identity_initPickUp(struct eap_sm *sm)
43 struct eap_identity_data *data;
44 data = eap_identity_init(sm);
52 static void eap_identity_reset(struct eap_sm *sm, void *priv)
54 struct eap_identity_data *data = priv;
59 static u8 * eap_identity_buildReq(struct eap_sm *sm, void *priv, int id,
62 struct eap_identity_data *data = priv;
68 if (sm->eapol_cb->get_eap_req_id_text) {
69 req_data = sm->eapol_cb->get_eap_req_id_text(sm->eapol_ctx,
75 req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, reqDataLen,
76 req_data_len, EAP_CODE_REQUEST, id, &pos);
78 wpa_printf(MSG_ERROR, "EAP-Identity: Failed to allocate "
79 "memory for request");
80 data->state = FAILURE;
85 memcpy(pos, req_data, req_data_len);
91 static Boolean eap_identity_check(struct eap_sm *sm, void *priv,
92 u8 *respData, size_t respDataLen)
97 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
98 respData, respDataLen, &len);
100 wpa_printf(MSG_INFO, "EAP-Identity: Invalid frame");
108 static void eap_identity_process(struct eap_sm *sm, void *priv,
109 u8 *respData, size_t respDataLen)
111 struct eap_identity_data *data = priv;
116 if (eap_identity_check(sm, data, respData, respDataLen)) {
117 wpa_printf(MSG_DEBUG, "EAP-Identity: failed to pick "
118 "up already started negotiation");
119 data->state = FAILURE;
125 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
126 respData, respDataLen, &len);
128 return; /* Should not happen - frame already validated */
130 wpa_hexdump_ascii(MSG_DEBUG, "EAP-Identity: Peer identity", pos, len);
132 sm->identity = malloc(len);
133 if (sm->identity == NULL) {
134 data->state = FAILURE;
136 memcpy(sm->identity, pos, len);
137 sm->identity_len = len;
138 data->state = SUCCESS;
143 static Boolean eap_identity_isDone(struct eap_sm *sm, void *priv)
145 struct eap_identity_data *data = priv;
146 return data->state != CONTINUE;
150 static Boolean eap_identity_isSuccess(struct eap_sm *sm, void *priv)
152 struct eap_identity_data *data = priv;
153 return data->state == SUCCESS;
157 int eap_server_identity_register(void)
159 struct eap_method *eap;
162 eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
163 EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
168 eap->init = eap_identity_init;
169 eap->initPickUp = eap_identity_initPickUp;
170 eap->reset = eap_identity_reset;
171 eap->buildReq = eap_identity_buildReq;
172 eap->check = eap_identity_check;
173 eap->process = eap_identity_process;
174 eap->isDone = eap_identity_isDone;
175 eap->isSuccess = eap_identity_isSuccess;
177 ret = eap_server_method_register(eap);
179 eap_server_method_free(eap);