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