From patchwork Mon Mar 15 13:24:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 12139389 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDFE0C2BA1E for ; Mon, 15 Mar 2021 13:26:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4502B64EF4 for ; Mon, 15 Mar 2021 13:26:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231292AbhCON0b (ORCPT ); Mon, 15 Mar 2021 09:26:31 -0400 Received: from mail-dm6nam12on2047.outbound.protection.outlook.com ([40.107.243.47]:2753 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229830AbhCON0F (ORCPT ); Mon, 15 Mar 2021 09:26:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NSCXMXGm+cBPpGAcHKTvMpqh4FMcfNlVvGLa5Hk8uFf+1c6DmP4un5/1T1Ic+p1f+x6NRZ/rp2yDCAmbi5qQEZZR4tUGeT8T+17d8J3lrdzOPfOjHt02oH8g6Pl8cC0/owuFeVrPmTUJj7kZYAsUPD8dp/eLAHC9beGlurbHaufBtHxUDmSgpMTT0fch685gc1ona2pJfIlJn/hDgEy+0dJmDfnZU+zGfNMzftKHg5wM01EYcyKpAMyXu5Oo6wlSytoyqZvS3WKPE8dKDErof3tZtz/zcPHNr+krUxH/CWqfqoUlkpF9FV6H74DxGTK5NgsYJKBxGkhz/DERry2czA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XGiAjmdFqkzEwqeANs72tUGoQwsiHdsIMoxNbghOPUo=; b=gu8Vk7sqOXnotWm/fzSZg1fVFOdFwSwQvLN/Yg/XK/cJvycAoBDkAFDnmNIQoFGn+wuunwyhbEOWlQMZXp9se8gjAPfY1DZpQqzNOe6v46SqiRvDqxHogewQvNDzT8UJw/PGgvND54N84ecV49vG+w0quScsV5uyxKWX8OqfZTsguNqBpzK77nGjm7l9i3j0MSsEX7OaDjJyTsN1E9YMlCowlimvhiJkz2OAV8gmzyO3ZxfYx0vspq0N5hoC1zginQkCmkFxX4RlrmlpoqCUBte++6VZf8HDrsw5nVowqmMaFKCAk0+tmHW2P2CRuU8jLhgjeLTy7efTb6vD1ykltw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XGiAjmdFqkzEwqeANs72tUGoQwsiHdsIMoxNbghOPUo=; b=AAVbbajvvmhY+nbCvfBmBND9ANx81ENDK86YXzxwPLxUlx95cx4ZmHmx30KWv9fMUsb75HzjIM2qnR74nwtxbSs1rBvcCgAb9n5RPoW/OMbHvZnj6cZRLWURjAdSOATKrGIlg60p+RZ7otGlAJb8whl95l7wncT8P9hb/+wzoCk= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=silabs.com; Received: from SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) by SA0PR11MB4544.namprd11.prod.outlook.com (2603:10b6:806:92::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Mon, 15 Mar 2021 13:26:01 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::41bc:5ce:dfa0:9701]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::41bc:5ce:dfa0:9701%7]) with mapi id 15.20.3933.032; Mon, 15 Mar 2021 13:26:01 +0000 From: Jerome Pouiller To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , devicetree@vger.kernel.org, Rob Herring , linux-mmc@vger.kernel.org, =?utf-8?q?Pali_Roh=C3=A1r?= , Ulf Hansson , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH v5 14/24] wfx: add key.c/key.h Date: Mon, 15 Mar 2021 14:24:51 +0100 Message-Id: <20210315132501.441681-15-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315132501.441681-1-Jerome.Pouiller@silabs.com> References: <20210315132501.441681-1-Jerome.Pouiller@silabs.com> X-Originating-IP: [2a01:e35:2435:66a0:544b:f17b:7ae8:fb7] X-ClientProxiedBy: SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pc-42.silabs.com (2a01:e35:2435:66a0:544b:f17b:7ae8:fb7) by SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 13:25:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8921d9b6-cb35-4aae-1ab0-08d8e7b5e062 X-MS-TrafficTypeDiagnostic: SA0PR11MB4544: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:376; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JMeqmY+T5mCI/bMKKA2fEknxllWRjF8eyCF47tqbIy3SaIGslEaBBmkyhqiPIV5+AojBK75B7P+rxVSc2dCdEi7lcivadiroE9iEfEEe+ilGlNmiyvZhtb1VfcuvTmrAkKBLGx+71kOObE/x1/grawn11yrhIbZVVpw4gyGMzKox5DodgRL+9EcZv9xQbbtrRl/cZeq1KP9vA+orHfxU7oKgaDa3Az44s51IPqXGlD4mZD/efETjt5Cx8poGOUOKuIUSPKVhh54dcpm9DW2hFs6vcKdMCKE7cOIZauC2fbQ3sb3GO1Ytv3wVqc1fDsdoaQJr1G/gR3moa2jKNE4CByVx3KAgICbTw85XhmCuU5CYxLi3+tm9O32r/0el+t9yBPcKrmRWtcvze0TyzqQJLwmzxEyk9jAuO75gA5DPMMOW29CtHjHcuElIb4pPsy6fYdKvlDqRgpsjLXKhNhVP1JMTyZnQpLdJD+9RrZpCqm1FWn43FK4Q6cPDpiD/m1paBHGZvgFOXxxFE3DWLIsC2JZYEY4NibDv4k9tuEttgm8NZCCmQw9MOA7vneBdDaCf X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR11MB2718.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(396003)(366004)(376002)(39850400004)(136003)(66574015)(8676002)(186003)(52116002)(86362001)(5660300002)(6486002)(7696005)(2906002)(83380400001)(4326008)(66476007)(16526019)(2616005)(107886003)(66946007)(8936002)(66556008)(1076003)(478600001)(6666004)(36756003)(7416002)(316002)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?PbjOr7THn3HkZWMZyrBI6HAQGCEMB3?= =?utf-8?q?kIC1bi6LkrUlB8DxPNjB/AYOD//1uICPYEpNmBS5bjxa4SJbJmPjrfCZHRPV1HTYP?= =?utf-8?q?+S3b+HrnObbzeIiqT5bIAKjan+3OjyzIzSQowXcfnl2SJpbSNAHWBjmwO+8bj0wW9?= =?utf-8?q?YvcSCyHm88RWrq3KVwNJVWaiuJts/G832wmX0xJHtQ0Q/o9dEF4kZzCDWJa+9tFJ7?= =?utf-8?q?Y9zntknLRZE4awgRBpvFKhYI9+FYQNbp9Iw+lh03UTxPldGPZhnM+xviXpo8u1tWd?= =?utf-8?q?GngJjvzDqj49My1lF44fKZPACGTB8qoknm+1L2fVKuUgam23y+fkgjLDwmiUojmJP?= =?utf-8?q?fR1qZ4gzH0vta+kM+IGAFtD4ZDlLPXdTQBzpvIkrY8jmOrWjKyVinseeT7oWdB3Xm?= =?utf-8?q?QlrFm1CKUZU9NiA5gfmzj3tjrTf0HViQymkW3px6sgdgTrbF9kvUxVhQ2pWfBc/QD?= =?utf-8?q?xoh6OOirvDpigISOIa+SUaddB+ZNpvwCUrEYUS0YwJnoztGvUc0Q6AAYnhF2WZofe?= =?utf-8?q?brTbi6AM3vJwP9pFY1PZyg+3Qv0Y7nSsXpw6K1gQ+cS8yI6XNfGRqq+t0KjveOdug?= =?utf-8?q?86FBPOgpOUdlNSygPjLveQWnWSozNdAXQ/6QGkIpj4SGuRDH3iD5ur+9xvtod4N6I?= =?utf-8?q?1KMVAMDWyvXIoGSVK0dW53h46weRIKbh+crBz+uW9Wm+KovoyWJ00iFQJKlm2zDOw?= =?utf-8?q?hlfMCH8t8aKUnurQD5j0QOwxZ6wkcPv6VNojrASNpJkNHkJIJLz9ktOdCMAdkAFmL?= =?utf-8?q?qM0RFFgSKq5MgvjL6DJDaveTTOE7FO+i5/7yiCtJKAUf2X6ljfPDpTSBzDO/AIrDg?= =?utf-8?q?4SuMVySH64vRBQT4zfR1DXBaFH6wzYKlRA9aiG+A11wF/T5YZwYASkwoGWjPn0syp?= =?utf-8?q?J/+wU+juRsp6j4E+M6XWI6GLBNwv2e2vn+ZzJt9m5Z55n9+YSjZF4S7LbAayUb89E?= =?utf-8?q?S1D747wt9mguXUrrNP2GDu1QJmmf/9TSAN9pBLKVwYCyG4kFC9smTb/plF+GeesXg?= =?utf-8?q?u04PvBwW5bvSoHxCdGeXCUQHV8QrAs044hW+reYAVJCGASFBZDmoQpRli2yloDGmz?= =?utf-8?q?LcDyuoFzl42Izjf0MK28knjHUsihoWoy0MUm/tE3aLAK6WrmaG7K3uA0Sr9ajiIDd?= =?utf-8?q?pwO6AYLhghpOjBRuWblY/PTBdaPEU+JcttxpvMUpmlH9L8YVtBNU6U29ZtBcqWueu?= =?utf-8?q?Wdc9SX6tvpuwdoFm1GUL0oT0lSwlnnqrd4hCVbf20Lli/YUKgdM0AVcJ+apz5pwyr?= =?utf-8?q?XVmp+DA5N5x0V/Ql9b9ef5jfhAiYm1/vboZwmO+YxHgbitqxCkBetH7S2fq1YGwdI?= =?utf-8?q?fJgXeZJJobfz/?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8921d9b6-cb35-4aae-1ab0-08d8e7b5e062 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 13:26:01.5096 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xt3nrQQiOETo05+ZSRBY88UtziQJgJ6V0mHVtoUkjGS1/4gx+qhvbvfBAGOhXh25wZNX3VPheFrI6H5kHRiXUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR11MB4544 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Jérôme Pouiller Signed-off-by: Jérôme Pouiller --- drivers/net/wireless/silabs/wfx/key.c | 241 ++++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/key.h | 20 +++ 2 files changed, 261 insertions(+) create mode 100644 drivers/net/wireless/silabs/wfx/key.c create mode 100644 drivers/net/wireless/silabs/wfx/key.h diff --git a/drivers/net/wireless/silabs/wfx/key.c b/drivers/net/wireless/silabs/wfx/key.c new file mode 100644 index 000000000000..65134a174683 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/key.c @@ -0,0 +1,241 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Key management related functions. + * + * Copyright (c) 2017-2020, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#include +#include + +#include "key.h" +#include "wfx.h" +#include "hif_tx_mib.h" + +static int wfx_alloc_key(struct wfx_dev *wdev) +{ + int idx; + + idx = ffs(~wdev->key_map) - 1; + if (idx < 0 || idx >= MAX_KEY_ENTRIES) + return -1; + + wdev->key_map |= BIT(idx); + return idx; +} + +static void wfx_free_key(struct wfx_dev *wdev, int idx) +{ + WARN(!(wdev->key_map & BIT(idx)), "inconsistent key allocation"); + wdev->key_map &= ~BIT(idx); +} + +static u8 fill_wep_pair(struct hif_wep_pairwise_key *msg, + struct ieee80211_key_conf *key, u8 *peer_addr) +{ + WARN(key->keylen > sizeof(msg->key_data), "inconsistent data"); + msg->key_length = key->keylen; + memcpy(msg->key_data, key->key, key->keylen); + ether_addr_copy(msg->peer_address, peer_addr); + return HIF_KEY_TYPE_WEP_PAIRWISE; +} + +static u8 fill_wep_group(struct hif_wep_group_key *msg, + struct ieee80211_key_conf *key) +{ + WARN(key->keylen > sizeof(msg->key_data), "inconsistent data"); + msg->key_id = key->keyidx; + msg->key_length = key->keylen; + memcpy(msg->key_data, key->key, key->keylen); + return HIF_KEY_TYPE_WEP_DEFAULT; +} + +static u8 fill_tkip_pair(struct hif_tkip_pairwise_key *msg, + struct ieee80211_key_conf *key, u8 *peer_addr) +{ + u8 *keybuf = key->key; + + WARN(key->keylen != sizeof(msg->tkip_key_data) + + sizeof(msg->tx_mic_key) + + sizeof(msg->rx_mic_key), "inconsistent data"); + memcpy(msg->tkip_key_data, keybuf, sizeof(msg->tkip_key_data)); + keybuf += sizeof(msg->tkip_key_data); + memcpy(msg->tx_mic_key, keybuf, sizeof(msg->tx_mic_key)); + keybuf += sizeof(msg->tx_mic_key); + memcpy(msg->rx_mic_key, keybuf, sizeof(msg->rx_mic_key)); + ether_addr_copy(msg->peer_address, peer_addr); + return HIF_KEY_TYPE_TKIP_PAIRWISE; +} + +static u8 fill_tkip_group(struct hif_tkip_group_key *msg, + struct ieee80211_key_conf *key, + struct ieee80211_key_seq *seq, + enum nl80211_iftype iftype) +{ + u8 *keybuf = key->key; + + WARN(key->keylen != sizeof(msg->tkip_key_data) + + 2 * sizeof(msg->rx_mic_key), "inconsistent data"); + msg->key_id = key->keyidx; + memcpy(msg->rx_sequence_counter, + &seq->tkip.iv16, sizeof(seq->tkip.iv16)); + memcpy(msg->rx_sequence_counter + sizeof(u16), + &seq->tkip.iv32, sizeof(seq->tkip.iv32)); + memcpy(msg->tkip_key_data, keybuf, sizeof(msg->tkip_key_data)); + keybuf += sizeof(msg->tkip_key_data); + if (iftype == NL80211_IFTYPE_AP) + /* Use Tx MIC Key */ + memcpy(msg->rx_mic_key, keybuf + 0, sizeof(msg->rx_mic_key)); + else + /* Use Rx MIC Key */ + memcpy(msg->rx_mic_key, keybuf + 8, sizeof(msg->rx_mic_key)); + return HIF_KEY_TYPE_TKIP_GROUP; +} + +static u8 fill_ccmp_pair(struct hif_aes_pairwise_key *msg, + struct ieee80211_key_conf *key, u8 *peer_addr) +{ + WARN(key->keylen != sizeof(msg->aes_key_data), "inconsistent data"); + ether_addr_copy(msg->peer_address, peer_addr); + memcpy(msg->aes_key_data, key->key, key->keylen); + return HIF_KEY_TYPE_AES_PAIRWISE; +} + +static u8 fill_ccmp_group(struct hif_aes_group_key *msg, + struct ieee80211_key_conf *key, + struct ieee80211_key_seq *seq) +{ + WARN(key->keylen != sizeof(msg->aes_key_data), "inconsistent data"); + memcpy(msg->aes_key_data, key->key, key->keylen); + memcpy(msg->rx_sequence_counter, seq->ccmp.pn, sizeof(seq->ccmp.pn)); + memreverse(msg->rx_sequence_counter, sizeof(seq->ccmp.pn)); + msg->key_id = key->keyidx; + return HIF_KEY_TYPE_AES_GROUP; +} + +static u8 fill_sms4_pair(struct hif_wapi_pairwise_key *msg, + struct ieee80211_key_conf *key, u8 *peer_addr) +{ + u8 *keybuf = key->key; + + WARN(key->keylen != sizeof(msg->wapi_key_data) + + sizeof(msg->mic_key_data), "inconsistent data"); + ether_addr_copy(msg->peer_address, peer_addr); + memcpy(msg->wapi_key_data, keybuf, sizeof(msg->wapi_key_data)); + keybuf += sizeof(msg->wapi_key_data); + memcpy(msg->mic_key_data, keybuf, sizeof(msg->mic_key_data)); + msg->key_id = key->keyidx; + return HIF_KEY_TYPE_WAPI_PAIRWISE; +} + +static u8 fill_sms4_group(struct hif_wapi_group_key *msg, + struct ieee80211_key_conf *key) +{ + u8 *keybuf = key->key; + + WARN(key->keylen != sizeof(msg->wapi_key_data) + + sizeof(msg->mic_key_data), "inconsistent data"); + memcpy(msg->wapi_key_data, keybuf, sizeof(msg->wapi_key_data)); + keybuf += sizeof(msg->wapi_key_data); + memcpy(msg->mic_key_data, keybuf, sizeof(msg->mic_key_data)); + msg->key_id = key->keyidx; + return HIF_KEY_TYPE_WAPI_GROUP; +} + +static u8 fill_aes_cmac_group(struct hif_igtk_group_key *msg, + struct ieee80211_key_conf *key, + struct ieee80211_key_seq *seq) +{ + WARN(key->keylen != sizeof(msg->igtk_key_data), "inconsistent data"); + memcpy(msg->igtk_key_data, key->key, key->keylen); + memcpy(msg->ipn, seq->aes_cmac.pn, sizeof(seq->aes_cmac.pn)); + memreverse(msg->ipn, sizeof(seq->aes_cmac.pn)); + msg->key_id = key->keyidx; + return HIF_KEY_TYPE_IGTK_GROUP; +} + +static int wfx_add_key(struct wfx_vif *wvif, struct ieee80211_sta *sta, + struct ieee80211_key_conf *key) +{ + int ret; + struct hif_req_add_key k = { }; + struct ieee80211_key_seq seq; + struct wfx_dev *wdev = wvif->wdev; + int idx = wfx_alloc_key(wvif->wdev); + bool pairwise = key->flags & IEEE80211_KEY_FLAG_PAIRWISE; + + WARN(key->flags & IEEE80211_KEY_FLAG_PAIRWISE && !sta, "inconsistent data"); + ieee80211_get_key_rx_seq(key, 0, &seq); + if (idx < 0) + return -EINVAL; + k.int_id = wvif->id; + k.entry_index = idx; + if (key->cipher == WLAN_CIPHER_SUITE_WEP40 || + key->cipher == WLAN_CIPHER_SUITE_WEP104) { + if (pairwise) + k.type = fill_wep_pair(&k.key.wep_pairwise_key, key, + sta->addr); + else + k.type = fill_wep_group(&k.key.wep_group_key, key); + } else if (key->cipher == WLAN_CIPHER_SUITE_TKIP) { + if (pairwise) + k.type = fill_tkip_pair(&k.key.tkip_pairwise_key, key, + sta->addr); + else + k.type = fill_tkip_group(&k.key.tkip_group_key, key, + &seq, wvif->vif->type); + } else if (key->cipher == WLAN_CIPHER_SUITE_CCMP) { + if (pairwise) + k.type = fill_ccmp_pair(&k.key.aes_pairwise_key, key, + sta->addr); + else + k.type = fill_ccmp_group(&k.key.aes_group_key, key, + &seq); + } else if (key->cipher == WLAN_CIPHER_SUITE_SMS4) { + if (pairwise) + k.type = fill_sms4_pair(&k.key.wapi_pairwise_key, key, + sta->addr); + else + k.type = fill_sms4_group(&k.key.wapi_group_key, key); + } else if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { + k.type = fill_aes_cmac_group(&k.key.igtk_group_key, key, &seq); + key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE; + } else { + dev_warn(wdev->dev, "unsupported key type %d\n", key->cipher); + wfx_free_key(wdev, idx); + return -EOPNOTSUPP; + } + ret = hif_add_key(wdev, &k); + if (ret) { + wfx_free_key(wdev, idx); + return -EOPNOTSUPP; + } + key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE | + IEEE80211_KEY_FLAG_RESERVE_TAILROOM; + key->hw_key_idx = idx; + return 0; +} + +static int wfx_remove_key(struct wfx_vif *wvif, struct ieee80211_key_conf *key) +{ + WARN(key->hw_key_idx >= MAX_KEY_ENTRIES, "corrupted hw_key_idx"); + wfx_free_key(wvif->wdev, key->hw_key_idx); + return hif_remove_key(wvif->wdev, key->hw_key_idx); +} + +int wfx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, + struct ieee80211_vif *vif, struct ieee80211_sta *sta, + struct ieee80211_key_conf *key) +{ + int ret = -EOPNOTSUPP; + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; + + mutex_lock(&wvif->wdev->conf_mutex); + if (cmd == SET_KEY) + ret = wfx_add_key(wvif, sta, key); + if (cmd == DISABLE_KEY) + ret = wfx_remove_key(wvif, key); + mutex_unlock(&wvif->wdev->conf_mutex); + return ret; +} + diff --git a/drivers/net/wireless/silabs/wfx/key.h b/drivers/net/wireless/silabs/wfx/key.h new file mode 100644 index 000000000000..eba7ac56080c --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/key.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Implementation of mac80211 API. + * + * Copyright (c) 2017-2020, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#ifndef WFX_KEY_H +#define WFX_KEY_H + +#include + +struct wfx_dev; +struct wfx_vif; + +int wfx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, + struct ieee80211_vif *vif, struct ieee80211_sta *sta, + struct ieee80211_key_conf *key); + +#endif