2 * hostapd / IEEE 802.1X Authenticator - EAPOL state machine
3 * Copyright (c) 2002-2005, 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
;
40 struct eapol_state_machine
{
46 /* global variables */
49 PortState authPortStatus
;
62 PortTypes portControl
;
65 Boolean reAuthenticate
;
67 /* Port Timers state machine */
68 /* 'Boolean tick' implicitly handled as registered timeout */
70 /* Authenticator PAE state machine */
71 enum { AUTH_PAE_INITIALIZE
, AUTH_PAE_DISCONNECTED
, AUTH_PAE_CONNECTING
,
72 AUTH_PAE_AUTHENTICATING
, AUTH_PAE_AUTHENTICATED
,
73 AUTH_PAE_ABORTING
, AUTH_PAE_HELD
, AUTH_PAE_FORCE_AUTH
,
74 AUTH_PAE_FORCE_UNAUTH
, AUTH_PAE_RESTART
} auth_pae_state
;
80 unsigned int reAuthCount
;
82 unsigned int quietPeriod
; /* default 60; 0..65535 */
83 #define AUTH_PAE_DEFAULT_quietPeriod 60
84 unsigned int reAuthMax
; /* default 2 */
85 #define AUTH_PAE_DEFAULT_reAuthMax 2
87 Counter authEntersConnecting
;
88 Counter authEapLogoffsWhileConnecting
;
89 Counter authEntersAuthenticating
;
90 Counter authAuthSuccessesWhileAuthenticating
;
91 Counter authAuthTimeoutsWhileAuthenticating
;
92 Counter authAuthFailWhileAuthenticating
;
93 Counter authAuthEapStartsWhileAuthenticating
;
94 Counter authAuthEapLogoffWhileAuthenticating
;
95 Counter authAuthReauthsWhileAuthenticated
;
96 Counter authAuthEapStartsWhileAuthenticated
;
97 Counter authAuthEapLogoffWhileAuthenticated
;
99 /* Backend Authentication state machine */
100 enum { BE_AUTH_REQUEST
, BE_AUTH_RESPONSE
, BE_AUTH_SUCCESS
,
101 BE_AUTH_FAIL
, BE_AUTH_TIMEOUT
, BE_AUTH_IDLE
, BE_AUTH_INITIALIZE
,
109 unsigned int serverTimeout
; /* default 30; 1..X */
110 #define BE_AUTH_DEFAULT_serverTimeout 30
112 Counter backendResponses
;
113 Counter backendAccessChallenges
;
114 Counter backendOtherRequestsToSupplicant
;
115 Counter backendAuthSuccesses
;
116 Counter backendAuthFails
;
118 /* Reauthentication Timer state machine */
119 enum { REAUTH_TIMER_INITIALIZE
, REAUTH_TIMER_REAUTHENTICATE
120 } reauth_timer_state
;
122 unsigned int reAuthPeriod
; /* default 3600 s */
123 Boolean reAuthEnabled
;
125 /* Authenticator Key Transmit state machine */
126 enum { AUTH_KEY_TX_NO_KEY_TRANSMIT
, AUTH_KEY_TX_KEY_TRANSMIT
129 /* Key Receive state machine */
130 enum { KEY_RX_NO_KEY_RECEIVE
, KEY_RX_KEY_RECEIVE
} key_rx_state
;
134 /* Controlled Directions state machine */
135 enum { CTRL_DIR_FORCE_BOTH
, CTRL_DIR_IN_OR_BOTH
} ctrl_dir_state
;
137 ControlledDirection adminControlledDirections
;
138 ControlledDirection operControlledDirections
;
141 /* Authenticator Statistics Table */
142 Counter dot1xAuthEapolFramesRx
;
143 Counter dot1xAuthEapolFramesTx
;
144 Counter dot1xAuthEapolStartFramesRx
;
145 Counter dot1xAuthEapolLogoffFramesRx
;
146 Counter dot1xAuthEapolRespIdFramesRx
;
147 Counter dot1xAuthEapolRespFramesRx
;
148 Counter dot1xAuthEapolReqIdFramesTx
;
149 Counter dot1xAuthEapolReqFramesTx
;
150 Counter dot1xAuthInvalidEapolFramesRx
;
151 Counter dot1xAuthEapLengthErrorFramesRx
;
152 Counter dot1xAuthLastEapolFrameVersion
;
154 /* Other variables - not defined in IEEE 802.1X */
155 u8 addr
[ETH_ALEN
]; /* Supplicant address */
156 #define EAPOL_SM_PREAUTH BIT(0)
157 int flags
; /* EAPOL_SM_* */
159 int radius_identifier
;
160 /* TODO: check when the last messages can be released */
161 struct radius_msg
*last_recv_radius
;
162 u8
*last_eap_supp
; /* last received EAP Response from Supplicant */
163 size_t last_eap_supp_len
;
164 u8
*last_eap_radius
; /* last received EAP Response from Authentication
166 size_t last_eap_radius_len
;
169 u8 eap_type_authsrv
; /* EAP type of the last EAP packet from
170 * Authentication server */
171 u8 eap_type_supp
; /* EAP type of the last EAP packet from Supplicant */
172 struct radius_class_data radius_class
;
174 /* Keys for encrypting and signing EAPOL-Key frames */
176 size_t eapol_key_sign_len
;
178 size_t eapol_key_crypt_len
;
180 Boolean rx_identity
; /* set to TRUE on reception of
181 * EAP-Response/Identity */
185 /* currentId was removed in IEEE 802.1X-REV, but it is needed to filter
186 * out EAP-Responses to old packets (e.g., to two EAP-Request/Identity
187 * packets that are often sent in the beginning of the authentication).
191 Boolean initializing
; /* in process of initializing state machines */
194 /* Somewhat nasty pointers to global hostapd and STA data to avoid
195 * passing these to every function */
196 struct hostapd_data
*hapd
;
197 struct sta_info
*sta
;
201 struct eapol_state_machine
*eapol_sm_alloc(struct hostapd_data
*hapd
,
202 struct sta_info
*sta
);
203 void eapol_sm_free(struct eapol_state_machine
*sm
);
204 void eapol_sm_step(struct eapol_state_machine
*sm
);
205 void eapol_sm_initialize(struct eapol_state_machine
*sm
);
206 void eapol_sm_dump_state(FILE *f
, const char *prefix
,
207 struct eapol_state_machine
*sm
);
208 int eapol_sm_eap_pending_cb(struct eapol_state_machine
*sm
, void *ctx
);
210 #endif /* EAPOL_SM_H */