Skip to content

Commit

Permalink
wifi: mt76: mt7921: fix channel switch fail in monitor mode
Browse files Browse the repository at this point in the history
When the chanctx enabled, IEEE80211_CONF_CHANGE_CHANNEL in .config()
would not be called anymore. mt76 cannot control RF channel for monitor.
Add monitor type set-channel flow in .change_chanctx().

Fixes: 41ac53c899bd ("wifi: mt76: mt7921: introduce chanctx support")
Reviewed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
deren authored and nbd168 committed Jan 23, 2023
1 parent 99e96b8 commit 833cd42
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mt7921/main.c
Expand Up @@ -1706,7 +1706,10 @@ static void mt7921_ctx_iter(void *priv, u8 *mac,
if (ctx != mvif->ctx)
return;

mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->mt76, ctx);
if (vif->type & NL80211_IFTYPE_MONITOR)
mt7921_mcu_config_sniffer(mvif, ctx);
else
mt76_connac_mcu_uni_set_chctx(mvif->phy->mt76, &mvif->mt76, ctx);
}

static void
Expand Down
68 changes: 68 additions & 0 deletions mt7921/mcu.c
Expand Up @@ -1093,6 +1093,74 @@ int mt7921_mcu_set_sniffer(struct mt7921_dev *dev, struct ieee80211_vif *vif,
true);
}

int mt7921_mcu_config_sniffer(struct mt7921_vif *vif,
struct ieee80211_chanctx_conf *ctx)
{
struct cfg80211_chan_def *chandef = &ctx->def;
int freq1 = chandef->center_freq1, freq2 = chandef->center_freq2;
const u8 ch_band[] = {
[NL80211_BAND_2GHZ] = 1,
[NL80211_BAND_5GHZ] = 2,
[NL80211_BAND_6GHZ] = 3,
};
const u8 ch_width[] = {
[NL80211_CHAN_WIDTH_20_NOHT] = 0,
[NL80211_CHAN_WIDTH_20] = 0,
[NL80211_CHAN_WIDTH_40] = 0,
[NL80211_CHAN_WIDTH_80] = 1,
[NL80211_CHAN_WIDTH_160] = 2,
[NL80211_CHAN_WIDTH_80P80] = 3,
[NL80211_CHAN_WIDTH_5] = 4,
[NL80211_CHAN_WIDTH_10] = 5,
[NL80211_CHAN_WIDTH_320] = 6,
};
struct {
struct {
u8 band_idx;
u8 pad[3];
} __packed hdr;
struct config_tlv {
__le16 tag;
__le16 len;
u16 aid;
u8 ch_band;
u8 bw;
u8 control_ch;
u8 sco;
u8 center_ch;
u8 center_ch2;
u8 drop_err;
u8 pad[3];
} __packed tlv;
} __packed req = {
.hdr = {
.band_idx = vif->mt76.band_idx,
},
.tlv = {
.tag = cpu_to_le16(1),
.len = cpu_to_le16(sizeof(req.tlv)),
.control_ch = chandef->chan->hw_value,
.center_ch = ieee80211_frequency_to_channel(freq1),
.drop_err = 1,
},
};
if (chandef->chan->band < ARRAY_SIZE(ch_band))
req.tlv.ch_band = ch_band[chandef->chan->band];
if (chandef->width < ARRAY_SIZE(ch_width))
req.tlv.bw = ch_width[chandef->width];

if (freq2)
req.tlv.center_ch2 = ieee80211_frequency_to_channel(freq2);

if (req.tlv.control_ch < req.tlv.center_ch)
req.tlv.sco = 1; /* SCA */
else if (req.tlv.control_ch > req.tlv.center_ch)
req.tlv.sco = 3; /* SCB */

return mt76_mcu_send_msg(vif->phy->mt76->dev, MCU_UNI_CMD(SNIFFER),
&req, sizeof(req), true);
}

int
mt7921_mcu_uni_add_beacon_offload(struct mt7921_dev *dev,
struct ieee80211_hw *hw,
Expand Down
2 changes: 2 additions & 0 deletions mt7921/mt7921.h
Expand Up @@ -529,6 +529,8 @@ void mt7921_set_ipv6_ns_work(struct work_struct *work);

int mt7921_mcu_set_sniffer(struct mt7921_dev *dev, struct ieee80211_vif *vif,
bool enable);
int mt7921_mcu_config_sniffer(struct mt7921_vif *vif,
struct ieee80211_chanctx_conf *ctx);

int mt7921_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
enum mt76_txq_id qid, struct mt76_wcid *wcid,
Expand Down

0 comments on commit 833cd42

Please sign in to comment.