linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mac80211: Split sending tx'ed frames to monitor interfaces into its own function
@ 2015-09-02 11:23 Helmut Schaa
  2015-09-02 11:23 ` [PATCH 2/2] mac80211: Copy tx'ed beacons to monitor mode Helmut Schaa
  0 siblings, 1 reply; 5+ messages in thread
From: Helmut Schaa @ 2015-09-02 11:23 UTC (permalink / raw)
  To: linux-wireless; +Cc: johannes, nbd, Helmut Schaa

This allows ieee80211_tx_monitor to be used directly for sending 802.11 frames
to all monitor interfaces.

Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
---
 net/mac80211/ieee80211_i.h |   3 ++
 net/mac80211/status.c      | 108 +++++++++++++++++++++++++--------------------
 2 files changed, 62 insertions(+), 49 deletions(-)

diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 6e52659..36552de 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1641,6 +1641,9 @@ void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
 struct sk_buff *
 ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
 			      struct sk_buff *skb, u32 info_flags);
+void ieee80211_tx_monitor(struct ieee80211_local *local, struct sk_buff *skb,
+			  struct ieee80211_supported_band *sband,
+			  int retry_count, int shift, bool send_to_cooked);
 
 void ieee80211_check_fast_xmit(struct sta_info *sta);
 void ieee80211_check_fast_xmit_all(struct ieee80211_local *local);
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index 8ba5832..98fd04c 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -668,16 +668,70 @@ void ieee80211_tx_status_noskb(struct ieee80211_hw *hw,
 }
 EXPORT_SYMBOL(ieee80211_tx_status_noskb);
 
-void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
+void ieee80211_tx_monitor(struct ieee80211_local *local, struct sk_buff *skb,
+			  struct ieee80211_supported_band *sband,
+			  int retry_count, int shift, bool send_to_cooked)
 {
 	struct sk_buff *skb2;
+	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+	struct ieee80211_sub_if_data *sdata;
+	struct net_device *prev_dev = NULL;
+	int rtap_len;
+
+	/* send frame to monitor interfaces now */
+	rtap_len = ieee80211_tx_radiotap_len(info);
+	if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
+		pr_err("ieee80211_tx_status: headroom too small\n");
+		dev_kfree_skb(skb);
+		return;
+	}
+	ieee80211_add_tx_radiotap_header(local, sband, skb, retry_count,
+					 rtap_len, shift);
+
+	/* XXX: is this sufficient for BPF? */
+	skb_set_mac_header(skb, 0);
+	skb->ip_summed = CHECKSUM_UNNECESSARY;
+	skb->pkt_type = PACKET_OTHERHOST;
+	skb->protocol = htons(ETH_P_802_2);
+	memset(skb->cb, 0, sizeof(skb->cb));
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
+		if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
+			if (!ieee80211_sdata_running(sdata))
+				continue;
+
+			if ((sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) &&
+			    !send_to_cooked)
+				continue;
+
+			if (prev_dev) {
+				skb2 = skb_clone(skb, GFP_ATOMIC);
+				if (skb2) {
+					skb2->dev = prev_dev;
+					netif_rx(skb2);
+				}
+			}
+
+			prev_dev = sdata->dev;
+		}
+	}
+	if (prev_dev) {
+		skb->dev = prev_dev;
+		netif_rx(skb);
+		skb = NULL;
+	}
+	rcu_read_unlock();
+	dev_kfree_skb(skb);
+}
+
+void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
 	struct ieee80211_local *local = hw_to_local(hw);
 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
 	__le16 fc;
 	struct ieee80211_supported_band *sband;
-	struct ieee80211_sub_if_data *sdata;
-	struct net_device *prev_dev = NULL;
 	struct sta_info *sta;
 	struct rhash_head *tmp;
 	int retry_count;
@@ -685,7 +739,6 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
 	bool send_to_cooked;
 	bool acked;
 	struct ieee80211_bar *bar;
-	int rtap_len;
 	int shift = 0;
 	int tid = IEEE80211_NUM_TIDS;
 	const struct bucket_table *tbl;
@@ -878,51 +931,8 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
 		return;
 	}
 
-	/* send frame to monitor interfaces now */
-	rtap_len = ieee80211_tx_radiotap_len(info);
-	if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
-		pr_err("ieee80211_tx_status: headroom too small\n");
-		dev_kfree_skb(skb);
-		return;
-	}
-	ieee80211_add_tx_radiotap_header(local, sband, skb, retry_count,
-					 rtap_len, shift);
-
-	/* XXX: is this sufficient for BPF? */
-	skb_set_mac_header(skb, 0);
-	skb->ip_summed = CHECKSUM_UNNECESSARY;
-	skb->pkt_type = PACKET_OTHERHOST;
-	skb->protocol = htons(ETH_P_802_2);
-	memset(skb->cb, 0, sizeof(skb->cb));
-
-	rcu_read_lock();
-	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
-		if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
-			if (!ieee80211_sdata_running(sdata))
-				continue;
-
-			if ((sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) &&
-			    !send_to_cooked)
-				continue;
-
-			if (prev_dev) {
-				skb2 = skb_clone(skb, GFP_ATOMIC);
-				if (skb2) {
-					skb2->dev = prev_dev;
-					netif_rx(skb2);
-				}
-			}
-
-			prev_dev = sdata->dev;
-		}
-	}
-	if (prev_dev) {
-		skb->dev = prev_dev;
-		netif_rx(skb);
-		skb = NULL;
-	}
-	rcu_read_unlock();
-	dev_kfree_skb(skb);
+	/* send to monitor interfaces */
+	ieee80211_tx_monitor(local, skb, sband, retry_count, shift, send_to_cooked);
 }
 EXPORT_SYMBOL(ieee80211_tx_status);
 
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mac80211: Copy tx'ed beacons to monitor mode
  2015-09-02 11:23 [PATCH 1/2] mac80211: Split sending tx'ed frames to monitor interfaces into its own function Helmut Schaa
@ 2015-09-02 11:23 ` Helmut Schaa
  2015-09-08 16:42   ` Johannes Berg
  2015-09-09  7:46   ` [PATCHv2] " Helmut Schaa
  0 siblings, 2 replies; 5+ messages in thread
