From patchwork Fri Sep 17 15:13: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: 12502549 X-Patchwork-Delegate: kuba@kernel.org 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.7 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,URIBL_BLOCKED, 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 E2580C433FE for ; Fri, 17 Sep 2021 15:16:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C95D660F6D for ; Fri, 17 Sep 2021 15:16:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344381AbhIQPR4 (ORCPT ); Fri, 17 Sep 2021 11:17:56 -0400 Received: from mail-mw2nam12on2045.outbound.protection.outlook.com ([40.107.244.45]:4192 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1343883AbhIQPQ5 (ORCPT ); Fri, 17 Sep 2021 11:16:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NE8yKHT8KIr9lTeAVgHkdNsNy1pM/Qskv6F6sGgdMH1x+CeedmT0l7FMH0ZTFomUk1R2rUYWxF2b49DqQ32mIaD1rli3jSHr0zMoMngZjxJaOiMPQYCC7fFkhi2riJ0TUID/EUNGMmbNNB9zaeOe8md9PqVgn2Kp5pidF/YAhtEbMb9hYBrsIpnqfIeF0ji/JbGMXNC7NpvIm25LYH04IWU33evJpEqaXqTSqBIRQYeZ/PRwJ1X71jK//06xC0PHgIYpeTLA4byAyYQDeW3uZ1J+6FVGlrBp5zBuYXwe+eqQXeIHLmSJT519w2t88okqaJ0xyymxsAryxqWbmvcjaA== 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; bh=xdE+7Y9kU+Kuls8oPQCRxATfxUpgKTkyNGR3RtiwYqc=; b=AZOShFu5ifo6R0AJ7dQIZzkGWLnP7r9Vj42lYNpdbTLCUzwnrcmlNnSoCBCEzFg8W71Xwz2ysKlQsTYtMapGRRGl7SbSSYm0eth4unMp7OzImVN0wAtxpT0P31At8vfTtnCr+0ky+Kp0+hjziYQDqrs7aZy2Xhbs1sj2PQwkRMGS2h/8Pj3MBUhaDC+cprWQDbyO3mil1U7LDqmVohXAdhX8zvvOlNZ6BX/jIxdEW+3qOZotUGqeH+Hpj9/to+YRjtqPZq2vIjCnIqkcS5VQn8wqn5Bo4OWkZ1830VHsM/iFmhd1h3hghpjzx2CDdjYSrzvd47edcxhuk0t6z2dVVw== 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=xdE+7Y9kU+Kuls8oPQCRxATfxUpgKTkyNGR3RtiwYqc=; b=b0Ws2ybRtDrSUlkLVzR7G5FkCB5dG1pEaF8WcAc9PvF+5TBHOM2dwKMcgFGIXCSRTvSP+H12BA/hp0aZnDtW9W+xdNSpihRIscGaj6leUClb/BXbkHcKcliHStZNw1oFNmpgoefOW7aCCqOWkjz4OAoPsbdpGtk7/FcFsT1FB4U= 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 SA2PR11MB4876.namprd11.prod.outlook.com (2603:10b6:806:119::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Fri, 17 Sep 2021 15:14:54 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd%7]) with mapi id 15.20.4500.017; Fri, 17 Sep 2021 15:14:54 +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 v6 14/24] wfx: add key.c/key.h Date: Fri, 17 Sep 2021 17:13:50 +0200 Message-Id: <20210917151401.2274772-15-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210917151401.2274772-1-Jerome.Pouiller@silabs.com> References: <20210917151401.2274772-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SA9PR03CA0029.namprd03.prod.outlook.com (2603:10b6:806:20::34) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 Received: from pc-42.silabs.com (2a01:e34:ecb5:66a0:9876:e1d7:65be:d294) by SA9PR03CA0029.namprd03.prod.outlook.com (2603:10b6:806:20::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 15:14:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bd89fbc4-27f1-4069-dcc4-08d979ede6fd X-MS-TrafficTypeDiagnostic: SA2PR11MB4876: 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: wb3Ue97yc+16s6C+i2hv3kFfZDkD2Az3baBtZj0SCUZiLiwbL+NIEWrpCGiGms/9dNg9IvRdjQV9NKclbynoe18latwlcM7CugPkX0b758jK+wPp9Ulim2O6OMyZGvAHOdeY9cYHrF24Rg6IYLG7tPgkC8tQqkq9od/TbPJobA4G/Ly0THpfuH9yw7xHObtJsBj/Es2h2ZaFtAMYI7y6xl3fM+Uh+34D8ACHoE3MANfSnHGCRXs7DMXOmkhT48MbERJshAKXm7jZAtmHG/XrFitK15bLI5hYCzBol+Hrn4CcmloFY2zOXO/YOtrISrFInu9N+ljKG+HHxAeC+ZoT38bfYZe/SVmwNcVjWM/reHyHtD3B9zmp1PjzIH5fRajGdE73tlgfmDYfLYt6woUF2IkC20VkeEPqbT7tVAGcXg3Ap7wWsZAvLojl4BYJ0PDr4qgEEgbvh/rBQEd/H8fqxPGcB1UeCBihr1ov29NiQ7BdWH/AlFde5I7CPiM/IwP2CfMT/UK8iyu/K4IYq2EoZIrvgfAyEZex3i+gRVtpeebaAgMOgQgM+eQS9XIYi5OgBDLjkkzz2xXwFxTUGUBju/JjrFCf0c0xmhB+JaHjBAh/DPbOnMR6vVTm8vD45cnw4hjGygluIqbVwtMdc7FuXg== 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:(366004)(66556008)(66946007)(508600001)(52116002)(7696005)(6916009)(66476007)(4326008)(316002)(86362001)(2616005)(6486002)(1076003)(107886003)(38100700002)(83380400001)(7416002)(2906002)(54906003)(5660300002)(186003)(8676002)(8936002)(66574015)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?nvH5M/4NLXy+rFyVJ/Qu4wZdmeGN?= =?utf-8?q?+wbhYS6YJ4dLCe4P1AecXxLO3Y4Uj3Fzreovj8NsmJafL3Ts398hMYlJAqDnuke5O?= =?utf-8?q?VSmLkCPY3iwY+x/DRtFZt/Ja2t9Y/sG1NMUPPjpBlkkScRrMOBMO/qe2ErL+lxtGt?= =?utf-8?q?oGrLX6MefQzY5BHkElzwJtuE2fHHTwSfjuwCIK6Z2IVGNzivE34nsN7L+c+lydwlO?= =?utf-8?q?YsE3NpKeOs0tdv+uEd1KcWNBLngA3bn7ExWyj0sNddWrqSGe1+99oJCUsIH20IUwB?= =?utf-8?q?pOmjUZzn/wGH//mrIXhc/aUt18Jv1kGjWl0Uz8LoTn4p2P6dx9stiDVTamWbHim9u?= =?utf-8?q?bMo4Jfr61lDFO+UMjEmQaNByvfLebXZWNY01JOdM1QZ722vhTji54rLxIB9/6llr1?= =?utf-8?q?Ek8RWBHBZrif0V52inZnzHlfLVZWCbncICoBl3w8vnZhfa3dSWpSTd+AxVBpjfXob?= =?utf-8?q?fnNxN33xEcU5XIbYQ1Ctv2ALBNyvNnmlepnBgOrX+BAKNy4//12jVr81oEJ0cVb10?= =?utf-8?q?XGjIp3VNDFnqKQRQImqrS86V7ADbcIWMYnA8NrehVkG2/Y9fmihOd/E6fKvuebK9k?= =?utf-8?q?57yOjyjc8a8vsKo59hELHplCi1a+rFOuM7QLe0wJ/xZGo4DGqSe0ZNbMrnrqzstdP?= =?utf-8?q?x4e8hxxhokgWrJkxTITpGXYCRlktTXUdKzE5+Gwy7xwoBU/Rmjf7VUy6jmoHnCZzb?= =?utf-8?q?yBWECdic+hm76sffERx9MNoocnDCEz093sOAw5LJz3kCtOioz2lLoSTMSphCRr0mc?= =?utf-8?q?UMTJnQKBLls+koPLTwywersnrm9R46YVc9V8IeUa3sy+5Eg3TT1AKdMjDaMp1voWj?= =?utf-8?q?KJuVZfhUEmlS+VwnotqCifZ+2gUclwtgBX60VEzsSl+A028PTj974n0wVbvrzckYn?= =?utf-8?q?ylvu4qkb+xJ6bDEehGHKljCmOLqG6Wsq+c1MhLFb1KKnBr3tCYcE76aqPHTSx3l6l?= =?utf-8?q?dqLa88G01Zr/ptvd53Wf7EeOpqRptLrhMwb7cxTaMcJzgGNbmvKkCiD5+rIoLi2AZ?= =?utf-8?q?91lo1e4hTguSWNjnEJXcyKbwaBQHECKzjt4AtVGCuhGA6wV5NQvockmCbGUBfrgGx?= =?utf-8?q?iu6OE93etp44cCJDXzTqIUoO/hucShWmBCQaivPz1qXWaYvXtAy0MyQ8oL2opE+3h?= =?utf-8?q?+Hkuiv2geU+2V+60D8POAKqbhpQUa8Or6xA5jtPIy2ME7W6MGgwhrl6L8d/D4ilMY?= =?utf-8?q?1/VgokV7cXzYUG+xXr06juM9waK1EEibQgLFyHSw7FtJscLPhuzEAvD1tnzJKkg79?= =?utf-8?q?YU4+Wr8A16o7Z2yoQDYldSPBsvwmi+9apARy7kwT2pFkq8OB7SR+WeXNE485WFYkL?= =?utf-8?q?dS1uOmv5GRnoODk?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: bd89fbc4-27f1-4069-dcc4-08d979ede6fd X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 15:14:54.1341 (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: PAZWRf7/iFHboZA14MnguGkqfYVc+DgMedUTmgi8gWdlru6wI0mzqWZ260XhF8GJwHRn/9vpKBoTcMxy6DKdYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB4876 Precedence: bulk List-ID: X-Mailing-List: netdev@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..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