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