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