eapol_sm.h 7.6 KB

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