Skip to contentSkip to conversation

ath5k: fix injection in monitor mode

PATCH Superseded Bruno Randolf 4 participants 9 messages Mar 1, 2010 – Mar 2, 2010 Atheros ATH5K wireless driver

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 ath5k: fix injection in monitor mode

injected frames have to use AR5K_PKT_TYPE_NORMAL, otherwise the hardware thinks it can mess with the contents of the frame - e.g. update the TSF of an injected beacon. injected frames should be sent as they are provided.

---

 drivers/net/wireless/ath/ath5k/base.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
drivers/net/wireless/ath/ath5k/base.c +10 -1
index 2468c64..904d7f0 100644
@@ -1285,6 +1285,7 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
 	u16 cts_rate = 0;
 	u16 duration = 0;
 	u8 rc_flags;
+	enum ath5k_pkt_type pkt_type;
 
 	flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK;
 
@@ -1322,9 +1323,17 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
 		duration = le16_to_cpu(ieee80211_ctstoself_duration(sc->hw,
 			sc->vif, pktlen, info));
 	}
+
+	/* we don't want the hardware to mess with injected frames in monitor
+	 * mode (e.g. update TSF in beacons) */
+	if (sc->opmode == NL80211_IFTYPE_MONITOR)
+		pkt_type = AR5K_PKT_TYPE_NORMAL;
+	else
+		pkt_type = get_hw_packet_type(skb);
+
 	ret = ah->ah_setup_tx_desc(ah, ds, pktlen,
 		ieee80211_get_hdrlen_from_skb(skb),
-		get_hw_packet_type(skb),
+		pkt_type,
 		(sc->power_level * 2),
 		hw_rate,
 		info->control.rates[0].count, keyidx, ah->ah_tx_ant, flags,
#1 lore raw

PATCH 2/5 ath5k: add antenna statistics and debugfs file for antenna settings

keep statistics about which antenna was used for TX and RX. this is used only for debugging right now, but might have other applications later.

add a new file 'antenna' in debugfs (/sys/kernel/debug/ath5k/phy0/antenna) to show antenna use statistics and antenna diversity related register values. it can also be used to set the antenna mode until we have proper support for that in iw:
- echo diversity > antenna: use default antenna mode (RX and TX diversity)
- echo fixed-a > antenna: use fixed antenna A for RX and TX
- echo fixed-b > antenna: use fixed antenna B for RX and TX
- echo clear > antenna: reset antenna statistics

---

 drivers/net/wireless/ath/ath5k/base.c  |   11 +++
 drivers/net/wireless/ath/ath5k/base.h  |    3 +
 drivers/net/wireless/ath/ath5k/debug.c |  111 ++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath/ath5k/debug.h |    1 
 4 files changed, 126 insertions(+), 0 deletions(-)
drivers/net/wireless/ath/ath5k/base.c +11 -0
index 904d7f0..79b548c 100644
@@ -1951,6 +1951,12 @@ accept:
 		rxs->signal = rxs->noise + rs.rs_rssi;
 
 		rxs->antenna = rs.rs_antenna;
+
+		if (rs.rs_antenna > 0 && rs.rs_antenna < 5)
+			sc->ant_stats_rx[rs.rs_antenna]++;
+		else
+			sc->ant_stats_rx[0]++; /* invalid */
+
 		rxs->rate_idx = ath5k_hw_to_driver_rix(sc, rs.rs_rate);
 		rxs->flag |= ath5k_rx_decrypted(sc, ds, skb, &rs);
 
@@ -2038,6 +2044,11 @@ ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq)
 			info->status.ack_signal = ts.ts_rssi;
 		}
 
+		if (ts.ts_antenna > 0 && ts.ts_antenna < 5)
+			sc->ant_stats_tx[ts.ts_antenna]++;
+		else
+			sc->ant_stats_tx[0]++; /* invalid */
+
 		ieee80211_tx_status(sc->hw, skb);
 
 		spin_lock(&sc->txbuflock);
drivers/net/wireless/ath/ath5k/base.h +3 -0
index 7e1a88a..2318fa6 100644
@@ -191,6 +191,9 @@ struct ath5k_softc {
 	int 			power_level;	/* Requested tx power in dbm */
 	bool			assoc;		/* associate state */
 	bool			enable_beacon;	/* true if beacons are on */
+
+	int			ant_stats_rx[5];/* antenna use statistics RX */
+	int			ant_stats_tx[5];/* antenna use statistics TX */
 };
 
 #define ath5k_hw_hasbssidmask(_ah) \
drivers/net/wireless/ath/ath5k/debug.c +111 -0

135 lines not on this page · raw message

