2 * EAP peer method: Test method for vendor specific (expanded) EAP type
3 * Copyright (c) 2005-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.
14 * This file implements a vendor specific test method using EAP expanded types.
15 * This is only for test use and must not be used for authentication since no
16 * security is provided.
23 #ifdef TEST_PENDING_REQUEST
25 #endif /* TEST_PENDING_REQUEST */
28 #define EAP_VENDOR_ID 0xfffefd
29 #define EAP_VENDOR_TYPE 0xfcfbfaf9
32 /* #define TEST_PENDING_REQUEST */
34 struct eap_vendor_test_data
{
35 enum { INIT
, CONFIRM
, SUCCESS
} state
;
40 static void * eap_vendor_test_init(struct eap_sm
*sm
)
42 struct eap_vendor_test_data
*data
;
43 data
= os_zalloc(sizeof(*data
));
52 static void eap_vendor_test_deinit(struct eap_sm
*sm
, void *priv
)
54 struct eap_vendor_test_data
*data
= priv
;
59 #ifdef TEST_PENDING_REQUEST
60 static void eap_vendor_ready(void *eloop_ctx
, void *timeout_ctx
)
62 struct eap_sm
*sm
= eloop_ctx
;
63 wpa_printf(MSG_DEBUG
, "EAP-VENDOR-TEST: Ready to re-process pending "
65 eap_notify_pending(sm
);
67 #endif /* TEST_PENDING_REQUEST */
70 static struct wpabuf
* eap_vendor_test_process(struct eap_sm
*sm
, void *priv
,
71 struct eap_method_ret
*ret
,
72 const struct wpabuf
*reqData
)
74 struct eap_vendor_test_data
*data
= priv
;
79 pos
= eap_hdr_validate(EAP_VENDOR_ID
, EAP_VENDOR_TYPE
, reqData
, &len
);
80 if (pos
== NULL
|| len
< 1) {
85 if (data
->state
== INIT
&& *pos
!= 1) {
86 wpa_printf(MSG_DEBUG
, "EAP-VENDOR-TEST: Unexpected message "
87 "%d in INIT state", *pos
);
92 if (data
->state
== CONFIRM
&& *pos
!= 3) {
93 wpa_printf(MSG_DEBUG
, "EAP-VENDOR-TEST: Unexpected message "
94 "%d in CONFIRM state", *pos
);
99 if (data
->state
== SUCCESS
) {
100 wpa_printf(MSG_DEBUG
, "EAP-VENDOR-TEST: Unexpected message "
106 if (data
->state
== CONFIRM
) {
107 #ifdef TEST_PENDING_REQUEST
108 if (data
->first_try
) {
110 wpa_printf(MSG_DEBUG
, "EAP-VENDOR-TEST: Testing "
113 eloop_register_timeout(1, 0, eap_vendor_ready
, sm
,
117 #endif /* TEST_PENDING_REQUEST */
122 wpa_printf(MSG_DEBUG
, "EAP-VENDOR-TEST: Generating Response");
123 ret
->allowNotifications
= TRUE
;
125 resp
= eap_msg_alloc(EAP_VENDOR_ID
, EAP_VENDOR_TYPE
, 1,
126 EAP_CODE_RESPONSE
, eap_get_id(reqData
));
130 if (data
->state
== INIT
) {
131 wpabuf_put_u8(resp
, 2);
132 data
->state
= CONFIRM
;
133 ret
->methodState
= METHOD_CONT
;
134 ret
->decision
= DECISION_FAIL
;
136 wpabuf_put_u8(resp
, 4);
137 data
->state
= SUCCESS
;
138 ret
->methodState
= METHOD_DONE
;
139 ret
->decision
= DECISION_UNCOND_SUCC
;
146 static Boolean
eap_vendor_test_isKeyAvailable(struct eap_sm
*sm
, void *priv
)
148 struct eap_vendor_test_data
*data
= priv
;
149 return data
->state
== SUCCESS
;
153 static u8
* eap_vendor_test_getKey(struct eap_sm
*sm
, void *priv
, size_t *len
)
155 struct eap_vendor_test_data
*data
= priv
;
157 const int key_len
= 64;
159 if (data
->state
!= SUCCESS
)
162 key
= os_malloc(key_len
);
166 os_memset(key
, 0x11, key_len
/ 2);
167 os_memset(key
+ key_len
/ 2, 0x22, key_len
/ 2);
174 int eap_peer_vendor_test_register(void)
176 struct eap_method
*eap
;
179 eap
= eap_peer_method_alloc(EAP_PEER_METHOD_INTERFACE_VERSION
,
180 EAP_VENDOR_ID
, EAP_VENDOR_TYPE
,
185 eap
->init
= eap_vendor_test_init
;
186 eap
->deinit
= eap_vendor_test_deinit
;
187 eap
->process
= eap_vendor_test_process
;
188 eap
->isKeyAvailable
= eap_vendor_test_isKeyAvailable
;
189 eap
->getKey
= eap_vendor_test_getKey
;
191 ret
= eap_peer_method_register(eap
);
193 eap_peer_method_free(eap
);