eapol_sm.h 7.5 KB

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