wpa_auth_i.h 7.2 KB

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