1 From aa87cd8b35736a5183745ab0ec4b82419024dfd7 Mon Sep 17 00:00:00 2001
2 From: Johannes Berg <johannes.berg@intel.com>
3 Date: Fri, 27 Jan 2023 12:39:31 +0100
4 Subject: [PATCH] wifi: mac80211: mlme: handle EHT channel puncturing
6 Handle the Puncturing info received from the AP in the
7 EHT Operation element in beacons.
9 If the info is invalid:
10 - during association: disable EHT connection for the AP
11 - after association: disconnect
13 This commit includes many (internal) bugfixes and spec
14 updates various people.
16 Co-developed-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
17 Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
18 Link: https://lore.kernel.org/r/20230127123930.4fbc74582331.I3547481d49f958389f59dfeba3fcc75e72b0aa6e@changeid
19 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
21 include/net/mac80211.h | 5 +-
22 net/mac80211/cfg.c | 2 +-
23 net/mac80211/chan.c | 2 +-
24 net/mac80211/ieee80211_i.h | 2 +-
25 net/mac80211/mlme.c | 224 ++++++++++++++++++++++++++++++++++++-
26 5 files changed, 228 insertions(+), 7 deletions(-)
28 --- a/include/net/mac80211.h
29 +++ b/include/net/mac80211.h
30 @@ -340,7 +340,7 @@ struct ieee80211_vif_chanctx_switch {
31 * @BSS_CHANGED_FILS_DISCOVERY: FILS discovery status changed.
32 * @BSS_CHANGED_UNSOL_BCAST_PROBE_RESP: Unsolicited broadcast probe response
35 + * @BSS_CHANGED_EHT_PUNCTURING: The channel puncturing bitmap changed.
37 enum ieee80211_bss_change {
38 BSS_CHANGED_ASSOC = 1<<0,
39 @@ -375,6 +375,7 @@ enum ieee80211_bss_change {
40 BSS_CHANGED_HE_BSS_COLOR = 1<<29,
41 BSS_CHANGED_FILS_DISCOVERY = 1<<30,
42 BSS_CHANGED_UNSOL_BCAST_PROBE_RESP = 1<<31,
43 + BSS_CHANGED_EHT_PUNCTURING = BIT_ULL(32),
45 /* when adding here, make sure to change ieee80211_reconfig */
47 @@ -640,6 +641,7 @@ struct ieee80211_fils_discovery {
48 * @tx_pwr_env_num: number of @tx_pwr_env.
49 * @pwr_reduction: power constraint of BSS.
50 * @eht_support: does this BSS support EHT
51 + * @eht_puncturing: bitmap to indicate which channels are punctured in this BSS
52 * @csa_active: marks whether a channel switch is going on. Internally it is
53 * write-protected by sdata_lock and local->mtx so holding either is fine
55 @@ -739,6 +741,7 @@ struct ieee80211_bss_conf {
63 --- a/net/mac80211/cfg.c
64 +++ b/net/mac80211/cfg.c
65 @@ -4195,7 +4195,7 @@ static int ieee80211_set_ap_chanwidth(st
66 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
67 struct ieee80211_link_data *link;
72 link = sdata_dereference(sdata->link[link_id], sdata);
74 --- a/net/mac80211/chan.c
75 +++ b/net/mac80211/chan.c
76 @@ -1935,7 +1935,7 @@ int ieee80211_link_use_reserved_context(
78 int ieee80211_link_change_bandwidth(struct ieee80211_link_data *link,
79 const struct cfg80211_chan_def *chandef,
83 struct ieee80211_sub_if_data *sdata = link->sdata;
84 struct ieee80211_bss_conf *link_conf = link->conf;
85 --- a/net/mac80211/ieee80211_i.h
86 +++ b/net/mac80211/ieee80211_i.h
87 @@ -2497,7 +2497,7 @@ int ieee80211_link_unreserve_chanctx(str
89 ieee80211_link_change_bandwidth(struct ieee80211_link_data *link,
90 const struct cfg80211_chan_def *chandef,
93 void ieee80211_link_release_channel(struct ieee80211_link_data *link);
94 void ieee80211_link_vlan_copy_chanctx(struct ieee80211_link_data *link);
95 void ieee80211_link_copy_chanctx_to_vlans(struct ieee80211_link_data *link,
96 --- a/net/mac80211/mlme.c
97 +++ b/net/mac80211/mlme.c
99 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
100 * Copyright 2013-2014 Intel Mobile Communications GmbH
101 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
102 - * Copyright (C) 2018 - 2022 Intel Corporation
103 + * Copyright (C) 2018 - 2023 Intel Corporation
106 #include <linux/delay.h>
107 @@ -88,6 +88,141 @@ MODULE_PARM_DESC(probe_wait_ms,
109 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
111 +struct ieee80211_per_bw_puncturing_values {
113 + const u16 *valid_values;
116 +static const u16 puncturing_values_80mhz[] = {
120 +static const u16 puncturing_values_160mhz[] = {
121 + 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1, 0xc0, 0x30, 0xc, 0x3
124 +static const u16 puncturing_values_320mhz[] = {
125 + 0xc000, 0x3000, 0xc00, 0x300, 0xc0, 0x30, 0xc, 0x3, 0xf000, 0xf00,
126 + 0xf0, 0xf, 0xfc00, 0xf300, 0xf0c0, 0xf030, 0xf00c, 0xf003, 0xc00f,
127 + 0x300f, 0xc0f, 0x30f, 0xcf, 0x3f
130 +#define IEEE80211_PER_BW_VALID_PUNCTURING_VALUES(_bw) \
132 + .len = ARRAY_SIZE(puncturing_values_ ## _bw ## mhz), \
133 + .valid_values = puncturing_values_ ## _bw ## mhz \
136 +static const struct ieee80211_per_bw_puncturing_values per_bw_puncturing[] = {
137 + IEEE80211_PER_BW_VALID_PUNCTURING_VALUES(80),
138 + IEEE80211_PER_BW_VALID_PUNCTURING_VALUES(160),
139 + IEEE80211_PER_BW_VALID_PUNCTURING_VALUES(320)
142 +static bool ieee80211_valid_disable_subchannel_bitmap(u16 *bitmap,
143 + enum nl80211_chan_width bw)
148 + case NL80211_CHAN_WIDTH_80:
151 + case NL80211_CHAN_WIDTH_160:
154 + case NL80211_CHAN_WIDTH_320:
165 + for (i = 0; i < per_bw_puncturing[idx].len; i++)
166 + if (per_bw_puncturing[idx].valid_values[i] == *bitmap)
173 + * Extract from the given disabled subchannel bitmap (raw format
174 + * from the EHT Operation Element) the bits for the subchannel
175 + * we're using right now.
178 +ieee80211_extract_dis_subch_bmap(const struct ieee80211_eht_operation *eht_oper,
179 + struct cfg80211_chan_def *chandef, u16 bitmap)
181 + struct ieee80211_eht_operation_info *info = (void *)eht_oper->optional;
182 + struct cfg80211_chan_def ap_chandef = *chandef;
183 + u32 ap_center_freq, local_center_freq;
184 + u32 ap_bw, local_bw;
185 + int ap_start_freq, local_start_freq;
188 + if (!(eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) ||
189 + !(eht_oper->params &
190 + IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT))
193 + /* set 160/320 supported to get the full AP definition */
194 + ieee80211_chandef_eht_oper(eht_oper, true, true, &ap_chandef);
195 + ap_center_freq = ap_chandef.center_freq1;
196 + ap_bw = 20 * BIT(u8_get_bits(info->control,
197 + IEEE80211_EHT_OPER_CHAN_WIDTH));
198 + ap_start_freq = ap_center_freq - ap_bw / 2;
199 + local_center_freq = chandef->center_freq1;
200 + local_bw = 20 * BIT(ieee80211_chan_width_to_rx_bw(chandef->width));
201 + local_start_freq = local_center_freq - local_bw / 2;
202 + shift = (local_start_freq - ap_start_freq) / 20;
203 + mask = BIT(local_bw / 20) - 1;
205 + return (bitmap >> shift) & mask;
209 + * Handle the puncturing bitmap, possibly downgrading bandwidth to get a
213 +ieee80211_handle_puncturing_bitmap(struct ieee80211_link_data *link,
214 + const struct ieee80211_eht_operation *eht_oper,
215 + u16 bitmap, u64 *changed)
217 + struct cfg80211_chan_def *chandef = &link->conf->chandef;
222 + changed = &_changed;
224 + while (chandef->width > NL80211_CHAN_WIDTH_40) {
226 + ieee80211_extract_dis_subch_bmap(eht_oper, chandef,
229 + if (ieee80211_valid_disable_subchannel_bitmap(&bitmap,
232 + link->u.mgd.conn_flags |=
233 + ieee80211_chandef_downgrade(chandef);
234 + *changed |= BSS_CHANGED_BANDWIDTH;
237 + if (chandef->width <= NL80211_CHAN_WIDTH_40)
240 + if (link->conf->eht_puncturing != extracted) {
241 + link->conf->eht_puncturing = extracted;
242 + *changed |= BSS_CHANGED_EHT_PUNCTURING;
247 * We can have multiple work items (and connection probing)
248 * scheduling this timer, but we need to take care to only
249 @@ -413,7 +548,7 @@ static int ieee80211_config_bw(struct ie
250 const struct ieee80211_he_operation *he_oper,
251 const struct ieee80211_eht_operation *eht_oper,
252 const struct ieee80211_s1g_oper_ie *s1g_oper,
253 - const u8 *bssid, u32 *changed)
254 + const u8 *bssid, u64 *changed)
256 struct ieee80211_sub_if_data *sdata = link->sdata;
257 struct ieee80211_local *local = sdata->local;
258 @@ -4140,6 +4275,7 @@ static bool ieee80211_assoc_config_link(
261 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
262 + *changed |= BSS_CHANGED_EHT_PUNCTURING;
264 bss_conf->eht_support = false;
266 @@ -5452,6 +5588,45 @@ static bool ieee80211_rx_our_beacon(cons
267 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
270 +static bool ieee80211_config_puncturing(struct ieee80211_link_data *link,
271 + const struct ieee80211_eht_operation *eht_oper,
274 + u16 bitmap = 0, extracted;
276 + if ((eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
277 + (eht_oper->params &
278 + IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
279 + const struct ieee80211_eht_operation_info *info =
280 + (void *)eht_oper->optional;
281 + const u8 *disable_subchannel_bitmap = info->optional;
283 + bitmap = get_unaligned_le16(disable_subchannel_bitmap);
286 + extracted = ieee80211_extract_dis_subch_bmap(eht_oper,
287 + &link->conf->chandef,
290 + /* accept if there are no changes */
291 + if (!(*changed & BSS_CHANGED_BANDWIDTH) &&
292 + extracted == link->conf->eht_puncturing)
295 + if (!ieee80211_valid_disable_subchannel_bitmap(&bitmap,
296 + link->conf->chandef.width)) {
298 + "Got an invalid disable subchannel bitmap from AP %pM: bitmap = 0x%x, bw = 0x%x. disconnect\n",
301 + link->conf->chandef.width);
305 + ieee80211_handle_puncturing_bitmap(link, eht_oper, bitmap, changed);
309 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
310 struct ieee80211_hdr *hdr, size_t len,
311 struct ieee80211_rx_status *rx_status)
312 @@ -5468,7 +5643,7 @@ static void ieee80211_rx_mgmt_beacon(str
313 struct ieee80211_channel *chan;
314 struct link_sta_info *link_sta;
315 struct sta_info *sta;
321 @@ -5761,6 +5936,21 @@ static void ieee80211_rx_mgmt_beacon(str
322 elems->pwr_constr_elem,
323 elems->cisco_dtpc_elem);
325 + if (elems->eht_operation &&
326 + !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
327 + if (!ieee80211_config_puncturing(link, elems->eht_operation,
329 + ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
330 + WLAN_REASON_DEAUTH_LEAVING,
332 + ieee80211_report_disconnect(sdata, deauth_buf,
333 + sizeof(deauth_buf), true,
334 + WLAN_REASON_DEAUTH_LEAVING,
340 ieee80211_link_info_change_notify(sdata, link, changed);
343 @@ -6862,9 +7052,12 @@ ieee80211_setup_assoc_link(struct ieee80
344 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
347 + link->conf->eht_puncturing = 0;
350 beacon_ies = rcu_dereference(cbss->beacon_ies);
352 + const struct ieee80211_eht_operation *eht_oper;
353 const struct element *elem;
356 @@ -6893,6 +7086,31 @@ ieee80211_setup_assoc_link(struct ieee80
357 link->conf->ema_ap = true;
359 link->conf->ema_ap = false;
361 + elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION,
362 + beacon_ies->data, beacon_ies->len);
363 + eht_oper = (const void *)(elem->data + 1);
366 + ieee80211_eht_oper_size_ok((const void *)(elem->data + 1),
367 + elem->datalen - 1) &&
368 + (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
369 + (eht_oper->params & IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
370 + const struct ieee80211_eht_operation_info *info =
371 + (void *)eht_oper->optional;
372 + const u8 *disable_subchannel_bitmap = info->optional;
375 + bitmap = get_unaligned_le16(disable_subchannel_bitmap);
376 + if (ieee80211_valid_disable_subchannel_bitmap(&bitmap,
377 + link->conf->chandef.width))
378 + ieee80211_handle_puncturing_bitmap(link,
383 + conn_flags |= IEEE80211_CONN_DISABLE_EHT;