Skip to contentSkip to conversation

ath5k: Fix TX/RX padding for all frames

PATCH In review Benoit Papillault 2 participants 4 messages Feb 27, 2010 1 message not in the archive Atheros ATH5K wireless driver

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): --to [email protected] --to [email protected] \

#1 lore raw

PATCH 1/1 ath5k: Fix TX/RX padding for all frames

Currently, the padding position is based on ieee80211_get_hdrlen_from_skb(). This is not correct since the HW does padding on RX (and expect the same padding to be present on TX) at the following position :

- management : 24 + 6 if 4-addr format

- control    : 24 + 6 if 4-addr format
- data       : 24 + 6 if 4-addr format + 2 if QoS
- invalid    : 24 + 6 if 4-addr format

whereas ieee80211_get_hdrlen_from_skb() is :

- management : 24

- control    : 16 except for ACK/CTS where it is 10
- data       : 24 + 6 if 4-addr format + 2 if QoS + 2 if QoS & order
- invalid    : 24

So, correct frames are not affected : management frames do not use 4-addr format, control frames have no body and invalid frames are ... not valid by definition. However, in order to use monitor interface for debugging purpose, one must be able to send/receive any frames, be it correct or not. Such frames are affected by incorrect padding.

Moreover, since padding is added on TX, we need to remove it before calling ieee80211_tx_status. This affect TX packets received by monitor interfaces.

It has been tested between an ath5k based card (AR5212) and an ar9170usb based card (netgear WNDA3100) using a frame generator and a monitor interface for each card.

---
 drivers/net/wireless/ath/ath5k/ath5k.h |    9 +---
 drivers/net/wireless/ath/ath5k/base.c  |   70 +++++++++++++++++++++++---------
 drivers/net/wireless/ath/ath5k/desc.c  |   10 +++--
 3 files changed, 59 insertions(+), 30 deletions(-)
drivers/net/wireless/ath/ath5k/ath5k.h +2 -7
index ac67f02..23543d4 100644
@@ -1141,9 +1141,9 @@ struct ath5k_hw {
 	int (*ah_setup_rx_desc)(struct ath5k_hw *ah, struct ath5k_desc *desc,
 				u32 size, unsigned int flags);
 	int (*ah_setup_tx_desc)(struct ath5k_hw *, struct ath5k_desc *,
-		unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
+		unsigned int, unsigned int, int, enum ath5k_pkt_type,
 		unsigned int, unsigned int, unsigned int, unsigned int,
-		unsigned int, unsigned int, unsigned int);
+		unsigned int, unsigned int, unsigned int, unsigned int);
 	int (*ah_setup_mrr_tx_desc)(struct ath5k_hw *, struct ath5k_desc *,
 		unsigned int, unsigned int, unsigned int, unsigned int,
 		unsigned int, unsigned int);
@@ -1370,9 +1370,4 @@ static inline u32 ath5k_hw_bitswap(u32 val, unsigned int bits)
 	return retval;
 }
 
-static inline int ath5k_pad_size(int hdrlen)
-{
-	return (hdrlen < 24) ? 0 : hdrlen & 3;
-}
-
 #endif
drivers/net/wireless/ath/ath5k/base.c +51 -19

153 lines not on this page · raw message

drivers/net/wireless/ath/ath5k/desc.c +6 -4
index dc30a2b..d26126b 100644
@@ -35,7 +35,8 @@
  */
 static int
 ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
-	unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
+	unsigned int pkt_len, unsigned int hdr_len, int padsize,
+	enum ath5k_pkt_type type,
 	unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
 	unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
 	unsigned int rtscts_rate, unsigned int rtscts_duration)
@@ -71,7 +72,7 @@ ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
 	/* Verify and set frame length */
 
 	/* remove padding we might have added before */
-	frame_len = pkt_len - ath5k_pad_size(hdr_len) + FCS_LEN;
+	frame_len = pkt_len - padsize + FCS_LEN;
 
 	if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
 		return -EINVAL;
@@ -100,7 +101,7 @@ ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
 			AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
 	}
 
