]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
wifi: mac80211: add strict mode disabling workarounds
authorJohannes Berg <johannes.berg@intel.com>
Wed, 5 Feb 2025 09:39:16 +0000 (11:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 20 Apr 2025 08:15:17 +0000 (10:15 +0200)
[ Upstream commit 3ad4fce66e4f9d82abfc366707757e29cc14a9d2 ]

Add a strict mode where we disable certain workarounds and have
additional checks such as, for now, that VHT capabilities from
association response match those from beacon/probe response. We
can extend the checks in the future.

Make it an opt-in setting by the driver so it can be set there
in some driver-specific way, for example. Also allow setting
this one hw flag through the hwflags debugfs, by writing a new
strict=0 or strict=1 value.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Reviewed-by: Ilan Peer <ilan.peer@intel.com>
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20250205110958.5cecb0469479.I4a69617dc60ba0d6308416ffbc3102cfd08ba068@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/mac80211.h
net/mac80211/debugfs.c
net/mac80211/mlme.c

index 5b712582f9a9ce6180430125cbd7129dbb9b2946..3b964f8834e7196da35e3cf01493db59366276a4 100644 (file)
@@ -2826,6 +2826,11 @@ struct ieee80211_txq {
  *     implements MLO, so operation can continue on other links when one
  *     link is switching.
  *
+ * @IEEE80211_HW_STRICT: strictly enforce certain things mandated by the spec
+ *     but otherwise ignored/worked around for interoperability. This is a
+ *     HW flag so drivers can opt in according to their own control, e.g. in
+ *     testing.
+ *
  * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
  */
 enum ieee80211_hw_flags {
@@ -2885,6 +2890,7 @@ enum ieee80211_hw_flags {
        IEEE80211_HW_DISALLOW_PUNCTURING,
        IEEE80211_HW_DISALLOW_PUNCTURING_5GHZ,
        IEEE80211_HW_HANDLES_QUIET_CSA,
+       IEEE80211_HW_STRICT,
 
        /* keep last, obviously */
        NUM_IEEE80211_HW_FLAGS
index 02b5476a4376c0778b57ec73d382ec96dd2b12ef..a0710ae0e7a499be6b2074ae16d92423e0dbff21 100644 (file)
@@ -499,6 +499,7 @@ static const char *hw_flag_names[] = {
        FLAG(DISALLOW_PUNCTURING),
        FLAG(DISALLOW_PUNCTURING_5GHZ),
        FLAG(HANDLES_QUIET_CSA),
+       FLAG(STRICT),
 #undef FLAG
 };
 
@@ -531,6 +532,46 @@ static ssize_t hwflags_read(struct file *file, char __user *user_buf,
        return rv;
 }
 
+static ssize_t hwflags_write(struct file *file, const char __user *user_buf,
+                            size_t count, loff_t *ppos)
+{
+       struct ieee80211_local *local = file->private_data;
+       char buf[100];
+       int val;
+
+       if (count >= sizeof(buf))
+               return -EINVAL;
+
+       if (copy_from_user(buf, user_buf, count))
+               return -EFAULT;
+
+       if (count && buf[count - 1] == '\n')
+               buf[count - 1] = '\0';
+       else
+               buf[count] = '\0';
+
+       if (sscanf(buf, "strict=%d", &val) == 1) {
+               switch (val) {
+               case 0:
+                       ieee80211_hw_set(&local->hw, STRICT);
+                       return count;
+               case 1:
+                       __clear_bit(IEEE80211_HW_STRICT, local->hw.flags);
+                       return count;
+               default:
+                       return -EINVAL;
+               }
+       }
+
+       return -EINVAL;
+}
+
+static const struct file_operations hwflags_ops = {
+       .open = simple_open,
+       .read = hwflags_read,
+       .write = hwflags_write,
+};
+
 static ssize_t misc_read(struct file *file, char __user *user_buf,
                         size_t count, loff_t *ppos)
 {
@@ -581,7 +622,6 @@ static ssize_t queues_read(struct file *file, char __user *user_buf,
        return simple_read_from_buffer(user_buf, count, ppos, buf, res);
 }
 
-DEBUGFS_READONLY_FILE_OPS(hwflags);
 DEBUGFS_READONLY_FILE_OPS(queues);
 DEBUGFS_READONLY_FILE_OPS(misc);
 
@@ -659,7 +699,7 @@ void debugfs_hw_add(struct ieee80211_local *local)
 #ifdef CONFIG_PM
        DEBUGFS_ADD_MODE(reset, 0200);
 #endif
-       DEBUGFS_ADD(hwflags);
+       DEBUGFS_ADD_MODE(hwflags, 0600);
        DEBUGFS_ADD(user_power);
        DEBUGFS_ADD(power);
        DEBUGFS_ADD(hw_conf);
index 88751b0eb317a367683b1802c62a42bec6bf55f6..ad0d040569dcd3cfabc36cc149f781251cc40f45 100644 (file)
@@ -166,6 +166,9 @@ ieee80211_determine_ap_chan(struct ieee80211_sub_if_data *sdata,
        bool no_vht = false;
        u32 ht_cfreq;
 
+       if (ieee80211_hw_check(&sdata->local->hw, STRICT))
+               ignore_ht_channel_mismatch = false;
+
        *chandef = (struct cfg80211_chan_def) {
                .chan = channel,
                .width = NL80211_CHAN_WIDTH_20_NOHT,
@@ -385,7 +388,7 @@ ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
         * zeroes, which is nonsense, and completely inconsistent with itself
         * (it doesn't have 8 streams). Accept the settings in this case anyway.
         */
-       if (!ap_min_req_set)
+       if (!ieee80211_hw_check(&sdata->local->hw, STRICT) && !ap_min_req_set)
                return true;
 
        /* make sure the AP is consistent with itself
@@ -445,7 +448,7 @@ ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
         * zeroes, which is nonsense, and completely inconsistent with itself
         * (it doesn't have 8 streams). Accept the settings in this case anyway.
         */
-       if (!ap_min_req_set)
+       if (!ieee80211_hw_check(&sdata->local->hw, STRICT) && !ap_min_req_set)
                return true;
 
        /* Need to go over for 80MHz, 160MHz and for 80+80 */
@@ -1212,13 +1215,15 @@ static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
         * Some APs apparently get confused if our capabilities are better
         * than theirs, so restrict what we advertise in the assoc request.
         */
-       if (!(ap_vht_cap->vht_cap_info &
-                       cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
-               cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
-                        IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
-       else if (!(ap_vht_cap->vht_cap_info &
-                       cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
-               cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
+       if (!ieee80211_hw_check(&local->hw, STRICT)) {
+               if (!(ap_vht_cap->vht_cap_info &
+                               cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
+                       cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
+                                IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
+               else if (!(ap_vht_cap->vht_cap_info &
+                               cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
+                       cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
+       }
 
        /*
         * If some other vif is using the MU-MIMO capability we cannot associate
@@ -1260,14 +1265,16 @@ static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
        return mu_mimo_owner;
 }
 
-static void ieee80211_assoc_add_rates(struct sk_buff *skb,
+static void ieee80211_assoc_add_rates(struct ieee80211_local *local,
+                                     struct sk_buff *skb,
                                      enum nl80211_chan_width width,
                                      struct ieee80211_supported_band *sband,
                                      struct ieee80211_mgd_assoc_data *assoc_data)
 {
        u32 rates;
 
-       if (assoc_data->supp_rates_len) {
+       if (assoc_data->supp_rates_len &&
+           !ieee80211_hw_check(&local->hw, STRICT)) {
                /*
                 * Get all rates supported by the device and the AP as
                 * some APs don't like getting a superset of their rates
@@ -1481,7 +1488,7 @@ static size_t ieee80211_assoc_link_elems(struct ieee80211_sub_if_data *sdata,
                *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
 
        if (sband->band != NL80211_BAND_S1GHZ)
-               ieee80211_assoc_add_rates(skb, width, sband, assoc_data);
+               ieee80211_assoc_add_rates(local, skb, width, sband, assoc_data);
 
        if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
            *capab & WLAN_CAPABILITY_RADIO_MEASURE) {
@@ -1925,7 +1932,8 @@ static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
         * for some reason check it and want it to be set, set the bit for all
         * pre-EHT connections as we used to do.
         */
-       if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_EHT)
+       if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_EHT &&
+           !ieee80211_hw_check(&local->hw, STRICT))
                capab |= WLAN_CAPABILITY_ESS;
 
        /* add the elements for the assoc (main) link */
@@ -4710,7 +4718,7 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
         * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
         * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
         */
-       if (!is_6ghz &&
+       if (!ieee80211_hw_check(&local->hw, STRICT) && !is_6ghz &&
            ((assoc_data->wmm && !elems->wmm_param) ||
             (link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT &&
              (!elems->ht_cap_elem || !elems->ht_operation)) ||
@@ -4846,6 +4854,15 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
                                bss_vht_cap = (const void *)elem->data;
                }
 
+               if (ieee80211_hw_check(&local->hw, STRICT) &&
+                   (!bss_vht_cap || memcmp(bss_vht_cap, elems->vht_cap_elem,
+                                           sizeof(*bss_vht_cap)))) {
+                       rcu_read_unlock();
+                       ret = false;
+                       link_info(link, "VHT capabilities mismatch\n");
+                       goto out;
+               }
+
                ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
                                                    elems->vht_cap_elem,
                                                    bss_vht_cap, link_sta);