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