-	/*Diferences between 5210-5211*/
+	/*Differences between 5210-5211*/
 	if (ah->ah_version == AR5K_AR5210) {
 		switch (type) {
 		case AR5K_PKT_TYPE_BEACON:
@@ -165,6 +166,7 @@ ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  */
 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
 	struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
+	int padsize,
 	enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
 	unsigned int tx_tries0, unsigned int key_index,
 	unsigned int antenna_mode, unsigned int flags,
@@ -206,7 +208,7 @@ static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
 	/* Verify and set frame length */
 
 	/* remove padding we might have added before */
-	frame_len = pkt_len - ath5k_pad_size(hdr_len) + FCS_LEN;
+	frame_len = pkt_len - padsize + FCS_LEN;
 
 	if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
 		return -EINVAL;
Signature · 1 line
1.5.6.5
#2 lore raw
Quoted 10 lines · Benoit Papillault

Currently, the padding position is based on ieee80211_get_hdrlen_from_skb(). This is not correct since the HW does padding on RX (and expect the same padding to be present on TX) at the following position :

- management : 24 + 6 if 4-addr format

- control    : 24 + 6 if 4-addr format
- data       : 24 + 6 if 4-addr format + 2 if QoS
- invalid    : 24 + 6 if 4-addr format
Quoted 7 lines

whereas ieee80211_get_hdrlen_from_skb() is :

- management : 24

- control    : 16 except for ACK/CTS where it is 10
- data       : 24 + 6 if 4-addr format + 2 if QoS + 2 if QoS & order
- invalid    : 24

I still don't get it - if ieee80211_get_header_len_from_skb() returns the wrong thing for 4-addr frames, wouldn't it be better to fix that?

The whole problem is the hardware wants the payload 4-byte aligned for the crypto hardware.

Anyway, I think the implementation could be simpler.

Quoted 1 line

+static int ath5k_cmn_padpos(struct sk_buff *skb)

This needs a better name (common? compute?)

drivers/net/wireless/ath/ath5k/base.c accept: · line 1929

Quoted 8 lines
drivers/net/wireless/ath/ath5k/base.c +4 -4
-		hdrlen = ieee80211_get_hdrlen_from_skb(skb);
-		padsize = ath5k_pad_size(hdrlen);
-		if (padsize) {
-			memmove(skb->data + padsize, skb->data, hdrlen);
+		padpos = ath5k_cmn_padpos(skb);
+		padsize = padpos & 3;
+		if (padsize && skb->len>=padpos+padsize) {
+			memmove(skb->data + padsize, skb->data, padpos);

Better would be putting this all in a function and then:

                ath5k_remove_padding(skb);

drivers/net/wireless/ath/ath5k/base.c ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq) · line 2055

Quoted 4 lines
drivers/net/wireless/ath/ath5k/base.c +4 -0
+		/*
+		 * Remove MAC header padding before giving the frame
+		 * back to mac80211.
+		 */

You get to use the new function you just created here...

Quoted 10 lines
drivers/net/wireless/ath/ath5k/base.c +1 -2
@@ -2680,8 +2711,7 @@ static int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb,
 	struct ath5k_softc *sc = hw->priv;
 	struct ath5k_buf *bf;
 	unsigned long flags;
-	int hdrlen;
-	int padsize;
+	int padpos, padsize;
 
 		if (skb_headroom(skb) < padsize) {
 			ATH5K_ERR(sc, "tx hdrlen not %%4: %d not enough"

drivers/net/wireless/ath/ath5k/base.c static int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb, · line 2738

Quoted 10 lines
drivers/net/wireless/ath/ath5k/base.c +4 -2
-				  " headroom to pad %d\n", hdrlen, padsize);
+				  " headroom to pad %d\n", padpos, padsize);
 			goto drop_packet;
 		}
 		skb_push(skb, padsize);
-		memmove(skb->data, skb->data+padsize, hdrlen);
+		memmove(skb->data, skb->data+padsize, padpos);
+	} else {
+		padsize = 0;
 	}

ath5k_add_padding()

drivers/net/wireless/ath/ath5k/desc.c ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc, · line 75

Quoted 6 lines
drivers/net/wireless/ath/ath5k/desc.c +1 -1
@@ -71,7 +72,7 @@ ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
 	/* Verify and set frame length */
 
 	/* remove padding we might have added before */
-	frame_len = pkt_len - ath5k_pad_size(hdr_len) + FCS_LEN;
+	frame_len = pkt_len - padsize + FCS_LEN;

Hrm... I think I added this originally, and I think it is wrong. I have some old docs which say padding doesn't count in txdesc. That simplifies things.

Signature · 1 line
Bob Copeland %% www.bobcopeland.com
#3 lore raw
Quoted 21 lines · Bob Copeland
Quoted 10 lines · Benoit Papillault

Currently, the padding position is based on ieee80211_get_hdrlen_from_skb(). This is not correct since the HW does padding on RX (and expect the same padding to be present on TX) at the following position :

- management : 24 + 6 if 4-addr format

- control    : 24 + 6 if 4-addr format
- data       : 24 + 6 if 4-addr format + 2 if QoS
- invalid    : 24 + 6 if 4-addr format
Quoted 8 lines

whereas ieee80211_get_hdrlen_from_skb() is :

- management : 24

- control    : 16 except for ACK/CTS where it is 10
- data       : 24 + 6 if 4-addr format + 2 if QoS + 2 if QoS & order
- invalid    : 24
Quoted 3 lines

I still don't get it - if ieee80211_get_header_len_from_skb() returns the wrong thing for 4-addr frames, wouldn't it be better to fix that?

No. Both functions serve different purpose :
- ieee80211_get_hdrlen_from_skb() is the header length as defined by the IEEE 802.11 specification and AFAIK is correct.
- the padding position is what the HW expects, as determined by my own tests.

Quoted 11 lines

The whole problem is the hardware wants the payload 4-byte aligned for the crypto hardware.

Anyway, I think the implementation could be simpler.

Quoted 2 lines

+static int ath5k_cmn_padpos(struct sk_buff *skb)

This needs a better name (common? compute?)

let's say : ath5k_common_padpos ? I just mimic the name used in ath9k.

Quoted 14 lines

drivers/net/wireless/ath/ath5k/base.c accept: · line 1929

Quoted 11 lines
drivers/net/wireless/ath/ath5k/base.c +4 -4
-		hdrlen = ieee80211_get_hdrlen_from_skb(skb);
-		padsize = ath5k_pad_size(hdrlen);
-		if (padsize) {
-			memmove(skb->data + padsize, skb->data, hdrlen);
+		padpos = ath5k_cmn_padpos(skb);
+		padsize = padpos & 3;
+		if (padsize && skb->len>=padpos+padsize) {
+			memmove(skb->data + padsize, skb->data, padpos);

Better would be putting this all in a function and then:

Quoted 2 lines
                ath5k_remove_padding(skb);

OK.

Quoted 20 lines

drivers/net/wireless/ath/ath5k/base.c ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq) · line 2055

Quoted 6 lines
drivers/net/wireless/ath/ath5k/base.c +4 -0
+		/*
+		 * Remove MAC header padding before giving the frame
+		 * back to mac80211.
+		 */

You get to use the new function you just created here...

Quoted 8 lines
drivers/net/wireless/ath/ath5k/base.c +1 -2
@@ -2680,8 +2711,7 @@ static int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb,
 	struct ath5k_softc *sc = hw->priv;
 	struct ath5k_buf *bf;
 	unsigned long flags;
-	int hdrlen;
-	int padsize;
+	int padpos, padsize;
 
Quoted 16 lines

drivers/net/wireless/ath/ath5k/base.c static int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb, · line 2738

Quoted 13 lines
drivers/net/wireless/ath/ath5k/base.c +4 -2
 		if (skb_headroom(skb) < padsize) {
 			ATH5K_ERR(sc, "tx hdrlen not %%4: %d not enough"
-				  " headroom to pad %d\n", hdrlen, padsize);
+				  " headroom to pad %d\n", padpos, padsize);
 			goto drop_packet;
 		}
 		skb_push(skb, padsize);
-		memmove(skb->data, skb->data+padsize, hdrlen);
+		memmove(skb->data, skb->data+padsize, padpos);
+	} else {
+		padsize = 0;
 	}

