Updated indentation in the patch to match style used elsewhere in OpenSSL
[libeap.git] / hostapd / eapol_sm.h
1 /*
2  * hostapd / IEEE 802.1X-2004 Authenticator - EAPOL state machine
3  * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
4  *
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.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #ifndef EAPOL_SM_H
16 #define EAPOL_SM_H
17
18 #include "defs.h"
19
20 /* IEEE Std 802.1X-2004, Ch. 8.2 */
21
22 typedef enum { ForceUnauthorized = 1, ForceAuthorized = 3, Auto = 2 }
23         PortTypes;
24 typedef enum { Unauthorized = 2, Authorized = 1 } PortState;
25 typedef enum { Both = 0, In = 1 } ControlledDirection;
26 typedef unsigned int Counter;
27
28 struct eap_sm;
29
30 struct radius_attr_data {
31         u8 *data;
32         size_t len;
33 };
34
35 struct radius_class_data {
36         struct radius_attr_data *attr;
37         size_t count;
38 };
39
40
41 struct eapol_auth_config {
42         int eap_reauth_period;
43         int wpa;
44         int individual_wep_key_len;
45         int eap_server;
46         void *ssl_ctx;
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;
51         u8 *eap_fast_a_id;
52         size_t eap_fast_a_id_len;
53         char *eap_fast_a_id_info;
54         int eap_fast_prov;
55         int pac_key_lifetime;
56         int pac_key_refresh_time;
57         int eap_sim_aka_result_ind;
58         int tnc;
59
60         /*
61          * Pointer to hostapd data. This is a temporary workaround for
62          * transition phase and will be removed once IEEE 802.1X/EAPOL code is
63          * separated more cleanly from rest of hostapd.
64          */
65         struct hostapd_data *hapd;
66 };
67
68 struct eap_user;
69
70 typedef enum {
71         EAPOL_LOGGER_DEBUG, EAPOL_LOGGER_INFO, EAPOL_LOGGER_WARNING
72 } eapol_logger_level;
73
74 struct eapol_auth_cb {
75         void (*eapol_send)(void *ctx, void *sta_ctx, u8 type, const u8 *data,
76                            size_t datalen);
77         void (*aaa_send)(void *ctx, void *sta_ctx, const u8 *data,
78                          size_t datalen);
79         void (*finished)(void *ctx, void *sta_ctx, int success, int preauth);
80         int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len,
81                             int phase2, struct eap_user *user);
82         int (*sta_entry_alive)(void *ctx, const u8 *addr);
83         void (*logger)(void *ctx, const u8 *addr, eapol_logger_level level,
84                        const char *txt);
85         void (*set_port_authorized)(void *ctx, void *sta_ctx, int authorized);
86         void (*abort_auth)(void *ctx, void *sta_ctx);
87         void (*tx_key)(void *ctx, void *sta_ctx);
88 };
89
90 /**
91  * struct eapol_authenticator - Global EAPOL authenticator data
92  */
93 struct eapol_authenticator {
94         struct eapol_auth_config conf;
95         struct eapol_auth_cb cb;
96 };
97
98
99 /**
100  * struct eapol_state_machine - Per-Supplicant Authenticator state machines
101  */
102 struct eapol_state_machine {
103         /* timers */
104         int aWhile;
105         int quietWhile;
106         int reAuthWhen;
107
108         /* global variables */
109         Boolean authAbort;
110         Boolean authFail;
111         PortState authPortStatus;
112         Boolean authStart;
113         Boolean authTimeout;
114         Boolean authSuccess;
115         Boolean eapolEap;
116         Boolean initialize;
117         Boolean keyDone;
118         Boolean keyRun;
119         Boolean keyTxEnabled;
120         PortTypes portControl;
121         Boolean portValid;
122         Boolean reAuthenticate;
123
124         /* Port Timers state machine */
125         /* 'Boolean tick' implicitly handled as registered timeout */
126
127         /* Authenticator PAE state machine */
128         enum { AUTH_PAE_INITIALIZE, AUTH_PAE_DISCONNECTED, AUTH_PAE_CONNECTING,
129                AUTH_PAE_AUTHENTICATING, AUTH_PAE_AUTHENTICATED,
130                AUTH_PAE_ABORTING, AUTH_PAE_HELD, AUTH_PAE_FORCE_AUTH,
131                AUTH_PAE_FORCE_UNAUTH, AUTH_PAE_RESTART } auth_pae_state;
132         /* variables */
133         Boolean eapolLogoff;
134         Boolean eapolStart;
135         PortTypes portMode;
136         unsigned int reAuthCount;
137         /* constants */
138         unsigned int quietPeriod; /* default 60; 0..65535 */
139 #define AUTH_PAE_DEFAULT_quietPeriod 60
140         unsigned int reAuthMax; /* default 2 */
141 #define AUTH_PAE_DEFAULT_reAuthMax 2
142         /* counters */
143         Counter authEntersConnecting;
144         Counter authEapLogoffsWhileConnecting;
145         Counter authEntersAuthenticating;
146         Counter authAuthSuccessesWhileAuthenticating;
147         Counter authAuthTimeoutsWhileAuthenticating;
148         Counter authAuthFailWhileAuthenticating;
149         Counter authAuthEapStartsWhileAuthenticating;
150         Counter authAuthEapLogoffWhileAuthenticating;
151         Counter authAuthReauthsWhileAuthenticated;
152         Counter authAuthEapStartsWhileAuthenticated;
153         Counter authAuthEapLogoffWhileAuthenticated;
154
155         /* Backend Authentication state machine */
156         enum { BE_AUTH_REQUEST, BE_AUTH_RESPONSE, BE_AUTH_SUCCESS,
157                BE_AUTH_FAIL, BE_AUTH_TIMEOUT, BE_AUTH_IDLE, BE_AUTH_INITIALIZE,
158                BE_AUTH_IGNORE
159         } be_auth_state;
160         /* constants */
161         unsigned int serverTimeout; /* default 30; 1..X */
162 #define BE_AUTH_DEFAULT_serverTimeout 30
163         /* counters */
164         Counter backendResponses;
165         Counter backendAccessChallenges;
166         Counter backendOtherRequestsToSupplicant;
167         Counter backendAuthSuccesses;
168         Counter backendAuthFails;
169
170         /* Reauthentication Timer state machine */
171         enum { REAUTH_TIMER_INITIALIZE, REAUTH_TIMER_REAUTHENTICATE
172         } reauth_timer_state;
173         /* constants */
174         unsigned int reAuthPeriod; /* default 3600 s */
175         Boolean reAuthEnabled;
176
177         /* Authenticator Key Transmit state machine */
178         enum { AUTH_KEY_TX_NO_KEY_TRANSMIT, AUTH_KEY_TX_KEY_TRANSMIT
179         } auth_key_tx_state;
180
181         /* Key Receive state machine */
182         enum { KEY_RX_NO_KEY_RECEIVE, KEY_RX_KEY_RECEIVE } key_rx_state;
183         /* variables */
184         Boolean rxKey;
185
186         /* Controlled Directions state machine */
187         enum { CTRL_DIR_FORCE_BOTH, CTRL_DIR_IN_OR_BOTH } ctrl_dir_state;
188         /* variables */
189         ControlledDirection adminControlledDirections;
190         ControlledDirection operControlledDirections;
191         Boolean operEdge;
192
193         /* Authenticator Statistics Table */
194         Counter dot1xAuthEapolFramesRx;
195         Counter dot1xAuthEapolFramesTx;
196         Counter dot1xAuthEapolStartFramesRx;
197         Counter dot1xAuthEapolLogoffFramesRx;
198         Counter dot1xAuthEapolRespIdFramesRx;
199         Counter dot1xAuthEapolRespFramesRx;
200         Counter dot1xAuthEapolReqIdFramesTx;
201         Counter dot1xAuthEapolReqFramesTx;
202         Counter dot1xAuthInvalidEapolFramesRx;
203         Counter dot1xAuthEapLengthErrorFramesRx;
204         Counter dot1xAuthLastEapolFrameVersion;
205
206         /* Other variables - not defined in IEEE 802.1X */
207         u8 addr[ETH_ALEN]; /* Supplicant address */
208 #define EAPOL_SM_PREAUTH BIT(0)
209 #define EAPOL_SM_WAIT_START BIT(1)
210         int flags; /* EAPOL_SM_* */
211
212         /* EAPOL/AAA <-> EAP full authenticator interface */
213         struct eap_eapol_interface *eap_if;
214
215         int radius_identifier;
216         /* TODO: check when the last messages can be released */
217         struct radius_msg *last_recv_radius;
218         u8 last_eap_id; /* last used EAP Identifier */
219         u8 *identity;
220         size_t identity_len;
221         u8 eap_type_authsrv; /* EAP type of the last EAP packet from
222                               * Authentication server */
223         u8 eap_type_supp; /* EAP type of the last EAP packet from Supplicant */
224         struct radius_class_data radius_class;
225
226         /* Keys for encrypting and signing EAPOL-Key frames */
227         u8 *eapol_key_sign;
228         size_t eapol_key_sign_len;
229         u8 *eapol_key_crypt;
230         size_t eapol_key_crypt_len;
231
232         struct eap_sm *eap;
233
234         Boolean initializing; /* in process of initializing state machines */
235         Boolean changed;
236
237         struct eapol_authenticator *eapol;
238
239         /* Somewhat nasty pointers to global hostapd and STA data to avoid
240          * passing these to every function */
241         struct hostapd_data *hapd;
242         struct sta_info *sta;
243 };
244
245
246 struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
247                                              struct eapol_auth_cb *cb);
248 void eapol_auth_deinit(struct eapol_authenticator *eapol);
249 struct eapol_state_machine *
250 eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
251                  int preauth, struct sta_info *sta);
252 void eapol_auth_free(struct eapol_state_machine *sm);
253 void eapol_auth_step(struct eapol_state_machine *sm);
254 void eapol_auth_initialize(struct eapol_state_machine *sm);
255 void eapol_auth_dump_state(FILE *f, const char *prefix,
256                            struct eapol_state_machine *sm);
257 int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx);
258
259 #endif /* EAPOL_SM_H */