wpa_i.h revision 351611
138032Speter/* 238032Speter * Internal WPA/RSN supplicant state machine definitions 338032Speter * Copyright (c) 2004-2018, Jouni Malinen <j@w1.fi> 438032Speter * 538032Speter * This software may be distributed under the terms of the BSD license. 690792Sgshapiro * See README for more details. 738032Speter */ 864562Sgshapiro 938032Speter#ifndef WPA_I_H 1038032Speter#define WPA_I_H 1138032Speter 1238032Speter#include "utils/list.h" 1338032Speter 1438032Speterstruct wpa_tdls_peer; 1566494Sgshapirostruct wpa_eapol_key; 1638032Speter 1766494Sgshapiro/** 1866494Sgshapiro * struct wpa_sm - Internal WPA state machine data 1966494Sgshapiro */ 2066494Sgshapirostruct wpa_sm { 2166494Sgshapiro u8 pmk[PMK_LEN_MAX]; 2266494Sgshapiro size_t pmk_len; 2366494Sgshapiro struct wpa_ptk ptk, tptk; 2466494Sgshapiro int ptk_set, tptk_set; 2566494Sgshapiro unsigned int msg_3_of_4_ok:1; 2666494Sgshapiro u8 snonce[WPA_NONCE_LEN]; 2766494Sgshapiro u8 anonce[WPA_NONCE_LEN]; /* ANonce from the last 1/4 msg */ 2866494Sgshapiro int renew_snonce; 2938032Speter u8 rx_replay_counter[WPA_REPLAY_COUNTER_LEN]; 3038032Speter int rx_replay_counter_set; 3138032Speter u8 request_counter[WPA_REPLAY_COUNTER_LEN]; 32168515Sgshapiro struct wpa_gtk gtk; 33168515Sgshapiro struct wpa_gtk gtk_wnm_sleep; 34168515Sgshapiro#ifdef CONFIG_IEEE80211W 35168515Sgshapiro struct wpa_igtk igtk; 3638032Speter struct wpa_igtk igtk_wnm_sleep; 3790792Sgshapiro#endif /* CONFIG_IEEE80211W */ 3880785Sgshapiro 3980785Sgshapiro struct eapol_sm *eapol; /* EAPOL state machine from upper level code */ 4080785Sgshapiro 4180785Sgshapiro struct rsn_pmksa_cache *pmksa; /* PMKSA cache */ 4280785Sgshapiro struct rsn_pmksa_cache_entry *cur_pmksa; /* current PMKSA entry */ 4380785Sgshapiro struct dl_list pmksa_candidates; 44141858Sgshapiro 45141858Sgshapiro struct l2_packet_data *l2_preauth; 46141858Sgshapiro struct l2_packet_data *l2_preauth_br; 47141858Sgshapiro struct l2_packet_data *l2_tdls; 48141858Sgshapiro u8 preauth_bssid[ETH_ALEN]; /* current RSN pre-auth peer or 49141858Sgshapiro * 00:00:00:00:00:00 if no pre-auth is 50182352Sgshapiro * in progress */ 51182352Sgshapiro struct eapol_sm *preauth_eapol; 52182352Sgshapiro 53182352Sgshapiro struct wpa_sm_ctx *ctx; 54182352Sgshapiro 55182352Sgshapiro void *scard_ctx; /* context for smartcard callbacks */ 56182352Sgshapiro int fast_reauth; /* whether EAP fast re-authentication is enabled */ 57182352Sgshapiro 58182352Sgshapiro void *network_ctx; 59182352Sgshapiro int allowed_pairwise_cipher; /* bitfield of WPA_CIPHER_* */ 60182352Sgshapiro int proactive_key_caching; 6194334Sgshapiro int eap_workaround; 6294334Sgshapiro void *eap_conf_ctx; 6394334Sgshapiro u8 ssid[32]; 6494334Sgshapiro size_t ssid_len; 6594334Sgshapiro int wpa_ptk_rekey; 6694334Sgshapiro int p2p; 6794334Sgshapiro int wpa_rsc_relaxation; 6894334Sgshapiro 6994334Sgshapiro u8 own_addr[ETH_ALEN]; 7094334Sgshapiro const char *ifname; 7194334Sgshapiro const char *bridge_ifname; 7294334Sgshapiro u8 bssid[ETH_ALEN]; 7394334Sgshapiro 7494334Sgshapiro unsigned int dot11RSNAConfigPMKLifetime; 7594334Sgshapiro unsigned int dot11RSNAConfigPMKReauthThreshold; 7694334Sgshapiro unsigned int dot11RSNAConfigSATimeout; 7794334Sgshapiro 7894334Sgshapiro unsigned int dot11RSNA4WayHandshakeFailures; 7994334Sgshapiro 8038032Speter /* Selected configuration (based on Beacon/ProbeResp WPA IE) */ 8138032Speter unsigned int proto; 8238032Speter unsigned int pairwise_cipher; 8338032Speter unsigned int group_cipher; 8438032Speter unsigned int key_mgmt; 8590792Sgshapiro unsigned int mgmt_group_cipher; 8638032Speter 8790792Sgshapiro int rsn_enabled; /* Whether RSN is enabled in configuration */ 8890792Sgshapiro int mfp; /* 0 = disabled, 1 = optional, 2 = mandatory */ 8990792Sgshapiro int ocv; /* Operating Channel Validation */ 9090792Sgshapiro 9138032Speter u8 *assoc_wpa_ie; /* Own WPA/RSN IE from (Re)AssocReq */ 9238032Speter size_t assoc_wpa_ie_len; 9338032Speter u8 *ap_wpa_ie, *ap_rsn_ie; 9438032Speter size_t ap_wpa_ie_len, ap_rsn_ie_len; 9538032Speter 9638032Speter#ifdef CONFIG_TDLS 9738032Speter struct wpa_tdls_peer *tdls; 9838032Speter int tdls_prohibited; 9938032Speter int tdls_chan_switch_prohibited; 10038032Speter int tdls_disabled; 10138032Speter 10238032Speter /* The driver supports TDLS */ 10338032Speter int tdls_supported; 10438032Speter 10538032Speter /* 10638032Speter * The driver requires explicit discovery/setup/teardown frames sent 10738032Speter * to it via tdls_mgmt. 10838032Speter */ 10938032Speter int tdls_external_setup; 11038032Speter 11138032Speter /* The driver supports TDLS channel switching */ 11238032Speter int tdls_chan_switch; 11338032Speter#endif /* CONFIG_TDLS */ 11438032Speter 11538032Speter#ifdef CONFIG_IEEE80211R 11638032Speter u8 xxkey[PMK_LEN_MAX]; /* PSK or the second 256 bits of MSK, or the 11742575Speter * first 384 bits of MSK */ 11842575Speter size_t xxkey_len; 11938032Speter u8 pmk_r0[PMK_LEN_MAX]; 12038032Speter size_t pmk_r0_len; 12138032Speter u8 pmk_r0_name[WPA_PMK_NAME_LEN]; 12238032Speter u8 pmk_r1[PMK_LEN_MAX]; 12338032Speter size_t pmk_r1_len; 12438032Speter u8 pmk_r1_name[WPA_PMK_NAME_LEN]; 12538032Speter u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN]; 12638032Speter u8 r0kh_id[FT_R0KH_ID_MAX_LEN]; 12738032Speter size_t r0kh_id_len; 12838032Speter u8 r1kh_id[FT_R1KH_ID_LEN]; 12938032Speter unsigned int ft_completed:1; 13038032Speter unsigned int ft_reassoc_completed:1; 13138032Speter unsigned int ft_protocol:1; 13238032Speter int over_the_ds_in_progress; 13338032Speter u8 target_ap[ETH_ALEN]; /* over-the-DS target AP */ 13438032Speter int set_ptk_after_assoc; 13538032Speter u8 mdie_ft_capab; /* FT Capability and Policy from target AP MDIE */ 13638032Speter u8 *assoc_resp_ies; /* MDIE and FTIE from (Re)Association Response */ 13738032Speter size_t assoc_resp_ies_len; 13838032Speter#endif /* CONFIG_IEEE80211R */ 13938032Speter 14038032Speter#ifdef CONFIG_P2P 14138032Speter u8 p2p_ip_addr[3 * 4]; 14238032Speter#endif /* CONFIG_P2P */ 14338032Speter 14438032Speter#ifdef CONFIG_TESTING_OPTIONS 14538032Speter struct wpabuf *test_assoc_ie; 14638032Speter#endif /* CONFIG_TESTING_OPTIONS */ 14738032Speter 14838032Speter#ifdef CONFIG_FILS 14938032Speter u8 fils_nonce[FILS_NONCE_LEN]; 15038032Speter u8 fils_session[FILS_SESSION_LEN]; 15138032Speter u8 fils_anonce[FILS_NONCE_LEN]; 15238032Speter u8 fils_key_auth_ap[FILS_MAX_KEY_AUTH_LEN]; 15338032Speter u8 fils_key_auth_sta[FILS_MAX_KEY_AUTH_LEN]; 15438032Speter size_t fils_key_auth_len; 15538032Speter unsigned int fils_completed:1; 15638032Speter unsigned int fils_erp_pmkid_set:1; 15738032Speter unsigned int fils_cache_id_set:1; 15890792Sgshapiro u8 fils_erp_pmkid[PMKID_LEN]; 15990792Sgshapiro u8 fils_cache_id[FILS_CACHE_ID_LEN]; 16090792Sgshapiro struct crypto_ecdh *fils_ecdh; 16190792Sgshapiro int fils_dh_group; 16290792Sgshapiro size_t fils_dh_elem_len; 16390792Sgshapiro struct wpabuf *fils_ft_ies; 16490792Sgshapiro u8 fils_ft[FILS_FT_MAX_LEN]; 16590792Sgshapiro size_t fils_ft_len; 16638032Speter#endif /* CONFIG_FILS */ 16738032Speter 16838032Speter#ifdef CONFIG_OWE 16938032Speter struct crypto_ecdh *owe_ecdh; 17038032Speter u16 owe_group; 17138032Speter#endif /* CONFIG_OWE */ 17238032Speter 17338032Speter#ifdef CONFIG_DPP2 17438032Speter struct wpabuf *dpp_z; 17538032Speter#endif /* CONFIG_DPP2 */ 17638032Speter}; 17738032Speter 17838032Speter 17938032Speterstatic inline void wpa_sm_set_state(struct wpa_sm *sm, enum wpa_states state) 18038032Speter{ 18138032Speter WPA_ASSERT(sm->ctx->set_state); 18238032Speter sm->ctx->set_state(sm->ctx->ctx, state); 18338032Speter} 184168515Sgshapiro 18538032Speterstatic inline enum wpa_states wpa_sm_get_state(struct wpa_sm *sm) 18638032Speter{ 18738032Speter WPA_ASSERT(sm->ctx->get_state); 18838032Speter return sm->ctx->get_state(sm->ctx->ctx); 18938032Speter} 19038032Speter 19138032Speterstatic inline void wpa_sm_deauthenticate(struct wpa_sm *sm, u16 reason_code) 19238032Speter{ 19338032Speter WPA_ASSERT(sm->ctx->deauthenticate); 19464562Sgshapiro sm->ctx->deauthenticate(sm->ctx->ctx, reason_code); 19590792Sgshapiro} 19664562Sgshapiro 19764562Sgshapirostatic inline int wpa_sm_set_key(struct wpa_sm *sm, enum wpa_alg alg, 19838032Speter const u8 *addr, int key_idx, int set_tx, 19938032Speter const u8 *seq, size_t seq_len, 20038032Speter const u8 *key, size_t key_len) 20138032Speter{ 20242575Speter WPA_ASSERT(sm->ctx->set_key); 20338032Speter return sm->ctx->set_key(sm->ctx->ctx, alg, addr, key_idx, set_tx, 20442575Speter seq, seq_len, key, key_len); 20542575Speter} 20642575Speter 20742575Speterstatic inline void * wpa_sm_get_network_ctx(struct wpa_sm *sm) 20842575Speter{ 20943730Speter WPA_ASSERT(sm->ctx->get_network_ctx); 21042575Speter return sm->ctx->get_network_ctx(sm->ctx->ctx); 21143730Speter} 21243730Speter 21343730Speterstatic inline int wpa_sm_get_bssid(struct wpa_sm *sm, u8 *bssid) 21443730Speter{ 21543730Speter WPA_ASSERT(sm->ctx->get_bssid); 21643730Speter return sm->ctx->get_bssid(sm->ctx->ctx, bssid); 21764562Sgshapiro} 21843730Speter 21943730Speterstatic inline int wpa_sm_ether_send(struct wpa_sm *sm, const u8 *dest, 22043730Speter u16 proto, const u8 *buf, size_t len) 22143730Speter{ 22243730Speter WPA_ASSERT(sm->ctx->ether_send); 22343730Speter return sm->ctx->ether_send(sm->ctx->ctx, dest, proto, buf, len); 22443730Speter} 22543730Speter 22643730Speterstatic inline int wpa_sm_get_beacon_ie(struct wpa_sm *sm) 22743730Speter{ 22843730Speter WPA_ASSERT(sm->ctx->get_beacon_ie); 22943730Speter return sm->ctx->get_beacon_ie(sm->ctx->ctx); 23043730Speter} 23143730Speter 23243730Speterstatic inline void wpa_sm_cancel_auth_timeout(struct wpa_sm *sm) 23364562Sgshapiro{ 23464562Sgshapiro WPA_ASSERT(sm->ctx->cancel_auth_timeout); 23564562Sgshapiro sm->ctx->cancel_auth_timeout(sm->ctx->ctx); 23643730Speter} 23743730Speter 23843730Speterstatic inline u8 * wpa_sm_alloc_eapol(struct wpa_sm *sm, u8 type, 23943730Speter const void *data, u16 data_len, 24043730Speter size_t *msg_len, void **data_pos) 24143730Speter{ 24243730Speter WPA_ASSERT(sm->ctx->alloc_eapol); 24343730Speter return sm->ctx->alloc_eapol(sm->ctx->ctx, type, data, data_len, 24443730Speter msg_len, data_pos); 24590792Sgshapiro} 24664562Sgshapiro 24764562Sgshapirostatic inline int wpa_sm_add_pmkid(struct wpa_sm *sm, void *network_ctx, 24890792Sgshapiro const u8 *bssid, const u8 *pmkid, 249168515Sgshapiro const u8 *cache_id, const u8 *pmk, 25064562Sgshapiro size_t pmk_len) 251168515Sgshapiro{ 25264562Sgshapiro WPA_ASSERT(sm->ctx->add_pmkid); 25364562Sgshapiro return sm->ctx->add_pmkid(sm->ctx->ctx, network_ctx, bssid, pmkid, 25464562Sgshapiro cache_id, pmk, pmk_len); 255110560Sgshapiro} 256110560Sgshapiro 257110560Sgshapirostatic inline int wpa_sm_remove_pmkid(struct wpa_sm *sm, void *network_ctx, 258110560Sgshapiro const u8 *bssid, const u8 *pmkid, 259110560Sgshapiro const u8 *cache_id) 260110560Sgshapiro{ 261182352Sgshapiro WPA_ASSERT(sm->ctx->remove_pmkid); 262 return sm->ctx->remove_pmkid(sm->ctx->ctx, network_ctx, bssid, pmkid, 263 cache_id); 264} 265 266static inline int wpa_sm_mlme_setprotection(struct wpa_sm *sm, const u8 *addr, 267 int protect_type, int key_type) 268{ 269 WPA_ASSERT(sm->ctx->mlme_setprotection); 270 return sm->ctx->mlme_setprotection(sm->ctx->ctx, addr, protect_type, 271 key_type); 272} 273 274static inline int wpa_sm_update_ft_ies(struct wpa_sm *sm, const u8 *md, 275 const u8 *ies, size_t ies_len) 276{ 277 if (sm->ctx->update_ft_ies) 278 return sm->ctx->update_ft_ies(sm->ctx->ctx, md, ies, ies_len); 279 return -1; 280} 281 282static inline int wpa_sm_send_ft_action(struct wpa_sm *sm, u8 action, 283 const u8 *target_ap, 284 const u8 *ies, size_t ies_len) 285{ 286 if (sm->ctx->send_ft_action) 287 return sm->ctx->send_ft_action(sm->ctx->ctx, action, target_ap, 288 ies, ies_len); 289 return -1; 290} 291 292static inline int wpa_sm_mark_authenticated(struct wpa_sm *sm, 293 const u8 *target_ap) 294{ 295 if (sm->ctx->mark_authenticated) 296 return sm->ctx->mark_authenticated(sm->ctx->ctx, target_ap); 297 return -1; 298} 299 300static inline void wpa_sm_set_rekey_offload(struct wpa_sm *sm) 301{ 302 if (!sm->ctx->set_rekey_offload) 303 return; 304 sm->ctx->set_rekey_offload(sm->ctx->ctx, sm->ptk.kek, sm->ptk.kek_len, 305 sm->ptk.kck, sm->ptk.kck_len, 306 sm->rx_replay_counter); 307} 308 309#ifdef CONFIG_TDLS 310static inline int wpa_sm_tdls_get_capa(struct wpa_sm *sm, 311 int *tdls_supported, 312 int *tdls_ext_setup, 313 int *tdls_chan_switch) 314{ 315 if (sm->ctx->tdls_get_capa) 316 return sm->ctx->tdls_get_capa(sm->ctx->ctx, tdls_supported, 317 tdls_ext_setup, tdls_chan_switch); 318 return -1; 319} 320 321static inline int wpa_sm_send_tdls_mgmt(struct wpa_sm *sm, const u8 *dst, 322 u8 action_code, u8 dialog_token, 323 u16 status_code, u32 peer_capab, 324 int initiator, const u8 *buf, 325 size_t len) 326{ 327 if (sm->ctx->send_tdls_mgmt) 328 return sm->ctx->send_tdls_mgmt(sm->ctx->ctx, dst, action_code, 329 dialog_token, status_code, 330 peer_capab, initiator, buf, 331 len); 332 return -1; 333} 334 335static inline int wpa_sm_tdls_oper(struct wpa_sm *sm, int oper, 336 const u8 *peer) 337{ 338 if (sm->ctx->tdls_oper) 339 return sm->ctx->tdls_oper(sm->ctx->ctx, oper, peer); 340 return -1; 341} 342 343static inline int 344wpa_sm_tdls_peer_addset(struct wpa_sm *sm, const u8 *addr, int add, 345 u16 aid, u16 capability, const u8 *supp_rates, 346 size_t supp_rates_len, 347 const struct ieee80211_ht_capabilities *ht_capab, 348 const struct ieee80211_vht_capabilities *vht_capab, 349 u8 qosinfo, int wmm, const u8 *ext_capab, 350 size_t ext_capab_len, const u8 *supp_channels, 351 size_t supp_channels_len, const u8 *supp_oper_classes, 352 size_t supp_oper_classes_len) 353{ 354 if (sm->ctx->tdls_peer_addset) 355 return sm->ctx->tdls_peer_addset(sm->ctx->ctx, addr, add, 356 aid, capability, supp_rates, 357 supp_rates_len, ht_capab, 358 vht_capab, qosinfo, wmm, 359 ext_capab, ext_capab_len, 360 supp_channels, 361 supp_channels_len, 362 supp_oper_classes, 363 supp_oper_classes_len); 364 return -1; 365} 366 367static inline int 368wpa_sm_tdls_enable_channel_switch(struct wpa_sm *sm, const u8 *addr, 369 u8 oper_class, 370 const struct hostapd_freq_params *freq_params) 371{ 372 if (sm->ctx->tdls_enable_channel_switch) 373 return sm->ctx->tdls_enable_channel_switch(sm->ctx->ctx, addr, 374 oper_class, 375 freq_params); 376 return -1; 377} 378 379static inline int 380wpa_sm_tdls_disable_channel_switch(struct wpa_sm *sm, const u8 *addr) 381{ 382 if (sm->ctx->tdls_disable_channel_switch) 383 return sm->ctx->tdls_disable_channel_switch(sm->ctx->ctx, addr); 384 return -1; 385} 386#endif /* CONFIG_TDLS */ 387 388static inline int wpa_sm_key_mgmt_set_pmk(struct wpa_sm *sm, 389 const u8 *pmk, size_t pmk_len) 390{ 391 if (!sm->ctx->key_mgmt_set_pmk) 392 return -1; 393 return sm->ctx->key_mgmt_set_pmk(sm->ctx->ctx, pmk, pmk_len); 394} 395 396static inline void wpa_sm_fils_hlp_rx(struct wpa_sm *sm, 397 const u8 *dst, const u8 *src, 398 const u8 *pkt, size_t pkt_len) 399{ 400 if (sm->ctx->fils_hlp_rx) 401 sm->ctx->fils_hlp_rx(sm->ctx->ctx, dst, src, pkt, pkt_len); 402} 403 404static inline int wpa_sm_channel_info(struct wpa_sm *sm, 405 struct wpa_channel_info *ci) 406{ 407 if (!sm->ctx->channel_info) 408 return -1; 409 return sm->ctx->channel_info(sm->ctx->ctx, ci); 410} 411 412 413int wpa_eapol_key_send(struct wpa_sm *sm, struct wpa_ptk *ptk, 414 int ver, const u8 *dest, u16 proto, 415 u8 *msg, size_t msg_len, u8 *key_mic); 416int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst, 417 const struct wpa_eapol_key *key, 418 int ver, const u8 *nonce, 419 const u8 *wpa_ie, size_t wpa_ie_len, 420 struct wpa_ptk *ptk); 421int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst, 422 const struct wpa_eapol_key *key, 423 u16 ver, u16 key_info, 424 struct wpa_ptk *ptk); 425 426int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr, 427 const struct wpa_eapol_key *key, struct wpa_ptk *ptk); 428 429void wpa_tdls_assoc(struct wpa_sm *sm); 430void wpa_tdls_disassoc(struct wpa_sm *sm); 431 432#endif /* WPA_I_H */ 433