eapol_sm.h 7.6 KB

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