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=-9.0 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 D14FEC282C4 for ; Sat, 9 Feb 2019 07:12:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9270D20863 for ; Sat, 9 Feb 2019 07:12:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microchiptechnology.onmicrosoft.com header.i=@microchiptechnology.onmicrosoft.com header.b="HH7zdXiv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726873AbfBIHMq (ORCPT ); Sat, 9 Feb 2019 02:12:46 -0500 Received: from esa2.microchip.iphmx.com ([68.232.149.84]:58339 "EHLO esa2.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbfBIHMq (ORCPT ); Sat, 9 Feb 2019 02:12:46 -0500 X-IronPort-AV: E=Sophos;i="5.58,350,1544511600"; d="scan'208";a="26314823" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 09 Feb 2019 00:12:46 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.76.107) with Microsoft SMTP Server (TLS) id 14.3.352.0; Sat, 9 Feb 2019 00:12:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector1-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TW7HJh1aNJy2PTBOf2XAraCR8a+7F+Gjy+IqWkrr0+o=; b=HH7zdXivzTwwx1MzX9kB34fTVlFY0QPA+DBL+rheQEiLMCaPGi/UhW97xT2PZB9dXQxnY6whPudZkfDHtw0AO74OWfMAnV5mW7I9CUbTr4Gepql+xhQ24gWi5EXYKuU4FQdzCh4o+lHqZYV/VkKUEbD3ZeDSuXJU4y13UeXJoF0= Received: from BYAPR11MB2567.namprd11.prod.outlook.com (52.135.226.160) by BYAPR11MB3077.namprd11.prod.outlook.com (20.177.226.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1601.22; Sat, 9 Feb 2019 07:12:42 +0000 Received: from BYAPR11MB2567.namprd11.prod.outlook.com ([fe80::cc6d:bc31:d5b:a27d]) by BYAPR11MB2567.namprd11.prod.outlook.com ([fe80::cc6d:bc31:d5b:a27d%5]) with mapi id 15.20.1601.016; Sat, 9 Feb 2019 07:12:42 +0000 From: To: CC: , , , , , , , Subject: [PATCH 10/16] wilc1000: add wilc_mon.c Thread-Topic: [PATCH 10/16] wilc1000: add wilc_mon.c Thread-Index: AQHUwEbZDnFg/fzVzUOx7T+YlO1kLQ== Date: Sat, 9 Feb 2019 07:12:42 +0000 Message-ID: <1549696298-9795-11-git-send-email-ajay.kathat@microchip.com> References: <1549696298-9795-1-git-send-email-ajay.kathat@microchip.com> In-Reply-To: <1549696298-9795-1-git-send-email-ajay.kathat@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MA1PR0101CA0021.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::31) To BYAPR11MB2567.namprd11.prod.outlook.com (2603:10b6:a02:c5::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Ajay.Kathat@microchip.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [183.82.17.42] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BYAPR11MB3077;6:4Rr4QcZyyUwrNFdwf+rPPpTAu+oTFDteD7JUh8qPGT0DqjE9N5huJw1yPt3xFs9wRXypU6EwtIZNehrhf08RFS/EwErjuidNfLxA1LxfF5gT+Nd3eVvi9Zy4gnels7uQtGLSNAAsjllJPAFeSAow5EcTyhXK7MohCECuaGCV4SFlLVA4giVtVAcUiaVfj7GS5qpSrJTNSBX5M1VrDx9Dja+REXzeZDVVlY58ATr0YClQOt/HDbToYP2Rzg0cZ3S14pS8yF6xfqKy3kk2qdDYoBFSbwBciNJmWz7R3kLKafoY/2s7qGrLFxuJlDpeqQzsXNU7UAe0hLhPToHZfBqmAxLkpR0liJSUFLWxBGGY9HvGGUR7BYAUEdOukXku1pIPlmjFUghmtDg1JnL6XtyJeWeUhRNy4BF+KIckCDv7BCSZT3iMhud64rdUPRm3Gd1K8wyuTw1/wMzvhWcNFFoozA==;5:umBTABMOIsH2kQJUGbICri8WcbdjZlUzUhPqDYmOROcRwtKUufk/bFXI72fJumqH7YDxvpvlXUZa86PmuO6j2FCqbiy4EztbEDGlVHXlosUDI2G/xnpMpj8Apeb9B+/y0rhxmf/WJMPmScFGI0iyaPyIh/KoBG3Kj2Uxp36Wa4B2fERUEf886xOgWtKHgIjGhZ93D+Pv265u3D+tIe4bng==;7:kJkupKCd9qdgJBVEk6Eygekp8ceEEaQJNFBUCt5TDl7MMfk66k4nNjTYQ8oTeVRle+9QLYheaeBb+6fuBd4WioWL4BGN8CeXzsxbPWawbnpzDQsOEVsydZJrdY7Su/1FO2guFgE7qD/LZUWl8AKTQQ== x-ms-office365-filtering-correlation-id: e5433450-e13f-4038-fef0-08d68e5dfb72 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605077)(2017052603328)(7153060)(7193020);SRVR:BYAPR11MB3077; x-ms-traffictypediagnostic: BYAPR11MB3077: x-microsoft-antispam-prvs: x-forefront-prvs: 09435FCA72 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(346002)(376002)(396003)(39860400002)(136003)(366004)(199004)(189003)(60444003)(81166006)(8676002)(81156014)(97736004)(386003)(6506007)(14454004)(99286004)(305945005)(486006)(72206003)(6916009)(53936002)(102836004)(478600001)(7736002)(8936002)(26005)(186003)(36756003)(50226002)(54906003)(256004)(2616005)(476003)(11346002)(446003)(68736007)(105586002)(106356001)(5640700003)(2351001)(6116002)(3846002)(52116002)(316002)(6436002)(66066001)(107886003)(25786009)(4326008)(2501003)(2906002)(76176011)(78486014)(6486002)(86362001)(71200400001)(71190400001)(6512007);DIR:OUT;SFP:1101;SCL:1;SRVR:BYAPR11MB3077;H:BYAPR11MB2567.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: VPrjACT+ch4JkHbptkOwA5rTmoz6gtgKo8RoSvl73y6WTLLou8Xn5MtE8rPDeyema8F62+815Qlrj9IzYcQqtwJTqm+gtkw8RpigNB0WMOufbPWsuV/daj9pBYklZRJJMPg+oISN/xu2ISZKmyHcEMRURMJM4d1eyCDxPhisKhuemkG2PZhuqyvZ5lJrA0Wb1xzJ1ABYyquoLDwYV87WtNQ8kDYDkWYySKV6eFrjSEjLwQTC+GL9hyGmT3h3D6AskU0nShCyUnHCKL9a7kvoNhlZqo7x16QwaD2mYWJpe8wJsAuAcFhJs4/fAHZD5+V+A3nj7ENYJz8vxQf3gSNRue3eJhtduM510/pPDcOqVoBbLE0AzS/mjsV+JJSxXsgCbv2XS373Sb3ncZdIlxkHBvymGkRUd7pz2iLlcIMIG98= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: e5433450-e13f-4038-fef0-08d68e5dfb72 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Feb 2019 07:12:39.1924 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3077 X-OriginatorOrg: microchip.com Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Ajay Singh Moved '/driver/staging/wilc1000/wilc_mon.c' to 'drivers/net/wireless/microchip/wilc1000/'. Signed-off-by: Ajay Singh --- drivers/net/wireless/microchip/wilc1000/wilc_mon.c | 258 +++++++++++++++++= ++++ 1 file changed, 258 insertions(+) create mode 100644 drivers/net/wireless/microchip/wilc1000/wilc_mon.c diff --git a/drivers/net/wireless/microchip/wilc1000/wilc_mon.c b/drivers/n= et/wireless/microchip/wilc1000/wilc_mon.c new file mode 100644 index 0000000..9fe19a3 --- /dev/null +++ b/drivers/net/wireless/microchip/wilc1000/wilc_mon.c @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiari= es. + * All rights reserved. + */ + +#include "wilc_wfi_cfgoperations.h" + +struct wilc_wfi_radiotap_hdr { + struct ieee80211_radiotap_header hdr; + u8 rate; +} __packed; + +struct wilc_wfi_radiotap_cb_hdr { + struct ieee80211_radiotap_header hdr; + u8 rate; + u8 dump; + u16 tx_flags; +} __packed; + +#define TX_RADIOTAP_PRESENT ((1 << IEEE80211_RADIOTAP_RATE) | \ + (1 << IEEE80211_RADIOTAP_TX_FLAGS)) + +void wilc_wfi_monitor_rx(struct net_device *mon_dev, u8 *buff, u32 size) +{ + u32 header, pkt_offset; + struct sk_buff *skb =3D NULL; + struct wilc_wfi_radiotap_hdr *hdr; + struct wilc_wfi_radiotap_cb_hdr *cb_hdr; + + if (!mon_dev) + return; + + if (!netif_running(mon_dev)) + return; + + /* Get WILC header */ + memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET); + le32_to_cpus(&header); + /* + * The packet offset field contain info about what type of management + * the frame we are dealing with and ack status + */ + pkt_offset =3D GET_PKT_OFFSET(header); + + if (pkt_offset & IS_MANAGMEMENT_CALLBACK) { + /* hostapd callback mgmt frame */ + + skb =3D dev_alloc_skb(size + sizeof(*cb_hdr)); + if (!skb) + return; + + skb_put_data(skb, buff, size); + + cb_hdr =3D skb_push(skb, sizeof(*cb_hdr)); + memset(cb_hdr, 0, sizeof(*cb_hdr)); + + cb_hdr->hdr.it_version =3D 0; /* PKTHDR_RADIOTAP_VERSION; */ + + cb_hdr->hdr.it_len =3D cpu_to_le16(sizeof(*cb_hdr)); + + cb_hdr->hdr.it_present =3D cpu_to_le32(TX_RADIOTAP_PRESENT); + + cb_hdr->rate =3D 5; + + if (pkt_offset & IS_MGMT_STATUS_SUCCES) { + /* success */ + cb_hdr->tx_flags =3D IEEE80211_RADIOTAP_F_TX_RTS; + } else { + cb_hdr->tx_flags =3D IEEE80211_RADIOTAP_F_TX_FAIL; + } + + } else { + skb =3D dev_alloc_skb(size + sizeof(*hdr)); + + if (!skb) + return; + + skb_put_data(skb, buff, size); + hdr =3D skb_push(skb, sizeof(*hdr)); + memset(hdr, 0, sizeof(struct wilc_wfi_radiotap_hdr)); + hdr->hdr.it_version =3D 0; /* PKTHDR_RADIOTAP_VERSION; */ + hdr->hdr.it_len =3D cpu_to_le16(sizeof(*hdr)); + hdr->hdr.it_present =3D cpu_to_le32 + (1 << IEEE80211_RADIOTAP_RATE); + hdr->rate =3D 5; + } + + skb->dev =3D mon_dev; + skb_reset_mac_header(skb); + skb->ip_summed =3D CHECKSUM_UNNECESSARY; + skb->pkt_type =3D PACKET_OTHERHOST; + skb->protocol =3D htons(ETH_P_802_2); + memset(skb->cb, 0, sizeof(skb->cb)); + + netif_rx(skb); +} + +struct tx_complete_mon_data { + int size; + void *buff; +}; + +static void mgmt_tx_complete(void *priv, int status) +{ + struct tx_complete_mon_data *pv_data =3D priv; + /* + * in case of fully hosting mode, the freeing will be done + * in response to the cfg packet + */ + kfree(pv_data->buff); + + kfree(pv_data); +} + +static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len) +{ + struct tx_complete_mon_data *mgmt_tx =3D NULL; + + if (!dev) + return -EFAULT; + + netif_stop_queue(dev); + mgmt_tx =3D kmalloc(sizeof(*mgmt_tx), GFP_ATOMIC); + if (!mgmt_tx) + return -ENOMEM; + + mgmt_tx->buff =3D kmemdup(buf, len, GFP_ATOMIC); + if (!mgmt_tx->buff) { + kfree(mgmt_tx); + return -ENOMEM; + } + + mgmt_tx->size =3D len; + + wilc_wlan_txq_add_mgmt_pkt(dev, mgmt_tx, mgmt_tx->buff, mgmt_tx->size, + mgmt_tx_complete); + + netif_wake_queue(dev); + return 0; +} + +static netdev_tx_t wilc_wfi_mon_xmit(struct sk_buff *skb, + struct net_device *dev) +{ + u32 rtap_len, ret =3D 0; + struct wilc_wfi_mon_priv *mon_priv; + struct sk_buff *skb2; + struct wilc_wfi_radiotap_cb_hdr *cb_hdr; + u8 srcadd[ETH_ALEN]; + u8 bssid[ETH_ALEN]; + + mon_priv =3D netdev_priv(dev); + if (!mon_priv) + return -EFAULT; + + rtap_len =3D ieee80211_get_radiotap_len(skb->data); + if (skb->len < rtap_len) + return -1; + + skb_pull(skb, rtap_len); + + if (skb->data[0] =3D=3D 0xc0 && is_broadcast_ether_addr(&skb->data[4])) { + skb2 =3D dev_alloc_skb(skb->len + sizeof(*cb_hdr)); + if (!skb2) + return -ENOMEM; + + skb_put_data(skb2, skb->data, skb->len); + + cb_hdr =3D skb_push(skb2, sizeof(*cb_hdr)); + memset(cb_hdr, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr)); + + cb_hdr->hdr.it_version =3D 0; /* PKTHDR_RADIOTAP_VERSION; */ + + cb_hdr->hdr.it_len =3D cpu_to_le16(sizeof(*cb_hdr)); + + cb_hdr->hdr.it_present =3D cpu_to_le32(TX_RADIOTAP_PRESENT); + + cb_hdr->rate =3D 5; + cb_hdr->tx_flags =3D 0x0004; + + skb2->dev =3D dev; + skb_reset_mac_header(skb2); + skb2->ip_summed =3D CHECKSUM_UNNECESSARY; + skb2->pkt_type =3D PACKET_OTHERHOST; + skb2->protocol =3D htons(ETH_P_802_2); + memset(skb2->cb, 0, sizeof(skb2->cb)); + + netif_rx(skb2); + + return 0; + } + skb->dev =3D mon_priv->real_ndev; + + ether_addr_copy(srcadd, &skb->data[10]); + ether_addr_copy(bssid, &skb->data[16]); + /* + * Identify if data or mgmt packet, if source address and bssid + * fields are equal send it to mgmt frames handler + */ + if (!(memcmp(srcadd, bssid, 6))) { + ret =3D mon_mgmt_tx(mon_priv->real_ndev, skb->data, skb->len); + if (ret) + netdev_err(dev, "fail to mgmt tx\n"); + dev_kfree_skb(skb); + } else { + ret =3D wilc_mac_xmit(skb, mon_priv->real_ndev); + } + + return ret; +} + +static const struct net_device_ops wilc_wfi_netdev_ops =3D { + .ndo_start_xmit =3D wilc_wfi_mon_xmit, + +}; + +struct net_device *wilc_wfi_init_mon_interface(struct wilc *wl, + const char *name, + struct net_device *real_dev) +{ + struct wilc_wfi_mon_priv *priv; + + /*If monitor interface is already initialized, return it*/ + if (wl->monitor_dev) + return wl->monitor_dev; + + wl->monitor_dev =3D alloc_etherdev(sizeof(struct wilc_wfi_mon_priv)); + if (!wl->monitor_dev) + return NULL; + + wl->monitor_dev->type =3D ARPHRD_IEEE80211_RADIOTAP; + strncpy(wl->monitor_dev->name, name, IFNAMSIZ); + wl->monitor_dev->name[IFNAMSIZ - 1] =3D 0; + wl->monitor_dev->netdev_ops =3D &wilc_wfi_netdev_ops; + + if (register_netdevice(wl->monitor_dev)) { + netdev_err(real_dev, "register_netdevice failed\n"); + return NULL; + } + priv =3D netdev_priv(wl->monitor_dev); + if (!priv) + return NULL; + + priv->real_ndev =3D real_dev; + + return wl->monitor_dev; +} + +void wilc_wfi_deinit_mon_interface(struct wilc *wl) +{ + if (!wl->monitor_dev) + return; + + unregister_netdev(wl->monitor_dev); + free_netdev(wl->monitor_dev); + wl->monitor_dev =3D NULL; +} --=20 2.7.4