drivers/net/wireless/ath/ath5k/debug.h +1 -0
index 66f69f0..0186127 100644
@@ -74,6 +74,7 @@ struct ath5k_dbg_info {
 	struct dentry		*debugfs_registers;
 	struct dentry		*debugfs_beacon;
 	struct dentry		*debugfs_reset;
+	struct dentry		*debugfs_antenna;
 };
 
 /**
#2 lore raw

PATCH 3/5 ath5k: use fixed antenna for tx descriptors

In reply to Bruno Randolf

when using a fixed antenna we should use the antenna number in all tx descriptors, otherwise the hardware will sometimes send the frame out on the other antenna. it seems like the hardware does not always respect the default antenna and diversity settings (esp. AR5K_STA_ID1_DEFAULT_ANTENNA).

also i would like to note that antenna diversity does not always work correctly on 5414 (at least) when only one antenna is connected: for example all frames might be received on antenna A but still the HW tries to send on antenna B some times, causing packet loss.

this is both verified with the antenna statistics output of the previous patch and a spectrum analyzer.

---

 drivers/net/wireless/ath/ath5k/phy.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath5k/phy.c +2 -2
index 72474c0..ffe253a 100644
@@ -1873,7 +1873,7 @@ ath5k_hw_set_antenna_mode(struct ath5k_hw *ah, u8 ant_mode)
 		break;
 	case AR5K_ANTMODE_FIXED_A:
 		def_ant = 1;
-		tx_ant = 0;
+		tx_ant = 1;
 		use_def_for_tx = true;
 		update_def_on_tx = false;
 		use_def_for_rts = true;
@@ -1882,7 +1882,7 @@ ath5k_hw_set_antenna_mode(struct ath5k_hw *ah, u8 ant_mode)
 		break;
 	case AR5K_ANTMODE_FIXED_B:
 		def_ant = 2;
-		tx_ant = 0;
+		tx_ant = 2;
 		use_def_for_tx = true;
 		update_def_on_tx = false;
 		use_def_for_rts = true;
#3 lore raw

PATCH 4/5 ath5k: preserve antenna settings

In reply to Bruno Randolf

save antenna settings and preserve across resets.

---

 drivers/net/wireless/ath/ath5k/attach.c |    1 +
 drivers/net/wireless/ath/ath5k/base.c   |    2 +-
 drivers/net/wireless/ath/ath5k/phy.c    |    1 +
 3 files changed, 3 insertions(+), 1 deletions(-)
drivers/net/wireless/ath/ath5k/attach.c +1 -0
index 4228444..c8bb102 100644
@@ -123,6 +123,7 @@ int ath5k_hw_attach(struct ath5k_softc *sc)
 	ah->ah_cw_min = AR5K_TUNE_CWMIN;
 	ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
 	ah->ah_software_retry = false;
+	ah->ah_ant_mode = AR5K_ANTMODE_DEFAULT;
 
 	/*
 	 * Find the mac version
drivers/net/wireless/ath/ath5k/base.c +1 -1
index 79b548c..c22bc85 100644
@@ -2925,7 +2925,7 @@ ath5k_config(struct ieee80211_hw *hw, u32 changed)
 	 * then we must allow the user to set how many tx antennas we
 	 * have available
 	 */
-	ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
+	ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
 
 unlock:
 	mutex_unlock(&sc->lock);
drivers/net/wireless/ath/ath5k/phy.c +1 -0
index ffe253a..3fa4f4d 100644
@@ -1929,6 +1929,7 @@ ath5k_hw_set_antenna_mode(struct ath5k_hw *ah, u8 ant_mode)
 
 	ah->ah_tx_ant = tx_ant;
 	ah->ah_ant_mode = ant_mode;
+	ah->ah_def_ant = def_ant;
 
 	sta_id1 |= use_def_for_tx ? AR5K_STA_ID1_DEFAULT_ANTENNA : 0;
 	sta_id1 |= update_def_on_tx ? AR5K_STA_ID1_DESC_ANTENNA : 0;
#4 lore raw

PATCH 5/5 ath5k: fix TSF reset

In reply to Bruno Randolf

to reset the TSF, AR5K_BEACON_RESET_TSF has to be 1, not 0. also we have a function for that so use it.

---

 drivers/net/wireless/ath/ath5k/reset.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath5k/reset.c +3 -4
index a35a7db..c780b55 100644
@@ -1379,11 +1379,10 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
 		ath5k_hw_set_sleep_clock(ah, true);
 
 	/*
-	 * Disable beacons and reset the register
+	 * Disable beacons and reset the TSF
 	 */
-	AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
-			AR5K_BEACON_RESET_TSF);
-
+	AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
+	ath5k_hw_reset_tsf(ah);
 	return 0;
 }
 
