2 * hostapd / IEEE 802.1X-2004 Authenticator - EAPOL state machine
3 * Copyright (c) 2002-2007, 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.
20 /* IEEE Std 802.1X-2004, Ch. 8.2 */
22 typedef enum { ForceUnauthorized = 1, ForceAuthorized = 3, Auto = 2 }
24 typedef enum { Unauthorized = 2, Authorized = 1 } PortState;
25 typedef enum { Both = 0, In = 1 } ControlledDirection;
26 typedef unsigned int Counter;
30 struct radius_attr_data {
35 struct radius_class_data {
36 struct radius_attr_data *attr;
41 struct eapol_auth_config {
42 int eap_reauth_period;
44 int individual_wep_key_len;
47 void *eap_sim_db_priv;
48 char *eap_req_id_text; /* a copy of this will be allocated */
49 size_t eap_req_id_text_len;
50 u8 *pac_opaque_encr_key;
52 int eap_sim_aka_result_ind;
55 * Pointer to hostapd data. This is a temporary workaround for
56 * transition phase and will be removed once IEEE 802.1X/EAPOL code is
57 * separated more cleanly from rest of hostapd.
59 struct hostapd_data *hapd;
65 EAPOL_LOGGER_DEBUG, EAPOL_LOGGER_INFO, EAPOL_LOGGER_WARNING
68 struct eapol_auth_cb {
69 void (*eapol_send)(void *ctx, void *sta_ctx, u8 type, const u8 *data,
71 void (*aaa_send)(void *ctx, void *sta_ctx, const u8 *data,
73 void (*finished)(void *ctx, void *sta_ctx, int success, int preauth);
74 int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len,
75 int phase2, struct eap_user *user);
76 int (*sta_entry_alive)(void *ctx, const u8 *addr);
77 void (*logger)(void *ctx, const u8 *addr, eapol_logger_level level,
79 void (*set_port_authorized)(void *ctx, void *sta_ctx, int authorized);
80 void (*abort_auth)(void *ctx, void *sta_ctx);
81 void (*tx_key)(void *ctx, void *sta_ctx);
85 * struct eapol_authenticator - Global EAPOL authenticator data
87 struct eapol_authenticator {
88 struct eapol_auth_config conf;
89 struct eapol_auth_cb cb;
94 * struct eapol_state_machine - Per-Supplicant Authenticator state machines
96 struct eapol_state_machine {
102 /* global variables */
105 PortState authPortStatus;
113 Boolean keyTxEnabled;
114 PortTypes portControl;
116 Boolean reAuthenticate;
118 /* Port Timers state machine */
119 /* 'Boolean tick' implicitly handled as registered timeout */
121 /* Authenticator PAE state machine */
122 enum { AUTH_PAE_INITIALIZE, AUTH_PAE_DISCONNECTED, AUTH_PAE_CONNECTING,
123 AUTH_PAE_AUTHENTICATING, AUTH_PAE_AUTHENTICATED,
124 AUTH_PAE_ABORTING, AUTH_PAE_HELD, AUTH_PAE_FORCE_AUTH,
125 AUTH_PAE_FORCE_UNAUTH, AUTH_PAE_RESTART } auth_pae_state;
130 unsigned int reAuthCount;
132 unsigned int quietPeriod; /* default 60; 0..65535 */
133 #define AUTH_PAE_DEFAULT_quietPeriod 60
134 unsigned int reAuthMax; /* default 2 */
135 #define AUTH_PAE_DEFAULT_reAuthMax 2
137 Counter authEntersConnecting;
138 Counter authEapLogoffsWhileConnecting;
139 Counter authEntersAuthenticating;
140 Counter authAuthSuccessesWhileAuthenticating;
141 Counter authAuthTimeoutsWhileAuthenticating;
142 Counter authAuthFailWhileAuthenticating;
143 Counter authAuthEapStartsWhileAuthenticating;
144 Counter authAuthEapLogoffWhileAuthenticating;
145 Counter authAuthReauthsWhileAuthenticated;
146 Counter authAuthEapStartsWhileAuthenticated;
147 Counter authAuthEapLogoffWhileAuthenticated;
149 /* Backend Authentication state machine */
150 enum { BE_AUTH_REQUEST, BE_AUTH_RESPONSE, BE_AUTH_SUCCESS,
151 BE_AUTH_FAIL, BE_AUTH_TIMEOUT, BE_AUTH_IDLE, BE_AUTH_INITIALIZE,
155 unsigned int serverTimeout; /* default 30; 1..X */
156 #define BE_AUTH_DEFAULT_serverTimeout 30
158 Counter backendResponses;
159 Counter backendAccessChallenges;
160 Counter backendOtherRequestsToSupplicant;
161 Counter backendAuthSuccesses;
162 Counter backendAuthFails;
164 /* Reauthentication Timer state machine */
165 enum { REAUTH_TIMER_INITIALIZE, REAUTH_TIMER_REAUTHENTICATE
166 } reauth_timer_state;
168 unsigned int reAuthPeriod; /* default 3600 s */
169 Boolean reAuthEnabled;
171 /* Authenticator Key Transmit state machine */
172 enum { AUTH_KEY_TX_NO_KEY_TRANSMIT, AUTH_KEY_TX_KEY_TRANSMIT
175 /* Key Receive state machine */
176 enum { KEY_RX_NO_KEY_RECEIVE, KEY_RX_KEY_RECEIVE } key_rx_state;
180 /* Controlled Directions state machine */
181 enum { CTRL_DIR_FORCE_BOTH, CTRL_DIR_IN_OR_BOTH } ctrl_dir_state;
183 ControlledDirection adminControlledDirections;
184 ControlledDirection operControlledDirections;
187 /* Authenticator Statistics Table */
188 Counter dot1xAuthEapolFramesRx;
189 Counter dot1xAuthEapolFramesTx;
190 Counter dot1xAuthEapolStartFramesRx;
191 Counter dot1xAuthEapolLogoffFramesRx;
192 Counter dot1xAuthEapolRespIdFramesRx;
193 Counter dot1xAuthEapolRespFramesRx;
194 Counter dot1xAuthEapolReqIdFramesTx;
195 Counter dot1xAuthEapolReqFramesTx;
196 Counter dot1xAuthInvalidEapolFramesRx;
197 Counter dot1xAuthEapLengthErrorFramesRx;
198 Counter dot1xAuthLastEapolFrameVersion;
200 /* Other variables - not defined in IEEE 802.1X */
201 u8 addr[ETH_ALEN]; /* Supplicant address */
202 #define EAPOL_SM_PREAUTH BIT(0)
203 #define EAPOL_SM_WAIT_START BIT(1)
204 int flags; /* EAPOL_SM_* */
206 /* EAPOL/AAA <-> EAP full authenticator interface */
207 struct eap_eapol_interface *eap_if;
209 int radius_identifier;
210 /* TODO: check when the last messages can be released */
211 struct radius_msg *last_recv_radius;
212 u8 last_eap_id; /* last used EAP Identifier */
215 u8 eap_type_authsrv; /* EAP type of the last EAP packet from
216 * Authentication server */
217 u8 eap_type_supp; /* EAP type of the last EAP packet from Supplicant */
218 struct radius_class_data radius_class;
220 /* Keys for encrypting and signing EAPOL-Key frames */
222 size_t eapol_key_sign_len;
224 size_t eapol_key_crypt_len;
228 Boolean initializing; /* in process of initializing state machines */
231 struct eapol_authenticator *eapol;
233 /* Somewhat nasty pointers to global hostapd and STA data to avoid
234 * passing these to every function */
235 struct hostapd_data *hapd;
236 struct sta_info *sta;
240 struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
241 struct eapol_auth_cb *cb);
242 void eapol_auth_deinit(struct eapol_authenticator *eapol);
243 struct eapol_state_machine *
244 eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
245 int preauth, struct sta_info *sta);
246 void eapol_auth_free(struct eapol_state_machine *sm);
247 void eapol_auth_step(struct eapol_state_machine *sm);
248 void eapol_auth_initialize(struct eapol_state_machine *sm);
249 void eapol_auth_dump_state(FILE *f, const char *prefix,
250 struct eapol_state_machine *sm);
251 int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx);
253 #endif /* EAPOL_SM_H */