wpa_auth_i.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * hostapd - IEEE 802.11i-2004 / WPA Authenticator: Internal definitions
  3. * Copyright (c) 2004-2015, 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. #include "utils/list.h"
  11. /* max(dot11RSNAConfigGroupUpdateCount,dot11RSNAConfigPairwiseUpdateCount) */
  12. #define RSNA_MAX_EAPOL_RETRIES 4
  13. struct wpa_group;
  14. struct wpa_state_machine {
  15. struct wpa_authenticator *wpa_auth;
  16. struct wpa_group *group;
  17. u8 addr[ETH_ALEN];
  18. u8 p2p_dev_addr[ETH_ALEN];
  19. enum {
  20. WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED,
  21. WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2,
  22. WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART,
  23. WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2,
  24. WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE
  25. } wpa_ptk_state;
  26. enum {
  27. WPA_PTK_GROUP_IDLE = 0,
  28. WPA_PTK_GROUP_REKEYNEGOTIATING,
  29. WPA_PTK_GROUP_REKEYESTABLISHED,
  30. WPA_PTK_GROUP_KEYERROR
  31. } wpa_ptk_group_state;
  32. Boolean Init;
  33. Boolean DeauthenticationRequest;
  34. Boolean AuthenticationRequest;
  35. Boolean ReAuthenticationRequest;
  36. Boolean Disconnect;
  37. u16 disconnect_reason; /* specific reason code to use with Disconnect */
  38. u32 TimeoutCtr;
  39. u32 GTimeoutCtr;
  40. Boolean TimeoutEvt;
  41. Boolean EAPOLKeyReceived;
  42. Boolean EAPOLKeyPairwise;
  43. Boolean EAPOLKeyRequest;
  44. Boolean MICVerified;
  45. Boolean GUpdateStationKeys;
  46. u8 ANonce[WPA_NONCE_LEN];
  47. u8 SNonce[WPA_NONCE_LEN];
  48. u8 alt_SNonce[WPA_NONCE_LEN];
  49. u8 alt_replay_counter[WPA_REPLAY_COUNTER_LEN];
  50. u8 PMK[PMK_LEN_MAX];
  51. unsigned int pmk_len;
  52. struct wpa_ptk PTK;
  53. Boolean PTK_valid;
  54. Boolean pairwise_set;
  55. Boolean tk_already_set;
  56. int keycount;
  57. Boolean Pair;
  58. struct wpa_key_replay_counter {
  59. u8 counter[WPA_REPLAY_COUNTER_LEN];
  60. Boolean valid;
  61. } key_replay[RSNA_MAX_EAPOL_RETRIES],
  62. prev_key_replay[RSNA_MAX_EAPOL_RETRIES];
  63. Boolean PInitAKeys; /* WPA only, not in IEEE 802.11i */
  64. Boolean PTKRequest; /* not in IEEE 802.11i state machine */
  65. Boolean has_GTK;
  66. Boolean PtkGroupInit; /* init request for PTK Group state machine */
  67. u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */
  68. size_t last_rx_eapol_key_len;
  69. unsigned int changed:1;
  70. unsigned int in_step_loop:1;
  71. unsigned int pending_deinit:1;
  72. unsigned int started:1;
  73. unsigned int mgmt_frame_prot:1;
  74. unsigned int rx_eapol_key_secure:1;
  75. unsigned int update_snonce:1;
  76. unsigned int alt_snonce_valid:1;
  77. #ifdef CONFIG_IEEE80211R_AP
  78. unsigned int ft_completed:1;
  79. unsigned int pmk_r1_name_valid:1;
  80. #endif /* CONFIG_IEEE80211R_AP */
  81. unsigned int is_wnmsleep:1;
  82. u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN];
  83. int req_replay_counter_used;
  84. u8 *wpa_ie;
  85. size_t wpa_ie_len;
  86. enum {
  87. WPA_VERSION_NO_WPA = 0 /* WPA not used */,
  88. WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */,
  89. WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */
  90. } wpa;
  91. int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
  92. int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */
  93. struct rsn_pmksa_cache_entry *pmksa;
  94. u32 dot11RSNAStatsTKIPLocalMICFailures;
  95. u32 dot11RSNAStatsTKIPRemoteMICFailures;
  96. #ifdef CONFIG_IEEE80211R_AP
  97. u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */
  98. size_t xxkey_len;
  99. u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth
  100. * Request */
  101. u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */
  102. size_t r0kh_id_len;
  103. u8 sup_pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name from EAPOL-Key
  104. * message 2/4 */
  105. u8 *assoc_resp_ftie;
  106. void (*ft_pending_cb)(void *ctx, const u8 *dst, const u8 *bssid,
  107. u16 auth_transaction, u16 status,
  108. const u8 *ies, size_t ies_len);
  109. void *ft_pending_cb_ctx;
  110. struct wpabuf *ft_pending_req_ies;
  111. u8 ft_pending_pull_nonce[FT_RRB_NONCE_LEN];
  112. u8 ft_pending_auth_transaction;
  113. u8 ft_pending_current_ap[ETH_ALEN];
  114. int ft_pending_pull_left_retries;
  115. #endif /* CONFIG_IEEE80211R_AP */
  116. int pending_1_of_4_timeout;
  117. #ifdef CONFIG_P2P
  118. u8 ip_addr[4];
  119. #endif /* CONFIG_P2P */
  120. #ifdef CONFIG_FILS
  121. u8 fils_key_auth_sta[FILS_MAX_KEY_AUTH_LEN];
  122. u8 fils_key_auth_ap[FILS_MAX_KEY_AUTH_LEN];
  123. size_t fils_key_auth_len;
  124. unsigned int fils_completed:1;
  125. #endif /* CONFIG_FILS */
  126. #ifdef CONFIG_TESTING_OPTIONS
  127. void (*eapol_status_cb)(void *ctx1, void *ctx2);
  128. void *eapol_status_cb_ctx1;
  129. void *eapol_status_cb_ctx2;
  130. #endif /* CONFIG_TESTING_OPTIONS */
  131. };
  132. /* per group key state machine data */
  133. struct wpa_group {
  134. struct wpa_group *next;
  135. int vlan_id;
  136. Boolean GInit;
  137. int GKeyDoneStations;
  138. Boolean GTKReKey;
  139. int GTK_len;
  140. int GN, GM;
  141. Boolean GTKAuthenticator;
  142. u8 Counter[WPA_NONCE_LEN];
  143. enum {
  144. WPA_GROUP_GTK_INIT = 0,
  145. WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE,
  146. WPA_GROUP_FATAL_FAILURE
  147. } wpa_group_state;
  148. u8 GMK[WPA_GMK_LEN];
  149. u8 GTK[2][WPA_GTK_MAX_LEN];
  150. u8 GNonce[WPA_NONCE_LEN];
  151. Boolean changed;
  152. Boolean first_sta_seen;
  153. Boolean reject_4way_hs_for_entropy;
  154. #ifdef CONFIG_IEEE80211W
  155. u8 IGTK[2][WPA_IGTK_MAX_LEN];
  156. int GN_igtk, GM_igtk;
  157. #endif /* CONFIG_IEEE80211W */
  158. /* Number of references except those in struct wpa_group->next */
  159. unsigned int references;
  160. unsigned int num_setup_iface;
  161. };
  162. struct wpa_ft_pmk_cache;
  163. /* per authenticator data */
  164. struct wpa_authenticator {
  165. struct wpa_group *group;
  166. unsigned int dot11RSNAStatsTKIPRemoteMICFailures;
  167. u32 dot11RSNAAuthenticationSuiteSelected;
  168. u32 dot11RSNAPairwiseCipherSelected;
  169. u32 dot11RSNAGroupCipherSelected;
  170. u8 dot11RSNAPMKIDUsed[PMKID_LEN];
  171. u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */
  172. u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */
  173. u32 dot11RSNAGroupCipherRequested; /* FIX: update */
  174. unsigned int dot11RSNATKIPCounterMeasuresInvoked;
  175. unsigned int dot11RSNA4WayHandshakeFailures;
  176. struct wpa_auth_config conf;
  177. const struct wpa_auth_callbacks *cb;
  178. void *cb_ctx;
  179. u8 *wpa_ie;
  180. size_t wpa_ie_len;
  181. u8 addr[ETH_ALEN];
  182. struct rsn_pmksa_cache *pmksa;
  183. struct wpa_ft_pmk_cache *ft_pmk_cache;
  184. #ifdef CONFIG_P2P
  185. struct bitfield *ip_pool;
  186. #endif /* CONFIG_P2P */
  187. };
  188. #ifdef CONFIG_IEEE80211R_AP
  189. #define FT_REMOTE_SEQ_BACKLOG 16
  190. struct ft_remote_seq_rx {
  191. u32 dom;
  192. struct os_reltime time_offset; /* local time - offset = remote time */
  193. /* accepted sequence numbers: (offset ... offset + 0x40000000]
  194. * (except those in last)
  195. * dropped sequence numbers: (offset - 0x40000000 ... offset]
  196. * all others trigger SEQ_REQ message (except first message)
  197. */
  198. u32 last[FT_REMOTE_SEQ_BACKLOG];
  199. unsigned int num_last;
  200. u32 offsetidx;
  201. struct dl_list queue; /* send nonces + rrb msgs awaiting seq resp */
  202. };
  203. struct ft_remote_seq_tx {
  204. u32 dom; /* non zero if initialized */
  205. u32 seq;
  206. };
  207. struct ft_remote_seq {
  208. struct ft_remote_seq_rx rx;
  209. struct ft_remote_seq_tx tx;
  210. };
  211. #endif /* CONFIG_IEEE80211R_AP */
  212. int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
  213. const u8 *pmkid);
  214. void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
  215. logger_level level, const char *txt);
  216. void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
  217. logger_level level, const char *fmt, ...);
  218. void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
  219. struct wpa_state_machine *sm, int key_info,
  220. const u8 *key_rsc, const u8 *nonce,
  221. const u8 *kde, size_t kde_len,
  222. int keyidx, int encr, int force_version);
  223. int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
  224. int (*cb)(struct wpa_state_machine *sm, void *ctx),
  225. void *cb_ctx);
  226. int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
  227. int (*cb)(struct wpa_authenticator *a, void *ctx),
  228. void *cb_ctx);
  229. #ifdef CONFIG_IEEE80211R_AP
  230. int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len);
  231. int wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id,
  232. size_t r0kh_id_len,
  233. const u8 *anonce, const u8 *snonce,
  234. u8 *buf, size_t len, const u8 *subelem,
  235. size_t subelem_len);
  236. int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
  237. struct wpa_ptk *ptk);
  238. struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void);
  239. void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache);
  240. void wpa_ft_install_ptk(struct wpa_state_machine *sm);
  241. int wpa_ft_store_pmk_r0(struct wpa_authenticator *wpa_auth,
  242. const u8 *spa, const u8 *pmk_r0,
  243. const u8 *pmk_r0_name, int pairwise);
  244. #endif /* CONFIG_IEEE80211R_AP */
  245. #endif /* WPA_AUTH_I_H */