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