2 * IEEE 802.1X-2004 Authenticator - EAPOL state machine
3 * Copyright (c) 2002-2009, 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_AUTH_SM_H
16 #define EAPOL_AUTH_SM_H
18 #include "common/defs.h"
19 #include "radius/radius.h"
21 /* IEEE Std 802.1X-2004, Ch. 8.2 */
23 typedef enum { ForceUnauthorized = 1, ForceAuthorized = 3, Auto = 2 }
25 typedef enum { Unauthorized = 2, Authorized = 1 } PortState;
26 typedef enum { Both = 0, In = 1 } ControlledDirection;
27 typedef unsigned int Counter;
32 struct eapol_auth_config {
33 int eap_reauth_period;
35 int individual_wep_key_len;
38 void *eap_sim_db_priv;
39 char *eap_req_id_text; /* a copy of this will be allocated */
40 size_t eap_req_id_text_len;
41 u8 *pac_opaque_encr_key;
43 size_t eap_fast_a_id_len;
44 char *eap_fast_a_id_info;
47 int pac_key_refresh_time;
48 int eap_sim_aka_result_ind;
50 struct wps_context *wps;
52 /* Opaque context pointer to owner data for callback functions */
59 EAPOL_LOGGER_DEBUG, EAPOL_LOGGER_INFO, EAPOL_LOGGER_WARNING
64 EAPOL_AUTH_REAUTHENTICATE
67 struct eapol_auth_cb {
68 void (*eapol_send)(void *ctx, void *sta_ctx, u8 type, const u8 *data,
70 void (*aaa_send)(void *ctx, void *sta_ctx, const u8 *data,
72 void (*finished)(void *ctx, void *sta_ctx, int success, int preauth);
73 int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len,
74 int phase2, struct eap_user *user);
75 int (*sta_entry_alive)(void *ctx, const u8 *addr);
76 void (*logger)(void *ctx, const u8 *addr, eapol_logger_level level,
78 void (*set_port_authorized)(void *ctx, void *sta_ctx, int authorized);
79 void (*abort_auth)(void *ctx, void *sta_ctx);
80 void (*tx_key)(void *ctx, void *sta_ctx);
81 void (*eapol_event)(void *ctx, void *sta_ctx, enum eapol_event type);
85 * struct eapol_authenticator - Global EAPOL authenticator data
87 struct eapol_authenticator {
88 struct eapol_auth_config conf;
89 struct eapol_auth_cb cb;
92 u8 default_wep_key_idx;
97 * struct eapol_state_machine - Per-Supplicant Authenticator state machines
99 struct eapol_state_machine {
105 /* global variables */
108 PortState authPortStatus;
116 Boolean keyTxEnabled;
117 PortTypes portControl;
119 Boolean reAuthenticate;
121 /* Port Timers state machine */
122 /* 'Boolean tick' implicitly handled as registered timeout */
124 /* Authenticator PAE state machine */
125 enum { AUTH_PAE_INITIALIZE, AUTH_PAE_DISCONNECTED, AUTH_PAE_CONNECTING,
126 AUTH_PAE_AUTHENTICATING, AUTH_PAE_AUTHENTICATED,
127 AUTH_PAE_ABORTING, AUTH_PAE_HELD, AUTH_PAE_FORCE_AUTH,
128 AUTH_PAE_FORCE_UNAUTH, AUTH_PAE_RESTART } auth_pae_state;
133 unsigned int reAuthCount;
135 unsigned int quietPeriod; /* default 60; 0..65535 */
136 #define AUTH_PAE_DEFAULT_quietPeriod 60
137 unsigned int reAuthMax; /* default 2 */
138 #define AUTH_PAE_DEFAULT_reAuthMax 2
140 Counter authEntersConnecting;
141 Counter authEapLogoffsWhileConnecting;
142 Counter authEntersAuthenticating;
143 Counter authAuthSuccessesWhileAuthenticating;
144 Counter authAuthTimeoutsWhileAuthenticating;
145 Counter authAuthFailWhileAuthenticating;
146 Counter authAuthEapStartsWhileAuthenticating;
147 Counter authAuthEapLogoffWhileAuthenticating;
148 Counter authAuthReauthsWhileAuthenticated;
149 Counter authAuthEapStartsWhileAuthenticated;
150 Counter authAuthEapLogoffWhileAuthenticated;
152 /* Backend Authentication state machine */
153 enum { BE_AUTH_REQUEST, BE_AUTH_RESPONSE, BE_AUTH_SUCCESS,
154 BE_AUTH_FAIL, BE_AUTH_TIMEOUT, BE_AUTH_IDLE, BE_AUTH_INITIALIZE,
158 unsigned int serverTimeout; /* default 30; 1..X */
159 #define BE_AUTH_DEFAULT_serverTimeout 30
161 Counter backendResponses;
162 Counter backendAccessChallenges;
163 Counter backendOtherRequestsToSupplicant;
164 Counter backendAuthSuccesses;
165 Counter backendAuthFails;
167 /* Reauthentication Timer state machine */
168 enum { REAUTH_TIMER_INITIALIZE, REAUTH_TIMER_REAUTHENTICATE
169 } reauth_timer_state;
171 unsigned int reAuthPeriod; /* default 3600 s */
172 Boolean reAuthEnabled;
174 /* Authenticator Key Transmit state machine */
175 enum { AUTH_KEY_TX_NO_KEY_TRANSMIT, AUTH_KEY_TX_KEY_TRANSMIT
178 /* Key Receive state machine */
179 enum { KEY_RX_NO_KEY_RECEIVE, KEY_RX_KEY_RECEIVE } key_rx_state;
183 /* Controlled Directions state machine */
184 enum { CTRL_DIR_FORCE_BOTH, CTRL_DIR_IN_OR_BOTH } ctrl_dir_state;
186 ControlledDirection adminControlledDirections;
187 ControlledDirection operControlledDirections;
190 /* Authenticator Statistics Table */
191 Counter dot1xAuthEapolFramesRx;
192 Counter dot1xAuthEapolFramesTx;
193 Counter dot1xAuthEapolStartFramesRx;
194 Counter dot1xAuthEapolLogoffFramesRx;
195 Counter dot1xAuthEapolRespIdFramesRx;
196 Counter dot1xAuthEapolRespFramesRx;
197 Counter dot1xAuthEapolReqIdFramesTx;
198 Counter dot1xAuthEapolReqFramesTx;
199 Counter dot1xAuthInvalidEapolFramesRx;
200 Counter dot1xAuthEapLengthErrorFramesRx;
201 Counter dot1xAuthLastEapolFrameVersion;
203 /* Other variables - not defined in IEEE 802.1X */
204 u8 addr[ETH_ALEN]; /* Supplicant address */
205 #define EAPOL_SM_PREAUTH BIT(0)
206 #define EAPOL_SM_WAIT_START BIT(1)
207 #define EAPOL_SM_USES_WPA BIT(2)
208 #define EAPOL_SM_FROM_PMKSA_CACHE BIT(3)
209 int flags; /* EAPOL_SM_* */
211 /* EAPOL/AAA <-> EAP full authenticator interface */
212 struct eap_eapol_interface *eap_if;
214 int radius_identifier;
215 /* TODO: check when the last messages can be released */
216 struct radius_msg *last_recv_radius;
217 u8 last_eap_id; /* last used EAP Identifier */
220 u8 eap_type_authsrv; /* EAP type of the last EAP packet from
221 * Authentication server */
222 u8 eap_type_supp; /* EAP type of the last EAP packet from Supplicant */
223 struct radius_class_data radius_class;
225 /* Keys for encrypting and signing EAPOL-Key frames */
227 size_t eapol_key_sign_len;
229 size_t eapol_key_crypt_len;
233 Boolean initializing; /* in process of initializing state machines */
236 struct eapol_authenticator *eapol;
238 void *sta; /* station context pointer to use in callbacks */
242 struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
243 struct eapol_auth_cb *cb);
244 void eapol_auth_deinit(struct eapol_authenticator *eapol);
245 struct eapol_state_machine *
246 eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
247 int flags, const struct wpabuf *assoc_wps_ie, void *sta_ctx);
248 void eapol_auth_free(struct eapol_state_machine *sm);
249 void eapol_auth_step(struct eapol_state_machine *sm);
250 void eapol_auth_dump_state(FILE *f, const char *prefix,
251 struct eapol_state_machine *sm);
252 int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx);
254 #endif /* EAPOL_AUTH_SM_H */