1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * mac80211 configuration hooks for cfg80211
4 *
5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2015 Intel Mobile Communications GmbH
7 * Copyright (C) 2015-2017 Intel Deutschland GmbH
8 * Copyright (C) 2018-2025 Intel Corporation
9 */
10
11 #include <linux/ieee80211.h>
12 #include <linux/nl80211.h>
13 #include <linux/rtnetlink.h>
14 #include <linux/slab.h>
15 #include <net/net_namespace.h>
16 #include <linux/rcupdate.h>
17 #include <linux/fips.h>
18 #include <linux/if_ether.h>
19 #include <net/cfg80211.h>
20 #include "ieee80211_i.h"
21 #include "driver-ops.h"
22 #include "rate.h"
23 #include "mesh.h"
24 #include "wme.h"
25
26 static struct ieee80211_link_data *
ieee80211_link_or_deflink(struct ieee80211_sub_if_data * sdata,int link_id,bool require_valid)27 ieee80211_link_or_deflink(struct ieee80211_sub_if_data *sdata, int link_id,
28 bool require_valid)
29 {
30 struct ieee80211_link_data *link;
31
32 if (link_id < 0) {
33 /*
34 * For keys, if sdata is not an MLD, we might not use
35 * the return value at all (if it's not a pairwise key),
36 * so in that case (require_valid==false) don't error.
37 */
38 if (require_valid && ieee80211_vif_is_mld(&sdata->vif))
39 return ERR_PTR(-EINVAL);
40
41 return &sdata->deflink;
42 }
43
44 link = sdata_dereference(sdata->link[link_id], sdata);
45 if (!link)
46 return ERR_PTR(-ENOLINK);
47 return link;
48 }
49
ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data * sdata,struct vif_params * params)50 static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
51 struct vif_params *params)
52 {
53 bool mu_mimo_groups = false;
54 bool mu_mimo_follow = false;
55
56 if (params->vht_mumimo_groups) {
57 u64 membership;
58
59 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
60
61 memcpy(sdata->vif.bss_conf.mu_group.membership,
62 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
63 memcpy(sdata->vif.bss_conf.mu_group.position,
64 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
65 WLAN_USER_POSITION_LEN);
66
67 /* don't care about endianness - just check for 0 */
68 memcpy(&membership, params->vht_mumimo_groups,
69 WLAN_MEMBERSHIP_LEN);
70 mu_mimo_groups = membership != 0;
71
72 /* Unset following if configured explicitly */
73 eth_broadcast_addr(sdata->u.mntr.mu_follow_addr);
74 }
75
76 if (params->vht_mumimo_follow_addr) {
77 mu_mimo_follow =
78 is_valid_ether_addr(params->vht_mumimo_follow_addr);
79 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
80 params->vht_mumimo_follow_addr);
81
82 /* Unset current membership until a management frame is RXed */
83 memset(sdata->vif.bss_conf.mu_group.membership, 0,
84 WLAN_MEMBERSHIP_LEN);
85 }
86
87 sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
88
89 /* Notify only after setting mu_mimo_owner */
90 if (sdata->vif.bss_conf.mu_mimo_owner &&
91 sdata->flags & IEEE80211_SDATA_IN_DRIVER)
92 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
93 BSS_CHANGED_MU_GROUPS);
94 }
95
ieee80211_set_mon_options(struct ieee80211_sub_if_data * sdata,struct vif_params * params)96 static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
97 struct vif_params *params)
98 {
99 struct ieee80211_local *local = sdata->local;
100 struct ieee80211_sub_if_data *monitor_sdata = NULL;
101
102 /* check flags first */
103 if (params->flags && ieee80211_sdata_running(sdata)) {
104 u32 mask = MONITOR_FLAG_ACTIVE;
105
106 /*
107 * Prohibit MONITOR_FLAG_ACTIVE to be changed
108 * while the interface is up.
109 * Else we would need to add a lot of cruft
110 * to update everything:
111 * monitor and all fif_* counters
112 * reconfigure hardware
113 */
114 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
115 return -EBUSY;
116 }
117
118 /* validate whether MU-MIMO can be configured */
119 if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) &&
120 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR) &&
121 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
122 return -EOPNOTSUPP;
123
124 /* Also update dependent monitor_sdata if required */
125 if (test_bit(SDATA_STATE_RUNNING, &sdata->state) &&
126 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR))
127 monitor_sdata = wiphy_dereference(local->hw.wiphy,
128 local->monitor_sdata);
129
130 /* apply all changes now - no failures allowed */
131
132 if (ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) ||
133 ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) {
134 /* This is copied in when the VIF is activated */
135 ieee80211_set_mu_mimo_follow(sdata, params);
136
137 if (monitor_sdata)
138 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
139 }
140
141 if (params->flags) {
142 if (ieee80211_sdata_running(sdata)) {
143 ieee80211_adjust_monitor_flags(sdata, -1);
144 sdata->u.mntr.flags = params->flags;
145 ieee80211_adjust_monitor_flags(sdata, 1);
146
147 ieee80211_configure_filter(local);
148 } else {
149 /*
150 * Because the interface is down, ieee80211_do_stop
151 * and ieee80211_do_open take care of "everything"
152 * mentioned in the comment above.
153 */
154 sdata->u.mntr.flags = params->flags;
155 }
156 }
157
158 return 0;
159 }
160
ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data * sdata,struct cfg80211_mbssid_config * params,struct ieee80211_bss_conf * link_conf)161 static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
162 struct cfg80211_mbssid_config *params,
163 struct ieee80211_bss_conf *link_conf)
164 {
165 struct ieee80211_sub_if_data *tx_sdata;
166 struct ieee80211_bss_conf *old;
167
168 link_conf->bssid_index = 0;
169 link_conf->nontransmitted = false;
170 link_conf->ema_ap = false;
171 link_conf->bssid_indicator = 0;
172
173 if (sdata->vif.type != NL80211_IFTYPE_AP || !params->tx_wdev)
174 return -EINVAL;
175
176 old = sdata_dereference(link_conf->tx_bss_conf, sdata);
177 if (old)
178 return -EALREADY;
179
180 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params->tx_wdev);
181 if (!tx_sdata)
182 return -EINVAL;
183
184 if (tx_sdata == sdata) {
185 rcu_assign_pointer(link_conf->tx_bss_conf, link_conf);
186 } else {
187 struct ieee80211_bss_conf *tx_bss_conf;
188
189 tx_bss_conf = sdata_dereference(tx_sdata->vif.link_conf[params->tx_link_id],
190 sdata);
191 if (rcu_access_pointer(tx_bss_conf->tx_bss_conf) != tx_bss_conf)
192 return -EINVAL;
193
194 rcu_assign_pointer(link_conf->tx_bss_conf, tx_bss_conf);
195
196 link_conf->nontransmitted = true;
197 link_conf->bssid_index = params->index;
198 link_conf->bssid_indicator = tx_bss_conf->bssid_indicator;
199 }
200 if (params->ema)
201 link_conf->ema_ap = true;
202
203 return 0;
204 }
205
ieee80211_add_iface(struct wiphy * wiphy,const char * name,unsigned char name_assign_type,enum nl80211_iftype type,struct vif_params * params)206 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
207 const char *name,
208 unsigned char name_assign_type,
209 enum nl80211_iftype type,
210 struct vif_params *params)
211 {
212 struct ieee80211_local *local = wiphy_priv(wiphy);
213 struct wireless_dev *wdev;
214 struct ieee80211_sub_if_data *sdata;
215 int err;
216
217 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
218 if (err)
219 return ERR_PTR(err);
220
221 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
222
223 if (type == NL80211_IFTYPE_MONITOR) {
224 err = ieee80211_set_mon_options(sdata, params);
225 if (err) {
226 ieee80211_if_remove(sdata);
227 return NULL;
228 }
229 }
230
231 /* Let the driver know that an interface is going to be added.
232 * Indicate so only for interface types that will be added to the
233 * driver.
234 */
235 switch (type) {
236 case NL80211_IFTYPE_AP_VLAN:
237 break;
238 case NL80211_IFTYPE_MONITOR:
239 if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) ||
240 !(params->flags & MONITOR_FLAG_ACTIVE))
241 break;
242 fallthrough;
243 default:
244 drv_prep_add_interface(local,
245 ieee80211_vif_type_p2p(&sdata->vif));
246 break;
247 }
248
249 return wdev;
250 }
251
ieee80211_del_iface(struct wiphy * wiphy,struct wireless_dev * wdev)252 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
253 {
254 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
255
256 return 0;
257 }
258
ieee80211_change_iface(struct wiphy * wiphy,struct net_device * dev,enum nl80211_iftype type,struct vif_params * params)259 static int ieee80211_change_iface(struct wiphy *wiphy,
260 struct net_device *dev,
261 enum nl80211_iftype type,
262 struct vif_params *params)
263 {
264 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
265 struct ieee80211_local *local = sdata->local;
266 struct sta_info *sta;
267 int ret;
268
269 lockdep_assert_wiphy(local->hw.wiphy);
270
271 ret = ieee80211_if_change_type(sdata, type);
272 if (ret)
273 return ret;
274
275 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
276 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
277 ieee80211_check_fast_rx_iface(sdata);
278 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
279 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
280
281 if (params->use_4addr == ifmgd->use_4addr)
282 return 0;
283
284 /* FIXME: no support for 4-addr MLO yet */
285 if (ieee80211_vif_is_mld(&sdata->vif))
286 return -EOPNOTSUPP;
287
288 sdata->u.mgd.use_4addr = params->use_4addr;
289 if (!ifmgd->associated)
290 return 0;
291
292 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
293 if (sta)
294 drv_sta_set_4addr(local, sdata, &sta->sta,
295 params->use_4addr);
296
297 if (params->use_4addr)
298 ieee80211_send_4addr_nullfunc(local, sdata);
299 }
300
301 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
302 ret = ieee80211_set_mon_options(sdata, params);
303 if (ret)
304 return ret;
305 }
306
307 return 0;
308 }
309
ieee80211_start_p2p_device(struct wiphy * wiphy,struct wireless_dev * wdev)310 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
311 struct wireless_dev *wdev)
312 {
313 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
314 int ret;
315
316 lockdep_assert_wiphy(sdata->local->hw.wiphy);
317
318 ret = ieee80211_check_combinations(sdata, NULL, 0, 0, -1);
319 if (ret < 0)
320 return ret;
321
322 return ieee80211_do_open(wdev, true);
323 }
324
ieee80211_stop_p2p_device(struct wiphy * wiphy,struct wireless_dev * wdev)325 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
326 struct wireless_dev *wdev)
327 {
328 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
329 }
330
ieee80211_nan_conf_free(struct cfg80211_nan_conf * conf)331 static void ieee80211_nan_conf_free(struct cfg80211_nan_conf *conf)
332 {
333 kfree(conf->cluster_id);
334 kfree(conf->extra_nan_attrs);
335 kfree(conf->vendor_elems);
336 memset(conf, 0, sizeof(*conf));
337 }
338
ieee80211_stop_nan(struct wiphy * wiphy,struct wireless_dev * wdev)339 static void ieee80211_stop_nan(struct wiphy *wiphy,
340 struct wireless_dev *wdev)
341 {
342 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
343
344 if (!sdata->u.nan.started)
345 return;
346
347 drv_stop_nan(sdata->local, sdata);
348 sdata->u.nan.started = false;
349
350 ieee80211_nan_conf_free(&sdata->u.nan.conf);
351
352 ieee80211_sdata_stop(sdata);
353 ieee80211_recalc_idle(sdata->local);
354 }
355
ieee80211_nan_conf_copy(struct cfg80211_nan_conf * dst,struct cfg80211_nan_conf * src,u32 changes)356 static int ieee80211_nan_conf_copy(struct cfg80211_nan_conf *dst,
357 struct cfg80211_nan_conf *src,
358 u32 changes)
359 {
360 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
361 dst->master_pref = src->master_pref;
362
363 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
364 dst->bands = src->bands;
365
366 if (changes & CFG80211_NAN_CONF_CHANGED_CONFIG) {
367 dst->scan_period = src->scan_period;
368 dst->scan_dwell_time = src->scan_dwell_time;
369 dst->discovery_beacon_interval =
370 src->discovery_beacon_interval;
371 dst->enable_dw_notification = src->enable_dw_notification;
372 memcpy(&dst->band_cfgs, &src->band_cfgs,
373 sizeof(dst->band_cfgs));
374
375 kfree(dst->cluster_id);
376 dst->cluster_id = NULL;
377
378 kfree(dst->extra_nan_attrs);
379 dst->extra_nan_attrs = NULL;
380 dst->extra_nan_attrs_len = 0;
381
382 kfree(dst->vendor_elems);
383 dst->vendor_elems = NULL;
384 dst->vendor_elems_len = 0;
385
386 if (src->cluster_id) {
387 dst->cluster_id = kmemdup(src->cluster_id, ETH_ALEN,
388 GFP_KERNEL);
389 if (!dst->cluster_id)
390 goto no_mem;
391 }
392
393 if (src->extra_nan_attrs && src->extra_nan_attrs_len) {
394 dst->extra_nan_attrs = kmemdup(src->extra_nan_attrs,
395 src->extra_nan_attrs_len,
396 GFP_KERNEL);
397 if (!dst->extra_nan_attrs)
398 goto no_mem;
399
400 dst->extra_nan_attrs_len = src->extra_nan_attrs_len;
401 }
402
403 if (src->vendor_elems && src->vendor_elems_len) {
404 dst->vendor_elems = kmemdup(src->vendor_elems,
405 src->vendor_elems_len,
406 GFP_KERNEL);
407 if (!dst->vendor_elems)
408 goto no_mem;
409
410 dst->vendor_elems_len = src->vendor_elems_len;
411 }
412 }
413
414 return 0;
415
416 no_mem:
417 ieee80211_nan_conf_free(dst);
418 return -ENOMEM;
419 }
420
ieee80211_start_nan(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_nan_conf * conf)421 static int ieee80211_start_nan(struct wiphy *wiphy,
422 struct wireless_dev *wdev,
423 struct cfg80211_nan_conf *conf)
424 {
425 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
426 int ret;
427
428 lockdep_assert_wiphy(sdata->local->hw.wiphy);
429
430 if (sdata->u.nan.started)
431 return -EALREADY;
432
433 ret = ieee80211_check_combinations(sdata, NULL, 0, 0, -1);
434 if (ret < 0)
435 return ret;
436
437 ret = ieee80211_do_open(wdev, true);
438 if (ret)
439 return ret;
440
441 ret = drv_start_nan(sdata->local, sdata, conf);
442 if (ret) {
443 ieee80211_sdata_stop(sdata);
444 return ret;
445 }
446
447 sdata->u.nan.started = true;
448 ieee80211_recalc_idle(sdata->local);
449
450 ret = ieee80211_nan_conf_copy(&sdata->u.nan.conf, conf, 0xFFFFFFFF);
451 if (ret) {
452 ieee80211_stop_nan(wiphy, wdev);
453 return ret;
454 }
455
456 return 0;
457 }
458
ieee80211_nan_change_conf(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_nan_conf * conf,u32 changes)459 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
460 struct wireless_dev *wdev,
461 struct cfg80211_nan_conf *conf,
462 u32 changes)
463 {
464 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
465 struct cfg80211_nan_conf new_conf = {};
466 int ret = 0;
467
468 if (sdata->vif.type != NL80211_IFTYPE_NAN)
469 return -EOPNOTSUPP;
470
471 if (!ieee80211_sdata_running(sdata))
472 return -ENETDOWN;
473
474 if (!changes)
475 return 0;
476
477 /* First make a full copy of the previous configuration and then apply
478 * the changes. This might be a little wasteful, but it is simpler.
479 */
480 ret = ieee80211_nan_conf_copy(&new_conf, &sdata->u.nan.conf,
481 0xFFFFFFFF);
482 if (ret < 0)
483 return ret;
484
485 ret = ieee80211_nan_conf_copy(&new_conf, conf, changes);
486 if (ret < 0)
487 return ret;
488
489 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
490 if (ret) {
491 ieee80211_nan_conf_free(&new_conf);
492 } else {
493 ieee80211_nan_conf_free(&sdata->u.nan.conf);
494 sdata->u.nan.conf = new_conf;
495 }
496
497 return ret;
498 }
499
ieee80211_add_nan_func(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_nan_func * nan_func)500 static int ieee80211_add_nan_func(struct wiphy *wiphy,
501 struct wireless_dev *wdev,
502 struct cfg80211_nan_func *nan_func)
503 {
504 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
505 int ret;
506
507 if (sdata->vif.type != NL80211_IFTYPE_NAN)
508 return -EOPNOTSUPP;
509
510 if (!ieee80211_sdata_running(sdata))
511 return -ENETDOWN;
512
513 spin_lock_bh(&sdata->u.nan.func_lock);
514
515 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
516 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
517 GFP_ATOMIC);
518 spin_unlock_bh(&sdata->u.nan.func_lock);
519
520 if (ret < 0)
521 return ret;
522
523 nan_func->instance_id = ret;
524
525 WARN_ON(nan_func->instance_id == 0);
526
527 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
528 if (ret) {
529 spin_lock_bh(&sdata->u.nan.func_lock);
530 idr_remove(&sdata->u.nan.function_inst_ids,
531 nan_func->instance_id);
532 spin_unlock_bh(&sdata->u.nan.func_lock);
533 }
534
535 return ret;
536 }
537
538 static struct cfg80211_nan_func *
ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data * sdata,u64 cookie)539 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
540 u64 cookie)
541 {
542 struct cfg80211_nan_func *func;
543 int id;
544
545 lockdep_assert_held(&sdata->u.nan.func_lock);
546
547 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
548 if (func->cookie == cookie)
549 return func;
550 }
551
552 return NULL;
553 }
554
ieee80211_del_nan_func(struct wiphy * wiphy,struct wireless_dev * wdev,u64 cookie)555 static void ieee80211_del_nan_func(struct wiphy *wiphy,
556 struct wireless_dev *wdev, u64 cookie)
557 {
558 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
559 struct cfg80211_nan_func *func;
560 u8 instance_id = 0;
561
562 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
563 !ieee80211_sdata_running(sdata))
564 return;
565
566 spin_lock_bh(&sdata->u.nan.func_lock);
567
568 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
569 if (func)
570 instance_id = func->instance_id;
571
572 spin_unlock_bh(&sdata->u.nan.func_lock);
573
574 if (instance_id)
575 drv_del_nan_func(sdata->local, sdata, instance_id);
576 }
577
ieee80211_set_noack_map(struct wiphy * wiphy,struct net_device * dev,u16 noack_map)578 static int ieee80211_set_noack_map(struct wiphy *wiphy,
579 struct net_device *dev,
580 u16 noack_map)
581 {
582 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
583
584 sdata->noack_map = noack_map;
585
586 ieee80211_check_fast_xmit_iface(sdata);
587
588 return 0;
589 }
590
ieee80211_set_tx(struct ieee80211_sub_if_data * sdata,const u8 * mac_addr,u8 key_idx)591 static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
592 const u8 *mac_addr, u8 key_idx)
593 {
594 struct ieee80211_local *local = sdata->local;
595 struct ieee80211_key *key;
596 struct sta_info *sta;
597 int ret = -EINVAL;
598
599 if (!wiphy_ext_feature_isset(local->hw.wiphy,
600 NL80211_EXT_FEATURE_EXT_KEY_ID))
601 return -EINVAL;
602
603 sta = sta_info_get_bss(sdata, mac_addr);
604
605 if (!sta)
606 return -EINVAL;
607
608 if (sta->ptk_idx == key_idx)
609 return 0;
610
611 key = wiphy_dereference(local->hw.wiphy, sta->ptk[key_idx]);
612
613 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
614 ret = ieee80211_set_tx_key(key);
615
616 return ret;
617 }
618
ieee80211_add_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_idx,bool pairwise,const u8 * mac_addr,struct key_params * params)619 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
620 int link_id, u8 key_idx, bool pairwise,
621 const u8 *mac_addr, struct key_params *params)
622 {
623 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
624 struct ieee80211_link_data *link =
625 ieee80211_link_or_deflink(sdata, link_id, false);
626 struct ieee80211_local *local = sdata->local;
627 struct sta_info *sta = NULL;
628 struct ieee80211_key *key;
629 int err;
630
631 lockdep_assert_wiphy(local->hw.wiphy);
632
633 if (!ieee80211_sdata_running(sdata))
634 return -ENETDOWN;
635
636 if (IS_ERR(link))
637 return PTR_ERR(link);
638
639 if (WARN_ON(pairwise && link_id >= 0))
640 return -EINVAL;
641
642 if (pairwise && params->mode == NL80211_KEY_SET_TX)
643 return ieee80211_set_tx(sdata, mac_addr, key_idx);
644
645 /* reject WEP and TKIP keys if WEP failed to initialize */
646 switch (params->cipher) {
647 case WLAN_CIPHER_SUITE_WEP40:
648 case WLAN_CIPHER_SUITE_TKIP:
649 case WLAN_CIPHER_SUITE_WEP104:
650 if (link_id >= 0)
651 return -EINVAL;
652 if (WARN_ON_ONCE(fips_enabled))
653 return -EINVAL;
654 break;
655 default:
656 break;
657 }
658
659 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
660 params->key, params->seq_len, params->seq);
661 if (IS_ERR(key))
662 return PTR_ERR(key);
663
664 if (pairwise) {
665 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
666 key->conf.link_id = -1;
667 } else {
668 key->conf.link_id = link->link_id;
669 }
670
671 if (params->mode == NL80211_KEY_NO_TX)
672 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
673
674 if (mac_addr) {
675 sta = sta_info_get_bss(sdata, mac_addr);
676 /*
677 * The ASSOC test makes sure the driver is ready to
678 * receive the key. When wpa_supplicant has roamed
679 * using FT, it attempts to set the key before
680 * association has completed, this rejects that attempt
681 * so it will set the key again after association.
682 *
683 * TODO: accept the key if we have a station entry and
684 * add it to the device after the station.
685 */
686 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
687 ieee80211_key_free_unused(key);
688 return -ENOENT;
689 }
690 }
691
692 switch (sdata->vif.type) {
693 case NL80211_IFTYPE_STATION:
694 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
695 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
696 break;
697 case NL80211_IFTYPE_AP:
698 case NL80211_IFTYPE_AP_VLAN:
699 /* Keys without a station are used for TX only */
700 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
701 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
702 break;
703 case NL80211_IFTYPE_ADHOC:
704 /* no MFP (yet) */
705 break;
706 case NL80211_IFTYPE_MESH_POINT:
707 #ifdef CONFIG_MAC80211_MESH
708 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
709 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
710 break;
711 #endif
712 case NL80211_IFTYPE_WDS:
713 case NL80211_IFTYPE_MONITOR:
714 case NL80211_IFTYPE_P2P_DEVICE:
715 case NL80211_IFTYPE_NAN:
716 case NL80211_IFTYPE_UNSPECIFIED:
717 case NUM_NL80211_IFTYPES:
718 case NL80211_IFTYPE_P2P_CLIENT:
719 case NL80211_IFTYPE_P2P_GO:
720 case NL80211_IFTYPE_OCB:
721 /* shouldn't happen */
722 WARN_ON_ONCE(1);
723 break;
724 }
725
726 err = ieee80211_key_link(key, link, sta);
727 /* KRACK protection, shouldn't happen but just silently accept key */
728 if (err == -EALREADY)
729 err = 0;
730
731 return err;
732 }
733
734 static struct ieee80211_key *
ieee80211_lookup_key(struct ieee80211_sub_if_data * sdata,int link_id,u8 key_idx,bool pairwise,const u8 * mac_addr)735 ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id,
736 u8 key_idx, bool pairwise, const u8 *mac_addr)
737 {
738 struct ieee80211_local *local __maybe_unused = sdata->local;
739 struct ieee80211_link_data *link = &sdata->deflink;
740 struct ieee80211_key *key;
741
742 if (link_id >= 0) {
743 link = sdata_dereference(sdata->link[link_id], sdata);
744 if (!link)
745 return NULL;
746 }
747
748 if (mac_addr) {
749 struct sta_info *sta;
750 struct link_sta_info *link_sta;
751
752 sta = sta_info_get_bss(sdata, mac_addr);
753 if (!sta)
754 return NULL;
755
756 if (link_id >= 0) {
757 link_sta = rcu_dereference_check(sta->link[link_id],
758 lockdep_is_held(&local->hw.wiphy->mtx));
759 if (!link_sta)
760 return NULL;
761 } else {
762 link_sta = &sta->deflink;
763 }
764
765 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
766 return wiphy_dereference(local->hw.wiphy,
767 sta->ptk[key_idx]);
768
769 if (!pairwise &&
770 key_idx < NUM_DEFAULT_KEYS +
771 NUM_DEFAULT_MGMT_KEYS +
772 NUM_DEFAULT_BEACON_KEYS)
773 return wiphy_dereference(local->hw.wiphy,
774 link_sta->gtk[key_idx]);
775
776 return NULL;
777 }
778
779 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
780 return wiphy_dereference(local->hw.wiphy, sdata->keys[key_idx]);
781
782 key = wiphy_dereference(local->hw.wiphy, link->gtk[key_idx]);
783 if (key)
784 return key;
785
786 /* or maybe it was a WEP key */
787 if (key_idx < NUM_DEFAULT_KEYS)
788 return wiphy_dereference(local->hw.wiphy, sdata->keys[key_idx]);
789
790 return NULL;
791 }
792
ieee80211_del_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_idx,bool pairwise,const u8 * mac_addr)793 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
794 int link_id, u8 key_idx, bool pairwise,
795 const u8 *mac_addr)
796 {
797 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
798 struct ieee80211_local *local = sdata->local;
799 struct ieee80211_key *key;
800
801 lockdep_assert_wiphy(local->hw.wiphy);
802
803 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
804 if (!key)
805 return -ENOENT;
806
807 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
808
809 return 0;
810 }
811
ieee80211_get_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_idx,bool pairwise,const u8 * mac_addr,void * cookie,void (* callback)(void * cookie,struct key_params * params))812 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
813 int link_id, u8 key_idx, bool pairwise,
814 const u8 *mac_addr, void *cookie,
815 void (*callback)(void *cookie,
816 struct key_params *params))
817 {
818 struct ieee80211_sub_if_data *sdata;
819 u8 seq[6] = {0};
820 struct key_params params;
821 struct ieee80211_key *key;
822 u64 pn64;
823 u32 iv32;
824 u16 iv16;
825 int err = -ENOENT;
826 struct ieee80211_key_seq kseq = {};
827
828 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
829
830 rcu_read_lock();
831
832 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
833 if (!key)
834 goto out;
835
836 memset(¶ms, 0, sizeof(params));
837
838 params.cipher = key->conf.cipher;
839
840 switch (key->conf.cipher) {
841 case WLAN_CIPHER_SUITE_TKIP:
842 pn64 = atomic64_read(&key->conf.tx_pn);
843 iv32 = TKIP_PN_TO_IV32(pn64);
844 iv16 = TKIP_PN_TO_IV16(pn64);
845
846 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
847 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
848 drv_get_key_seq(sdata->local, key, &kseq);
849 iv32 = kseq.tkip.iv32;
850 iv16 = kseq.tkip.iv16;
851 }
852
853 seq[0] = iv16 & 0xff;
854 seq[1] = (iv16 >> 8) & 0xff;
855 seq[2] = iv32 & 0xff;
856 seq[3] = (iv32 >> 8) & 0xff;
857 seq[4] = (iv32 >> 16) & 0xff;
858 seq[5] = (iv32 >> 24) & 0xff;
859 params.seq = seq;
860 params.seq_len = 6;
861 break;
862 case WLAN_CIPHER_SUITE_CCMP:
863 case WLAN_CIPHER_SUITE_CCMP_256:
864 case WLAN_CIPHER_SUITE_AES_CMAC:
865 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
866 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
867 offsetof(typeof(kseq), aes_cmac));
868 fallthrough;
869 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
870 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
871 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
872 offsetof(typeof(kseq), aes_gmac));
873 fallthrough;
874 case WLAN_CIPHER_SUITE_GCMP:
875 case WLAN_CIPHER_SUITE_GCMP_256:
876 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
877 offsetof(typeof(kseq), gcmp));
878
879 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
880 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
881 drv_get_key_seq(sdata->local, key, &kseq);
882 memcpy(seq, kseq.ccmp.pn, 6);
883 } else {
884 pn64 = atomic64_read(&key->conf.tx_pn);
885 seq[0] = pn64;
886 seq[1] = pn64 >> 8;
887 seq[2] = pn64 >> 16;
888 seq[3] = pn64 >> 24;
889 seq[4] = pn64 >> 32;
890 seq[5] = pn64 >> 40;
891 }
892 params.seq = seq;
893 params.seq_len = 6;
894 break;
895 default:
896 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
897 break;
898 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
899 break;
900 drv_get_key_seq(sdata->local, key, &kseq);
901 params.seq = kseq.hw.seq;
902 params.seq_len = kseq.hw.seq_len;
903 break;
904 }
905
906 callback(cookie, ¶ms);
907 err = 0;
908
909 out:
910 rcu_read_unlock();
911 return err;
912 }
913
ieee80211_config_default_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_idx,bool uni,bool multi)914 static int ieee80211_config_default_key(struct wiphy *wiphy,
915 struct net_device *dev,
916 int link_id, u8 key_idx, bool uni,
917 bool multi)
918 {
919 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
920 struct ieee80211_link_data *link =
921 ieee80211_link_or_deflink(sdata, link_id, false);
922
923 if (IS_ERR(link))
924 return PTR_ERR(link);
925
926 ieee80211_set_default_key(link, key_idx, uni, multi);
927
928 return 0;
929 }
930
ieee80211_config_default_mgmt_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_idx)931 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
932 struct net_device *dev,
933 int link_id, u8 key_idx)
934 {
935 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
936 struct ieee80211_link_data *link =
937 ieee80211_link_or_deflink(sdata, link_id, true);
938
939 if (IS_ERR(link))
940 return PTR_ERR(link);
941
942 ieee80211_set_default_mgmt_key(link, key_idx);
943
944 return 0;
945 }
946
ieee80211_config_default_beacon_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_idx)947 static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
948 struct net_device *dev,
949 int link_id, u8 key_idx)
950 {
951 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
952 struct ieee80211_link_data *link =
953 ieee80211_link_or_deflink(sdata, link_id, true);
954
955 if (IS_ERR(link))
956 return PTR_ERR(link);
957
958 ieee80211_set_default_beacon_key(link, key_idx);
959
960 return 0;
961 }
962
sta_set_rate_info_tx(struct sta_info * sta,const struct ieee80211_tx_rate * rate,struct rate_info * rinfo)963 void sta_set_rate_info_tx(struct sta_info *sta,
964 const struct ieee80211_tx_rate *rate,
965 struct rate_info *rinfo)
966 {
967 rinfo->flags = 0;
968 if (rate->flags & IEEE80211_TX_RC_MCS) {
969 rinfo->flags |= RATE_INFO_FLAGS_MCS;
970 rinfo->mcs = rate->idx;
971 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
972 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
973 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
974 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
975 } else {
976 struct ieee80211_supported_band *sband;
977
978 sband = ieee80211_get_sband(sta->sdata);
979 WARN_ON_ONCE(sband && !sband->bitrates);
980 if (sband && sband->bitrates)
981 rinfo->legacy = sband->bitrates[rate->idx].bitrate;
982 }
983 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
984 rinfo->bw = RATE_INFO_BW_40;
985 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
986 rinfo->bw = RATE_INFO_BW_80;
987 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
988 rinfo->bw = RATE_INFO_BW_160;
989 else
990 rinfo->bw = RATE_INFO_BW_20;
991 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
992 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
993 }
994
ieee80211_dump_station(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * mac,struct station_info * sinfo)995 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
996 int idx, u8 *mac, struct station_info *sinfo)
997 {
998 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
999 struct ieee80211_local *local = sdata->local;
1000 struct sta_info *sta;
1001 int ret = -ENOENT;
1002
1003 lockdep_assert_wiphy(local->hw.wiphy);
1004
1005 sta = sta_info_get_by_idx(sdata, idx);
1006 if (sta) {
1007 ret = 0;
1008 memcpy(mac, sta->sta.addr, ETH_ALEN);
1009 sta_set_sinfo(sta, sinfo, true);
1010
1011 /* Add accumulated removed link data to sinfo data for
1012 * consistency for MLO
1013 */
1014 if (sinfo->valid_links)
1015 sta_set_accumulated_removed_links_sinfo(sta, sinfo);
1016
1017 }
1018
1019 return ret;
1020 }
1021
ieee80211_dump_survey(struct wiphy * wiphy,struct net_device * dev,int idx,struct survey_info * survey)1022 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
1023 int idx, struct survey_info *survey)
1024 {
1025 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1026
1027 return drv_get_survey(local, idx, survey);
1028 }
1029
ieee80211_get_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_info * sinfo)1030 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1031 const u8 *mac, struct station_info *sinfo)
1032 {
1033 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1034 struct ieee80211_local *local = sdata->local;
1035 struct sta_info *sta;
1036 int ret = -ENOENT;
1037
1038 lockdep_assert_wiphy(local->hw.wiphy);
1039
1040 sta = sta_info_get_bss(sdata, mac);
1041 if (sta) {
1042 ret = 0;
1043 sta_set_sinfo(sta, sinfo, true);
1044
1045 /* Add accumulated removed link data to sinfo data for
1046 * consistency for MLO
1047 */
1048 if (sinfo->valid_links)
1049 sta_set_accumulated_removed_links_sinfo(sta, sinfo);
1050 }
1051
1052 return ret;
1053 }
1054
ieee80211_set_monitor_channel(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_chan_def * chandef)1055 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
1056 struct net_device *dev,
1057 struct cfg80211_chan_def *chandef)
1058 {
1059 struct ieee80211_local *local = wiphy_priv(wiphy);
1060 struct ieee80211_sub_if_data *sdata;
1061 struct ieee80211_chan_req chanreq = { .oper = *chandef };
1062 int ret;
1063
1064 lockdep_assert_wiphy(local->hw.wiphy);
1065
1066 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1067 if (!ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) {
1068 if (cfg80211_chandef_identical(&local->monitor_chanreq.oper,
1069 &chanreq.oper))
1070 return 0;
1071
1072 sdata = wiphy_dereference(wiphy, local->monitor_sdata);
1073 if (!sdata)
1074 goto done;
1075 }
1076
1077 if (rcu_access_pointer(sdata->deflink.conf->chanctx_conf) &&
1078 cfg80211_chandef_identical(&sdata->vif.bss_conf.chanreq.oper,
1079 &chanreq.oper))
1080 return 0;
1081
1082 ieee80211_link_release_channel(&sdata->deflink);
1083 ret = ieee80211_link_use_channel(&sdata->deflink, &chanreq,
1084 IEEE80211_CHANCTX_SHARED);
1085 if (ret)
1086 return ret;
1087 done:
1088 local->monitor_chanreq = chanreq;
1089 return 0;
1090 }
1091
1092 static int
ieee80211_set_probe_resp(struct ieee80211_sub_if_data * sdata,const u8 * resp,size_t resp_len,const struct ieee80211_csa_settings * csa,const struct ieee80211_color_change_settings * cca,struct ieee80211_link_data * link)1093 ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
1094 const u8 *resp, size_t resp_len,
1095 const struct ieee80211_csa_settings *csa,
1096 const struct ieee80211_color_change_settings *cca,
1097 struct ieee80211_link_data *link)
1098 {
1099 struct probe_resp *new, *old;
1100
1101 if (!resp || !resp_len)
1102 return 1;
1103
1104 old = sdata_dereference(link->u.ap.probe_resp, sdata);
1105
1106 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
1107 if (!new)
1108 return -ENOMEM;
1109
1110 new->len = resp_len;
1111 memcpy(new->data, resp, resp_len);
1112
1113 if (csa)
1114 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
1115 csa->n_counter_offsets_presp *
1116 sizeof(new->cntdwn_counter_offsets[0]));
1117 else if (cca)
1118 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
1119
1120 rcu_assign_pointer(link->u.ap.probe_resp, new);
1121 if (old)
1122 kfree_rcu(old, rcu_head);
1123
1124 return 0;
1125 }
1126
ieee80211_set_fils_discovery(struct ieee80211_sub_if_data * sdata,struct cfg80211_fils_discovery * params,struct ieee80211_link_data * link,struct ieee80211_bss_conf * link_conf,u64 * changed)1127 static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
1128 struct cfg80211_fils_discovery *params,
1129 struct ieee80211_link_data *link,
1130 struct ieee80211_bss_conf *link_conf,
1131 u64 *changed)
1132 {
1133 struct fils_discovery_data *new, *old = NULL;
1134 struct ieee80211_fils_discovery *fd;
1135
1136 if (!params->update)
1137 return 0;
1138
1139 fd = &link_conf->fils_discovery;
1140 fd->min_interval = params->min_interval;
1141 fd->max_interval = params->max_interval;
1142
1143 old = sdata_dereference(link->u.ap.fils_discovery, sdata);
1144 if (old)
1145 kfree_rcu(old, rcu_head);
1146
1147 if (params->tmpl && params->tmpl_len) {
1148 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
1149 if (!new)
1150 return -ENOMEM;
1151 new->len = params->tmpl_len;
1152 memcpy(new->data, params->tmpl, params->tmpl_len);
1153 rcu_assign_pointer(link->u.ap.fils_discovery, new);
1154 } else {
1155 RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
1156 }
1157
1158 *changed |= BSS_CHANGED_FILS_DISCOVERY;
1159 return 0;
1160 }
1161
1162 static int
ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data * sdata,struct cfg80211_unsol_bcast_probe_resp * params,struct ieee80211_link_data * link,struct ieee80211_bss_conf * link_conf,u64 * changed)1163 ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
1164 struct cfg80211_unsol_bcast_probe_resp *params,
1165 struct ieee80211_link_data *link,
1166 struct ieee80211_bss_conf *link_conf,
1167 u64 *changed)
1168 {
1169 struct unsol_bcast_probe_resp_data *new, *old = NULL;
1170
1171 if (!params->update)
1172 return 0;
1173
1174 link_conf->unsol_bcast_probe_resp_interval = params->interval;
1175
1176 old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata);
1177 if (old)
1178 kfree_rcu(old, rcu_head);
1179
1180 if (params->tmpl && params->tmpl_len) {
1181 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
1182 if (!new)
1183 return -ENOMEM;
1184 new->len = params->tmpl_len;
1185 memcpy(new->data, params->tmpl, params->tmpl_len);
1186 rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new);
1187 } else {
1188 RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
1189 }
1190
1191 *changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1192 return 0;
1193 }
1194
1195 static int
ieee80211_set_s1g_short_beacon(struct ieee80211_sub_if_data * sdata,struct ieee80211_link_data * link,struct cfg80211_s1g_short_beacon * params)1196 ieee80211_set_s1g_short_beacon(struct ieee80211_sub_if_data *sdata,
1197 struct ieee80211_link_data *link,
1198 struct cfg80211_s1g_short_beacon *params)
1199 {
1200 struct s1g_short_beacon_data *new;
1201 struct s1g_short_beacon_data *old =
1202 sdata_dereference(link->u.ap.s1g_short_beacon, sdata);
1203 size_t new_len =
1204 sizeof(*new) + params->short_head_len + params->short_tail_len;
1205
1206 if (!params->update)
1207 return 0;
1208
1209 if (!params->short_head)
1210 return -EINVAL;
1211
1212 new = kzalloc(new_len, GFP_KERNEL);
1213 if (!new)
1214 return -ENOMEM;
1215
1216 /* Memory layout: | struct | head | tail | */
1217 new->short_head = (u8 *)new + sizeof(*new);
1218 new->short_head_len = params->short_head_len;
1219 memcpy(new->short_head, params->short_head, params->short_head_len);
1220
1221 if (params->short_tail) {
1222 new->short_tail = new->short_head + params->short_head_len;
1223 new->short_tail_len = params->short_tail_len;
1224 memcpy(new->short_tail, params->short_tail,
1225 params->short_tail_len);
1226 }
1227
1228 rcu_assign_pointer(link->u.ap.s1g_short_beacon, new);
1229
1230 if (old)
1231 kfree_rcu(old, rcu_head);
1232
1233 return 0;
1234 }
1235
ieee80211_set_ftm_responder_params(struct ieee80211_sub_if_data * sdata,const u8 * lci,size_t lci_len,const u8 * civicloc,size_t civicloc_len,struct ieee80211_bss_conf * link_conf)1236 static int ieee80211_set_ftm_responder_params(
1237 struct ieee80211_sub_if_data *sdata,
1238 const u8 *lci, size_t lci_len,
1239 const u8 *civicloc, size_t civicloc_len,
1240 struct ieee80211_bss_conf *link_conf)
1241 {
1242 struct ieee80211_ftm_responder_params *new, *old;
1243 u8 *pos;
1244 int len;
1245
1246 if (!lci_len && !civicloc_len)
1247 return 0;
1248
1249 old = link_conf->ftmr_params;
1250 len = lci_len + civicloc_len;
1251
1252 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
1253 if (!new)
1254 return -ENOMEM;
1255
1256 pos = (u8 *)(new + 1);
1257 if (lci_len) {
1258 new->lci_len = lci_len;
1259 new->lci = pos;
1260 memcpy(pos, lci, lci_len);
1261 pos += lci_len;
1262 }
1263
1264 if (civicloc_len) {
1265 new->civicloc_len = civicloc_len;
1266 new->civicloc = pos;
1267 memcpy(pos, civicloc, civicloc_len);
1268 pos += civicloc_len;
1269 }
1270
1271 link_conf->ftmr_params = new;
1272 kfree(old);
1273
1274 return 0;
1275 }
1276
1277 static int
ieee80211_copy_mbssid_beacon(u8 * pos,struct cfg80211_mbssid_elems * dst,struct cfg80211_mbssid_elems * src)1278 ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
1279 struct cfg80211_mbssid_elems *src)
1280 {
1281 int i, offset = 0;
1282
1283 dst->cnt = src->cnt;
1284 for (i = 0; i < src->cnt; i++) {
1285 memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
1286 dst->elem[i].len = src->elem[i].len;
1287 dst->elem[i].data = pos + offset;
1288 offset += dst->elem[i].len;
1289 }
1290
1291 return offset;
1292 }
1293
1294 static int
ieee80211_copy_rnr_beacon(u8 * pos,struct cfg80211_rnr_elems * dst,struct cfg80211_rnr_elems * src)1295 ieee80211_copy_rnr_beacon(u8 *pos, struct cfg80211_rnr_elems *dst,
1296 struct cfg80211_rnr_elems *src)
1297 {
1298 int i, offset = 0;
1299
1300 dst->cnt = src->cnt;
1301 for (i = 0; i < src->cnt; i++) {
1302 memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
1303 dst->elem[i].len = src->elem[i].len;
1304 dst->elem[i].data = pos + offset;
1305 offset += dst->elem[i].len;
1306 }
1307
1308 return offset;
1309 }
1310
1311 static int
ieee80211_assign_beacon(struct ieee80211_sub_if_data * sdata,struct ieee80211_link_data * link,struct cfg80211_beacon_data * params,const struct ieee80211_csa_settings * csa,const struct ieee80211_color_change_settings * cca,u64 * changed)1312 ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
1313 struct ieee80211_link_data *link,
1314 struct cfg80211_beacon_data *params,
1315 const struct ieee80211_csa_settings *csa,
1316 const struct ieee80211_color_change_settings *cca,
1317 u64 *changed)
1318 {
1319 struct cfg80211_mbssid_elems *mbssid = NULL;
1320 struct cfg80211_rnr_elems *rnr = NULL;
1321 struct beacon_data *new, *old;
1322 int new_head_len, new_tail_len;
1323 int size, err;
1324 u64 _changed = BSS_CHANGED_BEACON;
1325 struct ieee80211_bss_conf *link_conf = link->conf;
1326
1327 old = sdata_dereference(link->u.ap.beacon, sdata);
1328
1329 /* Need to have a beacon head if we don't have one yet */
1330 if (!params->head && !old)
1331 return -EINVAL;
1332
1333 /* new or old head? */
1334 if (params->head)
1335 new_head_len = params->head_len;
1336 else
1337 new_head_len = old->head_len;
1338
1339 /* new or old tail? */
1340 if (params->tail || !old)
1341 /* params->tail_len will be zero for !params->tail */
1342 new_tail_len = params->tail_len;
1343 else
1344 new_tail_len = old->tail_len;
1345
1346 size = sizeof(*new) + new_head_len + new_tail_len;
1347
1348 /* new or old multiple BSSID elements? */
1349 if (params->mbssid_ies) {
1350 mbssid = params->mbssid_ies;
1351 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1352 if (params->rnr_ies) {
1353 rnr = params->rnr_ies;
1354 size += struct_size(new->rnr_ies, elem, rnr->cnt);
1355 }
1356 size += ieee80211_get_mbssid_beacon_len(mbssid, rnr,
1357 mbssid->cnt);
1358 } else if (old && old->mbssid_ies) {
1359 mbssid = old->mbssid_ies;
1360 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1361 if (old && old->rnr_ies) {
1362 rnr = old->rnr_ies;
1363 size += struct_size(new->rnr_ies, elem, rnr->cnt);
1364 }
1365 size += ieee80211_get_mbssid_beacon_len(mbssid, rnr,
1366 mbssid->cnt);
1367 }
1368
1369 new = kzalloc(size, GFP_KERNEL);
1370 if (!new)
1371 return -ENOMEM;
1372
1373 /* start filling the new info now */
1374
1375 /*
1376 * pointers go into the block we allocated,
1377 * memory is | beacon_data | head | tail | mbssid_ies | rnr_ies
1378 */
1379 new->head = ((u8 *) new) + sizeof(*new);
1380 new->tail = new->head + new_head_len;
1381 new->head_len = new_head_len;
1382 new->tail_len = new_tail_len;
1383 /* copy in optional mbssid_ies */
1384 if (mbssid) {
1385 u8 *pos = new->tail + new->tail_len;
1386
1387 new->mbssid_ies = (void *)pos;
1388 pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1389 pos += ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies,
1390 mbssid);
1391 if (rnr) {
1392 new->rnr_ies = (void *)pos;
1393 pos += struct_size(new->rnr_ies, elem, rnr->cnt);
1394 ieee80211_copy_rnr_beacon(pos, new->rnr_ies, rnr);
1395 }
1396 /* update bssid_indicator */
1397 if (new->mbssid_ies->cnt && new->mbssid_ies->elem[0].len > 2)
1398 link_conf->bssid_indicator =
1399 *(new->mbssid_ies->elem[0].data + 2);
1400 else
1401 link_conf->bssid_indicator = 0;
1402 }
1403
1404 if (csa) {
1405 new->cntdwn_current_counter = csa->count;
1406 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
1407 csa->n_counter_offsets_beacon *
1408 sizeof(new->cntdwn_counter_offsets[0]));
1409 } else if (cca) {
1410 new->cntdwn_current_counter = cca->count;
1411 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
1412 }
1413
1414 /* copy in head */
1415 if (params->head)
1416 memcpy(new->head, params->head, new_head_len);
1417 else
1418 memcpy(new->head, old->head, new_head_len);
1419
1420 /* copy in optional tail */
1421 if (params->tail)
1422 memcpy(new->tail, params->tail, new_tail_len);
1423 else
1424 if (old)
1425 memcpy(new->tail, old->tail, new_tail_len);
1426
1427 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
1428 params->probe_resp_len, csa, cca, link);
1429 if (err < 0) {
1430 kfree(new);
1431 return err;
1432 }
1433 if (err == 0)
1434 _changed |= BSS_CHANGED_AP_PROBE_RESP;
1435
1436 if (params->ftm_responder != -1) {
1437 link_conf->ftm_responder = params->ftm_responder;
1438 err = ieee80211_set_ftm_responder_params(sdata,
1439 params->lci,
1440 params->lci_len,
1441 params->civicloc,
1442 params->civicloc_len,
1443 link_conf);
1444
1445 if (err < 0) {
1446 kfree(new);
1447 return err;
1448 }
1449
1450 _changed |= BSS_CHANGED_FTM_RESPONDER;
1451 }
1452
1453 rcu_assign_pointer(link->u.ap.beacon, new);
1454 sdata->u.ap.active = true;
1455
1456 if (old)
1457 kfree_rcu(old, rcu_head);
1458
1459 *changed |= _changed;
1460 return 0;
1461 }
1462
ieee80211_num_beaconing_links(struct ieee80211_sub_if_data * sdata)1463 static u8 ieee80211_num_beaconing_links(struct ieee80211_sub_if_data *sdata)
1464 {
1465 struct ieee80211_link_data *link;
1466 u8 link_id, num = 0;
1467
1468 if (sdata->vif.type != NL80211_IFTYPE_AP &&
1469 sdata->vif.type != NL80211_IFTYPE_P2P_GO)
1470 return num;
1471
1472 /* non-MLO mode of operation also uses link_id 0 in sdata so it is
1473 * safe to directly proceed with the below loop
1474 */
1475 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1476 link = sdata_dereference(sdata->link[link_id], sdata);
1477 if (!link)
1478 continue;
1479
1480 if (sdata_dereference(link->u.ap.beacon, sdata))
1481 num++;
1482 }
1483
1484 return num;
1485 }
1486
ieee80211_start_ap(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_settings * params)1487 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1488 struct cfg80211_ap_settings *params)
1489 {
1490 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1491 struct ieee80211_local *local = sdata->local;
1492 struct beacon_data *old;
1493 struct ieee80211_sub_if_data *vlan;
1494 u64 changed = BSS_CHANGED_BEACON_INT |
1495 BSS_CHANGED_BEACON_ENABLED |
1496 BSS_CHANGED_BEACON |
1497 BSS_CHANGED_P2P_PS |
1498 BSS_CHANGED_TXPOWER |
1499 BSS_CHANGED_TWT;
1500 int i, err;
1501 int prev_beacon_int;
1502 unsigned int link_id = params->beacon.link_id;
1503 struct ieee80211_link_data *link;
1504 struct ieee80211_bss_conf *link_conf;
1505 struct ieee80211_chan_req chanreq = { .oper = params->chandef };
1506 u64 tsf;
1507
1508 lockdep_assert_wiphy(local->hw.wiphy);
1509
1510 link = sdata_dereference(sdata->link[link_id], sdata);
1511 if (!link)
1512 return -ENOLINK;
1513
1514 link_conf = link->conf;
1515
1516 old = sdata_dereference(link->u.ap.beacon, sdata);
1517 if (old)
1518 return -EALREADY;
1519
1520 link->smps_mode = IEEE80211_SMPS_OFF;
1521
1522 link->needed_rx_chains = sdata->local->rx_chains;
1523
1524 prev_beacon_int = link_conf->beacon_int;
1525 link_conf->beacon_int = params->beacon_interval;
1526
1527 if (params->ht_cap)
1528 link_conf->ht_ldpc =
1529 params->ht_cap->cap_info &
1530 cpu_to_le16(IEEE80211_HT_CAP_LDPC_CODING);
1531
1532 if (params->vht_cap) {
1533 link_conf->vht_ldpc =
1534 params->vht_cap->vht_cap_info &
1535 cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC);
1536 link_conf->vht_su_beamformer =
1537 params->vht_cap->vht_cap_info &
1538 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
1539 link_conf->vht_su_beamformee =
1540 params->vht_cap->vht_cap_info &
1541 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE);
1542 link_conf->vht_mu_beamformer =
1543 params->vht_cap->vht_cap_info &
1544 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
1545 link_conf->vht_mu_beamformee =
1546 params->vht_cap->vht_cap_info &
1547 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
1548 }
1549
1550 if (params->he_cap && params->he_oper) {
1551 link_conf->he_support = true;
1552 link_conf->htc_trig_based_pkt_ext =
1553 le32_get_bits(params->he_oper->he_oper_params,
1554 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
1555 link_conf->frame_time_rts_th =
1556 le32_get_bits(params->he_oper->he_oper_params,
1557 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
1558 changed |= BSS_CHANGED_HE_OBSS_PD;
1559
1560 if (params->beacon.he_bss_color.enabled)
1561 changed |= BSS_CHANGED_HE_BSS_COLOR;
1562 }
1563
1564 if (params->he_cap) {
1565 link_conf->he_ldpc =
1566 params->he_cap->phy_cap_info[1] &
1567 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
1568 link_conf->he_su_beamformer =
1569 params->he_cap->phy_cap_info[3] &
1570 IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER;
1571 link_conf->he_su_beamformee =
1572 params->he_cap->phy_cap_info[4] &
1573 IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE;
1574 link_conf->he_mu_beamformer =
1575 params->he_cap->phy_cap_info[4] &
1576 IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
1577 link_conf->he_full_ul_mumimo =
1578 params->he_cap->phy_cap_info[2] &
1579 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO;
1580 }
1581
1582 if (params->eht_cap) {
1583 if (!link_conf->he_support)
1584 return -EOPNOTSUPP;
1585
1586 link_conf->eht_support = true;
1587
1588 link_conf->eht_su_beamformer =
1589 params->eht_cap->fixed.phy_cap_info[0] &
1590 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER;
1591 link_conf->eht_su_beamformee =
1592 params->eht_cap->fixed.phy_cap_info[0] &
1593 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE;
1594 link_conf->eht_mu_beamformer =
1595 params->eht_cap->fixed.phy_cap_info[7] &
1596 (IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
1597 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
1598 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ);
1599 link_conf->eht_80mhz_full_bw_ul_mumimo =
1600 params->eht_cap->fixed.phy_cap_info[7] &
1601 (IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
1602 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
1603 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ);
1604 link_conf->eht_disable_mcs15 =
1605 u8_get_bits(params->eht_oper->params,
1606 IEEE80211_EHT_OPER_MCS15_DISABLE);
1607 } else {
1608 link_conf->eht_su_beamformer = false;
1609 link_conf->eht_su_beamformee = false;
1610 link_conf->eht_mu_beamformer = false;
1611 }
1612
1613 if (sdata->vif.type == NL80211_IFTYPE_AP &&
1614 params->mbssid_config.tx_wdev) {
1615 err = ieee80211_set_ap_mbssid_options(sdata,
1616 ¶ms->mbssid_config,
1617 link_conf);
1618 if (err)
1619 return err;
1620 }
1621
1622 err = ieee80211_link_use_channel(link, &chanreq,
1623 IEEE80211_CHANCTX_SHARED);
1624 if (!err)
1625 ieee80211_link_copy_chanctx_to_vlans(link, false);
1626 if (err) {
1627 link_conf->beacon_int = prev_beacon_int;
1628 return err;
1629 }
1630
1631 /*
1632 * Apply control port protocol, this allows us to
1633 * not encrypt dynamic WEP control frames.
1634 */
1635 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1636 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1637 sdata->control_port_over_nl80211 =
1638 params->crypto.control_port_over_nl80211;
1639 sdata->control_port_no_preauth =
1640 params->crypto.control_port_no_preauth;
1641
1642 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1643 vlan->control_port_protocol =
1644 params->crypto.control_port_ethertype;
1645 vlan->control_port_no_encrypt =
1646 params->crypto.control_port_no_encrypt;
1647 vlan->control_port_over_nl80211 =
1648 params->crypto.control_port_over_nl80211;
1649 vlan->control_port_no_preauth =
1650 params->crypto.control_port_no_preauth;
1651 }
1652
1653 link_conf->dtim_period = params->dtim_period;
1654 link_conf->enable_beacon = true;
1655 link_conf->allow_p2p_go_ps = sdata->vif.p2p;
1656 link_conf->twt_responder = params->twt_responder;
1657 link_conf->he_obss_pd = params->he_obss_pd;
1658 link_conf->he_bss_color = params->beacon.he_bss_color;
1659 link_conf->s1g_long_beacon_period = params->s1g_long_beacon_period;
1660 sdata->vif.cfg.s1g = params->chandef.chan->band == NL80211_BAND_S1GHZ;
1661
1662 sdata->vif.cfg.ssid_len = params->ssid_len;
1663 if (params->ssid_len)
1664 memcpy(sdata->vif.cfg.ssid, params->ssid,
1665 params->ssid_len);
1666 link_conf->hidden_ssid =
1667 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1668
1669 memset(&link_conf->p2p_noa_attr, 0,
1670 sizeof(link_conf->p2p_noa_attr));
1671 link_conf->p2p_noa_attr.oppps_ctwindow =
1672 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1673 if (params->p2p_opp_ps)
1674 link_conf->p2p_noa_attr.oppps_ctwindow |=
1675 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1676
1677 sdata->beacon_rate_set = false;
1678 if (wiphy_ext_feature_isset(local->hw.wiphy,
1679 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1680 for (i = 0; i < NUM_NL80211_BANDS; i++) {
1681 sdata->beacon_rateidx_mask[i] =
1682 params->beacon_rate.control[i].legacy;
1683 if (sdata->beacon_rateidx_mask[i])
1684 sdata->beacon_rate_set = true;
1685 }
1686 }
1687
1688 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
1689 link_conf->beacon_tx_rate = params->beacon_rate;
1690
1691 err = ieee80211_assign_beacon(sdata, link, ¶ms->beacon, NULL, NULL,
1692 &changed);
1693 if (err < 0)
1694 goto error;
1695
1696 err = ieee80211_set_fils_discovery(sdata, ¶ms->fils_discovery,
1697 link, link_conf, &changed);
1698 if (err < 0)
1699 goto error;
1700
1701 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1702 ¶ms->unsol_bcast_probe_resp,
1703 link, link_conf, &changed);
1704 if (err < 0)
1705 goto error;
1706
1707 if (sdata->vif.cfg.s1g) {
1708 err = ieee80211_set_s1g_short_beacon(sdata, link,
1709 ¶ms->s1g_short_beacon);
1710 if (err < 0)
1711 goto error;
1712 }
1713
1714 err = drv_start_ap(sdata->local, sdata, link_conf);
1715 if (err) {
1716 old = sdata_dereference(link->u.ap.beacon, sdata);
1717
1718 if (old)
1719 kfree_rcu(old, rcu_head);
1720 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1721
1722 if (ieee80211_num_beaconing_links(sdata) == 0)
1723 sdata->u.ap.active = false;
1724
1725 goto error;
1726 }
1727
1728 tsf = drv_get_tsf(local, sdata);
1729 ieee80211_recalc_dtim(sdata, tsf);
1730
1731 if (link->u.ap.s1g_short_beacon)
1732 ieee80211_recalc_sb_count(sdata, tsf);
1733
1734 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID);
1735 ieee80211_link_info_change_notify(sdata, link, changed);
1736
1737 if (ieee80211_num_beaconing_links(sdata) <= 1)
1738 netif_carrier_on(dev);
1739
1740 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1741 netif_carrier_on(vlan->dev);
1742
1743 return 0;
1744
1745 error:
1746 ieee80211_link_release_channel(link);
1747
1748 return err;
1749 }
1750
ieee80211_change_beacon(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_update * params)1751 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1752 struct cfg80211_ap_update *params)
1753
1754 {
1755 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1756 struct ieee80211_link_data *link;
1757 struct cfg80211_beacon_data *beacon = ¶ms->beacon;
1758 struct beacon_data *old;
1759 int err;
1760 struct ieee80211_bss_conf *link_conf;
1761 u64 changed = 0;
1762
1763 lockdep_assert_wiphy(wiphy);
1764
1765 link = sdata_dereference(sdata->link[beacon->link_id], sdata);
1766 if (!link)
1767 return -ENOLINK;
1768
1769 link_conf = link->conf;
1770
1771 /* don't allow changing the beacon while a countdown is in place - offset
1772 * of channel switch counter may change
1773 */
1774 if (link_conf->csa_active || link_conf->color_change_active)
1775 return -EBUSY;
1776
1777 old = sdata_dereference(link->u.ap.beacon, sdata);
1778 if (!old)
1779 return -ENOENT;
1780
1781 err = ieee80211_assign_beacon(sdata, link, beacon, NULL, NULL,
1782 &changed);
1783 if (err < 0)
1784 return err;
1785
1786 err = ieee80211_set_fils_discovery(sdata, ¶ms->fils_discovery,
1787 link, link_conf, &changed);
1788 if (err < 0)
1789 return err;
1790
1791 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1792 ¶ms->unsol_bcast_probe_resp,
1793 link, link_conf, &changed);
1794 if (err < 0)
1795 return err;
1796
1797 if (link->u.ap.s1g_short_beacon) {
1798 err = ieee80211_set_s1g_short_beacon(sdata, link,
1799 ¶ms->s1g_short_beacon);
1800 if (err < 0)
1801 return err;
1802 }
1803
1804 if (beacon->he_bss_color_valid &&
1805 beacon->he_bss_color.enabled != link_conf->he_bss_color.enabled) {
1806 link_conf->he_bss_color.enabled = beacon->he_bss_color.enabled;
1807 changed |= BSS_CHANGED_HE_BSS_COLOR;
1808 }
1809
1810 ieee80211_link_info_change_notify(sdata, link, changed);
1811 return 0;
1812 }
1813
ieee80211_free_next_beacon(struct ieee80211_link_data * link)1814 static void ieee80211_free_next_beacon(struct ieee80211_link_data *link)
1815 {
1816 if (!link->u.ap.next_beacon)
1817 return;
1818
1819 kfree(link->u.ap.next_beacon->mbssid_ies);
1820 kfree(link->u.ap.next_beacon->rnr_ies);
1821 kfree(link->u.ap.next_beacon);
1822 link->u.ap.next_beacon = NULL;
1823 }
1824
ieee80211_stop_ap(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id)1825 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1826 unsigned int link_id)
1827 {
1828 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1829 struct ieee80211_sub_if_data *vlan;
1830 struct ieee80211_local *local = sdata->local;
1831 struct beacon_data *old_beacon;
1832 struct probe_resp *old_probe_resp;
1833 struct fils_discovery_data *old_fils_discovery;
1834 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
1835 struct s1g_short_beacon_data *old_s1g_short_beacon;
1836 struct cfg80211_chan_def chandef;
1837 struct ieee80211_link_data *link =
1838 sdata_dereference(sdata->link[link_id], sdata);
1839 struct ieee80211_bss_conf *link_conf = link->conf;
1840 LIST_HEAD(keys);
1841
1842 lockdep_assert_wiphy(local->hw.wiphy);
1843
1844 old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
1845 if (!old_beacon)
1846 return -ENOENT;
1847 old_probe_resp = sdata_dereference(link->u.ap.probe_resp,
1848 sdata);
1849 old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery,
1850 sdata);
1851 old_unsol_bcast_probe_resp =
1852 sdata_dereference(link->u.ap.unsol_bcast_probe_resp,
1853 sdata);
1854 old_s1g_short_beacon =
1855 sdata_dereference(link->u.ap.s1g_short_beacon, sdata);
1856
1857 /* abort any running channel switch or color change */
1858 link_conf->csa_active = false;
1859 link_conf->color_change_active = false;
1860 ieee80211_vif_unblock_queues_csa(sdata);
1861
1862 ieee80211_free_next_beacon(link);
1863
1864 /* turn off carrier for this interface and dependent VLANs */
1865 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1866 netif_carrier_off(vlan->dev);
1867
1868 if (ieee80211_num_beaconing_links(sdata) <= 1) {
1869 netif_carrier_off(dev);
1870 sdata->u.ap.active = false;
1871 }
1872
1873 /* remove beacon and probe response */
1874 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1875 RCU_INIT_POINTER(link->u.ap.probe_resp, NULL);
1876 RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
1877 RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
1878 RCU_INIT_POINTER(link->u.ap.s1g_short_beacon, NULL);
1879 kfree_rcu(old_beacon, rcu_head);
1880 if (old_probe_resp)
1881 kfree_rcu(old_probe_resp, rcu_head);
1882 if (old_fils_discovery)
1883 kfree_rcu(old_fils_discovery, rcu_head);
1884 if (old_unsol_bcast_probe_resp)
1885 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
1886 if (old_s1g_short_beacon)
1887 kfree_rcu(old_s1g_short_beacon, rcu_head);
1888
1889 kfree(link_conf->ftmr_params);
1890 link_conf->ftmr_params = NULL;
1891
1892 link_conf->bssid_index = 0;
1893 link_conf->nontransmitted = false;
1894 link_conf->ema_ap = false;
1895 link_conf->bssid_indicator = 0;
1896 link_conf->fils_discovery.min_interval = 0;
1897 link_conf->fils_discovery.max_interval = 0;
1898 link_conf->unsol_bcast_probe_resp_interval = 0;
1899
1900 __sta_info_flush(sdata, true, link_id, NULL);
1901
1902 ieee80211_remove_link_keys(link, &keys);
1903 if (!list_empty(&keys)) {
1904 synchronize_net();
1905 ieee80211_free_key_list(local, &keys);
1906 }
1907
1908 ieee80211_stop_mbssid(sdata);
1909 RCU_INIT_POINTER(link_conf->tx_bss_conf, NULL);
1910
1911 link_conf->enable_beacon = false;
1912 sdata->beacon_rate_set = false;
1913 sdata->vif.cfg.ssid_len = 0;
1914 sdata->vif.cfg.s1g = false;
1915 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1916 ieee80211_link_info_change_notify(sdata, link,
1917 BSS_CHANGED_BEACON_ENABLED);
1918
1919 if (sdata->wdev.links[link_id].cac_started) {
1920 chandef = link_conf->chanreq.oper;
1921 wiphy_delayed_work_cancel(wiphy, &link->dfs_cac_timer_work);
1922 cfg80211_cac_event(sdata->dev, &chandef,
1923 NL80211_RADAR_CAC_ABORTED,
1924 GFP_KERNEL, link_id);
1925 }
1926
1927 drv_stop_ap(sdata->local, sdata, link_conf);
1928
1929 /* free all potentially still buffered bcast frames */
1930 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1931 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1932
1933 ieee80211_link_copy_chanctx_to_vlans(link, true);
1934 ieee80211_link_release_channel(link);
1935
1936 return 0;
1937 }
1938
sta_apply_auth_flags(struct ieee80211_local * local,struct sta_info * sta,u32 mask,u32 set)1939 static int sta_apply_auth_flags(struct ieee80211_local *local,
1940 struct sta_info *sta,
1941 u32 mask, u32 set)
1942 {
1943 int ret;
1944
1945 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1946 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1947 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1948 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1949 if (ret)
1950 return ret;
1951 }
1952
1953 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1954 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1955 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1956 /*
1957 * When peer becomes associated, init rate control as
1958 * well. Some drivers require rate control initialized
1959 * before drv_sta_state() is called.
1960 */
1961 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1962 rate_control_rate_init_all_links(sta);
1963
1964 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1965 if (ret)
1966 return ret;
1967 }
1968
1969 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1970 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1971 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1972 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1973 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1974 else
1975 ret = 0;
1976 if (ret)
1977 return ret;
1978 }
1979
1980 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1981 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1982 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1983 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1984 if (ret)
1985 return ret;
1986 }
1987
1988 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1989 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1990 test_sta_flag(sta, WLAN_STA_AUTH)) {
1991 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1992 if (ret)
1993 return ret;
1994 }
1995
1996 return 0;
1997 }
1998
sta_apply_mesh_params(struct ieee80211_local * local,struct sta_info * sta,struct station_parameters * params)1999 static void sta_apply_mesh_params(struct ieee80211_local *local,
2000 struct sta_info *sta,
2001 struct station_parameters *params)
2002 {
2003 #ifdef CONFIG_MAC80211_MESH
2004 struct ieee80211_sub_if_data *sdata = sta->sdata;
2005 u64 changed = 0;
2006
2007 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
2008 switch (params->plink_state) {
2009 case NL80211_PLINK_ESTAB:
2010 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
2011 changed = mesh_plink_inc_estab_count(sdata);
2012 sta->mesh->plink_state = params->plink_state;
2013 sta->mesh->aid = params->peer_aid;
2014
2015 ieee80211_mps_sta_status_update(sta);
2016 changed |= ieee80211_mps_set_sta_local_pm(sta,
2017 sdata->u.mesh.mshcfg.power_mode);
2018
2019 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
2020 /* init at low value */
2021 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
2022
2023 break;
2024 case NL80211_PLINK_LISTEN:
2025 case NL80211_PLINK_BLOCKED:
2026 case NL80211_PLINK_OPN_SNT:
2027 case NL80211_PLINK_OPN_RCVD:
2028 case NL80211_PLINK_CNF_RCVD:
2029 case NL80211_PLINK_HOLDING:
2030 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
2031 changed = mesh_plink_dec_estab_count(sdata);
2032 sta->mesh->plink_state = params->plink_state;
2033
2034 ieee80211_mps_sta_status_update(sta);
2035 changed |= ieee80211_mps_set_sta_local_pm(sta,
2036 NL80211_MESH_POWER_UNKNOWN);
2037 break;
2038 default:
2039 /* nothing */
2040 break;
2041 }
2042 }
2043
2044 switch (params->plink_action) {
2045 case NL80211_PLINK_ACTION_NO_ACTION:
2046 /* nothing */
2047 break;
2048 case NL80211_PLINK_ACTION_OPEN:
2049 changed |= mesh_plink_open(sta);
2050 break;
2051 case NL80211_PLINK_ACTION_BLOCK:
2052 changed |= mesh_plink_block(sta);
2053 break;
2054 }
2055
2056 if (params->local_pm)
2057 changed |= ieee80211_mps_set_sta_local_pm(sta,
2058 params->local_pm);
2059
2060 ieee80211_mbss_info_change_notify(sdata, changed);
2061 #endif
2062 }
2063
2064 enum sta_link_apply_mode {
2065 STA_LINK_MODE_NEW,
2066 STA_LINK_MODE_STA_MODIFY,
2067 STA_LINK_MODE_LINK_MODIFY,
2068 };
2069
sta_link_apply_parameters(struct ieee80211_local * local,struct sta_info * sta,enum sta_link_apply_mode mode,struct link_station_parameters * params)2070 static int sta_link_apply_parameters(struct ieee80211_local *local,
2071 struct sta_info *sta,
2072 enum sta_link_apply_mode mode,
2073 struct link_station_parameters *params)
2074 {
2075 struct ieee80211_supported_band *sband;
2076 struct ieee80211_sub_if_data *sdata = sta->sdata;
2077 u32 link_id = params->link_id < 0 ? 0 : params->link_id;
2078 struct ieee80211_link_data *link =
2079 sdata_dereference(sdata->link[link_id], sdata);
2080 struct link_sta_info *link_sta =
2081 rcu_dereference_protected(sta->link[link_id],
2082 lockdep_is_held(&local->hw.wiphy->mtx));
2083 bool changes = params->link_mac ||
2084 params->txpwr_set ||
2085 params->supported_rates_len ||
2086 params->ht_capa ||
2087 params->vht_capa ||
2088 params->he_capa ||
2089 params->eht_capa ||
2090 params->s1g_capa ||
2091 params->opmode_notif_used;
2092
2093 switch (mode) {
2094 case STA_LINK_MODE_NEW:
2095 if (!params->link_mac)
2096 return -EINVAL;
2097 break;
2098 case STA_LINK_MODE_LINK_MODIFY:
2099 break;
2100 case STA_LINK_MODE_STA_MODIFY:
2101 if (params->link_id >= 0)
2102 break;
2103 if (!changes)
2104 return 0;
2105 break;
2106 }
2107
2108 if (!link || !link_sta)
2109 return -EINVAL;
2110
2111 sband = ieee80211_get_link_sband(link);
2112 if (!sband)
2113 return -EINVAL;
2114
2115 if (params->link_mac) {
2116 if (mode == STA_LINK_MODE_NEW) {
2117 memcpy(link_sta->addr, params->link_mac, ETH_ALEN);
2118 memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN);
2119 } else if (!ether_addr_equal(link_sta->addr,
2120 params->link_mac)) {
2121 return -EINVAL;
2122 }
2123 }
2124
2125 if (params->txpwr_set) {
2126 int ret;
2127
2128 link_sta->pub->txpwr.type = params->txpwr.type;
2129 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
2130 link_sta->pub->txpwr.power = params->txpwr.power;
2131 ret = drv_sta_set_txpwr(local, sdata, sta);
2132 if (ret)
2133 return ret;
2134 }
2135
2136 if (params->supported_rates &&
2137 params->supported_rates_len &&
2138 !ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
2139 sband, params->supported_rates,
2140 params->supported_rates_len,
2141 &link_sta->pub->supp_rates[sband->band]))
2142 return -EINVAL;
2143
2144 if (params->ht_capa)
2145 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
2146 params->ht_capa, link_sta);
2147
2148 /* VHT can override some HT caps such as the A-MSDU max length */
2149 if (params->vht_capa)
2150 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
2151 params->vht_capa, NULL,
2152 link_sta);
2153
2154 if (params->he_capa)
2155 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
2156 (void *)params->he_capa,
2157 params->he_capa_len,
2158 (void *)params->he_6ghz_capa,
2159 link_sta);
2160
2161 if (params->he_capa && params->eht_capa)
2162 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
2163 (u8 *)params->he_capa,
2164 params->he_capa_len,
2165 params->eht_capa,
2166 params->eht_capa_len,
2167 link_sta);
2168
2169 if (params->s1g_capa)
2170 ieee80211_s1g_cap_to_sta_s1g_cap(sdata, params->s1g_capa,
2171 link_sta);
2172
2173 ieee80211_sta_init_nss(link_sta);
2174
2175 if (params->opmode_notif_used) {
2176 enum nl80211_chan_width width = link->conf->chanreq.oper.width;
2177
2178 switch (width) {
2179 case NL80211_CHAN_WIDTH_20:
2180 case NL80211_CHAN_WIDTH_40:
2181 case NL80211_CHAN_WIDTH_80:
2182 case NL80211_CHAN_WIDTH_160:
2183 case NL80211_CHAN_WIDTH_80P80:
2184 case NL80211_CHAN_WIDTH_320: /* not VHT, allowed for HE/EHT */
2185 break;
2186 default:
2187 return -EINVAL;
2188 }
2189
2190 /* returned value is only needed for rc update, but the
2191 * rc isn't initialized here yet, so ignore it
2192 */
2193 __ieee80211_vht_handle_opmode(sdata, link_sta,
2194 params->opmode_notif,
2195 sband->band);
2196 }
2197
2198 return 0;
2199 }
2200
sta_apply_parameters(struct ieee80211_local * local,struct sta_info * sta,struct station_parameters * params)2201 static int sta_apply_parameters(struct ieee80211_local *local,
2202 struct sta_info *sta,
2203 struct station_parameters *params)
2204 {
2205 struct ieee80211_sub_if_data *sdata = sta->sdata;
2206 u32 mask, set;
2207 int ret = 0;
2208
2209 mask = params->sta_flags_mask;
2210 set = params->sta_flags_set;
2211
2212 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2213 /*
2214 * In mesh mode, ASSOCIATED isn't part of the nl80211
2215 * API but must follow AUTHENTICATED for driver state.
2216 */
2217 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
2218 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2219 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
2220 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2221 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2222 /*
2223 * TDLS -- everything follows authorized, but
2224 * only becoming authorized is possible, not
2225 * going back
2226 */
2227 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
2228 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2229 BIT(NL80211_STA_FLAG_ASSOCIATED);
2230 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2231 BIT(NL80211_STA_FLAG_ASSOCIATED);
2232 }
2233 }
2234
2235 if (mask & BIT(NL80211_STA_FLAG_WME) &&
2236 local->hw.queues >= IEEE80211_NUM_ACS)
2237 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
2238
2239 /* auth flags will be set later for TDLS,
2240 * and for unassociated stations that move to associated */
2241 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
2242 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
2243 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
2244 ret = sta_apply_auth_flags(local, sta, mask, set);
2245 if (ret)
2246 return ret;
2247 }
2248
2249 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
2250 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
2251 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
2252 else
2253 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
2254 }
2255
2256 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
2257 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
2258 if (set & BIT(NL80211_STA_FLAG_MFP))
2259 set_sta_flag(sta, WLAN_STA_MFP);
2260 else
2261 clear_sta_flag(sta, WLAN_STA_MFP);
2262 }
2263
2264 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
2265 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2266 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
2267 else
2268 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
2269 }
2270
2271 if (mask & BIT(NL80211_STA_FLAG_SPP_AMSDU))
2272 sta->sta.spp_amsdu = set & BIT(NL80211_STA_FLAG_SPP_AMSDU);
2273
2274 /* mark TDLS channel switch support, if the AP allows it */
2275 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
2276 !sdata->deflink.u.mgd.tdls_chan_switch_prohibited &&
2277 params->ext_capab_len >= 4 &&
2278 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
2279 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
2280
2281 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
2282 !sdata->u.mgd.tdls_wider_bw_prohibited &&
2283 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
2284 params->ext_capab_len >= 8 &&
2285 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
2286 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
2287
2288 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
2289 sta->sta.uapsd_queues = params->uapsd_queues;
2290 sta->sta.max_sp = params->max_sp;
2291 }
2292
2293 ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab,
2294 params->ext_capab_len);
2295
2296 /*
2297 * cfg80211 validates this (1-2007) and allows setting the AID
2298 * only when creating a new station entry. For S1G APs, the current
2299 * implementation supports a maximum of 1600 AIDs.
2300 */
2301 if (params->aid) {
2302 if (sdata->vif.cfg.s1g &&
2303 params->aid > IEEE80211_MAX_SUPPORTED_S1G_AID)
2304 return -EINVAL;
2305
2306 sta->sta.aid = params->aid;
2307 }
2308
2309 /*
2310 * Some of the following updates would be racy if called on an
2311 * existing station, via ieee80211_change_station(). However,
2312 * all such changes are rejected by cfg80211 except for updates
2313 * changing the supported rates on an existing but not yet used
2314 * TDLS peer.
2315 */
2316
2317 if (params->listen_interval >= 0)
2318 sta->listen_interval = params->listen_interval;
2319
2320 if (params->eml_cap_present)
2321 sta->sta.eml_cap = params->eml_cap;
2322
2323 ret = sta_link_apply_parameters(local, sta, STA_LINK_MODE_STA_MODIFY,
2324 ¶ms->link_sta_params);
2325 if (ret)
2326 return ret;
2327
2328 if (params->support_p2p_ps >= 0)
2329 sta->sta.support_p2p_ps = params->support_p2p_ps;
2330
2331 if (ieee80211_vif_is_mesh(&sdata->vif))
2332 sta_apply_mesh_params(local, sta, params);
2333
2334 if (params->airtime_weight)
2335 sta->airtime_weight = params->airtime_weight;
2336
2337 /* set the STA state after all sta info from usermode has been set */
2338 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
2339 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
2340 ret = sta_apply_auth_flags(local, sta, mask, set);
2341 if (ret)
2342 return ret;
2343 }
2344
2345 /* Mark the STA as MLO if MLD MAC address is available */
2346 if (params->link_sta_params.mld_mac)
2347 sta->sta.mlo = true;
2348
2349 return 0;
2350 }
2351
ieee80211_add_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_parameters * params)2352 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
2353 const u8 *mac,
2354 struct station_parameters *params)
2355 {
2356 struct ieee80211_local *local = wiphy_priv(wiphy);
2357 struct sta_info *sta;
2358 struct ieee80211_sub_if_data *sdata;
2359 int err;
2360
2361 lockdep_assert_wiphy(local->hw.wiphy);
2362
2363 if (params->vlan) {
2364 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2365
2366 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2367 sdata->vif.type != NL80211_IFTYPE_AP)
2368 return -EINVAL;
2369 } else
2370 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2371
2372 if (ether_addr_equal(mac, sdata->vif.addr))
2373 return -EINVAL;
2374
2375 if (!is_valid_ether_addr(mac))
2376 return -EINVAL;
2377
2378 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
2379 sdata->vif.type == NL80211_IFTYPE_STATION &&
2380 !sdata->u.mgd.associated)
2381 return -EINVAL;
2382
2383 /*
2384 * If we have a link ID, it can be a non-MLO station on an AP MLD,
2385 * but we need to have a link_mac in that case as well, so use the
2386 * STA's MAC address in that case.
2387 */
2388 if (params->link_sta_params.link_id >= 0)
2389 sta = sta_info_alloc_with_link(sdata, mac,
2390 params->link_sta_params.link_id,
2391 params->link_sta_params.link_mac ?: mac,
2392 GFP_KERNEL);
2393 else
2394 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
2395
2396 if (!sta)
2397 return -ENOMEM;
2398
2399 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2400 sta->sta.tdls = true;
2401
2402 /* Though the mutex is not needed here (since the station is not
2403 * visible yet), sta_apply_parameters (and inner functions) require
2404 * the mutex due to other paths.
2405 */
2406 err = sta_apply_parameters(local, sta, params);
2407 if (err) {
2408 sta_info_free(local, sta);
2409 return err;
2410 }
2411
2412 /*
2413 * for TDLS and for unassociated station, rate control should be
2414 * initialized only when rates are known and station is marked
2415 * authorized/associated
2416 */
2417 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
2418 test_sta_flag(sta, WLAN_STA_ASSOC))
2419 rate_control_rate_init_all_links(sta);
2420
2421 return sta_info_insert(sta);
2422 }
2423
ieee80211_del_station(struct wiphy * wiphy,struct net_device * dev,struct station_del_parameters * params)2424 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
2425 struct station_del_parameters *params)
2426 {
2427 struct ieee80211_sub_if_data *sdata;
2428
2429 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2430
2431 if (params->mac)
2432 return sta_info_destroy_addr_bss(sdata, params->mac);
2433
2434 sta_info_flush(sdata, params->link_id);
2435 return 0;
2436 }
2437
ieee80211_change_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_parameters * params)2438 static int ieee80211_change_station(struct wiphy *wiphy,
2439 struct net_device *dev, const u8 *mac,
2440 struct station_parameters *params)
2441 {
2442 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2443 struct ieee80211_local *local = wiphy_priv(wiphy);
2444 struct sta_info *sta;
2445 struct ieee80211_sub_if_data *vlansdata;
2446 enum cfg80211_station_type statype;
2447 int err;
2448
2449 lockdep_assert_wiphy(local->hw.wiphy);
2450
2451 sta = sta_info_get_bss(sdata, mac);
2452 if (!sta)
2453 return -ENOENT;
2454
2455 switch (sdata->vif.type) {
2456 case NL80211_IFTYPE_MESH_POINT:
2457 if (sdata->u.mesh.user_mpm)
2458 statype = CFG80211_STA_MESH_PEER_USER;
2459 else
2460 statype = CFG80211_STA_MESH_PEER_KERNEL;
2461 break;
2462 case NL80211_IFTYPE_ADHOC:
2463 statype = CFG80211_STA_IBSS;
2464 break;
2465 case NL80211_IFTYPE_STATION:
2466 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2467 statype = CFG80211_STA_AP_STA;
2468 break;
2469 }
2470 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2471 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
2472 else
2473 statype = CFG80211_STA_TDLS_PEER_SETUP;
2474 break;
2475 case NL80211_IFTYPE_AP:
2476 case NL80211_IFTYPE_AP_VLAN:
2477 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2478 statype = CFG80211_STA_AP_CLIENT;
2479 else
2480 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
2481 break;
2482 default:
2483 return -EOPNOTSUPP;
2484 }
2485
2486 err = cfg80211_check_station_change(wiphy, params, statype);
2487 if (err)
2488 return err;
2489
2490 if (params->vlan && params->vlan != sta->sdata->dev) {
2491 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2492
2493 if (params->vlan->ieee80211_ptr->use_4addr) {
2494 if (vlansdata->u.vlan.sta)
2495 return -EBUSY;
2496
2497 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
2498 __ieee80211_check_fast_rx_iface(vlansdata);
2499 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
2500 }
2501
2502 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2503 sta->sdata->u.vlan.sta)
2504 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
2505
2506 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2507 ieee80211_vif_dec_num_mcast(sta->sdata);
2508
2509 sta->sdata = vlansdata;
2510 ieee80211_check_fast_rx(sta);
2511 ieee80211_check_fast_xmit(sta);
2512
2513 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
2514 ieee80211_vif_inc_num_mcast(sta->sdata);
2515 cfg80211_send_layer2_update(sta->sdata->dev,
2516 sta->sta.addr);
2517 }
2518 }
2519
2520 err = sta_apply_parameters(local, sta, params);
2521 if (err)
2522 return err;
2523
2524 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2525 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
2526 ieee80211_recalc_ps(local);
2527 ieee80211_recalc_ps_vif(sdata);
2528 }
2529
2530 return 0;
2531 }
2532
2533 #ifdef CONFIG_MAC80211_MESH
ieee80211_add_mpath(struct wiphy * wiphy,struct net_device * dev,const u8 * dst,const u8 * next_hop)2534 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
2535 const u8 *dst, const u8 *next_hop)
2536 {
2537 struct ieee80211_sub_if_data *sdata;
2538 struct mesh_path *mpath;
2539 struct sta_info *sta;
2540
2541 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2542
2543 rcu_read_lock();
2544 sta = sta_info_get(sdata, next_hop);
2545 if (!sta) {
2546 rcu_read_unlock();
2547 return -ENOENT;
2548 }
2549
2550 mpath = mesh_path_add(sdata, dst);
2551 if (IS_ERR(mpath)) {
2552 rcu_read_unlock();
2553 return PTR_ERR(mpath);
2554 }
2555
2556 mesh_path_fix_nexthop(mpath, sta);
2557
2558 rcu_read_unlock();
2559 return 0;
2560 }
2561
ieee80211_del_mpath(struct wiphy * wiphy,struct net_device * dev,const u8 * dst)2562 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
2563 const u8 *dst)
2564 {
2565 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2566
2567 if (dst)
2568 return mesh_path_del(sdata, dst);
2569
2570 mesh_path_flush_by_iface(sdata);
2571 return 0;
2572 }
2573
ieee80211_change_mpath(struct wiphy * wiphy,struct net_device * dev,const u8 * dst,const u8 * next_hop)2574 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2575 const u8 *dst, const u8 *next_hop)
2576 {
2577 struct ieee80211_sub_if_data *sdata;
2578 struct mesh_path *mpath;
2579 struct sta_info *sta;
2580
2581 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2582
2583 rcu_read_lock();
2584
2585 sta = sta_info_get(sdata, next_hop);
2586 if (!sta) {
2587 rcu_read_unlock();
2588 return -ENOENT;
2589 }
2590
2591 mpath = mesh_path_lookup(sdata, dst);
2592 if (!mpath) {
2593 rcu_read_unlock();
2594 return -ENOENT;
2595 }
2596
2597 mesh_path_fix_nexthop(mpath, sta);
2598
2599 rcu_read_unlock();
2600 return 0;
2601 }
2602
mpath_set_pinfo(struct mesh_path * mpath,u8 * next_hop,struct mpath_info * pinfo)2603 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2604 struct mpath_info *pinfo)
2605 {
2606 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2607
2608 if (next_hop_sta)
2609 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
2610 else
2611 eth_zero_addr(next_hop);
2612
2613 memset(pinfo, 0, sizeof(*pinfo));
2614
2615 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
2616
2617 pinfo->filled = MPATH_INFO_FRAME_QLEN |
2618 MPATH_INFO_SN |
2619 MPATH_INFO_METRIC |
2620 MPATH_INFO_EXPTIME |
2621 MPATH_INFO_DISCOVERY_TIMEOUT |
2622 MPATH_INFO_DISCOVERY_RETRIES |
2623 MPATH_INFO_FLAGS |
2624 MPATH_INFO_HOP_COUNT |
2625 MPATH_INFO_PATH_CHANGE;
2626
2627 pinfo->frame_qlen = mpath->frame_queue.qlen;
2628 pinfo->sn = mpath->sn;
2629 pinfo->metric = mpath->metric;
2630 if (time_before(jiffies, mpath->exp_time))
2631 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2632 pinfo->discovery_timeout =
2633 jiffies_to_msecs(mpath->discovery_timeout);
2634 pinfo->discovery_retries = mpath->discovery_retries;
2635 if (mpath->flags & MESH_PATH_ACTIVE)
2636 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2637 if (mpath->flags & MESH_PATH_RESOLVING)
2638 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
2639 if (mpath->flags & MESH_PATH_SN_VALID)
2640 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
2641 if (mpath->flags & MESH_PATH_FIXED)
2642 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
2643 if (mpath->flags & MESH_PATH_RESOLVED)
2644 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
2645 pinfo->hop_count = mpath->hop_count;
2646 pinfo->path_change_count = mpath->path_change_count;
2647 }
2648
ieee80211_get_mpath(struct wiphy * wiphy,struct net_device * dev,u8 * dst,u8 * next_hop,struct mpath_info * pinfo)2649 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2650 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2651
2652 {
2653 struct ieee80211_sub_if_data *sdata;
2654 struct mesh_path *mpath;
2655
2656 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2657
2658 rcu_read_lock();
2659 mpath = mesh_path_lookup(sdata, dst);
2660 if (!mpath) {
2661 rcu_read_unlock();
2662 return -ENOENT;
2663 }
2664 memcpy(dst, mpath->dst, ETH_ALEN);
2665 mpath_set_pinfo(mpath, next_hop, pinfo);
2666 rcu_read_unlock();
2667 return 0;
2668 }
2669
ieee80211_dump_mpath(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * dst,u8 * next_hop,struct mpath_info * pinfo)2670 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
2671 int idx, u8 *dst, u8 *next_hop,
2672 struct mpath_info *pinfo)
2673 {
2674 struct ieee80211_sub_if_data *sdata;
2675 struct mesh_path *mpath;
2676
2677 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2678
2679 rcu_read_lock();
2680 mpath = mesh_path_lookup_by_idx(sdata, idx);
2681 if (!mpath) {
2682 rcu_read_unlock();
2683 return -ENOENT;
2684 }
2685 memcpy(dst, mpath->dst, ETH_ALEN);
2686 mpath_set_pinfo(mpath, next_hop, pinfo);
2687 rcu_read_unlock();
2688 return 0;
2689 }
2690
mpp_set_pinfo(struct mesh_path * mpath,u8 * mpp,struct mpath_info * pinfo)2691 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2692 struct mpath_info *pinfo)
2693 {
2694 memset(pinfo, 0, sizeof(*pinfo));
2695 memcpy(mpp, mpath->mpp, ETH_ALEN);
2696
2697 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
2698 }
2699
ieee80211_get_mpp(struct wiphy * wiphy,struct net_device * dev,u8 * dst,u8 * mpp,struct mpath_info * pinfo)2700 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2701 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2702
2703 {
2704 struct ieee80211_sub_if_data *sdata;
2705 struct mesh_path *mpath;
2706
2707 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2708
2709 rcu_read_lock();
2710 mpath = mpp_path_lookup(sdata, dst);
2711 if (!mpath) {
2712 rcu_read_unlock();
2713 return -ENOENT;
2714 }
2715 memcpy(dst, mpath->dst, ETH_ALEN);
2716 mpp_set_pinfo(mpath, mpp, pinfo);
2717 rcu_read_unlock();
2718 return 0;
2719 }
2720
ieee80211_dump_mpp(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * dst,u8 * mpp,struct mpath_info * pinfo)2721 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2722 int idx, u8 *dst, u8 *mpp,
2723 struct mpath_info *pinfo)
2724 {
2725 struct ieee80211_sub_if_data *sdata;
2726 struct mesh_path *mpath;
2727
2728 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2729
2730 rcu_read_lock();
2731 mpath = mpp_path_lookup_by_idx(sdata, idx);
2732 if (!mpath) {
2733 rcu_read_unlock();
2734 return -ENOENT;
2735 }
2736 memcpy(dst, mpath->dst, ETH_ALEN);
2737 mpp_set_pinfo(mpath, mpp, pinfo);
2738 rcu_read_unlock();
2739 return 0;
2740 }
2741
ieee80211_get_mesh_config(struct wiphy * wiphy,struct net_device * dev,struct mesh_config * conf)2742 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
2743 struct net_device *dev,
2744 struct mesh_config *conf)
2745 {
2746 struct ieee80211_sub_if_data *sdata;
2747 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2748
2749 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2750 return 0;
2751 }
2752
_chg_mesh_attr(enum nl80211_meshconf_params parm,u32 mask)2753 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2754 {
2755 return (mask >> (parm-1)) & 0x1;
2756 }
2757
copy_mesh_setup(struct ieee80211_if_mesh * ifmsh,const struct mesh_setup * setup)2758 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2759 const struct mesh_setup *setup)
2760 {
2761 u8 *new_ie;
2762 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2763 struct ieee80211_sub_if_data, u.mesh);
2764 int i;
2765
2766 /* allocate information elements */
2767 new_ie = NULL;
2768
2769 if (setup->ie_len) {
2770 new_ie = kmemdup(setup->ie, setup->ie_len,
2771 GFP_KERNEL);
2772 if (!new_ie)
2773 return -ENOMEM;
2774 }
2775 ifmsh->ie_len = setup->ie_len;
2776 ifmsh->ie = new_ie;
2777
2778 /* now copy the rest of the setup parameters */
2779 ifmsh->mesh_id_len = setup->mesh_id_len;
2780 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
2781 ifmsh->mesh_sp_id = setup->sync_method;
2782 ifmsh->mesh_pp_id = setup->path_sel_proto;
2783 ifmsh->mesh_pm_id = setup->path_metric;
2784 ifmsh->user_mpm = setup->user_mpm;
2785 ifmsh->mesh_auth_id = setup->auth_id;
2786 ifmsh->security = IEEE80211_MESH_SEC_NONE;
2787 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
2788 if (setup->is_authenticated)
2789 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2790 if (setup->is_secure)
2791 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
2792
2793 /* mcast rate setting in Mesh Node */
2794 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2795 sizeof(setup->mcast_rate));
2796 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
2797
2798 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2799 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2800
2801 sdata->beacon_rate_set = false;
2802 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2803 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2804 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2805 sdata->beacon_rateidx_mask[i] =
2806 setup->beacon_rate.control[i].legacy;
2807 if (sdata->beacon_rateidx_mask[i])
2808 sdata->beacon_rate_set = true;
2809 }
2810 }
2811
2812 return 0;
2813 }
2814
ieee80211_update_mesh_config(struct wiphy * wiphy,struct net_device * dev,u32 mask,const struct mesh_config * nconf)2815 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
2816 struct net_device *dev, u32 mask,
2817 const struct mesh_config *nconf)
2818 {
2819 struct mesh_config *conf;
2820 struct ieee80211_sub_if_data *sdata;
2821 struct ieee80211_if_mesh *ifmsh;
2822
2823 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2824 ifmsh = &sdata->u.mesh;
2825
2826 /* Set the config options which we are interested in setting */
2827 conf = &(sdata->u.mesh.mshcfg);
2828 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2829 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2830 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2831 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2832 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2833 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2834 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2835 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2836 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2837 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2838 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2839 conf->dot11MeshTTL = nconf->dot11MeshTTL;
2840 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
2841 conf->element_ttl = nconf->element_ttl;
2842 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2843 if (ifmsh->user_mpm)
2844 return -EBUSY;
2845 conf->auto_open_plinks = nconf->auto_open_plinks;
2846 }
2847 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2848 conf->dot11MeshNbrOffsetMaxNeighbor =
2849 nconf->dot11MeshNbrOffsetMaxNeighbor;
2850 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2851 conf->dot11MeshHWMPmaxPREQretries =
2852 nconf->dot11MeshHWMPmaxPREQretries;
2853 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2854 conf->path_refresh_time = nconf->path_refresh_time;
2855 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2856 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2857 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2858 conf->dot11MeshHWMPactivePathTimeout =
2859 nconf->dot11MeshHWMPactivePathTimeout;
2860 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2861 conf->dot11MeshHWMPpreqMinInterval =
2862 nconf->dot11MeshHWMPpreqMinInterval;
2863 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2864 conf->dot11MeshHWMPperrMinInterval =
2865 nconf->dot11MeshHWMPperrMinInterval;
2866 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2867 mask))
2868 conf->dot11MeshHWMPnetDiameterTraversalTime =
2869 nconf->dot11MeshHWMPnetDiameterTraversalTime;
2870 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2871 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2872 ieee80211_mesh_root_setup(ifmsh);
2873 }
2874 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2875 /* our current gate announcement implementation rides on root
2876 * announcements, so require this ifmsh to also be a root node
2877 * */
2878 if (nconf->dot11MeshGateAnnouncementProtocol &&
2879 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2880 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2881 ieee80211_mesh_root_setup(ifmsh);
2882 }
2883 conf->dot11MeshGateAnnouncementProtocol =
2884 nconf->dot11MeshGateAnnouncementProtocol;
2885 }
2886 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2887 conf->dot11MeshHWMPRannInterval =
2888 nconf->dot11MeshHWMPRannInterval;
2889 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2890 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2891 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2892 /* our RSSI threshold implementation is supported only for
2893 * devices that report signal in dBm.
2894 */
2895 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2896 return -EOPNOTSUPP;
2897 conf->rssi_threshold = nconf->rssi_threshold;
2898 }
2899 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2900 conf->ht_opmode = nconf->ht_opmode;
2901 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2902 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2903 BSS_CHANGED_HT);
2904 }
2905 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2906 conf->dot11MeshHWMPactivePathToRootTimeout =
2907 nconf->dot11MeshHWMPactivePathToRootTimeout;
2908 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2909 conf->dot11MeshHWMProotInterval =
2910 nconf->dot11MeshHWMProotInterval;
2911 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2912 conf->dot11MeshHWMPconfirmationInterval =
2913 nconf->dot11MeshHWMPconfirmationInterval;
2914 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2915 conf->power_mode = nconf->power_mode;
2916 ieee80211_mps_local_status_update(sdata);
2917 }
2918 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2919 conf->dot11MeshAwakeWindowDuration =
2920 nconf->dot11MeshAwakeWindowDuration;
2921 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2922 conf->plink_timeout = nconf->plink_timeout;
2923 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2924 conf->dot11MeshConnectedToMeshGate =
2925 nconf->dot11MeshConnectedToMeshGate;
2926 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2927 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
2928 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2929 conf->dot11MeshConnectedToAuthServer =
2930 nconf->dot11MeshConnectedToAuthServer;
2931 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2932 return 0;
2933 }
2934
ieee80211_join_mesh(struct wiphy * wiphy,struct net_device * dev,const struct mesh_config * conf,const struct mesh_setup * setup)2935 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2936 const struct mesh_config *conf,
2937 const struct mesh_setup *setup)
2938 {
2939 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2940 struct ieee80211_chan_req chanreq = { .oper = setup->chandef };
2941 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2942 int err;
2943
2944 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2945
2946 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2947 err = copy_mesh_setup(ifmsh, setup);
2948 if (err)
2949 return err;
2950
2951 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2952
2953 /* can mesh use other SMPS modes? */
2954 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
2955 sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
2956
2957 err = ieee80211_link_use_channel(&sdata->deflink, &chanreq,
2958 IEEE80211_CHANCTX_SHARED);
2959 if (err)
2960 return err;
2961
2962 return ieee80211_start_mesh(sdata);
2963 }
2964
ieee80211_leave_mesh(struct wiphy * wiphy,struct net_device * dev)2965 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2966 {
2967 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2968
2969 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2970
2971 ieee80211_stop_mesh(sdata);
2972 ieee80211_link_release_channel(&sdata->deflink);
2973 kfree(sdata->u.mesh.ie);
2974
2975 return 0;
2976 }
2977 #endif
2978
ieee80211_change_bss(struct wiphy * wiphy,struct net_device * dev,struct bss_parameters * params)2979 static int ieee80211_change_bss(struct wiphy *wiphy,
2980 struct net_device *dev,
2981 struct bss_parameters *params)
2982 {
2983 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2984 struct ieee80211_link_data *link;
2985 struct ieee80211_supported_band *sband;
2986 u64 changed = 0;
2987
2988 link = ieee80211_link_or_deflink(sdata, params->link_id, true);
2989 if (IS_ERR(link))
2990 return PTR_ERR(link);
2991
2992 if (!sdata_dereference(link->u.ap.beacon, sdata))
2993 return -ENOENT;
2994
2995 sband = ieee80211_get_link_sband(link);
2996 if (!sband)
2997 return -EINVAL;
2998
2999 if (params->basic_rates) {
3000 if (!ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
3001 wiphy->bands[sband->band],
3002 params->basic_rates,
3003 params->basic_rates_len,
3004 &link->conf->basic_rates))
3005 return -EINVAL;
3006 changed |= BSS_CHANGED_BASIC_RATES;
3007 ieee80211_check_rate_mask(link);
3008 }
3009
3010 if (params->use_cts_prot >= 0) {
3011 link->conf->use_cts_prot = params->use_cts_prot;
3012 changed |= BSS_CHANGED_ERP_CTS_PROT;
3013 }
3014 if (params->use_short_preamble >= 0) {
3015 link->conf->use_short_preamble = params->use_short_preamble;
3016 changed |= BSS_CHANGED_ERP_PREAMBLE;
3017 }
3018
3019 if (!link->conf->use_short_slot &&
3020 (sband->band == NL80211_BAND_5GHZ ||
3021 sband->band == NL80211_BAND_6GHZ)) {
3022 link->conf->use_short_slot = true;
3023 changed |= BSS_CHANGED_ERP_SLOT;
3024 }
3025
3026 if (params->use_short_slot_time >= 0) {
3027 link->conf->use_short_slot = params->use_short_slot_time;
3028 changed |= BSS_CHANGED_ERP_SLOT;
3029 }
3030
3031 if (params->ap_isolate >= 0) {
3032 if (params->ap_isolate)
3033 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
3034 else
3035 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
3036 ieee80211_check_fast_rx_iface(sdata);
3037 }
3038
3039 if (params->ht_opmode >= 0) {
3040 link->conf->ht_operation_mode = (u16)params->ht_opmode;
3041 changed |= BSS_CHANGED_HT;
3042 }
3043
3044 if (params->p2p_ctwindow >= 0) {
3045 link->conf->p2p_noa_attr.oppps_ctwindow &=
3046 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
3047 link->conf->p2p_noa_attr.oppps_ctwindow |=
3048 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
3049 changed |= BSS_CHANGED_P2P_PS;
3050 }
3051
3052 if (params->p2p_opp_ps > 0) {
3053 link->conf->p2p_noa_attr.oppps_ctwindow |=
3054 IEEE80211_P2P_OPPPS_ENABLE_BIT;
3055 changed |= BSS_CHANGED_P2P_PS;
3056 } else if (params->p2p_opp_ps == 0) {
3057 link->conf->p2p_noa_attr.oppps_ctwindow &=
3058 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
3059 changed |= BSS_CHANGED_P2P_PS;
3060 }
3061
3062 ieee80211_link_info_change_notify(sdata, link, changed);
3063
3064 return 0;
3065 }
3066
ieee80211_set_txq_params(struct wiphy * wiphy,struct net_device * dev,struct ieee80211_txq_params * params)3067 static int ieee80211_set_txq_params(struct wiphy *wiphy,
3068 struct net_device *dev,
3069 struct ieee80211_txq_params *params)
3070 {
3071 struct ieee80211_local *local = wiphy_priv(wiphy);
3072 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3073 struct ieee80211_link_data *link =
3074 ieee80211_link_or_deflink(sdata, params->link_id, true);
3075 struct ieee80211_tx_queue_params p;
3076
3077 if (!local->ops->conf_tx)
3078 return -EOPNOTSUPP;
3079
3080 if (local->hw.queues < IEEE80211_NUM_ACS)
3081 return -EOPNOTSUPP;
3082
3083 if (IS_ERR(link))
3084 return PTR_ERR(link);
3085
3086 memset(&p, 0, sizeof(p));
3087 p.aifs = params->aifs;
3088 p.cw_max = params->cwmax;
3089 p.cw_min = params->cwmin;
3090 p.txop = params->txop;
3091
3092 /*
3093 * Setting tx queue params disables u-apsd because it's only
3094 * called in master mode.
3095 */
3096 p.uapsd = false;
3097
3098 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
3099
3100 link->tx_conf[params->ac] = p;
3101 if (drv_conf_tx(local, link, params->ac, &p)) {
3102 wiphy_debug(local->hw.wiphy,
3103 "failed to set TX queue parameters for AC %d\n",
3104 params->ac);
3105 return -EINVAL;
3106 }
3107
3108 ieee80211_link_info_change_notify(sdata, link,
3109 BSS_CHANGED_QOS);
3110
3111 return 0;
3112 }
3113
3114 #ifdef CONFIG_PM
ieee80211_suspend(struct wiphy * wiphy,struct cfg80211_wowlan * wowlan)3115 static int ieee80211_suspend(struct wiphy *wiphy,
3116 struct cfg80211_wowlan *wowlan)
3117 {
3118 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
3119 }
3120
ieee80211_resume(struct wiphy * wiphy)3121 static int ieee80211_resume(struct wiphy *wiphy)
3122 {
3123 return __ieee80211_resume(wiphy_priv(wiphy));
3124 }
3125 #else
3126 #define ieee80211_suspend NULL
3127 #define ieee80211_resume NULL
3128 #endif
3129
ieee80211_scan(struct wiphy * wiphy,struct cfg80211_scan_request * req)3130 static int ieee80211_scan(struct wiphy *wiphy,
3131 struct cfg80211_scan_request *req)
3132 {
3133 struct ieee80211_sub_if_data *sdata;
3134 struct ieee80211_link_data *link;
3135 struct ieee80211_channel *chan;
3136 int radio_idx;
3137
3138 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
3139
3140 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
3141 case NL80211_IFTYPE_STATION:
3142 case NL80211_IFTYPE_ADHOC:
3143 case NL80211_IFTYPE_MESH_POINT:
3144 case NL80211_IFTYPE_P2P_CLIENT:
3145 case NL80211_IFTYPE_P2P_DEVICE:
3146 break;
3147 case NL80211_IFTYPE_P2P_GO:
3148 if (sdata->local->ops->hw_scan)
3149 break;
3150 /*
3151 * FIXME: implement NoA while scanning in software,
3152 * for now fall through to allow scanning only when
3153 * beaconing hasn't been configured yet
3154 */
3155 fallthrough;
3156 case NL80211_IFTYPE_AP:
3157 /*
3158 * If the scan has been forced (and the driver supports
3159 * forcing), don't care about being beaconing already.
3160 * This will create problems to the attached stations (e.g. all
3161 * the frames sent while scanning on other channel will be
3162 * lost)
3163 */
3164 for_each_link_data(sdata, link) {
3165 /* if the link is not beaconing, ignore it */
3166 if (!sdata_dereference(link->u.ap.beacon, sdata))
3167 continue;
3168
3169 chan = link->conf->chanreq.oper.chan;
3170 radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chan);
3171
3172 if (ieee80211_is_radio_idx_in_scan_req(wiphy, req,
3173 radio_idx) &&
3174 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
3175 !(req->flags & NL80211_SCAN_FLAG_AP)))
3176 return -EOPNOTSUPP;
3177 }
3178 break;
3179 case NL80211_IFTYPE_NAN:
3180 default:
3181 return -EOPNOTSUPP;
3182 }
3183
3184 return ieee80211_request_scan(sdata, req);
3185 }
3186
ieee80211_abort_scan(struct wiphy * wiphy,struct wireless_dev * wdev)3187 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
3188 {
3189 ieee80211_scan_cancel(wiphy_priv(wiphy));
3190 }
3191
3192 static int
ieee80211_sched_scan_start(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_sched_scan_request * req)3193 ieee80211_sched_scan_start(struct wiphy *wiphy,
3194 struct net_device *dev,
3195 struct cfg80211_sched_scan_request *req)
3196 {
3197 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3198
3199 if (!sdata->local->ops->sched_scan_start)
3200 return -EOPNOTSUPP;
3201
3202 return ieee80211_request_sched_scan_start(sdata, req);
3203 }
3204
3205 static int
ieee80211_sched_scan_stop(struct wiphy * wiphy,struct net_device * dev,u64 reqid)3206 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
3207 u64 reqid)
3208 {
3209 struct ieee80211_local *local = wiphy_priv(wiphy);
3210
3211 if (!local->ops->sched_scan_stop)
3212 return -EOPNOTSUPP;
3213
3214 return ieee80211_request_sched_scan_stop(local);
3215 }
3216
ieee80211_auth(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_auth_request * req)3217 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
3218 struct cfg80211_auth_request *req)
3219 {
3220 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
3221 }
3222
ieee80211_assoc(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_assoc_request * req)3223 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
3224 struct cfg80211_assoc_request *req)
3225 {
3226 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
3227 }
3228
ieee80211_deauth(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_deauth_request * req)3229 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
3230 struct cfg80211_deauth_request *req)
3231 {
3232 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
3233 }
3234
ieee80211_disassoc(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_disassoc_request * req)3235 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
3236 struct cfg80211_disassoc_request *req)
3237 {
3238 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
3239 }
3240
ieee80211_join_ibss(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ibss_params * params)3241 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
3242 struct cfg80211_ibss_params *params)
3243 {
3244 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
3245 }
3246
ieee80211_leave_ibss(struct wiphy * wiphy,struct net_device * dev)3247 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
3248 {
3249 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
3250 }
3251
ieee80211_join_ocb(struct wiphy * wiphy,struct net_device * dev,struct ocb_setup * setup)3252 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
3253 struct ocb_setup *setup)
3254 {
3255 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
3256 }
3257
ieee80211_leave_ocb(struct wiphy * wiphy,struct net_device * dev)3258 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
3259 {
3260 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
3261 }
3262
ieee80211_set_mcast_rate(struct wiphy * wiphy,struct net_device * dev,int rate[NUM_NL80211_BANDS])3263 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
3264 int rate[NUM_NL80211_BANDS])
3265 {
3266 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3267
3268 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
3269 sizeof(int) * NUM_NL80211_BANDS);
3270
3271 if (ieee80211_sdata_running(sdata))
3272 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3273 BSS_CHANGED_MCAST_RATE);
3274
3275 return 0;
3276 }
3277
ieee80211_set_wiphy_params(struct wiphy * wiphy,int radio_idx,u32 changed)3278 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, int radio_idx,
3279 u32 changed)
3280 {
3281 struct ieee80211_local *local = wiphy_priv(wiphy);
3282 int err;
3283
3284 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
3285 ieee80211_check_fast_xmit_all(local);
3286
3287 err = drv_set_frag_threshold(local, radio_idx,
3288 wiphy->frag_threshold);
3289
3290 if (err) {
3291 ieee80211_check_fast_xmit_all(local);
3292 return err;
3293 }
3294 }
3295
3296 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
3297 (changed & WIPHY_PARAM_DYN_ACK)) {
3298 s16 coverage_class;
3299
3300 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
3301 wiphy->coverage_class : -1;
3302 err = drv_set_coverage_class(local, radio_idx,
3303 coverage_class);
3304
3305 if (err)
3306 return err;
3307 }
3308
3309 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
3310 u32 rts_threshold;
3311
3312 if ((radio_idx == -1) || (radio_idx >= wiphy->n_radio))
3313 rts_threshold = wiphy->rts_threshold;
3314 else
3315 rts_threshold =
3316 wiphy->radio_cfg[radio_idx].rts_threshold;
3317
3318 err = drv_set_rts_threshold(local, radio_idx, rts_threshold);
3319
3320 if (err)
3321 return err;
3322 }
3323
3324 if (changed & WIPHY_PARAM_RETRY_SHORT) {
3325 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
3326 return -EINVAL;
3327 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
3328 }
3329 if (changed & WIPHY_PARAM_RETRY_LONG) {
3330 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
3331 return -EINVAL;
3332 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
3333 }
3334 if (changed &
3335 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
3336 ieee80211_hw_config(local, radio_idx,
3337 IEEE80211_CONF_CHANGE_RETRY_LIMITS);
3338
3339 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
3340 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
3341 WIPHY_PARAM_TXQ_QUANTUM))
3342 ieee80211_txq_set_params(local, radio_idx);
3343
3344 return 0;
3345 }
3346
ieee80211_set_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int radio_idx,enum nl80211_tx_power_setting type,int mbm)3347 static int ieee80211_set_tx_power(struct wiphy *wiphy,
3348 struct wireless_dev *wdev, int radio_idx,
3349 enum nl80211_tx_power_setting type, int mbm)
3350 {
3351 struct ieee80211_local *local = wiphy_priv(wiphy);
3352 struct ieee80211_sub_if_data *sdata;
3353 enum nl80211_tx_power_setting txp_type = type;
3354 bool update_txp_type = false;
3355 bool has_monitor = false;
3356 int user_power_level;
3357 int old_power = local->user_power_level;
3358
3359 lockdep_assert_wiphy(local->hw.wiphy);
3360
3361 switch (type) {
3362 case NL80211_TX_POWER_AUTOMATIC:
3363 user_power_level = IEEE80211_UNSET_POWER_LEVEL;
3364 txp_type = NL80211_TX_POWER_LIMITED;
3365 break;
3366 case NL80211_TX_POWER_LIMITED:
3367 case NL80211_TX_POWER_FIXED:
3368 if (mbm < 0 || (mbm % 100))
3369 return -EOPNOTSUPP;
3370 user_power_level = MBM_TO_DBM(mbm);
3371 break;
3372 default:
3373 return -EINVAL;
3374 }
3375
3376 if (wdev) {
3377 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3378
3379 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
3380 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) {
3381 if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
3382 return -EOPNOTSUPP;
3383
3384 sdata = wiphy_dereference(local->hw.wiphy,
3385 local->monitor_sdata);
3386 if (!sdata)
3387 return -EOPNOTSUPP;
3388 }
3389
3390 for (int link_id = 0;
3391 link_id < ARRAY_SIZE(sdata->link);
3392 link_id++) {
3393 struct ieee80211_link_data *link =
3394 wiphy_dereference(wiphy, sdata->link[link_id]);
3395
3396 if (!link)
3397 continue;
3398
3399 link->user_power_level = user_power_level;
3400
3401 if (txp_type != link->conf->txpower_type) {
3402 update_txp_type = true;
3403 link->conf->txpower_type = txp_type;
3404 }
3405
3406 ieee80211_recalc_txpower(link, update_txp_type);
3407 }
3408 return 0;
3409 }
3410
3411 local->user_power_level = user_power_level;
3412
3413 list_for_each_entry(sdata, &local->interfaces, list) {
3414 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
3415 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) {
3416 has_monitor = true;
3417 continue;
3418 }
3419
3420 for (int link_id = 0;
3421 link_id < ARRAY_SIZE(sdata->link);
3422 link_id++) {
3423 struct ieee80211_link_data *link =
3424 wiphy_dereference(wiphy, sdata->link[link_id]);
3425
3426 if (!link)
3427 continue;
3428
3429 link->user_power_level = local->user_power_level;
3430 if (txp_type != link->conf->txpower_type)
3431 update_txp_type = true;
3432 link->conf->txpower_type = txp_type;
3433 }
3434 }
3435 list_for_each_entry(sdata, &local->interfaces, list) {
3436 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
3437 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR))
3438 continue;
3439
3440 for (int link_id = 0;
3441 link_id < ARRAY_SIZE(sdata->link);
3442 link_id++) {
3443 struct ieee80211_link_data *link =
3444 wiphy_dereference(wiphy, sdata->link[link_id]);
3445
3446 if (!link)
3447 continue;
3448
3449 ieee80211_recalc_txpower(link, update_txp_type);
3450 }
3451 }
3452
3453 if (has_monitor) {
3454 sdata = wiphy_dereference(local->hw.wiphy,
3455 local->monitor_sdata);
3456 if (sdata && ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) {
3457 sdata->deflink.user_power_level = local->user_power_level;
3458 if (txp_type != sdata->vif.bss_conf.txpower_type)
3459 update_txp_type = true;
3460 sdata->vif.bss_conf.txpower_type = txp_type;
3461
3462 ieee80211_recalc_txpower(&sdata->deflink,
3463 update_txp_type);
3464 }
3465 }
3466
3467 if (local->emulate_chanctx &&
3468 (old_power != local->user_power_level))
3469 ieee80211_hw_conf_chan(local);
3470
3471 return 0;
3472 }
3473
ieee80211_get_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int radio_idx,unsigned int link_id,int * dbm)3474 static int ieee80211_get_tx_power(struct wiphy *wiphy,
3475 struct wireless_dev *wdev,
3476 int radio_idx,
3477 unsigned int link_id,
3478 int *dbm)
3479 {
3480 struct ieee80211_local *local = wiphy_priv(wiphy);
3481 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3482 struct ieee80211_link_data *link_data;
3483
3484 if (local->ops->get_txpower &&
3485 (sdata->flags & IEEE80211_SDATA_IN_DRIVER))
3486 return drv_get_txpower(local, sdata, link_id, dbm);
3487
3488 if (local->emulate_chanctx) {
3489 *dbm = local->hw.conf.power_level;
3490 } else {
3491 link_data = wiphy_dereference(wiphy, sdata->link[link_id]);
3492
3493 if (link_data)
3494 *dbm = link_data->conf->txpower;
3495 else
3496 return -ENOLINK;
3497 }
3498
3499 /* INT_MIN indicates no power level was set yet */
3500 if (*dbm == INT_MIN)
3501 return -EINVAL;
3502
3503 return 0;
3504 }
3505
ieee80211_rfkill_poll(struct wiphy * wiphy)3506 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
3507 {
3508 struct ieee80211_local *local = wiphy_priv(wiphy);
3509
3510 drv_rfkill_poll(local);
3511 }
3512
3513 #ifdef CONFIG_NL80211_TESTMODE
ieee80211_testmode_cmd(struct wiphy * wiphy,struct wireless_dev * wdev,void * data,int len)3514 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
3515 struct wireless_dev *wdev,
3516 void *data, int len)
3517 {
3518 struct ieee80211_local *local = wiphy_priv(wiphy);
3519 struct ieee80211_vif *vif = NULL;
3520
3521 if (!local->ops->testmode_cmd)
3522 return -EOPNOTSUPP;
3523
3524 if (wdev) {
3525 struct ieee80211_sub_if_data *sdata;
3526
3527 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3528 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
3529 vif = &sdata->vif;
3530 }
3531
3532 return local->ops->testmode_cmd(&local->hw, vif, data, len);
3533 }
3534
ieee80211_testmode_dump(struct wiphy * wiphy,struct sk_buff * skb,struct netlink_callback * cb,void * data,int len)3535 static int ieee80211_testmode_dump(struct wiphy *wiphy,
3536 struct sk_buff *skb,
3537 struct netlink_callback *cb,
3538 void *data, int len)
3539 {
3540 struct ieee80211_local *local = wiphy_priv(wiphy);
3541
3542 if (!local->ops->testmode_dump)
3543 return -EOPNOTSUPP;
3544
3545 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
3546 }
3547 #endif
3548
__ieee80211_request_smps_mgd(struct ieee80211_sub_if_data * sdata,struct ieee80211_link_data * link,enum ieee80211_smps_mode smps_mode)3549 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
3550 struct ieee80211_link_data *link,
3551 enum ieee80211_smps_mode smps_mode)
3552 {
3553 const u8 *ap;
3554 enum ieee80211_smps_mode old_req;
3555 int err;
3556 struct sta_info *sta;
3557 bool tdls_peer_found = false;
3558
3559 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3560
3561 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
3562 return -EINVAL;
3563
3564 if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
3565 return 0;
3566
3567 old_req = link->u.mgd.req_smps;
3568 link->u.mgd.req_smps = smps_mode;
3569
3570 /* The driver indicated that EML is enabled for the interface, which
3571 * implies that SMPS flows towards the AP should be stopped.
3572 */
3573 if (sdata->vif.driver_flags & IEEE80211_VIF_EML_ACTIVE)
3574 return 0;
3575
3576 if (old_req == smps_mode &&
3577 smps_mode != IEEE80211_SMPS_AUTOMATIC)
3578 return 0;
3579
3580 /*
3581 * If not associated, or current association is not an HT
3582 * association, there's no need to do anything, just store
3583 * the new value until we associate.
3584 */
3585 if (!sdata->u.mgd.associated ||
3586 link->conf->chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT)
3587 return 0;
3588
3589 ap = sdata->vif.cfg.ap_addr;
3590
3591 rcu_read_lock();
3592 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
3593 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
3594 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3595 continue;
3596
3597 tdls_peer_found = true;
3598 break;
3599 }
3600 rcu_read_unlock();
3601
3602 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
3603 if (tdls_peer_found || !sdata->u.mgd.powersave)
3604 smps_mode = IEEE80211_SMPS_OFF;
3605 else
3606 smps_mode = IEEE80211_SMPS_DYNAMIC;
3607 }
3608
3609 /* send SM PS frame to AP */
3610 err = ieee80211_send_smps_action(sdata, smps_mode,
3611 ap, ap,
3612 ieee80211_vif_is_mld(&sdata->vif) ?
3613 link->link_id : -1);
3614 if (err)
3615 link->u.mgd.req_smps = old_req;
3616 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
3617 ieee80211_teardown_tdls_peers(link);
3618
3619 return err;
3620 }
3621
ieee80211_set_power_mgmt(struct wiphy * wiphy,struct net_device * dev,bool enabled,int timeout)3622 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
3623 bool enabled, int timeout)
3624 {
3625 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3626 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3627 unsigned int link_id;
3628
3629 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3630 return -EOPNOTSUPP;
3631
3632 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
3633 return -EOPNOTSUPP;
3634
3635 if (enabled == sdata->u.mgd.powersave &&
3636 timeout == local->dynamic_ps_forced_timeout)
3637 return 0;
3638
3639 sdata->u.mgd.powersave = enabled;
3640 local->dynamic_ps_forced_timeout = timeout;
3641
3642 /* no change, but if automatic follow powersave */
3643 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3644 struct ieee80211_link_data *link;
3645
3646 link = sdata_dereference(sdata->link[link_id], sdata);
3647
3648 if (!link)
3649 continue;
3650 __ieee80211_request_smps_mgd(sdata, link,
3651 link->u.mgd.req_smps);
3652 }
3653
3654 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3655 ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS);
3656
3657 ieee80211_recalc_ps(local);
3658 ieee80211_recalc_ps_vif(sdata);
3659 ieee80211_check_fast_rx_iface(sdata);
3660
3661 return 0;
3662 }
3663
ieee80211_set_cqm_rssi_link(struct ieee80211_sub_if_data * sdata,struct ieee80211_link_data * link,s32 rssi_thold,u32 rssi_hyst,s32 rssi_low,s32 rssi_high)3664 static void ieee80211_set_cqm_rssi_link(struct ieee80211_sub_if_data *sdata,
3665 struct ieee80211_link_data *link,
3666 s32 rssi_thold, u32 rssi_hyst,
3667 s32 rssi_low, s32 rssi_high)
3668 {
3669 struct ieee80211_bss_conf *conf;
3670
3671 if (!link || !link->conf)
3672 return;
3673
3674 conf = link->conf;
3675
3676 if (rssi_thold && rssi_hyst &&
3677 rssi_thold == conf->cqm_rssi_thold &&
3678 rssi_hyst == conf->cqm_rssi_hyst)
3679 return;
3680
3681 conf->cqm_rssi_thold = rssi_thold;
3682 conf->cqm_rssi_hyst = rssi_hyst;
3683 conf->cqm_rssi_low = rssi_low;
3684 conf->cqm_rssi_high = rssi_high;
3685 link->u.mgd.last_cqm_event_signal = 0;
3686
3687 if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
3688 return;
3689
3690 if (sdata->u.mgd.associated &&
3691 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3692 ieee80211_link_info_change_notify(sdata, link, BSS_CHANGED_CQM);
3693 }
3694
ieee80211_set_cqm_rssi_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_thold,u32 rssi_hyst)3695 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3696 struct net_device *dev,
3697 s32 rssi_thold, u32 rssi_hyst)
3698 {
3699 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3700 struct ieee80211_vif *vif = &sdata->vif;
3701 int link_id;
3702
3703 if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3704 !(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3705 return -EOPNOTSUPP;
3706
3707 /* For MLD, handle CQM change on all the active links */
3708 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
3709 struct ieee80211_link_data *link =
3710 sdata_dereference(sdata->link[link_id], sdata);
3711
3712 ieee80211_set_cqm_rssi_link(sdata, link, rssi_thold, rssi_hyst,
3713 0, 0);
3714 }
3715
3716 return 0;
3717 }
3718
ieee80211_set_cqm_rssi_range_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_low,s32 rssi_high)3719 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3720 struct net_device *dev,
3721 s32 rssi_low, s32 rssi_high)
3722 {
3723 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3724 struct ieee80211_vif *vif = &sdata->vif;
3725 int link_id;
3726
3727 if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)
3728 return -EOPNOTSUPP;
3729
3730 /* For MLD, handle CQM change on all the active links */
3731 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
3732 struct ieee80211_link_data *link =
3733 sdata_dereference(sdata->link[link_id], sdata);
3734
3735 ieee80211_set_cqm_rssi_link(sdata, link, 0, 0,
3736 rssi_low, rssi_high);
3737 }
3738
3739 return 0;
3740 }
3741
ieee80211_set_bitrate_mask(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id,const u8 * addr,const struct cfg80211_bitrate_mask * mask)3742 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3743 struct net_device *dev,
3744 unsigned int link_id,
3745 const u8 *addr,
3746 const struct cfg80211_bitrate_mask *mask)
3747 {
3748 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3749 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3750 int i, ret;
3751
3752 if (!ieee80211_sdata_running(sdata))
3753 return -ENETDOWN;
3754
3755 /*
3756 * If active validate the setting and reject it if it doesn't leave
3757 * at least one basic rate usable, since we really have to be able
3758 * to send something, and if we're an AP we have to be able to do
3759 * so at a basic rate so that all clients can receive it.
3760 */
3761 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
3762 sdata->vif.bss_conf.chanreq.oper.chan) {
3763 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3764 enum nl80211_band band;
3765
3766 band = sdata->vif.bss_conf.chanreq.oper.chan->band;
3767
3768 if (!(mask->control[band].legacy & basic_rates))
3769 return -EINVAL;
3770 }
3771
3772 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3773 ret = drv_set_bitrate_mask(local, sdata, mask);
3774 if (ret)
3775 return ret;
3776 }
3777
3778 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3779 struct ieee80211_supported_band *sband = wiphy->bands[i];
3780 int j;
3781
3782 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
3783 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3784 sizeof(mask->control[i].ht_mcs));
3785 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3786 mask->control[i].vht_mcs,
3787 sizeof(mask->control[i].vht_mcs));
3788
3789 sdata->rc_has_mcs_mask[i] = false;
3790 sdata->rc_has_vht_mcs_mask[i] = false;
3791 if (!sband)
3792 continue;
3793
3794 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
3795 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
3796 sdata->rc_has_mcs_mask[i] = true;
3797 break;
3798 }
3799 }
3800
3801 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
3802 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
3803 sdata->rc_has_vht_mcs_mask[i] = true;
3804 break;
3805 }
3806 }
3807 }
3808
3809 return 0;
3810 }
3811
ieee80211_is_scan_ongoing(struct wiphy * wiphy,struct ieee80211_local * local,struct cfg80211_chan_def * chandef)3812 static bool ieee80211_is_scan_ongoing(struct wiphy *wiphy,
3813 struct ieee80211_local *local,
3814 struct cfg80211_chan_def *chandef)
3815 {
3816 struct cfg80211_scan_request *scan_req;
3817 int chan_radio_idx, req_radio_idx;
3818 struct ieee80211_roc_work *roc;
3819
3820 if (list_empty(&local->roc_list) && !local->scanning)
3821 return false;
3822
3823 req_radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chandef->chan);
3824
3825 if (local->scanning) {
3826 scan_req = wiphy_dereference(wiphy, local->scan_req);
3827 /*
3828 * Scan is going on but info is not there. Should not happen
3829 * but if it does, let's not take risk and assume we can't use
3830 * the hw hence return true
3831 */
3832 if (WARN_ON_ONCE(!scan_req))
3833 return true;
3834
3835 return ieee80211_is_radio_idx_in_scan_req(wiphy, scan_req,
3836 req_radio_idx);
3837 }
3838
3839 list_for_each_entry(roc, &local->roc_list, list) {
3840 chan_radio_idx = cfg80211_get_radio_idx_by_chan(wiphy,
3841 roc->chan);
3842 if (chan_radio_idx == req_radio_idx)
3843 return true;
3844 }
3845
3846 return false;
3847 }
3848
ieee80211_start_radar_detection(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_chan_def * chandef,u32 cac_time_ms,int link_id)3849 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3850 struct net_device *dev,
3851 struct cfg80211_chan_def *chandef,
3852 u32 cac_time_ms, int link_id)
3853 {
3854 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3855 struct ieee80211_chan_req chanreq = { .oper = *chandef };
3856 struct ieee80211_local *local = sdata->local;
3857 struct ieee80211_link_data *link_data;
3858 int err;
3859
3860 lockdep_assert_wiphy(local->hw.wiphy);
3861
3862 if (ieee80211_is_scan_ongoing(wiphy, local, chandef))
3863 return -EBUSY;
3864
3865 link_data = sdata_dereference(sdata->link[link_id], sdata);
3866 if (!link_data)
3867 return -ENOLINK;
3868
3869 /* whatever, but channel contexts should not complain about that one */
3870 link_data->smps_mode = IEEE80211_SMPS_OFF;
3871 link_data->needed_rx_chains = local->rx_chains;
3872
3873 err = ieee80211_link_use_channel(link_data, &chanreq,
3874 IEEE80211_CHANCTX_SHARED);
3875 if (err)
3876 return err;
3877
3878 wiphy_delayed_work_queue(wiphy, &link_data->dfs_cac_timer_work,
3879 msecs_to_jiffies(cac_time_ms));
3880
3881 return 0;
3882 }
3883
ieee80211_end_cac(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id)3884 static void ieee80211_end_cac(struct wiphy *wiphy,
3885 struct net_device *dev, unsigned int link_id)
3886 {
3887 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3888 struct ieee80211_local *local = sdata->local;
3889 struct ieee80211_link_data *link_data;
3890
3891 lockdep_assert_wiphy(local->hw.wiphy);
3892
3893 list_for_each_entry(sdata, &local->interfaces, list) {
3894 link_data = sdata_dereference(sdata->link[link_id], sdata);
3895 if (!link_data)
3896 continue;
3897
3898 wiphy_delayed_work_cancel(wiphy,
3899 &link_data->dfs_cac_timer_work);
3900
3901 if (sdata->wdev.links[link_id].cac_started) {
3902 ieee80211_link_release_channel(link_data);
3903 sdata->wdev.links[link_id].cac_started = false;
3904 }
3905 }
3906 }
3907
3908 static struct cfg80211_beacon_data *
cfg80211_beacon_dup(struct cfg80211_beacon_data * beacon)3909 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3910 {
3911 struct cfg80211_beacon_data *new_beacon;
3912 u8 *pos;
3913 int len;
3914
3915 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3916 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3917 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
3918
3919 if (beacon->mbssid_ies)
3920 len += ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies,
3921 beacon->rnr_ies,
3922 beacon->mbssid_ies->cnt);
3923
3924 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3925 if (!new_beacon)
3926 return NULL;
3927
3928 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3929 new_beacon->mbssid_ies =
3930 kzalloc(struct_size(new_beacon->mbssid_ies,
3931 elem, beacon->mbssid_ies->cnt),
3932 GFP_KERNEL);
3933 if (!new_beacon->mbssid_ies) {
3934 kfree(new_beacon);
3935 return NULL;
3936 }
3937
3938 if (beacon->rnr_ies && beacon->rnr_ies->cnt) {
3939 new_beacon->rnr_ies =
3940 kzalloc(struct_size(new_beacon->rnr_ies,
3941 elem, beacon->rnr_ies->cnt),
3942 GFP_KERNEL);
3943 if (!new_beacon->rnr_ies) {
3944 kfree(new_beacon->mbssid_ies);
3945 kfree(new_beacon);
3946 return NULL;
3947 }
3948 }
3949 }
3950
3951 pos = (u8 *)(new_beacon + 1);
3952 if (beacon->head_len) {
3953 new_beacon->head_len = beacon->head_len;
3954 new_beacon->head = pos;
3955 memcpy(pos, beacon->head, beacon->head_len);
3956 pos += beacon->head_len;
3957 }
3958 if (beacon->tail_len) {
3959 new_beacon->tail_len = beacon->tail_len;
3960 new_beacon->tail = pos;
3961 memcpy(pos, beacon->tail, beacon->tail_len);
3962 pos += beacon->tail_len;
3963 }
3964 if (beacon->beacon_ies_len) {
3965 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3966 new_beacon->beacon_ies = pos;
3967 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3968 pos += beacon->beacon_ies_len;
3969 }
3970 if (beacon->proberesp_ies_len) {
3971 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3972 new_beacon->proberesp_ies = pos;
3973 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3974 pos += beacon->proberesp_ies_len;
3975 }
3976 if (beacon->assocresp_ies_len) {
3977 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3978 new_beacon->assocresp_ies = pos;
3979 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3980 pos += beacon->assocresp_ies_len;
3981 }
3982 if (beacon->probe_resp_len) {
3983 new_beacon->probe_resp_len = beacon->probe_resp_len;
3984 new_beacon->probe_resp = pos;
3985 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3986 pos += beacon->probe_resp_len;
3987 }
3988 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3989 pos += ieee80211_copy_mbssid_beacon(pos,
3990 new_beacon->mbssid_ies,
3991 beacon->mbssid_ies);
3992 if (beacon->rnr_ies && beacon->rnr_ies->cnt)
3993 pos += ieee80211_copy_rnr_beacon(pos,
3994 new_beacon->rnr_ies,
3995 beacon->rnr_ies);
3996 }
3997
3998 /* might copy -1, meaning no changes requested */
3999 new_beacon->ftm_responder = beacon->ftm_responder;
4000 if (beacon->lci) {
4001 new_beacon->lci_len = beacon->lci_len;
4002 new_beacon->lci = pos;
4003 memcpy(pos, beacon->lci, beacon->lci_len);
4004 pos += beacon->lci_len;
4005 }
4006 if (beacon->civicloc) {
4007 new_beacon->civicloc_len = beacon->civicloc_len;
4008 new_beacon->civicloc = pos;
4009 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
4010 pos += beacon->civicloc_len;
4011 }
4012
4013 return new_beacon;
4014 }
4015
ieee80211_csa_finish(struct ieee80211_vif * vif,unsigned int link_id)4016 void ieee80211_csa_finish(struct ieee80211_vif *vif, unsigned int link_id)
4017 {
4018 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4019 struct ieee80211_local *local = sdata->local;
4020 struct ieee80211_bss_conf *tx_bss_conf;
4021 struct ieee80211_link_data *link_data;
4022
4023 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
4024 return;
4025
4026 rcu_read_lock();
4027
4028 link_data = rcu_dereference(sdata->link[link_id]);
4029 if (WARN_ON(!link_data)) {
4030 rcu_read_unlock();
4031 return;
4032 }
4033
4034 tx_bss_conf = rcu_dereference(link_data->conf->tx_bss_conf);
4035 if (tx_bss_conf == link_data->conf) {
4036 /* Trigger ieee80211_csa_finish() on the non-transmitting
4037 * interfaces when channel switch is received on
4038 * transmitting interface
4039 */
4040 struct ieee80211_link_data *iter;
4041
4042 for_each_sdata_link_rcu(local, iter) {
4043 if (iter->sdata == sdata ||
4044 rcu_access_pointer(iter->conf->tx_bss_conf) != tx_bss_conf)
4045 continue;
4046
4047 wiphy_work_queue(iter->sdata->local->hw.wiphy,
4048 &iter->csa.finalize_work);
4049 }
4050 }
4051
4052 wiphy_work_queue(local->hw.wiphy, &link_data->csa.finalize_work);
4053
4054 rcu_read_unlock();
4055 }
4056 EXPORT_SYMBOL(ieee80211_csa_finish);
4057
ieee80211_channel_switch_disconnect(struct ieee80211_vif * vif)4058 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif)
4059 {
4060 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4061 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4062 struct ieee80211_local *local = sdata->local;
4063
4064 sdata_info(sdata, "channel switch failed, disconnecting\n");
4065 wiphy_work_queue(local->hw.wiphy, &ifmgd->csa_connection_drop_work);
4066 }
4067 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
4068
ieee80211_set_after_csa_beacon(struct ieee80211_link_data * link_data,u64 * changed)4069 static int ieee80211_set_after_csa_beacon(struct ieee80211_link_data *link_data,
4070 u64 *changed)
4071 {
4072 struct ieee80211_sub_if_data *sdata = link_data->sdata;
4073 int err;
4074
4075 switch (sdata->vif.type) {
4076 case NL80211_IFTYPE_AP:
4077 if (!link_data->u.ap.next_beacon)
4078 return -EINVAL;
4079
4080 err = ieee80211_assign_beacon(sdata, link_data,
4081 link_data->u.ap.next_beacon,
4082 NULL, NULL, changed);
4083 ieee80211_free_next_beacon(link_data);
4084
4085 if (err < 0)
4086 return err;
4087 break;
4088 case NL80211_IFTYPE_ADHOC:
4089 err = ieee80211_ibss_finish_csa(sdata, changed);
4090 if (err < 0)
4091 return err;
4092 break;
4093 #ifdef CONFIG_MAC80211_MESH
4094 case NL80211_IFTYPE_MESH_POINT:
4095 err = ieee80211_mesh_finish_csa(sdata, changed);
4096 if (err < 0)
4097 return err;
4098 break;
4099 #endif
4100 default:
4101 WARN_ON(1);
4102 return -EINVAL;
4103 }
4104
4105 return 0;
4106 }
4107
__ieee80211_csa_finalize(struct ieee80211_link_data * link_data)4108 static int __ieee80211_csa_finalize(struct ieee80211_link_data *link_data)
4109 {
4110 struct ieee80211_sub_if_data *sdata = link_data->sdata;
4111 struct ieee80211_local *local = sdata->local;
4112 struct ieee80211_bss_conf *link_conf = link_data->conf;
4113 u64 changed = 0;
4114 int err;
4115
4116 lockdep_assert_wiphy(local->hw.wiphy);
4117
4118 /*
4119 * using reservation isn't immediate as it may be deferred until later
4120 * with multi-vif. once reservation is complete it will re-schedule the
4121 * work with no reserved_chanctx so verify chandef to check if it
4122 * completed successfully
4123 */
4124
4125 if (link_data->reserved_chanctx) {
4126 /*
4127 * with multi-vif csa driver may call ieee80211_csa_finish()
4128 * many times while waiting for other interfaces to use their
4129 * reservations
4130 */
4131 if (link_data->reserved_ready)
4132 return 0;
4133
4134 return ieee80211_link_use_reserved_context(link_data);
4135 }
4136
4137 if (!cfg80211_chandef_identical(&link_conf->chanreq.oper,
4138 &link_data->csa.chanreq.oper))
4139 return -EINVAL;
4140
4141 link_conf->csa_active = false;
4142
4143 err = ieee80211_set_after_csa_beacon(link_data, &changed);
4144 if (err)
4145 return err;
4146
4147 ieee80211_link_info_change_notify(sdata, link_data, changed);
4148
4149 ieee80211_vif_unblock_queues_csa(sdata);
4150
4151 err = drv_post_channel_switch(link_data);
4152 if (err)
4153 return err;
4154
4155 cfg80211_ch_switch_notify(sdata->dev, &link_data->csa.chanreq.oper,
4156 link_data->link_id);
4157
4158 return 0;
4159 }
4160
ieee80211_csa_finalize(struct ieee80211_link_data * link_data)4161 static void ieee80211_csa_finalize(struct ieee80211_link_data *link_data)
4162 {
4163 struct ieee80211_sub_if_data *sdata = link_data->sdata;
4164
4165 if (__ieee80211_csa_finalize(link_data)) {
4166 sdata_info(sdata, "failed to finalize CSA on link %d, disconnecting\n",
4167 link_data->link_id);
4168 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
4169 GFP_KERNEL);
4170 }
4171 }
4172
ieee80211_csa_finalize_work(struct wiphy * wiphy,struct wiphy_work * work)4173 void ieee80211_csa_finalize_work(struct wiphy *wiphy, struct wiphy_work *work)
4174 {
4175 struct ieee80211_link_data *link =
4176 container_of(work, struct ieee80211_link_data, csa.finalize_work);
4177 struct ieee80211_sub_if_data *sdata = link->sdata;
4178 struct ieee80211_local *local = sdata->local;
4179
4180 lockdep_assert_wiphy(local->hw.wiphy);
4181
4182 /* AP might have been stopped while waiting for the lock. */
4183 if (!link->conf->csa_active)
4184 return;
4185
4186 if (!ieee80211_sdata_running(sdata))
4187 return;
4188
4189 ieee80211_csa_finalize(link);
4190 }
4191
ieee80211_set_csa_beacon(struct ieee80211_link_data * link_data,struct cfg80211_csa_settings * params,u64 * changed)4192 static int ieee80211_set_csa_beacon(struct ieee80211_link_data *link_data,
4193 struct cfg80211_csa_settings *params,
4194 u64 *changed)
4195 {
4196 struct ieee80211_sub_if_data *sdata = link_data->sdata;
4197 struct ieee80211_csa_settings csa = {};
4198 int err;
4199
4200 switch (sdata->vif.type) {
4201 case NL80211_IFTYPE_AP:
4202 link_data->u.ap.next_beacon =
4203 cfg80211_beacon_dup(¶ms->beacon_after);
4204 if (!link_data->u.ap.next_beacon)
4205 return -ENOMEM;
4206
4207 /*
4208 * With a count of 0, we don't have to wait for any
4209 * TBTT before switching, so complete the CSA
4210 * immediately. In theory, with a count == 1 we
4211 * should delay the switch until just before the next
4212 * TBTT, but that would complicate things so we switch
4213 * immediately too. If we would delay the switch
4214 * until the next TBTT, we would have to set the probe
4215 * response here.
4216 *
4217 * TODO: A channel switch with count <= 1 without
4218 * sending a CSA action frame is kind of useless,
4219 * because the clients won't know we're changing
4220 * channels. The action frame must be implemented
4221 * either here or in the userspace.
4222 */
4223 if (params->count <= 1)
4224 break;
4225
4226 if ((params->n_counter_offsets_beacon >
4227 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
4228 (params->n_counter_offsets_presp >
4229 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
4230 ieee80211_free_next_beacon(link_data);
4231 return -EINVAL;
4232 }
4233
4234 csa.counter_offsets_beacon = params->counter_offsets_beacon;
4235 csa.counter_offsets_presp = params->counter_offsets_presp;
4236 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
4237 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
4238 csa.count = params->count;
4239
4240 err = ieee80211_assign_beacon(sdata, link_data,
4241 ¶ms->beacon_csa, &csa,
4242 NULL, changed);
4243 if (err < 0) {
4244 ieee80211_free_next_beacon(link_data);
4245 return err;
4246 }
4247
4248 break;
4249 case NL80211_IFTYPE_ADHOC:
4250 if (!sdata->vif.cfg.ibss_joined)
4251 return -EINVAL;
4252
4253 if (params->chandef.width != sdata->u.ibss.chandef.width)
4254 return -EINVAL;
4255
4256 switch (params->chandef.width) {
4257 case NL80211_CHAN_WIDTH_40:
4258 if (cfg80211_get_chandef_type(¶ms->chandef) !=
4259 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
4260 return -EINVAL;
4261 break;
4262 case NL80211_CHAN_WIDTH_5:
4263 case NL80211_CHAN_WIDTH_10:
4264 case NL80211_CHAN_WIDTH_20_NOHT:
4265 case NL80211_CHAN_WIDTH_20:
4266 break;
4267 default:
4268 return -EINVAL;
4269 }
4270
4271 /* changes into another band are not supported */
4272 if (sdata->u.ibss.chandef.chan->band !=
4273 params->chandef.chan->band)
4274 return -EINVAL;
4275
4276 /* see comments in the NL80211_IFTYPE_AP block */
4277 if (params->count > 1) {
4278 err = ieee80211_ibss_csa_beacon(sdata, params, changed);
4279 if (err < 0)
4280 return err;
4281 }
4282
4283 ieee80211_send_action_csa(sdata, params);
4284
4285 break;
4286 #ifdef CONFIG_MAC80211_MESH
4287 case NL80211_IFTYPE_MESH_POINT: {
4288 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
4289
4290 /* changes into another band are not supported */
4291 if (sdata->vif.bss_conf.chanreq.oper.chan->band !=
4292 params->chandef.chan->band)
4293 return -EINVAL;
4294
4295 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
4296 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
4297 if (!ifmsh->pre_value)
4298 ifmsh->pre_value = 1;
4299 else
4300 ifmsh->pre_value++;
4301 }
4302
4303 /* see comments in the NL80211_IFTYPE_AP block */
4304 if (params->count > 1) {
4305 err = ieee80211_mesh_csa_beacon(sdata, params, changed);
4306 if (err < 0) {
4307 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
4308 return err;
4309 }
4310 }
4311
4312 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
4313 ieee80211_send_action_csa(sdata, params);
4314
4315 break;
4316 }
4317 #endif
4318 default:
4319 return -EOPNOTSUPP;
4320 }
4321
4322 return 0;
4323 }
4324
ieee80211_color_change_abort(struct ieee80211_link_data * link)4325 static void ieee80211_color_change_abort(struct ieee80211_link_data *link)
4326 {
4327 link->conf->color_change_active = false;
4328
4329 ieee80211_free_next_beacon(link);
4330
4331 cfg80211_color_change_aborted_notify(link->sdata->dev, link->link_id);
4332 }
4333
4334 static int
__ieee80211_channel_switch(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_csa_settings * params)4335 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
4336 struct cfg80211_csa_settings *params)
4337 {
4338 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4339 struct ieee80211_chan_req chanreq = { .oper = params->chandef };
4340 struct ieee80211_local *local = sdata->local;
4341 struct ieee80211_channel_switch ch_switch = {
4342 .link_id = params->link_id,
4343 };
4344 struct ieee80211_chanctx_conf *conf;
4345 struct ieee80211_chanctx *chanctx;
4346 struct ieee80211_bss_conf *link_conf;
4347 struct ieee80211_link_data *link_data;
4348 u64 changed = 0;
4349 u8 link_id = params->link_id;
4350 int err;
4351
4352 lockdep_assert_wiphy(local->hw.wiphy);
4353
4354 if (ieee80211_is_scan_ongoing(wiphy, local, ¶ms->chandef))
4355 return -EBUSY;
4356
4357 if (sdata->wdev.links[link_id].cac_started)
4358 return -EBUSY;
4359
4360 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
4361 return -EINVAL;
4362
4363 link_data = wiphy_dereference(wiphy, sdata->link[link_id]);
4364 if (!link_data)
4365 return -ENOLINK;
4366
4367 link_conf = link_data->conf;
4368
4369 if (chanreq.oper.punctured && !link_conf->eht_support)
4370 return -EINVAL;
4371
4372 /* don't allow another channel switch if one is already active. */
4373 if (link_conf->csa_active)
4374 return -EBUSY;
4375
4376 conf = wiphy_dereference(wiphy, link_conf->chanctx_conf);
4377 if (!conf) {
4378 err = -EBUSY;
4379 goto out;
4380 }
4381
4382 if (params->chandef.chan->freq_offset) {
4383 /* this may work, but is untested */
4384 err = -EOPNOTSUPP;
4385 goto out;
4386 }
4387
4388 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
4389 ¶ms->unsol_bcast_probe_resp,
4390 link_data, link_conf, &changed);
4391 if (err)
4392 goto out;
4393
4394 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
4395
4396 ch_switch.timestamp = 0;
4397 ch_switch.device_timestamp = 0;
4398 ch_switch.block_tx = params->block_tx;
4399 ch_switch.chandef = chanreq.oper;
4400 ch_switch.count = params->count;
4401
4402 err = drv_pre_channel_switch(sdata, &ch_switch);
4403 if (err)
4404 goto out;
4405
4406 err = ieee80211_link_reserve_chanctx(link_data, &chanreq,
4407 chanctx->mode,
4408 params->radar_required);
4409 if (err)
4410 goto out;
4411
4412 /* if reservation is invalid then this will fail */
4413 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0, -1);
4414 if (err) {
4415 ieee80211_link_unreserve_chanctx(link_data);
4416 goto out;
4417 }
4418
4419 /* if there is a color change in progress, abort it */
4420 if (link_conf->color_change_active)
4421 ieee80211_color_change_abort(link_data);
4422
4423 err = ieee80211_set_csa_beacon(link_data, params, &changed);
4424 if (err) {
4425 ieee80211_link_unreserve_chanctx(link_data);
4426 goto out;
4427 }
4428
4429 link_data->csa.chanreq = chanreq;
4430 link_conf->csa_active = true;
4431
4432 if (params->block_tx)
4433 ieee80211_vif_block_queues_csa(sdata);
4434
4435 cfg80211_ch_switch_started_notify(sdata->dev,
4436 &link_data->csa.chanreq.oper, link_id,
4437 params->count, params->block_tx);
4438
4439 if (changed) {
4440 ieee80211_link_info_change_notify(sdata, link_data, changed);
4441 drv_channel_switch_beacon(sdata, &link_data->csa.chanreq.oper);
4442 } else {
4443 /* if the beacon didn't change, we can finalize immediately */
4444 ieee80211_csa_finalize(link_data);
4445 }
4446
4447 out:
4448 return err;
4449 }
4450
ieee80211_channel_switch(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_csa_settings * params)4451 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
4452 struct cfg80211_csa_settings *params)
4453 {
4454 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4455 struct ieee80211_local *local = sdata->local;
4456
4457 lockdep_assert_wiphy(local->hw.wiphy);
4458
4459 return __ieee80211_channel_switch(wiphy, dev, params);
4460 }
4461
ieee80211_mgmt_tx_cookie(struct ieee80211_local * local)4462 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
4463 {
4464 lockdep_assert_wiphy(local->hw.wiphy);
4465
4466 local->roc_cookie_counter++;
4467
4468 /* wow, you wrapped 64 bits ... more likely a bug */
4469 if (WARN_ON(local->roc_cookie_counter == 0))
4470 local->roc_cookie_counter++;
4471
4472 return local->roc_cookie_counter;
4473 }
4474
ieee80211_attach_ack_skb(struct ieee80211_local * local,struct sk_buff * skb,u64 * cookie,gfp_t gfp)4475 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
4476 u64 *cookie, gfp_t gfp)
4477 {
4478 unsigned long spin_flags;
4479 struct sk_buff *ack_skb;
4480 int id;
4481
4482 ack_skb = skb_copy(skb, gfp);
4483 if (!ack_skb)
4484 return -ENOMEM;
4485
4486 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
4487 id = idr_alloc(&local->ack_status_frames, ack_skb,
4488 1, 0x2000, GFP_ATOMIC);
4489 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
4490
4491 if (id < 0) {
4492 kfree_skb(ack_skb);
4493 return -ENOMEM;
4494 }
4495
4496 IEEE80211_SKB_CB(skb)->status_data_idr = 1;
4497 IEEE80211_SKB_CB(skb)->status_data = id;
4498
4499 *cookie = ieee80211_mgmt_tx_cookie(local);
4500 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
4501
4502 return 0;
4503 }
4504
4505 static void
ieee80211_update_mgmt_frame_registrations(struct wiphy * wiphy,struct wireless_dev * wdev,struct mgmt_frame_regs * upd)4506 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
4507 struct wireless_dev *wdev,
4508 struct mgmt_frame_regs *upd)
4509 {
4510 struct ieee80211_local *local = wiphy_priv(wiphy);
4511 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4512 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
4513 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
4514 bool global_change, intf_change;
4515
4516 global_change =
4517 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
4518 (local->rx_mcast_action_reg !=
4519 !!(upd->global_mcast_stypes & action_mask));
4520 local->probe_req_reg = upd->global_stypes & preq_mask;
4521 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
4522
4523 intf_change = (sdata->vif.probe_req_reg !=
4524 !!(upd->interface_stypes & preq_mask)) ||
4525 (sdata->vif.rx_mcast_action_reg !=
4526 !!(upd->interface_mcast_stypes & action_mask));
4527 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
4528 sdata->vif.rx_mcast_action_reg =
4529 upd->interface_mcast_stypes & action_mask;
4530
4531 if (!local->open_count)
4532 return;
4533
4534 if (intf_change && ieee80211_sdata_running(sdata))
4535 drv_config_iface_filter(local, sdata,
4536 sdata->vif.probe_req_reg ?
4537 FIF_PROBE_REQ : 0,
4538 FIF_PROBE_REQ);
4539
4540 if (global_change)
4541 ieee80211_configure_filter(local);
4542 }
4543
ieee80211_set_antenna(struct wiphy * wiphy,int radio_idx,u32 tx_ant,u32 rx_ant)4544 static int ieee80211_set_antenna(struct wiphy *wiphy, int radio_idx,
4545 u32 tx_ant, u32 rx_ant)
4546 {
4547 struct ieee80211_local *local = wiphy_priv(wiphy);
4548 int ret;
4549
4550 if (local->started)
4551 return -EOPNOTSUPP;
4552
4553 ret = drv_set_antenna(local, tx_ant, rx_ant);
4554 if (ret)
4555 return ret;
4556
4557 local->rx_chains = hweight8(rx_ant);
4558 return 0;
4559 }
4560
ieee80211_get_antenna(struct wiphy * wiphy,int radio_idx,u32 * tx_ant,u32 * rx_ant)4561 static int ieee80211_get_antenna(struct wiphy *wiphy, int radio_idx,
4562 u32 *tx_ant, u32 *rx_ant)
4563 {
4564 struct ieee80211_local *local = wiphy_priv(wiphy);
4565
4566 return drv_get_antenna(local, radio_idx, tx_ant, rx_ant);
4567 }
4568
ieee80211_set_rekey_data(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_gtk_rekey_data * data)4569 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
4570 struct net_device *dev,
4571 struct cfg80211_gtk_rekey_data *data)
4572 {
4573 struct ieee80211_local *local = wiphy_priv(wiphy);
4574 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4575
4576 if (!local->ops->set_rekey_data)
4577 return -EOPNOTSUPP;
4578
4579 drv_set_rekey_data(local, sdata, data);
4580
4581 return 0;
4582 }
4583
ieee80211_probe_client(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u64 * cookie)4584 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
4585 const u8 *peer, u64 *cookie)
4586 {
4587 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4588 struct ieee80211_local *local = sdata->local;
4589 struct ieee80211_qos_hdr *nullfunc;
4590 struct sk_buff *skb;
4591 int size = sizeof(*nullfunc);
4592 __le16 fc;
4593 bool qos;
4594 struct ieee80211_tx_info *info;
4595 struct sta_info *sta;
4596 struct ieee80211_chanctx_conf *chanctx_conf;
4597 enum nl80211_band band;
4598 int ret;
4599
4600 /* the lock is needed to assign the cookie later */
4601 lockdep_assert_wiphy(local->hw.wiphy);
4602
4603 rcu_read_lock();
4604 sta = sta_info_get_bss(sdata, peer);
4605 if (!sta) {
4606 ret = -ENOLINK;
4607 goto unlock;
4608 }
4609
4610 qos = sta->sta.wme;
4611
4612 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
4613 if (WARN_ON(!chanctx_conf)) {
4614 ret = -EINVAL;
4615 goto unlock;
4616 }
4617 band = chanctx_conf->def.chan->band;
4618
4619 if (qos) {
4620 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4621 IEEE80211_STYPE_QOS_NULLFUNC |
4622 IEEE80211_FCTL_FROMDS);
4623 } else {
4624 size -= 2;
4625 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4626 IEEE80211_STYPE_NULLFUNC |
4627 IEEE80211_FCTL_FROMDS);
4628 }
4629
4630 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
4631 if (!skb) {
4632 ret = -ENOMEM;
4633 goto unlock;
4634 }
4635
4636 skb->dev = dev;
4637
4638 skb_reserve(skb, local->hw.extra_tx_headroom);
4639
4640 nullfunc = skb_put(skb, size);
4641 nullfunc->frame_control = fc;
4642 nullfunc->duration_id = 0;
4643 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
4644 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
4645 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
4646 nullfunc->seq_ctrl = 0;
4647
4648 info = IEEE80211_SKB_CB(skb);
4649
4650 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
4651 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
4652 info->band = band;
4653
4654 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
4655 skb->priority = 7;
4656 if (qos)
4657 nullfunc->qos_ctrl = cpu_to_le16(7);
4658
4659 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
4660 if (ret) {
4661 kfree_skb(skb);
4662 goto unlock;
4663 }
4664
4665 local_bh_disable();
4666 ieee80211_xmit(sdata, sta, skb);
4667 local_bh_enable();
4668
4669 ret = 0;
4670 unlock:
4671 rcu_read_unlock();
4672
4673 return ret;
4674 }
4675
ieee80211_cfg_get_channel(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id,struct cfg80211_chan_def * chandef)4676 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
4677 struct wireless_dev *wdev,
4678 unsigned int link_id,
4679 struct cfg80211_chan_def *chandef)
4680 {
4681 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4682 struct ieee80211_local *local = wiphy_priv(wiphy);
4683 struct ieee80211_chanctx_conf *chanctx_conf;
4684 struct ieee80211_link_data *link;
4685 int ret = -ENODATA;
4686
4687 rcu_read_lock();
4688 link = rcu_dereference(sdata->link[link_id]);
4689 if (!link) {
4690 ret = -ENOLINK;
4691 goto out;
4692 }
4693
4694 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
4695 if (chanctx_conf) {
4696 *chandef = link->conf->chanreq.oper;
4697 ret = 0;
4698 } else if (local->open_count > 0 &&
4699 local->open_count == local->virt_monitors &&
4700 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
4701 *chandef = local->monitor_chanreq.oper;
4702 ret = 0;
4703 }
4704 out:
4705 rcu_read_unlock();
4706
4707 return ret;
4708 }
4709
4710 #ifdef CONFIG_PM
ieee80211_set_wakeup(struct wiphy * wiphy,bool enabled)4711 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
4712 {
4713 drv_set_wakeup(wiphy_priv(wiphy), enabled);
4714 }
4715 #endif
4716
ieee80211_set_qos_map(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_qos_map * qos_map)4717 static int ieee80211_set_qos_map(struct wiphy *wiphy,
4718 struct net_device *dev,
4719 struct cfg80211_qos_map *qos_map)
4720 {
4721 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4722 struct mac80211_qos_map *new_qos_map, *old_qos_map;
4723
4724 if (qos_map) {
4725 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
4726 if (!new_qos_map)
4727 return -ENOMEM;
4728 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
4729 } else {
4730 /* A NULL qos_map was passed to disable QoS mapping */
4731 new_qos_map = NULL;
4732 }
4733
4734 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
4735 rcu_assign_pointer(sdata->qos_map, new_qos_map);
4736 if (old_qos_map)
4737 kfree_rcu(old_qos_map, rcu_head);
4738
4739 return 0;
4740 }
4741
ieee80211_set_ap_chanwidth(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id,struct cfg80211_chan_def * chandef)4742 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
4743 struct net_device *dev,
4744 unsigned int link_id,
4745 struct cfg80211_chan_def *chandef)
4746 {
4747 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4748 struct ieee80211_link_data *link;
4749 struct ieee80211_chan_req chanreq = { .oper = *chandef };
4750 int ret;
4751 u64 changed = 0;
4752
4753 link = sdata_dereference(sdata->link[link_id], sdata);
4754
4755 ret = ieee80211_link_change_chanreq(link, &chanreq, &changed);
4756 if (ret == 0)
4757 ieee80211_link_info_change_notify(sdata, link, changed);
4758
4759 return ret;
4760 }
4761
ieee80211_add_tx_ts(struct wiphy * wiphy,struct net_device * dev,u8 tsid,const u8 * peer,u8 up,u16 admitted_time)4762 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4763 u8 tsid, const u8 *peer, u8 up,
4764 u16 admitted_time)
4765 {
4766 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4767 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4768 int ac = ieee802_1d_to_ac[up];
4769
4770 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4771 return -EOPNOTSUPP;
4772
4773 if (!(sdata->wmm_acm & BIT(up)))
4774 return -EINVAL;
4775
4776 if (ifmgd->tx_tspec[ac].admitted_time)
4777 return -EBUSY;
4778
4779 if (admitted_time) {
4780 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4781 ifmgd->tx_tspec[ac].tsid = tsid;
4782 ifmgd->tx_tspec[ac].up = up;
4783 }
4784
4785 return 0;
4786 }
4787
ieee80211_del_tx_ts(struct wiphy * wiphy,struct net_device * dev,u8 tsid,const u8 * peer)4788 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4789 u8 tsid, const u8 *peer)
4790 {
4791 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4792 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4793 struct ieee80211_local *local = wiphy_priv(wiphy);
4794 int ac;
4795
4796 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4797 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4798
4799 /* skip unused entries */
4800 if (!tx_tspec->admitted_time)
4801 continue;
4802
4803 if (tx_tspec->tsid != tsid)
4804 continue;
4805
4806 /* due to this new packets will be reassigned to non-ACM ACs */
4807 tx_tspec->up = -1;
4808
4809 /* Make sure that all packets have been sent to avoid to
4810 * restore the QoS params on packets that are still on the
4811 * queues.
4812 */
4813 synchronize_net();
4814 ieee80211_flush_queues(local, sdata, false);
4815
4816 /* restore the normal QoS parameters
4817 * (unconditionally to avoid races)
4818 */
4819 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4820 tx_tspec->downgraded = false;
4821 ieee80211_sta_handle_tspec_ac_params(sdata);
4822
4823 /* finally clear all the data */
4824 memset(tx_tspec, 0, sizeof(*tx_tspec));
4825
4826 return 0;
4827 }
4828
4829 return -ENOENT;
4830 }
4831
ieee80211_nan_func_terminated(struct ieee80211_vif * vif,u8 inst_id,enum nl80211_nan_func_term_reason reason,gfp_t gfp)4832 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4833 u8 inst_id,
4834 enum nl80211_nan_func_term_reason reason,
4835 gfp_t gfp)
4836 {
4837 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4838 struct cfg80211_nan_func *func;
4839 u64 cookie;
4840
4841 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4842 return;
4843
4844 spin_lock_bh(&sdata->u.nan.func_lock);
4845
4846 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4847 if (WARN_ON(!func)) {
4848 spin_unlock_bh(&sdata->u.nan.func_lock);
4849 return;
4850 }
4851
4852 cookie = func->cookie;
4853 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4854
4855 spin_unlock_bh(&sdata->u.nan.func_lock);
4856
4857 cfg80211_free_nan_func(func);
4858
4859 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4860 reason, cookie, gfp);
4861 }
4862 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4863
ieee80211_nan_func_match(struct ieee80211_vif * vif,struct cfg80211_nan_match_params * match,gfp_t gfp)4864 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4865 struct cfg80211_nan_match_params *match,
4866 gfp_t gfp)
4867 {
4868 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4869 struct cfg80211_nan_func *func;
4870
4871 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4872 return;
4873
4874 spin_lock_bh(&sdata->u.nan.func_lock);
4875
4876 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
4877 if (WARN_ON(!func)) {
4878 spin_unlock_bh(&sdata->u.nan.func_lock);
4879 return;
4880 }
4881 match->cookie = func->cookie;
4882
4883 spin_unlock_bh(&sdata->u.nan.func_lock);
4884
4885 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4886 }
4887 EXPORT_SYMBOL(ieee80211_nan_func_match);
4888
ieee80211_set_multicast_to_unicast(struct wiphy * wiphy,struct net_device * dev,const bool enabled)4889 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4890 struct net_device *dev,
4891 const bool enabled)
4892 {
4893 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4894
4895 sdata->u.ap.multicast_to_unicast = enabled;
4896
4897 return 0;
4898 }
4899
ieee80211_fill_txq_stats(struct cfg80211_txq_stats * txqstats,struct txq_info * txqi)4900 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4901 struct txq_info *txqi)
4902 {
4903 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4904 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4905 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4906 }
4907
4908 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4909 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4910 txqstats->backlog_packets = txqi->tin.backlog_packets;
4911 }
4912
4913 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4914 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4915 txqstats->flows = txqi->tin.flows;
4916 }
4917
4918 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4919 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4920 txqstats->drops = txqi->cstats.drop_count;
4921 }
4922
4923 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4924 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4925 txqstats->ecn_marks = txqi->cstats.ecn_mark;
4926 }
4927
4928 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4929 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4930 txqstats->overlimit = txqi->tin.overlimit;
4931 }
4932
4933 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4934 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4935 txqstats->collisions = txqi->tin.collisions;
4936 }
4937
4938 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4939 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4940 txqstats->tx_bytes = txqi->tin.tx_bytes;
4941 }
4942
4943 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4944 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4945 txqstats->tx_packets = txqi->tin.tx_packets;
4946 }
4947 }
4948
ieee80211_get_txq_stats(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_txq_stats * txqstats)4949 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4950 struct wireless_dev *wdev,
4951 struct cfg80211_txq_stats *txqstats)
4952 {
4953 struct ieee80211_local *local = wiphy_priv(wiphy);
4954 struct ieee80211_sub_if_data *sdata;
4955 int ret = 0;
4956
4957 spin_lock_bh(&local->fq.lock);
4958
4959 if (wdev) {
4960 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4961 if (!sdata->vif.txq) {
4962 ret = 1;
4963 goto out;
4964 }
4965 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4966 } else {
4967 /* phy stats */
4968 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4969 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4970 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4971 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4972 BIT(NL80211_TXQ_STATS_COLLISIONS) |
4973 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4974 txqstats->backlog_packets = local->fq.backlog;
4975 txqstats->backlog_bytes = local->fq.memory_usage;
4976 txqstats->overlimit = local->fq.overlimit;
4977 txqstats->overmemory = local->fq.overmemory;
4978 txqstats->collisions = local->fq.collisions;
4979 txqstats->max_flows = local->fq.flows_cnt;
4980 }
4981
4982 out:
4983 spin_unlock_bh(&local->fq.lock);
4984
4985 return ret;
4986 }
4987
4988 static int
ieee80211_get_ftm_responder_stats(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ftm_responder_stats * ftm_stats)4989 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4990 struct net_device *dev,
4991 struct cfg80211_ftm_responder_stats *ftm_stats)
4992 {
4993 struct ieee80211_local *local = wiphy_priv(wiphy);
4994 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4995
4996 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4997 }
4998
4999 static int
ieee80211_start_pmsr(struct wiphy * wiphy,struct wireless_dev * dev,struct cfg80211_pmsr_request * request)5000 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
5001 struct cfg80211_pmsr_request *request)
5002 {
5003 struct ieee80211_local *local = wiphy_priv(wiphy);
5004 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
5005
5006 return drv_start_pmsr(local, sdata, request);
5007 }
5008
5009 static void
ieee80211_abort_pmsr(struct wiphy * wiphy,struct wireless_dev * dev,struct cfg80211_pmsr_request * request)5010 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
5011 struct cfg80211_pmsr_request *request)
5012 {
5013 struct ieee80211_local *local = wiphy_priv(wiphy);
5014 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
5015
5016 return drv_abort_pmsr(local, sdata, request);
5017 }
5018
ieee80211_set_tid_config(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_tid_config * tid_conf)5019 static int ieee80211_set_tid_config(struct wiphy *wiphy,
5020 struct net_device *dev,
5021 struct cfg80211_tid_config *tid_conf)
5022 {
5023 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5024 struct sta_info *sta;
5025
5026 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5027
5028 if (!sdata->local->ops->set_tid_config)
5029 return -EOPNOTSUPP;
5030
5031 if (!tid_conf->peer)
5032 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
5033
5034 sta = sta_info_get_bss(sdata, tid_conf->peer);
5035 if (!sta)
5036 return -ENOENT;
5037
5038 return drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
5039 }
5040
ieee80211_reset_tid_config(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u8 tids)5041 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
5042 struct net_device *dev,
5043 const u8 *peer, u8 tids)
5044 {
5045 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5046 struct sta_info *sta;
5047
5048 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5049
5050 if (!sdata->local->ops->reset_tid_config)
5051 return -EOPNOTSUPP;
5052
5053 if (!peer)
5054 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
5055
5056 sta = sta_info_get_bss(sdata, peer);
5057 if (!sta)
5058 return -ENOENT;
5059
5060 return drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
5061 }
5062
ieee80211_set_sar_specs(struct wiphy * wiphy,struct cfg80211_sar_specs * sar)5063 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
5064 struct cfg80211_sar_specs *sar)
5065 {
5066 struct ieee80211_local *local = wiphy_priv(wiphy);
5067
5068 if (!local->ops->set_sar_specs)
5069 return -EOPNOTSUPP;
5070
5071 return local->ops->set_sar_specs(&local->hw, sar);
5072 }
5073
5074 static int
ieee80211_set_after_color_change_beacon(struct ieee80211_link_data * link,u64 * changed)5075 ieee80211_set_after_color_change_beacon(struct ieee80211_link_data *link,
5076 u64 *changed)
5077 {
5078 struct ieee80211_sub_if_data *sdata = link->sdata;
5079
5080 switch (sdata->vif.type) {
5081 case NL80211_IFTYPE_AP: {
5082 int ret;
5083
5084 if (!link->u.ap.next_beacon)
5085 return -EINVAL;
5086
5087 ret = ieee80211_assign_beacon(sdata, link,
5088 link->u.ap.next_beacon,
5089 NULL, NULL, changed);
5090 ieee80211_free_next_beacon(link);
5091
5092 if (ret < 0)
5093 return ret;
5094
5095 break;
5096 }
5097 default:
5098 WARN_ON_ONCE(1);
5099 return -EINVAL;
5100 }
5101
5102 return 0;
5103 }
5104
5105 static int
ieee80211_set_color_change_beacon(struct ieee80211_link_data * link,struct cfg80211_color_change_settings * params,u64 * changed)5106 ieee80211_set_color_change_beacon(struct ieee80211_link_data *link,
5107 struct cfg80211_color_change_settings *params,
5108 u64 *changed)
5109 {
5110 struct ieee80211_sub_if_data *sdata = link->sdata;
5111 struct ieee80211_color_change_settings color_change = {};
5112 int err;
5113
5114 switch (sdata->vif.type) {
5115 case NL80211_IFTYPE_AP:
5116 link->u.ap.next_beacon =
5117 cfg80211_beacon_dup(¶ms->beacon_next);
5118 if (!link->u.ap.next_beacon)
5119 return -ENOMEM;
5120
5121 if (params->count <= 1)
5122 break;
5123
5124 color_change.counter_offset_beacon =
5125 params->counter_offset_beacon;
5126 color_change.counter_offset_presp =
5127 params->counter_offset_presp;
5128 color_change.count = params->count;
5129
5130 err = ieee80211_assign_beacon(sdata, link,
5131 ¶ms->beacon_color_change,
5132 NULL, &color_change, changed);
5133 if (err < 0) {
5134 ieee80211_free_next_beacon(link);
5135 return err;
5136 }
5137 break;
5138 default:
5139 return -EOPNOTSUPP;
5140 }
5141
5142 return 0;
5143 }
5144
5145 static void
ieee80211_color_change_bss_config_notify(struct ieee80211_link_data * link,u8 color,int enable,u64 changed)5146 ieee80211_color_change_bss_config_notify(struct ieee80211_link_data *link,
5147 u8 color, int enable, u64 changed)
5148 {
5149 struct ieee80211_sub_if_data *sdata = link->sdata;
5150
5151 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5152
5153 link->conf->he_bss_color.color = color;
5154 link->conf->he_bss_color.enabled = enable;
5155 changed |= BSS_CHANGED_HE_BSS_COLOR;
5156
5157 ieee80211_link_info_change_notify(sdata, link, changed);
5158
5159 if (!link->conf->nontransmitted &&
5160 rcu_access_pointer(link->conf->tx_bss_conf)) {
5161 struct ieee80211_link_data *tmp;
5162
5163 for_each_sdata_link(sdata->local, tmp) {
5164 if (tmp->sdata == sdata ||
5165 rcu_access_pointer(tmp->conf->tx_bss_conf) != link->conf)
5166 continue;
5167
5168 tmp->conf->he_bss_color.color = color;
5169 tmp->conf->he_bss_color.enabled = enable;
5170 ieee80211_link_info_change_notify(tmp->sdata, tmp,
5171 BSS_CHANGED_HE_BSS_COLOR);
5172 }
5173 }
5174 }
5175
ieee80211_color_change_finalize(struct ieee80211_link_data * link)5176 static int ieee80211_color_change_finalize(struct ieee80211_link_data *link)
5177 {
5178 struct ieee80211_sub_if_data *sdata = link->sdata;
5179 struct ieee80211_local *local = sdata->local;
5180 u64 changed = 0;
5181 int err;
5182
5183 lockdep_assert_wiphy(local->hw.wiphy);
5184
5185 link->conf->color_change_active = false;
5186
5187 err = ieee80211_set_after_color_change_beacon(link, &changed);
5188 if (err) {
5189 cfg80211_color_change_aborted_notify(sdata->dev, link->link_id);
5190 return err;
5191 }
5192
5193 ieee80211_color_change_bss_config_notify(link,
5194 link->conf->color_change_color,
5195 1, changed);
5196 cfg80211_color_change_notify(sdata->dev, link->link_id);
5197
5198 return 0;
5199 }
5200
ieee80211_color_change_finalize_work(struct wiphy * wiphy,struct wiphy_work * work)5201 void ieee80211_color_change_finalize_work(struct wiphy *wiphy,
5202 struct wiphy_work *work)
5203 {
5204 struct ieee80211_link_data *link =
5205 container_of(work, struct ieee80211_link_data,
5206 color_change_finalize_work);
5207 struct ieee80211_sub_if_data *sdata = link->sdata;
5208 struct ieee80211_bss_conf *link_conf = link->conf;
5209 struct ieee80211_local *local = sdata->local;
5210
5211 lockdep_assert_wiphy(local->hw.wiphy);
5212
5213 /* AP might have been stopped while waiting for the lock. */
5214 if (!link_conf->color_change_active)
5215 return;
5216
5217 if (!ieee80211_sdata_running(sdata))
5218 return;
5219
5220 ieee80211_color_change_finalize(link);
5221 }
5222
ieee80211_color_collision_detection_work(struct wiphy * wiphy,struct wiphy_work * work)5223 void ieee80211_color_collision_detection_work(struct wiphy *wiphy,
5224 struct wiphy_work *work)
5225 {
5226 struct ieee80211_link_data *link =
5227 container_of(work, struct ieee80211_link_data,
5228 color_collision_detect_work.work);
5229 struct ieee80211_sub_if_data *sdata = link->sdata;
5230
5231 cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap,
5232 link->link_id);
5233 }
5234
ieee80211_color_change_finish(struct ieee80211_vif * vif,u8 link_id)5235 void ieee80211_color_change_finish(struct ieee80211_vif *vif, u8 link_id)
5236 {
5237 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5238 struct ieee80211_link_data *link;
5239
5240 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5241 return;
5242
5243 rcu_read_lock();
5244
5245 link = rcu_dereference(sdata->link[link_id]);
5246 if (WARN_ON(!link)) {
5247 rcu_read_unlock();
5248 return;
5249 }
5250
5251 wiphy_work_queue(sdata->local->hw.wiphy,
5252 &link->color_change_finalize_work);
5253
5254 rcu_read_unlock();
5255 }
5256 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
5257
5258 void
ieee80211_obss_color_collision_notify(struct ieee80211_vif * vif,u64 color_bitmap,u8 link_id)5259 ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
5260 u64 color_bitmap, u8 link_id)
5261 {
5262 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5263 struct ieee80211_link_data *link;
5264
5265 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5266 return;
5267
5268 rcu_read_lock();
5269
5270 link = rcu_dereference(sdata->link[link_id]);
5271 if (WARN_ON(!link)) {
5272 rcu_read_unlock();
5273 return;
5274 }
5275
5276 if (link->conf->color_change_active || link->conf->csa_active) {
5277 rcu_read_unlock();
5278 return;
5279 }
5280
5281 if (wiphy_delayed_work_pending(sdata->local->hw.wiphy,
5282 &link->color_collision_detect_work)) {
5283 rcu_read_unlock();
5284 return;
5285 }
5286
5287 link->color_bitmap = color_bitmap;
5288 /* queue the color collision detection event every 500 ms in order to
5289 * avoid sending too much netlink messages to userspace.
5290 */
5291 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
5292 &link->color_collision_detect_work,
5293 msecs_to_jiffies(500));
5294
5295 rcu_read_unlock();
5296 }
5297 EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify);
5298
5299 static int
ieee80211_color_change(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_color_change_settings * params)5300 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
5301 struct cfg80211_color_change_settings *params)
5302 {
5303 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5304 struct ieee80211_local *local = sdata->local;
5305 struct ieee80211_bss_conf *link_conf;
5306 struct ieee80211_link_data *link;
5307 u8 link_id = params->link_id;
5308 u64 changed = 0;
5309 int err;
5310
5311 lockdep_assert_wiphy(local->hw.wiphy);
5312
5313 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5314 return -EINVAL;
5315
5316 link = wiphy_dereference(wiphy, sdata->link[link_id]);
5317 if (!link)
5318 return -ENOLINK;
5319
5320 link_conf = link->conf;
5321
5322 if (link_conf->nontransmitted)
5323 return -EINVAL;
5324
5325 /* don't allow another color change if one is already active or if csa
5326 * is active
5327 */
5328 if (link_conf->color_change_active || link_conf->csa_active) {
5329 err = -EBUSY;
5330 goto out;
5331 }
5332
5333 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
5334 ¶ms->unsol_bcast_probe_resp,
5335 link, link_conf, &changed);
5336 if (err)
5337 goto out;
5338
5339 err = ieee80211_set_color_change_beacon(link, params, &changed);
5340 if (err)
5341 goto out;
5342
5343 link_conf->color_change_active = true;
5344 link_conf->color_change_color = params->color;
5345
5346 cfg80211_color_change_started_notify(sdata->dev, params->count, link_id);
5347
5348 if (changed)
5349 ieee80211_color_change_bss_config_notify(link, 0, 0, changed);
5350 else
5351 /* if the beacon didn't change, we can finalize immediately */
5352 ieee80211_color_change_finalize(link);
5353
5354 out:
5355
5356 return err;
5357 }
5358
5359 static int
ieee80211_set_radar_background(struct wiphy * wiphy,struct cfg80211_chan_def * chandef)5360 ieee80211_set_radar_background(struct wiphy *wiphy,
5361 struct cfg80211_chan_def *chandef)
5362 {
5363 struct ieee80211_local *local = wiphy_priv(wiphy);
5364
5365 if (!local->ops->set_radar_background)
5366 return -EOPNOTSUPP;
5367
5368 return local->ops->set_radar_background(&local->hw, chandef);
5369 }
5370
ieee80211_add_intf_link(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id)5371 static int ieee80211_add_intf_link(struct wiphy *wiphy,
5372 struct wireless_dev *wdev,
5373 unsigned int link_id)
5374 {
5375 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
5376
5377 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5378
5379 if (wdev->use_4addr)
5380 return -EOPNOTSUPP;
5381
5382 return ieee80211_vif_set_links(sdata, wdev->valid_links, 0);
5383 }
5384
ieee80211_del_intf_link(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id)5385 static void ieee80211_del_intf_link(struct wiphy *wiphy,
5386 struct wireless_dev *wdev,
5387 unsigned int link_id)
5388 {
5389 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
5390 u16 new_links = wdev->valid_links & ~BIT(link_id);
5391
5392 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5393
5394 /* During the link teardown process, certain functions require the
5395 * link_id to remain in the valid_links bitmap. Therefore, instead
5396 * of removing the link_id from the bitmap, pass a masked value to
5397 * simulate as if link_id does not exist anymore.
5398 */
5399 ieee80211_vif_set_links(sdata, new_links, 0);
5400 }
5401
5402 static int
ieee80211_add_link_station(struct wiphy * wiphy,struct net_device * dev,struct link_station_parameters * params)5403 ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev,
5404 struct link_station_parameters *params)
5405 {
5406 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5407 struct ieee80211_local *local = wiphy_priv(wiphy);
5408 struct sta_info *sta;
5409 int ret;
5410
5411 lockdep_assert_wiphy(local->hw.wiphy);
5412
5413 sta = sta_info_get_bss(sdata, params->mld_mac);
5414 if (!sta)
5415 return -ENOENT;
5416
5417 if (!sta->sta.valid_links)
5418 return -EINVAL;
5419
5420 if (sta->sta.valid_links & BIT(params->link_id))
5421 return -EALREADY;
5422
5423 ret = ieee80211_sta_allocate_link(sta, params->link_id);
5424 if (ret)
5425 return ret;
5426
5427 ret = sta_link_apply_parameters(local, sta, STA_LINK_MODE_NEW, params);
5428 if (ret) {
5429 ieee80211_sta_free_link(sta, params->link_id);
5430 return ret;
5431 }
5432
5433 if (test_sta_flag(sta, WLAN_STA_ASSOC)) {
5434 struct link_sta_info *link_sta;
5435
5436 link_sta = sdata_dereference(sta->link[params->link_id], sdata);
5437 rate_control_rate_init(link_sta);
5438 }
5439
5440 /* ieee80211_sta_activate_link frees the link upon failure */
5441 return ieee80211_sta_activate_link(sta, params->link_id);
5442 }
5443
5444 static int
ieee80211_mod_link_station(struct wiphy * wiphy,struct net_device * dev,struct link_station_parameters * params)5445 ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev,
5446 struct link_station_parameters *params)
5447 {
5448 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5449 struct ieee80211_local *local = wiphy_priv(wiphy);
5450 struct sta_info *sta;
5451
5452 lockdep_assert_wiphy(local->hw.wiphy);
5453
5454 sta = sta_info_get_bss(sdata, params->mld_mac);
5455 if (!sta)
5456 return -ENOENT;
5457
5458 if (!(sta->sta.valid_links & BIT(params->link_id)))
5459 return -EINVAL;
5460
5461 return sta_link_apply_parameters(local, sta, STA_LINK_MODE_LINK_MODIFY,
5462 params);
5463 }
5464
5465 static int
ieee80211_del_link_station(struct wiphy * wiphy,struct net_device * dev,struct link_station_del_parameters * params)5466 ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev,
5467 struct link_station_del_parameters *params)
5468 {
5469 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5470 struct sta_info *sta;
5471
5472 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5473
5474 sta = sta_info_get_bss(sdata, params->mld_mac);
5475 if (!sta)
5476 return -ENOENT;
5477
5478 if (!(sta->sta.valid_links & BIT(params->link_id)))
5479 return -EINVAL;
5480
5481 /* must not create a STA without links */
5482 if (sta->sta.valid_links == BIT(params->link_id))
5483 return -EINVAL;
5484
5485 ieee80211_sta_remove_link(sta, params->link_id);
5486
5487 return 0;
5488 }
5489
ieee80211_set_hw_timestamp(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_set_hw_timestamp * hwts)5490 static int ieee80211_set_hw_timestamp(struct wiphy *wiphy,
5491 struct net_device *dev,
5492 struct cfg80211_set_hw_timestamp *hwts)
5493 {
5494 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5495 struct ieee80211_local *local = sdata->local;
5496
5497 if (!local->ops->set_hw_timestamp)
5498 return -EOPNOTSUPP;
5499
5500 if (!check_sdata_in_driver(sdata))
5501 return -EIO;
5502
5503 return local->ops->set_hw_timestamp(&local->hw, &sdata->vif, hwts);
5504 }
5505
5506 static int
ieee80211_set_ttlm(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ttlm_params * params)5507 ieee80211_set_ttlm(struct wiphy *wiphy, struct net_device *dev,
5508 struct cfg80211_ttlm_params *params)
5509 {
5510 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5511
5512 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5513
5514 return ieee80211_req_neg_ttlm(sdata, params);
5515 }
5516
5517 static int
ieee80211_assoc_ml_reconf(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ml_reconf_req * req)5518 ieee80211_assoc_ml_reconf(struct wiphy *wiphy, struct net_device *dev,
5519 struct cfg80211_ml_reconf_req *req)
5520 {
5521 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5522
5523 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5524
5525 return ieee80211_mgd_assoc_ml_reconf(sdata, req);
5526 }
5527
5528 static int
ieee80211_set_epcs(struct wiphy * wiphy,struct net_device * dev,bool enable)5529 ieee80211_set_epcs(struct wiphy *wiphy, struct net_device *dev, bool enable)
5530 {
5531 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5532
5533 return ieee80211_mgd_set_epcs(sdata, enable);
5534 }
5535
5536 const struct cfg80211_ops mac80211_config_ops = {
5537 .add_virtual_intf = ieee80211_add_iface,
5538 .del_virtual_intf = ieee80211_del_iface,
5539 .change_virtual_intf = ieee80211_change_iface,
5540 .start_p2p_device = ieee80211_start_p2p_device,
5541 .stop_p2p_device = ieee80211_stop_p2p_device,
5542 .add_key = ieee80211_add_key,
5543 .del_key = ieee80211_del_key,
5544 .get_key = ieee80211_get_key,
5545 .set_default_key = ieee80211_config_default_key,
5546 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
5547 .set_default_beacon_key = ieee80211_config_default_beacon_key,
5548 .start_ap = ieee80211_start_ap,
5549 .change_beacon = ieee80211_change_beacon,
5550 .stop_ap = ieee80211_stop_ap,
5551 .add_station = ieee80211_add_station,
5552 .del_station = ieee80211_del_station,
5553 .change_station = ieee80211_change_station,
5554 .get_station = ieee80211_get_station,
5555 .dump_station = ieee80211_dump_station,
5556 .dump_survey = ieee80211_dump_survey,
5557 #ifdef CONFIG_MAC80211_MESH
5558 .add_mpath = ieee80211_add_mpath,
5559 .del_mpath = ieee80211_del_mpath,
5560 .change_mpath = ieee80211_change_mpath,
5561 .get_mpath = ieee80211_get_mpath,
5562 .dump_mpath = ieee80211_dump_mpath,
5563 .get_mpp = ieee80211_get_mpp,
5564 .dump_mpp = ieee80211_dump_mpp,
5565 .update_mesh_config = ieee80211_update_mesh_config,
5566 .get_mesh_config = ieee80211_get_mesh_config,
5567 .join_mesh = ieee80211_join_mesh,
5568 .leave_mesh = ieee80211_leave_mesh,
5569 #endif
5570 .join_ocb = ieee80211_join_ocb,
5571 .leave_ocb = ieee80211_leave_ocb,
5572 .change_bss = ieee80211_change_bss,
5573 .inform_bss = ieee80211_inform_bss,
5574 .set_txq_params = ieee80211_set_txq_params,
5575 .set_monitor_channel = ieee80211_set_monitor_channel,
5576 .suspend = ieee80211_suspend,
5577 .resume = ieee80211_resume,
5578 .scan = ieee80211_scan,
5579 .abort_scan = ieee80211_abort_scan,
5580 .sched_scan_start = ieee80211_sched_scan_start,
5581 .sched_scan_stop = ieee80211_sched_scan_stop,
5582 .auth = ieee80211_auth,
5583 .assoc = ieee80211_assoc,
5584 .deauth = ieee80211_deauth,
5585 .disassoc = ieee80211_disassoc,
5586 .join_ibss = ieee80211_join_ibss,
5587 .leave_ibss = ieee80211_leave_ibss,
5588 .set_mcast_rate = ieee80211_set_mcast_rate,
5589 .set_wiphy_params = ieee80211_set_wiphy_params,
5590 .set_tx_power = ieee80211_set_tx_power,
5591 .get_tx_power = ieee80211_get_tx_power,
5592 .rfkill_poll = ieee80211_rfkill_poll,
5593 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
5594 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
5595 .set_power_mgmt = ieee80211_set_power_mgmt,
5596 .set_bitrate_mask = ieee80211_set_bitrate_mask,
5597 .remain_on_channel = ieee80211_remain_on_channel,
5598 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
5599 .mgmt_tx = ieee80211_mgmt_tx,
5600 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
5601 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
5602 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
5603 .update_mgmt_frame_registrations =
5604 ieee80211_update_mgmt_frame_registrations,
5605 .set_antenna = ieee80211_set_antenna,
5606 .get_antenna = ieee80211_get_antenna,
5607 .set_rekey_data = ieee80211_set_rekey_data,
5608 .tdls_oper = ieee80211_tdls_oper,
5609 .tdls_mgmt = ieee80211_tdls_mgmt,
5610 .tdls_channel_switch = ieee80211_tdls_channel_switch,
5611 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
5612 .probe_client = ieee80211_probe_client,
5613 .set_noack_map = ieee80211_set_noack_map,
5614 #ifdef CONFIG_PM
5615 .set_wakeup = ieee80211_set_wakeup,
5616 #endif
5617 .get_channel = ieee80211_cfg_get_channel,
5618 .start_radar_detection = ieee80211_start_radar_detection,
5619 .end_cac = ieee80211_end_cac,
5620 .channel_switch = ieee80211_channel_switch,
5621 .set_qos_map = ieee80211_set_qos_map,
5622 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
5623 .add_tx_ts = ieee80211_add_tx_ts,
5624 .del_tx_ts = ieee80211_del_tx_ts,
5625 .start_nan = ieee80211_start_nan,
5626 .stop_nan = ieee80211_stop_nan,
5627 .nan_change_conf = ieee80211_nan_change_conf,
5628 .add_nan_func = ieee80211_add_nan_func,
5629 .del_nan_func = ieee80211_del_nan_func,
5630 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
5631 .tx_control_port = ieee80211_tx_control_port,
5632 .get_txq_stats = ieee80211_get_txq_stats,
5633 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
5634 .start_pmsr = ieee80211_start_pmsr,
5635 .abort_pmsr = ieee80211_abort_pmsr,
5636 .probe_mesh_link = ieee80211_probe_mesh_link,
5637 .set_tid_config = ieee80211_set_tid_config,
5638 .reset_tid_config = ieee80211_reset_tid_config,
5639 .set_sar_specs = ieee80211_set_sar_specs,
5640 .color_change = ieee80211_color_change,
5641 .set_radar_background = ieee80211_set_radar_background,
5642 .add_intf_link = ieee80211_add_intf_link,
5643 .del_intf_link = ieee80211_del_intf_link,
5644 .add_link_station = ieee80211_add_link_station,
5645 .mod_link_station = ieee80211_mod_link_station,
5646 .del_link_station = ieee80211_del_link_station,
5647 .set_hw_timestamp = ieee80211_set_hw_timestamp,
5648 .set_ttlm = ieee80211_set_ttlm,
5649 .get_radio_mask = ieee80211_get_radio_mask,
5650 .assoc_ml_reconf = ieee80211_assoc_ml_reconf,
5651 .set_epcs = ieee80211_set_epcs,
5652 };
5653