From patchwork Tue Oct 5 13:53:50 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: 12536803 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07941C433EF for ; Tue, 5 Oct 2021 13:57:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE44A61074 for ; Tue, 5 Oct 2021 13:57:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235984AbhJEN6x (ORCPT ); Tue, 5 Oct 2021 09:58:53 -0400 Received: from mail-bn8nam11on2074.outbound.protection.outlook.com ([40.107.236.74]:47152 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236085AbhJEN5x (ORCPT ); Tue, 5 Oct 2021 09:57:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T3INaXsYTV4ojNZybb9Gl9PuD8hXJzHA7QFwCa+ls2iQCpcdfRdKdUuZl6qGAw6EALVsPmx4YKq525v8Gw19F4iCaBKRHZwIvI/MqcaNxSpv9nrfdh3Fwbre4DRswKbEuxggrrWqI7kxhBXq1R6xgFT/vib6AuixMmuwEjNmuq6NqAS0/joNwnp23aWhhZjpN/zidsLn3qT4B4mOfBS0OTLHRZvsovj/ybc3ScLI5BLVB2JYkrYyQMMBosUQaTrek2/iEi6OBhs5/eVzceHTPcCwI3TKMicLSlHs+lSsjpptKzlfgtMMl07YkDTytA9ZmWnewdl5JVbmIdmcUsEAbg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9I2Ep7jGpUHR0Stcx1LoF2xP2D1DDY49iGwXM1hX/es=; b=ZvjexcD7vb4tEQpU9D7LKz5DfaRINgavPnB/Sg43aAfyCxj8a3NwnUEyoPQqcwL2rTgn6CS1o/PZIWgPTtazn3H/UaCCzERXbfN00N7DYo162Vn4vYRzU2IAp1H57E4ToVkBwin2BZo7zEmscYcQEjkQdIDrV1TcfNFUIhBpkbixmF4Bl6YVMgwIXMcihpXCDEK6bdwaP57mvCAJtI6ZzVZqjV3PbJIGXKIv84C2ORFt7huGrAn4Zyg33U/kV5bG3mIm/Kfxd4XzK9MKm0OtQ/UHzDpVMMrHqNWqqM3cEbVONypISPILzcVkK2oOA0BvkzmcLhermCjIg0rPXCj2KA== 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=9I2Ep7jGpUHR0Stcx1LoF2xP2D1DDY49iGwXM1hX/es=; b=OQpCI0YKy7FOOY1m1WUFFAYfeXJwgB1odZf1Tdl53+j93OpxDZlJd8B/x4NJp8XJUpupbFd8yhQRDCvmWYJbb95XV/UPfc/U69R6JFsef8tDKrToV+BC+3Nzv/8jXcFR86yxhI/iPY/k20ZpF5PTki6iW8WdiHg/DZdfzAI4Lvo= 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 PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) by PH0PR11MB5644.namprd11.prod.outlook.com (2603:10b6:510:ef::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Tue, 5 Oct 2021 13:55:01 +0000 Received: from PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::31cb:3b13:b0e8:d8f4]) by PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::31cb:3b13:b0e8:d8f4%9]) with mapi id 15.20.4566.022; Tue, 5 Oct 2021 13:55:01 +0000 From: Jerome Pouiller To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Kalle Valo Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , "David S . Miller" , devicetree@vger.kernel.org, Rob Herring , linux-mmc@vger.kernel.org, =?utf-8?q?Pali?= =?utf-8?q?_Roh=C3=A1r?= , Ulf Hansson , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH v8 14/24] wfx: add key.c/key.h Date: Tue, 5 Oct 2021 15:53:50 +0200 Message-Id: <20211005135400.788058-15-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005135400.788058-1-Jerome.Pouiller@silabs.com> References: <20211005135400.788058-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: PR3P189CA0084.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::29) To PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) MIME-Version: 1.0 Received: from pc-42.silabs.com (37.71.187.125) by PR3P189CA0084.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Tue, 5 Oct 2021 13:54:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f154dfeb-9f5b-46fc-b004-08d98807b9ec X-MS-TrafficTypeDiagnostic: PH0PR11MB5644: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:346; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nxwni848xAZNPtesWfLmr21xfsJenejiY+hbmGZlOwTf7764COAgmHrckRbddcmA7Ro/DpYNg/hU2Uq7NlaW1rdazFFsyS17KkBTj4XoRkYY17qsf5vY+0isVbXRO40z1Db/rmQRWe9nHxtn9YoycW91JkzJa/MEp6t7aq+a5R/aZfPJZeSS15KkdmhGFmFap0LAiOgxitIzhGgatv4idp/Garc52rzzogmwbkmAZNoGjk0o/q9/ojMqkvj/VcQEof6EPB4bnJUZoQgdx9q+5SG/V3p4U0ryyhjIFFLxZkgcEx2KksY47TES4YRDP15bOHa8YGWxpBd79QrKofUfRdgraLxmkdSG23xz6t8ROutZuNvHGoNMFc0DDMUGRnziruhkfoRonGgYyv7ekinA7XcpXx9R7qrQ7h+Jhxf39ULbp2h3mcyZaqrSKZ2KA1cplz+myB47W4cELysPsodSLolSYJ5E55MkCojrdLnTZ2gVu2NtAvcWypIuplGQAMOyIc4ZyC2H8NH573SdVYon/CzSeXTA6Si24iFJ0fRS8M/F4q2b8EExyI8k0Qpe5mivEhxsZYRVp9hhlsarHIYnatM1CKhBxaNRHwJ/asTuhtcNoIeBufh7X3rJ08m3byT8MXRJp0xXQOx1KpvxTIy6Xjrfz902g3QBmO5uttN1FkMulGjyYcfqk1fv16VaAiwTAjpxKUO5tjAjbi60778joQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR11MB5657.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(66946007)(66556008)(8936002)(6916009)(83380400001)(956004)(508600001)(2616005)(66476007)(26005)(186003)(7416002)(2906002)(36756003)(4326008)(8676002)(107886003)(66574015)(7696005)(52116002)(38100700002)(316002)(1076003)(5660300002)(86362001)(6666004)(54906003)(38350700002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?iQoQpC4m2Dxd2nhZgKFU0ZucTa9J?= =?utf-8?q?uxUksSNFtuiu/SjvYEDFYXxeklLUTdi5JmI09tghVC09jwUOhIr8ril0d7OTicbOP?= =?utf-8?q?gXiwho6zb+S4meOpuroQEcbmzXGv9stXyt7Rhm+4yNHmZF1oXRjpDS81b1Q8hE3kI?= =?utf-8?q?cWsE/bW3I+C/LW1vwC1sD+2nNleZ/bCRWRqpEivz1jvR6+lOCk2RqwEKI87kb+xTW?= =?utf-8?q?xNbH9OFuyC7obunSWYgkhxdI1UFcLHr4aHnpjopkQtbfhC1H7lcWLQaUMJR84Trn8?= =?utf-8?q?lBlZINyIEJObTqemAcyHyyYQzQ3DGCHBI0uGa+mcYPde1Ws4KJI9p0E0PmOQYOm5x?= =?utf-8?q?SR5VS40ZLtXx7TZDSZYgAYVLv9JNiK1tEd77QhyhQFTY5CHfAP3kvxFp9+9b9t2+F?= =?utf-8?q?aVD6OFdSRgbXjGYIowoJwethQZzmaLanuIwZ9zQIp+hWhsaDf6zJk4++TWwSJ+j10?= =?utf-8?q?pNDXwTHB8ujIf6gtmhZk+xsflf/CAkqMfpT5bOke2IDAAgR3hSAxSoPRXEr5c0WdC?= =?utf-8?q?e5UbeUrcfQvrk4z06U8nkfH9v5wsw03HD8Z8leVp4MND4g6mMg9NfLjm0OJQgYb6u?= =?utf-8?q?Z42VKdgyg2b0H1DIYddciNx5r6tf3E4x4NPWL2DhuZHur7Bt/F55NS+uD5wJ+cp+f?= =?utf-8?q?kg0EPMzxObPV8CqFG1dSOwQ131YWKstoyRvVaUu467idnG0rM7IGX7Jw3I90b0Xtm?= =?utf-8?q?UmLIjIWFH44liddO4hFGwT5w+3joLzhZ+96QFbZyA8aO7/aN6YPFpmE/PgQsFpUEz?= =?utf-8?q?FgGO9dprAeBFpnhSqvR0KcJMw2HDNCxmzDpe+OFyFzbXahfOvCFjAjU7fe9/yYHLl?= =?utf-8?q?vbutx6GUPnpAAuhZfki+cIyrxXdj3Cf6F5+8dtm5pnThV8hLXc8nzg/kbuGtBrOS8?= =?utf-8?q?Z2mKJxr0+P2lG9Q/4OSiX3yrutoeJNJ+v76AJoodjsMJZlXF3h460rvqSmMDE3K2b?= =?utf-8?q?/qutl0lspw14nIBDQWmymuolkwWr5Q0RGWTYgY9VmK5Xzn1kuZrZliIORj//01e7D?= =?utf-8?q?Vp/hF49HCYIwu4TST/bnxTxslPknxY0Fu/wWM96vDJDwsqFtBsvQotRfI46MGQVjS?= =?utf-8?q?XyPjjcGUcoLqO0RY2AlaRaMlhlBrvxhsNBSrhIaoZm+G4WMyjew1AFyikiPTGUQV3?= =?utf-8?q?m1LPuN2I+Xw54uc/rZbPuxzYItumW0M3Jly6TZy3KPZf7iYPj40sj5GW66WQxeSl9?= =?utf-8?q?QZi5vI2J5Xy2CQH6vWDFD21kNclQQr229A+5d3WCtH54A45l/Fk4l2r+ALQkaZF48?= =?utf-8?q?psQTMWwAVw9LyAAo?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: f154dfeb-9f5b-46fc-b004-08d98807b9ec X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5657.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2021 13:55:01.7808 (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: eWbzE+Tw7nMdrv/MlAzMhqjW/J4fo884npuYfwQl18TfTe2nvVJ9miVPhlQ7qpApm4Fs4c5QCBo/v9aZ91UNeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5644 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..dea8238f9916 --- /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 wfx_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 wfx_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 wfx_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 wfx_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 wfx_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 wfx_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 wfx_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 wfx_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 wfx_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 wfx_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 = wfx_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 wfx_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..2d135eff7af2 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/key.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Key management related functions. + * + * 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