wifi: mac80211: refactor puncturing bitmap extraction
authorJohannes Berg <johannes.berg@intel.com>
Mon, 29 Jan 2024 18:34:45 +0000 (19:34 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Thu, 8 Feb 2024 12:07:37 +0000 (13:07 +0100)
Add a new inline helper function to ieee80211.h to
extract the disabled subchannels bitmap from an EHT
operation element, and use that in mac80211 where
we do that.

Link: https://msgid.link/20240129194108.d9f50dcec8d0.I8b08cbc2490a734fafcce0fa0fc328211ba6f10b@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/linux/ieee80211.h
net/mac80211/mlme.c

index a70388ae3a7b05f3d91ceadfbea11c9f67f6b880..d9d2c12531579ac22241e7e3ecc425194140bbfb 100644 (file)
@@ -3189,6 +3189,22 @@ ieee80211_eht_oper_size_ok(const u8 *data, u8 len)
        return len >= needed;
 }
 
+/* must validate ieee80211_eht_oper_size_ok() first */
+static inline u16
+ieee80211_eht_oper_dis_subchan_bitmap(const struct ieee80211_eht_operation *eht_oper)
+{
+       const struct ieee80211_eht_operation_info *info =
+               (const void *)eht_oper->optional;
+
+       if (!(eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT))
+               return 0;
+
+       if (!(eht_oper->params & IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT))
+               return 0;
+
+       return get_unaligned_le16(info->optional);
+}
+
 #define IEEE80211_BW_IND_DIS_SUBCH_PRESENT     BIT(1)
 
 struct ieee80211_bandwidth_indication {
index da202103faf0e89be0d1001e9e222acbd3f176f4..74a15f18e7eea38a490079effc8de629dbfb594b 100644 (file)
@@ -813,36 +813,27 @@ again:
        }
 
        if (conn->mode >= IEEE80211_CONN_MODE_EHT) {
-               const struct ieee80211_eht_operation *eht_oper;
+               u16 bitmap;
 
-               eht_oper = elems->eht_operation;
-
-               if (WARN_ON_ONCE(!eht_oper)) {
+               if (WARN_ON_ONCE(!elems->eht_operation)) {
                        ret = -EINVAL;
                        goto free;
                }
 
-               if (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT &&
-                   eht_oper->params & IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT) {
-                       const struct ieee80211_eht_operation_info *info =
-                               (void *)eht_oper->optional;
-                       const u8 *disable_subchannel_bitmap = info->optional;
-                       u16 bitmap;
-
-                       bitmap = get_unaligned_le16(disable_subchannel_bitmap);
-                       if (!cfg80211_valid_disable_subchannel_bitmap(&bitmap,
-                                                                     &ap_chandef) ||
-                           (bitmap &&
-                            ieee80211_hw_check(&local->hw, DISALLOW_PUNCTURING))) {
-                               conn->mode = IEEE80211_CONN_MODE_HE;
-                               conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
-                                                      conn->bw_limit,
-                                                      IEEE80211_CONN_BW_LIMIT_160);
-                               sdata_info(sdata,
-                                          "AP has invalid/unsupported puncturing, disabling EHT\n");
-                       }
-                       /* FIXME: store puncturing bitmap */
+               bitmap = ieee80211_eht_oper_dis_subchan_bitmap(elems->eht_operation);
+
+               if (!cfg80211_valid_disable_subchannel_bitmap(&bitmap,
+                                                             &ap_chandef) ||
+                   (bitmap &&
+                    ieee80211_hw_check(&local->hw, DISALLOW_PUNCTURING))) {
+                       conn->mode = IEEE80211_CONN_MODE_HE;
+                       conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
+                                              conn->bw_limit,
+                                              IEEE80211_CONN_BW_LIMIT_160);
+                       sdata_info(sdata,
+                                  "AP has invalid/unsupported puncturing, disabling EHT\n");
                }
+               /* FIXME: store puncturing bitmap */
        }
 
        /* the mode can only decrease, so this must terminate */
@@ -5879,18 +5870,9 @@ static bool ieee80211_config_puncturing(struct ieee80211_link_data *link,
                                        u64 *changed)
 {
        struct ieee80211_local *local = link->sdata->local;
-       u16 bitmap = 0, extracted;
-
-       if ((eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
-           (eht_oper->params &
-            IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
-               const struct ieee80211_eht_operation_info *info =
-                       (void *)eht_oper->optional;
-               const u8 *disable_subchannel_bitmap = info->optional;
-
-               bitmap = get_unaligned_le16(disable_subchannel_bitmap);
-       }
+       u16 bitmap, extracted;
 
+       bitmap = ieee80211_eht_oper_dis_subchan_bitmap(eht_oper);
        extracted = ieee80211_extract_dis_subch_bmap(eht_oper,
                                                     &link->conf->chanreq.oper,
                                                     bitmap);