eap.h 8.6 KB

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