Added preliminary Wi-Fi Protected Setup (WPS) implementation
[mech_eap.orig] / src / eapol_supp / eapol_supp_sm.h
1 /*
2  * EAPOL supplicant state machines
3  * Copyright (c) 2004-2008, 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_SUPP_SM_H
16 #define EAPOL_SUPP_SM_H
17
18 #include "defs.h"
19
20 typedef enum { Unauthorized, Authorized } PortStatus;
21 typedef enum { Auto, ForceUnauthorized, ForceAuthorized } PortControl;
22
23 /**
24  * struct eapol_config - Per network configuration for EAPOL state machines
25  */
26 struct eapol_config {
27         /**
28          * accept_802_1x_keys - Accept IEEE 802.1X (non-WPA) EAPOL-Key frames
29          *
30          * This variable should be set to 1 when using EAPOL state machines
31          * with non-WPA security policy to generate dynamic WEP keys. When
32          * using WPA, this should be set to 0 so that WPA state machine can
33          * process the EAPOL-Key frames.
34          */
35         int accept_802_1x_keys;
36
37 #define EAPOL_REQUIRE_KEY_UNICAST BIT(0)
38 #define EAPOL_REQUIRE_KEY_BROADCAST BIT(1)
39         /**
40          * required_keys - Which EAPOL-Key packets are required
41          *
42          * This variable determines which EAPOL-Key packets are required before
43          * marking connection authenticated. This is a bit field of
44          * EAPOL_REQUIRE_KEY_UNICAST and EAPOL_REQUIRE_KEY_BROADCAST flags.
45          */
46         int required_keys;
47
48         /**
49          * fast_reauth - Whether fast EAP reauthentication is enabled
50          */
51         int fast_reauth;
52
53         /**
54          * workaround - Whether EAP workarounds are enabled
55          */
56         unsigned int workaround;
57
58         /**
59          * eap_disabled - Whether EAP is disabled
60          */
61         int eap_disabled;
62 };
63
64 struct eapol_sm;
65 struct wpa_config_blob;
66 struct wps_credential;
67
68 /**
69  * struct eapol_ctx - Global (for all networks) EAPOL state machine context
70  */
71 struct eapol_ctx {
72         /**
73          * ctx - Pointer to arbitrary upper level context
74          */
75         void *ctx;
76
77         /**
78          * preauth - IEEE 802.11i/RSN pre-authentication
79          *
80          * This EAPOL state machine is used for IEEE 802.11i/RSN
81          * pre-authentication
82          */
83         int preauth;
84
85         /**
86          * cb - Function to be called when EAPOL negotiation has been completed
87          * @eapol: Pointer to EAPOL state machine data
88          * @success: Whether the authentication was completed successfully
89          * @ctx: Pointer to context data (cb_ctx)
90          *
91          * This optional callback function will be called when the EAPOL
92          * authentication has been completed. This allows the owner of the
93          * EAPOL state machine to process the key and terminate the EAPOL state
94          * machine. Currently, this is used only in RSN pre-authentication.
95          */
96         void (*cb)(struct eapol_sm *eapol, int success, void *ctx);
97
98         /**
99          * cb_ctx - Callback context for cb()
100          */
101         void *cb_ctx;
102
103         /**
104          * msg_ctx - Callback context for wpa_msg() calls
105          */
106         void *msg_ctx;
107
108         /**
109          * scard_ctx - Callback context for PC/SC scard_*() function calls
110          *
111          * This context can be updated with eapol_sm_register_scard_ctx().
112          */
113         void *scard_ctx;
114
115         /**
116          * eapol_send_ctx - Callback context for eapol_send() calls
117          */
118         void *eapol_send_ctx;
119
120         /**
121          * eapol_done_cb - Function to be called at successful completion
122          * @ctx: Callback context (ctx)
123          *
124          * This function is called at the successful completion of EAPOL
125          * authentication. If dynamic WEP keys are used, this is called only
126          * after all the expected keys have been received.
127          */
128         void (*eapol_done_cb)(void *ctx);
129
130         /**
131          * eapol_send - Send EAPOL packets
132          * @ctx: Callback context (eapol_send_ctx)
133          * @type: EAPOL type (IEEE802_1X_TYPE_*)
134          * @buf: Pointer to EAPOL payload
135          * @len: Length of the EAPOL payload
136          * Returns: 0 on success, -1 on failure
137          */
138         int (*eapol_send)(void *ctx, int type, const u8 *buf, size_t len);
139
140         /**
141          * set_wep_key - Configure WEP keys
142          * @ctx: Callback context (ctx)
143          * @unicast: Non-zero = unicast, 0 = multicast/broadcast key
144          * @keyidx: Key index (0..3)
145          * @key: WEP key
146          * @keylen: Length of the WEP key
147          * Returns: 0 on success, -1 on failure
148          */
149         int (*set_wep_key)(void *ctx, int unicast, int keyidx,
150                            const u8 *key, size_t keylen);
151
152         /**
153          * set_config_blob - Set or add a named configuration blob
154          * @ctx: Callback context (ctx)
155          * @blob: New value for the blob
156          *
157          * Adds a new configuration blob or replaces the current value of an
158          * existing blob.
159          */
160         void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob);
161
162         /**
163          * get_config_blob - Get a named configuration blob
164          * @ctx: Callback context (ctx)
165          * @name: Name of the blob
166          * Returns: Pointer to blob data or %NULL if not found
167          */
168         const struct wpa_config_blob * (*get_config_blob)(void *ctx,
169                                                           const char *name);
170
171         /**
172          * aborted_cached - Notify that cached PMK attempt was aborted
173          * @ctx: Callback context (ctx)
174          */
175         void (*aborted_cached)(void *ctx);
176
177 #ifdef EAP_TLS_OPENSSL
178         /**
179          * opensc_engine_path - Path to the OpenSSL engine for opensc
180          *
181          * This is an OpenSSL specific configuration option for loading OpenSC
182          * engine (engine_opensc.so); if %NULL, this engine is not loaded.
183          */
184         const char *opensc_engine_path;
185
186         /**
187          * pkcs11_engine_path - Path to the OpenSSL engine for PKCS#11
188          *
189          * This is an OpenSSL specific configuration option for loading PKCS#11
190          * engine (engine_pkcs11.so); if %NULL, this engine is not loaded.
191          */
192         const char *pkcs11_engine_path;
193
194         /**
195          * pkcs11_module_path - Path to the OpenSSL OpenSC/PKCS#11 module
196          *
197          * This is an OpenSSL specific configuration option for configuring
198          * path to OpenSC/PKCS#11 engine (opensc-pkcs11.so); if %NULL, this
199          * module is not loaded.
200          */
201         const char *pkcs11_module_path;
202 #endif /* EAP_TLS_OPENSSL */
203         /**
204          * mac_addr - MAC address of the peer
205          *
206          * This is only used by EAP-WSC and can be left %NULL if not available.
207          */
208         const u8 *mac_addr;
209
210         /**
211          * wps_cred - Notify that new credential was received from WPS
212          * @ctx: Callback context (ctx)
213          * Returns: 0 on success (credential stored), -1 on failure
214          *
215          * This callback is only needed when using WPS Enrollee to configure
216          * new credentials. This can be left %NULL if no WPS functionality is
217          * enabled.
218          */
219         int (*wps_cred)(void *ctx, struct wps_credential *cred);
220
221         /**
222          * eap_param_needed - Notify that EAP parameter is needed
223          * @ctx: Callback context (ctx)
224          * @field: Field name (e.g., "IDENTITY")
225          * @txt: User readable text describing the required parameter
226          */
227         void (*eap_param_needed)(void *ctx, const char *field,
228                                  const char *txt);
229 };
230
231
232 struct eap_peer_config;
233
234 #ifdef IEEE8021X_EAPOL
235 struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx);
236 void eapol_sm_deinit(struct eapol_sm *sm);
237 void eapol_sm_step(struct eapol_sm *sm);
238 int eapol_sm_get_status(struct eapol_sm *sm, char *buf, size_t buflen,
239                         int verbose);
240 int eapol_sm_get_mib(struct eapol_sm *sm, char *buf, size_t buflen);
241 void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod, int authPeriod,
242                         int startPeriod, int maxStart);
243 int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src, const u8 *buf,
244                       size_t len);
245 void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm);
246 void eapol_sm_notify_portEnabled(struct eapol_sm *sm, Boolean enabled);
247 void eapol_sm_notify_portValid(struct eapol_sm *sm, Boolean valid);
248 void eapol_sm_notify_eap_success(struct eapol_sm *sm, Boolean success);
249 void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail);
250 void eapol_sm_notify_config(struct eapol_sm *sm,
251                             struct eap_peer_config *config,
252                             const struct eapol_config *conf);
253 int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len);
254 void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff);
255 void eapol_sm_notify_cached(struct eapol_sm *sm);
256 void eapol_sm_notify_pmkid_attempt(struct eapol_sm *sm, int attempt);
257 void eapol_sm_register_scard_ctx(struct eapol_sm *sm, void *ctx);
258 void eapol_sm_notify_portControl(struct eapol_sm *sm, PortControl portControl);
259 void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm);
260 void eapol_sm_notify_ctrl_response(struct eapol_sm *sm);
261 void eapol_sm_request_reauth(struct eapol_sm *sm);
262 void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm, int in_eapol_sm);
263 void eapol_sm_invalidate_cached_session(struct eapol_sm *sm);
264 #else /* IEEE8021X_EAPOL */
265 static inline struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx)
266 {
267         free(ctx);
268         return (struct eapol_sm *) 1;
269 }
270 static inline void eapol_sm_deinit(struct eapol_sm *sm)
271 {
272 }
273 static inline void eapol_sm_step(struct eapol_sm *sm)
274 {
275 }
276 static inline int eapol_sm_get_status(struct eapol_sm *sm, char *buf,
277                                       size_t buflen, int verbose)
278 {
279         return 0;
280 }
281 static inline int eapol_sm_get_mib(struct eapol_sm *sm, char *buf,
282                                    size_t buflen)
283 {
284         return 0;
285 }
286 static inline void eapol_sm_configure(struct eapol_sm *sm, int heldPeriod,
287                                       int authPeriod, int startPeriod,
288                                       int maxStart)
289 {
290 }
291 static inline int eapol_sm_rx_eapol(struct eapol_sm *sm, const u8 *src,
292                                     const u8 *buf, size_t len)
293 {
294         return 0;
295 }
296 static inline void eapol_sm_notify_tx_eapol_key(struct eapol_sm *sm)
297 {
298 }
299 static inline void eapol_sm_notify_portEnabled(struct eapol_sm *sm,
300                                                Boolean enabled)
301 {
302 }
303 static inline void eapol_sm_notify_portValid(struct eapol_sm *sm,
304                                              Boolean valid)
305 {
306 }
307 static inline void eapol_sm_notify_eap_success(struct eapol_sm *sm,
308                                                Boolean success)
309 {
310 }
311 static inline void eapol_sm_notify_eap_fail(struct eapol_sm *sm, Boolean fail)
312 {
313 }
314 static inline void eapol_sm_notify_config(struct eapol_sm *sm,
315                                           struct eap_peer_config *config,
316                                           struct eapol_config *conf)
317 {
318 }
319 static inline int eapol_sm_get_key(struct eapol_sm *sm, u8 *key, size_t len)
320 {
321         return -1;
322 }
323 static inline void eapol_sm_notify_logoff(struct eapol_sm *sm, Boolean logoff)
324 {
325 }
326 static inline void eapol_sm_notify_cached(struct eapol_sm *sm)
327 {
328 }
329 #define eapol_sm_notify_pmkid_attempt(sm, attempt) do { } while (0)
330 #define eapol_sm_register_scard_ctx(sm, ctx) do { } while (0)
331 static inline void eapol_sm_notify_portControl(struct eapol_sm *sm,
332                                                PortControl portControl)
333 {
334 }
335 static inline void eapol_sm_notify_ctrl_attached(struct eapol_sm *sm)
336 {
337 }
338 static inline void eapol_sm_notify_ctrl_response(struct eapol_sm *sm)
339 {
340 }
341 static inline void eapol_sm_request_reauth(struct eapol_sm *sm)
342 {
343 }
344 static inline void eapol_sm_notify_lower_layer_success(struct eapol_sm *sm,
345                                                        int in_eapol_sm)
346 {
347 }
348 static inline void eapol_sm_invalidate_cached_session(struct eapol_sm *sm)
349 {
350 }
351 #endif /* IEEE8021X_EAPOL */
352
353 #endif /* EAPOL_SUPP_SM_H */