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