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 struct wpabuf
* eap_identity_buildReq(struct eap_sm
*sm
, void *priv
,
61 struct eap_identity_data
*data
= priv
;
66 if (sm
->eapol_cb
->get_eap_req_id_text
) {
67 req_data
= sm
->eapol_cb
->get_eap_req_id_text(sm
->eapol_ctx
,
73 req
= eap_msg_alloc(EAP_VENDOR_IETF
, EAP_TYPE_IDENTITY
, req_data_len
,
74 EAP_CODE_REQUEST
, id
);
76 wpa_printf(MSG_ERROR
, "EAP-Identity: Failed to allocate "
77 "memory for request");
78 data
->state
= FAILURE
;
82 wpabuf_put_data(req
, req_data
, req_data_len
);
88 static Boolean
eap_identity_check(struct eap_sm
*sm
, void *priv
,
89 struct wpabuf
*respData
)
94 pos
= eap_hdr_validate(EAP_VENDOR_IETF
, EAP_TYPE_IDENTITY
,
97 wpa_printf(MSG_INFO
, "EAP-Identity: Invalid frame");
105 static void eap_identity_process(struct eap_sm
*sm
, void *priv
,
106 struct wpabuf
*respData
)
108 struct eap_identity_data
*data
= priv
;
113 if (eap_identity_check(sm
, data
, respData
)) {
114 wpa_printf(MSG_DEBUG
, "EAP-Identity: failed to pick "
115 "up already started negotiation");
116 data
->state
= FAILURE
;
122 pos
= eap_hdr_validate(EAP_VENDOR_IETF
, EAP_TYPE_IDENTITY
,
125 return; /* Should not happen - frame already validated */
127 wpa_hexdump_ascii(MSG_DEBUG
, "EAP-Identity: Peer identity", pos
, len
);
128 os_free(sm
->identity
);
129 sm
->identity
= os_malloc(len
? len
: 1);
130 if (sm
->identity
== NULL
) {
131 data
->state
= FAILURE
;
133 os_memcpy(sm
->identity
, pos
, len
);
134 sm
->identity_len
= len
;
135 data
->state
= SUCCESS
;
140 static Boolean
eap_identity_isDone(struct eap_sm
*sm
, void *priv
)
142 struct eap_identity_data
*data
= priv
;
143 return data
->state
!= CONTINUE
;
147 static Boolean
eap_identity_isSuccess(struct eap_sm
*sm
, void *priv
)
149 struct eap_identity_data
*data
= priv
;
150 return data
->state
== SUCCESS
;
154 int eap_server_identity_register(void)
156 struct eap_method
*eap
;
159 eap
= eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION
,
160 EAP_VENDOR_IETF
, EAP_TYPE_IDENTITY
,
165 eap
->init
= eap_identity_init
;
166 eap
->initPickUp
= eap_identity_initPickUp
;
167 eap
->reset
= eap_identity_reset
;
168 eap
->buildReq
= eap_identity_buildReq
;
169 eap
->check
= eap_identity_check
;
170 eap
->process
= eap_identity_process
;
171 eap
->isDone
= eap_identity_isDone
;
172 eap
->isSuccess
= eap_identity_isSuccess
;
174 ret
= eap_server_method_register(eap
);
176 eap_server_method_free(eap
);