Merge from vendor branch GDB:
[dragonfly.git] / contrib / wpa_supplicant-0.4.9 / eap.h
1 /*
2  * WPA Supplicant / EAP state machine functions (RFC 4137)
3  * Copyright (c) 2004-2005, Jouni Malinen <jkmaline@cc.hut.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 EAP_H
16 #define EAP_H
17
18 #include "defs.h"
19 #include "eap_defs.h"
20
21 struct eap_sm;
22 struct wpa_ssid;
23 struct wpa_config_blob;
24
25
26 #ifdef IEEE8021X_EAPOL
27
28 /**
29  * enum eapol_bool_var - EAPOL boolean state variables for EAP state machine
30  *
31  * These variables are used in the interface between EAP peer state machine and
32  * lower layer. These are defined in RFC 4137, Sect. 4.1. Lower layer code is
33  * expected to maintain these variables and register a callback functions for
34  * EAP state machine to get and set the variables.
35  */
36 enum eapol_bool_var {
37         /**
38          * EAPOL_eapSuccess - EAP SUCCESS state reached
39          *
40          * EAP state machine reads and writes this value.
41          */
42         EAPOL_eapSuccess,
43
44         /**
45          * EAPOL_eapRestart - Lower layer request to restart authentication
46          *
47          * Set to TRUE in lower layer, FALSE in EAP state machine.
48          */
49         EAPOL_eapRestart,
50
51         /**
52          * EAPOL_eapFail - EAP FAILURE state reached
53          *
54          * EAP state machine writes this value.
55          */
56         EAPOL_eapFail,
57
58         /**
59          * EAPOL_eapResp - Response to send
60          *
61          * Set to TRUE in EAP state machine, FALSE in lower layer.
62          */
63         EAPOL_eapResp,
64
65         /**
66          * EAPOL_eapNoResp - Request has been process; no response to send
67          *
68          * Set to TRUE in EAP state machine, FALSE in lower layer.
69          */
70         EAPOL_eapNoResp,
71
72         /**
73          * EAPOL_eapReq - EAP request available from lower layer
74          *
75          * Set to TRUE in lower layer, FALSE in EAP state machine.
76          */
77         EAPOL_eapReq,
78
79         /**
80          * EAPOL_portEnabled - Lower layer is ready for communication
81          *
82          * EAP state machines reads this value.
83          */
84         EAPOL_portEnabled,
85
86         /**
87          * EAPOL_altAccept - Alternate indication of success (RFC3748)
88          *
89          * EAP state machines reads this value.
90          */
91         EAPOL_altAccept,
92
93         /**
94          * EAPOL_altReject - Alternate indication of failure (RFC3748)
95          *
96          * EAP state machines reads this value.
97          */
98         EAPOL_altReject
99 };
100
101 /**
102  * enum eapol_int_var - EAPOL integer state variables for EAP state machine
103  *
104  * These variables are used in the interface between EAP peer state machine and
105  * lower layer. These are defined in RFC 4137, Sect. 4.1. Lower layer code is
106  * expected to maintain these variables and register a callback functions for
107  * EAP state machine to get and set the variables.
108  */
109 enum eapol_int_var {
110         /**
111          * EAPOL_idleWhile - Outside time for EAP peer timeout
112          *
113          * This integer variable is used to provide an outside timer that the
114          * external (to EAP state machine) code must decrement by one every
115          * second until the value reaches zero. This is used in the same way as
116          * EAPOL state machine timers. EAP state machine reads and writes this
117          * value.
118          */
119         EAPOL_idleWhile
120 };
121
122 /**
123  * struct eapol_callbacks - Callback functions from EAP to lower layer
124  *
125  * This structure defines the callback functions that EAP state machine
126  * requires from the lower layer (usually EAPOL state machine) for updating
127  * state variables and requesting information. eapol_ctx from eap_sm_init()
128  * call will be used as the ctx parameter for these callback functions.
129  */
130 struct eapol_callbacks {
131         /**
132          * get_config - Get pointer to the current network configuration
133          * @ctx: eapol_ctx from eap_sm_init() call
134          */
135         struct wpa_ssid * (*get_config)(void *ctx);
136
137         /**
138          * get_bool - Get a boolean EAPOL state variable
139          * @variable: EAPOL boolean variable to get
140          * Returns: Value of the EAPOL variable
141          */
142         Boolean (*get_bool)(void *ctx, enum eapol_bool_var variable);
143
144         /**
145          * set_bool - Set a boolean EAPOL state variable
146          * @ctx: eapol_ctx from eap_sm_init() call
147          * @variable: EAPOL boolean variable to set
148          * @value: Value for the EAPOL variable
149          */
150         void (*set_bool)(void *ctx, enum eapol_bool_var variable,
151                          Boolean value);
152
153         /**
154          * get_int - Get an integer EAPOL state variable
155          * @ctx: eapol_ctx from eap_sm_init() call
156          * @variable: EAPOL integer variable to get
157          * Returns: Value of the EAPOL variable
158          */
159         unsigned int (*get_int)(void *ctx, enum eapol_int_var variable);
160
161         /**
162          * set_int - Set an integer EAPOL state variable
163          * @ctx: eapol_ctx from eap_sm_init() call
164          * @variable: EAPOL integer variable to set
165          * @value: Value for the EAPOL variable
166          */
167         void (*set_int)(void *ctx, enum eapol_int_var variable,
168                         unsigned int value);
169
170         /**
171          * get_eapReqData - Get EAP-Request data
172          * @ctx: eapol_ctx from eap_sm_init() call
173          * @len: Pointer to variable that will be set to eapReqDataLen
174          * Returns: Reference to eapReqData (EAP state machine will not free
175          * this) or %NULL if eapReqData not available.
176          */
177         u8 * (*get_eapReqData)(void *ctx, size_t *len);
178
179         /**
180          * set_config_blob - Set named configuration blob
181          * @ctx: eapol_ctx from eap_sm_init() call
182          * @blob: New value for the blob
183          *
184          * Adds a new configuration blob or replaces the current value of an
185          * existing blob.
186          */
187         void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob);
188
189         /**
190          * get_config_blob - Get a named configuration blob
191          * @ctx: eapol_ctx from eap_sm_init() call
192          * @name: Name of the blob
193          * Returns: Pointer to blob data or %NULL if not found
194          */
195         const struct wpa_config_blob * (*get_config_blob)(void *ctx,
196                                                           const char *name);
197 };
198
199 /**
200  * struct eap_config - Configuration for EAP state machine
201  */
202 struct eap_config {
203         /**
204          * opensc_engine_path - OpenSC engine for OpenSSL engine support
205          *
206          * Usually, path to engine_opensc.so.
207          */
208         const char *opensc_engine_path;
209         /**
210          * pkcs11_engine_path - PKCS#11 engine for OpenSSL engine support
211          *
212          * Usually, path to engine_pkcs11.so.
213          */
214         const char *pkcs11_engine_path;
215         /**
216          * pkcs11_module_path - OpenSC PKCS#11 module for OpenSSL engine
217          *
218          * Usually, path to opensc-pkcs11.so.
219          */
220         const char *pkcs11_module_path;
221 };
222
223 struct eap_sm * eap_sm_init(void *eapol_ctx, struct eapol_callbacks *eapol_cb,
224                             void *msg_ctx, struct eap_config *conf);
225 void eap_sm_deinit(struct eap_sm *sm);
226 int eap_sm_step(struct eap_sm *sm);
227 void eap_sm_abort(struct eap_sm *sm);
228 int eap_sm_get_status(struct eap_sm *sm, char *buf, size_t buflen,
229                       int verbose);
230 u8 * eap_sm_buildIdentity(struct eap_sm *sm, int id, size_t *len,
231                           int encrypted);
232 const struct eap_method * eap_sm_get_eap_methods(int method);
233 void eap_sm_request_identity(struct eap_sm *sm, struct wpa_ssid *config);
234 void eap_sm_request_password(struct eap_sm *sm, struct wpa_ssid *config);
235 void eap_sm_request_new_password(struct eap_sm *sm, struct wpa_ssid *config);
236 void eap_sm_request_pin(struct eap_sm *sm, struct wpa_ssid *config);
237 void eap_sm_request_otp(struct eap_sm *sm, struct wpa_ssid *config,
238                         const char *msg, size_t msg_len);
239 void eap_sm_request_passphrase(struct eap_sm *sm, struct wpa_ssid *config);
240 void eap_sm_notify_ctrl_attached(struct eap_sm *sm);
241 u8 eap_get_type(const char *name);
242 const char * eap_get_name(EapType type);
243 size_t eap_get_names(char *buf, size_t buflen);
244 u8 eap_get_phase2_type(const char *name);
245 u8 *eap_get_phase2_types(struct wpa_ssid *config, size_t *count);
246 void eap_set_fast_reauth(struct eap_sm *sm, int enabled);
247 void eap_set_workaround(struct eap_sm *sm, unsigned int workaround);
248 void eap_set_force_disabled(struct eap_sm *sm, int disabled);
249 struct wpa_ssid * eap_get_config(struct eap_sm *sm);
250 int eap_key_available(struct eap_sm *sm);
251 void eap_notify_success(struct eap_sm *sm);
252 void eap_notify_lower_layer_success(struct eap_sm *sm);
253 const u8 * eap_get_eapKeyData(struct eap_sm *sm, size_t *len);
254 u8 * eap_get_eapRespData(struct eap_sm *sm, size_t *len);
255 void eap_register_scard_ctx(struct eap_sm *sm, void *ctx);
256
257 #else /* IEEE8021X_EAPOL */
258
259 static inline u8 eap_get_type(const char *name)
260 {
261         return EAP_TYPE_NONE;
262 }
263
264 static inline const char * eap_get_name(EapType type)
265 {
266         return NULL;
267 }
268
269 static inline size_t eap_get_names(char *buf, size_t buflen)
270 {
271         return 0;
272 }
273
274 #endif /* IEEE8021X_EAPOL */
275
276 #endif /* EAP_H */