#5 lore raw
In reply to Bruno Randolf

please ignore this one, sorry ;(

bruno

Quoted 46 lines · On Monday 01 March 2010 20:59:03 Bruno Randolf wrote:

injected frames have to use AR5K_PKT_TYPE_NORMAL, otherwise the hardware thinks it can mess with the contents of the frame - e.g. update the TSF of an injected beacon. injected frames should be sent as they are provided.

---

 drivers/net/wireless/ath/ath5k/base.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/net/wireless/ath/ath5k/base.c index 2468c64..904d7f0 100644

drivers/net/wireless/ath/ath5k/base.c +10 -2
@@ -1285,6 +1285,7 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct
 ath5k_buf *bf, u16 cts_rate = 0;
 	u16 duration = 0;
 	u8 rc_flags;
+	enum ath5k_pkt_type pkt_type;
 
 	flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK;
 
@@ -1322,9 +1323,17 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct
 ath5k_buf *bf, duration = le16_to_cpu(ieee80211_ctstoself_duration(sc->hw,
 			sc->vif, pktlen, info));
 	}
+
+	/* we don't want the hardware to mess with injected frames in monitor
+	 * mode (e.g. update TSF in beacons) */
+	if (sc->opmode == NL80211_IFTYPE_MONITOR)
+		pkt_type = AR5K_PKT_TYPE_NORMAL;
+	else
+		pkt_type = get_hw_packet_type(skb);
+
 	ret = ah->ah_setup_tx_desc(ah, ds, pktlen,
 		ieee80211_get_hdrlen_from_skb(skb),
-		get_hw_packet_type(skb),
+		pkt_type,
 		(sc->power_level * 2),
 		hw_rate,
 		info->control.rates[0].count, keyidx, ah->ah_tx_ant, flags,
 
--

To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 4 lines · Bruno Randolf

please ignore this one, sorry ;(

bruno

This one is cool & needed for testing IBSS merges. I have pretty much the same in my tree.

Regards,
Benoit

Quoted 55 lines · On Monday 01 March 2010 20:59:03 Bruno Randolf wrote:
Quoted 44 lines

injected frames have to use AR5K_PKT_TYPE_NORMAL, otherwise the hardware thinks it can mess with the contents of the frame - e.g. update the TSF of an injected beacon. injected frames should be sent as they are provided.

---

 drivers/net/wireless/ath/ath5k/base.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/net/wireless/ath/ath5k/base.c index 2468c64..904d7f0 100644

drivers/net/wireless/ath/ath5k/base.c +10 -2
@@ -1285,6 +1285,7 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct
 ath5k_buf *bf, u16 cts_rate = 0;
 	u16 duration = 0;
 	u8 rc_flags;
+	enum ath5k_pkt_type pkt_type;
 
 	flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK;
 
@@ -1322,9 +1323,17 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct
 ath5k_buf *bf, duration = le16_to_cpu(ieee80211_ctstoself_duration(sc->hw,
 			sc->vif, pktlen, info));
 	}
+
+	/* we don't want the hardware to mess with injected frames in monitor
+	 * mode (e.g. update TSF in beacons) */
+	if (sc->opmode == NL80211_IFTYPE_MONITOR)
+		pkt_type = AR5K_PKT_TYPE_NORMAL;
+	else
+		pkt_type = get_hw_packet_type(skb);
+
 	ret = ah->ah_setup_tx_desc(ah, ds, pktlen,
 		ieee80211_get_hdrlen_from_skb(skb),
-		get_hw_packet_type(skb),
+		pkt_type,
 		(sc->power_level * 2),
 		hw_rate,
 		info->control.rates[0].count, keyidx, ah->ah_tx_ant, flags,
 
--
Quoted 4 lines

To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

_______________________________________________
ath5k-devel mailing list
[email protected]
https://lists.ath5k.org/mailman/listinfo/ath5k-devel

#7 lore raw
Quoted 7 lines · On Tuesday 02 March 2010 06:26:48 Benoit PAPILLAULT wrote:
Quoted 3 lines · Bruno Randolf

please ignore this one, sorry ;(

bruno

This one is cool & needed for testing IBSS merges. I have pretty much the same in my tree.

yes - only sc->opmode is never set. i'll come up with a patch to fix that.

bruno

Quoted 66 lines

Regards,
Benoit

Quoted 63 lines · On Monday 01 March 2010 20:59:03 Bruno Randolf wrote:
Quoted 54 lines

injected frames have to use AR5K_PKT_TYPE_NORMAL, otherwise the hardware thinks it can mess with the contents of the frame - e.g. update the TSF of an injected beacon. injected frames should be sent as they are provided.

---

 drivers/net/wireless/ath/ath5k/base.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/net/wireless/ath/ath5k/base.c index 2468c64..904d7f0 100644

drivers/net/wireless/ath/ath5k/base.c +1 -0
@@ -1285,6 +1285,7 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct
 ath5k_buf *bf, u16 cts_rate = 0;
 
 	u16 duration = 0;
 	u8 rc_flags;
 
+	enum ath5k_pkt_type pkt_type;
 
drivers/net/wireless/ath/ath5k/base.c +0 -0
 	flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK;
@@ -1322,9 +1323,17 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct

ath5k_buf *bf, duration =
le16_to_cpu(ieee80211_ctstoself_duration(sc->hw,

drivers/net/wireless/ath/ath5k/base.c +9 -2
 			sc->vif, pktlen, info));
 
 	}
 
+
+	/* we don't want the hardware to mess with injected frames in monitor
+	 * mode (e.g. update TSF in beacons) */
+	if (sc->opmode == NL80211_IFTYPE_MONITOR)
+		pkt_type = AR5K_PKT_TYPE_NORMAL;
+	else
+		pkt_type = get_hw_packet_type(skb);
+
 
 	ret = ah->ah_setup_tx_desc(ah, ds, pktlen,
 
 		ieee80211_get_hdrlen_from_skb(skb),
 
-		get_hw_packet_type(skb),
+		pkt_type,
 
 		(sc->power_level * 2),
 		hw_rate,
 		info->control.rates[0].count, keyidx, ah->ah_tx_ant, flags,
 
--
Quoted 3 lines

To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

_______________________________________________
ath5k-devel mailing list
[email protected]
https://lists.ath5k.org/mailman/listinfo/ath5k-devel

#8 lore raw

Actually, the right thing to check is info->flags & IEEE80211_TX_CTL_INJECTED - you shouldn't check the mode to determine injectedness.

Quoted 85 lines · Bruno Randolf
Quoted 7 lines · On Tuesday 02 March 2010 06:26:48 Benoit PAPILLAULT wrote:
Quoted 3 lines · Bruno Randolf

please ignore this one, sorry ;(

bruno

This one is cool & needed for testing IBSS merges. I have pretty much the same in my tree.

yes - only sc->opmode is never set. i'll come up with a patch to fix that.

bruno

Quoted 66 lines

Regards,
Benoit

Quoted 63 lines · On Monday 01 March 2010 20:59:03 Bruno Randolf wrote:
Quoted 49 lines

injected frames have to use AR5K_PKT_TYPE_NORMAL, otherwise the hardware thinks it can mess with the contents of the frame - e.g. update the TSF of an injected beacon. injected frames should be sent as they are provided.

---

 drivers/net/wireless/ath/ath5k/base.c |   11 ++++++++++-

 1 files changed, 10 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/net/wireless/ath/ath5k/base.c index 2468c64..904d7f0 100644

drivers/net/wireless/ath/ath5k/base.c +1 -0
@@ -1285,6 +1285,7 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct
 ath5k_buf *bf, u16 cts_rate = 0;
 
    u16 duration = 0;
    u8 rc_flags;
 
+  enum ath5k_pkt_type pkt_type;
 

   flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK;

drivers/net/wireless/ath/ath5k/base.c +0 -0
@@ -1322,9 +1323,17 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct

ath5k_buf *bf, duration =
le16_to_cpu(ieee80211_ctstoself_duration(sc->hw,

                   sc->vif, pktlen, info));

   }

drivers/net/wireless/ath/ath5k/base.c +8 -0
+
+  /* we don't want the hardware to mess with injected frames in monitor
+   * mode (e.g. update TSF in beacons) */
+  if (sc->opmode == NL80211_IFTYPE_MONITOR)
+          pkt_type = AR5K_PKT_TYPE_NORMAL;
+  else
+          pkt_type = get_hw_packet_type(skb);
+

   ret = ah->ah_setup_tx_desc(ah, ds, pktlen,

           ieee80211_get_hdrlen_from_skb(skb),

-          get_hw_packet_type(skb),
+          pkt_type,

Quoted 8 lines

           (sc->power_level * 2),
           hw_rate,
           info->control.rates[0].count, keyidx, ah->ah_tx_ant, flags,

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at  http://vger.kernel.org/majordomo-info.html

_______________________________________________
ath5k-devel mailing list
[email protected]
https://lists.ath5k.org/mailman/listinfo/ath5k-devel

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Vista: [V]iruses, [I]ntruders, [S]pyware, [T]rojans and [A]dware. :-)