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