From patchwork Wed Apr 18 11:39:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Singh X-Patchwork-Id: 10347925 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 52B0F6053F for ; Wed, 18 Apr 2018 11:40:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47CE1285F1 for ; Wed, 18 Apr 2018 11:40:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C184285EB; Wed, 18 Apr 2018 11:40:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1D2D285FD for ; Wed, 18 Apr 2018 11:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753824AbeDRLki (ORCPT ); Wed, 18 Apr 2018 07:40:38 -0400 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:64459 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753780AbeDRLkf (ORCPT ); Wed, 18 Apr 2018 07:40:35 -0400 X-IronPort-AV: E=Sophos;i="5.48,465,1517900400"; d="scan'208";a="13930664" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 18 Apr 2018 04:40:34 -0700 Received: from ajaysk-VirtualBox.mchp-main.com (10.10.76.4) by chn-sv-exch03.mchp-main.com (10.10.76.49) with Microsoft SMTP Server id 14.3.352.0; Wed, 18 Apr 2018 04:40:34 -0700 From: Ajay Singh To: CC: , , , , , , , Ajay Singh Subject: [PATCH 05/22] staging: wilc1000: refactor add_key() to avoid duplicated code Date: Wed, 18 Apr 2018 17:09:07 +0530 Message-ID: <1524051564-15497-6-git-send-email-ajay.kathat@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524051564-15497-1-git-send-email-ajay.kathat@microchip.com> References: <1524051564-15497-1-git-send-email-ajay.kathat@microchip.com> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Cleanup fixes by removing the duplicated code in actor add_key(). Signed-off-by: Ajay Singh --- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 64 ++++++++--------------- 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c index ac4cd58..329899f 100644 --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c @@ -922,8 +922,7 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, const u8 *rx_mic = NULL; const u8 *tx_mic = NULL; u8 mode = NO_ENCRYPT; - u8 gmode = NO_ENCRYPT; - u8 pmode = NO_ENCRYPT; + u8 op_mode; enum AUTHTYPE auth_type = ANY; struct wilc *wl; struct wilc_vif *vif; @@ -966,71 +965,54 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) { wilc_wfi_cfg_allocate_wpa_entry(priv, key_index); + if (params->key_len > 16 && + params->cipher == WLAN_CIPHER_SUITE_TKIP) { + tx_mic = params->key + 24; + rx_mic = params->key + 16; + keylen = params->key_len - 16; + } + if (!pairwise) { if (params->cipher == WLAN_CIPHER_SUITE_TKIP) - gmode = ENCRYPT_ENABLED | WPA | TKIP; + mode = ENCRYPT_ENABLED | WPA | TKIP; else - gmode = ENCRYPT_ENABLED | WPA2 | AES; + mode = ENCRYPT_ENABLED | WPA2 | AES; - priv->wilc_groupkey = gmode; + priv->wilc_groupkey = mode; - if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { - tx_mic = params->key + 24; - rx_mic = params->key + 16; - keylen = params->key_len - 16; - } wilc_wfi_cfg_copy_wpa_info(priv->wilc_gtk[key_index], params); - - wilc_add_rx_gtk(vif, params->key, keylen, - key_index, params->seq_len, - params->seq, rx_mic, - tx_mic, AP_MODE, gmode); - } else { if (params->cipher == WLAN_CIPHER_SUITE_TKIP) - pmode = ENCRYPT_ENABLED | WPA | TKIP; + mode = ENCRYPT_ENABLED | WPA | TKIP; else - pmode = priv->wilc_groupkey | AES; - - if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { - tx_mic = params->key + 24; - rx_mic = params->key + 16; - keylen = params->key_len - 16; - } + mode = priv->wilc_groupkey | AES; wilc_wfi_cfg_copy_wpa_info(priv->wilc_ptk[key_index], params); - - wilc_add_ptk(vif, params->key, keylen, - mac_addr, rx_mic, tx_mic, - AP_MODE, pmode, key_index); } - break; - } - - if (!pairwise) { - if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { + op_mode = AP_MODE; + } else { + if (params->key_len > 16 && + params->cipher == WLAN_CIPHER_SUITE_TKIP) { rx_mic = params->key + 24; tx_mic = params->key + 16; keylen = params->key_len - 16; } + op_mode = STATION_MODE; + } + + if (!pairwise) { wilc_add_rx_gtk(vif, params->key, keylen, key_index, params->seq_len, params->seq, rx_mic, - tx_mic, STATION_MODE, + tx_mic, op_mode, mode); } else { - if (params->key_len > 16 && params->cipher == WLAN_CIPHER_SUITE_TKIP) { - rx_mic = params->key + 24; - tx_mic = params->key + 16; - keylen = params->key_len - 16; - } - wilc_add_ptk(vif, params->key, keylen, mac_addr, rx_mic, tx_mic, - STATION_MODE, mode, key_index); + op_mode, mode, key_index); } break;