ath5k_add_padding()

OK.

Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
@@ -71,7 +72,7 @@ ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
 	/* Verify and set frame length */
 
Quoted 10 lines

drivers/net/wireless/ath/ath5k/desc.c ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc, · line 76

Quoted 4 lines
drivers/net/wireless/ath/ath5k/desc.c +1 -1
 	/* remove padding we might have added before */
-	frame_len = pkt_len - ath5k_pad_size(hdr_len) + FCS_LEN;
+	frame_len = pkt_len - padsize + FCS_LEN;
 

Hrm... I think I added this originally, and I think it is wrong. I have some old docs which say padding doesn't count in txdesc. That simplifies things.

So, you are saying it should be : frame_len = pkt_len + FCS_LEN only?
I can test on AR5212, but IIRC, this was affecting the FCS computed by the HW (ie the frame content received on the other side is fined, except the FCS is wrong since it is computed using the more bytes than expected).

Regards,
Benoit

#4 lore raw

PATCH 1/1 ath5k: Fix TX/RX padding for all frames

Currently, the padding position is based on ieee80211_get_hdrlen_from_skb(). This is not correct since the HW does padding on RX (and expect the same padding to be present on TX) at the following position :

- management : 24 + 6 if 4-addr format

- control    : 24 + 6 if 4-addr format
- data       : 24 + 6 if 4-addr format + 2 if QoS
- invalid    : 24 + 6 if 4-addr format

