xref: /aosp_15_r20/external/wpa_supplicant_8/src/pasn/pasn_common.h (revision 03f9172ca588f91df233974f4258bab95191f931)
1 /*
2  * PASN info for initiator and responder
3  *
4  * Copyright (C) 2019, Intel Corporation
5  * Copyright (c) 2022, Jouni Malinen <[email protected]>
6  * Copyright (C) 2022, Qualcomm Innovation Center, Inc.
7  *
8  * This software may be distributed under the terms of the BSD license.
9  * See README for more details.
10  */
11 
12 #ifndef PASN_COMMON_H
13 #define PASN_COMMON_H
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 enum pasn_fils_state {
20 	PASN_FILS_STATE_NONE = 0,
21 	PASN_FILS_STATE_PENDING_AS,
22 	PASN_FILS_STATE_COMPLETE
23 };
24 
25 struct pasn_fils {
26 	u8 state;
27 	u8 nonce[FILS_NONCE_LEN];
28 	u8 anonce[FILS_NONCE_LEN];
29 	u8 session[FILS_SESSION_LEN];
30 	u8 erp_pmkid[PMKID_LEN];
31 	bool completed;
32 	struct wpabuf *erp_resp;
33 };
34 
35 struct pasn_data {
36 	/* External modules access below variables using setter and getter
37 	 * functions */
38 	int akmp;
39 	int cipher;
40 	u8 own_addr[ETH_ALEN];
41 	u8 peer_addr[ETH_ALEN];
42 	u8 bssid[ETH_ALEN];
43 	struct rsn_pmksa_cache *pmksa;
44 	bool derive_kdk;
45 	size_t kdk_len;
46 	void *cb_ctx;
47 
48 #ifdef CONFIG_SAE
49 	struct sae_pt *pt;
50 #endif /* CONFIG_SAE */
51 
52 	/* Responder */
53 	const char *password;
54 	int wpa_key_mgmt;
55 	int rsn_pairwise;
56 	u16 rsnxe_capab;
57 	u8 *rsnxe_ie;
58 	bool custom_pmkid_valid;
59 	u8 custom_pmkid[PMKID_LEN];
60 
61 	/*
62 	 * Extra elements to add into Authentication frames. These can be used,
63 	 * e.g., for Wi-Fi Aware use cases.
64 	 */
65 	const u8 *extra_ies;
66 	size_t extra_ies_len;
67 
68 	/* External modules do not access below variables */
69 	size_t kek_len;
70 	u16 group;
71 	bool secure_ltf;
72 	int freq;
73 
74 	u8 trans_seq;
75 	u8 status;
76 
77 	size_t pmk_len;
78 	u8 pmk[PMK_LEN_MAX];
79 	bool using_pmksa;
80 
81 	u8 hash[SHA384_MAC_LEN];
82 
83 	struct wpabuf *beacon_rsne_rsnxe;
84 	struct wpa_ptk ptk;
85 	struct crypto_ecdh *ecdh;
86 
87 	struct wpabuf *comeback;
88 	u16 comeback_after;
89 
90 #ifdef CONFIG_SAE
91 	struct sae_data sae;
92 #endif /* CONFIG_SAE */
93 
94 #ifdef CONFIG_FILS
95 	bool fils_eapol;
96 	bool fils_wd_valid;
97 	struct pasn_fils fils;
98 #endif /* CONFIG_FILS */
99 
100 #ifdef CONFIG_IEEE80211R
101 	u8 pmk_r1[PMK_LEN_MAX];
102 	size_t pmk_r1_len;
103 	u8 pmk_r1_name[WPA_PMK_NAME_LEN];
104 #endif /* CONFIG_IEEE80211R */
105 	/* Note that this pointers to RSN PMKSA cache are actually defined
106 	 * differently for the PASN initiator (using RSN Supplicant
107 	 * implementation) and PASN responser (using RSN Authenticator
108 	 * implementation). Functions cannot be mixed between those cases. */
109 	struct rsn_pmksa_cache_entry *pmksa_entry;
110 	struct eapol_sm *eapol;
111 	int fast_reauth;
112 #ifdef CONFIG_TESTING_OPTIONS
113 	int corrupt_mic;
114 #endif /* CONFIG_TESTING_OPTIONS */
115 	int network_id;
116 
117 	u8 wrapped_data_format;
118 	struct wpabuf *secret;
119 
120 	/* Responder */
121 	bool noauth; /* Whether PASN without mutual authentication is enabled */
122 	int disable_pmksa_caching;
123 	int *pasn_groups;
124 	struct wpabuf *wrapped_data;
125 	int use_anti_clogging;
126 	const u8 *rsn_ie;
127 	size_t rsn_ie_len;
128 
129 	u8 *comeback_key;
130 	struct os_reltime last_comeback_key_update;
131 	u16 comeback_idx;
132 	u16 *comeback_pending_idx;
133 
134 	/**
135 	 * send_mgmt - Function handler to transmit a Management frame
136 	 * @ctx: Callback context from cb_ctx
137 	 * @frame_buf : Frame to transmit
138 	 * @frame_len: Length of frame to transmit
139 	 * @freq: Frequency in MHz for the channel on which to transmit
140 	 * @wait_dur: How many milliseconds to wait for a response frame
141 	 * Returns: 0 on success, -1 on failure
142 	 */
143 	int (*send_mgmt)(void *ctx, const u8 *data, size_t data_len, int noack,
144 			 unsigned int freq, unsigned int wait);
145 	/**
146 	 * validate_custom_pmkid - Handler to validate vendor specific PMKID
147 	 * @ctx: Callback context from cb_ctx
148 	 * @addr : MAC address of the peer
149 	 * @pmkid: Custom PMKID
150 	 * Returns: 0 on success (valid PMKID), -1 on failure
151 	 */
152 	int (*validate_custom_pmkid)(void *ctx, const u8 *addr,
153 				     const u8 *pmkid);
154 };
155 
156 /* Initiator */
157 void wpa_pasn_reset(struct pasn_data *pasn);
158 int wpas_pasn_start(struct pasn_data *pasn, const u8 *own_addr,
159 		    const u8 *peer_addr, const u8 *bssid,
160 		    int akmp, int cipher, u16 group,
161 		    int freq, const u8 *beacon_rsne, u8 beacon_rsne_len,
162 		    const u8 *beacon_rsnxe, u8 beacon_rsnxe_len,
163 		    const struct wpabuf *comeback);
164 int wpa_pasn_verify(struct pasn_data *pasn, const u8 *own_addr,
165 		    const u8 *peer_addr, const u8 *bssid,
166 		    int akmp, int cipher, u16 group,
167 		    int freq, const u8 *beacon_rsne, u8 beacon_rsne_len,
168 		    const u8 *beacon_rsnxe, u8 beacon_rsnxe_len,
169 		    const struct wpabuf *comeback);
170 int wpa_pasn_auth_rx(struct pasn_data *pasn, const u8 *data, size_t len,
171 		     struct wpa_pasn_params_data *pasn_params);
172 int wpa_pasn_auth_tx_status(struct pasn_data *pasn,
173 			    const u8 *data, size_t data_len, u8 acked);
174 
175 /* Responder */
176 int handle_auth_pasn_1(struct pasn_data *pasn,
177 		       const u8 *own_addr, const u8 *peer_addr,
178 		       const struct ieee80211_mgmt *mgmt, size_t len,
179 		       bool reject);
180 int handle_auth_pasn_3(struct pasn_data *pasn, const u8 *own_addr,
181 		       const u8 *peer_addr,
182 		       const struct ieee80211_mgmt *mgmt, size_t len);
183 int handle_auth_pasn_resp(struct pasn_data *pasn, const u8 *own_addr,
184 			  const u8 *peer_addr,
185 			  struct rsn_pmksa_cache_entry *pmksa, u16 status);
186 
187 struct pasn_data * pasn_data_init(void);
188 void pasn_data_deinit(struct pasn_data *pasn);
189 void pasn_register_callbacks(struct pasn_data *pasn, void *cb_ctx,
190 			     int (*send_mgmt)(void *ctx, const u8 *data,
191 					      size_t data_len, int noack,
192 					      unsigned int freq,
193 					      unsigned int wait),
194 			     int (*validate_custom_pmkid)(void *ctx,
195 							  const u8 *addr,
196 							  const u8 *pmkid));
197 void pasn_enable_kdk_derivation(struct pasn_data *pasn);
198 void pasn_disable_kdk_derivation(struct pasn_data *pasn);
199 
200 void pasn_set_akmp(struct pasn_data *pasn, int akmp);
201 void pasn_set_cipher(struct pasn_data *pasn, int cipher);
202 void pasn_set_own_addr(struct pasn_data *pasn, const u8 *addr);
203 void pasn_set_peer_addr(struct pasn_data *pasn, const u8 *addr);
204 void pasn_set_bssid(struct pasn_data *pasn, const u8 *addr);
205 void pasn_set_initiator_pmksa(struct pasn_data *pasn,
206 			      struct rsn_pmksa_cache *pmksa);
207 void pasn_set_responder_pmksa(struct pasn_data *pasn,
208 			      struct rsn_pmksa_cache *pmksa);
209 int pasn_set_pt(struct pasn_data *pasn, struct sae_pt *pt);
210 struct rsn_pmksa_cache * pasn_initiator_pmksa_cache_init(void);
211 void pasn_initiator_pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
212 int pasn_initiator_pmksa_cache_add(struct rsn_pmksa_cache *pmksa,
213 				   const u8 *own_addr, const u8 *bssid, u8 *pmk,
214 				   size_t pmk_len, u8 *pmkid);
215 int pasn_initiator_pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
216 				   const u8 *bssid, u8 *pmkid, u8 *pmk,
217 				   size_t *pmk_len);
218 void pasn_initiator_pmksa_cache_remove(struct rsn_pmksa_cache *pmksa,
219 				       const u8 *bssid);
220 void pasn_initiator_pmksa_cache_flush(struct rsn_pmksa_cache *pmksa);
221 
222 /* Responder */
223 void pasn_set_noauth(struct pasn_data *pasn, bool noauth);
224 void pasn_set_password(struct pasn_data *pasn, const char *password);
225 void pasn_set_wpa_key_mgmt(struct pasn_data *pasn, int key_mgmt);
226 void pasn_set_rsn_pairwise(struct pasn_data *pasn, int rsn_pairwise);
227 void pasn_set_rsnxe_caps(struct pasn_data *pasn, u16 rsnxe_capab);
228 void pasn_set_rsnxe_ie(struct pasn_data *pasn, const u8 *rsnxe_ie);
229 void pasn_set_custom_pmkid(struct pasn_data *pasn, const u8 *pmkid);
230 int pasn_set_extra_ies(struct pasn_data *pasn, const u8 *extra_ies,
231 		       size_t extra_ies_len);
232 struct rsn_pmksa_cache * pasn_responder_pmksa_cache_init(void);
233 void pasn_responder_pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
234 int pasn_responder_pmksa_cache_add(struct rsn_pmksa_cache *pmksa,
235 				   const u8 *own_addr, const u8 *bssid, u8 *pmk,
236 				   size_t pmk_len, u8 *pmkid);
237 int pasn_responder_pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
238 				   const u8 *bssid, u8 *pmkid, u8 *pmk,
239 				   size_t *pmk_len);
240 void pasn_responder_pmksa_cache_remove(struct rsn_pmksa_cache *pmksa,
241 				       const u8 *bssid);
242 void pasn_responder_pmksa_cache_flush(struct rsn_pmksa_cache *pmksa);
243 
244 int pasn_get_akmp(struct pasn_data *pasn);
245 int pasn_get_cipher(struct pasn_data *pasn);
246 size_t pasn_get_pmk_len(struct pasn_data *pasn);
247 u8 * pasn_get_pmk(struct pasn_data *pasn);
248 struct wpa_ptk * pasn_get_ptk(struct pasn_data *pasn);
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif /* PASN_COMMON_H */
254