mac80211: Build TX radiotap header dynamically
PATCH 1/2 mac80211: Build TX radiotap header dynamically
Get rid of the ieee80211_tx_status_rtap_hdr struct and instead build the rtap header dynamically. This makes it easier to extend the rtap header generation in the future.
Add ieee80211_tx_radiotap_len to calculate the expected size of the rtap header before generating it. Since we can't check if the rtap header fits into the requested headroom during compile time anymore add a WARN_ON_ONCE.
Also move the actual rtap header generation into its own function.
--- net/mac80211/ieee80211_i.h | 12 ----- net/mac80211/main.c | 6 +-- net/mac80211/status.c | 112 ++++++++++++++++++++++++++++++-------------- 3 files changed, 78 insertions(+), 52 deletions(-)
net/mac80211/ieee80211_i.h +0 -12
@@ -1178,18 +1178,6 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,netdev_tx_t ieee80211_subif_start_xmit (struct sk_buff *skb,struct net_device *dev); -/* -* radiotap header for status frames -*/ -struct ieee80211_tx_status_rtap_hdr { -struct ieee80211_radiotap_header hdr; -u8 rate; -u8 padding_for_rate; -__le16 tx_flags; -u8 data_retries; -} __packed; - -/* HT */ void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband, struct ieee80211_ht_cap *ht_cap_ie,
net/mac80211/main.c +1 -5
@@ -904,12 +904,8 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)* and we need some headroom for passing the frame to monitor * interfaces, but never both at the same time. */ -#ifndef __CHECKER__ -BUILD_BUG_ON (IEEE80211_TX_STATUS_HEADROOM != -sizeof (struct ieee80211_tx_status_rtap_hdr )); -#endif local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom, -sizeof (struct ieee80211_tx_status_rtap_hdr )); +IEEE80211_TX_STATUS_HEADROOM );debugfs_hw_add (local);
net/mac80211/status.c +77 -35
140 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 2/2 mac80211: Populate radiotap header with MCS info for TX frames
mac80211 already filled in the MCS rate info for rx'ed frames but tx'ed frames that are sent to a monitor interface during the status callback lack this information.
Add the radiotap fields for MCS info to ieee80211_tx_status_rtap_hdr and populate them when sending tx'ed frames to the monitors.
The needed headroom is only extended by one byte since we don't include legacy rate information in the rtap header for HT frames.
--- include/net/mac80211.h | 2 +- net/mac80211/status.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletions(-)
include/net/mac80211.h +1 -1
@@ -2520,7 +2520,7 @@ static inline int ieee80211_sta_ps_transition_ni(struct ieee80211_sta *sta,* The TX headroom reserved by mac80211 for its own tx_status functions. * This is enough for the radiotap header. */ -#define IEEE80211_TX_STATUS_HEADROOM 13 +#define IEEE80211_TX_STATUS_HEADROOM 14/** * ieee80211_sta_set_buffered - inform mac80211 about driver-buffered frames
net/mac80211/status.c +23 -0
@@ -242,6 +242,11 @@ static int ieee80211_tx_radiotap_len(struct ieee80211_tx_info *info)/* IEEE80211_RADIOTAP_DATA_RETRIES */ len +=1 ; + +/* IEEE80211_TX_RC_MCS */ +if (info->status.rates[0 ].idx >=0 && + info->status.rates[0 ].flags &IEEE80211_TX_RC_MCS ) + len +=3 ;return len; }
@@ -299,6 +304,24 @@ static void ieee80211_add_tx_radiotap_header(struct ieee80211_supported_band/* for now report the total retry_count */ *pos = retry_count; pos++; + +/* IEEE80211_TX_RC_MCS */ +if (info->status.rates[0 ].idx >=0 && + info->status.rates[0 ].flags &IEEE80211_TX_RC_MCS ) { + rthdr->it_present |=cpu_to_le32 (1 <<IEEE80211_RADIOTAP_MCS ); + pos[0 ] =IEEE80211_RADIOTAP_MCS_HAVE_MCS | +IEEE80211_RADIOTAP_MCS_HAVE_GI | +IEEE80211_RADIOTAP_MCS_HAVE_BW ; +if (info->status.rates[0 ].flags &IEEE80211_TX_RC_SHORT_GI ) + pos[1 ] |=IEEE80211_RADIOTAP_MCS_SGI ; +if (info->status.rates[0 ].flags &IEEE80211_TX_RC_40_MHZ_WIDTH ) + pos[1 ] |=IEEE80211_RADIOTAP_MCS_BW_40 ; +if (info->status.rates[0 ].flags &IEEE80211_TX_RC_GREEN_FIELD ) + pos[1 ] |=IEEE80211_RADIOTAP_MCS_FMT_GF ; + pos[2 ] = info->status.rates[0 ].idx; + pos +=3 ; + } + }/*
Signature · 1 line
1.7.3.4
Johannes Berg
maintainernet/mac80211/status.c static void ieee80211_set_bar_pending(struct sta_info *sta, u8 tid, u16 ssn) · line 280
Quoted 7 lines · Helmut Schaa
net/mac80211/status.c +7
-0+/* IEEE80211_RADIOTAP_RATE */ +if (info->status.rates[0 ].idx >=0 && + !(info->status.rates[0 ].flags &IEEE80211_TX_RC_MCS )) { + rthdr->it_present |=cpu_to_le32 (1 <<IEEE80211_RADIOTAP_RATE ); + *pos = sband->bitrates[info->status.rates[0 ].idx].bitrate /5 ; +/* padding for tx flags */ + pos +=2 ;
Since there's no over-all memset I think you need to clear the padding explicitly now.
johannes
Am Dienstag, 11. Oktober 2011, 18:25:45 schrieb Johannes Berg:
Quoted 3 lines · Helmut Schaa
Since there's no over-all memset I think you need to clear the padding explicitly now.
Like this one? :)
net/mac80211/status.c static void ieee80211_set_bar_pending(struct sta_info *sta, u8 tid, u16 ssn) · line 261
Quoted 3 lines
net/mac80211/status.c +3
-0+ rthdr = (struct ieee80211_radiotap_header *)skb_push (skb, rtap_len); + +memset (rthdr,0 , rtap_len);
Helmut
Johannes Berg
maintainerQuoted 10 lines · Helmut Schaa
Am Dienstag, 11. Oktober 2011, 18:25:45 schrieb Johannes Berg:
Quoted 3 lines · Helmut Schaa
Since there's no over-all memset I think you need to clear the padding explicitly now.
Like this one? :)
net/mac80211/status.c static void ieee80211_set_bar_pending(struct sta_info *sta, u8 tid, u16 ssn) · line 261
Quoted 3 lines
net/mac80211/status.c +3
-0+ rthdr = (struct ieee80211_radiotap_header *)skb_push (skb, rtap_len); + +memset (rthdr,0 , rtap_len);
Oh, oops, sorry!
Looks good to me then.
johannes
Johannes Berg
maintainernet/mac80211/status.c static void ieee80211_set_bar_pending(struct sta_info *sta, u8 tid, u16 ssn) · line 295
Quoted 3 lines · Helmut Schaa
net/mac80211/status.c +2
-0+__le16 txflags; +put_unaligned_le16 (txflags, pos);
Please send a patch to fix this endian bug that sparse found.
johannes
PATCH 1/1 mac80211: Fix endian bug in radiotap header generation
I intoduced this bug in commit a2fe81667410723d941a688e1958a49d67ca3346 "mac80211: Build TX radiotap header dynamically"
--- net/mac80211/status.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
net/mac80211/status.c +4 -4
@@ -260,7 +260,7 @@ static void ieee80211_add_tx_radiotap_header(struct ieee80211_supported_bandstruct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;struct ieee80211_radiotap_header *rthdr;unsigned char *pos; -__le16 txflags; +u16 txflags; rthdr = (struct ieee80211_radiotap_header *)skb_push (skb, rtap_len);
@@ -290,13 +290,13 @@ static void ieee80211_add_tx_radiotap_header(struct ieee80211_supported_band txflags =0 ;if (!(info->flags &IEEE80211_TX_STAT_ACK ) && !is_multicast_ether_addr (hdr->addr1)) - txflags |=cpu_to_le16 (IEEE80211_RADIOTAP_F_TX_FAIL ); + txflags |=IEEE80211_RADIOTAP_F_TX_FAIL ;if ((info->status.rates[0 ].flags &IEEE80211_TX_RC_USE_RTS_CTS ) || (info->status.rates[0 ].flags &IEEE80211_TX_RC_USE_CTS_PROTECT )) - txflags |=cpu_to_le16 (IEEE80211_RADIOTAP_F_TX_CTS ); + txflags |=IEEE80211_RADIOTAP_F_TX_CTS ;else if (info->status.rates[0 ].flags &IEEE80211_TX_RC_USE_RTS_CTS ) - txflags |=cpu_to_le16 (IEEE80211_RADIOTAP_F_TX_RTS ); + txflags |=IEEE80211_RADIOTAP_F_TX_RTS ;put_unaligned_le16 (txflags, pos); pos +=2 ;
Signature · 1 line
1.7.3.4
Re: [PATCH] mac80211: Fix endian bug in radiotap header generation
Quoted 2 lines · Helmut Schaa
I intoduced this bug in commit
a2fe81667410723d941a688e1958a49d67ca3346"mac80211: Build TX radiotap header dynamically"
Quoted 25 lines
Signed-off-by Helmut Schaa <[email protected]>--- net/mac80211/status.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)net/mac80211/status.c +2
-2@@ -260,7 +260,7 @@ static void ieee80211_add_tx_radiotap_header(struct ieee80211_supported_bandstruct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;struct ieee80211_radiotap_header *rthdr;unsigned char *pos; -__le16 txflags; +u16 txflags; rthdr = (struct ieee80211_radiotap_header *)skb_push (skb, rtap_len);@@ -290,13 +290,13 @@ static void ieee80211_add_tx_radiotap_header(struct ieee80211_supported_band txflags =0 ;if (!(info->flags &IEEE80211_TX_STAT_ACK ) && !is_multicast_ether_addr (hdr->addr1)) - txflags |=cpu_to_le16 (IEEE80211_RADIOTAP_F_TX_FAIL ); + txflags |=IEEE80211_RADIOTAP_F_TX_FAIL ;
net/mac80211/status.c static void ieee80211_add_tx_radiotap_header(struct ieee80211_supported_band · line 302
Quoted 10 lines
net/mac80211/status.c +2
-2if ((info->status.rates[0 ].flags &IEEE80211_TX_RC_USE_RTS_CTS ) || (info->status.rates[0 ].flags &IEEE80211_TX_RC_USE_CTS_PROTECT )) - txflags |=cpu_to_le16 (IEEE80211_RADIOTAP_F_TX_CTS ); + txflags |=IEEE80211_RADIOTAP_F_TX_CTS ;else if (info->status.rates[0 ].flags &IEEE80211_TX_RC_USE_RTS_CTS ) - txflags |=cpu_to_le16 (IEEE80211_RADIOTAP_F_TX_RTS ); + txflags |=IEEE80211_RADIOTAP_F_TX_RTS ;put_unaligned_le16 (txflags, pos); pos +=2 ;
Heh I would've fixed it by just using put_unaligned(txflags, pos) here, but either is fine with me :-)
johannes
Re: Re: [PATCH] mac80211: Fix endian bug in radiotap header generation
Am Freitag, 18. November 2011, 17:08:40 schrieb Johannes Berg:
Quoted 2 lines
Heh I would've fixed it by just using
put_unaligned(txflags, pos)here, but either is fine with me :-)
Hmm, right, but using this approach we even save some cpu_to_le16 calls on BE archs and maybe some day I'll learn to always build with "make C=1" to catch endian bugs before sending a patch :)
Thanks,
Helmut
Johannes Berg
maintainerRe: Re: [PATCH] mac80211: Fix endian bug in radiotap header generation
Quoted 6 lines · Helmut Schaa
Am Freitag, 18. November 2011, 17:08:40 schrieb Johannes Berg:
Quoted 2 lines
Heh I would've fixed it by just using
put_unaligned(txflags, pos)here, but either is fine with me :-)Hmm, right, but using this approach we even save some
cpu_to_le16calls on BE archs
Not really, because the compiler will translate cpu_to_le16(const) to swapped-const.
Quoted 2 lines
and maybe some day I'll learn to always build with "make C=1" to
catch endian bugs before sending a patch :)
:-)
johannes