xref: /freebsd/contrib/wpa/src/eapol_auth/eapol_auth_sm_i.h (revision a90b9d0159070121c221b966469c3e36d912bf82)
1e28a4053SRui Paulo /*
2e28a4053SRui Paulo  * IEEE 802.1X-2004 Authenticator - EAPOL state machine (internal definitions)
3e28a4053SRui Paulo  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4e28a4053SRui Paulo  *
5f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo  * See README for more details.
7e28a4053SRui Paulo  */
8e28a4053SRui Paulo 
9e28a4053SRui Paulo #ifndef EAPOL_AUTH_SM_I_H
10e28a4053SRui Paulo #define EAPOL_AUTH_SM_I_H
11e28a4053SRui Paulo 
12e28a4053SRui Paulo #include "common/defs.h"
13e28a4053SRui Paulo #include "radius/radius.h"
14e28a4053SRui Paulo 
15e28a4053SRui Paulo /* IEEE Std 802.1X-2004, Ch. 8.2 */
16e28a4053SRui Paulo 
17e28a4053SRui Paulo typedef enum { ForceUnauthorized = 1, ForceAuthorized = 3, Auto = 2 }
18e28a4053SRui Paulo 	PortTypes;
19e28a4053SRui Paulo typedef enum { Unauthorized = 2, Authorized = 1 } PortState;
20e28a4053SRui Paulo typedef enum { Both = 0, In = 1 } ControlledDirection;
21e28a4053SRui Paulo typedef unsigned int Counter;
22e28a4053SRui Paulo 
23e28a4053SRui Paulo 
24e28a4053SRui Paulo /**
25e28a4053SRui Paulo  * struct eapol_authenticator - Global EAPOL authenticator data
26e28a4053SRui Paulo  */
27e28a4053SRui Paulo struct eapol_authenticator {
28e28a4053SRui Paulo 	struct eapol_auth_config conf;
29e28a4053SRui Paulo 	struct eapol_auth_cb cb;
30e28a4053SRui Paulo 
31e28a4053SRui Paulo 	u8 *default_wep_key;
32e28a4053SRui Paulo 	u8 default_wep_key_idx;
33e28a4053SRui Paulo };
34e28a4053SRui Paulo 
35e28a4053SRui Paulo 
36e28a4053SRui Paulo /**
37e28a4053SRui Paulo  * struct eapol_state_machine - Per-Supplicant Authenticator state machines
38e28a4053SRui Paulo  */
39e28a4053SRui Paulo struct eapol_state_machine {
40e28a4053SRui Paulo 	/* timers */
41e28a4053SRui Paulo 	int aWhile;
42e28a4053SRui Paulo 	int quietWhile;
43e28a4053SRui Paulo 	int reAuthWhen;
44e28a4053SRui Paulo 
45e28a4053SRui Paulo 	/* global variables */
46c1d255d3SCy Schubert 	bool authAbort;
47c1d255d3SCy Schubert 	bool authFail;
48e28a4053SRui Paulo 	PortState authPortStatus;
49c1d255d3SCy Schubert 	bool authStart;
50c1d255d3SCy Schubert 	bool authTimeout;
51c1d255d3SCy Schubert 	bool authSuccess;
52c1d255d3SCy Schubert 	bool eapolEap;
53c1d255d3SCy Schubert 	bool initialize;
54c1d255d3SCy Schubert 	bool keyDone;
55c1d255d3SCy Schubert 	bool keyRun;
56c1d255d3SCy Schubert 	bool keyTxEnabled;
57e28a4053SRui Paulo 	PortTypes portControl;
58c1d255d3SCy Schubert 	bool portValid;
59c1d255d3SCy Schubert 	bool reAuthenticate;
60e28a4053SRui Paulo 
61e28a4053SRui Paulo 	/* Port Timers state machine */
62c1d255d3SCy Schubert 	/* 'bool tick' implicitly handled as registered timeout */
63e28a4053SRui Paulo 
64e28a4053SRui Paulo 	/* Authenticator PAE state machine */
65e28a4053SRui Paulo 	enum { AUTH_PAE_INITIALIZE, AUTH_PAE_DISCONNECTED, AUTH_PAE_CONNECTING,
66e28a4053SRui Paulo 	       AUTH_PAE_AUTHENTICATING, AUTH_PAE_AUTHENTICATED,
67e28a4053SRui Paulo 	       AUTH_PAE_ABORTING, AUTH_PAE_HELD, AUTH_PAE_FORCE_AUTH,
68e28a4053SRui Paulo 	       AUTH_PAE_FORCE_UNAUTH, AUTH_PAE_RESTART } auth_pae_state;
69e28a4053SRui Paulo 	/* variables */
70c1d255d3SCy Schubert 	bool eapolLogoff;
71c1d255d3SCy Schubert 	bool eapolStart;
72e28a4053SRui Paulo 	PortTypes portMode;
73e28a4053SRui Paulo 	unsigned int reAuthCount;
74e28a4053SRui Paulo 	/* constants */
75e28a4053SRui Paulo 	unsigned int quietPeriod; /* default 60; 0..65535 */
76e28a4053SRui Paulo #define AUTH_PAE_DEFAULT_quietPeriod 60
77e28a4053SRui Paulo 	unsigned int reAuthMax; /* default 2 */
78e28a4053SRui Paulo #define AUTH_PAE_DEFAULT_reAuthMax 2
79e28a4053SRui Paulo 	/* counters */
80e28a4053SRui Paulo 	Counter authEntersConnecting;
81e28a4053SRui Paulo 	Counter authEapLogoffsWhileConnecting;
82e28a4053SRui Paulo 	Counter authEntersAuthenticating;
83e28a4053SRui Paulo 	Counter authAuthSuccessesWhileAuthenticating;
84e28a4053SRui Paulo 	Counter authAuthTimeoutsWhileAuthenticating;
85e28a4053SRui Paulo 	Counter authAuthFailWhileAuthenticating;
86e28a4053SRui Paulo 	Counter authAuthEapStartsWhileAuthenticating;
87e28a4053SRui Paulo 	Counter authAuthEapLogoffWhileAuthenticating;
88e28a4053SRui Paulo 	Counter authAuthReauthsWhileAuthenticated;
89e28a4053SRui Paulo 	Counter authAuthEapStartsWhileAuthenticated;
90e28a4053SRui Paulo 	Counter authAuthEapLogoffWhileAuthenticated;
91e28a4053SRui Paulo 
92e28a4053SRui Paulo 	/* Backend Authentication state machine */
93e28a4053SRui Paulo 	enum { BE_AUTH_REQUEST, BE_AUTH_RESPONSE, BE_AUTH_SUCCESS,
94e28a4053SRui Paulo 	       BE_AUTH_FAIL, BE_AUTH_TIMEOUT, BE_AUTH_IDLE, BE_AUTH_INITIALIZE,
95e28a4053SRui Paulo 	       BE_AUTH_IGNORE
96e28a4053SRui Paulo 	} be_auth_state;
97e28a4053SRui Paulo 	/* constants */
98e28a4053SRui Paulo 	unsigned int serverTimeout; /* default 30; 1..X */
99e28a4053SRui Paulo #define BE_AUTH_DEFAULT_serverTimeout 30
100e28a4053SRui Paulo 	/* counters */
101e28a4053SRui Paulo 	Counter backendResponses;
102e28a4053SRui Paulo 	Counter backendAccessChallenges;
103e28a4053SRui Paulo 	Counter backendOtherRequestsToSupplicant;
104e28a4053SRui Paulo 	Counter backendAuthSuccesses;
105e28a4053SRui Paulo 	Counter backendAuthFails;
106e28a4053SRui Paulo 
107e28a4053SRui Paulo 	/* Reauthentication Timer state machine */
108e28a4053SRui Paulo 	enum { REAUTH_TIMER_INITIALIZE, REAUTH_TIMER_REAUTHENTICATE
109e28a4053SRui Paulo 	} reauth_timer_state;
110e28a4053SRui Paulo 	/* constants */
111e28a4053SRui Paulo 	unsigned int reAuthPeriod; /* default 3600 s */
112c1d255d3SCy Schubert 	bool reAuthEnabled;
113e28a4053SRui Paulo 
114e28a4053SRui Paulo 	/* Authenticator Key Transmit state machine */
115e28a4053SRui Paulo 	enum { AUTH_KEY_TX_NO_KEY_TRANSMIT, AUTH_KEY_TX_KEY_TRANSMIT
116e28a4053SRui Paulo 	} auth_key_tx_state;
117e28a4053SRui Paulo 
118e28a4053SRui Paulo 	/* Key Receive state machine */
119e28a4053SRui Paulo 	enum { KEY_RX_NO_KEY_RECEIVE, KEY_RX_KEY_RECEIVE } key_rx_state;
120e28a4053SRui Paulo 	/* variables */
121c1d255d3SCy Schubert 	bool rxKey;
122e28a4053SRui Paulo 
123e28a4053SRui Paulo 	/* Controlled Directions state machine */
124e28a4053SRui Paulo 	enum { CTRL_DIR_FORCE_BOTH, CTRL_DIR_IN_OR_BOTH } ctrl_dir_state;
125e28a4053SRui Paulo 	/* variables */
126e28a4053SRui Paulo 	ControlledDirection adminControlledDirections;
127e28a4053SRui Paulo 	ControlledDirection operControlledDirections;
128c1d255d3SCy Schubert 	bool operEdge;
129e28a4053SRui Paulo 
130e28a4053SRui Paulo 	/* Authenticator Statistics Table */
131e28a4053SRui Paulo 	Counter dot1xAuthEapolFramesRx;
132e28a4053SRui Paulo 	Counter dot1xAuthEapolFramesTx;
133e28a4053SRui Paulo 	Counter dot1xAuthEapolStartFramesRx;
134e28a4053SRui Paulo 	Counter dot1xAuthEapolLogoffFramesRx;
135e28a4053SRui Paulo 	Counter dot1xAuthEapolRespIdFramesRx;
136e28a4053SRui Paulo 	Counter dot1xAuthEapolRespFramesRx;
137e28a4053SRui Paulo 	Counter dot1xAuthEapolReqIdFramesTx;
138e28a4053SRui Paulo 	Counter dot1xAuthEapolReqFramesTx;
139e28a4053SRui Paulo 	Counter dot1xAuthInvalidEapolFramesRx;
140e28a4053SRui Paulo 	Counter dot1xAuthEapLengthErrorFramesRx;
141e28a4053SRui Paulo 	Counter dot1xAuthLastEapolFrameVersion;
142e28a4053SRui Paulo 
143e28a4053SRui Paulo 	/* Other variables - not defined in IEEE 802.1X */
144e28a4053SRui Paulo 	u8 addr[ETH_ALEN]; /* Supplicant address */
145e28a4053SRui Paulo 	int flags; /* EAPOL_SM_* */
146e28a4053SRui Paulo 
147e28a4053SRui Paulo 	/* EAPOL/AAA <-> EAP full authenticator interface */
148e28a4053SRui Paulo 	struct eap_eapol_interface *eap_if;
149e28a4053SRui Paulo 
150e28a4053SRui Paulo 	int radius_identifier;
151e28a4053SRui Paulo 	/* TODO: check when the last messages can be released */
152e28a4053SRui Paulo 	struct radius_msg *last_recv_radius;
153e28a4053SRui Paulo 	u8 last_eap_id; /* last used EAP Identifier */
154e28a4053SRui Paulo 	u8 *identity;
155e28a4053SRui Paulo 	size_t identity_len;
156e28a4053SRui Paulo 	u8 eap_type_authsrv; /* EAP type of the last EAP packet from
157e28a4053SRui Paulo 			      * Authentication server */
158e28a4053SRui Paulo 	u8 eap_type_supp; /* EAP type of the last EAP packet from Supplicant */
159e28a4053SRui Paulo 	struct radius_class_data radius_class;
160f05cddf9SRui Paulo 	struct wpabuf *radius_cui; /* Chargeable-User-Identity */
161e28a4053SRui Paulo 
162e28a4053SRui Paulo 	struct eap_sm *eap;
163e28a4053SRui Paulo 
164c1d255d3SCy Schubert 	bool initializing; /* in process of initializing state machines */
165c1d255d3SCy Schubert 	bool changed;
166e28a4053SRui Paulo 
167e28a4053SRui Paulo 	struct eapol_authenticator *eapol;
168e28a4053SRui Paulo 
169e28a4053SRui Paulo 	void *sta; /* station context pointer to use in callbacks */
1705b9c547cSRui Paulo 
1715b9c547cSRui Paulo 	int remediation;
1725b9c547cSRui Paulo 
173780fb4a2SCy Schubert 	u64 acct_multi_session_id;
174*a90b9d01SCy Schubert 
175*a90b9d01SCy Schubert 	unsigned int authenticated; /* The number of times authentication has
176*a90b9d01SCy Schubert 				     * been completed successfully. */
177*a90b9d01SCy Schubert 	bool stopped;
178e28a4053SRui Paulo };
179e28a4053SRui Paulo 
180e28a4053SRui Paulo #endif /* EAPOL_AUTH_SM_I_H */
181