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 9 #ifndef WPA_AUTH_I_H 10 #define WPA_AUTH_I_H 11 12 #include "utils/list.h" 13 14 /* max(dot11RSNAConfigGroupUpdateCount,dot11RSNAConfigPairwiseUpdateCount) */ 15 #define RSNA_MAX_EAPOL_RETRIES 4 16 17 struct wpa_group; 18 19 struct wpa_state_machine { 20 struct wpa_authenticator *wpa_auth; 21 struct wpa_group *group; 22 23 u8 addr[ETH_ALEN]; 24 u8 p2p_dev_addr[ETH_ALEN]; 25 u16 auth_alg; 26 27 enum { 28 WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED, 29 WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2, 30 WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART, 31 WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2, 32 WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE 33 } wpa_ptk_state; 34 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 42 bool Init; 43 bool DeauthenticationRequest; 44 bool AuthenticationRequest; 45 bool ReAuthenticationRequest; 46 bool Disconnect; 47 u16 disconnect_reason; /* specific reason code to use with Disconnect */ 48 u32 TimeoutCtr; 49 u32 GTimeoutCtr; 50 bool TimeoutEvt; 51 bool EAPOLKeyReceived; 52 bool EAPOLKeyPairwise; 53 bool EAPOLKeyRequest; 54 bool MICVerified; 55 bool GUpdateStationKeys; 56 u8 ANonce[WPA_NONCE_LEN]; 57 u8 SNonce[WPA_NONCE_LEN]; 58 u8 alt_SNonce[WPA_NONCE_LEN]; 59 u8 alt_replay_counter[WPA_REPLAY_COUNTER_LEN]; 60 u8 PMK[PMK_LEN_MAX]; 61 unsigned int pmk_len; 62 u8 pmkid[PMKID_LEN]; /* valid if pmkid_set == 1 */ 63 struct wpa_ptk PTK; 64 enum rsn_hash_alg hash_alg; 65 u8 keyidx_active; 66 bool use_ext_key_id; 67 bool PTK_valid; 68 bool pairwise_set; 69 bool tk_already_set; 70 int keycount; 71 bool Pair; 72 struct wpa_key_replay_counter { 73 u8 counter[WPA_REPLAY_COUNTER_LEN]; 74 bool valid; 75 } key_replay[RSNA_MAX_EAPOL_RETRIES], 76 prev_key_replay[RSNA_MAX_EAPOL_RETRIES]; 77 bool PInitAKeys; /* WPA only, not in IEEE 802.11i */ 78 bool PTKRequest; /* not in IEEE 802.11i state machine */ 79 bool has_GTK; 80 bool PtkGroupInit; /* init request for PTK Group state machine */ 81 82 u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */ 83 size_t last_rx_eapol_key_len; 84 85 unsigned int changed:1; 86 unsigned int in_step_loop:1; 87 unsigned int pending_deinit:1; 88 unsigned int started:1; 89 unsigned int mgmt_frame_prot:1; 90 unsigned int mfpr:1; 91 unsigned int rx_eapol_key_secure:1; 92 unsigned int update_snonce:1; 93 unsigned int alt_snonce_valid:1; 94 unsigned int waiting_radius_psk:1; 95 #ifdef CONFIG_IEEE80211R_AP 96 unsigned int ft_completed:1; 97 unsigned int pmk_r1_name_valid:1; 98 #endif /* CONFIG_IEEE80211R_AP */ 99 unsigned int is_wnmsleep:1; 100 unsigned int pmkid_set:1; 101 unsigned int spp_amsdu:1; 102 103 unsigned int ptkstart_without_success; 104 105 #ifdef CONFIG_OCV 106 int ocv_enabled; 107 #endif /* CONFIG_OCV */ 108 109 u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN]; 110 int req_replay_counter_used; 111 112 u8 *wpa_ie; 113 size_t wpa_ie_len; 114 u8 *rsnxe; 115 size_t rsnxe_len; 116 u8 *rsn_selection; 117 size_t rsn_selection_len; 118 119 enum { 120 WPA_VERSION_NO_WPA = 0 /* WPA not used */, 121 WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */, 122 WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */ 123 } wpa; 124 int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */ 125 int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */ 126 struct rsn_pmksa_cache_entry *pmksa; 127 128 u32 dot11RSNAStatsTKIPLocalMICFailures; 129 u32 dot11RSNAStatsTKIPRemoteMICFailures; 130 131 bool rsn_override; 132 bool rsn_override_2; 133 134 #ifdef CONFIG_IEEE80211R_AP 135 u8 xxkey[PMK_LEN_MAX]; /* PSK or the second 256 bits of MSK, or the 136 * first 384 bits of MSK */ 137 size_t xxkey_len; 138 u8 pmk_r1[PMK_LEN_MAX]; 139 unsigned int pmk_r1_len; 140 u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth 141 * Request */ 142 u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */ 143 size_t r0kh_id_len; 144 u8 *assoc_resp_ftie; 145 146 void (*ft_pending_cb)(void *ctx, const u8 *dst, 147 u16 auth_transaction, u16 status, 148 const u8 *ies, size_t ies_len); 149 void *ft_pending_cb_ctx; 150 struct wpabuf *ft_pending_req_ies; 151 u8 ft_pending_pull_nonce[FT_RRB_NONCE_LEN]; 152 u8 ft_pending_auth_transaction; 153 u8 ft_pending_current_ap[ETH_ALEN]; 154 int ft_pending_pull_left_retries; 155 #endif /* CONFIG_IEEE80211R_AP */ 156 157 int pending_1_of_4_timeout; 158 159 #ifdef CONFIG_P2P 160 u8 ip_addr[4]; 161 unsigned int ip_addr_bit; 162 #endif /* CONFIG_P2P */ 163 164 #ifdef CONFIG_FILS 165 u8 fils_key_auth_sta[FILS_MAX_KEY_AUTH_LEN]; 166 u8 fils_key_auth_ap[FILS_MAX_KEY_AUTH_LEN]; 167 size_t fils_key_auth_len; 168 unsigned int fils_completed:1; 169 #endif /* CONFIG_FILS */ 170 171 #ifdef CONFIG_DPP2 172 struct wpabuf *dpp_z; 173 #endif /* CONFIG_DPP2 */ 174 175 #ifdef CONFIG_TESTING_OPTIONS 176 void (*eapol_status_cb)(void *ctx1, void *ctx2); 177 void *eapol_status_cb_ctx1; 178 void *eapol_status_cb_ctx2; 179 #endif /* CONFIG_TESTING_OPTIONS */ 180 181 #ifdef CONFIG_IEEE80211BE 182 u8 peer_mld_addr[ETH_ALEN]; 183 s8 mld_assoc_link_id; 184 u8 n_mld_affiliated_links; 185 186 struct mld_link { 187 bool valid; 188 bool rejected; 189 u8 peer_addr[ETH_ALEN]; 190 191 struct wpa_authenticator *wpa_auth; 192 } mld_links[MAX_NUM_MLD_LINKS]; 193 #endif /* CONFIG_IEEE80211BE */ 194 195 bool ssid_protection; 196 197 struct wpabuf *sae_pw_id; 198 unsigned int sae_pw_id_counter; 199 }; 200 201 202 /* per group key state machine data */ 203 struct wpa_group { 204 struct wpa_group *next; 205 int vlan_id; 206 207 bool GInit; 208 int GKeyDoneStations; 209 bool GTKReKey; 210 int GTK_len; 211 int GN, GM; 212 bool GTKAuthenticator; 213 u8 Counter[WPA_NONCE_LEN]; 214 215 enum { 216 WPA_GROUP_GTK_INIT = 0, 217 WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE, 218 WPA_GROUP_FATAL_FAILURE 219 } wpa_group_state; 220 221 u8 GMK[WPA_GMK_LEN]; 222 u8 GTK[2][WPA_GTK_MAX_LEN]; 223 u8 GNonce[WPA_NONCE_LEN]; 224 bool changed; 225 bool first_sta_seen; 226 bool reject_4way_hs_for_entropy; 227 u8 IGTK[2][WPA_IGTK_MAX_LEN]; 228 u8 BIGTK[2][WPA_IGTK_MAX_LEN]; 229 int GN_igtk, GM_igtk; 230 int GN_bigtk, GM_bigtk; 231 bool bigtk_set; 232 bool bigtk_configured; 233 /* Number of references except those in struct wpa_group->next */ 234 unsigned int references; 235 unsigned int num_setup_iface; 236 }; 237 238 239 struct wpa_ft_pmk_cache; 240 241 /* per authenticator data */ 242 struct wpa_authenticator { 243 struct wpa_group *group; 244 245 unsigned int dot11RSNAStatsTKIPRemoteMICFailures; 246 u32 dot11RSNAAuthenticationSuiteSelected; 247 u32 dot11RSNAPairwiseCipherSelected; 248 u32 dot11RSNAGroupCipherSelected; 249 u8 dot11RSNAPMKIDUsed[PMKID_LEN]; 250 u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */ 251 u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */ 252 u32 dot11RSNAGroupCipherRequested; /* FIX: update */ 253 unsigned int dot11RSNATKIPCounterMeasuresInvoked; 254 unsigned int dot11RSNA4WayHandshakeFailures; 255 256 struct wpa_auth_config conf; 257 const struct wpa_auth_callbacks *cb; 258 void *cb_ctx; 259 260 u8 *wpa_ie; 261 size_t wpa_ie_len; 262 263 u8 addr[ETH_ALEN]; 264 265 struct rsn_pmksa_cache *pmksa; 266 struct wpa_ft_pmk_cache *ft_pmk_cache; 267 268 bool non_tx_beacon_prot; 269 270 #ifdef CONFIG_P2P 271 struct bitfield *ip_pool; 272 #endif /* CONFIG_P2P */ 273 274 #ifdef CONFIG_IEEE80211BE 275 /* MLD-level PMKSA cache for non-AP MLD entries only. */ 276 struct rsn_pmksa_cache *ml_pmksa; 277 bool is_ml; 278 u8 mld_addr[ETH_ALEN]; 279 u8 link_id; 280 bool primary_auth; 281 #endif /* CONFIG_IEEE80211BE */ 282 }; 283 284 285 #ifdef CONFIG_IEEE80211R_AP 286 287 #define FT_REMOTE_SEQ_BACKLOG 16 288 struct ft_remote_seq_rx { 289 u32 dom; 290 struct os_reltime time_offset; /* local time - offset = remote time */ 291 292 /* accepted sequence numbers: (offset ... offset + 0x40000000] 293 * (except those in last) 294 * dropped sequence numbers: (offset - 0x40000000 ... offset] 295 * all others trigger SEQ_REQ message (except first message) 296 */ 297 u32 last[FT_REMOTE_SEQ_BACKLOG]; 298 unsigned int num_last; 299 u32 offsetidx; 300 301 struct dl_list queue; /* send nonces + rrb msgs awaiting seq resp */ 302 }; 303 304 struct ft_remote_seq_tx { 305 u32 dom; /* non zero if initialized */ 306 u32 seq; 307 }; 308 309 struct ft_remote_seq { 310 struct ft_remote_seq_rx rx; 311 struct ft_remote_seq_tx tx; 312 }; 313 314 #endif /* CONFIG_IEEE80211R_AP */ 315 316 317 int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len, 318 const u8 *pmkid); 319 int wpa_write_rsnxe(struct wpa_auth_config *conf, u8 *buf, size_t len); 320 void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr, 321 logger_level level, const char *txt); 322 void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr, 323 logger_level level, const char *fmt, ...) 324 PRINTF_FORMAT(4, 5); 325 void __wpa_send_eapol(struct wpa_authenticator *wpa_auth, 326 struct wpa_state_machine *sm, int key_info, 327 const u8 *key_rsc, const u8 *nonce, 328 const u8 *kde, size_t kde_len, 329 int keyidx, int encr, int force_version); 330 int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth, 331 int (*cb)(struct wpa_state_machine *sm, void *ctx), 332 void *cb_ctx); 333 int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth, 334 int (*cb)(struct wpa_authenticator *a, void *ctx), 335 void *cb_ctx); 336 void wpa_auth_store_ptksa(struct wpa_authenticator *wpa_auth, 337 const u8 *addr, int cipher, 338 u32 life_time, const struct wpa_ptk *ptk); 339 340 #ifdef CONFIG_IEEE80211R_AP 341 int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len); 342 int wpa_write_ftie(struct wpa_auth_config *conf, int key_mgmt, size_t key_len, 343 const u8 *r0kh_id, size_t r0kh_id_len, 344 const u8 *anonce, const u8 *snonce, 345 u8 *buf, size_t len, const u8 *subelem, 346 size_t subelem_len, int rsnxe_used); 347 int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, struct wpa_ptk *ptk, 348 u8 *pmk_r0, u8 *pmk_r1, u8 *pmk_r0_name, 349 size_t *key_len, size_t kdk_len); 350 void wpa_auth_ft_store_keys(struct wpa_state_machine *sm, const u8 *pmk_r0, 351 const u8 *pmk_r1, const u8 *pmk_r0_name, 352 size_t key_len); 353 struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void); 354 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache); 355 void wpa_ft_install_ptk(struct wpa_state_machine *sm, int retry); 356 int wpa_ft_store_pmk_fils(struct wpa_state_machine *sm, const u8 *pmk_r0, 357 const u8 *pmk_r0_name); 358 #endif /* CONFIG_IEEE80211R_AP */ 359 360 #endif /* WPA_AUTH_I_H */ 361