1 /*
2  * wpa_supplicant - WPA definitions
3  * Copyright (c) 2003-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_H
10 #define WPA_H
11 
12 #include "sdkconfig.h"
13 #include "utils/common.h"
14 #include "utils/includes.h"
15 #include "common/defs.h"
16 #include "common/wpa_common.h"
17 #include "esp_wifi_types.h"
18 #include "esp_wifi_crypto_types.h"
19 #include "wpa_i.h"
20 
21 struct wpa_sm;
22 extern struct wpa_sm gWpaSm;
23 
24 #define WPA_SM_STATE(_sm) ((_sm)->wpa_state)
25 
26 bool wpa_sta_is_cur_pmksa_set(void);
27 bool wpa_sta_in_4way_handshake(void);
28 bool wpa_sta_cur_pmksa_matches_akm(void);
29 
30 #define WPA_ASSERT  assert
31 
32 struct l2_ethhdr {
33     u8 h_dest[ETH_ALEN];
34     u8 h_source[ETH_ALEN];
35     be16 h_proto;
36 } STRUCT_PACKED;
37 
38 
39 void wpa_sm_set_state(enum wpa_states state);
40 
41 void wpa_set_pmk(uint8_t *pmk, size_t pmk_length, const u8 *pmkid, bool cache_pmksa);
42 
43 int wpa_michael_mic_failure(u16 isunicast);
44 
45 wifi_cipher_type_t cipher_type_map_supp_to_public(unsigned cipher);
46 
47 unsigned cipher_type_map_public_to_supp(wifi_cipher_type_t cipher);
48 
49 void wpa_sta_clear_curr_pmksa(void);
50 
51 int wpa_sm_set_key(struct install_key *sm, enum wpa_alg alg,
52         u8 *addr, int key_idx, int set_tx,
53         u8 *seq, size_t seq_len,
54         u8 *key, size_t key_len,
55         enum key_flag key_flag);
56 
57 int wpa_sm_set_ap_rsnxe(const u8 *ie, size_t len);
58 
59 int wpa_sm_set_assoc_rsnxe(struct wpa_sm *sm, const u8 *ie, size_t len);
60 
61 void wpa_sm_drop_sa(struct wpa_sm *sm);
62 
63 #ifdef CONFIG_IEEE80211R
64 
65 int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len);
66 int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie);
67 int wpa_ft_add_mdie(struct wpa_sm *sm, u8 *ies, size_t ies_len,
68 		    const u8 *mdie);
69 const u8 * wpa_sm_get_ft_md(struct wpa_sm *sm);
70 int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
71 			    int ft_action, const u8 *target_ap,
72 			    const u8 *ric_ies, size_t ric_ies_len);
73 int wpa_ft_is_completed(struct wpa_sm *sm);
74 void wpa_reset_ft_completed(struct wpa_sm *sm);
75 int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
76 				 size_t ies_len, const u8 *src_addr);
77 int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
78 			 const u8 *mdie);
79 
80 #else /* CONFIG_IEEE80211R */
81 
82 static inline int
wpa_sm_set_ft_params(struct wpa_sm * sm,const u8 * ies,size_t ies_len)83 wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len)
84 {
85 	return 0;
86 }
87 
wpa_ft_prepare_auth_request(struct wpa_sm * sm,const u8 * mdie)88 static inline int wpa_ft_prepare_auth_request(struct wpa_sm *sm,
89 					      const u8 *mdie)
90 {
91 	return 0;
92 }
93 
wpa_ft_add_mdie(struct wpa_sm * sm,u8 * ies,size_t ies_len,const u8 * mdie)94 static inline int wpa_ft_add_mdie(struct wpa_sm *sm, u8 *ies, size_t ies_len,
95 				  const u8 *mdie)
96 {
97 	return 0;
98 }
99 
100 static inline int
wpa_ft_process_response(struct wpa_sm * sm,const u8 * ies,size_t ies_len,int ft_action,const u8 * target_ap)101 wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
102 			int ft_action, const u8 *target_ap)
103 {
104 	return 0;
105 }
106 
wpa_ft_is_completed(struct wpa_sm * sm)107 static inline int wpa_ft_is_completed(struct wpa_sm *sm)
108 {
109 	return 0;
110 }
111 
wpa_reset_ft_completed(struct wpa_sm * sm)112 static inline void wpa_reset_ft_completed(struct wpa_sm *sm)
113 {
114 }
115 
116 static inline int
wpa_ft_validate_reassoc_resp(struct wpa_sm * sm,const u8 * ies,size_t ies_len,const u8 * src_addr)117 wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
118 			     const u8 *src_addr)
119 {
120 	return -1;
121 }
122 
123 #endif /* CONFIG_IEEE80211R */
124 struct wpa_sm * get_wpa_sm(void);
125 
126 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm);
127 
128 void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid);
129 
130 void wpa_sm_notify_disassoc(struct wpa_sm *sm);
131 
132 int owe_process_assoc_resp(const u8 *rsn_ie, size_t rsn_len, const uint8_t *dh_ie, size_t dh_len);
133 
134 struct wpabuf *owe_build_assoc_req(struct wpa_sm *sm, u16 group);
135 
136 #endif /* WPA_H */
137