From patchwork Tue Jan 11 17:14:14 2022 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: 12710138 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56FE2C4167D for ; Tue, 11 Jan 2022 17:17:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344489AbiAKRRa (ORCPT ); Tue, 11 Jan 2022 12:17:30 -0500 Received: from mail-mw2nam10on2078.outbound.protection.outlook.com ([40.107.94.78]:38384 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1344219AbiAKRQS (ORCPT ); Tue, 11 Jan 2022 12:16:18 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HHkT3IGsQwpUuxfxaX3xJTt70jWLU4XgW73nB+xWdj1SanO6GR72iJzlLs2sMGEugCwJunzZqaiAVIdaPOzzKGJJgrCDr36jJAvQEojmh1Qh60/reCMvDZHmMONjkAzl0QmRwl38UmtTR7FNSgDjL0Mq++AVm+WEpxZbdb9+t/OXiuOe+/gT4TpXGHxhpTXrWIWlvYlYrUJLbz70k9pd3FR2RUzd/vAG2LQOQkGJAEnAkonKj6SWlEsOe/HMUdLnJreD1HW9udDcKRKhSnSzKzdQx83kIW1hdIH+HGFrTDiO7d2Fan2VWQBo4p9iIHilEaaeftWg4l3p1NMWFInHpw== 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=+q5yFVw1FvWVOxPW6sYuS3FQ744kmiWczGiDFWXd7G0=; b=WLFl+HFepSWSVJktk0Y/7SCzbIML25Hi5mjmEoEQhphY6aeXCpqxPJ/pKIj8qyNyoOTuIEvLPl6SGra7VhsyVtXWPcl8AQlb4O/J+zEpPhZ1+6NAtduAeRoHkRn+pqp0xaF6BKU8AlVpl/9IPQjmv+4nZBT5fj1xTu3OIxxGzGlqHTh3WUmMyaTlLjs5j1KJUok137mV5G1805WyTJY/7EFLs4F63vJ94a8v/25T6EKxtlsc/MGtHAeeHS3m/TCr7unXyMkfuiEaiyVHYmt2++aj4TmzzFcEoU1Uqcb+3svZb64kZ1A962pnKndmUdOLoTYp9QWWchCWIfcNXWh8rg== 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=+q5yFVw1FvWVOxPW6sYuS3FQ744kmiWczGiDFWXd7G0=; b=DZpj8pSWJ7cCN7YQsLhfSeU7Ta+fWfGxUM8mMZcPxdJhtrGSXWdZmctnFX/5Qy5XTXwjtEEZanmgPetPtFP/SbMOj6Npzs6ZwYfUzTXtsEv+otKWWq5o2R/t/KwsXlC2Nxhe/kLa/qqmR4/89iH5fpGmq5XFUgEUblnUv9XkZ8M= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=silabs.com; Received: from PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) by PH0PR11MB5609.namprd11.prod.outlook.com (2603:10b6:510:e0::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.9; Tue, 11 Jan 2022 17:15:22 +0000 Received: from PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::d031:da9e:71a:73e4]) by PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::d031:da9e:71a:73e4%6]) with mapi id 15.20.4867.012; Tue, 11 Jan 2022 17:15:22 +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 v9 14/24] wfx: add key.c/key.h Date: Tue, 11 Jan 2022 18:14:14 +0100 Message-Id: <20220111171424.862764-15-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220111171424.862764-1-Jerome.Pouiller@silabs.com> References: <20220111171424.862764-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SN1PR12CA0099.namprd12.prod.outlook.com (2603:10b6:802:21::34) To PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 41342c22-ddfa-4a2e-ac1f-08d9d525f378 X-MS-TrafficTypeDiagnostic: PH0PR11MB5609:EE_ 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: qgiixNqVEDggbc77i324j3R9hTh0u4QZsnHKec/0pUcegtcL9kWyvTXjo/sH993UTjUbSlW5wJ3+uYDkpZ/+8SreClQbX+roC2QjnmYLX2GSaPYdfFw/Ofpk7N6aJBjMCsgIoIg97w30Uhk410TFJ7KxQ29gjpugD51MeUFvrydl2S0TnL7YddTpoCSntdTwgJj4+g3/1H6+dQjUX4EYWuKUCdMIqMi6SxeNaKfkdxKl4WFyyZoQ7rHh9a15bP8U/ebrTg9tz/xYhIXFb+71SALQ6cL/fYNrQ1PWmfoL1BK7kYKdIVAOrtjKspabY+yTsUgK05ITr55ZH+rmvgm3bNUHRejsw4jnF+UgJDJc+t6XdAJwrXjEBOxYexM7t/1jhNqIBmnSMqVJuJmKuySaAOH26nymG0w8vBy3CxrZ22wXFY6R2Mc1CRhxOTADJTPCGfKT6azJ7hMA1qCjWNcm0rS+KWEWD5sMrDLocgfvaBvla5A2dP03TpPBJW5URsPaooUTDIkYMJlafy1eSePJafKWjIpGGl4CCHqCWO3/CjApJW3X44F8FPqeGvvsQyZ3FxjiM3Pd6Xekkl27n4DAC4+3E+/8kaU7uOqgooAdM/42tcolYAxg4mbMdr/rM0rWQIjyLZkrXPMW/hHTiPKF4Q== 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)(5660300002)(8676002)(36756003)(38100700002)(186003)(7416002)(66476007)(54906003)(6486002)(6916009)(6512007)(4326008)(508600001)(107886003)(66946007)(6666004)(2616005)(1076003)(8936002)(66556008)(86362001)(2906002)(6506007)(52116002)(66574015)(316002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rBak05GviRM3B3kusHDSw+SLwZ7I?= =?utf-8?q?vRWCmdUavDyZDJM8hdpvIRIG7QoaOJnNppo9U+SmpjtwGlYtg+elpEghon5h7Nlru?= =?utf-8?q?Fxcbr79UwDKRJ2YnnLcpB2uaIn3eYZ2D9cMk5/yqNSd6rmW4kfke4JPLdU44BniBE?= =?utf-8?q?cnKGqbKb2k3xDgXoowbxN4pmN/O5KIKVT9d/4F/CKU1tqXoY9YiqwCNkbger70oco?= =?utf-8?q?UNt5+IXE+BuKqj9mReK/owCL/SbTaBcVzqVfi705vbEB2xzX+t3CggQUO2pFNiwYn?= =?utf-8?q?e7OPhEazHUk0JhMfnsRzv4ROAyJlzXaSfqbHAcxweTtAVyIu0vLAEcHOi0dFAnl6h?= =?utf-8?q?P6nyoJGA8ope4p5X7dEWXy2bDdHEolo5mmP+5hMEqYSX/NsqWw/YtnggnkANLECxs?= =?utf-8?q?rPvP9GLOFogrt1LURY6VTL1/ejCIPfPnrqPgdBG/n91C1AVbVr9lnxOp/fnxnklC2?= =?utf-8?q?Oj+IdK4H+T2sCAetQ0NrZ7HxlRU1rNok6v1V702w1ceq7wGD4qzC/IK6vsV0ld4iJ?= =?utf-8?q?xPpzT/dk1cOJBzDnK3LWFTy2H4B15phIpuBsR5BwCB0/1MHpNxT8/tjHFQ4J/7KLj?= =?utf-8?q?7lUPlXb+BP51cTgo9RuP3kbDZQh+p/E2yqI0Sioqze6tOOq7azlMCg7Dscoa2JziX?= =?utf-8?q?ORmPkEjO6BH78xDYgoLBZ1sn3qKwLcncYqm3OmWY5o8ynpdjTQrgsn1jWl85eQtQK?= =?utf-8?q?7jYwXwo4G8rVS6tYmzMAU0ceQ09kXQbIdELlCKYSnUh0W2tixNB5SZ3NJKYplDPvF?= =?utf-8?q?5pUcVDf3Qmm6Aqv/C+x7xZcJrwbpuNw8B7k8HX/yM+MlDP4CqI7Goa4uTt6zo2clC?= =?utf-8?q?yvngnO9ZlNq0FdJLhvz1BM8c4LbOkVELh23VB16BDAxHN19oAw7FgAO5rejKqittO?= =?utf-8?q?aoiNgBmHvEf0sUjHJRasQIPU2xRNGasRiIwimb/4TT/HLhFWml06869hO9KJpyh08?= =?utf-8?q?/znWiqawSsVb/r44Crty4NjMPj4qblu7SmkN7hAa3ueqJ1j+BIc/iQGRy/1y/5b46?= =?utf-8?q?4ePJiQDSmHOL/yeqA0m7wjmLb3pmA4VdceMocbRGPP9DwlhDdKCKARuTjLTv9sIoR?= =?utf-8?q?c98O8QCLO6n0BTrEK/XdbnGZ4FgS3AsDK3d/VymQNtHOJ5x0LVeHz1vZ2oJGyWLLh?= =?utf-8?q?bBnWiMFCKefhqdK7j+Bh4iQ2NVRUb7TkY2FnUJuKcK3Q2ViitfJ1R+Z2TssFM6qc6?= =?utf-8?q?SjyiBI2v0rloTAs/P8nejaGtvW/bp6bEm0ZLOBXNAzvoedrO9EJRTfae4tKeQX6mi?= =?utf-8?q?ZHFFsFMsDqy1kxHiYiEZ8DdU348UNlUuv5yFeR4SNl1NmE/qgTlVknQgEzYJ1IJq6?= =?utf-8?q?07NL8NNqfFS/SNdKphleEvW3CMbFmGumh3/NNakV+lzuiNGZrA4h9kfyBZgD5maB9?= =?utf-8?q?NK8AETaFbk+rJwV8w6OV8fy9f6Nb9xNPxyflQEG+EShr3kJLNkw2wdm+BKmu549MX?= =?utf-8?q?DKUADt6hoDJvIrW7vmzhI29zrVbCV8XUOisXaf+pHlfXakx9HUdgwxQ8vZD7ab1x0?= =?utf-8?q?nelv2gc4oZIhyqB+8yOmqDUX6Z21SfuOO1xk+rkc1ar00k1dxARnGnPNCYeUS0dGi?= =?utf-8?q?lpHvgdU+OSxXPP6gYwzrH6vn0tcdxRJy3u8p2Aon7FThjnvrSWjF1c=3D?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41342c22-ddfa-4a2e-ac1f-08d9d525f378 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5657.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2022 17:15:22.6958 (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: KHqtHlSxS68Qhr0TfCrKhzs19DQ2YF5FgCQyR51fuda0PVFOhkzZYlDJtFZirVL1HLyf+151V2NnKMwa6H/0mA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5609 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 | 227 ++++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/key.h | 19 +++ 2 files changed, 246 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..8f23e8d42bd4 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/key.c @@ -0,0 +1,227 @@ +// 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..2234e36dbbcd --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/key.h @@ -0,0 +1,19 @@ +/* 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