blob: 7b7c73792d8af69048acbb8413732ce7728527f0 [file] [log] [blame]
Sunil Ravi77d572f2023-01-17 23:58:31 +00001/*
2 * PASN info for initiator and responder
3 *
4 * Copyright (C) 2019, Intel Corporation
5 * Copyright (c) 2022, Jouni Malinen <j@w1.fi>
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
16extern "C" {
17#endif
18
Sunil Ravi77d572f2023-01-17 23:58:31 +000019enum pasn_fils_state {
20 PASN_FILS_STATE_NONE = 0,
21 PASN_FILS_STATE_PENDING_AS,
22 PASN_FILS_STATE_COMPLETE
23};
24
25struct 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
35struct pasn_data {
Sunil Ravi99c035e2024-07-12 01:42:03 +000036 /* External modules access below variables using setter and getter
37 * functions */
Sunil Ravi77d572f2023-01-17 23:58:31 +000038 int akmp;
39 int cipher;
Sunil Ravi99c035e2024-07-12 01:42:03 +000040 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;
Sunil Ravic0f5d412024-09-11 22:12:49 +000057 u8 *rsnxe_ie;
Sunil Ravi99c035e2024-07-12 01:42:03 +000058 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 */
Sunil Ravic0f5d412024-09-11 22:12:49 +000069 size_t kek_len;
Sunil Ravi77d572f2023-01-17 23:58:31 +000070 u16 group;
71 bool secure_ltf;
72 int freq;
Sunil Ravi77d572f2023-01-17 23:58:31 +000073
74 u8 trans_seq;
75 u8 status;
76
Sunil Ravi77d572f2023-01-17 23:58:31 +000077 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;
Sunil Ravi77d572f2023-01-17 23:58:31 +000092#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. */
Sunil Ravi77d572f2023-01-17 23:58:31 +0000109 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 */
Sunil Ravi77d572f2023-01-17 23:58:31 +0000115 int network_id;
116
117 u8 wrapped_data_format;
118 struct wpabuf *secret;
119
Sunil Ravi640215c2023-06-28 23:08:09 +0000120 /* Responder */
121 bool noauth; /* Whether PASN without mutual authentication is enabled */
Sunil Ravi77d572f2023-01-17 23:58:31 +0000122 int disable_pmksa_caching;
123 int *pasn_groups;
124 struct wpabuf *wrapped_data;
125 int use_anti_clogging;
126 const u8 *rsn_ie;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000127 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
Sunil Ravi77d572f2023-01-17 23:58:31 +0000134 /**
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 */
Sunil Ravi77d572f2023-01-17 23:58:31 +0000157void wpa_pasn_reset(struct pasn_data *pasn);
158int 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);
164int 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);
170int wpa_pasn_auth_rx(struct pasn_data *pasn, const u8 *data, size_t len,
171 struct wpa_pasn_params_data *pasn_params);
172int wpa_pasn_auth_tx_status(struct pasn_data *pasn,
173 const u8 *data, size_t data_len, u8 acked);
174
175/* Responder */
176int handle_auth_pasn_1(struct pasn_data *pasn,
177 const u8 *own_addr, const u8 *peer_addr,
Sunil Ravic0f5d412024-09-11 22:12:49 +0000178 const struct ieee80211_mgmt *mgmt, size_t len,
179 bool reject);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000180int 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);
183int 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
Sunil Ravi99c035e2024-07-12 01:42:03 +0000187struct pasn_data * pasn_data_init(void);
188void pasn_data_deinit(struct pasn_data *pasn);
189void 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));
197void pasn_enable_kdk_derivation(struct pasn_data *pasn);
198void pasn_disable_kdk_derivation(struct pasn_data *pasn);
199
200void pasn_set_akmp(struct pasn_data *pasn, int akmp);
201void pasn_set_cipher(struct pasn_data *pasn, int cipher);
202void pasn_set_own_addr(struct pasn_data *pasn, const u8 *addr);
203void pasn_set_peer_addr(struct pasn_data *pasn, const u8 *addr);
204void pasn_set_bssid(struct pasn_data *pasn, const u8 *addr);
205void pasn_set_initiator_pmksa(struct pasn_data *pasn,
206 struct rsn_pmksa_cache *pmksa);
207void pasn_set_responder_pmksa(struct pasn_data *pasn,
208 struct rsn_pmksa_cache *pmksa);
209int pasn_set_pt(struct pasn_data *pasn, struct sae_pt *pt);
Sunil Ravic0f5d412024-09-11 22:12:49 +0000210struct rsn_pmksa_cache * pasn_initiator_pmksa_cache_init(void);
211void pasn_initiator_pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
212int 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);
215int pasn_initiator_pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
216 const u8 *bssid, u8 *pmkid, u8 *pmk,
217 size_t *pmk_len);
218void pasn_initiator_pmksa_cache_remove(struct rsn_pmksa_cache *pmksa,
219 const u8 *bssid);
220void pasn_initiator_pmksa_cache_flush(struct rsn_pmksa_cache *pmksa);
Sunil Ravi99c035e2024-07-12 01:42:03 +0000221
222/* Responder */
Sunil Ravic0f5d412024-09-11 22:12:49 +0000223void pasn_set_noauth(struct pasn_data *pasn, bool noauth);
Sunil Ravi99c035e2024-07-12 01:42:03 +0000224void pasn_set_password(struct pasn_data *pasn, const char *password);
225void pasn_set_wpa_key_mgmt(struct pasn_data *pasn, int key_mgmt);
226void pasn_set_rsn_pairwise(struct pasn_data *pasn, int rsn_pairwise);
227void pasn_set_rsnxe_caps(struct pasn_data *pasn, u16 rsnxe_capab);
228void pasn_set_rsnxe_ie(struct pasn_data *pasn, const u8 *rsnxe_ie);
229void pasn_set_custom_pmkid(struct pasn_data *pasn, const u8 *pmkid);
230int pasn_set_extra_ies(struct pasn_data *pasn, const u8 *extra_ies,
231 size_t extra_ies_len);
Sunil Ravic0f5d412024-09-11 22:12:49 +0000232struct rsn_pmksa_cache * pasn_responder_pmksa_cache_init(void);
233void pasn_responder_pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
234int 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);
237int pasn_responder_pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
238 const u8 *bssid, u8 *pmkid, u8 *pmk,
239 size_t *pmk_len);
240void pasn_responder_pmksa_cache_remove(struct rsn_pmksa_cache *pmksa,
241 const u8 *bssid);
242void pasn_responder_pmksa_cache_flush(struct rsn_pmksa_cache *pmksa);
Sunil Ravi99c035e2024-07-12 01:42:03 +0000243
244int pasn_get_akmp(struct pasn_data *pasn);
245int pasn_get_cipher(struct pasn_data *pasn);
246size_t pasn_get_pmk_len(struct pasn_data *pasn);
247u8 * pasn_get_pmk(struct pasn_data *pasn);
248struct wpa_ptk * pasn_get_ptk(struct pasn_data *pasn);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000249
250#ifdef __cplusplus
251}
252#endif
253#endif /* PASN_COMMON_H */