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