linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ajay Singh <ajay.kathat@microchip.com>
To: <linux-wireless@vger.kernel.org>
Cc: <kvalo@codeaurora.org>, <gregkh@linuxfoundation.org>,
	<ganesh.krishna@microchip.com>, <aditya.shankar@microchip.com>,
	<venkateswara.kaja@microchip.com>, <claudiu.beznea@microchip.com>,
	<adham.abozaeid@microchip.com>,
	Ajay Singh <ajay.kathat@microchip.com>
Subject: [PATCH 14/19] wilc: add linux_mon.c
Date: Wed, 26 Sep 2018 15:55:20 +0530	[thread overview]
Message-ID: <1537957525-11467-15-git-send-email-ajay.kathat@microchip.com> (raw)
In-Reply-To: <1537957525-11467-1-git-send-email-ajay.kathat@microchip.com>

Moved '/driver/staging/wilc1000/linux_mon.c' to
'drivers/net/wireless/microchip/wilc/'.

Signed-off-by: Ajay Singh <ajay.kathat@microchip.com>
---
 drivers/net/wireless/microchip/wilc/linux_mon.c | 273 ++++++++++++++++++++++++
 1 file changed, 273 insertions(+)
 create mode 100644 drivers/net/wireless/microchip/wilc/linux_mon.c

