2 * hostapd / EAP-Identity
3 * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
15 struct eap_identity_data {
16 enum { CONTINUE, SUCCESS, FAILURE } state;
21 static void * eap_identity_init(struct eap_sm *sm)
23 struct eap_identity_data *data;
25 data = os_zalloc(sizeof(*data));
28 data->state = CONTINUE;
34 static void * eap_identity_initPickUp(struct eap_sm *sm)
36 struct eap_identity_data *data;
37 data = eap_identity_init(sm);
45 static void eap_identity_reset(struct eap_sm *sm, void *priv)
47 struct eap_identity_data *data = priv;
52 static struct wpabuf * eap_identity_buildReq(struct eap_sm *sm, void *priv,
55 struct eap_identity_data *data = priv;
60 if (sm->eapol_cb->get_eap_req_id_text) {
61 req_data = sm->eapol_cb->get_eap_req_id_text(sm->eapol_ctx,
67 req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, req_data_len,
68 EAP_CODE_REQUEST, id);
70 wpa_printf(MSG_ERROR, "EAP-Identity: Failed to allocate "
71 "memory for request");
72 data->state = FAILURE;
76 wpabuf_put_data(req, req_data, req_data_len);
82 static Boolean eap_identity_check(struct eap_sm *sm, void *priv,
83 struct wpabuf *respData)
88 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
91 wpa_printf(MSG_INFO, "EAP-Identity: Invalid frame");
99 static void eap_identity_process(struct eap_sm *sm, void *priv,
100 struct wpabuf *respData)
102 struct eap_identity_data *data = priv;
108 if (eap_identity_check(sm, data, respData)) {
109 wpa_printf(MSG_DEBUG, "EAP-Identity: failed to pick "
110 "up already started negotiation");
111 data->state = FAILURE;
117 pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
120 return; /* Should not happen - frame already validated */
122 wpa_hexdump_ascii(MSG_DEBUG, "EAP-Identity: Peer identity", pos, len);
123 buf = os_malloc(len * 4 + 1);
125 printf_encode(buf, len * 4 + 1, pos, len);
126 eap_log_msg(sm, "EAP-Response/Identity '%s'", buf);
130 sm->update_user = TRUE;
131 os_free(sm->identity);
132 sm->identity = os_malloc(len ? len : 1);
133 if (sm->identity == NULL) {
134 data->state = FAILURE;
136 os_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;
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 return eap_server_method_register(eap);