[PATCH] wifi: mt7601u: add monitor mode and packet injection support
From: Herman Semenoff
Date: Tue Nov 17 2026 - 00:10:58 EST
From: Herman Semenoff <GermanAizek@xxxxxxxxxxxxx>
Date: Tue, 17 Nov 2026 07:55:00 +0300
Subject: [PATCH wireless-next] wifi: mt7601u: add monitor mode and
packet injection support
The mt7601u driver currently only advertises NL80211_IFTYPE_STATION
and lacks proper monitor mode and raw frame transmission (packet
injection) support.
Specifically:
1. When switching to monitor mode, mac80211 raises
IEEE80211_CONF_CHANGE_MONITOR in ops->config(), but mt7601u ignores
it. As a result, MT_RX_FILTR_CFG_PROMISC remains set in the hardware
RX filter, causing the MAC to drop third-party frames.
2. In mt7601u_add_interface(), adding a monitor interface (e.g. via
airmon-ng) allocates a GROUP_WCID and overwrites dev->macaddr.
If a station interface already exists, add_interface() fails with
-ENOSPC. For monitor interfaces, do not allocate a group WCID and
do not override the device MAC address.
3. In mt7601u_mac_start(), ensure MT_RX_FILTR_CFG_PROMISC is cleared if
IEEE80211_CONF_MONITOR is active.
4. In mt76_configure_filter(), include MT_RX_FILTR_CFG_RTS and
MT_RX_FILTR_CFG_BAR in the control frame filter so RTS and BAR frames
can be captured in monitor mode.
5. In mt7601u_register_device(), allocate dev->mon_wcid with
devm_kzalloc() instead of uninitialized devm_kmalloc() to ensure
rate control fields start in a clean state, and add
NL80211_IFTYPE_MONITOR to interface_modes.
6. In mt7601u_tx(), transmit packets via dev->mon_wcid when transmitting
on a monitor interface (vif->type == NL80211_IFTYPE_MONITOR).
Signed-off-by: Herman Semenoff <GermanAizek@xxxxxxxxx>
Signed-off-by: Herman Semenoff <GermanAizek@xxxxxxxxxxxxx>
---
drivers/net/wireless/mediatek/mt7601u/init.c | 7 ++++---
drivers/net/wireless/mediatek/mt7601u/main.c | 20 ++++++++++++++++++++
drivers/net/wireless/mediatek/mt7601u/tx.c | 2 +-
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt7601u/init.c
b/drivers/net/wireless/mediatek/mt7601u/init.c
index 5d9e952b2966..c01bb3fc4a7f 100644
--- a/drivers/net/wireless/mediatek/mt7601u/init.c
+++ b/drivers/net/wireless/mediatek/mt7601u/init.c
@@ -242,6 +242,8 @@ int mt7601u_mac_start(struct mt7601u_dev *dev)
MT_RX_FILTR_CFG_ACK | MT_RX_FILTR_CFG_CTS |
MT_RX_FILTR_CFG_RTS | MT_RX_FILTR_CFG_PSPOLL |
MT_RX_FILTR_CFG_BA | MT_RX_FILTR_CFG_CTRL_RSV;
+ if (dev->hw->conf.flags & IEEE80211_CONF_MONITOR)
+ dev->rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
mt7601u_wr(dev, MT_RX_FILTR_CFG, dev->rxfilter);
mt7601u_wr(dev, MT_MAC_SYS_CTRL,
@@ -583,8 +585,8 @@ int mt7601u_register_device(struct mt7601u_dev *dev)
dev->wcid_mask[0] |= 1;
/* init fake wcid for monitor interfaces */
- dev->mon_wcid = devm_kmalloc(dev->dev, sizeof(*dev->mon_wcid),
- GFP_KERNEL);
+ dev->mon_wcid = devm_kzalloc(dev->dev, sizeof(*dev->mon_wcid),
+ GFP_KERNEL);
if (!dev->mon_wcid)
return -ENOMEM;
dev->mon_wcid->idx = 0xff;
@@ -609,7 +611,8 @@ int mt7601u_register_device(struct mt7601u_dev *dev)
SET_IEEE80211_PERM_ADDR(hw, dev->macaddr);
wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
- wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
+ wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
+ BIT(NL80211_IFTYPE_MONITOR);
wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
diff --git a/drivers/net/wireless/mediatek/mt7601u/main.c
b/drivers/net/wireless/mediatek/mt7601u/main.c
index 05ba43e1985c..29486c4767e3 100644
--- a/drivers/net/wireless/mediatek/mt7601u/main.c
+++ b/drivers/net/wireless/mediatek/mt7601u/main.c
@@ -56,6 +56,12 @@ static int mt7601u_add_interface(struct ieee80211_hw *hw,
*/
mvif->idx = idx;
+ if (vif->type == NL80211_IFTYPE_MONITOR) {
+ mvif->group_wcid.idx = 0xff;
+ mvif->group_wcid.hw_key_idx = -1;
+ return 0;
+ }
+
if (!ether_addr_equal(dev->macaddr, vif->addr))
mt7601u_set_macaddr(dev, vif->addr);
@@ -75,6 +81,9 @@ static void mt7601u_remove_interface(struct ieee80211_hw *hw,
struct mt76_vif *mvif = (struct mt76_vif *) vif->drv_priv;
unsigned int wcid = mvif->group_wcid.idx;
+ if (vif->type == NL80211_IFTYPE_MONITOR)
+ return;
+
dev->wcid_mask[wcid / BITS_PER_LONG] &= ~BIT(wcid % BITS_PER_LONG);
}
@@ -91,6 +100,15 @@ static int mt7601u_config(struct ieee80211_hw *hw,
int radio_idx, u32 changed)
ieee80211_wake_queues(hw);
}
+ if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
+ if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
+ dev->rxfilter |= MT_RX_FILTR_CFG_PROMISC;
+ else
+ dev->rxfilter &= ~MT_RX_FILTR_CFG_PROMISC;
+
+ mt76_wr(dev, MT_RX_FILTR_CFG, dev->rxfilter);
+ }
+
mutex_unlock(&dev->mutex);
return ret;
@@ -118,6 +136,8 @@ mt76_configure_filter(struct ieee80211_hw *hw,
unsigned int changed_flags,
MT76_FILTER(PLCPFAIL, MT_RX_FILTR_CFG_PHY_ERR);
MT76_FILTER(CONTROL, MT_RX_FILTR_CFG_ACK |
MT_RX_FILTR_CFG_CTS |
+ MT_RX_FILTR_CFG_RTS |
+ MT_RX_FILTR_CFG_BAR |
MT_RX_FILTR_CFG_CFEND |
MT_RX_FILTR_CFG_CFACK |
MT_RX_FILTR_CFG_BA |
diff --git a/drivers/net/wireless/mediatek/mt7601u/tx.c
b/drivers/net/wireless/mediatek/mt7601u/tx.c
index 5aeeac0dd9fe..d3328181f961 100644
--- a/drivers/net/wireless/mediatek/mt7601u/tx.c
+++ b/drivers/net/wireless/mediatek/mt7601u/tx.c
@@ -211,7 +211,7 @@ void mt7601u_tx(struct ieee80211_hw *hw, struct
ieee80211_tx_control *control,
if (sta) {
msta = (struct mt76_sta *) sta->drv_priv;
wcid = &msta->wcid;
- } else if (vif) {
+ } else if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
struct mt76_vif *mvif = (struct mt76_vif *)vif->drv_priv;
wcid = &mvif->group_wcid;
--
2.55.0