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