eapol_sm.h 7.5 KB

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