2 * EAP peer state machines internal structures (RFC 4137)
3 * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
13 #include "eap_peer/eap.h"
14 #include "eap_common/eap_common.h"
16 /* RFC 4137 - EAP Peer state machine */
19 DECISION_FAIL, DECISION_COND_SUCC, DECISION_UNCOND_SUCC
23 METHOD_NONE, METHOD_INIT, METHOD_CONT, METHOD_MAY_CONT, METHOD_DONE
27 * struct eap_method_ret - EAP return values from struct eap_method::process()
29 * These structure contains OUT variables for the interface between peer state
30 * machine and methods (RFC 4137, Sect. 4.2). eapRespData will be returned as
31 * the return value of struct eap_method::process() so it is not included in
34 struct eap_method_ret {
36 * ignore - Whether method decided to drop the current packed (OUT)
41 * methodState - Method-specific state (IN/OUT)
43 EapMethodState methodState;
46 * decision - Authentication decision (OUT)
51 * allowNotifications - Whether method allows notifications (OUT)
53 Boolean allowNotifications;
58 * struct eap_method - EAP method interface
59 * This structure defines the EAP method interface. Each method will need to
60 * register its own EAP type, EAP name, and set of function pointers for method
61 * specific operations. This interface is based on section 4.4 of RFC 4137.
65 * vendor - EAP Vendor-ID (EAP_VENDOR_*) (0 = IETF)
70 * method - EAP type number (EAP_TYPE_*)
75 * name - Name of the method (e.g., "TLS")
80 * init - Initialize an EAP method
81 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
82 * Returns: Pointer to allocated private data, or %NULL on failure
84 * This function is used to initialize the EAP method explicitly
85 * instead of using METHOD_INIT state as specific in RFC 4137. The
86 * method is expected to initialize it method-specific state and return
87 * a pointer that will be used as the priv argument to other calls.
89 void * (*init)(struct eap_sm *sm);
92 * deinit - Deinitialize an EAP method
93 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
94 * @priv: Pointer to private EAP method data from eap_method::init()
96 * Deinitialize the EAP method and free any allocated private data.
98 void (*deinit)(struct eap_sm *sm, void *priv);
101 * process - Process an EAP request
102 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
103 * @priv: Pointer to private EAP method data from eap_method::init()
104 * @ret: Return values from EAP request validation and processing
105 * @reqData: EAP request to be processed (eapReqData)
106 * Returns: Pointer to allocated EAP response packet (eapRespData)
108 * This function is a combination of m.check(), m.process(), and
109 * m.buildResp() procedures defined in section 4.4 of RFC 4137 In other
110 * words, this function validates the incoming request, processes it,
111 * and build a response packet. m.check() and m.process() return values
112 * are returned through struct eap_method_ret *ret variable. Caller is
113 * responsible for freeing the returned EAP response packet.
115 struct wpabuf * (*process)(struct eap_sm *sm, void *priv,
116 struct eap_method_ret *ret,
117 const struct wpabuf *reqData);
120 * isKeyAvailable - Find out whether EAP method has keying material
121 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
122 * @priv: Pointer to private EAP method data from eap_method::init()
123 * Returns: %TRUE if key material (eapKeyData) is available
125 Boolean (*isKeyAvailable)(struct eap_sm *sm, void *priv);
128 * getKey - Get EAP method specific keying material (eapKeyData)
129 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
130 * @priv: Pointer to private EAP method data from eap_method::init()
131 * @len: Pointer to variable to store key length (eapKeyDataLen)
132 * Returns: Keying material (eapKeyData) or %NULL if not available
134 * This function can be used to get the keying material from the EAP
135 * method. The key may already be stored in the method-specific private
136 * data or this function may derive the key.
138 u8 * (*getKey)(struct eap_sm *sm, void *priv, size_t *len);
141 * get_status - Get EAP method status
142 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
143 * @priv: Pointer to private EAP method data from eap_method::init()
144 * @buf: Buffer for status information
145 * @buflen: Maximum buffer length
146 * @verbose: Whether to include verbose status information
147 * Returns: Number of bytes written to buf
149 * Query EAP method for status information. This function fills in a
150 * text area with current status information from the EAP method. If
151 * the buffer (buf) is not large enough, status information will be
152 * truncated to fit the buffer.
154 int (*get_status)(struct eap_sm *sm, void *priv, char *buf,
155 size_t buflen, int verbose);
158 * has_reauth_data - Whether method is ready for fast reauthentication
159 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
160 * @priv: Pointer to private EAP method data from eap_method::init()
161 * Returns: %TRUE or %FALSE based on whether fast reauthentication is
164 * This function is an optional handler that only EAP methods
165 * supporting fast re-authentication need to implement.
167 Boolean (*has_reauth_data)(struct eap_sm *sm, void *priv);
170 * deinit_for_reauth - Release data that is not needed for fast re-auth
171 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
172 * @priv: Pointer to private EAP method data from eap_method::init()
174 * This function is an optional handler that only EAP methods
175 * supporting fast re-authentication need to implement. This is called
176 * when authentication has been completed and EAP state machine is
177 * requesting that enough state information is maintained for fast
180 void (*deinit_for_reauth)(struct eap_sm *sm, void *priv);
183 * init_for_reauth - Prepare for start of fast re-authentication
184 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
185 * @priv: Pointer to private EAP method data from eap_method::init()
187 * This function is an optional handler that only EAP methods
188 * supporting fast re-authentication need to implement. This is called
189 * when EAP authentication is started and EAP state machine is
190 * requesting fast re-authentication to be used.
192 void * (*init_for_reauth)(struct eap_sm *sm, void *priv);
195 * get_identity - Get method specific identity for re-authentication
196 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
197 * @priv: Pointer to private EAP method data from eap_method::init()
198 * @len: Length of the returned identity
199 * Returns: Pointer to the method specific identity or %NULL if default
200 * identity is to be used
202 * This function is an optional handler that only EAP methods
203 * that use method specific identity need to implement.
205 const u8 * (*get_identity)(struct eap_sm *sm, void *priv, size_t *len);
208 * free - Free EAP method data
209 * @method: Pointer to the method data registered with
210 * eap_peer_method_register().
212 * This function will be called when the EAP method is being
213 * unregistered. If the EAP method allocated resources during
214 * registration (e.g., allocated struct eap_method), they should be
215 * freed in this function. No other method functions will be called
216 * after this call. If this function is not defined (i.e., function
217 * pointer is %NULL), a default handler is used to release the method
218 * data with free(method). This is suitable for most cases.
220 void (*free)(struct eap_method *method);
222 #define EAP_PEER_METHOD_INTERFACE_VERSION 1
224 * version - Version of the EAP peer method interface
226 * The EAP peer method implementation should set this variable to
227 * EAP_PEER_METHOD_INTERFACE_VERSION. This is used to verify that the
228 * EAP method is using supported API version when using dynamically
229 * loadable EAP methods.
234 * next - Pointer to the next EAP method
236 * This variable is used internally in the EAP method registration code
237 * to create a linked list of registered EAP methods.
239 struct eap_method *next;
241 #ifdef CONFIG_DYNAMIC_EAP_METHODS
243 * dl_handle - Handle for the dynamic library
245 * This variable is used internally in the EAP method registration code
246 * to store a handle for the dynamic library. If the method is linked
247 * in statically, this is %NULL.
250 #endif /* CONFIG_DYNAMIC_EAP_METHODS */
253 * get_emsk - Get EAP method specific keying extended material (EMSK)
254 * @sm: Pointer to EAP state machine allocated with eap_peer_sm_init()
255 * @priv: Pointer to private EAP method data from eap_method::init()
256 * @len: Pointer to a variable to store EMSK length
257 * Returns: EMSK or %NULL if not available
259 * This function can be used to get the extended keying material from
260 * the EAP method. The key may already be stored in the method-specific
261 * private data or this function may derive the key.
263 u8 * (*get_emsk)(struct eap_sm *sm, void *priv, size_t *len);
268 * struct eap_sm - EAP state machine data
272 EAP_INITIALIZE, EAP_DISABLED, EAP_IDLE, EAP_RECEIVED,
273 EAP_GET_METHOD, EAP_METHOD, EAP_SEND_RESPONSE, EAP_DISCARD,
274 EAP_IDENTITY, EAP_NOTIFICATION, EAP_RETRANSMIT, EAP_SUCCESS,
277 /* Long-term local variables */
278 EapType selectedMethod;
279 EapMethodState methodState;
281 struct wpabuf *lastRespData;
282 EapDecision decision;
283 /* Short-term local variables */
295 /* Miscellaneous variables */
296 Boolean allowNotifications; /* peer state machine <-> methods */
297 struct wpabuf *eapRespData; /* peer to lower layer */
298 Boolean eapKeyAvailable; /* peer to lower layer */
299 u8 *eapKeyData; /* peer to lower layer */
300 size_t eapKeyDataLen; /* peer to lower layer */
301 const struct eap_method *m; /* selected EAP method */
302 /* not defined in RFC 4137 */
305 struct eapol_callbacks *eapol_cb;
306 void *eap_method_priv;
310 Boolean rxResp /* LEAP only */;
313 u8 req_md5[16]; /* MD5() of the current EAP packet */
314 u8 last_md5[16]; /* MD5() of the previously received EAP packet; used
315 * in duplicate request detection. */
322 unsigned int workaround;
324 /* Optional challenges generated in Phase 1 (EAP-FAST) */
325 u8 *peer_challenge, *auth_challenge;
330 struct wps_context *wps;
334 struct ext_password_data *ext_pw;
335 struct wpabuf *ext_pw_buf;
338 const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len);
339 const u8 * eap_get_config_password(struct eap_sm *sm, size_t *len);
340 const u8 * eap_get_config_password2(struct eap_sm *sm, size_t *len, int *hash);
341 const u8 * eap_get_config_new_password(struct eap_sm *sm, size_t *len);
342 const u8 * eap_get_config_otp(struct eap_sm *sm, size_t *len);
343 void eap_clear_config_otp(struct eap_sm *sm);
344 const char * eap_get_config_phase1(struct eap_sm *sm);
345 const char * eap_get_config_phase2(struct eap_sm *sm);
346 int eap_get_config_fragment_size(struct eap_sm *sm);
347 struct eap_peer_config * eap_get_config(struct eap_sm *sm);
348 void eap_set_config_blob(struct eap_sm *sm, struct wpa_config_blob *blob);
349 const struct wpa_config_blob *
350 eap_get_config_blob(struct eap_sm *sm, const char *name);
351 void eap_notify_pending(struct eap_sm *sm);
352 int eap_allowed_method(struct eap_sm *sm, int vendor, u32 method);