From patchwork Thu Sep 19 13:52:39 2019 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: 11152433 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0EEE416B1 for ; Thu, 19 Sep 2019 13:53:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C71F821D6C for ; Thu, 19 Sep 2019 13:53:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=silabs.onmicrosoft.com header.i=@silabs.onmicrosoft.com header.b="IfsNLz5h" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390591AbfISNxe (ORCPT ); Thu, 19 Sep 2019 09:53:34 -0400 Received: from mail-eopbgr700050.outbound.protection.outlook.com ([40.107.70.50]:52064 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2403855AbfISNwy (ORCPT ); Thu, 19 Sep 2019 09:52:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UnUXwM0keSxav1D8L1z8rmQjssjPk0RkRqrLbztJSd3YrpqYWSTVGS2IlysWd5mJws5g4Wkk0P70uMmF5kDlxlF04pZDfzKWHIThHE37aZGY0uy308YuHQdxtwkyTf8lBzEfueI31en2GV9lxD5Rdz8hJQskJBZWcJQHUrCD8wC59bUl/VOZKMszWl6a8BMsdw+NIYOOgoArqSZ9se105bK3Bb1qxruY1lGOTDZrrazUYgRoAO9okNkbKbZNOrpcbjB+qusHA66RlBUxF3CAZTDR8ZmFq2JJ89fj+vJctaysQigAxMiegKmc5712ygeFNxL/VrbozvYzWTM6WHywxg== 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=FuS2otXZYhv5vPjSXbr2OYHe4M5DwuNOKQpSQcbgvK4=; b=GXXQHeh9v821AB24o/mC5SZK5nuv7T1qiYnK5iWn67zKL03yteOoMBB1lp+WRcGv43EtcAMORHasC/q8LJY9whSwvPfDdMNX24lRhfpwTSrJY2z/I4c38xXa/yIoxinMmajnTU0HM9ZksH0r8lW3l2Z/PtzDfA/zPRLZsCxamkmNUNmusUeRKOnEBOxg+JJxFPbVgBZjnp2dnIn4MuSaFF/GILMka59OTavt4Ss+O5PWdNZIl2l5tMUUe6I8x3QUzYY/MqPWgEJrXr5DVW8s+ej8FcZL1wStBiHSNV5366UlgN1S9tV0scz1rrntC+h+kQfc/Cluhaw8j94ITOh1XA== 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=FuS2otXZYhv5vPjSXbr2OYHe4M5DwuNOKQpSQcbgvK4=; b=IfsNLz5hs8Dz2irWTxB/JUfKRUmwdgOzT6ciySKlY98uAcC/VpEJy0CX7v/ILnDZgm+3NZ317B+BTYJwqA9e+jnOds/xe+Iw4kdDXTxxVtP2cHt2QAfhZbxXQAp/GARSZWIAbEJ0iYxO0dVB04ahE/Ed6Fcs2rcZZG+vHYQFVE4= Received: from MN2PR11MB4063.namprd11.prod.outlook.com (20.179.149.217) by MN2PR11MB4400.namprd11.prod.outlook.com (52.135.37.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2263.20; Thu, 19 Sep 2019 13:52:41 +0000 Received: from MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::45dc:e073:4446:4bf8]) by MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::45dc:e073:4446:4bf8%3]) with mapi id 15.20.2263.023; Thu, 19 Sep 2019 13:52:41 +0000 From: Jerome Pouiller To: "devel@driverdev.osuosl.org" , "linux-wireless@vger.kernel.org" CC: "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , David Le Goff , Jerome Pouiller Subject: [PATCH v2 17/20] staging: wfx: allow to receive 802.11 frames Thread-Topic: [PATCH v2 17/20] staging: wfx: allow to receive 802.11 frames Thread-Index: AQHVbvGABbymuPOZiU6PKG1f05FAww== Date: Thu, 19 Sep 2019 13:52:39 +0000 Message-ID: <20190919135220.30663-18-Jerome.Pouiller@silabs.com> References: <20190919135220.30663-1-Jerome.Pouiller@silabs.com> In-Reply-To: <20190919135220.30663-1-Jerome.Pouiller@silabs.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jerome.Pouiller@silabs.com; x-originating-ip: [37.71.187.125] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b87ba7e0-77c6-4c6c-9eec-08d73d08a3c0 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600167)(711020)(4605104)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:MN2PR11MB4400; x-ms-traffictypediagnostic: MN2PR11MB4400: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:608; x-forefront-prvs: 016572D96D x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(1496009)(376002)(39850400004)(136003)(366004)(396003)(346002)(189003)(43544003)(199004)(3846002)(76176011)(8676002)(76116006)(476003)(25786009)(2616005)(6116002)(54906003)(71190400001)(6436002)(102836004)(6486002)(36756003)(186003)(71200400001)(26005)(305945005)(6512007)(99286004)(6506007)(91956017)(7736002)(446003)(8936002)(256004)(81156014)(14444005)(2906002)(66066001)(107886003)(4326008)(86362001)(14454004)(478600001)(64756008)(81166006)(2501003)(486006)(66574012)(316002)(66946007)(66446008)(66556008)(5660300002)(11346002)(66476007)(1076003)(110136005);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR11MB4400;H:MN2PR11MB4063.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: silabs.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: xHWBeaxZIKLAehSNWPt3OIo8oqglIXTKC5ZowfuIEilDlmFV49EYf3AC+6Jj/x6UeuEqsaS3AwRPwZ0eAn9TfI6Ki+0W8YjCqkSYdA+RzsdJkVzLCoYZelJQgTraaAxTPAI+SyD+Eyc4WVOyjEQHRGMHIJpE3td1MDQzMyn9KJAW8j1KJuQY9RdFtPoYlSNIvFQwjwcPJWLRE1P2qrtWDfxnxVSEuUntKC3AGj9HTcJOPYfeAO4ymf12638AaINo2ccNaTCB0/MfWGbQmrev5XBLX2SQNo+waHQRO5fHMsySuxfEAupQcdVGo5OKGAk+qIaSbdYA/ItNbAMOusX9ld5DPBlDKj8W5WFSNEwvnl3Ok73SfkaJFKZIq2sNK28FiNYn9mxZ1QtJLtch9CcH0cdszoqoev56jAz+lZbjRxI= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: b87ba7e0-77c6-4c6c-9eec-08d73d08a3c0 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Sep 2019 13:52:39.9904 (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: T/WbvipT0rC837PGxute3bYOBpihueklbikZ25NdbtR/457sgLGggS5gsBfLnLsSr1lzGK7zzPs0KlCjZdeJmw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4400 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Jérôme Pouiller Again, this task is more complex than it should since driver try to handle itself power saving of stations. Signed-off-by: Jérôme Pouiller --- drivers/staging/wfx/Makefile | 1 + drivers/staging/wfx/data_rx.c | 182 ++++++++++++++++++++++++++++++++++ drivers/staging/wfx/data_rx.h | 18 ++++ drivers/staging/wfx/hif_rx.c | 23 +++++ 4 files changed, 224 insertions(+) create mode 100644 drivers/staging/wfx/data_rx.c create mode 100644 drivers/staging/wfx/data_rx.h diff --git a/drivers/staging/wfx/Makefile b/drivers/staging/wfx/Makefile index d5ac9fafd1f1..d9e21515d08e 100644 --- a/drivers/staging/wfx/Makefile +++ b/drivers/staging/wfx/Makefile @@ -11,6 +11,7 @@ wfx-y := \ hif_rx.o \ queue.o \ data_tx.o \ + data_rx.o \ sta.o \ main.o \ sta.o \ diff --git a/drivers/staging/wfx/data_rx.c b/drivers/staging/wfx/data_rx.c new file mode 100644 index 000000000000..3b3117b2edac --- /dev/null +++ b/drivers/staging/wfx/data_rx.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Datapath implementation. + * + * Copyright (c) 2017-2019, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#include +#include + +#include "data_rx.h" +#include "wfx.h" +#include "bh.h" +#include "sta.h" + +static int wfx_handle_pspoll(struct wfx_vif *wvif, struct sk_buff *skb) +{ + struct ieee80211_sta *sta; + struct ieee80211_pspoll *pspoll = (struct ieee80211_pspoll *)skb->data; + int link_id = 0; + u32 pspoll_mask = 0; + int i; + + if (!ether_addr_equal(wvif->vif->addr, pspoll->bssid)) + return 1; + + rcu_read_lock(); + sta = ieee80211_find_sta(wvif->vif, pspoll->ta); + if (sta) + link_id = ((struct wfx_sta_priv *) &sta->drv_priv)->link_id; + rcu_read_unlock(); + if (link_id) + pspoll_mask = BIT(link_id); + else + return 1; + + wvif->pspoll_mask |= pspoll_mask; + /* Do not report pspols if data for given link id is queued already. */ + for (i = 0; i < IEEE80211_NUM_ACS; ++i) { + if (wfx_tx_queue_get_num_queued(&wvif->wdev->tx_queue[i], + pspoll_mask)) { + wfx_bh_request_tx(wvif->wdev); + return 1; + } + } + return 0; +} + +static int wfx_drop_encrypt_data(struct wfx_dev *wdev, struct hif_ind_rx *arg, struct sk_buff *skb) +{ + struct ieee80211_hdr *frame = (struct ieee80211_hdr *) skb->data; + size_t hdrlen = ieee80211_hdrlen(frame->frame_control); + size_t iv_len, icv_len; + + /* Oops... There is no fast way to ask mac80211 about + * IV/ICV lengths. Even defineas are not exposed. + */ + switch (arg->rx_flags.encryp) { + case HIF_RI_FLAGS_WEP_ENCRYPTED: + iv_len = 4 /* WEP_IV_LEN */; + icv_len = 4 /* WEP_ICV_LEN */; + break; + case HIF_RI_FLAGS_TKIP_ENCRYPTED: + iv_len = 8 /* TKIP_IV_LEN */; + icv_len = 4 /* TKIP_ICV_LEN */ + + 8 /*MICHAEL_MIC_LEN*/; + break; + case HIF_RI_FLAGS_AES_ENCRYPTED: + iv_len = 8 /* CCMP_HDR_LEN */; + icv_len = 8 /* CCMP_MIC_LEN */; + break; + case HIF_RI_FLAGS_WAPI_ENCRYPTED: + iv_len = 18 /* WAPI_HDR_LEN */; + icv_len = 16 /* WAPI_MIC_LEN */; + break; + default: + dev_err(wdev->dev, "unknown encryption type %d\n", + arg->rx_flags.encryp); + return -EIO; + } + + /* Firmware strips ICV in case of MIC failure. */ + if (arg->status == HIF_STATUS_MICFAILURE) + icv_len = 0; + + if (skb->len < hdrlen + iv_len + icv_len) { + dev_warn(wdev->dev, "malformed SDU received\n"); + return -EIO; + } + + /* Remove IV, ICV and MIC */ + skb_trim(skb, skb->len - icv_len); + memmove(skb->data + iv_len, skb->data, hdrlen); + skb_pull(skb, iv_len); + return 0; + +} + +void wfx_rx_cb(struct wfx_vif *wvif, struct hif_ind_rx *arg, struct sk_buff *skb) +{ + int link_id = arg->rx_flags.peer_sta_id; + struct ieee80211_rx_status *hdr = IEEE80211_SKB_RXCB(skb); + struct ieee80211_hdr *frame = (struct ieee80211_hdr *) skb->data; + struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) skb->data; + struct wfx_link_entry *entry = NULL; + bool early_data = false; + + memset(hdr, 0, sizeof(*hdr)); + + // FIXME: Why do we drop these frames? + if (!arg->rcpi_rssi && + (ieee80211_is_probe_resp(frame->frame_control) || + ieee80211_is_beacon(frame->frame_control))) + goto drop; + + if (link_id && link_id <= WFX_MAX_STA_IN_AP_MODE) { + entry = &wvif->link_id_db[link_id - 1]; + entry->timestamp = jiffies; + if (entry->status == WFX_LINK_SOFT && ieee80211_is_data(frame->frame_control)) + early_data = true; + } + + if (arg->status == HIF_STATUS_MICFAILURE) + hdr->flag |= RX_FLAG_MMIC_ERROR; + else if (arg->status) + goto drop; + + if (skb->len < sizeof(struct ieee80211_pspoll)) { + dev_warn(wvif->wdev->dev, "malformed SDU received\n"); + goto drop; + } + + if (ieee80211_is_pspoll(frame->frame_control)) + if (wfx_handle_pspoll(wvif, skb)) + goto drop; + + hdr->band = NL80211_BAND_2GHZ; + hdr->freq = ieee80211_channel_to_frequency(arg->channel_number, hdr->band); + + if (arg->rxed_rate >= 14) { + hdr->encoding = RX_ENC_HT; + hdr->rate_idx = arg->rxed_rate - 14; + } else if (arg->rxed_rate >= 4) { + hdr->rate_idx = arg->rxed_rate - 2; + } else { + hdr->rate_idx = arg->rxed_rate; + } + + hdr->signal = arg->rcpi_rssi / 2 - 110; + hdr->antenna = 0; + + if (arg->rx_flags.encryp) { + if (wfx_drop_encrypt_data(wvif->wdev, arg, skb)) + goto drop; + hdr->flag |= RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED; + if (arg->rx_flags.encryp == HIF_RI_FLAGS_TKIP_ENCRYPTED) + hdr->flag |= RX_FLAG_MMIC_STRIPPED; + } + + /* Filter block ACK negotiation: fully controlled by firmware */ + if (ieee80211_is_action(frame->frame_control) + && arg->rx_flags.match_uc_addr + && mgmt->u.action.category == WLAN_CATEGORY_BACK) + goto drop; + + if (early_data) { + spin_lock_bh(&wvif->ps_state_lock); + /* Double-check status with lock held */ + if (entry->status == WFX_LINK_SOFT) + skb_queue_tail(&entry->rx_queue, skb); + else + ieee80211_rx_irqsafe(wvif->wdev->hw, skb); + spin_unlock_bh(&wvif->ps_state_lock); + } else { + ieee80211_rx_irqsafe(wvif->wdev->hw, skb); + } + + return; + +drop: + dev_kfree_skb(skb); +} diff --git a/drivers/staging/wfx/data_rx.h b/drivers/staging/wfx/data_rx.h new file mode 100644 index 000000000000..b44d15268f83 --- /dev/null +++ b/drivers/staging/wfx/data_rx.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Datapath implementation. + * + * Copyright (c) 2017-2019, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#ifndef WFX_DATA_RX_H +#define WFX_DATA_RX_H + +#include "hif_api_cmd.h" + +struct wfx_vif; +struct sk_buff; + +void wfx_rx_cb(struct wfx_vif *wvif, struct hif_ind_rx *arg, struct sk_buff *skb); + +#endif /* WFX_DATA_RX_H */ diff --git a/drivers/staging/wfx/hif_rx.c b/drivers/staging/wfx/hif_rx.c index 97c4c2f082fb..c07984b0535d 100644 --- a/drivers/staging/wfx/hif_rx.c +++ b/drivers/staging/wfx/hif_rx.c @@ -11,6 +11,7 @@ #include "hif_rx.h" #include "wfx.h" +#include "data_rx.h" #include "secure_link.h" #include "hif_api_cmd.h" @@ -127,6 +128,21 @@ static int hif_keys_indication(struct wfx_dev *wdev, struct hif_msg *hif, void * return 0; } +static int hif_receive_indication(struct wfx_dev *wdev, struct hif_msg *hif, void *buf, struct sk_buff *skb) +{ + struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); + struct hif_ind_rx *body = buf; + + if (!wvif) { + dev_warn(wdev->dev, "ignore rx data for non existant vif %d\n", hif->interface); + return 0; + } + skb_pull(skb, sizeof(struct hif_msg) + sizeof(struct hif_ind_rx)); + wfx_rx_cb(wvif, body, skb); + + return 0; +} + static int hif_join_complete_indication(struct wfx_dev *wdev, struct hif_msg *hif, void *buf) { struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); @@ -218,6 +234,8 @@ static const struct { { HIF_IND_ID_GENERIC, hif_generic_indication }, { HIF_IND_ID_ERROR, hif_error_indication }, { HIF_IND_ID_EXCEPTION, hif_exception_indication }, + // FIXME: allocate skb_p from hif_receive_indication and make it generic + //{ HIF_IND_ID_RX, hif_receive_indication }, }; void wfx_handle_rx(struct wfx_dev *wdev, struct sk_buff *skb) @@ -226,6 +244,11 @@ void wfx_handle_rx(struct wfx_dev *wdev, struct sk_buff *skb) struct hif_msg *hif = (struct hif_msg *) skb->data; int hif_id = hif->id; + if (hif_id == HIF_IND_ID_RX) { + // hif_receive_indication take care of skb lifetime + hif_receive_indication(wdev, hif, hif->body, skb); + return; + } // Note: mutex_is_lock cause an implicit memory barrier that protect // buf_send if (mutex_is_locked(&wdev->hif_cmd.lock)