diff --git a/drivers/net/wireless/microchip/wilc/linux_mon.c b/drivers/net/wireless/microchip/wilc/linux_mon.c
new file mode 100644
index 0000000..a634468
--- /dev/null
+++ b/drivers/net/wireless/microchip/wilc/linux_mon.c
@@ -0,0 +1,273 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
+ * 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;
+
+static struct net_device *wilc_wfi_mon; /* global monitor netdev */
+
+static u8 srcadd[6];
+static u8 bssid[6];
+
+#define IEEE80211_RADIOTAP_F_TX_RTS	0x0004  /* used rts/cts handshake */
+#define IEEE80211_RADIOTAP_F_TX_FAIL	0x0001  /* failed due to excessive*/
+
+#define TX_RADIOTAP_PRESENT ((1 << IEEE80211_RADIOTAP_RATE) |	\
+			     (1 << IEEE80211_RADIOTAP_TX_FLAGS))
+
+void wilc_wfi_monitor_rx(u8 *buff, u32 size)
+{
+	u32 header, pkt_offset;
+	struct sk_buff *skb = NULL;
+	struct wilc_wfi_radiotap_hdr *hdr;
+	struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
+
+	if (!wilc_wfi_mon)
+		return;
+
+	if (!netif_running(wilc_wfi_mon))
+		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 = GET_PKT_OFFSET(header);
+
+	if (pkt_offset & IS_MANAGMEMENT_CALLBACK) {
+		/* hostapd callback mgmt frame */
+
+		skb = dev_alloc_skb(size + sizeof(*cb_hdr));
+		if (!skb)
+			return;
+
+		skb_put_data(skb, buff, size);
+
+		cb_hdr = skb_push(skb, sizeof(*cb_hdr));
+		memset(cb_hdr, 0, sizeof(*cb_hdr));
+
+		cb_hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */
+
+		cb_hdr->hdr.it_len = cpu_to_le16(sizeof(*cb_hdr));
+
+		cb_hdr->hdr.it_present = cpu_to_le32(TX_RADIOTAP_PRESENT);
+
+		cb_hdr->rate = 5;
+
+		if (pkt_offset & IS_MGMT_STATUS_SUCCES)	{
+			/* success */
+			cb_hdr->tx_flags = IEEE80211_RADIOTAP_F_TX_RTS;
+		} else {
+			cb_hdr->tx_flags = IEEE80211_RADIOTAP_F_TX_FAIL;
+		}
+
+	} else {
+		skb = dev_alloc_skb(size + sizeof(*hdr));
+
+		if (!skb)
+			return;
+
+		skb_put_data(skb, buff, size);
+		hdr = skb_push(skb, sizeof(*hdr));
+		memset(hdr, 0, sizeof(struct wilc_wfi_radiotap_hdr));
+		hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */
+		hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
+		hdr->hdr.it_present = cpu_to_le32
+				(1 << IEEE80211_RADIOTAP_RATE);
+		hdr->rate = 5;
+	}
+
+	skb->dev = wilc_wfi_mon;
+	skb_reset_mac_header(skb);
+	skb->ip_summed = CHECKSUM_UNNECESSARY;
+	skb->pkt_type = PACKET_OTHERHOST;
+	skb->protocol = 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 = 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 = NULL;
+
+	if (!dev)
+		return -EFAULT;
+
+	netif_stop_queue(dev);
+	mgmt_tx = kmalloc(sizeof(*mgmt_tx), GFP_ATOMIC);
+	if (!mgmt_tx)
+		return -ENOMEM;
+
+	mgmt_tx->buff = kmemdup(buf, len, GFP_ATOMIC);
+	if (!mgmt_tx->buff) {
+		kfree(mgmt_tx);
+		return -ENOMEM;
+	}
+
+	mgmt_tx->size = 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 = 0;
+	struct wilc_wfi_mon_priv  *mon_priv;
+	struct sk_buff *skb2;
+	struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
+
+	if (!wilc_wfi_mon)
+		return -EFAULT;
+
+	mon_priv = netdev_priv(wilc_wfi_mon);
+	if (!mon_priv)
+		return -EFAULT;
+	rtap_len = ieee80211_get_radiotap_len(skb->data);
+	if (skb->len < rtap_len)
+		return -1;
+
+	skb_pull(skb, rtap_len);
+
+	if (skb->data[0] == 0xc0 && is_broadcast_ether_addr(&skb->data[4])) {
+		skb2 = dev_alloc_skb(skb->len + sizeof(*cb_hdr));
+		if (!skb2)
+			return -ENOMEM;
+
+		skb_put_data(skb2, skb->data, skb->len);
+
+		cb_hdr = skb_push(skb2, sizeof(*cb_hdr));
+		memset(cb_hdr, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr));
+
+		cb_hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */
+
+		cb_hdr->hdr.it_len = cpu_to_le16(sizeof(*cb_hdr));
+
+		cb_hdr->hdr.it_present = cpu_to_le32(TX_RADIOTAP_PRESENT);
+
+		cb_hdr->rate = 5;
+		cb_hdr->tx_flags = 0x0004;
+
+		skb2->dev = wilc_wfi_mon;
+		skb_reset_mac_header(skb2);
+		skb2->ip_summed = CHECKSUM_UNNECESSARY;
+		skb2->pkt_type = PACKET_OTHERHOST;
+		skb2->protocol = htons(ETH_P_802_2);
+		memset(skb2->cb, 0, sizeof(skb2->cb));
+
+		netif_rx(skb2);
+
+		return 0;
+	}
+	skb->dev = mon_priv->real_ndev;
+
+	memcpy(srcadd, &skb->data[10], 6);
+	memcpy(bssid, &skb->data[16], 6);
+	/*
+	 * 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 = 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 = wilc_mac_xmit(skb, mon_priv->real_ndev);
+	}
+
+	return ret;
+}
+
+static const struct net_device_ops wilc_wfi_netdev_ops = {
+	.ndo_start_xmit         = wilc_wfi_mon_xmit,
+
+};
+
+struct net_device *wilc_wfi_init_mon_interface(const char *name,
+					       struct net_device *real_dev)
+{
+	struct wilc_wfi_mon_priv *priv;
+
+	/*If monitor interface is already initialized, return it*/
+	if (wilc_wfi_mon)
+		return wilc_wfi_mon;
+
+	wilc_wfi_mon = alloc_etherdev(sizeof(struct wilc_wfi_mon_priv));
+	if (!wilc_wfi_mon)
+		return NULL;
+	wilc_wfi_mon->type = ARPHRD_IEEE80211_RADIOTAP;
+	strncpy(wilc_wfi_mon->name, name, IFNAMSIZ);
+	wilc_wfi_mon->name[IFNAMSIZ - 1] = 0;
+	wilc_wfi_mon->netdev_ops = &wilc_wfi_netdev_ops;
+
+	if (register_netdevice(wilc_wfi_mon)) {
+		netdev_err(real_dev, "register_netdevice failed\n");
+		return NULL;
+	}
+	priv = netdev_priv(wilc_wfi_mon);
+	if (!priv)
+		return NULL;
+
+	priv->real_ndev = real_dev;
+
+	return wilc_wfi_mon;
+}
+
+void wilc_wfi_deinit_mon_interface(void)
+{
+	bool rollback_lock = false;
+
+	if (wilc_wfi_mon) {
+		if (rtnl_is_locked()) {
+			rtnl_unlock();
+			rollback_lock = true;
+		}
+		unregister_netdev(wilc_wfi_mon);
+
+		if (rollback_lock) {
+			rtnl_lock();
+			rollback_lock = false;
+		}
+		wilc_wfi_mon = NULL;
+	}
+}
-- 
2.7.4


  parent reply	other threads:[~2018-09-26 10:26 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-26 10:25 [RFC 00/19] wilc: added driver for wilc module Ajay Singh
2018-09-26 10:25 ` [PATCH 01/19] wilc: add coreconfigurator.h Ajay Singh
2018-09-26 10:25 ` [PATCH 02/19] wilc: add coreconfigurator.c Ajay Singh
2018-10-08 14:16   ` Johannes Berg
2018-10-09  9:42     ` Ajay Singh
2018-10-09 10:05       ` Johannes Berg
2018-09-26 10:25 ` [PATCH 03/19] wilc: add host_interface.h Ajay Singh
2018-10-08 14:20   ` Johannes Berg
2018-10-09 10:34     ` Ajay Singh
2018-10-09 10:36       ` Johannes Berg
2018-10-09 11:44         ` Ajay Singh
2018-10-09 11:46           ` Johannes Berg
2018-10-09 12:18             ` Ajay Singh
2018-10-09 18:36               ` Adham.Abozaeid
2018-10-09 19:14                 ` Johannes Berg
2018-10-09 20:01                   ` Adham.Abozaeid
2018-10-09 20:02                     ` Johannes Berg
2018-10-09 20:06                       ` Adham.Abozaeid
2018-10-29 14:56           ` Kalle Valo
2018-10-30  3:20             ` Ajay.Kathat
2018-09-26 10:25 ` [PATCH 04/19] wilc: add host_interface.c Ajay Singh
2018-10-08 14:31   ` Johannes Berg
2018-10-10 20:06     ` Adham.Abozaeid
2018-10-11  7:01       ` Johannes Berg
2018-10-12 22:08         ` Adham.Abozaeid
2018-10-18  8:23           ` Johannes Berg
2018-10-18 18:30             ` Adham.Abozaeid
2018-10-19  7:02               ` Johannes Berg
2018-10-19 20:53                 ` Adham.Abozaeid
2018-10-29 20:10                   ` Johannes Berg
2018-10-29 21:32                     ` Adham.Abozaeid
2018-10-29 21:33                       ` Johannes Berg
2018-10-11  6:57     ` Ajay Singh
2018-10-10 20:14   ` Johannes Berg
2018-10-12 21:55     ` Adham.Abozaeid
2018-10-18  8:23       ` Johannes Berg
2018-09-26 10:25 ` [PATCH 05/19] wilc: add wilc_wlan_if.h Ajay Singh
2018-10-08 14:33   ` Johannes Berg
2018-10-11  6:59     ` Ajay Singh
2018-09-26 10:25 ` [PATCH 06/19] wilc: add wilc_wlan_cfg.h Ajay Singh
2018-09-26 10:25 ` [PATCH 07/19] wilc: add wilc_wlan_cfg.c Ajay Singh
2018-09-26 10:25 ` [PATCH 08/19] wilc: add wilc_wlan.h Ajay Singh
2018-09-26 10:25 ` [PATCH 09/19] wilc: add wilc_wlan.c Ajay Singh
2018-09-26 10:25 ` [PATCH 10/19] wilc: add wilc_wfi_netdevice.h Ajay Singh
2018-09-26 10:25 ` [PATCH 11/19] wilc: add wilc_wfi_cfgoperations.h Ajay Singh
2018-09-26 10:25 ` [PATCH 12/19] wilc: add wilc_wfi_cfgoperations.c Ajay Singh
2018-10-08 14:57   ` Johannes Berg
2018-10-09  4:23     ` Adham.Abozaeid
2018-10-09  7:55       ` Johannes Berg
2018-10-09 17:15         ` Adham.Abozaeid
2018-10-19 21:47           ` Adham.Abozaeid
2018-10-29 20:11             ` Johannes Berg
2018-10-29 21:43               ` Adham.Abozaeid
2018-09-26 10:25 ` [PATCH 13/19] wilc: add linux_wlan.c Ajay Singh
2018-10-08 14:41   ` Johannes Berg
2018-10-11  7:00     ` Ajay Singh
2018-10-11  7:03       ` Johannes Berg
2018-10-11  7:26         ` Ajay Singh
2018-09-26 10:25 ` Ajay Singh [this message]
2018-10-08 14:44   ` [PATCH 14/19] wilc: add linux_mon.c Johannes Berg
2018-10-11  7:12     ` Ajay Singh
2018-10-11  7:15       ` Johannes Berg
2018-09-26 10:25 ` [PATCH 15/19] wilc: add wilc_spi.c Ajay Singh
2018-09-26 10:25 ` [PATCH 16/19] wilc: add wilc_sdio.c Ajay Singh
2018-09-26 10:25 ` [PATCH 17/19] wilc: updated DT device binding for wilc device Ajay Singh
2018-09-26 10:25 ` [PATCH 18/19] wilc: add Makefile and Kconfig files for wilc compilation Ajay Singh
2018-09-26 10:25 ` [PATCH 19/19] wilc: added wilc module compilation in wireless Makefile & Kconfig Ajay Singh
2018-10-06 12:45 ` [RFC 00/19] wilc: added driver for wilc module Kalle Valo
2018-10-08  5:17   ` Ajay Singh
2018-10-08  7:38     ` Kalle Valo
2018-10-08 18:34       ` Adham.Abozaeid
2018-11-15 14:11         ` Kalle Valo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1537957525-11467-15-git-send-email-ajay.kathat@microchip.com \
    --to=ajay.kathat@microchip.com \
    --cc=adham.abozaeid@microchip.com \
    --cc=aditya.shankar@microchip.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=ganesh.krishna@microchip.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=venkateswara.kaja@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).