eapol_sm.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * IEEE 802.1X-2004 Authenticator - EAPOL state machine
  3. * Copyright (c) 2002-2009, 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 EAPOL_SM_H
  15. #define EAPOL_SM_H
  16. #include "common/defs.h"
  17. #include "radius/radius.h"
  18. /* IEEE Std 802.1X-2004, Ch. 8.2 */
  19. typedef enum { ForceUnauthorized = 1, ForceAuthorized = 3, Auto = 2 }
  20. PortTypes;
  21. typedef enum { Unauthorized = 2, Authorized = 1 } PortState;
  22. typedef enum { Both = 0, In = 1 } ControlledDirection;
  23. typedef unsigned int Counter;
  24. struct eap_sm;
  25. struct eapol_auth_config {
  26. int eap_reauth_period;
  27. int wpa;
  28. int individual_wep_key_len;
  29. int eap_server;
  30. void *ssl_ctx;
  31. void *eap_sim_db_priv;
  32. char *eap_req_id_text; /* a copy of this will be allocated */
  33. size_t eap_req_id_text_len;
  34. u8 *pac_opaque_encr_key;
  35. u8 *eap_fast_a_id;
  36. size_t eap_fast_a_id_len;
  37. char *eap_fast_a_id_info;
  38. int eap_fast_prov;
  39. int pac_key_lifetime;
  40. int pac_key_refresh_time;
  41. int eap_sim_aka_result_ind;
  42. int tnc;
  43. struct wps_context *wps;
  44. /* Opaque context pointer to owner data for callback functions */
  45. void *ctx;
  46. };
  47. struct eap_user;
  48. typedef enum {
  49. EAPOL_LOGGER_DEBUG, EAPOL_LOGGER_INFO, EAPOL_LOGGER_WARNING
  50. } eapol_logger_level;
  51. enum eapol_event {
  52. EAPOL_AUTH_SM_CHANGE,
  53. EAPOL_AUTH_REAUTHENTICATE
  54. };
  55. struct eapol_auth_cb {
  56. void (*eapol_send)(void *ctx, void *sta_ctx, u8 type, const u8 *data,
  57. size_t datalen);
  58. void (*aaa_send)(void *ctx, void *sta_ctx, const u8 *data,
  59. size_t datalen);
  60. void (*finished)(void *ctx, void *sta_ctx, int success, int preauth);
  61. int (*get_eap_user)(void *ctx, const u8 *identity, size_t identity_len,
  62. int phase2, struct eap_user *user);
  63. int (*sta_entry_alive)(void *ctx, const u8 *addr);
  64. void (*logger)(void *ctx, const u8 *addr, eapol_logger_level level,
  65. const char *txt);
  66. void (*set_port_authorized)(void *ctx, void *sta_ctx, int authorized);
  67. void (*abort_auth)(void *ctx, void *sta_ctx);
  68. void (*tx_key)(void *ctx, void *sta_ctx);
  69. void (*eapol_event)(void *ctx, void *sta_ctx, enum eapol_event type);
  70. };
  71. /**
  72. * struct eapol_authenticator - Global EAPOL authenticator data
  73. */
  74. struct eapol_authenticator {
  75. struct eapol_auth_config conf;
  76. struct eapol_auth_cb cb;
  77. u8 *default_wep_key;
  78. u8 default_wep_key_idx;
  79. };
  80. /**
  81. * struct eapol_state_machine - Per-Supplicant Authenticator state machines
  82. */
  83. struct eapol_state_machine {
  84. /* timers */
  85. int aWhile;
  86. int quietWhile;
  87. int reAuthWhen;
  88. /* global variables */
  89. Boolean authAbort;
  90. Boolean authFail;
  91. PortState authPortStatus;
  92. Boolean authStart;
  93. Boolean authTimeout;
  94. Boolean authSuccess;
  95. Boolean eapolEap;
  96. Boolean initialize;
  97. Boolean keyDone;
  98. Boolean keyRun;
  99. Boolean keyTxEnabled;
  100. PortTypes portControl;
  101. Boolean portValid;
  102. Boolean reAuthenticate;
  103. /* Port Timers state machine */
  104. /* 'Boolean tick' implicitly handled as registered timeout */
  105. /* Authenticator PAE state machine */
  106. enum { AUTH_PAE_INITIALIZE, AUTH_PAE_DISCONNECTED, AUTH_PAE_CONNECTING,
  107. AUTH_PAE_AUTHENTICATING, AUTH_PAE_AUTHENTICATED,
  108. AUTH_PAE_ABORTING, AUTH_PAE_HELD, AUTH_PAE_FORCE_AUTH,
  109. AUTH_PAE_FORCE_UNAUTH, AUTH_PAE_RESTART } auth_pae_state;
  110. /* variables */
  111. Boolean eapolLogoff;
  112. Boolean eapolStart;
  113. PortTypes portMode;
  114. unsigned int reAuthCount;
  115. /* constants */
  116. unsigned int quietPeriod; /* default 60; 0..65535 */
  117. #define AUTH_PAE_DEFAULT_quietPeriod 60
  118. unsigned int reAuthMax; /* default 2 */
  119. #define AUTH_PAE_DEFAULT_reAuthMax 2
  120. /* counters */
  121. Counter authEntersConnecting;
  122. Counter authEapLogoffsWhileConnecting;
  123. Counter authEntersAuthenticating;
  124. Counter authAuthSuccessesWhileAuthenticating;
  125. Counter authAuthTimeoutsWhileAuthenticating;
  126. Counter authAuthFailWhileAuthenticating;
  127. Counter authAuthEapStartsWhileAuthenticating;
  128. Counter authAuthEapLogoffWhileAuthenticating;
  129. Counter authAuthReauthsWhileAuthenticated;
  130. Counter authAuthEapStartsWhileAuthenticated;
  131. Counter authAuthEapLogoffWhileAuthenticated;
  132. /* Backend Authentication state machine */
  133. enum { BE_AUTH_REQUEST, BE_AUTH_RESPONSE, BE_AUTH_SUCCESS,
  134. BE_AUTH_FAIL, BE_AUTH_TIMEOUT, BE_AUTH_IDLE, BE_AUTH_INITIALIZE,
  135. BE_AUTH_IGNORE
  136. } be_auth_state;
  137. /* constants */
  138. unsigned int serverTimeout; /* default 30; 1..X */
  139. #define BE_AUTH_DEFAULT_serverTimeout 30
  140. /* counters */
  141. Counter backendResponses;
  142. Counter backendAccessChallenges;
  143. Counter backendOtherRequestsToSupplicant;
  144. Counter backendAuthSuccesses;
  145. Counter backendAuthFails;
  146. /* Reauthentication Timer state machine */
  147. enum { REAUTH_TIMER_INITIALIZE, REAUTH_TIMER_REAUTHENTICATE
  148. } reauth_timer_state;
  149. /* constants */
  150. unsigned int reAuthPeriod; /* default 3600 s */
  151. Boolean reAuthEnabled;
  152. /* Authenticator Key Transmit state machine */
  153. enum { AUTH_KEY_TX_NO_KEY_TRANSMIT, AUTH_KEY_TX_KEY_TRANSMIT
  154. } auth_key_tx_state;
  155. /* Key Receive state machine */
  156. enum { KEY_RX_NO_KEY_RECEIVE, KEY_RX_KEY_RECEIVE } key_rx_state;
  157. /* variables */
  158. Boolean rxKey;
  159. /* Controlled Directions state machine */
  160. enum { CTRL_DIR_FORCE_BOTH, CTRL_DIR_IN_OR_BOTH } ctrl_dir_state;
  161. /* variables */
  162. ControlledDirection adminControlledDirections;
  163. ControlledDirection operControlledDirections;
  164. Boolean operEdge;
  165. /* Authenticator Statistics Table */
  166. Counter dot1xAuthEapolFramesRx;
  167. Counter dot1xAuthEapolFramesTx;
  168. Counter dot1xAuthEapolStartFramesRx;
  169. Counter dot1xAuthEapolLogoffFramesRx;
  170. Counter dot1xAuthEapolRespIdFramesRx;
  171. Counter dot1xAuthEapolRespFramesRx;
  172. Counter dot1xAuthEapolReqIdFramesTx;
  173. Counter dot1xAuthEapolReqFramesTx;
  174. Counter dot1xAuthInvalidEapolFramesRx;
  175. Counter dot1xAuthEapLengthErrorFramesRx;
  176. Counter dot1xAuthLastEapolFrameVersion;
  177. /* Other variables - not defined in IEEE 802.1X */
  178. u8 addr[ETH_ALEN]; /* Supplicant address */
  179. #define EAPOL_SM_PREAUTH BIT(0)
  180. #define EAPOL_SM_WAIT_START BIT(1)
  181. #define EAPOL_SM_USES_WPA BIT(2)
  182. #define EAPOL_SM_FROM_PMKSA_CACHE BIT(3)
  183. int flags; /* EAPOL_SM_* */
  184. /* EAPOL/AAA <-> EAP full authenticator interface */
  185. struct eap_eapol_interface *eap_if;
  186. int radius_identifier;
  187. /* TODO: check when the last messages can be released */
  188. struct radius_msg *last_recv_radius;
  189. u8 last_eap_id; /* last used EAP Identifier */
  190. u8 *identity;
  191. size_t identity_len;
  192. u8 eap_type_authsrv; /* EAP type of the last EAP packet from
  193. * Authentication server */
  194. u8 eap_type_supp; /* EAP type of the last EAP packet from Supplicant */
  195. struct radius_class_data radius_class;
  196. /* Keys for encrypting and signing EAPOL-Key frames */
  197. u8 *eapol_key_sign;
  198. size_t eapol_key_sign_len;
  199. u8 *eapol_key_crypt;
  200. size_t eapol_key_crypt_len;
  201. struct eap_sm *eap;
  202. Boolean initializing; /* in process of initializing state machines */
  203. Boolean changed;
  204. struct eapol_authenticator *eapol;
  205. void *sta; /* station context pointer to use in callbacks */
  206. };
  207. struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,
  208. struct eapol_auth_cb *cb);
  209. void eapol_auth_deinit(struct eapol_authenticator *eapol);
  210. struct eapol_state_machine *
  211. eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
  212. int flags, const struct wpabuf *assoc_wps_ie, void *sta_ctx);
  213. void eapol_auth_free(struct eapol_state_machine *sm);
  214. void eapol_auth_step(struct eapol_state_machine *sm);
  215. void eapol_auth_dump_state(FILE *f, const char *prefix,
  216. struct eapol_state_machine *sm);
  217. int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx);
  218. #endif /* EAPOL_SM_H */