blob: 25e44a1953d4f5a5c101dd61552e86ab9a49620d [file] [log] [blame]
Sunil Ravi99c035e2024-07-12 01:42:03 +00001/*
2 * PASN common processing
3 *
4 * Copyright (C) 2024, Qualcomm Innovation Center, Inc.
5 *
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
8 */
9
10#include "utils/includes.h"
11
12#include "utils/common.h"
13#include "common/wpa_common.h"
14#include "common/sae.h"
15#include "crypto/sha384.h"
16#include "crypto/crypto.h"
17#include "common/ieee802_11_defs.h"
18#include "pasn_common.h"
19
20
21struct pasn_data * pasn_data_init(void)
22{
23 struct pasn_data *pasn = os_zalloc(sizeof(struct pasn_data));
24
25 return pasn;
26}
27
28
29void pasn_data_deinit(struct pasn_data *pasn)
30{
Sunil Ravic0f5d412024-09-11 22:12:49 +000031 if (!pasn)
32 return;
33 os_free(pasn->rsnxe_ie);
Sunil Ravi99c035e2024-07-12 01:42:03 +000034 bin_clear_free(pasn, sizeof(struct pasn_data));
35}
36
37
38void pasn_register_callbacks(struct pasn_data *pasn, void *cb_ctx,
39 int (*send_mgmt)(void *ctx, const u8 *data,
40 size_t data_len, int noack,
41 unsigned int freq,
42 unsigned int wait),
43 int (*validate_custom_pmkid)(void *ctx,
44 const u8 *addr,
45 const u8 *pmkid))
46{
47 if (!pasn)
48 return;
49
50 pasn->cb_ctx = cb_ctx;
51 pasn->send_mgmt = send_mgmt;
52 pasn->validate_custom_pmkid = validate_custom_pmkid;
53}
54
55
56void pasn_enable_kdk_derivation(struct pasn_data *pasn)
57{
58 if (!pasn)
59 return;
60 pasn->derive_kdk = true;
61 pasn->kdk_len = WPA_KDK_MAX_LEN;
62}
63
64
65void pasn_disable_kdk_derivation(struct pasn_data *pasn)
66{
67 if (!pasn)
68 return;
69 pasn->derive_kdk = false;
70 pasn->kdk_len = 0;
71}
72
73
74void pasn_set_akmp(struct pasn_data *pasn, int akmp)
75{
76 if (!pasn)
77 return;
78 pasn->akmp = akmp;
79}
80
81
82void pasn_set_cipher(struct pasn_data *pasn, int cipher)
83{
84 if (!pasn)
85 return;
86 pasn->cipher = cipher;
87}
88
89
90void pasn_set_own_addr(struct pasn_data *pasn, const u8 *addr)
91{
92 if (!pasn || !addr)
93 return;
94 os_memcpy(pasn->own_addr, addr, ETH_ALEN);
95}
96
97
98void pasn_set_peer_addr(struct pasn_data *pasn, const u8 *addr)
99{
100 if (!pasn || !addr)
101 return;
102 os_memcpy(pasn->peer_addr, addr, ETH_ALEN);
103}
104
105
106void pasn_set_bssid(struct pasn_data *pasn, const u8 *addr)
107{
108 if (!pasn || !addr)
109 return;
110 os_memcpy(pasn->bssid, addr, ETH_ALEN);
111}
112
113
114int pasn_set_pt(struct pasn_data *pasn, struct sae_pt *pt)
115{
116 if (!pasn)
117 return -1;
118#ifdef CONFIG_SAE
119 pasn->pt = pt;
120 return 0;
121#else /* CONFIG_SAE */
122 return -1;
123#endif /* CONFIG_SAE */
124}
125
126
127void pasn_set_password(struct pasn_data *pasn, const char *password)
128{
129 if (!pasn)
130 return;
131 pasn->password = password;
132}
133
134
135void pasn_set_wpa_key_mgmt(struct pasn_data *pasn, int key_mgmt)
136{
137 if (!pasn)
138 return;
139 pasn->wpa_key_mgmt = key_mgmt;
140}
141
142
143void pasn_set_rsn_pairwise(struct pasn_data *pasn, int rsn_pairwise)
144{
145 if (!pasn)
146 return;
147 pasn->rsn_pairwise = rsn_pairwise;
148}
149
150
151void pasn_set_rsnxe_caps(struct pasn_data *pasn, u16 rsnxe_capab)
152{
153 if (!pasn)
154 return;
155 pasn->rsnxe_capab = rsnxe_capab;
156}
157
158
159void pasn_set_rsnxe_ie(struct pasn_data *pasn, const u8 *rsnxe_ie)
160{
161 if (!pasn || !rsnxe_ie)
162 return;
Sunil Ravic0f5d412024-09-11 22:12:49 +0000163 pasn->rsnxe_ie = os_memdup(rsnxe_ie, 2 + rsnxe_ie[1]);
Sunil Ravi99c035e2024-07-12 01:42:03 +0000164}
165
166
167void pasn_set_custom_pmkid(struct pasn_data *pasn, const u8 *pmkid)
168{
169 if (!pasn || !pmkid)
170 return;
171 os_memcpy(pasn->custom_pmkid, pmkid, PMKID_LEN);
172 pasn->custom_pmkid_valid = true;
173}
174
175
176int pasn_set_extra_ies(struct pasn_data *pasn, const u8 *extra_ies,
177 size_t extra_ies_len)
178{
179 if (!pasn || !extra_ies_len || !extra_ies)
180 return -1;
181
182 if (pasn->extra_ies) {
183 os_free((u8 *) pasn->extra_ies);
184 pasn->extra_ies_len = extra_ies_len;
185 }
186
187 pasn->extra_ies = os_memdup(extra_ies, extra_ies_len);
188 if (!pasn->extra_ies) {
189 wpa_printf(MSG_ERROR,
190 "PASN: Extra IEs memory allocation failed");
191 return -1;
192 }
193 pasn->extra_ies_len = extra_ies_len;
194 return 0;
195}
196
197
Sunil Ravic0f5d412024-09-11 22:12:49 +0000198void pasn_set_noauth(struct pasn_data *pasn, bool noauth)
199{
200 if (!pasn)
201 return;
202 pasn->noauth = noauth;
203}
204
205
Sunil Ravi99c035e2024-07-12 01:42:03 +0000206int pasn_get_akmp(struct pasn_data *pasn)
207{
208 if (!pasn)
209 return 0;
210 return pasn->akmp;
211}
212
213
214int pasn_get_cipher(struct pasn_data *pasn)
215{
216 if (!pasn)
217 return 0;
218 return pasn->cipher;
219}
220
221
222size_t pasn_get_pmk_len(struct pasn_data *pasn)
223{
224 if (!pasn)
225 return 0;
226 return pasn->pmk_len;
227}
228
229
230u8 * pasn_get_pmk(struct pasn_data *pasn)
231{
232 if (!pasn)
233 return NULL;
234 return pasn->pmk;
235}
236
237
238struct wpa_ptk * pasn_get_ptk(struct pasn_data *pasn)
239{
240 if (!pasn)
241 return NULL;
242 return &pasn->ptk;
243}