From: Helmut Schaa @ 2015-09-02 11:23 UTC (permalink / raw)
  To: linux-wireless; +Cc: johannes, nbd, Helmut Schaa

When debugging wireless powersave issues on the AP side it's quite helpful
to see our own beacons that are transmitted by the hardware/driver. However,
this is not that easy since beacons don't pass through the regular TX queues.

Preferably drivers would call ieee80211_tx_status also for tx'ed beacons
but that's not always possible. Hence, just send a copy of each beacon
generated by ieee80211_beacon_get_tim to monitor devices when they are
getting fetched by the driver.

Also add a HW flag IEEE80211_HW_BEACON_TX_STATUS that can be used by
drivers to indicate that they report TX status for beacons.

Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
---
Changes since RFC:
* don't send beacons to cooked monitors
* avoid assignment within if condition
* Introduce IEEE80211_HW_BEACON_TX_STATUS

 include/net/mac80211.h |  4 ++++
 net/mac80211/debugfs.c |  1 +
 net/mac80211/tx.c      | 13 +++++++++++++
 3 files changed, 18 insertions(+)

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index e3314e5..b136ac5 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -1892,6 +1892,9 @@ struct ieee80211_txq {
  * @IEEE80211_HW_TDLS_WIDER_BW: The device/driver supports wider bandwidth
  *	than then BSS bandwidth for a TDLS link on the base channel.
  *
+ * @IEEE80211_HW_BEACON_TX_STATUS: The device/driver provides TX status
+ *	for sent beacons.
+ *
  * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
  */
 enum ieee80211_hw_flags {
@@ -1925,6 +1928,7 @@ enum ieee80211_hw_flags {
 	IEEE80211_HW_SUPPORTS_CLONED_SKBS,
 	IEEE80211_HW_SINGLE_SCAN_ON_ALL_BANDS,
 	IEEE80211_HW_TDLS_WIDER_BW,
+	IEEE80211_HW_BEACON_TX_STATUS,
 
 	/* keep last, obviously */
 	NUM_IEEE80211_HW_FLAGS
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index ced6bf3..d55f5ba 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -123,6 +123,7 @@ static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = {
 	FLAG(SUPPORTS_CLONED_SKBS),
 	FLAG(SINGLE_SCAN_ON_ALL_BANDS),
 	FLAG(TDLS_WIDER_BW),
+	FLAG(BEACON_TX_STATUS),
 
 	/* keep last for the build bug below */
 	(void *)0x1
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 84e0e8c..88720cb 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -3512,6 +3512,8 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
 {
 	struct ieee80211_mutable_offsets offs = {};
 	struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false);
+	struct ieee80211_supported_band *sband;
+	int shift;
 
 	if (tim_offset)
 		*tim_offset = offs.tim_offset;
@@ -3519,6 +3521,17 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
 	if (tim_length)
 		*tim_length = offs.tim_length;
 
+	/* send a copy to monitor interfaces */
+	if (!ieee80211_hw_check(hw, BEACON_TX_STATUS) &&
+	    hw_to_local(hw)->monitors) {
+		struct sk_buff *copy = skb_copy(bcn, GFP_ATOMIC);
+		if (copy) {
+			shift = ieee80211_vif_get_shift(vif);
+			sband = hw->wiphy->bands[ieee80211_get_sdata_band(vif_to_sdata(vif))];
+			ieee80211_tx_monitor(hw_to_local(hw), copy, sband, 1, shift, false);
+		}
+	}
+
 	return bcn;
 }
 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mac80211: Copy tx'ed beacons to monitor mode
  2015-09-02 11:23 ` [PATCH 2/2] mac80211: Copy tx'ed beacons to monitor mode Helmut Schaa
@ 2015-09-08 16:42   ` Johannes Berg
  2015-09-09  7:46   ` [PATCHv2] " Helmut Schaa
  1 sibling, 0 replies; 5+ messages in thread
From: Johannes Berg @ 2015-09-08 16:42 UTC (permalink / raw)
  To: Helmut Schaa, linux-wireless; +Cc: nbd

I applied patch 1, but 

> +	/* send a copy to monitor interfaces */
> +	if (!ieee80211_hw_check(hw, BEACON_TX_STATUS) &&
> +	    hw_to_local(hw)->monitors) {
> +		struct sk_buff *copy = skb_copy(bcn, GFP_ATOMIC);
> +		if (copy) {
> +			shift = ieee80211_vif_get_shift(vif);
> +			sband = hw->wiphy
> ->bands[ieee80211_get_sdata_band(vif_to_sdata(vif))];
> +			ieee80211_tx_monitor(hw_to_local(hw), copy, 
> sband, 1, shift, false);
> +		}
> +	}
> +
> 
Please add a blank line after declarations and try to get shorter lines
here.

johannes

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCHv2] mac80211: Copy tx'ed beacons to monitor mode
  2015-09-02 11:23 ` [PATCH 2/2] mac80211: Copy tx'ed beacons to monitor mode Helmut Schaa
  2015-09-08 16:42   ` Johannes Berg
@ 2015-09-09  7:46   ` Helmut Schaa
  2015-09-18  9:07     ` Johannes Berg
  1 sibling, 1 reply; 5+ messages in thread
From: Helmut Schaa @ 2015-09-09  7:46 UTC (permalink / raw)
  To: linux-wireless; +Cc: johannes, nbd, Helmut Schaa

When debugging wireless powersave issues on the AP side it's quite helpful
to see our own beacons that are transmitted by the hardware/driver. However,
this is not that easy since beacons don't pass through the regular TX queues.

Preferably drivers would call ieee80211_tx_status also for tx'ed beacons
but that's not always possible. Hence, just send a copy of each beacon
generated by ieee80211_beacon_get_tim to monitor devices when they are
getting fetched by the driver.

Also add a HW flag IEEE80211_HW_BEACON_TX_STATUS that can be used by
drivers to indicate that they report TX status for beacons.

Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
---

Changes since RFC:
* don't send beacons to cooked monitors
* avoid assignment within if condition
* Introduce IEEE80211_HW_BEACON_TX_STATUS

Changes since v1:
* Invert logic to get shorter lines (<80 chars)

 include/net/mac80211.h |  4 ++++
 net/mac80211/debugfs.c |  1 +
 net/mac80211/tx.c      | 16 ++++++++++++++++
 3 files changed, 21 insertions(+)

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index e3314e5..b136ac5 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -1892,6 +1892,9 @@ struct ieee80211_txq {
  * @IEEE80211_HW_TDLS_WIDER_BW: The device/driver supports wider bandwidth
  *	than then BSS bandwidth for a TDLS link on the base channel.
  *
+ * @IEEE80211_HW_BEACON_TX_STATUS: The device/driver provides TX status
+ *	for sent beacons.
+ *
  * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
  */
 enum ieee80211_hw_flags {
@@ -1925,6 +1928,7 @@ enum ieee80211_hw_flags {
 	IEEE80211_HW_SUPPORTS_CLONED_SKBS,
 	IEEE80211_HW_SINGLE_SCAN_ON_ALL_BANDS,
 	IEEE80211_HW_TDLS_WIDER_BW,
+	IEEE80211_HW_BEACON_TX_STATUS,
 
 	/* keep last, obviously */
 	NUM_IEEE80211_HW_FLAGS
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index ced6bf3..d55f5ba 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -123,6 +123,7 @@ static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = {
 	FLAG(SUPPORTS_CLONED_SKBS),
 	FLAG(SINGLE_SCAN_ON_ALL_BANDS),
 	FLAG(TDLS_WIDER_BW),
+	FLAG(BEACON_TX_STATUS),
 
 	/* keep last for the build bug below */
 	(void *)0x1
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 84e0e8c..e482f3e 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -3512,6 +3512,9 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
 {
 	struct ieee80211_mutable_offsets offs = {};
 	struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false);
+	struct sk_buff *copy;
+	struct ieee80211_supported_band *sband;
+	int shift;
 
 	if (tim_offset)
 		*tim_offset = offs.tim_offset;
@@ -3519,6 +3522,19 @@ struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
 	if (tim_length)
 		*tim_length = offs.tim_length;
 
+	if (ieee80211_hw_check(hw, BEACON_TX_STATUS) ||
+	    !hw_to_local(hw)->monitors)
+		return bcn;
+
+	/* send a copy to monitor interfaces */
+	copy = skb_copy(bcn, GFP_ATOMIC);
+	if (!copy)
+		return bcn;
+
+	shift = ieee80211_vif_get_shift(vif);
+	sband = hw->wiphy->bands[ieee80211_get_sdata_band(vif_to_sdata(vif))];
+	ieee80211_tx_monitor(hw_to_local(hw), copy, sband, 1, shift, false);
+
 	return bcn;
 }
 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCHv2] mac80211: Copy tx'ed beacons to monitor mode
  2015-09-09  7:46   ` [PATCHv2] " Helmut Schaa
@ 2015-09-18  9:07     ` Johannes Berg
  0 siblings, 0 replies; 5+ messages in thread
From: Johannes Berg @ 2015-09-18  9:07 UTC (permalink / raw)
  To: Helmut Schaa, linux-wireless; +Cc: nbd

On Wed, 2015-09-09 at 09:46 +0200, Helmut Schaa wrote:
> When debugging wireless powersave issues on the AP side it's quite 
> helpful
> to see our own beacons that are transmitted by the hardware/driver. 
> However,
> this is not that easy since beacons don't pass through the regular TX 
> queues.
> 
> Preferably drivers would call ieee80211_tx_status also for tx'ed 
> beacons
> but that's not always possible. Hence, just send a copy of each 
> beacon
> generated by ieee80211_beacon_get_tim to monitor devices when they 
> are
> getting fetched by the driver.
> 
> Also add a HW flag IEEE80211_HW_BEACON_TX_STATUS that can be used by
> drivers to indicate that they report TX status for beacons.
> 
Applied.

johannes

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-18  9:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-02 11:23 [PATCH 1/2] mac80211: Split sending tx'ed frames to monitor interfaces into its own function Helmut Schaa
2015-09-02 11:23 ` [PATCH 2/2] mac80211: Copy tx'ed beacons to monitor mode Helmut Schaa
2015-09-08 16:42   ` Johannes Berg
2015-09-09  7:46   ` [PATCHv2] " Helmut Schaa
2015-09-18  9:07     ` Johannes Berg

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).