Merge from vendor branch BIND:
[dragonfly.git] / contrib / hostapd-0.4.9 / eapol_sm.h
1 #ifndef EAPOL_SM_H
2 #define EAPOL_SM_H
3
4 #include "defs.h"
5
6 /* IEEE Std 802.1X-REV-d11, Ch. 8.2 */
7
8 typedef enum { ForceUnauthorized = 1, ForceAuthorized = 3, Auto = 2 }
9         PortTypes;
10 typedef enum { Unauthorized = 2, Authorized = 1 } PortState;
11 typedef enum { Both = 0, In = 1 } ControlledDirection;
12 typedef unsigned int Counter;
13
14
15 /* Authenticator PAE state machine */
16 struct eapol_auth_pae_sm {
17         /* variables */
18         Boolean eapolLogoff;
19         Boolean eapolStart;
20         Boolean eapRestart;
21         PortTypes portMode;
22         unsigned int reAuthCount;
23
24         /* constants */
25         unsigned int quietPeriod; /* default 60; 0..65535 */
26 #define AUTH_PAE_DEFAULT_quietPeriod 60
27         unsigned int reAuthMax; /* default 2 */
28 #define AUTH_PAE_DEFAULT_reAuthMax 2
29
30         /* counters */
31         Counter authEntersConnecting;
32         Counter authEapLogoffsWhileConnecting;
33         Counter authEntersAuthenticating;
34         Counter authAuthSuccessesWhileAuthenticating;
35         Counter authAuthTimeoutsWhileAuthenticating;
36         Counter authAuthFailWhileAuthenticating;
37         Counter authAuthEapStartsWhileAuthenticating;
38         Counter authAuthEapLogoffWhileAuthenticating;
39         Counter authAuthReauthsWhileAuthenticated;
40         Counter authAuthEapStartsWhileAuthenticated;
41         Counter authAuthEapLogoffWhileAuthenticated;
42
43         enum { AUTH_PAE_INITIALIZE, AUTH_PAE_DISCONNECTED, AUTH_PAE_CONNECTING,
44                AUTH_PAE_AUTHENTICATING, AUTH_PAE_AUTHENTICATED,
45                AUTH_PAE_ABORTING, AUTH_PAE_HELD, AUTH_PAE_FORCE_AUTH,
46                AUTH_PAE_FORCE_UNAUTH, AUTH_PAE_RESTART } state;
47 };
48
49
50 /* Backend Authentication state machine */
51 struct eapol_backend_auth_sm {
52         /* variables */
53         Boolean eapNoReq;
54         Boolean eapReq;
55         Boolean eapResp;
56
57         /* constants */
58         unsigned int serverTimeout; /* default 30; 1..X */
59 #define BE_AUTH_DEFAULT_serverTimeout 30
60
61         /* counters */
62         Counter backendResponses;
63         Counter backendAccessChallenges;
64         Counter backendOtherRequestsToSupplicant;
65         Counter backendAuthSuccesses;
66         Counter backendAuthFails;
67
68         enum { BE_AUTH_REQUEST, BE_AUTH_RESPONSE, BE_AUTH_SUCCESS,
69                BE_AUTH_FAIL, BE_AUTH_TIMEOUT, BE_AUTH_IDLE, BE_AUTH_INITIALIZE,
70                BE_AUTH_IGNORE
71         } state;
72 };
73
74
75 /* Reauthentication Timer state machine */
76 struct eapol_reauth_timer_sm {
77         /* constants */
78         unsigned int reAuthPeriod; /* default 3600 s */
79         Boolean reAuthEnabled;
80
81         enum { REAUTH_TIMER_INITIALIZE, REAUTH_TIMER_REAUTHENTICATE } state;
82 };
83
84
85 /* Authenticator Key Transmit state machine */
86 struct eapol_auth_key_tx {
87         enum { AUTH_KEY_TX_NO_KEY_TRANSMIT, AUTH_KEY_TX_KEY_TRANSMIT } state;
88 };
89
90
91 /* Key Receive state machine */
92 struct eapol_key_rx {
93         /* variables */
94         Boolean rxKey;
95
96         enum { KEY_RX_NO_KEY_RECEIVE, KEY_RX_KEY_RECEIVE } state;
97 };
98
99
100 /* Controlled Directions state machine */
101 struct eapol_ctrl_dir {
102         /* variables */
103         ControlledDirection adminControlledDirections;
104         ControlledDirection operControlledDirections;
105         Boolean operEdge;
106
107         enum { CTRL_DIR_FORCE_BOTH, CTRL_DIR_IN_OR_BOTH } state;
108 };
109
110
111 struct eap_sm;
112
113 struct radius_attr_data {
114         u8 *data;
115         size_t len;
116 };
117
118 struct radius_class_data {
119         struct radius_attr_data *attr;
120         size_t count;
121 };
122
123 struct eapol_state_machine {
124         /* timers */
125         int aWhile;
126         int quietWhile;
127         int reAuthWhen;
128
129         /* global variables */
130         Boolean authAbort;
131         Boolean authFail;
132         PortState authPortStatus;
133         Boolean authStart;
134         Boolean authTimeout;
135         Boolean authSuccess;
136         Boolean eapFail;
137         Boolean eapolEap;
138         Boolean eapSuccess;
139         Boolean eapTimeout;
140         Boolean initialize;
141         Boolean keyAvailable;
142         Boolean keyDone;
143         Boolean keyRun;
144         Boolean keyTxEnabled;
145         PortTypes portControl;
146         Boolean portEnabled;
147         Boolean portValid;
148         Boolean reAuthenticate;
149
150         /* Port Timers state machine */
151         /* 'Boolean tick' implicitly handled as registered timeout */
152
153         struct eapol_auth_pae_sm auth_pae;
154         struct eapol_backend_auth_sm be_auth;
155         struct eapol_reauth_timer_sm reauth_timer;
156         struct eapol_auth_key_tx auth_key_tx;
157         struct eapol_key_rx key_rx;
158         struct eapol_ctrl_dir ctrl_dir;
159
160         /* Authenticator Statistics Table */
161         Counter dot1xAuthEapolFramesRx;
162         Counter dot1xAuthEapolFramesTx;
163         Counter dot1xAuthEapolStartFramesRx;
164         Counter dot1xAuthEapolLogoffFramesRx;
165         Counter dot1xAuthEapolRespIdFramesRx;
166         Counter dot1xAuthEapolRespFramesRx;
167         Counter dot1xAuthEapolReqIdFramesTx;
168         Counter dot1xAuthEapolReqFramesTx;
169         Counter dot1xAuthInvalidEapolFramesRx;
170         Counter dot1xAuthEapLengthErrorFramesRx;
171         Counter dot1xAuthLastEapolFrameVersion;
172
173         /* Other variables - not defined in IEEE 802.1X */
174         u8 addr[ETH_ALEN]; /* Supplicant address */
175 #define EAPOL_SM_PREAUTH BIT(0)
176         int flags; /* EAPOL_SM_* */
177
178         int radius_identifier;
179         /* TODO: check when the last messages can be released */
180         struct radius_msg *last_recv_radius;
181         u8 *last_eap_supp; /* last received EAP Response from Supplicant */
182         size_t last_eap_supp_len;
183         u8 *last_eap_radius; /* last received EAP Response from Authentication
184                               * Server */
185         size_t last_eap_radius_len;
186         u8 *identity;
187         size_t identity_len;
188         struct radius_class_data radius_class;
189
190         /* Keys for encrypting and signing EAPOL-Key frames */
191         u8 *eapol_key_sign;
192         size_t eapol_key_sign_len;
193         u8 *eapol_key_crypt;
194         size_t eapol_key_crypt_len;
195
196         Boolean rx_identity; /* set to TRUE on reception of
197                               * EAP-Response/Identity */
198
199         struct eap_sm *eap;
200
201         /* currentId was removed in IEEE 802.1X-REV, but it is needed to filter
202          * out EAP-Responses to old packets (e.g., to two EAP-Request/Identity
203          * packets that are often sent in the beginning of the authentication).
204          */
205         u8 currentId;
206
207         Boolean initializing; /* in process of initializing state machines */
208
209         /* Somewhat nasty pointers to global hostapd and STA data to avoid
210          * passing these to every function */
211         struct hostapd_data *hapd;
212         struct sta_info *sta;
213 };
214
215
216 struct eapol_state_machine *eapol_sm_alloc(hostapd *hapd,
217                                            struct sta_info *sta);
218 void eapol_sm_free(struct eapol_state_machine *sm);
219 void eapol_sm_step(struct eapol_state_machine *sm);
220 void eapol_sm_initialize(struct eapol_state_machine *sm);
221 void eapol_sm_dump_state(FILE *f, const char *prefix,
222                          struct eapol_state_machine *sm);
223
224 #endif /* EAPOL_SM_H */