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