2 * EAPOL supplicant state machines
3 * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #ifndef EAPOL_SUPP_SM_H
10 #define EAPOL_SUPP_SM_H
12 #include "common/defs.h"
16 typedef enum { Unauthorized
, Authorized
} PortStatus
;
17 typedef enum { Auto
, ForceUnauthorized
, ForceAuthorized
} PortControl
;
20 * struct eapol_config - Per network configuration for EAPOL state machines
24 * accept_802_1x_keys - Accept IEEE 802.1X (non-WPA) EAPOL-Key frames
26 * This variable should be set to 1 when using EAPOL state machines
27 * with non-WPA security policy to generate dynamic WEP keys. When
28 * using WPA, this should be set to 0 so that WPA state machine can
29 * process the EAPOL-Key frames.
31 int accept_802_1x_keys
;
33 #define EAPOL_REQUIRE_KEY_UNICAST BIT(0)
34 #define EAPOL_REQUIRE_KEY_BROADCAST BIT(1)
36 * required_keys - Which EAPOL-Key packets are required
38 * This variable determines which EAPOL-Key packets are required before
39 * marking connection authenticated. This is a bit field of
40 * EAPOL_REQUIRE_KEY_UNICAST and EAPOL_REQUIRE_KEY_BROADCAST flags.
45 * fast_reauth - Whether fast EAP reauthentication is enabled
50 * workaround - Whether EAP workarounds are enabled
52 unsigned int workaround
;
55 * eap_disabled - Whether EAP is disabled
60 * external_sim - Use external processing for SIM/USIM operations
64 #define EAPOL_LOCAL_WPS_IN_USE BIT(0)
65 #define EAPOL_PEER_IS_WPS20_AP BIT(1)
67 * wps - Whether this connection is used for WPS
73 struct wpa_config_blob
;
75 enum eapol_supp_result
{
76 EAPOL_SUPP_RESULT_FAILURE
,
77 EAPOL_SUPP_RESULT_SUCCESS
,
78 EAPOL_SUPP_RESULT_EXPECTED_FAILURE
82 * struct eapol_ctx - Global (for all networks) EAPOL state machine context
86 * ctx - Pointer to arbitrary upper level context
91 * preauth - IEEE 802.11i/RSN pre-authentication
93 * This EAPOL state machine is used for IEEE 802.11i/RSN
99 * cb - Function to be called when EAPOL negotiation has been completed
100 * @eapol: Pointer to EAPOL state machine data
101 * @result: Whether the authentication was completed successfully
102 * @ctx: Pointer to context data (cb_ctx)
104 * This optional callback function will be called when the EAPOL
105 * authentication has been completed. This allows the owner of the
106 * EAPOL state machine to process the key and terminate the EAPOL state
107 * machine. Currently, this is used only in RSN pre-authentication.
109 void (*cb
)(struct eapol_sm
*eapol
, enum eapol_supp_result result
,
113 * cb_ctx - Callback context for cb()
118 * msg_ctx - Callback context for wpa_msg() calls
123 * scard_ctx - Callback context for PC/SC scard_*() function calls
125 * This context can be updated with eapol_sm_register_scard_ctx().
130 * eapol_send_ctx - Callback context for eapol_send() calls
132 void *eapol_send_ctx
;
135 * eapol_done_cb - Function to be called at successful completion
136 * @ctx: Callback context (ctx)
138 * This function is called at the successful completion of EAPOL
139 * authentication. If dynamic WEP keys are used, this is called only
140 * after all the expected keys have been received.
142 void (*eapol_done_cb
)(void *ctx
);
145 * eapol_send - Send EAPOL packets
146 * @ctx: Callback context (eapol_send_ctx)
147 * @type: EAPOL type (IEEE802_1X_TYPE_*)
148 * @buf: Pointer to EAPOL payload
149 * @len: Length of the EAPOL payload
150 * Returns: 0 on success, -1 on failure
152 int (*eapol_send
)(void *ctx
, int type
, const u8
*buf
, size_t len
);
155 * set_wep_key - Configure WEP keys
156 * @ctx: Callback context (ctx)
157 * @unicast: Non-zero = unicast, 0 = multicast/broadcast key
158 * @keyidx: Key index (0..3)
160 * @keylen: Length of the WEP key
161 * Returns: 0 on success, -1 on failure
163 int (*set_wep_key
)(void *ctx
, int unicast
, int keyidx
,
164 const u8
*key
, size_t keylen
);
167 * set_config_blob - Set or add a named configuration blob
168 * @ctx: Callback context (ctx)
169 * @blob: New value for the blob
171 * Adds a new configuration blob or replaces the current value of an
174 void (*set_config_blob
)(void *ctx
, struct wpa_config_blob
*blob
);
177 * get_config_blob - Get a named configuration blob
178 * @ctx: Callback context (ctx)
179 * @name: Name of the blob
180 * Returns: Pointer to blob data or %NULL if not found
182 const struct wpa_config_blob
* (*get_config_blob
)(void *ctx
,
186 * aborted_cached - Notify that cached PMK attempt was aborted
187 * @ctx: Callback context (ctx)
189 void (*aborted_cached
)(void *ctx
);
192 * opensc_engine_path - Path to the OpenSSL engine for opensc
194 * This is an OpenSSL specific configuration option for loading OpenSC
195 * engine (engine_opensc.so); if %NULL, this engine is not loaded.
197 const char *opensc_engine_path
;
200 * pkcs11_engine_path - Path to the OpenSSL engine for PKCS#11
202 * This is an OpenSSL specific configuration option for loading PKCS#11
203 * engine (engine_pkcs11.so); if %NULL, this engine is not loaded.
205 const char *pkcs11_engine_path
;
208 * pkcs11_module_path - Path to the OpenSSL OpenSC/PKCS#11 module
210 * This is an OpenSSL specific configuration option for configuring
211 * path to OpenSC/PKCS#11 engine (opensc-pkcs11.so); if %NULL, this
212 * module is not loaded.
214 const char *pkcs11_module_path
;
217 * openssl_ciphers - OpenSSL cipher string
219 * This is an OpenSSL specific configuration option for configuring the
220 * default ciphers. If not set, "DEFAULT:!EXP:!LOW" is used as the
223 const char *openssl_ciphers
;
226 * wps - WPS context data
228 * This is only used by EAP-WSC and can be left %NULL if not available.
230 struct wps_context
*wps
;
233 * eap_param_needed - Notify that EAP parameter is needed
234 * @ctx: Callback context (ctx)
235 * @field: Field indicator (e.g., WPA_CTRL_REQ_EAP_IDENTITY)
236 * @txt: User readable text describing the required parameter
238 void (*eap_param_needed
)(void *ctx
, enum wpa_ctrl_req_type field
,
242 * port_cb - Set port authorized/unauthorized callback (optional)
243 * @ctx: Callback context (ctx)
244 * @authorized: Whether the supplicant port is now in authorized state
246 void (*port_cb
)(void *ctx
, int authorized
);
249 * cert_cb - Notification of a peer certificate
250 * @ctx: Callback context (ctx)
251 * @cert: Certificate information
252 * @cert_hash: SHA-256 hash of the certificate
254 void (*cert_cb
)(void *ctx
, struct tls_cert_data
*cert
,
255 const char *cert_hash
);
258 * cert_in_cb - Include server certificates in callback
263 * status_cb - Notification of a change in EAP status
264 * @ctx: Callback context (ctx)
265 * @status: Step in the process of EAP authentication
266 * @parameter: Step-specific parameter, e.g., EAP method name
268 void (*status_cb
)(void *ctx
, const char *status
,
269 const char *parameter
);
272 * eap_error_cb - Notification of EAP method error
273 * @ctx: Callback context (ctx)
274 * @error_code: EAP method error code
276 void (*eap_error_cb
)(void *ctx
, int error_code
);
278 #ifdef CONFIG_EAP_PROXY
280 * eap_proxy_cb - Callback signifying any updates from eap_proxy
281 * @ctx: eapol_ctx from eap_peer_sm_init() call
283 void (*eap_proxy_cb
)(void *ctx
);
286 * eap_proxy_notify_sim_status - Notification of SIM status change
287 * @ctx: eapol_ctx from eap_peer_sm_init() call
288 * @status: One of enum value from sim_state
290 void (*eap_proxy_notify_sim_status
)(void *ctx
,
291 enum eap_proxy_sim_state sim_state
);
292 #endif /* CONFIG_EAP_PROXY */
295 * set_anon_id - Set or add anonymous identity
296 * @ctx: eapol_ctx from eap_peer_sm_init() call
297 * @id: Anonymous identity (e.g., EAP-SIM pseudonym)
298 * @len: Length of anonymous identity in octets
300 void (*set_anon_id
)(void *ctx
, const u8
*id
, size_t len
);
303 * confirm_auth_cb - Callback confirming if we can install a new PTK
304 * @ctx: eapol_ctx from eap_peer_sm_init() call
305 * Returns: 0 when authentication can continue, -1 when reconnecting
307 * Automatically triggers a reconnect when not.
309 int (*confirm_auth_cb
)(void *ctx
);
313 struct eap_peer_config
;
314 struct ext_password_data
;
316 #ifdef IEEE8021X_EAPOL
317 struct eapol_sm
*eapol_sm_init(struct eapol_ctx
*ctx
);
318 void eapol_sm_deinit(struct eapol_sm
*sm
);
319 void eapol_sm_step(struct eapol_sm
*sm
);
320 int eapol_sm_get_status(struct eapol_sm
*sm
, char *buf
, size_t buflen
,
322 int eapol_sm_get_mib(struct eapol_sm
*sm
, char *buf
, size_t buflen
);
323 void eapol_sm_configure(struct eapol_sm
*sm
, int heldPeriod
, int authPeriod
,
324 int startPeriod
, int maxStart
);
325 int eapol_sm_rx_eapol(struct eapol_sm
*sm
, const u8
*src
, const u8
*buf
,
327 void eapol_sm_notify_tx_eapol_key(struct eapol_sm
*sm
);
328 void eapol_sm_notify_portEnabled(struct eapol_sm
*sm
, Boolean enabled
);
329 void eapol_sm_notify_portValid(struct eapol_sm
*sm
, Boolean valid
);
330 void eapol_sm_notify_eap_success(struct eapol_sm
*sm
, Boolean success
);
331 void eapol_sm_notify_eap_fail(struct eapol_sm
*sm
, Boolean fail
);
332 void eapol_sm_notify_config(struct eapol_sm
*sm
,
333 struct eap_peer_config
*config
,
334 const struct eapol_config
*conf
);
335 int eapol_sm_get_key(struct eapol_sm
*sm
, u8
*key
, size_t len
);
336 const u8
* eapol_sm_get_session_id(struct eapol_sm
*sm
, size_t *len
);
337 void eapol_sm_notify_logoff(struct eapol_sm
*sm
, Boolean logoff
);
338 void eapol_sm_notify_cached(struct eapol_sm
*sm
);
339 void eapol_sm_notify_pmkid_attempt(struct eapol_sm
*sm
);
340 void eapol_sm_register_scard_ctx(struct eapol_sm
*sm
, void *ctx
);
341 void eapol_sm_notify_portControl(struct eapol_sm
*sm
, PortControl portControl
);
342 void eapol_sm_notify_ctrl_attached(struct eapol_sm
*sm
);
343 void eapol_sm_notify_ctrl_response(struct eapol_sm
*sm
);
344 void eapol_sm_request_reauth(struct eapol_sm
*sm
);
345 void eapol_sm_notify_lower_layer_success(struct eapol_sm
*sm
, int in_eapol_sm
);
346 void eapol_sm_invalidate_cached_session(struct eapol_sm
*sm
);
347 const char * eapol_sm_get_method_name(struct eapol_sm
*sm
);
348 void eapol_sm_set_ext_pw_ctx(struct eapol_sm
*sm
,
349 struct ext_password_data
*ext
);
350 int eapol_sm_failed(struct eapol_sm
*sm
);
351 void eapol_sm_erp_flush(struct eapol_sm
*sm
);
352 struct wpabuf
* eapol_sm_build_erp_reauth_start(struct eapol_sm
*sm
);
353 void eapol_sm_process_erp_finish(struct eapol_sm
*sm
, const u8
*buf
,
355 int eapol_sm_get_eap_proxy_imsi(void *ctx
, int sim_num
, char *imsi
,
357 int eapol_sm_update_erp_next_seq_num(struct eapol_sm
*sm
, u16 next_seq_num
);
358 int eapol_sm_get_erp_info(struct eapol_sm
*sm
, struct eap_peer_config
*config
,
359 const u8
**username
, size_t *username_len
,
360 const u8
**realm
, size_t *realm_len
,
361 u16
*erp_next_seq_num
, const u8
**rrk
,
364 #else /* IEEE8021X_EAPOL */
365 static inline struct eapol_sm
*eapol_sm_init(struct eapol_ctx
*ctx
)
368 return (struct eapol_sm
*) 1;
370 static inline void eapol_sm_deinit(struct eapol_sm
*sm
)
373 static inline void eapol_sm_step(struct eapol_sm
*sm
)
376 static inline int eapol_sm_get_status(struct eapol_sm
*sm
, char *buf
,
377 size_t buflen
, int verbose
)
381 static inline int eapol_sm_get_mib(struct eapol_sm
*sm
, char *buf
,
386 static inline void eapol_sm_configure(struct eapol_sm
*sm
, int heldPeriod
,
387 int authPeriod
, int startPeriod
,
391 static inline int eapol_sm_rx_eapol(struct eapol_sm
*sm
, const u8
*src
,
392 const u8
*buf
, size_t len
)
396 static inline void eapol_sm_notify_tx_eapol_key(struct eapol_sm
*sm
)
399 static inline void eapol_sm_notify_portEnabled(struct eapol_sm
*sm
,
403 static inline void eapol_sm_notify_portValid(struct eapol_sm
*sm
,
407 static inline void eapol_sm_notify_eap_success(struct eapol_sm
*sm
,
411 static inline void eapol_sm_notify_eap_fail(struct eapol_sm
*sm
, Boolean fail
)
414 static inline void eapol_sm_notify_config(struct eapol_sm
*sm
,
415 struct eap_peer_config
*config
,
416 struct eapol_config
*conf
)
419 static inline int eapol_sm_get_key(struct eapol_sm
*sm
, u8
*key
, size_t len
)
423 static inline const u8
*
424 eapol_sm_get_session_id(struct eapol_sm
*sm
, size_t *len
)
428 static inline void eapol_sm_notify_logoff(struct eapol_sm
*sm
, Boolean logoff
)
431 static inline void eapol_sm_notify_cached(struct eapol_sm
*sm
)
434 static inline void eapol_sm_notify_pmkid_attempt(struct eapol_sm
*sm
)
437 #define eapol_sm_register_scard_ctx(sm, ctx) do { } while (0)
438 static inline void eapol_sm_notify_portControl(struct eapol_sm
*sm
,
439 PortControl portControl
)
442 static inline void eapol_sm_notify_ctrl_attached(struct eapol_sm
*sm
)
445 static inline void eapol_sm_notify_ctrl_response(struct eapol_sm
*sm
)
448 static inline void eapol_sm_request_reauth(struct eapol_sm
*sm
)
451 static inline void eapol_sm_notify_lower_layer_success(struct eapol_sm
*sm
,
455 static inline void eapol_sm_invalidate_cached_session(struct eapol_sm
*sm
)
458 static inline const char * eapol_sm_get_method_name(struct eapol_sm
*sm
)
462 static inline void eapol_sm_set_ext_pw_ctx(struct eapol_sm
*sm
,
463 struct ext_password_data
*ext
)
466 static inline int eapol_sm_failed(struct eapol_sm
*sm
)
470 static inline void eapol_sm_erp_flush(struct eapol_sm
*sm
)
473 static inline struct wpabuf
*
474 eapol_sm_build_erp_reauth_start(struct eapol_sm
*sm
)
478 static inline void eapol_sm_process_erp_finish(struct eapol_sm
*sm
,
479 const u8
*buf
, size_t len
)
482 static inline int eapol_sm_update_erp_next_seq_num(struct eapol_sm
*sm
,
488 eapol_sm_get_erp_info(struct eapol_sm
*sm
, struct eap_peer_config
*config
,
489 const u8
**username
, size_t *username_len
,
490 const u8
**realm
, size_t *realm_len
,
491 u16
*erp_next_seq_num
, const u8
**rrk
, size_t *rrk_len
)
495 #endif /* IEEE8021X_EAPOL */
497 #endif /* EAPOL_SUPP_SM_H */