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