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 ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab,
2348 params->ext_capab_len);
2349
2350 /*
2351 * cfg80211 validates this (1-2007) and allows setting the AID
2352 * only when creating a new station entry. For S1G APs, the current
2353 * implementation supports a maximum of 1600 AIDs.
2354 */
2355 if (params->aid) {
2356 if (sdata->vif.cfg.s1g &&
2357 params->aid > IEEE80211_MAX_SUPPORTED_S1G_AID)
2358 return -EINVAL;
2359
2360 sta->sta.aid = params->aid;
2361 }
2362
2363 /*
2364 * Some of the following updates would be racy if called on an
2365 * existing station, via ieee80211_change_station(). However,
2366 * all such changes are rejected by cfg80211 except for updates
2367 * changing the supported rates on an existing but not yet used
2368 * TDLS peer.
2369 */
2370
2371 if (params->listen_interval >= 0)
2372 sta->listen_interval = params->listen_interval;
2373
2374 if (params->eml_cap_present)
2375 sta->sta.eml_cap = params->eml_cap;
2376
2377 ret = sta_link_apply_parameters(local, sta, STA_LINK_MODE_STA_MODIFY,
2378 ¶ms->link_sta_params);
2379 if (ret)
2380 return ret;
2381
2382 if (params->support_p2p_ps >= 0)
2383 sta->sta.support_p2p_ps = params->support_p2p_ps;
2384
2385 if (ieee80211_vif_is_mesh(&sdata->vif))
2386 sta_apply_mesh_params(local, sta, params);
2387
2388 if (params->airtime_weight)
2389 sta->airtime_weight = params->airtime_weight;
2390
2391 if (params->nmi_mac) {
2392 struct ieee80211_sub_if_data *nmi =
2393 rcu_dereference_wiphy(local->hw.wiphy,
2394 sdata->u.nan_data.nmi);
2395 struct sta_info *nmi_sta;
2396
2397 if (WARN_ON(!nmi))
2398 return -EINVAL;
2399
2400 nmi_sta = sta_info_get(nmi, params->nmi_mac);
2401 if (!nmi_sta)
2402 return -ENOENT;
2403 rcu_assign_pointer(sta->sta.nmi, &nmi_sta->sta);
2404
2405 /* For NAN_DATA stations, copy capabilities from the NMI station */
2406 if (!nmi_sta->deflink.pub->ht_cap.ht_supported)
2407 return -EINVAL;
2408
2409 sta->deflink.pub->ht_cap = nmi_sta->deflink.pub->ht_cap;
2410 sta->deflink.pub->vht_cap = nmi_sta->deflink.pub->vht_cap;
2411 sta->deflink.pub->he_cap = nmi_sta->deflink.pub->he_cap;
2412 memcpy(&sta->deflink.pub->supp_rates,
2413 &nmi_sta->deflink.pub->supp_rates,
2414 sizeof(sta->deflink.pub->supp_rates));
2415 }
2416
2417 /* set the STA state after all sta info from usermode has been set */
2418 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
2419 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
2420 ret = sta_apply_auth_flags(local, sta, mask, set);
2421 if (ret)
2422 return ret;
2423 }
2424
2425 /* Mark the STA as MLO if MLD MAC address is available */
2426 if (params->link_sta_params.mld_mac)
2427 sta->sta.mlo = true;
2428
2429 return 0;
2430 }
2431
ieee80211_add_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)2432 static int ieee80211_add_station(struct wiphy *wiphy, struct wireless_dev *wdev,
2433 const u8 *mac,
2434 struct station_parameters *params)
2435 {
2436 struct ieee80211_local *local = wiphy_priv(wiphy);
2437 struct sta_info *sta;
2438 struct ieee80211_sub_if_data *sdata;
2439 int err;
2440
2441 lockdep_assert_wiphy(local->hw.wiphy);
2442
2443 if (params->vlan) {
2444 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2445
2446 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2447 sdata->vif.type != NL80211_IFTYPE_AP)
2448 return -EINVAL;
2449 } else
2450 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2451
2452 if (ether_addr_equal(mac, sdata->vif.addr))
2453 return -EINVAL;
2454
2455 if (!is_valid_ether_addr(mac))
2456 return -EINVAL;
2457
2458 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
2459 sdata->vif.type == NL80211_IFTYPE_STATION &&
2460 !sdata->u.mgd.associated)
2461 return -EINVAL;
2462
2463 /*
2464 * If we have a link ID, it can be a non-MLO station on an AP MLD,
2465 * but we need to have a link_mac in that case as well, so use the
2466 * STA's MAC address in that case.
2467 */
2468 if (params->link_sta_params.link_id >= 0)
2469 sta = sta_info_alloc_with_link(sdata, mac,
2470 params->link_sta_params.link_id,
2471 params->link_sta_params.link_mac ?: mac,
2472 GFP_KERNEL);
2473 else
2474 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
2475
2476 if (!sta)
2477 return -ENOMEM;
2478
2479 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2480 sta->sta.tdls = true;
2481
2482 /* Though the mutex is not needed here (since the station is not
2483 * visible yet), sta_apply_parameters (and inner functions) require
2484 * the mutex due to other paths.
2485 */
2486 err = sta_apply_parameters(local, sta, params);
2487 if (err) {
2488 sta_info_free(local, sta);
2489 return err;
2490 }
2491
2492 /*
2493 * for TDLS and for unassociated station, rate control should be
2494 * initialized only when rates are known and station is marked
2495 * authorized/associated
2496 */
2497 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
2498 test_sta_flag(sta, WLAN_STA_ASSOC))
2499 rate_control_rate_init_all_links(sta);
2500
2501 err = sta_info_insert(sta);
2502
2503 /*
2504 * ieee80211_nan_update_ndi_carrier was called from sta_apply_parameters,
2505 * but then we did not have the STA in the list.
2506 */
2507 if (!err && sdata->vif.type == NL80211_IFTYPE_NAN_DATA)
2508 ieee80211_nan_update_ndi_carrier(sta->sdata);
2509 return err;
2510 }
2511
ieee80211_del_station(struct wiphy * wiphy,struct wireless_dev * wdev,struct station_del_parameters * params)2512 static int ieee80211_del_station(struct wiphy *wiphy, struct wireless_dev *wdev,
2513 struct station_del_parameters *params)
2514 {
2515 struct ieee80211_sub_if_data *sdata;
2516
2517 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2518
2519 if (params->mac)
2520 return sta_info_destroy_addr_bss(sdata, params->mac);
2521
2522 sta_info_flush(sdata, params->link_id);
2523 return 0;
2524 }
2525
ieee80211_set_sta_4addr(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata,struct sta_info * sta)2526 static int ieee80211_set_sta_4addr(struct ieee80211_local *local,
2527 struct ieee80211_sub_if_data *sdata,
2528 struct sta_info *sta)
2529 {
2530 struct ieee80211_vif *vif = &sdata->vif;
2531 struct wiphy *wiphy = local->hw.wiphy;
2532 struct ieee80211_sub_if_data *master;
2533 struct ieee80211_bss_conf *link_conf;
2534 struct wireless_dev *wdev;
2535 unsigned long master_iter;
2536 int link_id;
2537 int err;
2538
2539 lockdep_assert_wiphy(local->hw.wiphy);
2540
2541 if (sdata->u.vlan.sta)
2542 return -EBUSY;
2543
2544 wdev = &sdata->wdev;
2545 master = container_of(sdata->bss,
2546 struct ieee80211_sub_if_data,
2547 u.ap);
2548
2549 if (sta->sta.valid_links) {
2550 u16 sta_links = sta->sta.valid_links;
2551 u16 new_links = master->vif.valid_links & sta_links;
2552 u16 orig_links = wdev->valid_links;
2553
2554 wdev->valid_links = new_links;
2555
2556 err = ieee80211_vif_set_links(sdata, new_links, 0);
2557 if (err) {
2558 wdev->valid_links = orig_links;
2559 return err;
2560 }
2561
2562 master_iter = master->vif.valid_links;
2563
2564 for_each_set_bit(link_id, &master_iter,
2565 IEEE80211_MLD_MAX_NUM_LINKS) {
2566 if (!(sta_links & BIT(link_id))) {
2567 eth_zero_addr(wdev->links[link_id].addr);
2568 } else {
2569 link_conf = wiphy_dereference(wiphy,
2570 vif->link_conf[link_id]);
2571
2572 ether_addr_copy(wdev->links[link_id].addr,
2573 link_conf->bssid);
2574 }
2575 }
2576 }
2577
2578 rcu_assign_pointer(sdata->u.vlan.sta, sta);
2579 __ieee80211_check_fast_rx_iface(sdata);
2580 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
2581
2582 return 0;
2583 }
2584
ieee80211_change_station(struct wiphy * wiphy,struct wireless_dev * wdev,const u8 * mac,struct station_parameters * params)2585 static int ieee80211_change_station(struct wiphy *wiphy,
2586 struct wireless_dev *wdev, const u8 *mac,
2587 struct station_parameters *params)
2588 {
2589 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2590 struct ieee80211_local *local = wiphy_priv(wiphy);
2591 struct sta_info *sta;
2592 struct ieee80211_sub_if_data *vlansdata;
2593 enum cfg80211_station_type statype;
2594 int err;
2595
2596 lockdep_assert_wiphy(local->hw.wiphy);
2597
2598 sta = sta_info_get_bss(sdata, mac);
2599 if (!sta)
2600 return -ENOENT;
2601
2602 switch (sdata->vif.type) {
2603 case NL80211_IFTYPE_MESH_POINT:
2604 if (sdata->u.mesh.user_mpm)
2605 statype = CFG80211_STA_MESH_PEER_USER;
2606 else
2607 statype = CFG80211_STA_MESH_PEER_KERNEL;
2608 break;
2609 case NL80211_IFTYPE_ADHOC:
2610 statype = CFG80211_STA_IBSS;
2611 break;
2612 case NL80211_IFTYPE_STATION:
2613 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2614 statype = CFG80211_STA_AP_STA;
2615 break;
2616 }
2617 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2618 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
2619 else
2620 statype = CFG80211_STA_TDLS_PEER_SETUP;
2621 break;
2622 case NL80211_IFTYPE_AP:
2623 case NL80211_IFTYPE_AP_VLAN:
2624 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2625 statype = CFG80211_STA_AP_CLIENT;
2626 else
2627 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
2628 break;
2629 case NL80211_IFTYPE_NAN:
2630 statype = CFG80211_STA_NAN_MGMT;
2631 break;
2632 case NL80211_IFTYPE_NAN_DATA:
2633 statype = CFG80211_STA_NAN_DATA;
2634 break;
2635 default:
2636 return -EOPNOTSUPP;
2637 }
2638
2639 err = cfg80211_check_station_change(wiphy, params, statype);
2640 if (err)
2641 return err;
2642
2643 if (params->vlan && params->vlan != sta->sdata->dev) {
2644 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2645
2646 if (params->vlan->ieee80211_ptr->use_4addr) {
2647 err = ieee80211_set_sta_4addr(local, vlansdata, sta);
2648 if (err)
2649 return err;
2650
2651 }
2652
2653 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2654 sta->sdata->u.vlan.sta)
2655 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
2656
2657 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2658 ieee80211_vif_dec_num_mcast(sta->sdata);
2659
2660 sta->sdata = vlansdata;
2661 ieee80211_check_fast_rx(sta);
2662 ieee80211_check_fast_xmit(sta);
2663
2664 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
2665 ieee80211_vif_inc_num_mcast(sta->sdata);
2666 cfg80211_send_layer2_update(sta->sdata->dev,
2667 sta->sta.addr);
2668 }
2669 }
2670
2671 /* NAN capabilties should not change */
2672 if (statype == CFG80211_STA_NAN_DATA &&
2673 sta->deflink.pub->ht_cap.ht_supported &&
2674 (params->link_sta_params.ht_capa ||
2675 params->link_sta_params.vht_capa ||
2676 params->link_sta_params.he_capa))
2677 return -EINVAL;
2678
2679 err = sta_apply_parameters(local, sta, params);
2680 if (err)
2681 return err;
2682
2683 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2684 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
2685 ieee80211_recalc_ps(local);
2686 ieee80211_recalc_ps_vif(sdata);
2687 }
2688
2689 return 0;
2690 }
2691
2692 #ifdef CONFIG_MAC80211_MESH
ieee80211_add_mpath(struct wiphy * wiphy,struct net_device * dev,const u8 * dst,const u8 * next_hop)2693 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
2694 const u8 *dst, const u8 *next_hop)
2695 {
2696 struct ieee80211_sub_if_data *sdata;
2697 struct mesh_path *mpath;
2698 struct sta_info *sta;
2699
2700 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2701
2702 rcu_read_lock();
2703 sta = sta_info_get(sdata, next_hop);
2704 if (!sta) {
2705 rcu_read_unlock();
2706 return -ENOENT;
2707 }
2708
2709 mpath = mesh_path_add(sdata, dst);
2710 if (IS_ERR(mpath)) {
2711 rcu_read_unlock();
2712 return PTR_ERR(mpath);
2713 }
2714
2715 mesh_path_fix_nexthop(mpath, sta);
2716
2717 rcu_read_unlock();
2718 return 0;
2719 }
2720
ieee80211_del_mpath(struct wiphy * wiphy,struct net_device * dev,const u8 * dst)2721 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
2722 const u8 *dst)
2723 {
2724 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2725
2726 if (dst)
2727 return mesh_path_del(sdata, dst);
2728
2729 mesh_path_flush_by_iface(sdata);
2730 return 0;
2731 }
2732
ieee80211_change_mpath(struct wiphy * wiphy,struct net_device * dev,const u8 * dst,const u8 * next_hop)2733 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2734 const u8 *dst, const u8 *next_hop)
2735 {
2736 struct ieee80211_sub_if_data *sdata;
2737 struct mesh_path *mpath;
2738 struct sta_info *sta;
2739
2740 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2741
2742 rcu_read_lock();
2743
2744 sta = sta_info_get(sdata, next_hop);
2745 if (!sta) {
2746 rcu_read_unlock();
2747 return -ENOENT;
2748 }
2749
2750 mpath = mesh_path_lookup(sdata, dst);
2751 if (!mpath) {
2752 rcu_read_unlock();
2753 return -ENOENT;
2754 }
2755
2756 mesh_path_fix_nexthop(mpath, sta);
2757
2758 rcu_read_unlock();
2759 return 0;
2760 }
2761
mpath_set_pinfo(struct mesh_path * mpath,u8 * next_hop,struct mpath_info * pinfo)2762 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2763 struct mpath_info *pinfo)
2764 {
2765 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2766
2767 if (next_hop_sta)
2768 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
2769 else
2770 eth_zero_addr(next_hop);
2771
2772 memset(pinfo, 0, sizeof(*pinfo));
2773
2774 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
2775
2776 pinfo->filled = MPATH_INFO_FRAME_QLEN |
2777 MPATH_INFO_SN |
2778 MPATH_INFO_METRIC |
2779 MPATH_INFO_EXPTIME |
2780 MPATH_INFO_DISCOVERY_TIMEOUT |
2781 MPATH_INFO_DISCOVERY_RETRIES |
2782 MPATH_INFO_FLAGS |
2783 MPATH_INFO_HOP_COUNT |
2784 MPATH_INFO_PATH_CHANGE;
2785
2786 pinfo->frame_qlen = mpath->frame_queue.qlen;
2787 pinfo->sn = mpath->sn;
2788 pinfo->metric = mpath->metric;
2789 if (time_before(jiffies, mpath->exp_time))
2790 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2791 pinfo->discovery_timeout =
2792 jiffies_to_msecs(mpath->discovery_timeout);
2793 pinfo->discovery_retries = mpath->discovery_retries;
2794 if (mpath->flags & MESH_PATH_ACTIVE)
2795 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2796 if (mpath->flags & MESH_PATH_RESOLVING)
2797 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
2798 if (mpath->flags & MESH_PATH_SN_VALID)
2799 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
2800 if (mpath->flags & MESH_PATH_FIXED)
2801 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
2802 if (mpath->flags & MESH_PATH_RESOLVED)
2803 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
2804 pinfo->hop_count = mpath->hop_count;
2805 pinfo->path_change_count = mpath->path_change_count;
2806 }
2807
ieee80211_get_mpath(struct wiphy * wiphy,struct net_device * dev,u8 * dst,u8 * next_hop,struct mpath_info * pinfo)2808 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2809 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2810
2811 {
2812 struct ieee80211_sub_if_data *sdata;
2813 struct mesh_path *mpath;
2814
2815 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2816
2817 rcu_read_lock();
2818 mpath = mesh_path_lookup(sdata, dst);
2819 if (!mpath) {
2820 rcu_read_unlock();
2821 return -ENOENT;
2822 }
2823 memcpy(dst, mpath->dst, ETH_ALEN);
2824 mpath_set_pinfo(mpath, next_hop, pinfo);
2825 rcu_read_unlock();
2826 return 0;
2827 }
2828
ieee80211_dump_mpath(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * dst,u8 * next_hop,struct mpath_info * pinfo)2829 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
2830 int idx, u8 *dst, u8 *next_hop,
2831 struct mpath_info *pinfo)
2832 {
2833 struct ieee80211_sub_if_data *sdata;
2834 struct mesh_path *mpath;
2835
2836 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2837
2838 rcu_read_lock();
2839 mpath = mesh_path_lookup_by_idx(sdata, idx);
2840 if (!mpath) {
2841 rcu_read_unlock();
2842 return -ENOENT;
2843 }
2844 memcpy(dst, mpath->dst, ETH_ALEN);
2845 mpath_set_pinfo(mpath, next_hop, pinfo);
2846 rcu_read_unlock();
2847 return 0;
2848 }
2849
mpp_set_pinfo(struct mesh_path * mpath,u8 * mpp,struct mpath_info * pinfo)2850 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2851 struct mpath_info *pinfo)
2852 {
2853 memset(pinfo, 0, sizeof(*pinfo));
2854 memcpy(mpp, mpath->mpp, ETH_ALEN);
2855
2856 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
2857 }
2858
ieee80211_get_mpp(struct wiphy * wiphy,struct net_device * dev,u8 * dst,u8 * mpp,struct mpath_info * pinfo)2859 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2860 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2861
2862 {
2863 struct ieee80211_sub_if_data *sdata;
2864 struct mesh_path *mpath;
2865
2866 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2867
2868 rcu_read_lock();
2869 mpath = mpp_path_lookup(sdata, dst);
2870 if (!mpath) {
2871 rcu_read_unlock();
2872 return -ENOENT;
2873 }
2874 memcpy(dst, mpath->dst, ETH_ALEN);
2875 mpp_set_pinfo(mpath, mpp, pinfo);
2876 rcu_read_unlock();
2877 return 0;
2878 }
2879
ieee80211_dump_mpp(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * dst,u8 * mpp,struct mpath_info * pinfo)2880 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2881 int idx, u8 *dst, u8 *mpp,
2882 struct mpath_info *pinfo)
2883 {
2884 struct ieee80211_sub_if_data *sdata;
2885 struct mesh_path *mpath;
2886
2887 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2888
2889 rcu_read_lock();
2890 mpath = mpp_path_lookup_by_idx(sdata, idx);
2891 if (!mpath) {
2892 rcu_read_unlock();
2893 return -ENOENT;
2894 }
2895 memcpy(dst, mpath->dst, ETH_ALEN);
2896 mpp_set_pinfo(mpath, mpp, pinfo);
2897 rcu_read_unlock();
2898 return 0;
2899 }
2900
ieee80211_get_mesh_config(struct wiphy * wiphy,struct net_device * dev,struct mesh_config * conf)2901 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
2902 struct net_device *dev,
2903 struct mesh_config *conf)
2904 {
2905 struct ieee80211_sub_if_data *sdata;
2906 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2907
2908 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2909 return 0;
2910 }
2911
_chg_mesh_attr(enum nl80211_meshconf_params parm,u32 mask)2912 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2913 {
2914 return (mask >> (parm-1)) & 0x1;
2915 }
2916
copy_mesh_setup(struct ieee80211_if_mesh * ifmsh,const struct mesh_setup * setup)2917 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2918 const struct mesh_setup *setup)
2919 {
2920 u8 *new_ie;
2921 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2922 struct ieee80211_sub_if_data, u.mesh);
2923 int i;
2924
2925 /* allocate information elements */
2926 new_ie = NULL;
2927
2928 if (setup->ie_len) {
2929 new_ie = kmemdup(setup->ie, setup->ie_len,
2930 GFP_KERNEL);
2931 if (!new_ie)
2932 return -ENOMEM;
2933 }
2934 ifmsh->ie_len = setup->ie_len;
2935 ifmsh->ie = new_ie;
2936
2937 /* now copy the rest of the setup parameters */
2938 ifmsh->mesh_id_len = setup->mesh_id_len;
2939 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
2940 ifmsh->mesh_sp_id = setup->sync_method;
2941 ifmsh->mesh_pp_id = setup->path_sel_proto;
2942 ifmsh->mesh_pm_id = setup->path_metric;
2943 ifmsh->user_mpm = setup->user_mpm;
2944 ifmsh->mesh_auth_id = setup->auth_id;
2945 ifmsh->security = IEEE80211_MESH_SEC_NONE;
2946 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
2947 if (setup->is_authenticated)
2948 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2949 if (setup->is_secure)
2950 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
2951
2952 /* mcast rate setting in Mesh Node */
2953 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2954 sizeof(setup->mcast_rate));
2955 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
2956
2957 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2958 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2959
2960 sdata->beacon_rate_set = false;
2961 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2962 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2963 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2964 sdata->beacon_rateidx_mask[i] =
2965 setup->beacon_rate.control[i].legacy;
2966 if (sdata->beacon_rateidx_mask[i])
2967 sdata->beacon_rate_set = true;
2968 }
2969 }
2970
2971 return 0;
2972 }
2973
ieee80211_update_mesh_config(struct wiphy * wiphy,struct net_device * dev,u32 mask,const struct mesh_config * nconf)2974 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
2975 struct net_device *dev, u32 mask,
2976 const struct mesh_config *nconf)
2977 {
2978 struct mesh_config *conf;
2979 struct ieee80211_sub_if_data *sdata;
2980 struct ieee80211_if_mesh *ifmsh;
2981
2982 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2983 ifmsh = &sdata->u.mesh;
2984
2985 /* Set the config options which we are interested in setting */
2986 conf = &(sdata->u.mesh.mshcfg);
2987 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2988 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2989 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2990 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2991 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2992 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2993 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2994 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2995 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2996 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2997 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2998 conf->dot11MeshTTL = nconf->dot11MeshTTL;
2999 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
3000 conf->element_ttl = nconf->element_ttl;
3001 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
3002 if (ifmsh->user_mpm)
3003 return -EBUSY;
3004 conf->auto_open_plinks = nconf->auto_open_plinks;
3005 }
3006 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
3007 conf->dot11MeshNbrOffsetMaxNeighbor =
3008 nconf->dot11MeshNbrOffsetMaxNeighbor;
3009 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
3010 conf->dot11MeshHWMPmaxPREQretries =
3011 nconf->dot11MeshHWMPmaxPREQretries;
3012 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
3013 conf->path_refresh_time = nconf->path_refresh_time;
3014 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
3015 conf->min_discovery_timeout = nconf->min_discovery_timeout;
3016 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
3017 conf->dot11MeshHWMPactivePathTimeout =
3018 nconf->dot11MeshHWMPactivePathTimeout;
3019 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
3020 conf->dot11MeshHWMPpreqMinInterval =
3021 nconf->dot11MeshHWMPpreqMinInterval;
3022 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
3023 conf->dot11MeshHWMPperrMinInterval =
3024 nconf->dot11MeshHWMPperrMinInterval;
3025 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
3026 mask))
3027 conf->dot11MeshHWMPnetDiameterTraversalTime =
3028 nconf->dot11MeshHWMPnetDiameterTraversalTime;
3029 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
3030 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
3031 ieee80211_mesh_root_setup(ifmsh);
3032 }
3033 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
3034 /* our current gate announcement implementation rides on root
3035 * announcements, so require this ifmsh to also be a root node
3036 * */
3037 if (nconf->dot11MeshGateAnnouncementProtocol &&
3038 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
3039 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
3040 ieee80211_mesh_root_setup(ifmsh);
3041 }
3042 conf->dot11MeshGateAnnouncementProtocol =
3043 nconf->dot11MeshGateAnnouncementProtocol;
3044 }
3045 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
3046 conf->dot11MeshHWMPRannInterval =
3047 nconf->dot11MeshHWMPRannInterval;
3048 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
3049 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
3050 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
3051 /* our RSSI threshold implementation is supported only for
3052 * devices that report signal in dBm.
3053 */
3054 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
3055 return -EOPNOTSUPP;
3056 conf->rssi_threshold = nconf->rssi_threshold;
3057 }
3058 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
3059 conf->ht_opmode = nconf->ht_opmode;
3060 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
3061 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3062 BSS_CHANGED_HT);
3063 }
3064 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
3065 conf->dot11MeshHWMPactivePathToRootTimeout =
3066 nconf->dot11MeshHWMPactivePathToRootTimeout;
3067 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
3068 conf->dot11MeshHWMProotInterval =
3069 nconf->dot11MeshHWMProotInterval;
3070 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
3071 conf->dot11MeshHWMPconfirmationInterval =
3072 nconf->dot11MeshHWMPconfirmationInterval;
3073 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
3074 conf->power_mode = nconf->power_mode;
3075 ieee80211_mps_local_status_update(sdata);
3076 }
3077 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
3078 conf->dot11MeshAwakeWindowDuration =
3079 nconf->dot11MeshAwakeWindowDuration;
3080 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
3081 conf->plink_timeout = nconf->plink_timeout;
3082 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
3083 conf->dot11MeshConnectedToMeshGate =
3084 nconf->dot11MeshConnectedToMeshGate;
3085 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
3086 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
3087 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
3088 conf->dot11MeshConnectedToAuthServer =
3089 nconf->dot11MeshConnectedToAuthServer;
3090 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
3091 return 0;
3092 }
3093
ieee80211_join_mesh(struct wiphy * wiphy,struct net_device * dev,const struct mesh_config * conf,const struct mesh_setup * setup)3094 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
3095 const struct mesh_config *conf,
3096 const struct mesh_setup *setup)
3097 {
3098 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3099 struct ieee80211_chan_req chanreq = { .oper = setup->chandef };
3100 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3101 int err;
3102
3103 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3104
3105 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
3106 err = copy_mesh_setup(ifmsh, setup);
3107 if (err)
3108 return err;
3109
3110 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
3111
3112 /* can mesh use other SMPS modes? */
3113 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
3114 sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
3115
3116 err = ieee80211_link_use_channel(&sdata->deflink, &chanreq,
3117 IEEE80211_CHANCTX_SHARED);
3118 if (err)
3119 return err;
3120
3121 return ieee80211_start_mesh(sdata);
3122 }
3123
ieee80211_leave_mesh(struct wiphy * wiphy,struct net_device * dev)3124 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
3125 {
3126 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3127
3128 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3129
3130 ieee80211_stop_mesh(sdata);
3131 ieee80211_link_release_channel(&sdata->deflink);
3132 kfree(sdata->u.mesh.ie);
3133
3134 return 0;
3135 }
3136 #endif
3137
ieee80211_change_bss(struct wiphy * wiphy,struct net_device * dev,struct bss_parameters * params)3138 static int ieee80211_change_bss(struct wiphy *wiphy,
3139 struct net_device *dev,
3140 struct bss_parameters *params)
3141 {
3142 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3143 struct ieee80211_link_data *link;
3144 struct ieee80211_supported_band *sband;
3145 u64 changed = 0;
3146
3147 link = ieee80211_link_or_deflink(sdata, params->link_id, true);
3148 if (IS_ERR(link))
3149 return PTR_ERR(link);
3150
3151 if (!sdata_dereference(link->u.ap.beacon, sdata))
3152 return -ENOENT;
3153
3154 sband = ieee80211_get_link_sband(link);
3155 if (!sband)
3156 return -EINVAL;
3157
3158 if (params->basic_rates) {
3159 if (!ieee80211_parse_bitrates(sband,
3160 params->basic_rates,
3161 params->basic_rates_len,
3162 &link->conf->basic_rates))
3163 return -EINVAL;
3164 changed |= BSS_CHANGED_BASIC_RATES;
3165 ieee80211_check_rate_mask(link);
3166 }
3167
3168 if (params->use_cts_prot >= 0) {
3169 link->conf->use_cts_prot = params->use_cts_prot;
3170 changed |= BSS_CHANGED_ERP_CTS_PROT;
3171 }
3172 if (params->use_short_preamble >= 0) {
3173 link->conf->use_short_preamble = params->use_short_preamble;
3174 changed |= BSS_CHANGED_ERP_PREAMBLE;
3175 }
3176
3177 if (!link->conf->use_short_slot &&
3178 (sband->band == NL80211_BAND_5GHZ ||
3179 sband->band == NL80211_BAND_6GHZ)) {
3180 link->conf->use_short_slot = true;
3181 changed |= BSS_CHANGED_ERP_SLOT;
3182 }
3183
3184 if (params->use_short_slot_time >= 0) {
3185 link->conf->use_short_slot = params->use_short_slot_time;
3186 changed |= BSS_CHANGED_ERP_SLOT;
3187 }
3188
3189 if (params->ap_isolate >= 0) {
3190 if (params->ap_isolate)
3191 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
3192 else
3193 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
3194 ieee80211_check_fast_rx_iface(sdata);
3195 }
3196
3197 if (params->ht_opmode >= 0) {
3198 link->conf->ht_operation_mode = (u16)params->ht_opmode;
3199 changed |= BSS_CHANGED_HT;
3200 }
3201
3202 if (params->p2p_ctwindow >= 0) {
3203 link->conf->p2p_noa_attr.oppps_ctwindow &=
3204 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
3205 link->conf->p2p_noa_attr.oppps_ctwindow |=
3206 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
3207 changed |= BSS_CHANGED_P2P_PS;
3208 }
3209
3210 if (params->p2p_opp_ps > 0) {
3211 link->conf->p2p_noa_attr.oppps_ctwindow |=
3212 IEEE80211_P2P_OPPPS_ENABLE_BIT;
3213 changed |= BSS_CHANGED_P2P_PS;
3214 } else if (params->p2p_opp_ps == 0) {
3215 link->conf->p2p_noa_attr.oppps_ctwindow &=
3216 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
3217 changed |= BSS_CHANGED_P2P_PS;
3218 }
3219
3220 ieee80211_link_info_change_notify(sdata, link, changed);
3221
3222 return 0;
3223 }
3224
ieee80211_set_txq_params(struct wiphy * wiphy,struct net_device * dev,struct ieee80211_txq_params * params)3225 static int ieee80211_set_txq_params(struct wiphy *wiphy,
3226 struct net_device *dev,
3227 struct ieee80211_txq_params *params)
3228 {
3229 struct ieee80211_local *local = wiphy_priv(wiphy);
3230 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3231 struct ieee80211_link_data *link =
3232 ieee80211_link_or_deflink(sdata, params->link_id, true);
3233 struct ieee80211_tx_queue_params p;
3234
3235 if (!local->ops->conf_tx)
3236 return -EOPNOTSUPP;
3237
3238 if (local->hw.queues < IEEE80211_NUM_ACS)
3239 return -EOPNOTSUPP;
3240
3241 if (IS_ERR(link))
3242 return PTR_ERR(link);
3243
3244 memset(&p, 0, sizeof(p));
3245 p.aifs = params->aifs;
3246 p.cw_max = params->cwmax;
3247 p.cw_min = params->cwmin;
3248 p.txop = params->txop;
3249
3250 /*
3251 * Setting tx queue params disables u-apsd because it's only
3252 * called in master mode.
3253 */
3254 p.uapsd = false;
3255
3256 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
3257
3258 link->tx_conf[params->ac] = p;
3259 if (drv_conf_tx(local, link, params->ac, &p)) {
3260 wiphy_debug(local->hw.wiphy,
3261 "failed to set TX queue parameters for AC %d\n",
3262 params->ac);
3263 return -EINVAL;
3264 }
3265
3266 ieee80211_link_info_change_notify(sdata, link,
3267 BSS_CHANGED_QOS);
3268
3269 return 0;
3270 }
3271
3272 #ifdef CONFIG_PM
ieee80211_suspend(struct wiphy * wiphy,struct cfg80211_wowlan * wowlan)3273 static int ieee80211_suspend(struct wiphy *wiphy,
3274 struct cfg80211_wowlan *wowlan)
3275 {
3276 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
3277 }
3278
ieee80211_resume(struct wiphy * wiphy)3279 static int ieee80211_resume(struct wiphy *wiphy)
3280 {
3281 return __ieee80211_resume(wiphy_priv(wiphy));
3282 }
3283 #else
3284 #define ieee80211_suspend NULL
3285 #define ieee80211_resume NULL
3286 #endif
3287
ieee80211_scan(struct wiphy * wiphy,struct cfg80211_scan_request * req)3288 static int ieee80211_scan(struct wiphy *wiphy,
3289 struct cfg80211_scan_request *req)
3290 {
3291 struct ieee80211_sub_if_data *sdata;
3292 struct ieee80211_link_data *link;
3293 struct ieee80211_channel *chan;
3294 int radio_idx;
3295
3296 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
3297
3298 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
3299 case NL80211_IFTYPE_STATION:
3300 case NL80211_IFTYPE_ADHOC:
3301 case NL80211_IFTYPE_MESH_POINT:
3302 case NL80211_IFTYPE_P2P_CLIENT:
3303 case NL80211_IFTYPE_P2P_DEVICE:
3304 break;
3305 case NL80211_IFTYPE_P2P_GO:
3306 if (sdata->local->ops->hw_scan)
3307 break;
3308 /*
3309 * FIXME: implement NoA while scanning in software,
3310 * for now fall through to allow scanning only when
3311 * beaconing hasn't been configured yet
3312 */
3313 fallthrough;
3314 case NL80211_IFTYPE_AP:
3315 /*
3316 * If the scan has been forced (and the driver supports
3317 * forcing), don't care about being beaconing already.
3318 * This will create problems to the attached stations (e.g. all
3319 * the frames sent while scanning on other channel will be
3320 * lost)
3321 */
3322 for_each_link_data(sdata, link) {
3323 /* if the link is not beaconing, ignore it */
3324 if (!sdata_dereference(link->u.ap.beacon, sdata))
3325 continue;
3326
3327 chan = link->conf->chanreq.oper.chan;
3328 radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chan);
3329
3330 if (ieee80211_is_radio_idx_in_scan_req(wiphy, req,
3331 radio_idx) &&
3332 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
3333 !(req->flags & NL80211_SCAN_FLAG_AP)))
3334 return -EOPNOTSUPP;
3335 }
3336 break;
3337 case NL80211_IFTYPE_NAN:
3338 default:
3339 return -EOPNOTSUPP;
3340 }
3341
3342 return ieee80211_request_scan(sdata, req);
3343 }
3344
ieee80211_abort_scan(struct wiphy * wiphy,struct wireless_dev * wdev)3345 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
3346 {
3347 ieee80211_scan_cancel(wiphy_priv(wiphy));
3348 }
3349
3350 static int
ieee80211_sched_scan_start(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_sched_scan_request * req)3351 ieee80211_sched_scan_start(struct wiphy *wiphy,
3352 struct net_device *dev,
3353 struct cfg80211_sched_scan_request *req)
3354 {
3355 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3356
3357 if (!sdata->local->ops->sched_scan_start)
3358 return -EOPNOTSUPP;
3359
3360 return ieee80211_request_sched_scan_start(sdata, req);
3361 }
3362
3363 static int
ieee80211_sched_scan_stop(struct wiphy * wiphy,struct net_device * dev,u64 reqid)3364 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
3365 u64 reqid)
3366 {
3367 struct ieee80211_local *local = wiphy_priv(wiphy);
3368
3369 if (!local->ops->sched_scan_stop)
3370 return -EOPNOTSUPP;
3371
3372 return ieee80211_request_sched_scan_stop(local);
3373 }
3374
ieee80211_auth(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_auth_request * req)3375 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
3376 struct cfg80211_auth_request *req)
3377 {
3378 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
3379 }
3380
ieee80211_assoc(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_assoc_request * req)3381 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
3382 struct cfg80211_assoc_request *req)
3383 {
3384 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
3385 }
3386
ieee80211_deauth(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_deauth_request * req)3387 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
3388 struct cfg80211_deauth_request *req)
3389 {
3390 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
3391 }
3392
ieee80211_disassoc(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_disassoc_request * req)3393 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
3394 struct cfg80211_disassoc_request *req)
3395 {
3396 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
3397 }
3398
ieee80211_join_ibss(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ibss_params * params)3399 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
3400 struct cfg80211_ibss_params *params)
3401 {
3402 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
3403 }
3404
ieee80211_leave_ibss(struct wiphy * wiphy,struct net_device * dev)3405 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
3406 {
3407 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
3408 }
3409
ieee80211_join_ocb(struct wiphy * wiphy,struct net_device * dev,struct ocb_setup * setup)3410 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
3411 struct ocb_setup *setup)
3412 {
3413 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
3414 }
3415
ieee80211_leave_ocb(struct wiphy * wiphy,struct net_device * dev)3416 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
3417 {
3418 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
3419 }
3420
ieee80211_set_mcast_rate(struct wiphy * wiphy,struct net_device * dev,int rate[NUM_NL80211_BANDS])3421 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
3422 int rate[NUM_NL80211_BANDS])
3423 {
3424 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3425
3426 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
3427 sizeof(int) * NUM_NL80211_BANDS);
3428
3429 if (ieee80211_sdata_running(sdata))
3430 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3431 BSS_CHANGED_MCAST_RATE);
3432
3433 return 0;
3434 }
3435
ieee80211_set_wiphy_params(struct wiphy * wiphy,int radio_idx,u32 changed)3436 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, int radio_idx,
3437 u32 changed)
3438 {
3439 struct ieee80211_local *local = wiphy_priv(wiphy);
3440 int err;
3441
3442 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
3443 ieee80211_check_fast_xmit_all(local);
3444
3445 err = drv_set_frag_threshold(local, radio_idx,
3446 wiphy->frag_threshold);
3447
3448 if (err) {
3449 ieee80211_check_fast_xmit_all(local);
3450 return err;
3451 }
3452 }
3453
3454 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
3455 (changed & WIPHY_PARAM_DYN_ACK)) {
3456 s16 coverage_class;
3457
3458 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
3459 wiphy->coverage_class : -1;
3460 err = drv_set_coverage_class(local, radio_idx,
3461 coverage_class);
3462
3463 if (err)
3464 return err;
3465 }
3466
3467 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
3468 u32 rts_threshold;
3469
3470 if ((radio_idx == -1) || (radio_idx >= wiphy->n_radio))
3471 rts_threshold = wiphy->rts_threshold;
3472 else
3473 rts_threshold =
3474 wiphy->radio_cfg[radio_idx].rts_threshold;
3475
3476 err = drv_set_rts_threshold(local, radio_idx, rts_threshold);
3477
3478 if (err)
3479 return err;
3480 }
3481
3482 if (changed & WIPHY_PARAM_RETRY_SHORT) {
3483 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
3484 return -EINVAL;
3485 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
3486 }
3487 if (changed & WIPHY_PARAM_RETRY_LONG) {
3488 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
3489 return -EINVAL;
3490 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
3491 }
3492 if (changed &
3493 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
3494 ieee80211_hw_config(local, radio_idx,
3495 IEEE80211_CONF_CHANGE_RETRY_LIMITS);
3496
3497 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
3498 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
3499 WIPHY_PARAM_TXQ_QUANTUM))
3500 ieee80211_txq_set_params(local, radio_idx);
3501
3502 return 0;
3503 }
3504
ieee80211_set_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int radio_idx,enum nl80211_tx_power_setting type,int mbm)3505 static int ieee80211_set_tx_power(struct wiphy *wiphy,
3506 struct wireless_dev *wdev, int radio_idx,
3507 enum nl80211_tx_power_setting type, int mbm)
3508 {
3509 struct ieee80211_local *local = wiphy_priv(wiphy);
3510 struct ieee80211_sub_if_data *sdata;
3511 enum nl80211_tx_power_setting txp_type = type;
3512 bool update_txp_type = false;
3513 bool has_monitor = false;
3514 int user_power_level;
3515 int old_power = local->user_power_level;
3516
3517 lockdep_assert_wiphy(local->hw.wiphy);
3518
3519 switch (type) {
3520 case NL80211_TX_POWER_AUTOMATIC:
3521 user_power_level = IEEE80211_UNSET_POWER_LEVEL;
3522 txp_type = NL80211_TX_POWER_LIMITED;
3523 break;
3524 case NL80211_TX_POWER_LIMITED:
3525 case NL80211_TX_POWER_FIXED:
3526 if (mbm < 0 || (mbm % 100))
3527 return -EOPNOTSUPP;
3528 user_power_level = MBM_TO_DBM(mbm);
3529 break;
3530 default:
3531 return -EINVAL;
3532 }
3533
3534 if (wdev) {
3535 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3536
3537 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
3538 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) {
3539 if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
3540 return -EOPNOTSUPP;
3541
3542 sdata = wiphy_dereference(local->hw.wiphy,
3543 local->monitor_sdata);
3544 if (!sdata)
3545 return -EOPNOTSUPP;
3546 }
3547
3548 for (int link_id = 0;
3549 link_id < ARRAY_SIZE(sdata->link);
3550 link_id++) {
3551 struct ieee80211_link_data *link =
3552 wiphy_dereference(wiphy, sdata->link[link_id]);
3553
3554 if (!link)
3555 continue;
3556
3557 link->user_power_level = user_power_level;
3558
3559 if (txp_type != link->conf->txpower_type) {
3560 update_txp_type = true;
3561 link->conf->txpower_type = txp_type;
3562 }
3563
3564 ieee80211_recalc_txpower(link, update_txp_type);
3565 }
3566 return 0;
3567 }
3568
3569 local->user_power_level = user_power_level;
3570
3571 list_for_each_entry(sdata, &local->interfaces, list) {
3572 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
3573 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) {
3574 has_monitor = true;
3575 continue;
3576 }
3577
3578 for (int link_id = 0;
3579 link_id < ARRAY_SIZE(sdata->link);
3580 link_id++) {
3581 struct ieee80211_link_data *link =
3582 wiphy_dereference(wiphy, sdata->link[link_id]);
3583
3584 if (!link)
3585 continue;
3586
3587 link->user_power_level = local->user_power_level;
3588 if (txp_type != link->conf->txpower_type)
3589 update_txp_type = true;
3590 link->conf->txpower_type = txp_type;
3591 }
3592 }
3593 list_for_each_entry(sdata, &local->interfaces, list) {
3594 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
3595 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR))
3596 continue;
3597
3598 for (int link_id = 0;
3599 link_id < ARRAY_SIZE(sdata->link);
3600 link_id++) {
3601 struct ieee80211_link_data *link =
3602 wiphy_dereference(wiphy, sdata->link[link_id]);
3603
3604 if (!link)
3605 continue;
3606
3607 ieee80211_recalc_txpower(link, update_txp_type);
3608 }
3609 }
3610
3611 if (has_monitor) {
3612 sdata = wiphy_dereference(local->hw.wiphy,
3613 local->monitor_sdata);
3614 if (sdata && ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) {
3615 sdata->deflink.user_power_level = local->user_power_level;
3616 if (txp_type != sdata->vif.bss_conf.txpower_type)
3617 update_txp_type = true;
3618 sdata->vif.bss_conf.txpower_type = txp_type;
3619
3620 ieee80211_recalc_txpower(&sdata->deflink,
3621 update_txp_type);
3622 }
3623 }
3624
3625 if (local->emulate_chanctx &&
3626 (old_power != local->user_power_level))
3627 ieee80211_hw_conf_chan(local);
3628
3629 return 0;
3630 }
3631
ieee80211_get_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int radio_idx,unsigned int link_id,int * dbm)3632 static int ieee80211_get_tx_power(struct wiphy *wiphy,
3633 struct wireless_dev *wdev,
3634 int radio_idx,
3635 unsigned int link_id,
3636 int *dbm)
3637 {
3638 struct ieee80211_local *local = wiphy_priv(wiphy);
3639 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3640 struct ieee80211_link_data *link_data;
3641
3642 if (local->ops->get_txpower &&
3643 (sdata->flags & IEEE80211_SDATA_IN_DRIVER))
3644 return drv_get_txpower(local, sdata, link_id, dbm);
3645
3646 if (local->emulate_chanctx) {
3647 *dbm = local->hw.conf.power_level;
3648 } else {
3649 link_data = wiphy_dereference(wiphy, sdata->link[link_id]);
3650
3651 if (link_data)
3652 *dbm = link_data->conf->txpower;
3653 else
3654 return -ENOLINK;
3655 }
3656
3657 /* INT_MIN indicates no power level was set yet */
3658 if (*dbm == INT_MIN)
3659 return -EINVAL;
3660
3661 return 0;
3662 }
3663
ieee80211_rfkill_poll(struct wiphy * wiphy)3664 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
3665 {
3666 struct ieee80211_local *local = wiphy_priv(wiphy);
3667
3668 drv_rfkill_poll(local);
3669 }
3670
3671 #ifdef CONFIG_NL80211_TESTMODE
ieee80211_testmode_cmd(struct wiphy * wiphy,struct wireless_dev * wdev,void * data,int len)3672 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
3673 struct wireless_dev *wdev,
3674 void *data, int len)
3675 {
3676 struct ieee80211_local *local = wiphy_priv(wiphy);
3677 struct ieee80211_vif *vif = NULL;
3678
3679 if (!local->ops->testmode_cmd)
3680 return -EOPNOTSUPP;
3681
3682 if (wdev) {
3683 struct ieee80211_sub_if_data *sdata;
3684
3685 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3686 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
3687 vif = &sdata->vif;
3688 }
3689
3690 return local->ops->testmode_cmd(&local->hw, vif, data, len);
3691 }
3692
ieee80211_testmode_dump(struct wiphy * wiphy,struct sk_buff * skb,struct netlink_callback * cb,void * data,int len)3693 static int ieee80211_testmode_dump(struct wiphy *wiphy,
3694 struct sk_buff *skb,
3695 struct netlink_callback *cb,
3696 void *data, int len)
3697 {
3698 struct ieee80211_local *local = wiphy_priv(wiphy);
3699
3700 if (!local->ops->testmode_dump)
3701 return -EOPNOTSUPP;
3702
3703 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
3704 }
3705 #endif
3706
__ieee80211_request_smps_mgd(struct ieee80211_sub_if_data * sdata,struct ieee80211_link_data * link,enum ieee80211_smps_mode smps_mode)3707 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
3708 struct ieee80211_link_data *link,
3709 enum ieee80211_smps_mode smps_mode)
3710 {
3711 const u8 *ap;
3712 enum ieee80211_smps_mode old_req;
3713 int err;
3714 struct sta_info *sta;
3715 bool tdls_peer_found = false;
3716
3717 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3718
3719 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
3720 return -EINVAL;
3721
3722 if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
3723 return 0;
3724
3725 old_req = link->u.mgd.req_smps;
3726 link->u.mgd.req_smps = smps_mode;
3727
3728 /* The driver indicated that EML is enabled for the interface, which
3729 * implies that SMPS flows towards the AP should be stopped.
3730 */
3731 if (sdata->vif.driver_flags & IEEE80211_VIF_EML_ACTIVE)
3732 return 0;
3733
3734 if (old_req == smps_mode &&
3735 smps_mode != IEEE80211_SMPS_AUTOMATIC)
3736 return 0;
3737
3738 /*
3739 * If not associated, or current association is not an HT
3740 * association, there's no need to do anything, just store
3741 * the new value until we associate.
3742 */
3743 if (!sdata->u.mgd.associated ||
3744 link->conf->chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT)
3745 return 0;
3746
3747 ap = sdata->vif.cfg.ap_addr;
3748
3749 rcu_read_lock();
3750 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
3751 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
3752 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3753 continue;
3754
3755 tdls_peer_found = true;
3756 break;
3757 }
3758 rcu_read_unlock();
3759
3760 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
3761 if (tdls_peer_found || !sdata->u.mgd.powersave)
3762 smps_mode = IEEE80211_SMPS_OFF;
3763 else
3764 smps_mode = IEEE80211_SMPS_DYNAMIC;
3765 }
3766
3767 /* send SM PS frame to AP */
3768 err = ieee80211_send_smps_action(sdata, smps_mode,
3769 ap, ap,
3770 ieee80211_vif_is_mld(&sdata->vif) ?
3771 link->link_id : -1);
3772 if (err)
3773 link->u.mgd.req_smps = old_req;
3774 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
3775 ieee80211_teardown_tdls_peers(link);
3776
3777 return err;
3778 }
3779
ieee80211_set_power_mgmt(struct wiphy * wiphy,struct net_device * dev,bool enabled,int timeout)3780 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
3781 bool enabled, int timeout)
3782 {
3783 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3784 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3785 unsigned int link_id;
3786
3787 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3788 return -EOPNOTSUPP;
3789
3790 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
3791 return -EOPNOTSUPP;
3792
3793 if (enabled == sdata->u.mgd.powersave &&
3794 timeout == local->dynamic_ps_forced_timeout)
3795 return 0;
3796
3797 sdata->u.mgd.powersave = enabled;
3798 local->dynamic_ps_forced_timeout = timeout;
3799
3800 /* no change, but if automatic follow powersave */
3801 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3802 struct ieee80211_link_data *link;
3803
3804 link = sdata_dereference(sdata->link[link_id], sdata);
3805
3806 if (!link)
3807 continue;
3808 __ieee80211_request_smps_mgd(sdata, link,
3809 link->u.mgd.req_smps);
3810 }
3811
3812 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3813 ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS);
3814
3815 ieee80211_recalc_ps(local);
3816 ieee80211_recalc_ps_vif(sdata);
3817 ieee80211_check_fast_rx_iface(sdata);
3818
3819 return 0;
3820 }
3821
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)3822 static void ieee80211_set_cqm_rssi_link(struct ieee80211_sub_if_data *sdata,
3823 struct ieee80211_link_data *link,
3824 s32 rssi_thold, u32 rssi_hyst,
3825 s32 rssi_low, s32 rssi_high)
3826 {
3827 struct ieee80211_bss_conf *conf;
3828
3829 if (!link || !link->conf)
3830 return;
3831
3832 conf = link->conf;
3833
3834 if (rssi_thold && rssi_hyst &&
3835 rssi_thold == conf->cqm_rssi_thold &&
3836 rssi_hyst == conf->cqm_rssi_hyst)
3837 return;
3838
3839 conf->cqm_rssi_thold = rssi_thold;
3840 conf->cqm_rssi_hyst = rssi_hyst;
3841 conf->cqm_rssi_low = rssi_low;
3842 conf->cqm_rssi_high = rssi_high;
3843 link->u.mgd.last_cqm_event_signal = 0;
3844
3845 if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
3846 return;
3847
3848 if (sdata->u.mgd.associated &&
3849 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3850 ieee80211_link_info_change_notify(sdata, link, BSS_CHANGED_CQM);
3851 }
3852
ieee80211_set_cqm_rssi_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_thold,u32 rssi_hyst)3853 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3854 struct net_device *dev,
3855 s32 rssi_thold, u32 rssi_hyst)
3856 {
3857 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3858 struct ieee80211_vif *vif = &sdata->vif;
3859 int link_id;
3860
3861 if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3862 !(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3863 return -EOPNOTSUPP;
3864
3865 /* For MLD, handle CQM change on all the active links */
3866 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
3867 struct ieee80211_link_data *link =
3868 sdata_dereference(sdata->link[link_id], sdata);
3869
3870 ieee80211_set_cqm_rssi_link(sdata, link, rssi_thold, rssi_hyst,
3871 0, 0);
3872 }
3873
3874 return 0;
3875 }
3876
ieee80211_set_cqm_rssi_range_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_low,s32 rssi_high)3877 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3878 struct net_device *dev,
3879 s32 rssi_low, s32 rssi_high)
3880 {
3881 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3882 struct ieee80211_vif *vif = &sdata->vif;
3883 int link_id;
3884
3885 if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)
3886 return -EOPNOTSUPP;
3887
3888 /* For MLD, handle CQM change on all the active links */
3889 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
3890 struct ieee80211_link_data *link =
3891 sdata_dereference(sdata->link[link_id], sdata);
3892
3893 ieee80211_set_cqm_rssi_link(sdata, link, 0, 0,
3894 rssi_low, rssi_high);
3895 }
3896
3897 return 0;
3898 }
3899
ieee80211_set_bitrate_mask(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id,const u8 * addr,const struct cfg80211_bitrate_mask * mask)3900 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3901 struct net_device *dev,
3902 unsigned int link_id,
3903 const u8 *addr,
3904 const struct cfg80211_bitrate_mask *mask)
3905 {
3906 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3907 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3908 int i, ret;
3909
3910 if (!ieee80211_sdata_running(sdata))
3911 return -ENETDOWN;
3912
3913 /*
3914 * If active validate the setting and reject it if it doesn't leave
3915 * at least one basic rate usable, since we really have to be able
3916 * to send something, and if we're an AP we have to be able to do
3917 * so at a basic rate so that all clients can receive it.
3918 */
3919 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
3920 sdata->vif.bss_conf.chanreq.oper.chan) {
3921 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3922 enum nl80211_band band;
3923
3924 band = sdata->vif.bss_conf.chanreq.oper.chan->band;
3925
3926 if (!(mask->control[band].legacy & basic_rates))
3927 return -EINVAL;
3928 }
3929
3930 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3931 ret = drv_set_bitrate_mask(local, sdata, mask);
3932 if (ret)
3933 return ret;
3934 }
3935
3936 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3937 struct ieee80211_supported_band *sband = wiphy->bands[i];
3938 int j;
3939
3940 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
3941 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3942 sizeof(mask->control[i].ht_mcs));
3943 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3944 mask->control[i].vht_mcs,
3945 sizeof(mask->control[i].vht_mcs));
3946
3947 sdata->rc_has_mcs_mask[i] = false;
3948 sdata->rc_has_vht_mcs_mask[i] = false;
3949 if (!sband)
3950 continue;
3951
3952 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
3953 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
3954 sdata->rc_has_mcs_mask[i] = true;
3955 break;
3956 }
3957 }
3958
3959 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
3960 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
3961 sdata->rc_has_vht_mcs_mask[i] = true;
3962 break;
3963 }
3964 }
3965 }
3966
3967 return 0;
3968 }
3969
ieee80211_is_scan_ongoing(struct wiphy * wiphy,struct ieee80211_local * local,struct cfg80211_chan_def * chandef)3970 static bool ieee80211_is_scan_ongoing(struct wiphy *wiphy,
3971 struct ieee80211_local *local,
3972 struct cfg80211_chan_def *chandef)
3973 {
3974 struct cfg80211_scan_request *scan_req;
3975 int chan_radio_idx, req_radio_idx;
3976 struct ieee80211_roc_work *roc;
3977
3978 if (list_empty(&local->roc_list) && !local->scanning)
3979 return false;
3980
3981 req_radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chandef->chan);
3982
3983 if (local->scanning) {
3984 scan_req = wiphy_dereference(wiphy, local->scan_req);
3985 /*
3986 * Scan is going on but info is not there. Should not happen
3987 * but if it does, let's not take risk and assume we can't use
3988 * the hw hence return true
3989 */
3990 if (WARN_ON_ONCE(!scan_req))
3991 return true;
3992
3993 return ieee80211_is_radio_idx_in_scan_req(wiphy, scan_req,
3994 req_radio_idx);
3995 }
3996
3997 list_for_each_entry(roc, &local->roc_list, list) {
3998 chan_radio_idx = cfg80211_get_radio_idx_by_chan(wiphy,
3999 roc->chan);
4000 if (chan_radio_idx == req_radio_idx)
4001 return true;
4002 }
4003
4004 return false;
4005 }
4006
ieee80211_start_radar_detection(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_chan_def * chandef,u32 cac_time_ms,int link_id)4007 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
4008 struct net_device *dev,
4009 struct cfg80211_chan_def *chandef,
4010 u32 cac_time_ms, int link_id)
4011 {
4012 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4013 struct ieee80211_chan_req chanreq = { .oper = *chandef };
4014 struct ieee80211_local *local = sdata->local;
4015 struct ieee80211_link_data *link_data;
4016 int err;
4017
4018 lockdep_assert_wiphy(local->hw.wiphy);
4019
4020 if (ieee80211_is_scan_ongoing(wiphy, local, chandef))
4021 return -EBUSY;
4022
4023 link_data = sdata_dereference(sdata->link[link_id], sdata);
4024 if (!link_data)
4025 return -ENOLINK;
4026
4027 /* whatever, but channel contexts should not complain about that one */
4028 link_data->smps_mode = IEEE80211_SMPS_OFF;
4029 link_data->needed_rx_chains = local->rx_chains;
4030
4031 err = ieee80211_link_use_channel(link_data, &chanreq,
4032 IEEE80211_CHANCTX_SHARED);
4033 if (err)
4034 return err;
4035
4036 wiphy_hrtimer_work_queue(wiphy, &link_data->dfs_cac_timer_work,
4037 ms_to_ktime(cac_time_ms));
4038
4039 return 0;
4040 }
4041
ieee80211_end_cac(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id)4042 static void ieee80211_end_cac(struct wiphy *wiphy,
4043 struct net_device *dev, unsigned int link_id)
4044 {
4045 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4046 struct ieee80211_local *local = sdata->local;
4047 struct ieee80211_link_data *link_data;
4048
4049 lockdep_assert_wiphy(local->hw.wiphy);
4050
4051 list_for_each_entry(sdata, &local->interfaces, list) {
4052 link_data = sdata_dereference(sdata->link[link_id], sdata);
4053 if (!link_data)
4054 continue;
4055
4056 wiphy_hrtimer_work_cancel(wiphy,
4057 &link_data->dfs_cac_timer_work);
4058
4059 if (sdata->wdev.links[link_id].cac_started) {
4060 ieee80211_link_release_channel(link_data);
4061 sdata->wdev.links[link_id].cac_started = false;
4062 }
4063 }
4064 }
4065
4066 static struct cfg80211_beacon_data *
cfg80211_beacon_dup(struct cfg80211_beacon_data * beacon)4067 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
4068 {
4069 struct cfg80211_beacon_data *new_beacon;
4070 u8 *pos;
4071 int len;
4072
4073 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
4074 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
4075 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
4076
4077 if (beacon->mbssid_ies)
4078 len += ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies,
4079 beacon->rnr_ies,
4080 beacon->mbssid_ies->cnt);
4081
4082 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
4083 if (!new_beacon)
4084 return NULL;
4085
4086 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
4087 new_beacon->mbssid_ies =
4088 kzalloc_flex(*new_beacon->mbssid_ies, elem,
4089 beacon->mbssid_ies->cnt);
4090 if (!new_beacon->mbssid_ies) {
4091 kfree(new_beacon);
4092 return NULL;
4093 }
4094
4095 if (beacon->rnr_ies && beacon->rnr_ies->cnt) {
4096 new_beacon->rnr_ies =
4097 kzalloc_flex(*new_beacon->rnr_ies, elem,
4098 beacon->rnr_ies->cnt);
4099 if (!new_beacon->rnr_ies) {
4100 kfree(new_beacon->mbssid_ies);
4101 kfree(new_beacon);
4102 return NULL;
4103 }
4104 }
4105 }
4106
4107 pos = (u8 *)(new_beacon + 1);
4108 if (beacon->head_len) {
4109 new_beacon->head_len = beacon->head_len;
4110 new_beacon->head = pos;
4111 memcpy(pos, beacon->head, beacon->head_len);
4112 pos += beacon->head_len;
4113 }
4114 if (beacon->tail_len) {
4115 new_beacon->tail_len = beacon->tail_len;
4116 new_beacon->tail = pos;
4117 memcpy(pos, beacon->tail, beacon->tail_len);
4118 pos += beacon->tail_len;
4119 }
4120 if (beacon->beacon_ies_len) {
4121 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
4122 new_beacon->beacon_ies = pos;
4123 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
4124 pos += beacon->beacon_ies_len;
4125 }
4126 if (beacon->proberesp_ies_len) {
4127 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
4128 new_beacon->proberesp_ies = pos;
4129 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
4130 pos += beacon->proberesp_ies_len;
4131 }
4132 if (beacon->assocresp_ies_len) {
4133 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
4134 new_beacon->assocresp_ies = pos;
4135 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
4136 pos += beacon->assocresp_ies_len;
4137 }
4138 if (beacon->probe_resp_len) {
4139 new_beacon->probe_resp_len = beacon->probe_resp_len;
4140 new_beacon->probe_resp = pos;
4141 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
4142 pos += beacon->probe_resp_len;
4143 }
4144 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
4145 pos += ieee80211_copy_mbssid_beacon(pos,
4146 new_beacon->mbssid_ies,
4147 beacon->mbssid_ies);
4148 if (beacon->rnr_ies && beacon->rnr_ies->cnt)
4149 pos += ieee80211_copy_rnr_beacon(pos,
4150 new_beacon->rnr_ies,
4151 beacon->rnr_ies);
4152 }
4153
4154 /* might copy -1, meaning no changes requested */
4155 new_beacon->ftm_responder = beacon->ftm_responder;
4156 if (beacon->lci) {
4157 new_beacon->lci_len = beacon->lci_len;
4158 new_beacon->lci = pos;
4159 memcpy(pos, beacon->lci, beacon->lci_len);
4160 pos += beacon->lci_len;
4161 }
4162 if (beacon->civicloc) {
4163 new_beacon->civicloc_len = beacon->civicloc_len;
4164 new_beacon->civicloc = pos;
4165 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
4166 pos += beacon->civicloc_len;
4167 }
4168
4169 return new_beacon;
4170 }
4171
ieee80211_csa_finish(struct ieee80211_vif * vif,unsigned int link_id)4172 void ieee80211_csa_finish(struct ieee80211_vif *vif, unsigned int link_id)
4173 {
4174 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4175 struct ieee80211_local *local = sdata->local;
4176 struct ieee80211_bss_conf *tx_bss_conf;
4177 struct ieee80211_link_data *link_data;
4178
4179 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
4180 return;
4181
4182 rcu_read_lock();
4183
4184 link_data = rcu_dereference(sdata->link[link_id]);
4185 if (WARN_ON(!link_data)) {
4186 rcu_read_unlock();
4187 return;
4188 }
4189
4190 tx_bss_conf = rcu_dereference(link_data->conf->tx_bss_conf);
4191 if (tx_bss_conf == link_data->conf) {
4192 /* Trigger ieee80211_csa_finish() on the non-transmitting
4193 * interfaces when channel switch is received on
4194 * transmitting interface
4195 */
4196 struct ieee80211_link_data *iter;
4197
4198 for_each_sdata_link_rcu(local, iter) {
4199 if (iter->sdata == sdata ||
4200 rcu_access_pointer(iter->conf->tx_bss_conf) != tx_bss_conf)
4201 continue;
4202
4203 wiphy_work_queue(iter->sdata->local->hw.wiphy,
4204 &iter->csa.finalize_work);
4205 }
4206 }
4207
4208 wiphy_work_queue(local->hw.wiphy, &link_data->csa.finalize_work);
4209
4210 rcu_read_unlock();
4211 }
4212 EXPORT_SYMBOL(ieee80211_csa_finish);
4213
ieee80211_channel_switch_disconnect(struct ieee80211_vif * vif)4214 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif)
4215 {
4216 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4217 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4218 struct ieee80211_local *local = sdata->local;
4219
4220 sdata_info(sdata, "channel switch failed, disconnecting\n");
4221 wiphy_work_queue(local->hw.wiphy, &ifmgd->csa_connection_drop_work);
4222 }
4223 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
4224
ieee80211_set_after_csa_beacon(struct ieee80211_link_data * link_data,u64 * changed)4225 static int ieee80211_set_after_csa_beacon(struct ieee80211_link_data *link_data,
4226 u64 *changed)
4227 {
4228 struct ieee80211_sub_if_data *sdata = link_data->sdata;
4229 int err;
4230
4231 switch (sdata->vif.type) {
4232 case NL80211_IFTYPE_AP:
4233 if (!link_data->u.ap.next_beacon)
4234 return -EINVAL;
4235
4236 err = ieee80211_assign_beacon(sdata, link_data,
4237 link_data->u.ap.next_beacon,
4238 NULL, NULL, changed);
4239 ieee80211_free_next_beacon(link_data);
4240
4241 if (err < 0)
4242 return err;
4243 break;
4244 case NL80211_IFTYPE_ADHOC:
4245 err = ieee80211_ibss_finish_csa(sdata, changed);
4246 if (err < 0)
4247 return err;
4248 break;
4249 #ifdef CONFIG_MAC80211_MESH
4250 case NL80211_IFTYPE_MESH_POINT:
4251 err = ieee80211_mesh_finish_csa(sdata, changed);
4252 if (err < 0)
4253 return err;
4254 break;
4255 #endif
4256 default:
4257 WARN_ON(1);
4258 return -EINVAL;
4259 }
4260
4261 return 0;
4262 }
4263
__ieee80211_csa_finalize(struct ieee80211_link_data * link_data)4264 static int __ieee80211_csa_finalize(struct ieee80211_link_data *link_data)
4265 {
4266 struct ieee80211_sub_if_data *sdata = link_data->sdata;
4267 struct ieee80211_local *local = sdata->local;
4268 struct ieee80211_bss_conf *link_conf = link_data->conf;
4269 u64 changed = 0;
4270 int err;
4271
4272 lockdep_assert_wiphy(local->hw.wiphy);
4273
4274 /*
4275 * using reservation isn't immediate as it may be deferred until later
4276 * with multi-vif. once reservation is complete it will re-schedule the
4277 * work with no reserved_chanctx so verify chandef to check if it
4278 * completed successfully
4279 */
4280
4281 if (link_data->reserved_chanctx) {
4282 /*
4283 * with multi-vif csa driver may call ieee80211_csa_finish()
4284 * many times while waiting for other interfaces to use their
4285 * reservations
4286 */
4287 if (link_data->reserved_ready)
4288 return 0;
4289
4290 return ieee80211_link_use_reserved_context(link_data);
4291 }
4292
4293 if (!cfg80211_chandef_identical(&link_conf->chanreq.oper,
4294 &link_data->csa.chanreq.oper))
4295 return -EINVAL;
4296
4297 link_conf->csa_active = false;
4298
4299 err = ieee80211_set_after_csa_beacon(link_data, &changed);
4300 if (err)
4301 return err;
4302
4303 ieee80211_link_info_change_notify(sdata, link_data, changed);
4304
4305 ieee80211_vif_unblock_queues_csa(sdata);
4306
4307 err = drv_post_channel_switch(link_data);
4308 if (err)
4309 return err;
4310
4311 cfg80211_ch_switch_notify(sdata->dev, &link_data->csa.chanreq.oper,
4312 link_data->link_id);
4313
4314 return 0;
4315 }
4316
ieee80211_csa_finalize(struct ieee80211_link_data * link_data)4317 static void ieee80211_csa_finalize(struct ieee80211_link_data *link_data)
4318 {
4319 struct ieee80211_sub_if_data *sdata = link_data->sdata;
4320 int link_id = -1;
4321
4322 if (__ieee80211_csa_finalize(link_data)) {
4323 sdata_info(sdata, "failed to finalize CSA on link %d, disconnecting\n",
4324 link_data->link_id);
4325 if (sdata->vif.type == NL80211_IFTYPE_AP ||
4326 sdata->vif.type == NL80211_IFTYPE_P2P_GO)
4327 /*
4328 * link_id is expected only for AP/P2P_GO type
4329 * currently
4330 */
4331 link_id = link_data->link_id;
4332
4333 cfg80211_stop_link(sdata->local->hw.wiphy, &sdata->wdev,
4334 link_id, GFP_KERNEL);
4335 }
4336 }
4337
ieee80211_csa_finalize_work(struct wiphy * wiphy,struct wiphy_work * work)4338 void ieee80211_csa_finalize_work(struct wiphy *wiphy, struct wiphy_work *work)
4339 {
4340 struct ieee80211_link_data *link =
4341 container_of(work, struct ieee80211_link_data, csa.finalize_work);
4342 struct ieee80211_sub_if_data *sdata = link->sdata;
4343 struct ieee80211_local *local = sdata->local;
4344
4345 lockdep_assert_wiphy(local->hw.wiphy);
4346
4347 /* AP might have been stopped while waiting for the lock. */
4348 if (!link->conf->csa_active)
4349 return;
4350
4351 if (!ieee80211_sdata_running(sdata))
4352 return;
4353
4354 ieee80211_csa_finalize(link);
4355 }
4356
ieee80211_set_csa_beacon(struct ieee80211_link_data * link_data,struct cfg80211_csa_settings * params,u64 * changed)4357 static int ieee80211_set_csa_beacon(struct ieee80211_link_data *link_data,
4358 struct cfg80211_csa_settings *params,
4359 u64 *changed)
4360 {
4361 struct ieee80211_sub_if_data *sdata = link_data->sdata;
4362 struct ieee80211_csa_settings csa = {};
4363 int err;
4364
4365 switch (sdata->vif.type) {
4366 case NL80211_IFTYPE_AP:
4367 link_data->u.ap.next_beacon =
4368 cfg80211_beacon_dup(¶ms->beacon_after);
4369 if (!link_data->u.ap.next_beacon)
4370 return -ENOMEM;
4371
4372 /*
4373 * With a count of 0, we don't have to wait for any
4374 * TBTT before switching, so complete the CSA
4375 * immediately. In theory, with a count == 1 we
4376 * should delay the switch until just before the next
4377 * TBTT, but that would complicate things so we switch
4378 * immediately too. If we would delay the switch
4379 * until the next TBTT, we would have to set the probe
4380 * response here.
4381 *
4382 * TODO: A channel switch with count <= 1 without
4383 * sending a CSA action frame is kind of useless,
4384 * because the clients won't know we're changing
4385 * channels. The action frame must be implemented
4386 * either here or in the userspace.
4387 */
4388 if (params->count <= 1)
4389 break;
4390
4391 if ((params->n_counter_offsets_beacon >
4392 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
4393 (params->n_counter_offsets_presp >
4394 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
4395 ieee80211_free_next_beacon(link_data);
4396 return -EINVAL;
4397 }
4398
4399 csa.counter_offsets_beacon = params->counter_offsets_beacon;
4400 csa.counter_offsets_presp = params->counter_offsets_presp;
4401 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
4402 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
4403 csa.count = params->count;
4404
4405 err = ieee80211_assign_beacon(sdata, link_data,
4406 ¶ms->beacon_csa, &csa,
4407 NULL, changed);
4408 if (err < 0) {
4409 ieee80211_free_next_beacon(link_data);
4410 return err;
4411 }
4412
4413 break;
4414 case NL80211_IFTYPE_ADHOC:
4415 if (!sdata->vif.cfg.ibss_joined)
4416 return -EINVAL;
4417
4418 if (params->chandef.width != sdata->u.ibss.chandef.width)
4419 return -EINVAL;
4420
4421 switch (params->chandef.width) {
4422 case NL80211_CHAN_WIDTH_40:
4423 if (cfg80211_get_chandef_type(¶ms->chandef) !=
4424 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
4425 return -EINVAL;
4426 break;
4427 case NL80211_CHAN_WIDTH_5:
4428 case NL80211_CHAN_WIDTH_10:
4429 case NL80211_CHAN_WIDTH_20_NOHT:
4430 case NL80211_CHAN_WIDTH_20:
4431 break;
4432 default:
4433 return -EINVAL;
4434 }
4435
4436 /* changes into another band are not supported */
4437 if (sdata->u.ibss.chandef.chan->band !=
4438 params->chandef.chan->band)
4439 return -EINVAL;
4440
4441 /* see comments in the NL80211_IFTYPE_AP block */
4442 if (params->count > 1) {
4443 err = ieee80211_ibss_csa_beacon(sdata, params, changed);
4444 if (err < 0)
4445 return err;
4446 }
4447
4448 ieee80211_send_action_csa(sdata, params);
4449
4450 break;
4451 #ifdef CONFIG_MAC80211_MESH
4452 case NL80211_IFTYPE_MESH_POINT: {
4453 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
4454
4455 /* changes into another band are not supported */
4456 if (sdata->vif.bss_conf.chanreq.oper.chan->band !=
4457 params->chandef.chan->band)
4458 return -EINVAL;
4459
4460 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
4461 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
4462 if (!ifmsh->pre_value)
4463 ifmsh->pre_value = 1;
4464 else
4465 ifmsh->pre_value++;
4466 }
4467
4468 /* see comments in the NL80211_IFTYPE_AP block */
4469 if (params->count > 1) {
4470 err = ieee80211_mesh_csa_beacon(sdata, params, changed);
4471 if (err < 0) {
4472 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
4473 return err;
4474 }
4475 }
4476
4477 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
4478 ieee80211_send_action_csa(sdata, params);
4479
4480 break;
4481 }
4482 #endif
4483 default:
4484 return -EOPNOTSUPP;
4485 }
4486
4487 return 0;
4488 }
4489
ieee80211_color_change_abort(struct ieee80211_link_data * link)4490 static void ieee80211_color_change_abort(struct ieee80211_link_data *link)
4491 {
4492 link->conf->color_change_active = false;
4493
4494 ieee80211_free_next_beacon(link);
4495
4496 cfg80211_color_change_aborted_notify(link->sdata->dev, link->link_id);
4497 }
4498
4499 static int
__ieee80211_channel_switch(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_csa_settings * params)4500 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
4501 struct cfg80211_csa_settings *params)
4502 {
4503 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4504 struct ieee80211_chan_req chanreq = { .oper = params->chandef };
4505 struct ieee80211_local *local = sdata->local;
4506 struct ieee80211_channel_switch ch_switch = {
4507 .link_id = params->link_id,
4508 };
4509 struct ieee80211_chanctx_conf *conf;
4510 struct ieee80211_chanctx *chanctx;
4511 struct ieee80211_bss_conf *link_conf;
4512 struct ieee80211_link_data *link_data;
4513 u64 changed = 0;
4514 u8 link_id = params->link_id;
4515 int err;
4516
4517 lockdep_assert_wiphy(local->hw.wiphy);
4518
4519 if (ieee80211_is_scan_ongoing(wiphy, local, ¶ms->chandef))
4520 return -EBUSY;
4521
4522 if (sdata->wdev.links[link_id].cac_started)
4523 return -EBUSY;
4524
4525 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
4526 return -EINVAL;
4527
4528 link_data = wiphy_dereference(wiphy, sdata->link[link_id]);
4529 if (!link_data)
4530 return -ENOLINK;
4531
4532 link_conf = link_data->conf;
4533
4534 if (chanreq.oper.punctured && !link_conf->eht_support)
4535 return -EINVAL;
4536
4537 /* don't allow another channel switch if one is already active. */
4538 if (link_conf->csa_active)
4539 return -EBUSY;
4540
4541 conf = wiphy_dereference(wiphy, link_conf->chanctx_conf);
4542 if (!conf) {
4543 err = -EBUSY;
4544 goto out;
4545 }
4546
4547 if (params->chandef.chan->freq_offset) {
4548 /* this may work, but is untested */
4549 err = -EOPNOTSUPP;
4550 goto out;
4551 }
4552
4553 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
4554 ¶ms->unsol_bcast_probe_resp,
4555 link_data, link_conf, &changed);
4556 if (err)
4557 goto out;
4558
4559 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
4560
4561 ch_switch.timestamp = 0;
4562 ch_switch.device_timestamp = 0;
4563 ch_switch.block_tx = params->block_tx;
4564 ch_switch.chandef = chanreq.oper;
4565 ch_switch.count = params->count;
4566
4567 err = drv_pre_channel_switch(sdata, &ch_switch);
4568 if (err)
4569 goto out;
4570
4571 err = ieee80211_link_reserve_chanctx(link_data, &chanreq,
4572 chanctx->mode,
4573 params->radar_required);
4574 if (err)
4575 goto out;
4576
4577 /* if reservation is invalid then this will fail */
4578 err = ieee80211_check_combinations(sdata, NULL, 0, 0, -1);
4579 if (err) {
4580 ieee80211_link_unreserve_chanctx(link_data);
4581 goto out;
4582 }
4583
4584 /* if there is a color change in progress, abort it */
4585 if (link_conf->color_change_active)
4586 ieee80211_color_change_abort(link_data);
4587
4588 err = ieee80211_set_csa_beacon(link_data, params, &changed);
4589 if (err) {
4590 ieee80211_link_unreserve_chanctx(link_data);
4591 goto out;
4592 }
4593
4594 link_data->csa.chanreq = chanreq;
4595 link_conf->csa_active = true;
4596
4597 if (params->block_tx)
4598 ieee80211_vif_block_queues_csa(sdata);
4599
4600 cfg80211_ch_switch_started_notify(sdata->dev,
4601 &link_data->csa.chanreq.oper, link_id,
4602 params->count, params->block_tx);
4603
4604 if (changed) {
4605 ieee80211_link_info_change_notify(sdata, link_data, changed);
4606 drv_channel_switch_beacon(sdata, &link_data->csa.chanreq.oper);
4607 } else {
4608 /* if the beacon didn't change, we can finalize immediately */
4609 ieee80211_csa_finalize(link_data);
4610 }
4611
4612 out:
4613 return err;
4614 }
4615
ieee80211_channel_switch(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_csa_settings * params)4616 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
4617 struct cfg80211_csa_settings *params)
4618 {
4619 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4620 struct ieee80211_local *local = sdata->local;
4621
4622 lockdep_assert_wiphy(local->hw.wiphy);
4623
4624 return __ieee80211_channel_switch(wiphy, dev, params);
4625 }
4626
ieee80211_mgmt_tx_cookie(struct ieee80211_local * local)4627 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
4628 {
4629 lockdep_assert_wiphy(local->hw.wiphy);
4630
4631 local->roc_cookie_counter++;
4632
4633 /* wow, you wrapped 64 bits ... more likely a bug */
4634 if (WARN_ON(local->roc_cookie_counter == 0))
4635 local->roc_cookie_counter++;
4636
4637 return local->roc_cookie_counter;
4638 }
4639
ieee80211_attach_ack_skb(struct ieee80211_local * local,struct sk_buff * skb,u64 * cookie,gfp_t gfp)4640 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
4641 u64 *cookie, gfp_t gfp)
4642 {
4643 unsigned long spin_flags;
4644 struct sk_buff *ack_skb;
4645 int id;
4646
4647 ack_skb = skb_copy(skb, gfp);
4648 if (!ack_skb)
4649 return -ENOMEM;
4650
4651 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
4652 id = idr_alloc(&local->ack_status_frames, ack_skb,
4653 1, 0x2000, GFP_ATOMIC);
4654 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
4655
4656 if (id < 0) {
4657 kfree_skb(ack_skb);
4658 return -ENOMEM;
4659 }
4660
4661 IEEE80211_SKB_CB(skb)->status_data_idr = 1;
4662 IEEE80211_SKB_CB(skb)->status_data = id;
4663
4664 *cookie = ieee80211_mgmt_tx_cookie(local);
4665 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
4666
4667 return 0;
4668 }
4669
4670 static void
ieee80211_update_mgmt_frame_registrations(struct wiphy * wiphy,struct wireless_dev * wdev,struct mgmt_frame_regs * upd)4671 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
4672 struct wireless_dev *wdev,
4673 struct mgmt_frame_regs *upd)
4674 {
4675 struct ieee80211_local *local = wiphy_priv(wiphy);
4676 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4677 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
4678 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
4679 bool global_change, intf_change;
4680
4681 global_change =
4682 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
4683 (local->rx_mcast_action_reg !=
4684 !!(upd->global_mcast_stypes & action_mask));
4685 local->probe_req_reg = upd->global_stypes & preq_mask;
4686 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
4687
4688 intf_change = (sdata->vif.probe_req_reg !=
4689 !!(upd->interface_stypes & preq_mask)) ||
4690 (sdata->vif.rx_mcast_action_reg !=
4691 !!(upd->interface_mcast_stypes & action_mask));
4692 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
4693 sdata->vif.rx_mcast_action_reg =
4694 upd->interface_mcast_stypes & action_mask;
4695
4696 if (!local->open_count)
4697 return;
4698
4699 if (intf_change && ieee80211_sdata_running(sdata))
4700 drv_config_iface_filter(local, sdata,
4701 sdata->vif.probe_req_reg ?
4702 FIF_PROBE_REQ : 0,
4703 FIF_PROBE_REQ);
4704
4705 if (global_change)
4706 ieee80211_configure_filter(local);
4707 }
4708
ieee80211_set_antenna(struct wiphy * wiphy,int radio_idx,u32 tx_ant,u32 rx_ant)4709 static int ieee80211_set_antenna(struct wiphy *wiphy, int radio_idx,
4710 u32 tx_ant, u32 rx_ant)
4711 {
4712 struct ieee80211_local *local = wiphy_priv(wiphy);
4713 int ret;
4714
4715 if (local->started)
4716 return -EOPNOTSUPP;
4717
4718 ret = drv_set_antenna(local, tx_ant, rx_ant);
4719 if (ret)
4720 return ret;
4721
4722 local->rx_chains = hweight8(rx_ant);
4723 return 0;
4724 }
4725
ieee80211_get_antenna(struct wiphy * wiphy,int radio_idx,u32 * tx_ant,u32 * rx_ant)4726 static int ieee80211_get_antenna(struct wiphy *wiphy, int radio_idx,
4727 u32 *tx_ant, u32 *rx_ant)
4728 {
4729 struct ieee80211_local *local = wiphy_priv(wiphy);
4730
4731 return drv_get_antenna(local, radio_idx, tx_ant, rx_ant);
4732 }
4733
ieee80211_set_rekey_data(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_gtk_rekey_data * data)4734 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
4735 struct net_device *dev,
4736 struct cfg80211_gtk_rekey_data *data)
4737 {
4738 struct ieee80211_local *local = wiphy_priv(wiphy);
4739 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4740
4741 if (!local->ops->set_rekey_data)
4742 return -EOPNOTSUPP;
4743
4744 drv_set_rekey_data(local, sdata, data);
4745
4746 return 0;
4747 }
4748
ieee80211_probe_client(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u64 * cookie)4749 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
4750 const u8 *peer, u64 *cookie)
4751 {
4752 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4753 struct ieee80211_local *local = sdata->local;
4754 struct ieee80211_qos_hdr *nullfunc;
4755 struct sk_buff *skb;
4756 int size = sizeof(*nullfunc);
4757 __le16 fc;
4758 bool qos;
4759 struct ieee80211_tx_info *info;
4760 struct sta_info *sta;
4761 struct ieee80211_chanctx_conf *chanctx_conf;
4762 struct ieee80211_bss_conf *conf;
4763 enum nl80211_band band;
4764 u8 link_id;
4765 int ret;
4766
4767 /* the lock is needed to assign the cookie later */
4768 lockdep_assert_wiphy(local->hw.wiphy);
4769
4770 rcu_read_lock();
4771 sta = sta_info_get_bss(sdata, peer);
4772 if (!sta) {
4773 ret = -ENOLINK;
4774 goto unlock;
4775 }
4776
4777 qos = sta->sta.wme;
4778
4779 if (ieee80211_vif_is_mld(&sdata->vif)) {
4780 if (sta->sta.mlo) {
4781 link_id = IEEE80211_LINK_UNSPECIFIED;
4782 } else {
4783 /*
4784 * For non-MLO clients connected to an AP MLD, band
4785 * information is not used; instead, sta->deflink is
4786 * used to send packets.
4787 */
4788 link_id = sta->deflink.link_id;
4789
4790 conf = rcu_dereference(sdata->vif.link_conf[link_id]);
4791
4792 if (unlikely(!conf)) {
4793 ret = -ENOLINK;
4794 goto unlock;
4795 }
4796 }
4797 /* MLD transmissions must not rely on the band */
4798 band = 0;
4799 } else {
4800 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
4801 if (WARN_ON(!chanctx_conf)) {
4802 ret = -EINVAL;
4803 goto unlock;
4804 }
4805 band = chanctx_conf->def.chan->band;
4806 link_id = 0;
4807 }
4808
4809 if (qos) {
4810 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4811 IEEE80211_STYPE_QOS_NULLFUNC |
4812 IEEE80211_FCTL_FROMDS);
4813 } else {
4814 size -= 2;
4815 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4816 IEEE80211_STYPE_NULLFUNC |
4817 IEEE80211_FCTL_FROMDS);
4818 }
4819
4820 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
4821 if (!skb) {
4822 ret = -ENOMEM;
4823 goto unlock;
4824 }
4825
4826 skb->dev = dev;
4827
4828 skb_reserve(skb, local->hw.extra_tx_headroom);
4829
4830 nullfunc = skb_put(skb, size);
4831 nullfunc->frame_control = fc;
4832 nullfunc->duration_id = 0;
4833 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
4834 if (ieee80211_vif_is_mld(&sdata->vif) && !sta->sta.mlo) {
4835 memcpy(nullfunc->addr2, conf->addr, ETH_ALEN);
4836 memcpy(nullfunc->addr3, conf->addr, ETH_ALEN);
4837 } else {
4838 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
4839 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
4840 }
4841 nullfunc->seq_ctrl = 0;
4842
4843 info = IEEE80211_SKB_CB(skb);
4844
4845 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
4846 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
4847 info->band = band;
4848
4849 info->control.flags |= u32_encode_bits(link_id,
4850 IEEE80211_TX_CTRL_MLO_LINK);
4851 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
4852 skb->priority = 7;
4853 if (qos)
4854 nullfunc->qos_ctrl = cpu_to_le16(7);
4855
4856 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
4857 if (ret) {
4858 kfree_skb(skb);
4859 goto unlock;
4860 }
4861
4862 local_bh_disable();
4863 ieee80211_xmit(sdata, sta, skb);
4864 local_bh_enable();
4865
4866 ret = 0;
4867 unlock:
4868 rcu_read_unlock();
4869
4870 return ret;
4871 }
4872
ieee80211_cfg_get_channel(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id,struct cfg80211_chan_def * chandef)4873 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
4874 struct wireless_dev *wdev,
4875 unsigned int link_id,
4876 struct cfg80211_chan_def *chandef)
4877 {
4878 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4879 struct ieee80211_local *local = wiphy_priv(wiphy);
4880 struct ieee80211_chanctx_conf *chanctx_conf;
4881 struct ieee80211_link_data *link;
4882 int ret = -ENODATA;
4883
4884 rcu_read_lock();
4885 link = rcu_dereference(sdata->link[link_id]);
4886 if (!link) {
4887 ret = -ENOLINK;
4888 goto out;
4889 }
4890
4891 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
4892 if (chanctx_conf) {
4893 *chandef = link->conf->chanreq.oper;
4894 ret = 0;
4895 } else if (local->open_count > 0 &&
4896 local->open_count == local->virt_monitors &&
4897 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
4898 *chandef = local->monitor_chanreq.oper;
4899 ret = 0;
4900 }
4901 out:
4902 rcu_read_unlock();
4903
4904 return ret;
4905 }
4906
4907 #ifdef CONFIG_PM
ieee80211_set_wakeup(struct wiphy * wiphy,bool enabled)4908 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
4909 {
4910 drv_set_wakeup(wiphy_priv(wiphy), enabled);
4911 }
4912 #endif
4913
ieee80211_set_qos_map(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_qos_map * qos_map)4914 static int ieee80211_set_qos_map(struct wiphy *wiphy,
4915 struct net_device *dev,
4916 struct cfg80211_qos_map *qos_map)
4917 {
4918 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4919 struct mac80211_qos_map *new_qos_map, *old_qos_map;
4920
4921 if (qos_map) {
4922 new_qos_map = kzalloc_obj(*new_qos_map);
4923 if (!new_qos_map)
4924 return -ENOMEM;
4925 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
4926 } else {
4927 /* A NULL qos_map was passed to disable QoS mapping */
4928 new_qos_map = NULL;
4929 }
4930
4931 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
4932 rcu_assign_pointer(sdata->qos_map, new_qos_map);
4933 if (old_qos_map)
4934 kfree_rcu(old_qos_map, rcu_head);
4935
4936 return 0;
4937 }
4938
ieee80211_set_ap_chanwidth(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id,struct cfg80211_chan_def * chandef)4939 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
4940 struct net_device *dev,
4941 unsigned int link_id,
4942 struct cfg80211_chan_def *chandef)
4943 {
4944 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4945 struct ieee80211_link_data *link;
4946 struct ieee80211_chan_req chanreq = { .oper = *chandef };
4947 int ret;
4948 u64 changed = 0;
4949
4950 link = sdata_dereference(sdata->link[link_id], sdata);
4951
4952 ret = ieee80211_link_change_chanreq(link, &chanreq, &changed);
4953 if (ret == 0)
4954 ieee80211_link_info_change_notify(sdata, link, changed);
4955
4956 return ret;
4957 }
4958
ieee80211_add_tx_ts(struct wiphy * wiphy,struct net_device * dev,u8 tsid,const u8 * peer,u8 up,u16 admitted_time)4959 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4960 u8 tsid, const u8 *peer, u8 up,
4961 u16 admitted_time)
4962 {
4963 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4964 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4965 int ac = ieee802_1d_to_ac[up];
4966
4967 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4968 return -EOPNOTSUPP;
4969
4970 if (!(sdata->wmm_acm & BIT(up)))
4971 return -EINVAL;
4972
4973 if (ifmgd->tx_tspec[ac].admitted_time)
4974 return -EBUSY;
4975
4976 if (admitted_time) {
4977 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4978 ifmgd->tx_tspec[ac].tsid = tsid;
4979 ifmgd->tx_tspec[ac].up = up;
4980 }
4981
4982 return 0;
4983 }
4984
ieee80211_del_tx_ts(struct wiphy * wiphy,struct net_device * dev,u8 tsid,const u8 * peer)4985 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4986 u8 tsid, const u8 *peer)
4987 {
4988 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4989 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4990 struct ieee80211_local *local = wiphy_priv(wiphy);
4991 int ac;
4992
4993 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4994 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4995
4996 /* skip unused entries */
4997 if (!tx_tspec->admitted_time)
4998 continue;
4999
5000 if (tx_tspec->tsid != tsid)
5001 continue;
5002
5003 /* due to this new packets will be reassigned to non-ACM ACs */
5004 tx_tspec->up = -1;
5005
5006 /* Make sure that all packets have been sent to avoid to
5007 * restore the QoS params on packets that are still on the
5008 * queues.
5009 */
5010 synchronize_net();
5011 ieee80211_flush_queues(local, sdata, false);
5012
5013 /* restore the normal QoS parameters
5014 * (unconditionally to avoid races)
5015 */
5016 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
5017 tx_tspec->downgraded = false;
5018 ieee80211_sta_handle_tspec_ac_params(sdata);
5019
5020 /* finally clear all the data */
5021 memset(tx_tspec, 0, sizeof(*tx_tspec));
5022
5023 return 0;
5024 }
5025
5026 return -ENOENT;
5027 }
5028
ieee80211_nan_func_terminated(struct ieee80211_vif * vif,u8 inst_id,enum nl80211_nan_func_term_reason reason,gfp_t gfp)5029 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
5030 u8 inst_id,
5031 enum nl80211_nan_func_term_reason reason,
5032 gfp_t gfp)
5033 {
5034 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5035 struct cfg80211_nan_func *func;
5036 u64 cookie;
5037
5038 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
5039 return;
5040
5041 if (WARN_ON(sdata->local->hw.wiphy->nan_capa.flags &
5042 WIPHY_NAN_FLAGS_USERSPACE_DE))
5043 return;
5044
5045 spin_lock_bh(&sdata->u.nan.de.func_lock);
5046
5047 func = idr_find(&sdata->u.nan.de.function_inst_ids, inst_id);
5048 if (WARN_ON(!func)) {
5049 spin_unlock_bh(&sdata->u.nan.de.func_lock);
5050 return;
5051 }
5052
5053 cookie = func->cookie;
5054 idr_remove(&sdata->u.nan.de.function_inst_ids, inst_id);
5055
5056 spin_unlock_bh(&sdata->u.nan.de.func_lock);
5057
5058 cfg80211_free_nan_func(func);
5059
5060 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
5061 reason, cookie, gfp);
5062 }
5063 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
5064
ieee80211_nan_func_match(struct ieee80211_vif * vif,struct cfg80211_nan_match_params * match,gfp_t gfp)5065 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
5066 struct cfg80211_nan_match_params *match,
5067 gfp_t gfp)
5068 {
5069 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5070 struct cfg80211_nan_func *func;
5071
5072 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
5073 return;
5074
5075 if (WARN_ON(sdata->local->hw.wiphy->nan_capa.flags &
5076 WIPHY_NAN_FLAGS_USERSPACE_DE))
5077 return;
5078
5079 spin_lock_bh(&sdata->u.nan.de.func_lock);
5080
5081 func = idr_find(&sdata->u.nan.de.function_inst_ids, match->inst_id);
5082 if (WARN_ON(!func)) {
5083 spin_unlock_bh(&sdata->u.nan.de.func_lock);
5084 return;
5085 }
5086 match->cookie = func->cookie;
5087
5088 spin_unlock_bh(&sdata->u.nan.de.func_lock);
5089
5090 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
5091 }
5092 EXPORT_SYMBOL(ieee80211_nan_func_match);
5093
ieee80211_set_multicast_to_unicast(struct wiphy * wiphy,struct net_device * dev,const bool enabled)5094 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
5095 struct net_device *dev,
5096 const bool enabled)
5097 {
5098 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5099
5100 sdata->u.ap.multicast_to_unicast = enabled;
5101
5102 return 0;
5103 }
5104
ieee80211_fill_txq_stats(struct cfg80211_txq_stats * txqstats,struct txq_info * txqi)5105 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
5106 struct txq_info *txqi)
5107 {
5108 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
5109 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
5110 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
5111 }
5112
5113 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
5114 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
5115 txqstats->backlog_packets = txqi->tin.backlog_packets;
5116 }
5117
5118 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
5119 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
5120 txqstats->flows = txqi->tin.flows;
5121 }
5122
5123 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
5124 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
5125 txqstats->drops = txqi->cstats.drop_count;
5126 }
5127
5128 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
5129 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
5130 txqstats->ecn_marks = txqi->cstats.ecn_mark;
5131 }
5132
5133 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
5134 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
5135 txqstats->overlimit = txqi->tin.overlimit;
5136 }
5137
5138 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
5139 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
5140 txqstats->collisions = txqi->tin.collisions;
5141 }
5142
5143 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
5144 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
5145 txqstats->tx_bytes = txqi->tin.tx_bytes;
5146 }
5147
5148 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
5149 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
5150 txqstats->tx_packets = txqi->tin.tx_packets;
5151 }
5152 }
5153
ieee80211_get_txq_stats(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_txq_stats * txqstats)5154 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
5155 struct wireless_dev *wdev,
5156 struct cfg80211_txq_stats *txqstats)
5157 {
5158 struct ieee80211_local *local = wiphy_priv(wiphy);
5159 struct ieee80211_sub_if_data *sdata;
5160 int ret = 0;
5161
5162 spin_lock_bh(&local->fq.lock);
5163
5164 if (wdev) {
5165 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
5166 if (!sdata->vif.txq) {
5167 ret = 1;
5168 goto out;
5169 }
5170 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
5171 } else {
5172 /* phy stats */
5173 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
5174 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
5175 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
5176 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
5177 BIT(NL80211_TXQ_STATS_COLLISIONS) |
5178 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
5179 txqstats->backlog_packets = local->fq.backlog;
5180 txqstats->backlog_bytes = local->fq.memory_usage;
5181 txqstats->overlimit = local->fq.overlimit;
5182 txqstats->overmemory = local->fq.overmemory;
5183 txqstats->collisions = local->fq.collisions;
5184 txqstats->max_flows = local->fq.flows_cnt;
5185 }
5186
5187 out:
5188 spin_unlock_bh(&local->fq.lock);
5189
5190 return ret;
5191 }
5192
5193 static int
ieee80211_get_ftm_responder_stats(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ftm_responder_stats * ftm_stats)5194 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
5195 struct net_device *dev,
5196 struct cfg80211_ftm_responder_stats *ftm_stats)
5197 {
5198 struct ieee80211_local *local = wiphy_priv(wiphy);
5199 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5200
5201 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
5202 }
5203
5204 static int
ieee80211_start_pmsr(struct wiphy * wiphy,struct wireless_dev * dev,struct cfg80211_pmsr_request * request)5205 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
5206 struct cfg80211_pmsr_request *request)
5207 {
5208 struct ieee80211_local *local = wiphy_priv(wiphy);
5209 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
5210
5211 return drv_start_pmsr(local, sdata, request);
5212 }
5213
5214 static void
ieee80211_abort_pmsr(struct wiphy * wiphy,struct wireless_dev * dev,struct cfg80211_pmsr_request * request)5215 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
5216 struct cfg80211_pmsr_request *request)
5217 {
5218 struct ieee80211_local *local = wiphy_priv(wiphy);
5219 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
5220
5221 return drv_abort_pmsr(local, sdata, request);
5222 }
5223
ieee80211_set_tid_config(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_tid_config * tid_conf)5224 static int ieee80211_set_tid_config(struct wiphy *wiphy,
5225 struct net_device *dev,
5226 struct cfg80211_tid_config *tid_conf)
5227 {
5228 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5229 struct sta_info *sta;
5230
5231 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5232
5233 if (!sdata->local->ops->set_tid_config)
5234 return -EOPNOTSUPP;
5235
5236 if (!tid_conf->peer)
5237 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
5238
5239 sta = sta_info_get_bss(sdata, tid_conf->peer);
5240 if (!sta)
5241 return -ENOENT;
5242
5243 return drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
5244 }
5245
ieee80211_reset_tid_config(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u8 tids)5246 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
5247 struct net_device *dev,
5248 const u8 *peer, u8 tids)
5249 {
5250 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5251 struct sta_info *sta;
5252
5253 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5254
5255 if (!sdata->local->ops->reset_tid_config)
5256 return -EOPNOTSUPP;
5257
5258 if (!peer)
5259 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
5260
5261 sta = sta_info_get_bss(sdata, peer);
5262 if (!sta)
5263 return -ENOENT;
5264
5265 return drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
5266 }
5267
ieee80211_set_sar_specs(struct wiphy * wiphy,struct cfg80211_sar_specs * sar)5268 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
5269 struct cfg80211_sar_specs *sar)
5270 {
5271 struct ieee80211_local *local = wiphy_priv(wiphy);
5272
5273 if (!local->ops->set_sar_specs)
5274 return -EOPNOTSUPP;
5275
5276 return local->ops->set_sar_specs(&local->hw, sar);
5277 }
5278
5279 static int
ieee80211_set_after_color_change_beacon(struct ieee80211_link_data * link,u64 * changed)5280 ieee80211_set_after_color_change_beacon(struct ieee80211_link_data *link,
5281 u64 *changed)
5282 {
5283 struct ieee80211_sub_if_data *sdata = link->sdata;
5284
5285 switch (sdata->vif.type) {
5286 case NL80211_IFTYPE_AP: {
5287 int ret;
5288
5289 if (!link->u.ap.next_beacon)
5290 return -EINVAL;
5291
5292 ret = ieee80211_assign_beacon(sdata, link,
5293 link->u.ap.next_beacon,
5294 NULL, NULL, changed);
5295 ieee80211_free_next_beacon(link);
5296
5297 if (ret < 0)
5298 return ret;
5299
5300 break;
5301 }
5302 default:
5303 WARN_ON_ONCE(1);
5304 return -EINVAL;
5305 }
5306
5307 return 0;
5308 }
5309
5310 static int
ieee80211_set_color_change_beacon(struct ieee80211_link_data * link,struct cfg80211_color_change_settings * params,u64 * changed)5311 ieee80211_set_color_change_beacon(struct ieee80211_link_data *link,
5312 struct cfg80211_color_change_settings *params,
5313 u64 *changed)
5314 {
5315 struct ieee80211_sub_if_data *sdata = link->sdata;
5316 struct ieee80211_color_change_settings color_change = {};
5317 int err;
5318
5319 switch (sdata->vif.type) {
5320 case NL80211_IFTYPE_AP:
5321 link->u.ap.next_beacon =
5322 cfg80211_beacon_dup(¶ms->beacon_next);
5323 if (!link->u.ap.next_beacon)
5324 return -ENOMEM;
5325
5326 if (params->count <= 1)
5327 break;
5328
5329 color_change.counter_offset_beacon =
5330 params->counter_offset_beacon;
5331 color_change.counter_offset_presp =
5332 params->counter_offset_presp;
5333 color_change.count = params->count;
5334
5335 err = ieee80211_assign_beacon(sdata, link,
5336 ¶ms->beacon_color_change,
5337 NULL, &color_change, changed);
5338 if (err < 0) {
5339 ieee80211_free_next_beacon(link);
5340 return err;
5341 }
5342 break;
5343 default:
5344 return -EOPNOTSUPP;
5345 }
5346
5347 return 0;
5348 }
5349
5350 static void
ieee80211_color_change_bss_config_notify(struct ieee80211_link_data * link,u8 color,int enable,u64 changed)5351 ieee80211_color_change_bss_config_notify(struct ieee80211_link_data *link,
5352 u8 color, int enable, u64 changed)
5353 {
5354 struct ieee80211_sub_if_data *sdata = link->sdata;
5355
5356 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5357
5358 link->conf->he_bss_color.color = color;
5359 link->conf->he_bss_color.enabled = enable;
5360 changed |= BSS_CHANGED_HE_BSS_COLOR;
5361
5362 ieee80211_link_info_change_notify(sdata, link, changed);
5363
5364 if (!link->conf->nontransmitted &&
5365 rcu_access_pointer(link->conf->tx_bss_conf)) {
5366 struct ieee80211_link_data *tmp;
5367
5368 for_each_sdata_link(sdata->local, tmp) {
5369 if (tmp->sdata == sdata ||
5370 rcu_access_pointer(tmp->conf->tx_bss_conf) != link->conf)
5371 continue;
5372
5373 tmp->conf->he_bss_color.color = color;
5374 tmp->conf->he_bss_color.enabled = enable;
5375 ieee80211_link_info_change_notify(tmp->sdata, tmp,
5376 BSS_CHANGED_HE_BSS_COLOR);
5377 }
5378 }
5379 }
5380
ieee80211_color_change_finalize(struct ieee80211_link_data * link)5381 static int ieee80211_color_change_finalize(struct ieee80211_link_data *link)
5382 {
5383 struct ieee80211_sub_if_data *sdata = link->sdata;
5384 struct ieee80211_local *local = sdata->local;
5385 u64 changed = 0;
5386 int err;
5387
5388 lockdep_assert_wiphy(local->hw.wiphy);
5389
5390 link->conf->color_change_active = false;
5391
5392 err = ieee80211_set_after_color_change_beacon(link, &changed);
5393 if (err) {
5394 cfg80211_color_change_aborted_notify(sdata->dev, link->link_id);
5395 return err;
5396 }
5397
5398 ieee80211_color_change_bss_config_notify(link,
5399 link->conf->color_change_color,
5400 1, changed);
5401 cfg80211_color_change_notify(sdata->dev, link->link_id);
5402
5403 return 0;
5404 }
5405
ieee80211_color_change_finalize_work(struct wiphy * wiphy,struct wiphy_work * work)5406 void ieee80211_color_change_finalize_work(struct wiphy *wiphy,
5407 struct wiphy_work *work)
5408 {
5409 struct ieee80211_link_data *link =
5410 container_of(work, struct ieee80211_link_data,
5411 color_change_finalize_work);
5412 struct ieee80211_sub_if_data *sdata = link->sdata;
5413 struct ieee80211_bss_conf *link_conf = link->conf;
5414 struct ieee80211_local *local = sdata->local;
5415
5416 lockdep_assert_wiphy(local->hw.wiphy);
5417
5418 /* AP might have been stopped while waiting for the lock. */
5419 if (!link_conf->color_change_active)
5420 return;
5421
5422 if (!ieee80211_sdata_running(sdata))
5423 return;
5424
5425 ieee80211_color_change_finalize(link);
5426 }
5427
ieee80211_color_collision_detection_work(struct wiphy * wiphy,struct wiphy_work * work)5428 void ieee80211_color_collision_detection_work(struct wiphy *wiphy,
5429 struct wiphy_work *work)
5430 {
5431 struct ieee80211_link_data *link =
5432 container_of(work, struct ieee80211_link_data,
5433 color_collision_detect_work.work);
5434 struct ieee80211_sub_if_data *sdata = link->sdata;
5435
5436 cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap,
5437 link->link_id);
5438 }
5439
ieee80211_color_change_finish(struct ieee80211_vif * vif,u8 link_id)5440 void ieee80211_color_change_finish(struct ieee80211_vif *vif, u8 link_id)
5441 {
5442 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5443 struct ieee80211_link_data *link;
5444
5445 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5446 return;
5447
5448 rcu_read_lock();
5449
5450 link = rcu_dereference(sdata->link[link_id]);
5451 if (WARN_ON(!link)) {
5452 rcu_read_unlock();
5453 return;
5454 }
5455
5456 wiphy_work_queue(sdata->local->hw.wiphy,
5457 &link->color_change_finalize_work);
5458
5459 rcu_read_unlock();
5460 }
5461 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
5462
5463 void
ieee80211_obss_color_collision_notify(struct ieee80211_vif * vif,u64 color_bitmap,u8 link_id)5464 ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
5465 u64 color_bitmap, u8 link_id)
5466 {
5467 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5468 struct ieee80211_link_data *link;
5469
5470 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5471 return;
5472
5473 rcu_read_lock();
5474
5475 link = rcu_dereference(sdata->link[link_id]);
5476 if (WARN_ON(!link)) {
5477 rcu_read_unlock();
5478 return;
5479 }
5480
5481 if (link->conf->color_change_active || link->conf->csa_active) {
5482 rcu_read_unlock();
5483 return;
5484 }
5485
5486 if (wiphy_delayed_work_pending(sdata->local->hw.wiphy,
5487 &link->color_collision_detect_work)) {
5488 rcu_read_unlock();
5489 return;
5490 }
5491
5492 link->color_bitmap = color_bitmap;
5493 /* queue the color collision detection event every 500 ms in order to
5494 * avoid sending too much netlink messages to userspace.
5495 */
5496 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
5497 &link->color_collision_detect_work,
5498 msecs_to_jiffies(500));
5499
5500 rcu_read_unlock();
5501 }
5502 EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify);
5503
5504 static int
ieee80211_color_change(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_color_change_settings * params)5505 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
5506 struct cfg80211_color_change_settings *params)
5507 {
5508 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5509 struct ieee80211_local *local = sdata->local;
5510 struct ieee80211_bss_conf *link_conf;
5511 struct ieee80211_link_data *link;
5512 u8 link_id = params->link_id;
5513 u64 changed = 0;
5514 int err;
5515
5516 lockdep_assert_wiphy(local->hw.wiphy);
5517
5518 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5519 return -EINVAL;
5520
5521 link = wiphy_dereference(wiphy, sdata->link[link_id]);
5522 if (!link)
5523 return -ENOLINK;
5524
5525 link_conf = link->conf;
5526
5527 if (link_conf->nontransmitted)
5528 return -EINVAL;
5529
5530 /* don't allow another color change if one is already active or if csa
5531 * is active
5532 */
5533 if (link_conf->color_change_active || link_conf->csa_active) {
5534 err = -EBUSY;
5535 goto out;
5536 }
5537
5538 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
5539 ¶ms->unsol_bcast_probe_resp,
5540 link, link_conf, &changed);
5541 if (err)
5542 goto out;
5543
5544 err = ieee80211_set_color_change_beacon(link, params, &changed);
5545 if (err)
5546 goto out;
5547
5548 link_conf->color_change_active = true;
5549 link_conf->color_change_color = params->color;
5550
5551 cfg80211_color_change_started_notify(sdata->dev, params->count, link_id);
5552
5553 if (changed)
5554 ieee80211_color_change_bss_config_notify(link, 0, 0, changed);
5555 else
5556 /* if the beacon didn't change, we can finalize immediately */
5557 ieee80211_color_change_finalize(link);
5558
5559 out:
5560
5561 return err;
5562 }
5563
5564 static int
ieee80211_set_radar_background(struct wiphy * wiphy,struct cfg80211_chan_def * chandef)5565 ieee80211_set_radar_background(struct wiphy *wiphy,
5566 struct cfg80211_chan_def *chandef)
5567 {
5568 struct ieee80211_local *local = wiphy_priv(wiphy);
5569
5570 if (!local->ops->set_radar_background)
5571 return -EOPNOTSUPP;
5572
5573 return local->ops->set_radar_background(&local->hw, chandef);
5574 }
5575
ieee80211_add_intf_link(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id)5576 static int ieee80211_add_intf_link(struct wiphy *wiphy,
5577 struct wireless_dev *wdev,
5578 unsigned int link_id)
5579 {
5580 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
5581
5582 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5583
5584 return ieee80211_vif_set_links(sdata, wdev->valid_links, 0);
5585 }
5586
ieee80211_del_intf_link(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id)5587 static void ieee80211_del_intf_link(struct wiphy *wiphy,
5588 struct wireless_dev *wdev,
5589 unsigned int link_id)
5590 {
5591 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
5592 u16 new_links = wdev->valid_links & ~BIT(link_id);
5593
5594 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5595
5596 /* During the link teardown process, certain functions require the
5597 * link_id to remain in the valid_links bitmap. Therefore, instead
5598 * of removing the link_id from the bitmap, pass a masked value to
5599 * simulate as if link_id does not exist anymore.
5600 */
5601 ieee80211_vif_set_links(sdata, new_links, 0);
5602 }
5603
5604 static int
ieee80211_add_link_station(struct wiphy * wiphy,struct net_device * dev,struct link_station_parameters * params)5605 ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev,
5606 struct link_station_parameters *params)
5607 {
5608 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5609 struct ieee80211_local *local = wiphy_priv(wiphy);
5610 struct sta_info *sta;
5611 int ret;
5612
5613 lockdep_assert_wiphy(local->hw.wiphy);
5614
5615 sta = sta_info_get_bss(sdata, params->mld_mac);
5616 if (!sta)
5617 return -ENOENT;
5618
5619 if (!sta->sta.valid_links)
5620 return -EINVAL;
5621
5622 if (sta->sta.valid_links & BIT(params->link_id))
5623 return -EALREADY;
5624
5625 ret = ieee80211_sta_allocate_link(sta, params->link_id);
5626 if (ret)
5627 return ret;
5628
5629 ret = sta_link_apply_parameters(local, sta, STA_LINK_MODE_NEW, params);
5630 if (ret) {
5631 ieee80211_sta_free_link(sta, params->link_id);
5632 return ret;
5633 }
5634
5635 if (test_sta_flag(sta, WLAN_STA_ASSOC)) {
5636 struct link_sta_info *link_sta;
5637
5638 link_sta = sdata_dereference(sta->link[params->link_id], sdata);
5639 rate_control_rate_init(link_sta);
5640 }
5641
5642 /* ieee80211_sta_activate_link frees the link upon failure */
5643 return ieee80211_sta_activate_link(sta, params->link_id);
5644 }
5645
5646 static int
ieee80211_mod_link_station(struct wiphy * wiphy,struct net_device * dev,struct link_station_parameters * params)5647 ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev,
5648 struct link_station_parameters *params)
5649 {
5650 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5651 struct ieee80211_local *local = wiphy_priv(wiphy);
5652 struct sta_info *sta;
5653
5654 lockdep_assert_wiphy(local->hw.wiphy);
5655
5656 sta = sta_info_get_bss(sdata, params->mld_mac);
5657 if (!sta)
5658 return -ENOENT;
5659
5660 if (!(sta->sta.valid_links & BIT(params->link_id)))
5661 return -EINVAL;
5662
5663 return sta_link_apply_parameters(local, sta, STA_LINK_MODE_LINK_MODIFY,
5664 params);
5665 }
5666
5667 static int
ieee80211_del_link_station(struct wiphy * wiphy,struct net_device * dev,struct link_station_del_parameters * params)5668 ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev,
5669 struct link_station_del_parameters *params)
5670 {
5671 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5672 struct sta_info *sta;
5673
5674 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5675
5676 sta = sta_info_get_bss(sdata, params->mld_mac);
5677 if (!sta)
5678 return -ENOENT;
5679
5680 if (!(sta->sta.valid_links & BIT(params->link_id)))
5681 return -EINVAL;
5682
5683 /* must not create a STA without links */
5684 if (sta->sta.valid_links == BIT(params->link_id))
5685 return -EINVAL;
5686
5687 ieee80211_sta_remove_link(sta, params->link_id);
5688
5689 return 0;
5690 }
5691
ieee80211_set_hw_timestamp(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_set_hw_timestamp * hwts)5692 static int ieee80211_set_hw_timestamp(struct wiphy *wiphy,
5693 struct net_device *dev,
5694 struct cfg80211_set_hw_timestamp *hwts)
5695 {
5696 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5697 struct ieee80211_local *local = sdata->local;
5698
5699 if (!local->ops->set_hw_timestamp)
5700 return -EOPNOTSUPP;
5701
5702 if (!check_sdata_in_driver(sdata))
5703 return -EIO;
5704
5705 return local->ops->set_hw_timestamp(&local->hw, &sdata->vif, hwts);
5706 }
5707
5708 static int
ieee80211_set_ttlm(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ttlm_params * params)5709 ieee80211_set_ttlm(struct wiphy *wiphy, struct net_device *dev,
5710 struct cfg80211_ttlm_params *params)
5711 {
5712 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5713
5714 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5715
5716 return ieee80211_req_neg_ttlm(sdata, params);
5717 }
5718
5719 static int
ieee80211_assoc_ml_reconf(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ml_reconf_req * req)5720 ieee80211_assoc_ml_reconf(struct wiphy *wiphy, struct net_device *dev,
5721 struct cfg80211_ml_reconf_req *req)
5722 {
5723 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5724
5725 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5726
5727 return ieee80211_mgd_assoc_ml_reconf(sdata, req);
5728 }
5729
5730 static int
ieee80211_set_epcs(struct wiphy * wiphy,struct net_device * dev,bool enable)5731 ieee80211_set_epcs(struct wiphy *wiphy, struct net_device *dev, bool enable)
5732 {
5733 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5734
5735 return ieee80211_mgd_set_epcs(sdata, enable);
5736 }
5737
5738 static int
ieee80211_set_local_nan_sched(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_nan_local_sched * sched)5739 ieee80211_set_local_nan_sched(struct wiphy *wiphy,
5740 struct wireless_dev *wdev,
5741 struct cfg80211_nan_local_sched *sched)
5742 {
5743 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
5744
5745 lockdep_assert_wiphy(wiphy);
5746
5747 return ieee80211_nan_set_local_sched(sdata, sched);
5748 }
5749
5750 static int
ieee80211_set_peer_nan_sched(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_nan_peer_sched * sched)5751 ieee80211_set_peer_nan_sched(struct wiphy *wiphy,
5752 struct wireless_dev *wdev,
5753 struct cfg80211_nan_peer_sched *sched)
5754 {
5755 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
5756
5757 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5758
5759 return ieee80211_nan_set_peer_sched(sdata, sched);
5760 }
5761
5762 const struct cfg80211_ops mac80211_config_ops = {
5763 .add_virtual_intf = ieee80211_add_iface,
5764 .del_virtual_intf = ieee80211_del_iface,
5765 .change_virtual_intf = ieee80211_change_iface,
5766 .start_p2p_device = ieee80211_start_p2p_device,
5767 .stop_p2p_device = ieee80211_stop_p2p_device,
5768 .add_key = ieee80211_add_key,
5769 .del_key = ieee80211_del_key,
5770 .get_key = ieee80211_get_key,
5771 .set_default_key = ieee80211_config_default_key,
5772 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
5773 .set_default_beacon_key = ieee80211_config_default_beacon_key,
5774 .start_ap = ieee80211_start_ap,
5775 .change_beacon = ieee80211_change_beacon,
5776 .stop_ap = ieee80211_stop_ap,
5777 .add_station = ieee80211_add_station,
5778 .del_station = ieee80211_del_station,
5779 .change_station = ieee80211_change_station,
5780 .get_station = ieee80211_get_station,
5781 .dump_station = ieee80211_dump_station,
5782 .dump_survey = ieee80211_dump_survey,
5783 #ifdef CONFIG_MAC80211_MESH
5784 .add_mpath = ieee80211_add_mpath,
5785 .del_mpath = ieee80211_del_mpath,
5786 .change_mpath = ieee80211_change_mpath,
5787 .get_mpath = ieee80211_get_mpath,
5788 .dump_mpath = ieee80211_dump_mpath,
5789 .get_mpp = ieee80211_get_mpp,
5790 .dump_mpp = ieee80211_dump_mpp,
5791 .update_mesh_config = ieee80211_update_mesh_config,
5792 .get_mesh_config = ieee80211_get_mesh_config,
5793 .join_mesh = ieee80211_join_mesh,
5794 .leave_mesh = ieee80211_leave_mesh,
5795 #endif
5796 .join_ocb = ieee80211_join_ocb,
5797 .leave_ocb = ieee80211_leave_ocb,
5798 .change_bss = ieee80211_change_bss,
5799 .inform_bss = ieee80211_inform_bss,
5800 .set_txq_params = ieee80211_set_txq_params,
5801 .set_monitor_channel = ieee80211_set_monitor_channel,
5802 .suspend = ieee80211_suspend,
5803 .resume = ieee80211_resume,
5804 .scan = ieee80211_scan,
5805 .abort_scan = ieee80211_abort_scan,
5806 .sched_scan_start = ieee80211_sched_scan_start,
5807 .sched_scan_stop = ieee80211_sched_scan_stop,
5808 .auth = ieee80211_auth,
5809 .assoc = ieee80211_assoc,
5810 .deauth = ieee80211_deauth,
5811 .disassoc = ieee80211_disassoc,
5812 .join_ibss = ieee80211_join_ibss,
5813 .leave_ibss = ieee80211_leave_ibss,
5814 .set_mcast_rate = ieee80211_set_mcast_rate,
5815 .set_wiphy_params = ieee80211_set_wiphy_params,
5816 .set_tx_power = ieee80211_set_tx_power,
5817 .get_tx_power = ieee80211_get_tx_power,
5818 .rfkill_poll = ieee80211_rfkill_poll,
5819 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
5820 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
5821 .set_power_mgmt = ieee80211_set_power_mgmt,
5822 .set_bitrate_mask = ieee80211_set_bitrate_mask,
5823 .remain_on_channel = ieee80211_remain_on_channel,
5824 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
5825 .mgmt_tx = ieee80211_mgmt_tx,
5826 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
5827 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
5828 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
5829 .update_mgmt_frame_registrations =
5830 ieee80211_update_mgmt_frame_registrations,
5831 .set_antenna = ieee80211_set_antenna,
5832 .get_antenna = ieee80211_get_antenna,
5833 .set_rekey_data = ieee80211_set_rekey_data,
5834 .tdls_oper = ieee80211_tdls_oper,
5835 .tdls_mgmt = ieee80211_tdls_mgmt,
5836 .tdls_channel_switch = ieee80211_tdls_channel_switch,
5837 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
5838 .probe_client = ieee80211_probe_client,
5839 .set_noack_map = ieee80211_set_noack_map,
5840 #ifdef CONFIG_PM
5841 .set_wakeup = ieee80211_set_wakeup,
5842 #endif
5843 .get_channel = ieee80211_cfg_get_channel,
5844 .start_radar_detection = ieee80211_start_radar_detection,
5845 .end_cac = ieee80211_end_cac,
5846 .channel_switch = ieee80211_channel_switch,
5847 .set_qos_map = ieee80211_set_qos_map,
5848 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
5849 .add_tx_ts = ieee80211_add_tx_ts,
5850 .del_tx_ts = ieee80211_del_tx_ts,
5851 .start_nan = ieee80211_start_nan,
5852 .stop_nan = ieee80211_stop_nan,
5853 .nan_change_conf = ieee80211_nan_change_conf,
5854 .add_nan_func = ieee80211_add_nan_func,
5855 .del_nan_func = ieee80211_del_nan_func,
5856 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
5857 .tx_control_port = ieee80211_tx_control_port,
5858 .get_txq_stats = ieee80211_get_txq_stats,
5859 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
5860 .start_pmsr = ieee80211_start_pmsr,
5861 .abort_pmsr = ieee80211_abort_pmsr,
5862 .probe_mesh_link = ieee80211_probe_mesh_link,
5863 .set_tid_config = ieee80211_set_tid_config,
5864 .reset_tid_config = ieee80211_reset_tid_config,
5865 .set_sar_specs = ieee80211_set_sar_specs,
5866 .color_change = ieee80211_color_change,
5867 .set_radar_background = ieee80211_set_radar_background,
5868 .add_intf_link = ieee80211_add_intf_link,
5869 .del_intf_link = ieee80211_del_intf_link,
5870 .add_link_station = ieee80211_add_link_station,
5871 .mod_link_station = ieee80211_mod_link_station,
5872 .del_link_station = ieee80211_del_link_station,
5873 .set_hw_timestamp = ieee80211_set_hw_timestamp,
5874 .set_ttlm = ieee80211_set_ttlm,
5875 .get_radio_mask = ieee80211_get_radio_mask,
5876 .assoc_ml_reconf = ieee80211_assoc_ml_reconf,
5877 .set_epcs = ieee80211_set_epcs,
5878 .nan_set_local_sched = ieee80211_set_local_nan_sched,
5879 .nan_set_peer_sched = ieee80211_set_peer_nan_sched,
5880 };
5881