2 * EAPOL supplicant state machines
3 * Copyright (c) 2004-2008, 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.
15 #ifndef EAPOL_SUPP_SM_H
16 #define EAPOL_SUPP_SM_H
20 typedef enum { Unauthorized, Authorized } PortStatus;
21 typedef enum { Auto, ForceUnauthorized, ForceAuthorized } PortControl;
24 * struct eapol_config - Per network configuration for EAPOL state machines
28 * accept_802_1x_keys - Accept IEEE 802.1X (non-WPA) EAPOL-Key frames
30 * This variable should be set to 1 when using EAPOL state machines
31 * with non-WPA security policy to generate dynamic WEP keys. When
32 * using WPA, this should be set to 0 so that WPA state machine can
33 * process the EAPOL-Key frames.
35 int accept_802_1x_keys;
37 #define EAPOL_REQUIRE_KEY_UNICAST BIT(0)
38 #define EAPOL_REQUIRE_KEY_BROADCAST BIT(1)
40 * required_keys - Which EAPOL-Key packets are required
42 * This variable determines which EAPOL-Key packets are required before
43 * marking connection authenticated. This is a bit field of
44 * EAPOL_REQUIRE_KEY_UNICAST and EAPOL_REQUIRE_KEY_BROADCAST flags.
49 * fast_reauth - Whether fast EAP reauthentication is enabled
54 * workaround - Whether EAP workarounds are enabled
56 unsigned int workaround;
59 * eap_disabled - Whether EAP is disabled
65 struct wpa_config_blob;
66 struct wps_credential;
69 * struct eapol_ctx - Global (for all networks) EAPOL state machine context
73 * ctx - Pointer to arbitrary upper level context
78 * preauth - IEEE 802.11i/RSN pre-authentication
80 * This EAPOL state machine is used for IEEE 802.11i/RSN
86 * cb - Function to be called when EAPOL negotiation has been completed
87 * @eapol: Pointer to EAPOL state machine data
88 * @success: Whether the authentication was completed successfully
89 * @ctx: Pointer to context data (cb_ctx)
91 * This optional callback function will be called when the EAPOL
92 * authentication has been completed. This allows the owner of the
93 * EAPOL state machine to process the key and terminate the EAPOL state
94 * machine. Currently, this is used only in RSN pre-authentication.
96 void (*cb)(struct eapol_sm *eapol, int success, void *ctx);
99 * cb_ctx - Callback context for cb()
104 * msg_ctx - Callback context for wpa_msg() calls
109 * scard_ctx - Callback context for PC/SC scard_*() function calls
111 * This context can be updated with eapol_sm_register_scard_ctx().
116 * eapol_send_ctx - Callback context for eapol_send() calls
118 void *eapol_send_ctx;
121 * eapol_done_cb - Function to be called at successful completion
122 * @ctx: Callback context (ctx)
124 * This function is called at the successful completion of EAPOL
125 * authentication. If dynamic WEP keys are used, this is called only
126 * after all the expected keys have been received.
128 void (*eapol_done_cb)(void *ctx);
131 * eapol_send - Send EAPOL packets
132 * @ctx: Callback context (eapol_send_ctx)
133 * @type: EAPOL type (IEEE802_1X_TYPE_*)
134 * @buf: Pointer to EAPOL payload
135 * @len: Length of the EAPOL payload
136 * Returns: 0 on success, -1 on failure
138 int (*eapol_send)(void *ctx, int type, const u8 *buf, size_t len);
141 * set_wep_key - Configure WEP keys
142 * @ctx: Callback context (ctx)
143 * @unicast: Non-zero = unicast, 0 = multicast/broadcast key
144 * @keyidx: Key index (0..3)
146 * @keylen: Length of the WEP key
147 * Returns: 0 on success, -1 on failure
149 int (*set_wep_key)(void *ctx, int unicast, int keyidx,
150 const u8 *key, size_t keylen);
153 * set_config_blob - Set or add a named configuration blob
154 * @ctx: Callback context (ctx)
155 * @blob: New value for the blob
157 * Adds a new configuration blob or replaces the current value of an
160 void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob);
163 * get_config_blob - Get a named configuration blob
164 * @ctx: Callback context (ctx)
165 * @name: Name of the blob
166 * Returns: Pointer to blob data or %NULL if not found
168 const struct wpa_config_blob * (*get_config_blob)(void *ctx,
172 * aborted_cached - Notify that cached PMK attempt was aborted
173 * @ctx: Callback context (ctx)
175 void (*aborted_cached)(void *ctx);
177 #ifdef EAP_TLS_OPENSSL
179 * opensc_engine_path - Path to the OpenSSL engine for opensc
181 * This is an OpenSSL specific configuration option for loading OpenSC
182 * engine (engine_opensc.so); if %NULL, this engine is not loaded.
184 const char *opensc_engine_path;
187 * pkcs11_engine_path - Path to the OpenSSL engine for PKCS#11
189 * This is an OpenSSL specific configuration option for loading PKCS#11
190 * engine (engine_pkcs11.so); if %NULL, this engine is not loaded.
192 const char *pkcs11_engine_path;
195 * pkcs11_module_path - Path to the OpenSSL OpenSC/PKCS#11 module
197 * This is an OpenSSL specific configuration option for configuring
198 * path to OpenSC/PKCS#11 engine (opensc-pkcs11.so); if %NULL, this
199 * module is not loaded.
201 const char *pkcs11_module_path;
202 #endif /* EAP_TLS_OPENSSL */
204 * mac_addr - MAC address of the peer
206 * This is only used by EAP-WSC and can be left %NULL if not available.
211 * wps_cred - Notify that new credential was received from WPS
212 * @ctx: Callback context (ctx)
213 * Returns: 0 on success (credential stored), -1 on failure
215 * This callback is only needed when using WPS Enrollee to configure
216 * new credentials. This can be left %NULL if no WPS functionality is
219 int (*wps_cred)(void *ctx, struct wps_credential *cred);
222 * eap_param_needed - Notify that EAP parameter is needed
223 * @ctx: Callback context (ctx)
224 * @field: Field name (e.g., "IDENTITY")
225 * @txt: User readable text describing the required parameter
227 void (*eap_param_needed)(void *ctx, const char *field,
232 struct eap_peer_config;
234 #ifdef IEEE8021X_EAPOL
235 struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx);
236 void eapol_sm_deinit(struct eapol_sm *sm);
237 void eapol_sm_step(struct eapol_sm *sm);
238 int eapol_sm_get_status(struct eapol_sm *sm, char *buf, size_t buflen,
240 int eapol_sm_get_mib(struct eapol_sm *sm, char *buf, size_t buflen);
241 void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod, int authPeriod,
242 int startPeriod, int maxStart);
243 int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src, const u8 *buf,
245 void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm);
246 void eapol_sm_notify_portEnabled(struct eapol_sm *sm, Boolean enabled);
247 void eapol_sm_notify_portValid(struct eapol_sm *sm, Boolean valid);
248 void eapol_sm_notify_eap_success(struct eapol_sm *sm, Boolean success);
249 void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail);
250 void eapol_sm_notify_config(struct eapol_sm *sm,
251 struct eap_peer_config *config,
252 const struct eapol_config *conf);
253 int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len);
254 void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff);
255 void eapol_sm_notify_cached(struct eapol_sm *sm);
256 void eapol_sm_notify_pmkid_attempt(struct eapol_sm *sm, int attempt);
257 void eapol_sm_register_scard_ctx(struct eapol_sm *sm, void *ctx);
258 void eapol_sm_notify_portControl(struct eapol_sm *sm, PortControl portControl);
259 void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm);
260 void eapol_sm_notify_ctrl_response(struct eapol_sm *sm);
261 void eapol_sm_request_reauth(struct eapol_sm *sm);
262 void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm, int in_eapol_sm);
263 void eapol_sm_invalidate_cached_session(struct eapol_sm *sm);
264 #else /* IEEE8021X_EAPOL */
265 static inline struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx)
268 return (struct eapol_sm *) 1;
270 static inline void eapol_sm_deinit(struct eapol_sm *sm)
273 static inline void eapol_sm_step(struct eapol_sm *sm)
276 static inline int eapol_sm_get_status(struct eapol_sm *sm, char *buf,
277 size_t buflen, int verbose)
281 static inline int eapol_sm_get_mib(struct eapol_sm *sm, char *buf,
286 static inline void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod,
287 int authPeriod, int startPeriod,
291 static inline int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src,
292 const u8 *buf, size_t len)
296 static inline void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm)
299 static inline void eapol_sm_notify_portEnabled(struct eapol_sm *sm,
303 static inline void eapol_sm_notify_portValid(struct eapol_sm *sm,
307 static inline void eapol_sm_notify_eap_success(struct eapol_sm *sm,
311 static inline void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail)
314 static inline void eapol_sm_notify_config(struct eapol_sm *sm,
315 struct eap_peer_config *config,
316 struct eapol_config *conf)
319 static inline int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len)
323 static inline void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff)
326 static inline void eapol_sm_notify_cached(struct eapol_sm *sm)
329 #define eapol_sm_notify_pmkid_attempt(sm, attempt) do { } while (0)
330 #define eapol_sm_register_scard_ctx(sm, ctx) do { } while (0)
331 static inline void eapol_sm_notify_portControl(struct eapol_sm *sm,
332 PortControl portControl)
335 static inline void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm)
338 static inline void eapol_sm_notify_ctrl_response(struct eapol_sm *sm)
341 static inline void eapol_sm_request_reauth(struct eapol_sm *sm)
344 static inline void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm,
348 static inline void eapol_sm_invalidate_cached_session(struct eapol_sm *sm)
351 #endif /* IEEE8021X_EAPOL */
353 #endif /* EAPOL_SUPP_SM_H */