1214501Srpaulo/* 2214501Srpaulo * hostapd - IEEE 802.11i-2004 / WPA Authenticator: Internal definitions 3214501Srpaulo * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi> 4214501Srpaulo * 5252726Srpaulo * This software may be distributed under the terms of the BSD license. 6252726Srpaulo * See README for more details. 7214501Srpaulo */ 8214501Srpaulo 9214501Srpaulo#ifndef WPA_AUTH_I_H 10214501Srpaulo#define WPA_AUTH_I_H 11214501Srpaulo 12214501Srpaulo/* max(dot11RSNAConfigGroupUpdateCount,dot11RSNAConfigPairwiseUpdateCount) */ 13214501Srpaulo#define RSNA_MAX_EAPOL_RETRIES 4 14214501Srpaulo 15214501Srpaulostruct wpa_group; 16214501Srpaulo 17214501Srpaulostruct wpa_stsl_negotiation { 18214501Srpaulo struct wpa_stsl_negotiation *next; 19214501Srpaulo u8 initiator[ETH_ALEN]; 20214501Srpaulo u8 peer[ETH_ALEN]; 21214501Srpaulo}; 22214501Srpaulo 23214501Srpaulo 24214501Srpaulostruct wpa_state_machine { 25214501Srpaulo struct wpa_authenticator *wpa_auth; 26214501Srpaulo struct wpa_group *group; 27214501Srpaulo 28214501Srpaulo u8 addr[ETH_ALEN]; 29214501Srpaulo 30214501Srpaulo enum { 31214501Srpaulo WPA_PTK_INITIALIZE, WPA_PTK_DISCONNECT, WPA_PTK_DISCONNECTED, 32214501Srpaulo WPA_PTK_AUTHENTICATION, WPA_PTK_AUTHENTICATION2, 33214501Srpaulo WPA_PTK_INITPMK, WPA_PTK_INITPSK, WPA_PTK_PTKSTART, 34214501Srpaulo WPA_PTK_PTKCALCNEGOTIATING, WPA_PTK_PTKCALCNEGOTIATING2, 35214501Srpaulo WPA_PTK_PTKINITNEGOTIATING, WPA_PTK_PTKINITDONE 36214501Srpaulo } wpa_ptk_state; 37214501Srpaulo 38214501Srpaulo enum { 39214501Srpaulo WPA_PTK_GROUP_IDLE = 0, 40214501Srpaulo WPA_PTK_GROUP_REKEYNEGOTIATING, 41214501Srpaulo WPA_PTK_GROUP_REKEYESTABLISHED, 42214501Srpaulo WPA_PTK_GROUP_KEYERROR 43214501Srpaulo } wpa_ptk_group_state; 44214501Srpaulo 45214501Srpaulo Boolean Init; 46214501Srpaulo Boolean DeauthenticationRequest; 47214501Srpaulo Boolean AuthenticationRequest; 48214501Srpaulo Boolean ReAuthenticationRequest; 49214501Srpaulo Boolean Disconnect; 50214501Srpaulo int TimeoutCtr; 51214501Srpaulo int GTimeoutCtr; 52214501Srpaulo Boolean TimeoutEvt; 53214501Srpaulo Boolean EAPOLKeyReceived; 54214501Srpaulo Boolean EAPOLKeyPairwise; 55214501Srpaulo Boolean EAPOLKeyRequest; 56214501Srpaulo Boolean MICVerified; 57214501Srpaulo Boolean GUpdateStationKeys; 58214501Srpaulo u8 ANonce[WPA_NONCE_LEN]; 59214501Srpaulo u8 SNonce[WPA_NONCE_LEN]; 60214501Srpaulo u8 PMK[PMK_LEN]; 61214501Srpaulo struct wpa_ptk PTK; 62214501Srpaulo Boolean PTK_valid; 63214501Srpaulo Boolean pairwise_set; 64324740Sgordon Boolean tk_already_set; 65214501Srpaulo int keycount; 66214501Srpaulo Boolean Pair; 67252726Srpaulo struct wpa_key_replay_counter { 68214501Srpaulo u8 counter[WPA_REPLAY_COUNTER_LEN]; 69214501Srpaulo Boolean valid; 70252726Srpaulo } key_replay[RSNA_MAX_EAPOL_RETRIES], 71252726Srpaulo prev_key_replay[RSNA_MAX_EAPOL_RETRIES]; 72214501Srpaulo Boolean PInitAKeys; /* WPA only, not in IEEE 802.11i */ 73214501Srpaulo Boolean PTKRequest; /* not in IEEE 802.11i state machine */ 74214501Srpaulo Boolean has_GTK; 75214501Srpaulo Boolean PtkGroupInit; /* init request for PTK Group state machine */ 76214501Srpaulo 77214501Srpaulo u8 *last_rx_eapol_key; /* starting from IEEE 802.1X header */ 78214501Srpaulo size_t last_rx_eapol_key_len; 79214501Srpaulo 80214501Srpaulo unsigned int changed:1; 81214501Srpaulo unsigned int in_step_loop:1; 82214501Srpaulo unsigned int pending_deinit:1; 83214501Srpaulo unsigned int started:1; 84214501Srpaulo unsigned int mgmt_frame_prot:1; 85252726Srpaulo unsigned int rx_eapol_key_secure:1; 86252726Srpaulo unsigned int update_snonce:1; 87214501Srpaulo#ifdef CONFIG_IEEE80211R 88214501Srpaulo unsigned int ft_completed:1; 89214501Srpaulo unsigned int pmk_r1_name_valid:1; 90214501Srpaulo#endif /* CONFIG_IEEE80211R */ 91252726Srpaulo unsigned int is_wnmsleep:1; 92214501Srpaulo 93214501Srpaulo u8 req_replay_counter[WPA_REPLAY_COUNTER_LEN]; 94214501Srpaulo int req_replay_counter_used; 95214501Srpaulo 96214501Srpaulo u8 *wpa_ie; 97214501Srpaulo size_t wpa_ie_len; 98214501Srpaulo 99214501Srpaulo enum { 100214501Srpaulo WPA_VERSION_NO_WPA = 0 /* WPA not used */, 101214501Srpaulo WPA_VERSION_WPA = 1 /* WPA / IEEE 802.11i/D3.0 */, 102214501Srpaulo WPA_VERSION_WPA2 = 2 /* WPA2 / IEEE 802.11i */ 103214501Srpaulo } wpa; 104214501Srpaulo int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */ 105214501Srpaulo int wpa_key_mgmt; /* the selected WPA_KEY_MGMT_* */ 106214501Srpaulo struct rsn_pmksa_cache_entry *pmksa; 107214501Srpaulo 108214501Srpaulo u32 dot11RSNAStatsTKIPLocalMICFailures; 109214501Srpaulo u32 dot11RSNAStatsTKIPRemoteMICFailures; 110214501Srpaulo 111214501Srpaulo#ifdef CONFIG_IEEE80211R 112214501Srpaulo u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */ 113214501Srpaulo size_t xxkey_len; 114214501Srpaulo u8 pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name derived from FT Auth 115214501Srpaulo * Request */ 116214501Srpaulo u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; /* R0KH-ID from FT Auth Request */ 117214501Srpaulo size_t r0kh_id_len; 118214501Srpaulo u8 sup_pmk_r1_name[WPA_PMK_NAME_LEN]; /* PMKR1Name from EAPOL-Key 119214501Srpaulo * message 2/4 */ 120214501Srpaulo u8 *assoc_resp_ftie; 121214501Srpaulo#endif /* CONFIG_IEEE80211R */ 122252726Srpaulo 123252726Srpaulo int pending_1_of_4_timeout; 124214501Srpaulo}; 125214501Srpaulo 126214501Srpaulo 127214501Srpaulo/* per group key state machine data */ 128214501Srpaulostruct wpa_group { 129214501Srpaulo struct wpa_group *next; 130214501Srpaulo int vlan_id; 131214501Srpaulo 132214501Srpaulo Boolean GInit; 133214501Srpaulo int GKeyDoneStations; 134214501Srpaulo Boolean GTKReKey; 135214501Srpaulo int GTK_len; 136214501Srpaulo int GN, GM; 137214501Srpaulo Boolean GTKAuthenticator; 138214501Srpaulo u8 Counter[WPA_NONCE_LEN]; 139214501Srpaulo 140214501Srpaulo enum { 141214501Srpaulo WPA_GROUP_GTK_INIT = 0, 142214501Srpaulo WPA_GROUP_SETKEYS, WPA_GROUP_SETKEYSDONE 143214501Srpaulo } wpa_group_state; 144214501Srpaulo 145214501Srpaulo u8 GMK[WPA_GMK_LEN]; 146214501Srpaulo u8 GTK[2][WPA_GTK_MAX_LEN]; 147214501Srpaulo u8 GNonce[WPA_NONCE_LEN]; 148214501Srpaulo Boolean changed; 149252726Srpaulo Boolean first_sta_seen; 150252726Srpaulo Boolean reject_4way_hs_for_entropy; 151214501Srpaulo#ifdef CONFIG_IEEE80211W 152214501Srpaulo u8 IGTK[2][WPA_IGTK_LEN]; 153214501Srpaulo int GN_igtk, GM_igtk; 154214501Srpaulo#endif /* CONFIG_IEEE80211W */ 155214501Srpaulo}; 156214501Srpaulo 157214501Srpaulo 158214501Srpaulostruct wpa_ft_pmk_cache; 159214501Srpaulo 160214501Srpaulo/* per authenticator data */ 161214501Srpaulostruct wpa_authenticator { 162214501Srpaulo struct wpa_group *group; 163214501Srpaulo 164214501Srpaulo unsigned int dot11RSNAStatsTKIPRemoteMICFailures; 165214501Srpaulo u32 dot11RSNAAuthenticationSuiteSelected; 166214501Srpaulo u32 dot11RSNAPairwiseCipherSelected; 167214501Srpaulo u32 dot11RSNAGroupCipherSelected; 168214501Srpaulo u8 dot11RSNAPMKIDUsed[PMKID_LEN]; 169214501Srpaulo u32 dot11RSNAAuthenticationSuiteRequested; /* FIX: update */ 170214501Srpaulo u32 dot11RSNAPairwiseCipherRequested; /* FIX: update */ 171214501Srpaulo u32 dot11RSNAGroupCipherRequested; /* FIX: update */ 172214501Srpaulo unsigned int dot11RSNATKIPCounterMeasuresInvoked; 173214501Srpaulo unsigned int dot11RSNA4WayHandshakeFailures; 174214501Srpaulo 175214501Srpaulo struct wpa_stsl_negotiation *stsl_negotiations; 176214501Srpaulo 177214501Srpaulo struct wpa_auth_config conf; 178214501Srpaulo struct wpa_auth_callbacks cb; 179214501Srpaulo 180214501Srpaulo u8 *wpa_ie; 181214501Srpaulo size_t wpa_ie_len; 182214501Srpaulo 183214501Srpaulo u8 addr[ETH_ALEN]; 184214501Srpaulo 185214501Srpaulo struct rsn_pmksa_cache *pmksa; 186214501Srpaulo struct wpa_ft_pmk_cache *ft_pmk_cache; 187214501Srpaulo}; 188214501Srpaulo 189214501Srpaulo 190214501Srpauloint wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len, 191214501Srpaulo const u8 *pmkid); 192214501Srpaulovoid wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr, 193214501Srpaulo logger_level level, const char *txt); 194214501Srpaulovoid wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr, 195214501Srpaulo logger_level level, const char *fmt, ...); 196214501Srpaulovoid __wpa_send_eapol(struct wpa_authenticator *wpa_auth, 197214501Srpaulo struct wpa_state_machine *sm, int key_info, 198214501Srpaulo const u8 *key_rsc, const u8 *nonce, 199214501Srpaulo const u8 *kde, size_t kde_len, 200214501Srpaulo int keyidx, int encr, int force_version); 201214501Srpauloint wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth, 202214501Srpaulo int (*cb)(struct wpa_state_machine *sm, void *ctx), 203214501Srpaulo void *cb_ctx); 204214501Srpauloint wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth, 205214501Srpaulo int (*cb)(struct wpa_authenticator *a, void *ctx), 206214501Srpaulo void *cb_ctx); 207214501Srpaulo 208214501Srpaulo#ifdef CONFIG_PEERKEY 209214501Srpauloint wpa_stsl_remove(struct wpa_authenticator *wpa_auth, 210214501Srpaulo struct wpa_stsl_negotiation *neg); 211214501Srpaulovoid wpa_smk_error(struct wpa_authenticator *wpa_auth, 212214501Srpaulo struct wpa_state_machine *sm, struct wpa_eapol_key *key); 213214501Srpaulovoid wpa_smk_m1(struct wpa_authenticator *wpa_auth, 214214501Srpaulo struct wpa_state_machine *sm, struct wpa_eapol_key *key); 215214501Srpaulovoid wpa_smk_m3(struct wpa_authenticator *wpa_auth, 216214501Srpaulo struct wpa_state_machine *sm, struct wpa_eapol_key *key); 217214501Srpaulo#endif /* CONFIG_PEERKEY */ 218214501Srpaulo 219214501Srpaulo#ifdef CONFIG_IEEE80211R 220214501Srpauloint wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len); 221214501Srpauloint wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id, 222214501Srpaulo size_t r0kh_id_len, 223214501Srpaulo const u8 *anonce, const u8 *snonce, 224214501Srpaulo u8 *buf, size_t len, const u8 *subelem, 225214501Srpaulo size_t subelem_len); 226214501Srpauloint wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk, 227214501Srpaulo struct wpa_ptk *ptk, size_t ptk_len); 228214501Srpaulostruct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void); 229214501Srpaulovoid wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache); 230214501Srpaulovoid wpa_ft_install_ptk(struct wpa_state_machine *sm); 231214501Srpaulo#endif /* CONFIG_IEEE80211R */ 232214501Srpaulo 233214501Srpaulo#endif /* WPA_AUTH_I_H */ 234