eapol_supp_sm.h revision 61d9df3e62aaa0e87ad05452fcb95142159a17b6
1/*
2 * EAPOL supplicant state machines
3 * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9#ifndef EAPOL_SUPP_SM_H
10#define EAPOL_SUPP_SM_H
11
12#include "common/defs.h"
13
14typedef enum { Unauthorized, Authorized } PortStatus;
15typedef enum { Auto, ForceUnauthorized, ForceAuthorized } PortControl;
16
17/**
18 * struct eapol_config - Per network configuration for EAPOL state machines
19 */
20struct eapol_config {
21	/**
22	 * accept_802_1x_keys - Accept IEEE 802.1X (non-WPA) EAPOL-Key frames
23	 *
24	 * This variable should be set to 1 when using EAPOL state machines
25	 * with non-WPA security policy to generate dynamic WEP keys. When
26	 * using WPA, this should be set to 0 so that WPA state machine can
27	 * process the EAPOL-Key frames.
28	 */
29	int accept_802_1x_keys;
30
31#define EAPOL_REQUIRE_KEY_UNICAST BIT(0)
32#define EAPOL_REQUIRE_KEY_BROADCAST BIT(1)
33	/**
34	 * required_keys - Which EAPOL-Key packets are required
35	 *
36	 * This variable determines which EAPOL-Key packets are required before
37	 * marking connection authenticated. This is a bit field of
38	 * EAPOL_REQUIRE_KEY_UNICAST and EAPOL_REQUIRE_KEY_BROADCAST flags.
39	 */
40	int required_keys;
41
42	/**
43	 * fast_reauth - Whether fast EAP reauthentication is enabled
44	 */
45	int fast_reauth;
46
47	/**
48	 * workaround - Whether EAP workarounds are enabled
49	 */
50	unsigned int workaround;
51
52	/**
53	 * eap_disabled - Whether EAP is disabled
54	 */
55	int eap_disabled;
56};
57
58struct eapol_sm;
59struct wpa_config_blob;
60
61/**
62 * struct eapol_ctx - Global (for all networks) EAPOL state machine context
63 */
64struct eapol_ctx {
65	/**
66	 * ctx - Pointer to arbitrary upper level context
67	 */
68	void *ctx;
69
70	/**
71	 * preauth - IEEE 802.11i/RSN pre-authentication
72	 *
73	 * This EAPOL state machine is used for IEEE 802.11i/RSN
74	 * pre-authentication
75	 */
76	int preauth;
77
78	/**
79	 * cb - Function to be called when EAPOL negotiation has been completed
80	 * @eapol: Pointer to EAPOL state machine data
81	 * @success: Whether the authentication was completed successfully
82	 * @ctx: Pointer to context data (cb_ctx)
83	 *
84	 * This optional callback function will be called when the EAPOL
85	 * authentication has been completed. This allows the owner of the
86	 * EAPOL state machine to process the key and terminate the EAPOL state
87	 * machine. Currently, this is used only in RSN pre-authentication.
88	 */
89	void (*cb)(struct eapol_sm *eapol, int success, void *ctx);
90
91	/**
92	 * cb_ctx - Callback context for cb()
93	 */
94	void *cb_ctx;
95
96	/**
97	 * msg_ctx - Callback context for wpa_msg() calls
98	 */
99	void *msg_ctx;
100
101	/**
102	 * scard_ctx - Callback context for PC/SC scard_*() function calls
103	 *
104	 * This context can be updated with eapol_sm_register_scard_ctx().
105	 */
106	void *scard_ctx;
107
108	/**
109	 * eapol_send_ctx - Callback context for eapol_send() calls
110	 */
111	void *eapol_send_ctx;
112
113	/**
114	 * eapol_done_cb - Function to be called at successful completion
115	 * @ctx: Callback context (ctx)
116	 *
117	 * This function is called at the successful completion of EAPOL
118	 * authentication. If dynamic WEP keys are used, this is called only
119	 * after all the expected keys have been received.
120	 */
121	void (*eapol_done_cb)(void *ctx);
122
123	/**
124	 * eapol_send - Send EAPOL packets
125	 * @ctx: Callback context (eapol_send_ctx)
126	 * @type: EAPOL type (IEEE802_1X_TYPE_*)
127	 * @buf: Pointer to EAPOL payload
128	 * @len: Length of the EAPOL payload
129	 * Returns: 0 on success, -1 on failure
130	 */
131	int (*eapol_send)(void *ctx, int type, const u8 *buf, size_t len);
132
133	/**
134	 * set_wep_key - Configure WEP keys
135	 * @ctx: Callback context (ctx)
136	 * @unicast: Non-zero = unicast, 0 = multicast/broadcast key
137	 * @keyidx: Key index (0..3)
138	 * @key: WEP key
139	 * @keylen: Length of the WEP key
140	 * Returns: 0 on success, -1 on failure
141	 */
142	int (*set_wep_key)(void *ctx, int unicast, int keyidx,
143			   const u8 *key, size_t keylen);
144
145	/**
146	 * set_config_blob - Set or add a named configuration blob
147	 * @ctx: Callback context (ctx)
148	 * @blob: New value for the blob
149	 *
150	 * Adds a new configuration blob or replaces the current value of an
151	 * existing blob.
152	 */
153	void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob);
154
155	/**
156	 * get_config_blob - Get a named configuration blob
157	 * @ctx: Callback context (ctx)
158	 * @name: Name of the blob
159	 * Returns: Pointer to blob data or %NULL if not found
160	 */
161	const struct wpa_config_blob * (*get_config_blob)(void *ctx,
162							  const char *name);
163
164	/**
165	 * aborted_cached - Notify that cached PMK attempt was aborted
166	 * @ctx: Callback context (ctx)
167	 */
168	void (*aborted_cached)(void *ctx);
169
170	/**
171	 * opensc_engine_path - Path to the OpenSSL engine for opensc
172	 *
173	 * This is an OpenSSL specific configuration option for loading OpenSC
174	 * engine (engine_opensc.so); if %NULL, this engine is not loaded.
175	 */
176	const char *opensc_engine_path;
177
178	/**
179	 * pkcs11_engine_path - Path to the OpenSSL engine for PKCS#11
180	 *
181	 * This is an OpenSSL specific configuration option for loading PKCS#11
182	 * engine (engine_pkcs11.so); if %NULL, this engine is not loaded.
183	 */
184	const char *pkcs11_engine_path;
185
186	/**
187	 * pkcs11_module_path - Path to the OpenSSL OpenSC/PKCS#11 module
188	 *
189	 * This is an OpenSSL specific configuration option for configuring
190	 * path to OpenSC/PKCS#11 engine (opensc-pkcs11.so); if %NULL, this
191	 * module is not loaded.
192	 */
193	const char *pkcs11_module_path;
194
195	/**
196	 * wps - WPS context data
197	 *
198	 * This is only used by EAP-WSC and can be left %NULL if not available.
199	 */
200	struct wps_context *wps;
201
202	/**
203	 * eap_param_needed - Notify that EAP parameter is needed
204	 * @ctx: Callback context (ctx)
205	 * @field: Field indicator (e.g., WPA_CTRL_REQ_EAP_IDENTITY)
206	 * @txt: User readable text describing the required parameter
207	 */
208	void (*eap_param_needed)(void *ctx, enum wpa_ctrl_req_type field,
209				 const char *txt);
210
211	/**
212	 * port_cb - Set port authorized/unauthorized callback (optional)
213	 * @ctx: Callback context (ctx)
214	 * @authorized: Whether the supplicant port is now in authorized state
215	 */
216	void (*port_cb)(void *ctx, int authorized);
217
218	/**
219	 * cert_cb - Notification of a peer certificate
220	 * @ctx: Callback context (ctx)
221	 * @depth: Depth in certificate chain (0 = server)
222	 * @subject: Subject of the peer certificate
223	 * @cert_hash: SHA-256 hash of the certificate
224	 * @cert: Peer certificate
225	 */
226	void (*cert_cb)(void *ctx, int depth, const char *subject,
227			const char *cert_hash, const struct wpabuf *cert);
228
229	/**
230	 * cert_in_cb - Include server certificates in callback
231	 */
232	int cert_in_cb;
233
234	/**
235	 * status_cb - Notification of a change in EAP status
236	 * @ctx: Callback context (ctx)
237	 * @status: Step in the process of EAP authentication
238	 * @parameter: Step-specific parameter, e.g., EAP method name
239	 */
240	void (*status_cb)(void *ctx, const char *status,
241			  const char *parameter);
242};
243
244
245struct eap_peer_config;
246struct ext_password_data;
247
248#ifdef IEEE8021X_EAPOL
249struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx);
250void eapol_sm_deinit(struct eapol_sm *sm);
251void eapol_sm_step(struct eapol_sm *sm);
252int eapol_sm_get_status(struct eapol_sm *sm, char *buf, size_t buflen,
253			int verbose);
254int eapol_sm_get_mib(struct eapol_sm *sm, char *buf, size_t buflen);
255void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod, int authPeriod,
256			int startPeriod, int maxStart);
257int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src, const u8 *buf,
258		      size_t len);
259void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm);
260void eapol_sm_notify_portEnabled(struct eapol_sm *sm, Boolean enabled);
261void eapol_sm_notify_portValid(struct eapol_sm *sm, Boolean valid);
262void eapol_sm_notify_eap_success(struct eapol_sm *sm, Boolean success);
263void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail);
264void eapol_sm_notify_config(struct eapol_sm *sm,
265			    struct eap_peer_config *config,
266			    const struct eapol_config *conf);
267int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len);
268void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff);
269void eapol_sm_notify_cached(struct eapol_sm *sm);
270void eapol_sm_notify_pmkid_attempt(struct eapol_sm *sm, int attempt);
271void eapol_sm_register_scard_ctx(struct eapol_sm *sm, void *ctx);
272void eapol_sm_notify_portControl(struct eapol_sm *sm, PortControl portControl);
273void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm);
274void eapol_sm_notify_ctrl_response(struct eapol_sm *sm);
275void eapol_sm_request_reauth(struct eapol_sm *sm);
276void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm, int in_eapol_sm);
277void eapol_sm_invalidate_cached_session(struct eapol_sm *sm);
278const char * eapol_sm_get_method_name(struct eapol_sm *sm);
279void eapol_sm_set_ext_pw_ctx(struct eapol_sm *sm,
280			     struct ext_password_data *ext);
281int eapol_sm_failed(struct eapol_sm *sm);
282#else /* IEEE8021X_EAPOL */
283static inline struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx)
284{
285	free(ctx);
286	return (struct eapol_sm *) 1;
287}
288static inline void eapol_sm_deinit(struct eapol_sm *sm)
289{
290}
291static inline void eapol_sm_step(struct eapol_sm *sm)
292{
293}
294static inline int eapol_sm_get_status(struct eapol_sm *sm, char *buf,
295				      size_t buflen, int verbose)
296{
297	return 0;
298}
299static inline int eapol_sm_get_mib(struct eapol_sm *sm, char *buf,
300				   size_t buflen)
301{
302	return 0;
303}
304static inline void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod,
305				      int authPeriod, int startPeriod,
306				      int maxStart)
307{
308}
309static inline int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src,
310				    const u8 *buf, size_t len)
311{
312	return 0;
313}
314static inline void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm)
315{
316}
317static inline void eapol_sm_notify_portEnabled(struct eapol_sm *sm,
318					       Boolean enabled)
319{
320}
321static inline void eapol_sm_notify_portValid(struct eapol_sm *sm,
322					     Boolean valid)
323{
324}
325static inline void eapol_sm_notify_eap_success(struct eapol_sm *sm,
326					       Boolean success)
327{
328}
329static inline void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail)
330{
331}
332static inline void eapol_sm_notify_config(struct eapol_sm *sm,
333					  struct eap_peer_config *config,
334					  struct eapol_config *conf)
335{
336}
337static inline int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len)
338{
339	return -1;
340}
341static inline void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff)
342{
343}
344static inline void eapol_sm_notify_cached(struct eapol_sm *sm)
345{
346}
347#define eapol_sm_notify_pmkid_attempt(sm, attempt) do { } while (0)
348#define eapol_sm_register_scard_ctx(sm, ctx) do { } while (0)
349static inline void eapol_sm_notify_portControl(struct eapol_sm *sm,
350					       PortControl portControl)
351{
352}
353static inline void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm)
354{
355}
356static inline void eapol_sm_notify_ctrl_response(struct eapol_sm *sm)
357{
358}
359static inline void eapol_sm_request_reauth(struct eapol_sm *sm)
360{
361}
362static inline void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm,
363						       int in_eapol_sm)
364{
365}
366static inline void eapol_sm_invalidate_cached_session(struct eapol_sm *sm)
367{
368}
369static inline const char * eapol_sm_get_method_name(struct eapol_sm *sm)
370{
371	return NULL;
372}
373static inline void eapol_sm_set_ext_pw_ctx(struct eapol_sm *sm,
374					   struct ext_password_data *ext)
375{
376}
377static inline int eapol_sm_failed(struct eapol_sm *sm)
378{
379	return 0;
380}
381#endif /* IEEE8021X_EAPOL */
382
383#endif /* EAPOL_SUPP_SM_H */
384