1 // SPDX-License-Identifier: ISC
2 /*
3 * Copyright (c) 2022 Broadcom Corporation
4 */
5 #include <linux/errno.h>
6 #include <linux/types.h>
7 #include <core.h>
8 #include <bus.h>
9 #include <fwvid.h>
10 #include <fwil.h>
11
12 #include "vops.h"
13
14 #define BRCMF_CYW_E_LAST 197
15
brcmf_cyw_set_sae_pwd(struct brcmf_if * ifp,struct cfg80211_crypto_settings * crypto)16 static int brcmf_cyw_set_sae_pwd(struct brcmf_if *ifp,
17 struct cfg80211_crypto_settings *crypto)
18 {
19 struct brcmf_pub *drvr = ifp->drvr;
20 struct brcmf_wsec_sae_pwd_le sae_pwd;
21 u16 pwd_len = crypto->sae_pwd_len;
22 int err;
23
24 if (pwd_len > BRCMF_WSEC_MAX_SAE_PASSWORD_LEN) {
25 bphy_err(drvr, "sae_password must be less than %d\n",
26 BRCMF_WSEC_MAX_SAE_PASSWORD_LEN);
27 return -EINVAL;
28 }
29
30 sae_pwd.key_len = cpu_to_le16(pwd_len);
31 memcpy(sae_pwd.key, crypto->sae_pwd, pwd_len);
32
33 err = brcmf_fil_iovar_data_set(ifp, "sae_password", &sae_pwd,
34 sizeof(sae_pwd));
35 if (err < 0)
36 bphy_err(drvr, "failed to set SAE password in firmware (len=%u)\n",
37 pwd_len);
38
39 return err;
40 }
41
brcmf_cyw_alloc_fweh_info(struct brcmf_pub * drvr)42 static int brcmf_cyw_alloc_fweh_info(struct brcmf_pub *drvr)
43 {
44 struct brcmf_fweh_info *fweh;
45
46 fweh = kzalloc(struct_size(fweh, evt_handler, BRCMF_CYW_E_LAST),
47 GFP_KERNEL);
48 if (!fweh)
49 return -ENOMEM;
50
51 fweh->num_event_codes = BRCMF_CYW_E_LAST;
52 drvr->fweh = fweh;
53 return 0;
54 }
55
56 const struct brcmf_fwvid_ops brcmf_cyw_ops = {
57 .set_sae_password = brcmf_cyw_set_sae_pwd,
58 .alloc_fweh_info = brcmf_cyw_alloc_fweh_info,
59 };
60