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