whereas ieee80211_get_hdrlen_from_skb() is :

- management : 24

- control    : 16 except for ACK/CTS where it is 10
- data       : 24 + 6 if 4-addr format + 2 if QoS + 2 if QoS & order
- invalid    : 24

So, correct frames are not affected : management frames do not use 4-addr format, control frames have no body and invalid frames are ... not valid by definition. However, in order to use monitor interface for debugging purpose, one must be able to send/receive any frames, be it correct or not. Such frames are affected by incorrect padding.

Moreover, since padding is added on TX, we need to remove it before calling ieee80211_tx_status. This affect TX packets received by monitor interfaces.

It has been tested between an ath5k based card (AR5212) and an ar9170usb based card (netgear WNDA3100) using a frame generator and a monitor interface for each card.

v2: Added ath5k_add_padding / ath5k_remove_padding

---
 drivers/net/wireless/ath/ath5k/ath5k.h |    9 +--
 drivers/net/wireless/ath/ath5k/base.c  |  105 ++++++++++++++++++++++++--------
 drivers/net/wireless/ath/ath5k/desc.c  |   10 ++-
 3 files changed, 88 insertions(+), 36 deletions(-)
drivers/net/wireless/ath/ath5k/ath5k.h +2 -7
index ac67f02..23543d4 100644
@@ -1141,9 +1141,9 @@ struct ath5k_hw {
 	int (*ah_setup_rx_desc)(struct ath5k_hw *ah, struct ath5k_desc *desc,
 				u32 size, unsigned int flags);
 	int (*ah_setup_tx_desc)(struct ath5k_hw *, struct ath5k_desc *,
-		unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
+		unsigned int, unsigned int, int, enum ath5k_pkt_type,
 		unsigned int, unsigned int, unsigned int, unsigned int,
-		unsigned int, unsigned int, unsigned int);
+		unsigned int, unsigned int, unsigned int, unsigned int);
 	int (*ah_setup_mrr_tx_desc)(struct ath5k_hw *, struct ath5k_desc *,
 		unsigned int, unsigned int, unsigned int, unsigned int,
 		unsigned int, unsigned int);
@@ -1370,9 +1370,4 @@ static inline u32 ath5k_hw_bitswap(u32 val, unsigned int bits)
 	return retval;
 }
 
-static inline int ath5k_pad_size(int hdrlen)
-{
-	return (hdrlen < 24) ? 0 : hdrlen & 3;
-}
-
 #endif
drivers/net/wireless/ath/ath5k/base.c +80 -25

177 lines not on this page · raw message

drivers/net/wireless/ath/ath5k/desc.c +6 -4
index dc30a2b..d26126b 100644
@@ -35,7 +35,8 @@
  */
 static int
 ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
-	unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
+	unsigned int pkt_len, unsigned int hdr_len, int padsize,
+	enum ath5k_pkt_type type,
 	unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
 	unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
 	unsigned int rtscts_rate, unsigned int rtscts_duration)
@@ -71,7 +72,7 @@ ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
 	/* Verify and set frame length */
 
 	/* remove padding we might have added before */
-	frame_len = pkt_len - ath5k_pad_size(hdr_len) + FCS_LEN;
+	frame_len = pkt_len - padsize + FCS_LEN;
 
 	if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
 		return -EINVAL;
@@ -100,7 +101,7 @@ ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
 			AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
 	}
 
-	/*Diferences between 5210-5211*/
+	/*Differences between 5210-5211*/
 	if (ah->ah_version == AR5K_AR5210) {
 		switch (type) {
 		case AR5K_PKT_TYPE_BEACON:
@@ -165,6 +166,7 @@ ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  */
 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
 	struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
+	int padsize,
 	enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
 	unsigned int tx_tries0, unsigned int key_index,
 	unsigned int antenna_mode, unsigned int flags,
@@ -206,7 +208,7 @@ static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
 	/* Verify and set frame length */
 
 	/* remove padding we might have added before */
-	frame_len = pkt_len - ath5k_pad_size(hdr_len) + FCS_LEN;
+	frame_len = pkt_len - padsize + FCS_LEN;
 
 	if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
 		return -EINVAL;
Signature · 1 line
1.5.6.5