Skip to contentSkip to conversation

wifi: mac80211: parse the TWT Flow field of received TWT Teardown frames

PATCH New Phillipe Gustavo 1 participant 1 message Nov 9 mac80211

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: mac80211: parse the TWT Flow field of received TWT Teardown frames

ieee80211_s1g_rx_twt_teardown() passes the whole TWT Flow octet of a received TWT Teardown frame to the driver as the flow identifier. That octet is not just a flow id: bits 0-2 carry the TWT Flow Identifier, bits 5-6 the Negotiation Type and bit 7 is "Teardown All TWT".

When a station sets "Teardown All TWT", the driver is asked to tear down flow 128. mt7915 ignores such a flowid in mt7915_mac_twt_teardown_flow() (flowid >= MT7915_MAX_STA_TWT_AGRT), so the agreement stays installed in the firmware. The station no longer follows the TWT schedule while the AP keeps restricting delivery to the service periods, so downlink frames are sent while the station is dozing.

Seen with a Samsung Galaxy S26 Ultra on an MT7981 AP (Xiaomi AX3000T, OpenWrt 25.12.6). The station sets up an individual agreement and tears it down about 200 ms later:

  STA -> AP  TWT Setup     req_type 0x0023 (Suggest, implicit, announced)
  AP  -> STA TWT Setup     req_type 0x0028 (Accept)
  STA -> AP  TWT Teardown  TWT Flow 0x80 (Teardown All TWT, flow id 0)

mt76 twt_stats still lists the agreement afterwards, the station sees thousands of "tx failed" per minute and downlink drops from ~450 Mbit/s to 5-10 Mbit/s until it reassociates.

Decode the field: tear down every flow id when "Teardown All TWT" is set, otherwise pass only the flow identifier, and ignore teardowns of broadcast agreements since only individual agreements can be set up.

With this change the agreement is removed after each teardown and downlink stays at 300-420 Mbit/s with the TWT responder enabled.

Fixes f5a4c24e689f ("mac80211: introduce individual TWT support in AP mode")
---
 net/mac80211/s1g.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
net/mac80211/s1g.c +23 -1
index 4b70afa..96b9beb 100644
@@ -9,6 +9,11 @@
 #include "ieee80211_i.h"
 #include "driver-ops.h"
 
+/* TWT Flow field of the TWT Teardown frame */
+#define IEEE80211_TWT_TEARDOWN_FLOWID		GENMASK(2, 0)
+#define IEEE80211_TWT_TEARDOWN_NEG_TYPE		GENMASK(6, 5)
+#define IEEE80211_TWT_TEARDOWN_ALL		BIT(7)
+
 bool ieee80211_s1g_is_twt_setup(struct sk_buff *skb)
 {
 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
@@ -122,9 +127,26 @@ ieee80211_s1g_rx_twt_teardown(struct ieee80211_sub_if_data *sdata,
 			      struct sta_info *sta, struct sk_buff *skb)
 {
 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
+	u8 flow = mgmt->u.action.s1g.variable[0];
+	u8 flowid;
+
+	if (flow & IEEE80211_TWT_TEARDOWN_ALL) {
+		for (flowid = 0; flowid <= IEEE80211_TWT_TEARDOWN_FLOWID;
+		     flowid++)
+			drv_twt_teardown_request(sdata->local, sdata,
+						 &sta->sta, flowid);
+		return;
+	}
+
+	/* only individual TWT agreements can be set up, see
+	 * ieee80211_s1g_rx_twt_setup()
+	 */
+	if (u8_get_bits(flow, IEEE80211_TWT_TEARDOWN_NEG_TYPE))
+		return;
 
+	flowid = u8_get_bits(flow, IEEE80211_TWT_TEARDOWN_FLOWID);
 	drv_twt_teardown_request(sdata->local, sdata, &sta->sta,
-				 mgmt->u.action.s1g.variable[0]);
+				 flowid);
 }
 
 static void