The AR6006 firmware in the Xiaomi AIoT AC2350 reports a dual band phy in its ready event, but the board only has a 2.4 GHz front end. A scan on that router saw no 5 GHz network at all, not even the router's own. Call wiphy_read_of_freq_limits() before the wiphy is registered, so a board can describe the limit with ieee80211-freq-limit on the node of the USB device. It works on the per-device channel copies, so other ath6kl devices are not affected. A band that has no enabled channel left is dropped from the wiphy, so user space does not see a band full of disabled channels. A limit that leaves no channel at all only gets a warning. The ath6kl loops over wiphy->bands already skip a missing band, and the previous patch handles a connection on a frequency that has no channel. ath6kl does not pass the limit to the firmware, which picks the network on its own. Reject a connection on a channel that the limit disabled, as the previous patch does for a frequency without a channel. The check uses orig_flags, as brcmfmac does, so a channel that only the regulatory domain disables is not affected. Signed-off-by: Josef Schlehofer --- On the router, ieee80211-freq-limit = <2400000 2483000> on the node of the USB port, added at runtime, left only the 2.4 GHz band in iw phy, and station and AP mode worked. With <2400000 2430000> only channels 1 and 2 stayed enabled, and connections the firmware made on channel 6 were rejected. drivers/net/wireless/ath/ath6kl/cfg80211.c | 41 ++++++++++++++++++++++ drivers/net/wireless/ath/ath6kl/main.c | 8 +++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c index 7f1ffe4b7..97107510b 100644 --- a/drivers/net/wireless/ath/ath6kl/cfg80211.c +++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c @@ -3875,6 +3875,39 @@ static const struct wiphy_wowlan_support ath6kl_wowlan_support = { }; #endif +static bool +ath6kl_band_has_channel(const struct ieee80211_supported_band *sband) +{ + int i; + + for (i = 0; i < sband->n_channels; i++) + if (!(sband->channels[i].flags & IEEE80211_CHAN_DISABLED)) + return true; + + return false; +} + +/* drop bands without an enabled channel, unless no band would be left */ +static void ath6kl_drop_empty_bands(struct wiphy *wiphy) +{ + int band, left = 0; + + for (band = 0; band < NUM_NL80211_BANDS; band++) + if (wiphy->bands[band] && + ath6kl_band_has_channel(wiphy->bands[band])) + left++; + + if (!left) { + ath6kl_warn("ieee80211-freq-limit leaves no channel\n"); + return; + } + + for (band = 0; band < NUM_NL80211_BANDS; band++) + if (wiphy->bands[band] && + !ath6kl_band_has_channel(wiphy->bands[band])) + wiphy->bands[band] = NULL; +} + int ath6kl_cfg80211_init(struct ath6kl *ar) { struct wiphy *wiphy = ar->wiphy; @@ -3990,6 +4023,14 @@ int ath6kl_cfg80211_init(struct ath6kl *ar) if (band_5gig) wiphy->bands[NL80211_BAND_5GHZ] = &ar->band_5ghz; + /* + * Some boards only have a front end for one band although the + * firmware reports a dual band phy. Let the device tree limit the + * channels and drop a band that has none left. + */ + wiphy_read_of_freq_limits(wiphy); + ath6kl_drop_empty_bands(wiphy); + wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; wiphy->cipher_suites = cipher_suites; diff --git a/drivers/net/wireless/ath/ath6kl/main.c b/drivers/net/wireless/ath/ath6kl/main.c index a062598ce..20fa471a9 100644 --- a/drivers/net/wireless/ath/ath6kl/main.c +++ b/drivers/net/wireless/ath/ath6kl/main.c @@ -632,12 +632,16 @@ void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid, u8 *assoc_info) { struct ath6kl *ar = vif->ar; + struct ieee80211_channel *chan; /* * cfg80211 needs a channel for the BSS. Reject a connection on a - * frequency that has no channel on this device. + * frequency without a channel here, or on a channel disabled before + * wiphy_register() (orig_flags), as ieee80211-freq-limit does. Later + * regulatory updates only change flags. */ - if (!ieee80211_get_channel(ar->wiphy, channel)) { + chan = ieee80211_get_channel(ar->wiphy, channel); + if (!chan || (chan->orig_flags & IEEE80211_CHAN_DISABLED)) { ath6kl_err("connected on unsupported frequency %u MHz\n", channel); ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx); ath6kl_disconnect_event(vif, DISCONNECT_CMD, bssid, 0, NULL, -- 2.54.0 (Apple Git-157)