wpa_auth_i.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * hostapd - IEEE 802.11i-2004 / WPA Authenticator: Internal definitions
  3. * Copyright (c) 2004-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 WPA_AUTH_I_H
  15. #define WPA_AUTH_I_H
  16. /* max(dot11RSNAConfigGroupUpdateCount,dot11RSNAConfigPairwiseUpdateCount) */
  17. #define RSNA_MAX_EAPOL_RETRIES 4
  18. struct wpa_group;
  19. struct wpa_stsl_negotiation {
  20. struct wpa_stsl_negotiation *next;
  21. u8 initiator[ETH_ALEN];
  22. u8 peer[ETH_ALEN];
  23. };
  24. struct wpa_state_machine {
  25. struct wpa_authenticator *wpa_auth;
  26. struct wpa_group *group;
  27. u8 addr[ETH_ALEN];
  28. enum {
  29. WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED,
  30. WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2,
  31. WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART,
  32. WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2,
  33. WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE
  34. } wpa_ptk_state;
  35. enum {
  36. WPA_PTK_GROUP_IDLE = 0,
  37. WPA_PTK_GROUP_REKEYNEGOTIATING,
  38. WPA_PTK_GROUP_REKEYESTABLISHED,
  39. WPA_PTK_GROUP_KEYERROR
  40. } wpa_ptk_group_state;
  41. Boolean Init;
  42. Boolean DeauthenticationRequest;
  43. Boolean AuthenticationRequest;
  44. Boolean ReAuthenticationRequest;
  45. Boolean Disconnect;
  46. int TimeoutCtr;
  47. int GTimeoutCtr;
  48. Boolean TimeoutEvt;
  49. Boolean EAPOLKeyReceived;
  50. Boolean EAPOLKeyPairwise;
  51. Boolean EAPOLKeyRequest;
  52. Boolean MICVerified;
  53. Boolean GUpdateStationKeys;
  54. u8 ANonce[WPA_NONCE_LEN];
  55. u8 SNonce[WPA_NONCE_LEN];
  56. u8 PMK[PMK_LEN];
  57. struct wpa_ptk PTK;
  58. Boolean PTK_valid;
  59. Boolean pairwise_set;
  60. int keycount;
  61. Boolean Pair;
  62. struct {
  63. u8 counter[WPA_REPLAY_COUNTER_LEN];
  64. Boolean valid;
  65. } key_replay[RSNA_MAX_EAPOL_RETRIES];
  66. Boolean PInitAKeys; /* WPA only, not in IEEE 802.11i */
  67. Boolean PTKRequest; /* not in IEEE 802.11i state machine */
  68. Boolean has_GTK;
  69. Boolean PtkGroupInit; /* init request for PTK Group state machine */
  70. u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */
  71. size_t last_rx_eapol_key_len;
  72. unsigned int changed:1;
  73. unsigned int in_step_loop:1;
  74. unsigned int pending_deinit:1;
  75. unsigned int started:1;
  76. unsigned int mgmt_frame_prot:1;
  77. #ifdef CONFIG_IEEE80211R
  78. unsigned int ft_completed:1;
  79. unsigned int pmk_r1_name_valid:1;
  80. #endif /* CONFIG_IEEE80211R */
  81. u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN];
  82. int req_replay_counter_used;
  83. u8 *wpa_ie;
  84. size_t wpa_ie_len;
  85. enum {
  86. WPA_VERSION_NO_WPA = 0 /* WPA not used */,
  87. WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */,
  88. WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */
  89. } wpa;
  90. int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
  91. int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */
  92. struct rsn_pmksa_cache_entry *pmksa;
  93. u32 dot11RSNAStatsTKIPLocalMICFailures;
  94. u32 dot11RSNAStatsTKIPRemoteMICFailures;
  95. #ifdef CONFIG_IEEE80211R
  96. u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */
  97. size_t xxkey_len;
  98. u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth
  99. * Request */
  100. u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
  101. size_t r0kh_id_len;
  102. #endif /* CONFIG_IEEE80211R */
  103. };
  104. /* per group key state machine data */
  105. struct wpa_group {
  106. struct wpa_group *next;
  107. int vlan_id;
  108. Boolean GInit;
  109. int GKeyDoneStations;
  110. Boolean GTKReKey;
  111. int GTK_len;
  112. int GN, GM;
  113. Boolean GTKAuthenticator;
  114. u8 Counter[WPA_NONCE_LEN];
  115. enum {
  116. WPA_GROUP_GTK_INIT = 0,
  117. WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE
  118. } wpa_group_state;
  119. u8 GMK[WPA_GMK_LEN];
  120. u8 GTK[2][WPA_GTK_MAX_LEN];
  121. u8 GNonce[WPA_NONCE_LEN];
  122. Boolean changed;
  123. #ifdef CONFIG_IEEE80211W
  124. u8 IGTK[2][WPA_IGTK_LEN];
  125. int GN_igtk, GM_igtk;
  126. #endif /* CONFIG_IEEE80211W */
  127. };
  128. struct wpa_ft_pmk_cache;
  129. /* per authenticator data */
  130. struct wpa_authenticator {
  131. struct wpa_group *group;
  132. unsigned int dot11RSNAStatsTKIPRemoteMICFailures;
  133. u32 dot11RSNAAuthenticationSuiteSelected;
  134. u32 dot11RSNAPairwiseCipherSelected;
  135. u32 dot11RSNAGroupCipherSelected;
  136. u8 dot11RSNAPMKIDUsed[PMKID_LEN];
  137. u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */
  138. u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */
  139. u32 dot11RSNAGroupCipherRequested; /* FIX: update */
  140. unsigned int dot11RSNATKIPCounterMeasuresInvoked;
  141. unsigned int dot11RSNA4WayHandshakeFailures;
  142. struct wpa_stsl_negotiation *stsl_negotiations;
  143. struct wpa_auth_config conf;
  144. struct wpa_auth_callbacks cb;
  145. u8 *wpa_ie;
  146. size_t wpa_ie_len;
  147. u8 addr[ETH_ALEN];
  148. struct rsn_pmksa_cache *pmksa;
  149. struct wpa_ft_pmk_cache *ft_pmk_cache;
  150. };
  151. int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
  152. const u8 *pmkid);
  153. void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
  154. logger_level level, const char *txt);
  155. void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
  156. logger_level level, const char *fmt, ...);
  157. void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
  158. struct wpa_state_machine *sm, int key_info,
  159. const u8 *key_rsc, const u8 *nonce,
  160. const u8 *kde, size_t kde_len,
  161. int keyidx, int encr, int force_version);
  162. int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
  163. int (*cb)(struct wpa_state_machine *sm, void *ctx),
  164. void *cb_ctx);
  165. int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
  166. int (*cb)(struct wpa_authenticator *a, void *ctx),
  167. void *cb_ctx);
  168. #ifdef CONFIG_PEERKEY
  169. int wpa_stsl_remove(struct wpa_authenticator *wpa_auth,
  170. struct wpa_stsl_negotiation *neg);
  171. void wpa_smk_error(struct wpa_authenticator *wpa_auth,
  172. struct wpa_state_machine *sm, struct wpa_eapol_key *key);
  173. void wpa_smk_m1(struct wpa_authenticator *wpa_auth,
  174. struct wpa_state_machine *sm, struct wpa_eapol_key *key);
  175. void wpa_smk_m3(struct wpa_authenticator *wpa_auth,
  176. struct wpa_state_machine *sm, struct wpa_eapol_key *key);
  177. #endif /* CONFIG_PEERKEY */
  178. #ifdef CONFIG_IEEE80211R
  179. int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len);
  180. int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
  181. struct wpa_ptk *ptk, size_t ptk_len);
  182. struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void);
  183. void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache);
  184. #endif /* CONFIG_IEEE80211R */
  185. #endif /* WPA_AUTH_I_H */