wifi: rtl8xxxu: honour rate, retries and bandwidth of injected frames
v2 cover wifi: rtl8xxxu: honour rate, retries and bandwidth of injected frames
rtl8xxxu ignores most of the radiotap header of injected frames. On a RTL8192CU every injected frame went out at MCS 7 and 20 MHz whatever was requested, the retry count was ignored, and NOACK frames were retried up to 48 times. That makes the driver unusable for tools that rely on fixed-rate injection.
Patch 1 makes gen1 chips (RTL8188CU, RTL8192CU, RTL8723AU) use the injected rate and guard interval, without rate fallback.
Patch 2 makes the radiotap retry count and NOACK work. max_rate_tries is 0 today, so mac80211 clamps injected retries to zero, and the hardware default of 48 retries is used instead: unicast frames to an absent station then stalled injection for over 100 s in my tests.
Patch 3 sends injected frames at 40 MHz when they ask for it. Only QoS data frames get the 40 MHz descriptor bits today.
Frames without radiotap rate information are not affected.
Gen2 chips and the RTL8188EU use other descriptor formats. Patches for them follow as a separate RFT series, since I cannot test them.
Testing, all on RTL8192CU (0bda:8178) in monitor mode, received by a second radio:
- 1, 5.5, 6 and 54 Mbps and MCS 0/7/8/15 with long and short GI arrive at the requested rate (stock driver: all MCS 7).
- Unicast frames to an absent station: drain time grows with the requested retry count, NOACK frames are sent once.
- Channel 6 HT40+ and HT40-: MCS 0 and 7 requested at 40 MHz arrive at 40 MHz (stock driver: 20 MHz).
- checkpatch --strict, W=1 and sparse are clean for each patch.
AI tool use (Documentation/process/generated-content.rst): the patches were written with help from Claude Code (Claude Opus 5.5). It was asked to find why injected frames ignore the radiotap rate, retry count and bandwidth, write the fixes, and run the over-the-air tests above. I have reviewed and tested the changes and take responsibility for them.
---
Changes in v2:
- Patch 1: drop the comment above rtl8xxxu_tx_rate_inject().
- Patch 2: set the retry limit together with the management frame
case, so the field is no longer cleared and set twice; use le32_encode_bits(); add TXDESC32_RETRY_LIMIT_MAX for max_rate_tries.
- Patch 3: declare bw40 on its own line.
- Collect Reviewed-by and Acked-by from Ping-Ke.
- Link to v1: https://patch.msgid.link/[email protected]
---
Ahmet Zeren (3):
wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips
wifi: rtl8xxxu: honour the retry count of injected frames on gen1 chips
wifi: rtl8xxxu: honour the bandwidth of injected frames on gen1 chips
drivers/net/wireless/realtek/rtl8xxxu/core.c | 76 +++++++++++++++++++++--- drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 1 + 2 files changed, 68 insertions(+), 9 deletions(-)
---
base-commit: 0bdc579dbfc251a6b6838ee9459b6771b948c617
change-id: 20261120-b4-inject-f6f4bc873392
Best regards,
Signature · 1 line
Ahmet Zeren <[email protected]>
PATCH v2 1/3 wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips
When a frame is injected with a rate in its radiotap header, the driver ignores it and leaves the choice to the firmware rate adaptation. On a RTL8192CU every injected frame went out at MCS 7, whatever was asked.
Use the injected rate and guard interval, and disable rate fallback so the frame is sent at exactly that rate.
Tested on RTL8192CU (0bda:8178) in monitor mode on 2.4 GHz: 1, 5.5, 6 and 54 Mbps, MCS 0/7/8/15 with long and short GI were all received at the requested rate. Frames without a radiotap rate are unchanged.
--- drivers/net/wireless/realtek/rtl8xxxu/core.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/net/wireless/realtek/rtl8xxxu/core.c +25 -0
@@ -5223,6 +5223,24 @@ static void rtl8xxxu_dump_action(struct device *dev, } } +static bool rtl8xxxu_tx_rate_inject (struct ieee80211_tx_info *tx_info, +u32 *rate,bool *sgi) +{ +struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0 ]; + +if (!(tx_info->control.flags &IEEE80211_TX_CTRL_RATE_INJECT )) +return false; + +if (txrate->flags &IEEE80211_TX_RC_MCS ) + *rate =DESC_RATE_MCS0 + txrate->idx; +else + *rate = rtl8xxxu_legacy_ratetable[txrate->idx].hw_value; + + *sgi = txrate->flags &IEEE80211_TX_RC_SHORT_GI ; + +return true; +} +/* * Fill in v1 (gen1) specific TX descriptor bits. * This format is used on 8188cu/8192cu/8723au
@@ -5240,6 +5258,9 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,u8 tid = qc[0 ] &IEEE80211_QOS_CTL_TID_MASK ;u32 rate =0 ;u16 seq_number; +bool inject; + + inject =rtl8xxxu_tx_rate_inject (tx_info, &rate, &sgi);if (rtl8xxxu_debug &RTL8XXXU_DEBUG_TX ) dev_info(dev, "%s: TX rate: %d, pkt size %u\n",
@@ -5285,6 +5306,10 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,if (sgi) tx_desc->txdw5 |=cpu_to_le32 (TXDESC32_SHORT_GI ); +if (inject) + tx_desc->txdw4 |=cpu_to_le32 (TXDESC32_USE_DRIVER_RATE | +TXDESC_DISABLE_DATA_FB ); +/* * rts_rate is zero if RTS/CTS or CTS to SELF are not enabled */
Signature · 1 line
2.56.1
Re: [PATCH rtw-next v2 1/3] wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips
Quoted 9 lines · Ahmet Zeren
From: Ahmet Zeren <[email protected]>
When a frame is injected with a rate in its radiotap header, the driver ignores it and leaves the choice to the firmware rate adaptation. On a RTL8192CU every injected frame went out at MCS 7, whatever was asked.
Use the injected rate and guard interval, and disable rate fallback so the frame is sent at exactly that rate.
Quoted 6 lines
Tested on RTL8192CU (0bda:8178) in monitor mode on 2.4 GHz: 1, 5.5, 6 and 54 Mbps, MCS 0/7/8/15 with long and short GI were all received at the requested rate. Frames without a radiotap rate are unchanged.
Reviewed-by Ping-Ke Shih <[email protected]>Signed-off-by Ahmet Zeren <[email protected]>
3 patch(es) applied to rtw-next branch of rtw.git, thanks.
50b9e3778de9 wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips b2ccb6a04761 wifi: rtl8xxxu: honour the retry count of injected frames on gen1 chips 30f5119c965e wifi: rtl8xxxu: honour the bandwidth of injected frames on gen1 chips
PATCH v2 2/3 wifi: rtl8xxxu: honour the retry count of injected frames on gen1 chips
In reply to Ahmet Zerenmax_rate_tries is never set, so mac80211 clamps the retry count of every injected frame to zero and the radiotap retries field has no effect. Injected frames also ignore IEEE80211_TX_CTL_NO_ACK and use the default hardware retry limit of 48. Unicast frames to an absent station then take seconds each, which stalls all injection behind them.
Advertise the 6-bit retry limit of the TX descriptor, and on gen1 chips program the retry limit of injected frames: none when no ACK is expected, otherwise the radiotap retry count.
Tested on RTL8192CU (0bda:8178): 40 unicast frames at 1 Mbps to an absent station drain in ~0.13 s with NOACK or 0 retries, ~0.45 s with 2, ~1.1 s with 4 and ~3.3 s with 6 retries. Without this patch the same frames had not drained after 100 s, even with NOACK.
--- drivers/net/wireless/realtek/rtl8xxxu/core.c | 29 +++++++++++++++++++++++- drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtl8xxxu/core.c +28 -1
@@ -5241,6 +5241,24 @@ static bool rtl8xxxu_tx_rate_inject(struct ieee80211_tx_info *tx_info,return true; } +/* +* Retry limit of an injected frame: none if no ACK is expected, else the +* radiotap retry count. -1 leaves it to the hardware. +*/ +static int rtl8xxxu_tx_retry_inject (struct ieee80211_tx_info *tx_info) +{ +if (!(tx_info->flags &IEEE80211_TX_CTL_INJECTED )) +return -1 ; + +if (tx_info->flags &IEEE80211_TX_CTL_NO_ACK ) +return 0 ; + +if (tx_info->control.flags &IEEE80211_TX_CTRL_RATE_INJECT ) +return tx_info->control.rates[0 ].count -1 ; + +return -1 ; +} +/* * Fill in v1 (gen1) specific TX descriptor bits. * This format is used on 8188cu/8192cu/8723au
@@ -5258,9 +5276,11 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,u8 tid = qc[0 ] &IEEE80211_QOS_CTL_TID_MASK ;u32 rate =0 ;u16 seq_number; +int retries;bool inject; inject =rtl8xxxu_tx_rate_inject (tx_info, &rate, &sgi); + retries =rtl8xxxu_tx_retry_inject (tx_info);if (rtl8xxxu_debug &RTL8XXXU_DEBUG_TX ) dev_info(dev, "%s: TX rate: %d, pkt size %u\n",
@@ -5283,7 +5303,13 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,if (ieee80211_is_mgmt (hdr->frame_control)) { tx_desc->txdw5 =cpu_to_le32 (rate); tx_desc->txdw4 |=cpu_to_le32 (TXDESC32_USE_DRIVER_RATE ); - tx_desc->txdw5 |=cpu_to_le32 (6 <<TXDESC32_RETRY_LIMIT_SHIFT ); +if (retries <0 ) + retries =6 ; + } + +if (retries >=0 ) { + tx_desc->txdw5 |=le32_encode_bits (retries, +TXDESC32_RETRY_LIMIT_MASK ); tx_desc->txdw5 |=cpu_to_le32 (TXDESC32_RETRY_LIMIT_ENABLE ); }
@@ -7975,6 +8001,7 @@ static int rtl8xxxu_probe(struct usb_interface *interface,SET_IEEE80211_PERM_ADDR (hw, priv->mac_addr); hw->extra_tx_headroom = priv->fops->tx_desc_size; + hw->max_rate_tries =TXDESC32_RETRY_LIMIT_MAX +1 ;ieee80211_hw_set (hw,SIGNAL_DBM );/*
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +1 -0
@@ -575,6 +575,7 @@ struct rtl8xxxu_txdesc40 {#define TXDESC32_RETRY_LIMIT_ENABLE BIT(17)#define TXDESC32_RETRY_LIMIT_SHIFT 18#define TXDESC32_RETRY_LIMIT_MASK 0x00fc0000 +#define TXDESC32_RETRY_LIMIT_MAX 63/* Word 6 */ #define TXDESC_MAX_AGG_SHIFT 11
Signature · 1 line
2.56.1
RE: [PATCH rtw-next v2 2/3] wifi: rtl8xxxu: honour the retry count of injected frames on gen1 chips
Quoted 12 lines · Ahmet Zeren via B4 Relay <[email protected]> wrote:
From: Ahmet Zeren <[email protected]>
max_rate_triesis never set, so mac80211 clamps the retry count of every injected frame to zero and the radiotap retries field has no effect. Injected frames also ignoreIEEE80211_TX_CTL_NO_ACKand use the default hardware retry limit of 48. Unicast frames to an absent station then take seconds each, which stalls all injection behind them.Advertise the 6-bit retry limit of the TX descriptor, and on gen1 chips program the retry limit of injected frames: none when no ACK is expected, otherwise the radiotap retry count.
Quoted 6 lines
Tested on RTL8192CU (0bda:8178): 40 unicast frames at 1 Mbps to an absent station drain in ~0.13 s with NOACK or 0 retries, ~0.45 s with 2, ~1.1 s with 4 and ~3.3 s with 6 retries. Without this patch the same frames had not drained after 100 s, even with NOACK.
Signed-off-by Ahmet Zeren <[email protected]>
PATCH v2 3/3 wifi: rtl8xxxu: honour the bandwidth of injected frames on gen1 chips
In reply to Ahmet ZerenInjected frames are always sent at 20 MHz, even when they ask for 40 MHz on a 40 MHz channel, because only QoS data frames get the 40 MHz bits in the TX descriptor.
Set them for injected frames with IEEE80211_TX_RC_40_MHZ_WIDTH.
Tested on RTL8192CU (0bda:8178) on channel 6 HT40+ and HT40-, received by a second radio sniffing at 40 MHz: MCS 0 and 7 requested at 40 MHz arrive at 40 MHz (without this patch: 20 MHz), requested at 20 MHz they stay at 20 MHz.
--- drivers/net/wireless/realtek/rtl8xxxu/core.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/core.c +14 -8
@@ -5278,6 +5278,7 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,u16 seq_number;int retries;bool inject; +bool bw40; inject =rtl8xxxu_tx_rate_inject (tx_info, &rate, &sgi); retries =rtl8xxxu_tx_retry_inject (tx_info);
@@ -5313,17 +5314,22 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr, tx_desc->txdw5 |=cpu_to_le32 (TXDESC32_RETRY_LIMIT_ENABLE ); } -if (ieee80211_is_data_qos (hdr->frame_control)) { +if (ieee80211_is_data_qos (hdr->frame_control)) tx_desc->txdw4 |=cpu_to_le32 (TXDESC32_QOS ); -if (conf_is_ht40 (&hw->conf)) { - tx_desc->txdw4 |=cpu_to_le32 (TXDESC_DATA_BW ); +if (inject) + bw40 = tx_info->control.rates[0 ].flags &IEEE80211_TX_RC_40_MHZ_WIDTH ; +else + bw40 =ieee80211_is_data_qos (hdr->frame_control) && +conf_is_ht40 (&hw->conf); -if (conf_is_ht40_minus (&hw->conf)) - tx_desc->txdw4 |=cpu_to_le32 (TXDESC_PRIME_CH_OFF_UPPER ); -else - tx_desc->txdw4 |=cpu_to_le32 (TXDESC_PRIME_CH_OFF_LOWER ); - } +if (bw40) { + tx_desc->txdw4 |=cpu_to_le32 (TXDESC_DATA_BW ); + +if (conf_is_ht40_minus (&hw->conf)) + tx_desc->txdw4 |=cpu_to_le32 (TXDESC_PRIME_CH_OFF_UPPER ); +else + tx_desc->txdw4 |=cpu_to_le32 (TXDESC_PRIME_CH_OFF_LOWER ); }if (short_preamble)
Signature · 1 line
2.56.1
RE: [PATCH rtw-next v2 3/3] wifi: rtl8xxxu: honour the bandwidth of injected frames on gen1 chips
Quoted 6 lines · Ahmet Zeren via B4 Relay <[email protected]> wrote:
From: Ahmet Zeren <[email protected]>
Injected frames are always sent at 20 MHz, even when they ask for 40 MHz on a 40 MHz channel, because only QoS data frames get the 40 MHz bits in the TX descriptor.
Quoted 8 lines
Set them for injected frames with
IEEE80211_TX_RC_40_MHZ_WIDTH.Tested on RTL8192CU (0bda:8178) on channel 6 HT40+ and HT40-, received by a second radio sniffing at 40 MHz: MCS 0 and 7 requested at 40 MHz arrive at 40 MHz (without this patch: 20 MHz), requested at 20 MHz they stay at 20 MHz.
Acked-by Ping-Ke Shih <[email protected]>
I wrongly replied Acked-by. I'll change it to Reviewed-by during committing.
Quoted 1 line
Signed-off-by Ahmet Zeren <[email protected]>