eapol_sm.h 7.8 KB

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