2 * hostapd / Test method for vendor specific (expanded) EAP type
3 * Copyright (c) 2005-2007, 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 #define EAP_VENDOR_ID 0xfffefd
22 #define EAP_VENDOR_TYPE 0xfcfbfaf9
25 struct eap_vendor_test_data
{
26 enum { INIT
, CONFIRM
, SUCCESS
, FAILURE
} state
;
30 static const char * eap_vendor_test_state_txt(int state
)
47 static void eap_vendor_test_state(struct eap_vendor_test_data
*data
,
50 wpa_printf(MSG_DEBUG
, "EAP-VENDOR-TEST: %s -> %s",
51 eap_vendor_test_state_txt(data
->state
),
52 eap_vendor_test_state_txt(state
));
57 static void * eap_vendor_test_init(struct eap_sm
*sm
)
59 struct eap_vendor_test_data
*data
;
61 data
= os_zalloc(sizeof(*data
));
70 static void eap_vendor_test_reset(struct eap_sm
*sm
, void *priv
)
72 struct eap_vendor_test_data
*data
= priv
;
77 static struct wpabuf
* eap_vendor_test_buildReq(struct eap_sm
*sm
, void *priv
,
80 struct eap_vendor_test_data
*data
= priv
;
83 req
= eap_msg_alloc(EAP_VENDOR_ID
, EAP_VENDOR_TYPE
, 1,
84 EAP_CODE_REQUEST
, id
);
86 wpa_printf(MSG_ERROR
, "EAP-VENDOR-TEST: Failed to allocate "
87 "memory for request");
91 wpabuf_put_u8(req
, data
->state
== INIT
? 1 : 3);
97 static Boolean
eap_vendor_test_check(struct eap_sm
*sm
, void *priv
,
98 struct wpabuf
*respData
)
103 pos
= eap_hdr_validate(EAP_VENDOR_ID
, EAP_VENDOR_TYPE
, respData
, &len
);
104 if (pos
== NULL
|| len
< 1) {
105 wpa_printf(MSG_INFO
, "EAP-VENDOR-TEST: Invalid frame");
113 static void eap_vendor_test_process(struct eap_sm
*sm
, void *priv
,
114 struct wpabuf
*respData
)
116 struct eap_vendor_test_data
*data
= priv
;
120 pos
= eap_hdr_validate(EAP_VENDOR_ID
, EAP_VENDOR_TYPE
, respData
, &len
);
121 if (pos
== NULL
|| len
< 1)
124 if (data
->state
== INIT
) {
126 eap_vendor_test_state(data
, CONFIRM
);
128 eap_vendor_test_state(data
, FAILURE
);
129 } else if (data
->state
== CONFIRM
) {
131 eap_vendor_test_state(data
, SUCCESS
);
133 eap_vendor_test_state(data
, FAILURE
);
135 eap_vendor_test_state(data
, FAILURE
);
139 static Boolean
eap_vendor_test_isDone(struct eap_sm
*sm
, void *priv
)
141 struct eap_vendor_test_data
*data
= priv
;
142 return data
->state
== SUCCESS
;
146 static u8
* eap_vendor_test_getKey(struct eap_sm
*sm
, void *priv
, size_t *len
)
148 struct eap_vendor_test_data
*data
= priv
;
150 const int key_len
= 64;
152 if (data
->state
!= SUCCESS
)
155 key
= os_malloc(key_len
);
159 os_memset(key
, 0x11, key_len
/ 2);
160 os_memset(key
+ key_len
/ 2, 0x22, key_len
/ 2);
167 static Boolean
eap_vendor_test_isSuccess(struct eap_sm
*sm
, void *priv
)
169 struct eap_vendor_test_data
*data
= priv
;
170 return data
->state
== SUCCESS
;
174 int eap_server_vendor_test_register(void)
176 struct eap_method
*eap
;
179 eap
= eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION
,
180 EAP_VENDOR_ID
, EAP_VENDOR_TYPE
,
185 eap
->init
= eap_vendor_test_init
;
186 eap
->reset
= eap_vendor_test_reset
;
187 eap
->buildReq
= eap_vendor_test_buildReq
;
188 eap
->check
= eap_vendor_test_check
;
189 eap
->process
= eap_vendor_test_process
;
190 eap
->isDone
= eap_vendor_test_isDone
;
191 eap
->getKey
= eap_vendor_test_getKey
;
192 eap
->isSuccess
= eap_vendor_test_isSuccess
;
194 ret
= eap_server_method_register(eap
);
196 eap_server_method_free(eap
);