xref: /linux/net/mac80211/cfg.c (revision 2697b79a469b68e3ad3640f55284359c1396278d)
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 	} else {
1383 		link_conf->eht_su_beamformer = false;
1384 		link_conf->eht_su_beamformee = false;
1385 		link_conf->eht_mu_beamformer = false;
1386 	}
1387 
1388 	if (sdata->vif.type == NL80211_IFTYPE_AP &&
1389 	    params->mbssid_config.tx_wdev) {
1390 		err = ieee80211_set_ap_mbssid_options(sdata,
1391 						      params->mbssid_config,
1392 						      link_conf);
1393 		if (err)
1394 			return err;
1395 	}
1396 
1397 	err = ieee80211_link_use_channel(link, &chanreq,
1398 					 IEEE80211_CHANCTX_SHARED);
1399 	if (!err)
1400 		ieee80211_link_copy_chanctx_to_vlans(link, false);
1401 	if (err) {
1402 		link_conf->beacon_int = prev_beacon_int;
1403 		return err;
1404 	}
1405 
1406 	/*
1407 	 * Apply control port protocol, this allows us to
1408 	 * not encrypt dynamic WEP control frames.
1409 	 */
1410 	sdata->control_port_protocol = params->crypto.control_port_ethertype;
1411 	sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1412 	sdata->control_port_over_nl80211 =
1413 				params->crypto.control_port_over_nl80211;
1414 	sdata->control_port_no_preauth =
1415 				params->crypto.control_port_no_preauth;
1416 
1417 	list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1418 		vlan->control_port_protocol =
1419 			params->crypto.control_port_ethertype;
1420 		vlan->control_port_no_encrypt =
1421 			params->crypto.control_port_no_encrypt;
1422 		vlan->control_port_over_nl80211 =
1423 			params->crypto.control_port_over_nl80211;
1424 		vlan->control_port_no_preauth =
1425 			params->crypto.control_port_no_preauth;
1426 	}
1427 
1428 	link_conf->dtim_period = params->dtim_period;
1429 	link_conf->enable_beacon = true;
1430 	link_conf->allow_p2p_go_ps = sdata->vif.p2p;
1431 	link_conf->twt_responder = params->twt_responder;
1432 	link_conf->he_obss_pd = params->he_obss_pd;
1433 	link_conf->he_bss_color = params->beacon.he_bss_color;
1434 	sdata->vif.cfg.s1g = params->chandef.chan->band ==
1435 				  NL80211_BAND_S1GHZ;
1436 
1437 	sdata->vif.cfg.ssid_len = params->ssid_len;
1438 	if (params->ssid_len)
1439 		memcpy(sdata->vif.cfg.ssid, params->ssid,
1440 		       params->ssid_len);
1441 	link_conf->hidden_ssid =
1442 		(params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1443 
1444 	memset(&link_conf->p2p_noa_attr, 0,
1445 	       sizeof(link_conf->p2p_noa_attr));
1446 	link_conf->p2p_noa_attr.oppps_ctwindow =
1447 		params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1448 	if (params->p2p_opp_ps)
1449 		link_conf->p2p_noa_attr.oppps_ctwindow |=
1450 					IEEE80211_P2P_OPPPS_ENABLE_BIT;
1451 
1452 	sdata->beacon_rate_set = false;
1453 	if (wiphy_ext_feature_isset(local->hw.wiphy,
1454 				    NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1455 		for (i = 0; i < NUM_NL80211_BANDS; i++) {
1456 			sdata->beacon_rateidx_mask[i] =
1457 				params->beacon_rate.control[i].legacy;
1458 			if (sdata->beacon_rateidx_mask[i])
1459 				sdata->beacon_rate_set = true;
1460 		}
1461 	}
1462 
1463 	if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
1464 		link_conf->beacon_tx_rate = params->beacon_rate;
1465 
1466 	err = ieee80211_assign_beacon(sdata, link, &params->beacon, NULL, NULL,
1467 				      &changed);
1468 	if (err < 0)
1469 		goto error;
1470 
1471 	err = ieee80211_set_fils_discovery(sdata, &params->fils_discovery,
1472 					   link, link_conf, &changed);
1473 	if (err < 0)
1474 		goto error;
1475 
1476 	err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1477 						   &params->unsol_bcast_probe_resp,
1478 						   link, link_conf, &changed);
1479 	if (err < 0)
1480 		goto error;
1481 
1482 	err = drv_start_ap(sdata->local, sdata, link_conf);
1483 	if (err) {
1484 		old = sdata_dereference(link->u.ap.beacon, sdata);
1485 
1486 		if (old)
1487 			kfree_rcu(old, rcu_head);
1488 		RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1489 
1490 		if (ieee80211_num_beaconing_links(sdata) == 0)
1491 			sdata->u.ap.active = false;
1492 
1493 		goto error;
1494 	}
1495 
1496 	ieee80211_recalc_dtim(local, sdata);
1497 	ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID);
1498 	ieee80211_link_info_change_notify(sdata, link, changed);
1499 
1500 	if (ieee80211_num_beaconing_links(sdata) <= 1)
1501 		netif_carrier_on(dev);
1502 
1503 	list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1504 		netif_carrier_on(vlan->dev);
1505 
1506 	return 0;
1507 
1508 error:
1509 	ieee80211_link_release_channel(link);
1510 
1511 	return err;
1512 }
1513 
1514 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1515 				   struct cfg80211_ap_update *params)
1516 
1517 {
1518 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1519 	struct ieee80211_link_data *link;
1520 	struct cfg80211_beacon_data *beacon = &params->beacon;
1521 	struct beacon_data *old;
1522 	int err;
1523 	struct ieee80211_bss_conf *link_conf;
1524 	u64 changed = 0;
1525 
1526 	lockdep_assert_wiphy(wiphy);
1527 
1528 	link = sdata_dereference(sdata->link[beacon->link_id], sdata);
1529 	if (!link)
1530 		return -ENOLINK;
1531 
1532 	link_conf = link->conf;
1533 
1534 	/* don't allow changing the beacon while a countdown is in place - offset
1535 	 * of channel switch counter may change
1536 	 */
1537 	if (link_conf->csa_active || link_conf->color_change_active)
1538 		return -EBUSY;
1539 
1540 	old = sdata_dereference(link->u.ap.beacon, sdata);
1541 	if (!old)
1542 		return -ENOENT;
1543 
1544 	err = ieee80211_assign_beacon(sdata, link, beacon, NULL, NULL,
1545 				      &changed);
1546 	if (err < 0)
1547 		return err;
1548 
1549 	err = ieee80211_set_fils_discovery(sdata, &params->fils_discovery,
1550 					   link, link_conf, &changed);
1551 	if (err < 0)
1552 		return err;
1553 
1554 	err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1555 						   &params->unsol_bcast_probe_resp,
1556 						   link, link_conf, &changed);
1557 	if (err < 0)
1558 		return err;
1559 
1560 	if (beacon->he_bss_color_valid &&
1561 	    beacon->he_bss_color.enabled != link_conf->he_bss_color.enabled) {
1562 		link_conf->he_bss_color.enabled = beacon->he_bss_color.enabled;
1563 		changed |= BSS_CHANGED_HE_BSS_COLOR;
1564 	}
1565 
1566 	ieee80211_link_info_change_notify(sdata, link, changed);
1567 	return 0;
1568 }
1569 
1570 static void ieee80211_free_next_beacon(struct ieee80211_link_data *link)
1571 {
1572 	if (!link->u.ap.next_beacon)
1573 		return;
1574 
1575 	kfree(link->u.ap.next_beacon->mbssid_ies);
1576 	kfree(link->u.ap.next_beacon->rnr_ies);
1577 	kfree(link->u.ap.next_beacon);
1578 	link->u.ap.next_beacon = NULL;
1579 }
1580 
1581 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1582 			     unsigned int link_id)
1583 {
1584 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1585 	struct ieee80211_sub_if_data *vlan;
1586 	struct ieee80211_local *local = sdata->local;
1587 	struct beacon_data *old_beacon;
1588 	struct probe_resp *old_probe_resp;
1589 	struct fils_discovery_data *old_fils_discovery;
1590 	struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
1591 	struct cfg80211_chan_def chandef;
1592 	struct ieee80211_link_data *link =
1593 		sdata_dereference(sdata->link[link_id], sdata);
1594 	struct ieee80211_bss_conf *link_conf = link->conf;
1595 	LIST_HEAD(keys);
1596 
1597 	lockdep_assert_wiphy(local->hw.wiphy);
1598 
1599 	old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
1600 	if (!old_beacon)
1601 		return -ENOENT;
1602 	old_probe_resp = sdata_dereference(link->u.ap.probe_resp,
1603 					   sdata);
1604 	old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery,
1605 					       sdata);
1606 	old_unsol_bcast_probe_resp =
1607 		sdata_dereference(link->u.ap.unsol_bcast_probe_resp,
1608 				  sdata);
1609 
1610 	/* abort any running channel switch or color change */
1611 	link_conf->csa_active = false;
1612 	link_conf->color_change_active = false;
1613 	if (sdata->csa_blocked_queues) {
1614 		ieee80211_wake_vif_queues(local, sdata,
1615 					  IEEE80211_QUEUE_STOP_REASON_CSA);
1616 		sdata->csa_blocked_queues = false;
1617 	}
1618 
1619 	ieee80211_free_next_beacon(link);
1620 
1621 	/* turn off carrier for this interface and dependent VLANs */
1622 	list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1623 		netif_carrier_off(vlan->dev);
1624 
1625 	if (ieee80211_num_beaconing_links(sdata) <= 1) {
1626 		netif_carrier_off(dev);
1627 		sdata->u.ap.active = false;
1628 	}
1629 
1630 	/* remove beacon and probe response */
1631 	RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1632 	RCU_INIT_POINTER(link->u.ap.probe_resp, NULL);
1633 	RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
1634 	RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
1635 	kfree_rcu(old_beacon, rcu_head);
1636 	if (old_probe_resp)
1637 		kfree_rcu(old_probe_resp, rcu_head);
1638 	if (old_fils_discovery)
1639 		kfree_rcu(old_fils_discovery, rcu_head);
1640 	if (old_unsol_bcast_probe_resp)
1641 		kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
1642 
1643 	kfree(link_conf->ftmr_params);
1644 	link_conf->ftmr_params = NULL;
1645 
1646 	sdata->vif.mbssid_tx_vif = NULL;
1647 	link_conf->bssid_index = 0;
1648 	link_conf->nontransmitted = false;
1649 	link_conf->ema_ap = false;
1650 	link_conf->bssid_indicator = 0;
1651 
1652 	__sta_info_flush(sdata, true, link_id);
1653 
1654 	ieee80211_remove_link_keys(link, &keys);
1655 	if (!list_empty(&keys)) {
1656 		synchronize_net();
1657 		ieee80211_free_key_list(local, &keys);
1658 	}
1659 
1660 	link_conf->enable_beacon = false;
1661 	sdata->beacon_rate_set = false;
1662 	sdata->vif.cfg.ssid_len = 0;
1663 	clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1664 	ieee80211_link_info_change_notify(sdata, link,
1665 					  BSS_CHANGED_BEACON_ENABLED);
1666 
1667 	if (sdata->wdev.cac_started) {
1668 		chandef = link_conf->chanreq.oper;
1669 		wiphy_delayed_work_cancel(wiphy, &link->dfs_cac_timer_work);
1670 		cfg80211_cac_event(sdata->dev, &chandef,
1671 				   NL80211_RADAR_CAC_ABORTED,
1672 				   GFP_KERNEL);
1673 	}
1674 
1675 	drv_stop_ap(sdata->local, sdata, link_conf);
1676 
1677 	/* free all potentially still buffered bcast frames */
1678 	local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1679 	ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1680 
1681 	ieee80211_link_copy_chanctx_to_vlans(link, true);
1682 	ieee80211_link_release_channel(link);
1683 
1684 	return 0;
1685 }
1686 
1687 static int sta_apply_auth_flags(struct ieee80211_local *local,
1688 				struct sta_info *sta,
1689 				u32 mask, u32 set)
1690 {
1691 	int ret;
1692 
1693 	if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1694 	    set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1695 	    !test_sta_flag(sta, WLAN_STA_AUTH)) {
1696 		ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1697 		if (ret)
1698 			return ret;
1699 	}
1700 
1701 	if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1702 	    set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1703 	    !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1704 		/*
1705 		 * When peer becomes associated, init rate control as
1706 		 * well. Some drivers require rate control initialized
1707 		 * before drv_sta_state() is called.
1708 		 */
1709 		if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1710 			rate_control_rate_init(sta);
1711 
1712 		ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1713 		if (ret)
1714 			return ret;
1715 	}
1716 
1717 	if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1718 		if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1719 			ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1720 		else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1721 			ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1722 		else
1723 			ret = 0;
1724 		if (ret)
1725 			return ret;
1726 	}
1727 
1728 	if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1729 	    !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1730 	    test_sta_flag(sta, WLAN_STA_ASSOC)) {
1731 		ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1732 		if (ret)
1733 			return ret;
1734 	}
1735 
1736 	if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1737 	    !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1738 	    test_sta_flag(sta, WLAN_STA_AUTH)) {
1739 		ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1740 		if (ret)
1741 			return ret;
1742 	}
1743 
1744 	return 0;
1745 }
1746 
1747 static void sta_apply_mesh_params(struct ieee80211_local *local,
1748 				  struct sta_info *sta,
1749 				  struct station_parameters *params)
1750 {
1751 #ifdef CONFIG_MAC80211_MESH
1752 	struct ieee80211_sub_if_data *sdata = sta->sdata;
1753 	u64 changed = 0;
1754 
1755 	if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1756 		switch (params->plink_state) {
1757 		case NL80211_PLINK_ESTAB:
1758 			if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1759 				changed = mesh_plink_inc_estab_count(sdata);
1760 			sta->mesh->plink_state = params->plink_state;
1761 			sta->mesh->aid = params->peer_aid;
1762 
1763 			ieee80211_mps_sta_status_update(sta);
1764 			changed |= ieee80211_mps_set_sta_local_pm(sta,
1765 				      sdata->u.mesh.mshcfg.power_mode);
1766 
1767 			ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1768 			/* init at low value */
1769 			ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1770 
1771 			break;
1772 		case NL80211_PLINK_LISTEN:
1773 		case NL80211_PLINK_BLOCKED:
1774 		case NL80211_PLINK_OPN_SNT:
1775 		case NL80211_PLINK_OPN_RCVD:
1776 		case NL80211_PLINK_CNF_RCVD:
1777 		case NL80211_PLINK_HOLDING:
1778 			if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1779 				changed = mesh_plink_dec_estab_count(sdata);
1780 			sta->mesh->plink_state = params->plink_state;
1781 
1782 			ieee80211_mps_sta_status_update(sta);
1783 			changed |= ieee80211_mps_set_sta_local_pm(sta,
1784 					NL80211_MESH_POWER_UNKNOWN);
1785 			break;
1786 		default:
1787 			/*  nothing  */
1788 			break;
1789 		}
1790 	}
1791 
1792 	switch (params->plink_action) {
1793 	case NL80211_PLINK_ACTION_NO_ACTION:
1794 		/* nothing */
1795 		break;
1796 	case NL80211_PLINK_ACTION_OPEN:
1797 		changed |= mesh_plink_open(sta);
1798 		break;
1799 	case NL80211_PLINK_ACTION_BLOCK:
1800 		changed |= mesh_plink_block(sta);
1801 		break;
1802 	}
1803 
1804 	if (params->local_pm)
1805 		changed |= ieee80211_mps_set_sta_local_pm(sta,
1806 							  params->local_pm);
1807 
1808 	ieee80211_mbss_info_change_notify(sdata, changed);
1809 #endif
1810 }
1811 
1812 static int sta_link_apply_parameters(struct ieee80211_local *local,
1813 				     struct sta_info *sta, bool new_link,
1814 				     struct link_station_parameters *params)
1815 {
1816 	int ret = 0;
1817 	struct ieee80211_supported_band *sband;
1818 	struct ieee80211_sub_if_data *sdata = sta->sdata;
1819 	u32 link_id = params->link_id < 0 ? 0 : params->link_id;
1820 	struct ieee80211_link_data *link =
1821 		sdata_dereference(sdata->link[link_id], sdata);
1822 	struct link_sta_info *link_sta =
1823 		rcu_dereference_protected(sta->link[link_id],
1824 					  lockdep_is_held(&local->hw.wiphy->mtx));
1825 
1826 	/*
1827 	 * If there are no changes, then accept a link that exist,
1828 	 * unless it's a new link.
1829 	 */
1830 	if (params->link_id >= 0 && !new_link &&
1831 	    !params->link_mac && !params->txpwr_set &&
1832 	    !params->supported_rates_len &&
1833 	    !params->ht_capa && !params->vht_capa &&
1834 	    !params->he_capa && !params->eht_capa &&
1835 	    !params->opmode_notif_used)
1836 		return 0;
1837 
1838 	if (!link || !link_sta)
1839 		return -EINVAL;
1840 
1841 	sband = ieee80211_get_link_sband(link);
1842 	if (!sband)
1843 		return -EINVAL;
1844 
1845 	if (params->link_mac) {
1846 		if (new_link) {
1847 			memcpy(link_sta->addr, params->link_mac, ETH_ALEN);
1848 			memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN);
1849 		} else if (!ether_addr_equal(link_sta->addr,
1850 					     params->link_mac)) {
1851 			return -EINVAL;
1852 		}
1853 	} else if (new_link) {
1854 		return -EINVAL;
1855 	}
1856 
1857 	if (params->txpwr_set) {
1858 		link_sta->pub->txpwr.type = params->txpwr.type;
1859 		if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1860 			link_sta->pub->txpwr.power = params->txpwr.power;
1861 		ret = drv_sta_set_txpwr(local, sdata, sta);
1862 		if (ret)
1863 			return ret;
1864 	}
1865 
1866 	if (params->supported_rates &&
1867 	    params->supported_rates_len) {
1868 		ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
1869 					 sband, params->supported_rates,
1870 					 params->supported_rates_len,
1871 					 &link_sta->pub->supp_rates[sband->band]);
1872 	}
1873 
1874 	if (params->ht_capa)
1875 		ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1876 						  params->ht_capa, link_sta);
1877 
1878 	/* VHT can override some HT caps such as the A-MSDU max length */
1879 	if (params->vht_capa)
1880 		ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1881 						    params->vht_capa, NULL,
1882 						    link_sta);
1883 
1884 	if (params->he_capa)
1885 		ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1886 						  (void *)params->he_capa,
1887 						  params->he_capa_len,
1888 						  (void *)params->he_6ghz_capa,
1889 						  link_sta);
1890 
1891 	if (params->he_capa && params->eht_capa)
1892 		ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
1893 						    (u8 *)params->he_capa,
1894 						    params->he_capa_len,
1895 						    params->eht_capa,
1896 						    params->eht_capa_len,
1897 						    link_sta);
1898 
1899 	if (params->opmode_notif_used) {
1900 		/* returned value is only needed for rc update, but the
1901 		 * rc isn't initialized here yet, so ignore it
1902 		 */
1903 		__ieee80211_vht_handle_opmode(sdata, link_sta,
1904 					      params->opmode_notif,
1905 					      sband->band);
1906 	}
1907 
1908 	ieee80211_sta_init_nss(link_sta);
1909 
1910 	return ret;
1911 }
1912 
1913 static int sta_apply_parameters(struct ieee80211_local *local,
1914 				struct sta_info *sta,
1915 				struct station_parameters *params)
1916 {
1917 	struct ieee80211_sub_if_data *sdata = sta->sdata;
1918 	u32 mask, set;
1919 	int ret = 0;
1920 
1921 	mask = params->sta_flags_mask;
1922 	set = params->sta_flags_set;
1923 
1924 	if (ieee80211_vif_is_mesh(&sdata->vif)) {
1925 		/*
1926 		 * In mesh mode, ASSOCIATED isn't part of the nl80211
1927 		 * API but must follow AUTHENTICATED for driver state.
1928 		 */
1929 		if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1930 			mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1931 		if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1932 			set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1933 	} else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1934 		/*
1935 		 * TDLS -- everything follows authorized, but
1936 		 * only becoming authorized is possible, not
1937 		 * going back
1938 		 */
1939 		if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1940 			set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1941 			       BIT(NL80211_STA_FLAG_ASSOCIATED);
1942 			mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1943 				BIT(NL80211_STA_FLAG_ASSOCIATED);
1944 		}
1945 	}
1946 
1947 	if (mask & BIT(NL80211_STA_FLAG_WME) &&
1948 	    local->hw.queues >= IEEE80211_NUM_ACS)
1949 		sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1950 
1951 	/* auth flags will be set later for TDLS,
1952 	 * and for unassociated stations that move to associated */
1953 	if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1954 	    !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1955 	      (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1956 		ret = sta_apply_auth_flags(local, sta, mask, set);
1957 		if (ret)
1958 			return ret;
1959 	}
1960 
1961 	if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1962 		if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1963 			set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1964 		else
1965 			clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1966 	}
1967 
1968 	if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1969 		sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1970 		if (set & BIT(NL80211_STA_FLAG_MFP))
1971 			set_sta_flag(sta, WLAN_STA_MFP);
1972 		else
1973 			clear_sta_flag(sta, WLAN_STA_MFP);
1974 	}
1975 
1976 	if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1977 		if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1978 			set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1979 		else
1980 			clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1981 	}
1982 
1983 	if (mask & BIT(NL80211_STA_FLAG_SPP_AMSDU))
1984 		sta->sta.spp_amsdu = set & BIT(NL80211_STA_FLAG_SPP_AMSDU);
1985 
1986 	/* mark TDLS channel switch support, if the AP allows it */
1987 	if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1988 	    !sdata->deflink.u.mgd.tdls_chan_switch_prohibited &&
1989 	    params->ext_capab_len >= 4 &&
1990 	    params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1991 		set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1992 
1993 	if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1994 	    !sdata->u.mgd.tdls_wider_bw_prohibited &&
1995 	    ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1996 	    params->ext_capab_len >= 8 &&
1997 	    params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1998 		set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1999 
2000 	if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
2001 		sta->sta.uapsd_queues = params->uapsd_queues;
2002 		sta->sta.max_sp = params->max_sp;
2003 	}
2004 
2005 	ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab,
2006 					      params->ext_capab_len);
2007 
2008 	/*
2009 	 * cfg80211 validates this (1-2007) and allows setting the AID
2010 	 * only when creating a new station entry
2011 	 */
2012 	if (params->aid)
2013 		sta->sta.aid = params->aid;
2014 
2015 	/*
2016 	 * Some of the following updates would be racy if called on an
2017 	 * existing station, via ieee80211_change_station(). However,
2018 	 * all such changes are rejected by cfg80211 except for updates
2019 	 * changing the supported rates on an existing but not yet used
2020 	 * TDLS peer.
2021 	 */
2022 
2023 	if (params->listen_interval >= 0)
2024 		sta->listen_interval = params->listen_interval;
2025 
2026 	ret = sta_link_apply_parameters(local, sta, false,
2027 					&params->link_sta_params);
2028 	if (ret)
2029 		return ret;
2030 
2031 	if (params->support_p2p_ps >= 0)
2032 		sta->sta.support_p2p_ps = params->support_p2p_ps;
2033 
2034 	if (ieee80211_vif_is_mesh(&sdata->vif))
2035 		sta_apply_mesh_params(local, sta, params);
2036 
2037 	if (params->airtime_weight)
2038 		sta->airtime_weight = params->airtime_weight;
2039 
2040 	/* set the STA state after all sta info from usermode has been set */
2041 	if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
2042 	    set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
2043 		ret = sta_apply_auth_flags(local, sta, mask, set);
2044 		if (ret)
2045 			return ret;
2046 	}
2047 
2048 	/* Mark the STA as MLO if MLD MAC address is available */
2049 	if (params->link_sta_params.mld_mac)
2050 		sta->sta.mlo = true;
2051 
2052 	return 0;
2053 }
2054 
2055 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
2056 				 const u8 *mac,
2057 				 struct station_parameters *params)
2058 {
2059 	struct ieee80211_local *local = wiphy_priv(wiphy);
2060 	struct sta_info *sta;
2061 	struct ieee80211_sub_if_data *sdata;
2062 	int err;
2063 
2064 	lockdep_assert_wiphy(local->hw.wiphy);
2065 
2066 	if (params->vlan) {
2067 		sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2068 
2069 		if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2070 		    sdata->vif.type != NL80211_IFTYPE_AP)
2071 			return -EINVAL;
2072 	} else
2073 		sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2074 
2075 	if (ether_addr_equal(mac, sdata->vif.addr))
2076 		return -EINVAL;
2077 
2078 	if (!is_valid_ether_addr(mac))
2079 		return -EINVAL;
2080 
2081 	if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
2082 	    sdata->vif.type == NL80211_IFTYPE_STATION &&
2083 	    !sdata->u.mgd.associated)
2084 		return -EINVAL;
2085 
2086 	/*
2087 	 * If we have a link ID, it can be a non-MLO station on an AP MLD,
2088 	 * but we need to have a link_mac in that case as well, so use the
2089 	 * STA's MAC address in that case.
2090 	 */
2091 	if (params->link_sta_params.link_id >= 0)
2092 		sta = sta_info_alloc_with_link(sdata, mac,
2093 					       params->link_sta_params.link_id,
2094 					       params->link_sta_params.link_mac ?: mac,
2095 					       GFP_KERNEL);
2096 	else
2097 		sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
2098 
2099 	if (!sta)
2100 		return -ENOMEM;
2101 
2102 	if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2103 		sta->sta.tdls = true;
2104 
2105 	/* Though the mutex is not needed here (since the station is not
2106 	 * visible yet), sta_apply_parameters (and inner functions) require
2107 	 * the mutex due to other paths.
2108 	 */
2109 	err = sta_apply_parameters(local, sta, params);
2110 	if (err) {
2111 		sta_info_free(local, sta);
2112 		return err;
2113 	}
2114 
2115 	/*
2116 	 * for TDLS and for unassociated station, rate control should be
2117 	 * initialized only when rates are known and station is marked
2118 	 * authorized/associated
2119 	 */
2120 	if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
2121 	    test_sta_flag(sta, WLAN_STA_ASSOC))
2122 		rate_control_rate_init(sta);
2123 
2124 	return sta_info_insert(sta);
2125 }
2126 
2127 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
2128 				 struct station_del_parameters *params)
2129 {
2130 	struct ieee80211_sub_if_data *sdata;
2131 
2132 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2133 
2134 	if (params->mac)
2135 		return sta_info_destroy_addr_bss(sdata, params->mac);
2136 
2137 	sta_info_flush(sdata, params->link_id);
2138 	return 0;
2139 }
2140 
2141 static int ieee80211_change_station(struct wiphy *wiphy,
2142 				    struct net_device *dev, const u8 *mac,
2143 				    struct station_parameters *params)
2144 {
2145 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2146 	struct ieee80211_local *local = wiphy_priv(wiphy);
2147 	struct sta_info *sta;
2148 	struct ieee80211_sub_if_data *vlansdata;
2149 	enum cfg80211_station_type statype;
2150 	int err;
2151 
2152 	lockdep_assert_wiphy(local->hw.wiphy);
2153 
2154 	sta = sta_info_get_bss(sdata, mac);
2155 	if (!sta)
2156 		return -ENOENT;
2157 
2158 	switch (sdata->vif.type) {
2159 	case NL80211_IFTYPE_MESH_POINT:
2160 		if (sdata->u.mesh.user_mpm)
2161 			statype = CFG80211_STA_MESH_PEER_USER;
2162 		else
2163 			statype = CFG80211_STA_MESH_PEER_KERNEL;
2164 		break;
2165 	case NL80211_IFTYPE_ADHOC:
2166 		statype = CFG80211_STA_IBSS;
2167 		break;
2168 	case NL80211_IFTYPE_STATION:
2169 		if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2170 			statype = CFG80211_STA_AP_STA;
2171 			break;
2172 		}
2173 		if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2174 			statype = CFG80211_STA_TDLS_PEER_ACTIVE;
2175 		else
2176 			statype = CFG80211_STA_TDLS_PEER_SETUP;
2177 		break;
2178 	case NL80211_IFTYPE_AP:
2179 	case NL80211_IFTYPE_AP_VLAN:
2180 		if (test_sta_flag(sta, WLAN_STA_ASSOC))
2181 			statype = CFG80211_STA_AP_CLIENT;
2182 		else
2183 			statype = CFG80211_STA_AP_CLIENT_UNASSOC;
2184 		break;
2185 	default:
2186 		return -EOPNOTSUPP;
2187 	}
2188 
2189 	err = cfg80211_check_station_change(wiphy, params, statype);
2190 	if (err)
2191 		return err;
2192 
2193 	if (params->vlan && params->vlan != sta->sdata->dev) {
2194 		vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2195 
2196 		if (params->vlan->ieee80211_ptr->use_4addr) {
2197 			if (vlansdata->u.vlan.sta)
2198 				return -EBUSY;
2199 
2200 			rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
2201 			__ieee80211_check_fast_rx_iface(vlansdata);
2202 			drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
2203 		}
2204 
2205 		if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2206 		    sta->sdata->u.vlan.sta)
2207 			RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
2208 
2209 		if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2210 			ieee80211_vif_dec_num_mcast(sta->sdata);
2211 
2212 		sta->sdata = vlansdata;
2213 		ieee80211_check_fast_rx(sta);
2214 		ieee80211_check_fast_xmit(sta);
2215 
2216 		if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
2217 			ieee80211_vif_inc_num_mcast(sta->sdata);
2218 			cfg80211_send_layer2_update(sta->sdata->dev,
2219 						    sta->sta.addr);
2220 		}
2221 	}
2222 
2223 	err = sta_apply_parameters(local, sta, params);
2224 	if (err)
2225 		return err;
2226 
2227 	if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2228 	    params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
2229 		ieee80211_recalc_ps(local);
2230 		ieee80211_recalc_ps_vif(sdata);
2231 	}
2232 
2233 	return 0;
2234 }
2235 
2236 #ifdef CONFIG_MAC80211_MESH
2237 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
2238 			       const u8 *dst, const u8 *next_hop)
2239 {
2240 	struct ieee80211_sub_if_data *sdata;
2241 	struct mesh_path *mpath;
2242 	struct sta_info *sta;
2243 
2244 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2245 
2246 	rcu_read_lock();
2247 	sta = sta_info_get(sdata, next_hop);
2248 	if (!sta) {
2249 		rcu_read_unlock();
2250 		return -ENOENT;
2251 	}
2252 
2253 	mpath = mesh_path_add(sdata, dst);
2254 	if (IS_ERR(mpath)) {
2255 		rcu_read_unlock();
2256 		return PTR_ERR(mpath);
2257 	}
2258 
2259 	mesh_path_fix_nexthop(mpath, sta);
2260 
2261 	rcu_read_unlock();
2262 	return 0;
2263 }
2264 
2265 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
2266 			       const u8 *dst)
2267 {
2268 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2269 
2270 	if (dst)
2271 		return mesh_path_del(sdata, dst);
2272 
2273 	mesh_path_flush_by_iface(sdata);
2274 	return 0;
2275 }
2276 
2277 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2278 				  const u8 *dst, const u8 *next_hop)
2279 {
2280 	struct ieee80211_sub_if_data *sdata;
2281 	struct mesh_path *mpath;
2282 	struct sta_info *sta;
2283 
2284 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2285 
2286 	rcu_read_lock();
2287 
2288 	sta = sta_info_get(sdata, next_hop);
2289 	if (!sta) {
2290 		rcu_read_unlock();
2291 		return -ENOENT;
2292 	}
2293 
2294 	mpath = mesh_path_lookup(sdata, dst);
2295 	if (!mpath) {
2296 		rcu_read_unlock();
2297 		return -ENOENT;
2298 	}
2299 
2300 	mesh_path_fix_nexthop(mpath, sta);
2301 
2302 	rcu_read_unlock();
2303 	return 0;
2304 }
2305 
2306 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2307 			    struct mpath_info *pinfo)
2308 {
2309 	struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2310 
2311 	if (next_hop_sta)
2312 		memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
2313 	else
2314 		eth_zero_addr(next_hop);
2315 
2316 	memset(pinfo, 0, sizeof(*pinfo));
2317 
2318 	pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
2319 
2320 	pinfo->filled = MPATH_INFO_FRAME_QLEN |
2321 			MPATH_INFO_SN |
2322 			MPATH_INFO_METRIC |
2323 			MPATH_INFO_EXPTIME |
2324 			MPATH_INFO_DISCOVERY_TIMEOUT |
2325 			MPATH_INFO_DISCOVERY_RETRIES |
2326 			MPATH_INFO_FLAGS |
2327 			MPATH_INFO_HOP_COUNT |
2328 			MPATH_INFO_PATH_CHANGE;
2329 
2330 	pinfo->frame_qlen = mpath->frame_queue.qlen;
2331 	pinfo->sn = mpath->sn;
2332 	pinfo->metric = mpath->metric;
2333 	if (time_before(jiffies, mpath->exp_time))
2334 		pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2335 	pinfo->discovery_timeout =
2336 			jiffies_to_msecs(mpath->discovery_timeout);
2337 	pinfo->discovery_retries = mpath->discovery_retries;
2338 	if (mpath->flags & MESH_PATH_ACTIVE)
2339 		pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2340 	if (mpath->flags & MESH_PATH_RESOLVING)
2341 		pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
2342 	if (mpath->flags & MESH_PATH_SN_VALID)
2343 		pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
2344 	if (mpath->flags & MESH_PATH_FIXED)
2345 		pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
2346 	if (mpath->flags & MESH_PATH_RESOLVED)
2347 		pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
2348 	pinfo->hop_count = mpath->hop_count;
2349 	pinfo->path_change_count = mpath->path_change_count;
2350 }
2351 
2352 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2353 			       u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2354 
2355 {
2356 	struct ieee80211_sub_if_data *sdata;
2357 	struct mesh_path *mpath;
2358 
2359 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2360 
2361 	rcu_read_lock();
2362 	mpath = mesh_path_lookup(sdata, dst);
2363 	if (!mpath) {
2364 		rcu_read_unlock();
2365 		return -ENOENT;
2366 	}
2367 	memcpy(dst, mpath->dst, ETH_ALEN);
2368 	mpath_set_pinfo(mpath, next_hop, pinfo);
2369 	rcu_read_unlock();
2370 	return 0;
2371 }
2372 
2373 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
2374 				int idx, u8 *dst, u8 *next_hop,
2375 				struct mpath_info *pinfo)
2376 {
2377 	struct ieee80211_sub_if_data *sdata;
2378 	struct mesh_path *mpath;
2379 
2380 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2381 
2382 	rcu_read_lock();
2383 	mpath = mesh_path_lookup_by_idx(sdata, idx);
2384 	if (!mpath) {
2385 		rcu_read_unlock();
2386 		return -ENOENT;
2387 	}
2388 	memcpy(dst, mpath->dst, ETH_ALEN);
2389 	mpath_set_pinfo(mpath, next_hop, pinfo);
2390 	rcu_read_unlock();
2391 	return 0;
2392 }
2393 
2394 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2395 			  struct mpath_info *pinfo)
2396 {
2397 	memset(pinfo, 0, sizeof(*pinfo));
2398 	memcpy(mpp, mpath->mpp, ETH_ALEN);
2399 
2400 	pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
2401 }
2402 
2403 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2404 			     u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2405 
2406 {
2407 	struct ieee80211_sub_if_data *sdata;
2408 	struct mesh_path *mpath;
2409 
2410 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2411 
2412 	rcu_read_lock();
2413 	mpath = mpp_path_lookup(sdata, dst);
2414 	if (!mpath) {
2415 		rcu_read_unlock();
2416 		return -ENOENT;
2417 	}
2418 	memcpy(dst, mpath->dst, ETH_ALEN);
2419 	mpp_set_pinfo(mpath, mpp, pinfo);
2420 	rcu_read_unlock();
2421 	return 0;
2422 }
2423 
2424 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2425 			      int idx, u8 *dst, u8 *mpp,
2426 			      struct mpath_info *pinfo)
2427 {
2428 	struct ieee80211_sub_if_data *sdata;
2429 	struct mesh_path *mpath;
2430 
2431 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2432 
2433 	rcu_read_lock();
2434 	mpath = mpp_path_lookup_by_idx(sdata, idx);
2435 	if (!mpath) {
2436 		rcu_read_unlock();
2437 		return -ENOENT;
2438 	}
2439 	memcpy(dst, mpath->dst, ETH_ALEN);
2440 	mpp_set_pinfo(mpath, mpp, pinfo);
2441 	rcu_read_unlock();
2442 	return 0;
2443 }
2444 
2445 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
2446 				struct net_device *dev,
2447 				struct mesh_config *conf)
2448 {
2449 	struct ieee80211_sub_if_data *sdata;
2450 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2451 
2452 	memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2453 	return 0;
2454 }
2455 
2456 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2457 {
2458 	return (mask >> (parm-1)) & 0x1;
2459 }
2460 
2461 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2462 		const struct mesh_setup *setup)
2463 {
2464 	u8 *new_ie;
2465 	struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2466 					struct ieee80211_sub_if_data, u.mesh);
2467 	int i;
2468 
2469 	/* allocate information elements */
2470 	new_ie = NULL;
2471 
2472 	if (setup->ie_len) {
2473 		new_ie = kmemdup(setup->ie, setup->ie_len,
2474 				GFP_KERNEL);
2475 		if (!new_ie)
2476 			return -ENOMEM;
2477 	}
2478 	ifmsh->ie_len = setup->ie_len;
2479 	ifmsh->ie = new_ie;
2480 
2481 	/* now copy the rest of the setup parameters */
2482 	ifmsh->mesh_id_len = setup->mesh_id_len;
2483 	memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
2484 	ifmsh->mesh_sp_id = setup->sync_method;
2485 	ifmsh->mesh_pp_id = setup->path_sel_proto;
2486 	ifmsh->mesh_pm_id = setup->path_metric;
2487 	ifmsh->user_mpm = setup->user_mpm;
2488 	ifmsh->mesh_auth_id = setup->auth_id;
2489 	ifmsh->security = IEEE80211_MESH_SEC_NONE;
2490 	ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
2491 	if (setup->is_authenticated)
2492 		ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2493 	if (setup->is_secure)
2494 		ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
2495 
2496 	/* mcast rate setting in Mesh Node */
2497 	memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2498 						sizeof(setup->mcast_rate));
2499 	sdata->vif.bss_conf.basic_rates = setup->basic_rates;
2500 
2501 	sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2502 	sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2503 
2504 	sdata->beacon_rate_set = false;
2505 	if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2506 				    NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2507 		for (i = 0; i < NUM_NL80211_BANDS; i++) {
2508 			sdata->beacon_rateidx_mask[i] =
2509 				setup->beacon_rate.control[i].legacy;
2510 			if (sdata->beacon_rateidx_mask[i])
2511 				sdata->beacon_rate_set = true;
2512 		}
2513 	}
2514 
2515 	return 0;
2516 }
2517 
2518 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
2519 					struct net_device *dev, u32 mask,
2520 					const struct mesh_config *nconf)
2521 {
2522 	struct mesh_config *conf;
2523 	struct ieee80211_sub_if_data *sdata;
2524 	struct ieee80211_if_mesh *ifmsh;
2525 
2526 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2527 	ifmsh = &sdata->u.mesh;
2528 
2529 	/* Set the config options which we are interested in setting */
2530 	conf = &(sdata->u.mesh.mshcfg);
2531 	if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2532 		conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2533 	if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2534 		conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2535 	if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2536 		conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2537 	if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2538 		conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2539 	if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2540 		conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2541 	if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2542 		conf->dot11MeshTTL = nconf->dot11MeshTTL;
2543 	if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
2544 		conf->element_ttl = nconf->element_ttl;
2545 	if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2546 		if (ifmsh->user_mpm)
2547 			return -EBUSY;
2548 		conf->auto_open_plinks = nconf->auto_open_plinks;
2549 	}
2550 	if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2551 		conf->dot11MeshNbrOffsetMaxNeighbor =
2552 			nconf->dot11MeshNbrOffsetMaxNeighbor;
2553 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2554 		conf->dot11MeshHWMPmaxPREQretries =
2555 			nconf->dot11MeshHWMPmaxPREQretries;
2556 	if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2557 		conf->path_refresh_time = nconf->path_refresh_time;
2558 	if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2559 		conf->min_discovery_timeout = nconf->min_discovery_timeout;
2560 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2561 		conf->dot11MeshHWMPactivePathTimeout =
2562 			nconf->dot11MeshHWMPactivePathTimeout;
2563 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2564 		conf->dot11MeshHWMPpreqMinInterval =
2565 			nconf->dot11MeshHWMPpreqMinInterval;
2566 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2567 		conf->dot11MeshHWMPperrMinInterval =
2568 			nconf->dot11MeshHWMPperrMinInterval;
2569 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2570 			   mask))
2571 		conf->dot11MeshHWMPnetDiameterTraversalTime =
2572 			nconf->dot11MeshHWMPnetDiameterTraversalTime;
2573 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2574 		conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2575 		ieee80211_mesh_root_setup(ifmsh);
2576 	}
2577 	if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2578 		/* our current gate announcement implementation rides on root
2579 		 * announcements, so require this ifmsh to also be a root node
2580 		 * */
2581 		if (nconf->dot11MeshGateAnnouncementProtocol &&
2582 		    !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2583 			conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2584 			ieee80211_mesh_root_setup(ifmsh);
2585 		}
2586 		conf->dot11MeshGateAnnouncementProtocol =
2587 			nconf->dot11MeshGateAnnouncementProtocol;
2588 	}
2589 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2590 		conf->dot11MeshHWMPRannInterval =
2591 			nconf->dot11MeshHWMPRannInterval;
2592 	if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2593 		conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2594 	if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2595 		/* our RSSI threshold implementation is supported only for
2596 		 * devices that report signal in dBm.
2597 		 */
2598 		if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2599 			return -EOPNOTSUPP;
2600 		conf->rssi_threshold = nconf->rssi_threshold;
2601 	}
2602 	if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2603 		conf->ht_opmode = nconf->ht_opmode;
2604 		sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2605 		ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2606 						  BSS_CHANGED_HT);
2607 	}
2608 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2609 		conf->dot11MeshHWMPactivePathToRootTimeout =
2610 			nconf->dot11MeshHWMPactivePathToRootTimeout;
2611 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2612 		conf->dot11MeshHWMProotInterval =
2613 			nconf->dot11MeshHWMProotInterval;
2614 	if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2615 		conf->dot11MeshHWMPconfirmationInterval =
2616 			nconf->dot11MeshHWMPconfirmationInterval;
2617 	if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2618 		conf->power_mode = nconf->power_mode;
2619 		ieee80211_mps_local_status_update(sdata);
2620 	}
2621 	if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2622 		conf->dot11MeshAwakeWindowDuration =
2623 			nconf->dot11MeshAwakeWindowDuration;
2624 	if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2625 		conf->plink_timeout = nconf->plink_timeout;
2626 	if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2627 		conf->dot11MeshConnectedToMeshGate =
2628 			nconf->dot11MeshConnectedToMeshGate;
2629 	if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2630 		conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
2631 	if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2632 		conf->dot11MeshConnectedToAuthServer =
2633 			nconf->dot11MeshConnectedToAuthServer;
2634 	ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2635 	return 0;
2636 }
2637 
2638 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2639 			       const struct mesh_config *conf,
2640 			       const struct mesh_setup *setup)
2641 {
2642 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2643 	struct ieee80211_chan_req chanreq = { .oper = setup->chandef };
2644 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2645 	int err;
2646 
2647 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
2648 
2649 	memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2650 	err = copy_mesh_setup(ifmsh, setup);
2651 	if (err)
2652 		return err;
2653 
2654 	sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2655 
2656 	/* can mesh use other SMPS modes? */
2657 	sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
2658 	sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
2659 
2660 	err = ieee80211_link_use_channel(&sdata->deflink, &chanreq,
2661 					 IEEE80211_CHANCTX_SHARED);
2662 	if (err)
2663 		return err;
2664 
2665 	return ieee80211_start_mesh(sdata);
2666 }
2667 
2668 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2669 {
2670 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2671 
2672 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
2673 
2674 	ieee80211_stop_mesh(sdata);
2675 	ieee80211_link_release_channel(&sdata->deflink);
2676 	kfree(sdata->u.mesh.ie);
2677 
2678 	return 0;
2679 }
2680 #endif
2681 
2682 static int ieee80211_change_bss(struct wiphy *wiphy,
2683 				struct net_device *dev,
2684 				struct bss_parameters *params)
2685 {
2686 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2687 	struct ieee80211_link_data *link;
2688 	struct ieee80211_supported_band *sband;
2689 	u64 changed = 0;
2690 
2691 	link = ieee80211_link_or_deflink(sdata, params->link_id, true);
2692 	if (IS_ERR(link))
2693 		return PTR_ERR(link);
2694 
2695 	if (!sdata_dereference(link->u.ap.beacon, sdata))
2696 		return -ENOENT;
2697 
2698 	sband = ieee80211_get_link_sband(link);
2699 	if (!sband)
2700 		return -EINVAL;
2701 
2702 	if (params->basic_rates) {
2703 		if (!ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
2704 					      wiphy->bands[sband->band],
2705 					      params->basic_rates,
2706 					      params->basic_rates_len,
2707 					      &link->conf->basic_rates))
2708 			return -EINVAL;
2709 		changed |= BSS_CHANGED_BASIC_RATES;
2710 		ieee80211_check_rate_mask(link);
2711 	}
2712 
2713 	if (params->use_cts_prot >= 0) {
2714 		link->conf->use_cts_prot = params->use_cts_prot;
2715 		changed |= BSS_CHANGED_ERP_CTS_PROT;
2716 	}
2717 	if (params->use_short_preamble >= 0) {
2718 		link->conf->use_short_preamble = params->use_short_preamble;
2719 		changed |= BSS_CHANGED_ERP_PREAMBLE;
2720 	}
2721 
2722 	if (!link->conf->use_short_slot &&
2723 	    (sband->band == NL80211_BAND_5GHZ ||
2724 	     sband->band == NL80211_BAND_6GHZ)) {
2725 		link->conf->use_short_slot = true;
2726 		changed |= BSS_CHANGED_ERP_SLOT;
2727 	}
2728 
2729 	if (params->use_short_slot_time >= 0) {
2730 		link->conf->use_short_slot = params->use_short_slot_time;
2731 		changed |= BSS_CHANGED_ERP_SLOT;
2732 	}
2733 
2734 	if (params->ap_isolate >= 0) {
2735 		if (params->ap_isolate)
2736 			sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2737 		else
2738 			sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2739 		ieee80211_check_fast_rx_iface(sdata);
2740 	}
2741 
2742 	if (params->ht_opmode >= 0) {
2743 		link->conf->ht_operation_mode = (u16)params->ht_opmode;
2744 		changed |= BSS_CHANGED_HT;
2745 	}
2746 
2747 	if (params->p2p_ctwindow >= 0) {
2748 		link->conf->p2p_noa_attr.oppps_ctwindow &=
2749 					~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2750 		link->conf->p2p_noa_attr.oppps_ctwindow |=
2751 			params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2752 		changed |= BSS_CHANGED_P2P_PS;
2753 	}
2754 
2755 	if (params->p2p_opp_ps > 0) {
2756 		link->conf->p2p_noa_attr.oppps_ctwindow |=
2757 					IEEE80211_P2P_OPPPS_ENABLE_BIT;
2758 		changed |= BSS_CHANGED_P2P_PS;
2759 	} else if (params->p2p_opp_ps == 0) {
2760 		link->conf->p2p_noa_attr.oppps_ctwindow &=
2761 					~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2762 		changed |= BSS_CHANGED_P2P_PS;
2763 	}
2764 
2765 	ieee80211_link_info_change_notify(sdata, link, changed);
2766 
2767 	return 0;
2768 }
2769 
2770 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2771 				    struct net_device *dev,
2772 				    struct ieee80211_txq_params *params)
2773 {
2774 	struct ieee80211_local *local = wiphy_priv(wiphy);
2775 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2776 	struct ieee80211_link_data *link =
2777 		ieee80211_link_or_deflink(sdata, params->link_id, true);
2778 	struct ieee80211_tx_queue_params p;
2779 
2780 	if (!local->ops->conf_tx)
2781 		return -EOPNOTSUPP;
2782 
2783 	if (local->hw.queues < IEEE80211_NUM_ACS)
2784 		return -EOPNOTSUPP;
2785 
2786 	if (IS_ERR(link))
2787 		return PTR_ERR(link);
2788 
2789 	memset(&p, 0, sizeof(p));
2790 	p.aifs = params->aifs;
2791 	p.cw_max = params->cwmax;
2792 	p.cw_min = params->cwmin;
2793 	p.txop = params->txop;
2794 
2795 	/*
2796 	 * Setting tx queue params disables u-apsd because it's only
2797 	 * called in master mode.
2798 	 */
2799 	p.uapsd = false;
2800 
2801 	ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2802 
2803 	link->tx_conf[params->ac] = p;
2804 	if (drv_conf_tx(local, link, params->ac, &p)) {
2805 		wiphy_debug(local->hw.wiphy,
2806 			    "failed to set TX queue parameters for AC %d\n",
2807 			    params->ac);
2808 		return -EINVAL;
2809 	}
2810 
2811 	ieee80211_link_info_change_notify(sdata, link,
2812 					  BSS_CHANGED_QOS);
2813 
2814 	return 0;
2815 }
2816 
2817 #ifdef CONFIG_PM
2818 static int ieee80211_suspend(struct wiphy *wiphy,
2819 			     struct cfg80211_wowlan *wowlan)
2820 {
2821 	return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2822 }
2823 
2824 static int ieee80211_resume(struct wiphy *wiphy)
2825 {
2826 	return __ieee80211_resume(wiphy_priv(wiphy));
2827 }
2828 #else
2829 #define ieee80211_suspend NULL
2830 #define ieee80211_resume NULL
2831 #endif
2832 
2833 static int ieee80211_scan(struct wiphy *wiphy,
2834 			  struct cfg80211_scan_request *req)
2835 {
2836 	struct ieee80211_sub_if_data *sdata;
2837 
2838 	sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2839 
2840 	switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2841 	case NL80211_IFTYPE_STATION:
2842 	case NL80211_IFTYPE_ADHOC:
2843 	case NL80211_IFTYPE_MESH_POINT:
2844 	case NL80211_IFTYPE_P2P_CLIENT:
2845 	case NL80211_IFTYPE_P2P_DEVICE:
2846 		break;
2847 	case NL80211_IFTYPE_P2P_GO:
2848 		if (sdata->local->ops->hw_scan)
2849 			break;
2850 		/*
2851 		 * FIXME: implement NoA while scanning in software,
2852 		 * for now fall through to allow scanning only when
2853 		 * beaconing hasn't been configured yet
2854 		 */
2855 		fallthrough;
2856 	case NL80211_IFTYPE_AP:
2857 		/*
2858 		 * If the scan has been forced (and the driver supports
2859 		 * forcing), don't care about being beaconing already.
2860 		 * This will create problems to the attached stations (e.g. all
2861 		 * the frames sent while scanning on other channel will be
2862 		 * lost)
2863 		 */
2864 		if (sdata->deflink.u.ap.beacon &&
2865 		    (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2866 		     !(req->flags & NL80211_SCAN_FLAG_AP)))
2867 			return -EOPNOTSUPP;
2868 		break;
2869 	case NL80211_IFTYPE_NAN:
2870 	default:
2871 		return -EOPNOTSUPP;
2872 	}
2873 
2874 	return ieee80211_request_scan(sdata, req);
2875 }
2876 
2877 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2878 {
2879 	ieee80211_scan_cancel(wiphy_priv(wiphy));
2880 }
2881 
2882 static int
2883 ieee80211_sched_scan_start(struct wiphy *wiphy,
2884 			   struct net_device *dev,
2885 			   struct cfg80211_sched_scan_request *req)
2886 {
2887 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2888 
2889 	if (!sdata->local->ops->sched_scan_start)
2890 		return -EOPNOTSUPP;
2891 
2892 	return ieee80211_request_sched_scan_start(sdata, req);
2893 }
2894 
2895 static int
2896 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2897 			  u64 reqid)
2898 {
2899 	struct ieee80211_local *local = wiphy_priv(wiphy);
2900 
2901 	if (!local->ops->sched_scan_stop)
2902 		return -EOPNOTSUPP;
2903 
2904 	return ieee80211_request_sched_scan_stop(local);
2905 }
2906 
2907 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2908 			  struct cfg80211_auth_request *req)
2909 {
2910 	return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2911 }
2912 
2913 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2914 			   struct cfg80211_assoc_request *req)
2915 {
2916 	return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2917 }
2918 
2919 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2920 			    struct cfg80211_deauth_request *req)
2921 {
2922 	return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2923 }
2924 
2925 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2926 			      struct cfg80211_disassoc_request *req)
2927 {
2928 	return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2929 }
2930 
2931 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2932 			       struct cfg80211_ibss_params *params)
2933 {
2934 	return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2935 }
2936 
2937 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2938 {
2939 	return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2940 }
2941 
2942 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2943 			      struct ocb_setup *setup)
2944 {
2945 	return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2946 }
2947 
2948 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2949 {
2950 	return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2951 }
2952 
2953 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2954 				    int rate[NUM_NL80211_BANDS])
2955 {
2956 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2957 
2958 	memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2959 	       sizeof(int) * NUM_NL80211_BANDS);
2960 
2961 	if (ieee80211_sdata_running(sdata))
2962 		ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2963 						  BSS_CHANGED_MCAST_RATE);
2964 
2965 	return 0;
2966 }
2967 
2968 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2969 {
2970 	struct ieee80211_local *local = wiphy_priv(wiphy);
2971 	int err;
2972 
2973 	if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2974 		ieee80211_check_fast_xmit_all(local);
2975 
2976 		err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2977 
2978 		if (err) {
2979 			ieee80211_check_fast_xmit_all(local);
2980 			return err;
2981 		}
2982 	}
2983 
2984 	if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2985 	    (changed & WIPHY_PARAM_DYN_ACK)) {
2986 		s16 coverage_class;
2987 
2988 		coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2989 					wiphy->coverage_class : -1;
2990 		err = drv_set_coverage_class(local, coverage_class);
2991 
2992 		if (err)
2993 			return err;
2994 	}
2995 
2996 	if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2997 		err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2998 
2999 		if (err)
3000 			return err;
3001 	}
3002 
3003 	if (changed & WIPHY_PARAM_RETRY_SHORT) {
3004 		if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
3005 			return -EINVAL;
3006 		local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
3007 	}
3008 	if (changed & WIPHY_PARAM_RETRY_LONG) {
3009 		if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
3010 			return -EINVAL;
3011 		local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
3012 	}
3013 	if (changed &
3014 	    (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
3015 		ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
3016 
3017 	if (changed & (WIPHY_PARAM_TXQ_LIMIT |
3018 		       WIPHY_PARAM_TXQ_MEMORY_LIMIT |
3019 		       WIPHY_PARAM_TXQ_QUANTUM))
3020 		ieee80211_txq_set_params(local);
3021 
3022 	return 0;
3023 }
3024 
3025 static int ieee80211_set_tx_power(struct wiphy *wiphy,
3026 				  struct wireless_dev *wdev,
3027 				  enum nl80211_tx_power_setting type, int mbm)
3028 {
3029 	struct ieee80211_local *local = wiphy_priv(wiphy);
3030 	struct ieee80211_sub_if_data *sdata;
3031 	enum nl80211_tx_power_setting txp_type = type;
3032 	bool update_txp_type = false;
3033 	bool has_monitor = false;
3034 
3035 	lockdep_assert_wiphy(local->hw.wiphy);
3036 
3037 	if (wdev) {
3038 		sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3039 
3040 		if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3041 			sdata = wiphy_dereference(local->hw.wiphy,
3042 						  local->monitor_sdata);
3043 			if (!sdata)
3044 				return -EOPNOTSUPP;
3045 		}
3046 
3047 		switch (type) {
3048 		case NL80211_TX_POWER_AUTOMATIC:
3049 			sdata->deflink.user_power_level =
3050 				IEEE80211_UNSET_POWER_LEVEL;
3051 			txp_type = NL80211_TX_POWER_LIMITED;
3052 			break;
3053 		case NL80211_TX_POWER_LIMITED:
3054 		case NL80211_TX_POWER_FIXED:
3055 			if (mbm < 0 || (mbm % 100))
3056 				return -EOPNOTSUPP;
3057 			sdata->deflink.user_power_level = MBM_TO_DBM(mbm);
3058 			break;
3059 		}
3060 
3061 		if (txp_type != sdata->vif.bss_conf.txpower_type) {
3062 			update_txp_type = true;
3063 			sdata->vif.bss_conf.txpower_type = txp_type;
3064 		}
3065 
3066 		ieee80211_recalc_txpower(sdata, update_txp_type);
3067 
3068 		return 0;
3069 	}
3070 
3071 	switch (type) {
3072 	case NL80211_TX_POWER_AUTOMATIC:
3073 		local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
3074 		txp_type = NL80211_TX_POWER_LIMITED;
3075 		break;
3076 	case NL80211_TX_POWER_LIMITED:
3077 	case NL80211_TX_POWER_FIXED:
3078 		if (mbm < 0 || (mbm % 100))
3079 			return -EOPNOTSUPP;
3080 		local->user_power_level = MBM_TO_DBM(mbm);
3081 		break;
3082 	}
3083 
3084 	list_for_each_entry(sdata, &local->interfaces, list) {
3085 		if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3086 			has_monitor = true;
3087 			continue;
3088 		}
3089 		sdata->deflink.user_power_level = local->user_power_level;
3090 		if (txp_type != sdata->vif.bss_conf.txpower_type)
3091 			update_txp_type = true;
3092 		sdata->vif.bss_conf.txpower_type = txp_type;
3093 	}
3094 	list_for_each_entry(sdata, &local->interfaces, list) {
3095 		if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
3096 			continue;
3097 		ieee80211_recalc_txpower(sdata, update_txp_type);
3098 	}
3099 
3100 	if (has_monitor) {
3101 		sdata = wiphy_dereference(local->hw.wiphy,
3102 					  local->monitor_sdata);
3103 		if (sdata) {
3104 			sdata->deflink.user_power_level = local->user_power_level;
3105 			if (txp_type != sdata->vif.bss_conf.txpower_type)
3106 				update_txp_type = true;
3107 			sdata->vif.bss_conf.txpower_type = txp_type;
3108 
3109 			ieee80211_recalc_txpower(sdata, update_txp_type);
3110 		}
3111 	}
3112 
3113 	return 0;
3114 }
3115 
3116 static int ieee80211_get_tx_power(struct wiphy *wiphy,
3117 				  struct wireless_dev *wdev,
3118 				  int *dbm)
3119 {
3120 	struct ieee80211_local *local = wiphy_priv(wiphy);
3121 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3122 
3123 	if (local->ops->get_txpower)
3124 		return drv_get_txpower(local, sdata, dbm);
3125 
3126 	if (local->emulate_chanctx)
3127 		*dbm = local->hw.conf.power_level;
3128 	else
3129 		*dbm = sdata->vif.bss_conf.txpower;
3130 
3131 	/* INT_MIN indicates no power level was set yet */
3132 	if (*dbm == INT_MIN)
3133 		return -EINVAL;
3134 
3135 	return 0;
3136 }
3137 
3138 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
3139 {
3140 	struct ieee80211_local *local = wiphy_priv(wiphy);
3141 
3142 	drv_rfkill_poll(local);
3143 }
3144 
3145 #ifdef CONFIG_NL80211_TESTMODE
3146 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
3147 				  struct wireless_dev *wdev,
3148 				  void *data, int len)
3149 {
3150 	struct ieee80211_local *local = wiphy_priv(wiphy);
3151 	struct ieee80211_vif *vif = NULL;
3152 
3153 	if (!local->ops->testmode_cmd)
3154 		return -EOPNOTSUPP;
3155 
3156 	if (wdev) {
3157 		struct ieee80211_sub_if_data *sdata;
3158 
3159 		sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3160 		if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
3161 			vif = &sdata->vif;
3162 	}
3163 
3164 	return local->ops->testmode_cmd(&local->hw, vif, data, len);
3165 }
3166 
3167 static int ieee80211_testmode_dump(struct wiphy *wiphy,
3168 				   struct sk_buff *skb,
3169 				   struct netlink_callback *cb,
3170 				   void *data, int len)
3171 {
3172 	struct ieee80211_local *local = wiphy_priv(wiphy);
3173 
3174 	if (!local->ops->testmode_dump)
3175 		return -EOPNOTSUPP;
3176 
3177 	return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
3178 }
3179 #endif
3180 
3181 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
3182 				 struct ieee80211_link_data *link,
3183 				 enum ieee80211_smps_mode smps_mode)
3184 {
3185 	const u8 *ap;
3186 	enum ieee80211_smps_mode old_req;
3187 	int err;
3188 	struct sta_info *sta;
3189 	bool tdls_peer_found = false;
3190 
3191 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
3192 
3193 	if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
3194 		return -EINVAL;
3195 
3196 	if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
3197 		return 0;
3198 
3199 	old_req = link->u.mgd.req_smps;
3200 	link->u.mgd.req_smps = smps_mode;
3201 
3202 	/* The driver indicated that EML is enabled for the interface, which
3203 	 * implies that SMPS flows towards the AP should be stopped.
3204 	 */
3205 	if (sdata->vif.driver_flags & IEEE80211_VIF_EML_ACTIVE)
3206 		return 0;
3207 
3208 	if (old_req == smps_mode &&
3209 	    smps_mode != IEEE80211_SMPS_AUTOMATIC)
3210 		return 0;
3211 
3212 	/*
3213 	 * If not associated, or current association is not an HT
3214 	 * association, there's no need to do anything, just store
3215 	 * the new value until we associate.
3216 	 */
3217 	if (!sdata->u.mgd.associated ||
3218 	    link->conf->chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT)
3219 		return 0;
3220 
3221 	ap = sdata->vif.cfg.ap_addr;
3222 
3223 	rcu_read_lock();
3224 	list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
3225 		if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
3226 		    !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3227 			continue;
3228 
3229 		tdls_peer_found = true;
3230 		break;
3231 	}
3232 	rcu_read_unlock();
3233 
3234 	if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
3235 		if (tdls_peer_found || !sdata->u.mgd.powersave)
3236 			smps_mode = IEEE80211_SMPS_OFF;
3237 		else
3238 			smps_mode = IEEE80211_SMPS_DYNAMIC;
3239 	}
3240 
3241 	/* send SM PS frame to AP */
3242 	err = ieee80211_send_smps_action(sdata, smps_mode,
3243 					 ap, ap,
3244 					 ieee80211_vif_is_mld(&sdata->vif) ?
3245 					 link->link_id : -1);
3246 	if (err)
3247 		link->u.mgd.req_smps = old_req;
3248 	else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
3249 		ieee80211_teardown_tdls_peers(link);
3250 
3251 	return err;
3252 }
3253 
3254 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
3255 				    bool enabled, int timeout)
3256 {
3257 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3258 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3259 	unsigned int link_id;
3260 
3261 	if (sdata->vif.type != NL80211_IFTYPE_STATION)
3262 		return -EOPNOTSUPP;
3263 
3264 	if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
3265 		return -EOPNOTSUPP;
3266 
3267 	if (enabled == sdata->u.mgd.powersave &&
3268 	    timeout == local->dynamic_ps_forced_timeout)
3269 		return 0;
3270 
3271 	sdata->u.mgd.powersave = enabled;
3272 	local->dynamic_ps_forced_timeout = timeout;
3273 
3274 	/* no change, but if automatic follow powersave */
3275 	for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3276 		struct ieee80211_link_data *link;
3277 
3278 		link = sdata_dereference(sdata->link[link_id], sdata);
3279 
3280 		if (!link)
3281 			continue;
3282 		__ieee80211_request_smps_mgd(sdata, link,
3283 					     link->u.mgd.req_smps);
3284 	}
3285 
3286 	if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3287 		ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3288 
3289 	ieee80211_recalc_ps(local);
3290 	ieee80211_recalc_ps_vif(sdata);
3291 	ieee80211_check_fast_rx_iface(sdata);
3292 
3293 	return 0;
3294 }
3295 
3296 static void ieee80211_set_cqm_rssi_link(struct ieee80211_sub_if_data *sdata,
3297 					struct ieee80211_link_data *link,
3298 					s32 rssi_thold, u32 rssi_hyst,
3299 					s32 rssi_low, s32 rssi_high)
3300 {
3301 	struct ieee80211_bss_conf *conf;
3302 
3303 	if (!link || !link->conf)
3304 		return;
3305 
3306 	conf = link->conf;
3307 
3308 	if (rssi_thold && rssi_hyst &&
3309 	    rssi_thold == conf->cqm_rssi_thold &&
3310 	    rssi_hyst == conf->cqm_rssi_hyst)
3311 		return;
3312 
3313 	conf->cqm_rssi_thold = rssi_thold;
3314 	conf->cqm_rssi_hyst = rssi_hyst;
3315 	conf->cqm_rssi_low = rssi_low;
3316 	conf->cqm_rssi_high = rssi_high;
3317 	link->u.mgd.last_cqm_event_signal = 0;
3318 
3319 	if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
3320 		return;
3321 
3322 	if (sdata->u.mgd.associated &&
3323 	    (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3324 		ieee80211_link_info_change_notify(sdata, link, BSS_CHANGED_CQM);
3325 }
3326 
3327 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3328 					 struct net_device *dev,
3329 					 s32 rssi_thold, u32 rssi_hyst)
3330 {
3331 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3332 	struct ieee80211_vif *vif = &sdata->vif;
3333 	int link_id;
3334 
3335 	if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3336 	    !(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3337 		return -EOPNOTSUPP;
3338 
3339 	/* For MLD, handle CQM change on all the active links */
3340 	for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
3341 		struct ieee80211_link_data *link =
3342 			sdata_dereference(sdata->link[link_id], sdata);
3343 
3344 		ieee80211_set_cqm_rssi_link(sdata, link, rssi_thold, rssi_hyst,
3345 					    0, 0);
3346 	}
3347 
3348 	return 0;
3349 }
3350 
3351 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3352 					       struct net_device *dev,
3353 					       s32 rssi_low, s32 rssi_high)
3354 {
3355 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3356 	struct ieee80211_vif *vif = &sdata->vif;
3357 	int link_id;
3358 
3359 	if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)
3360 		return -EOPNOTSUPP;
3361 
3362 	/* For MLD, handle CQM change on all the active links */
3363 	for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
3364 		struct ieee80211_link_data *link =
3365 			sdata_dereference(sdata->link[link_id], sdata);
3366 
3367 		ieee80211_set_cqm_rssi_link(sdata, link, 0, 0,
3368 					    rssi_low, rssi_high);
3369 	}
3370 
3371 	return 0;
3372 }
3373 
3374 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3375 				      struct net_device *dev,
3376 				      unsigned int link_id,
3377 				      const u8 *addr,
3378 				      const struct cfg80211_bitrate_mask *mask)
3379 {
3380 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3381 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3382 	int i, ret;
3383 
3384 	if (!ieee80211_sdata_running(sdata))
3385 		return -ENETDOWN;
3386 
3387 	/*
3388 	 * If active validate the setting and reject it if it doesn't leave
3389 	 * at least one basic rate usable, since we really have to be able
3390 	 * to send something, and if we're an AP we have to be able to do
3391 	 * so at a basic rate so that all clients can receive it.
3392 	 */
3393 	if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
3394 	    sdata->vif.bss_conf.chanreq.oper.chan) {
3395 		u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3396 		enum nl80211_band band;
3397 
3398 		band = sdata->vif.bss_conf.chanreq.oper.chan->band;
3399 
3400 		if (!(mask->control[band].legacy & basic_rates))
3401 			return -EINVAL;
3402 	}
3403 
3404 	if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3405 		ret = drv_set_bitrate_mask(local, sdata, mask);
3406 		if (ret)
3407 			return ret;
3408 	}
3409 
3410 	for (i = 0; i < NUM_NL80211_BANDS; i++) {
3411 		struct ieee80211_supported_band *sband = wiphy->bands[i];
3412 		int j;
3413 
3414 		sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
3415 		memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3416 		       sizeof(mask->control[i].ht_mcs));
3417 		memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3418 		       mask->control[i].vht_mcs,
3419 		       sizeof(mask->control[i].vht_mcs));
3420 
3421 		sdata->rc_has_mcs_mask[i] = false;
3422 		sdata->rc_has_vht_mcs_mask[i] = false;
3423 		if (!sband)
3424 			continue;
3425 
3426 		for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
3427 			if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
3428 				sdata->rc_has_mcs_mask[i] = true;
3429 				break;
3430 			}
3431 		}
3432 
3433 		for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
3434 			if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
3435 				sdata->rc_has_vht_mcs_mask[i] = true;
3436 				break;
3437 			}
3438 		}
3439 	}
3440 
3441 	return 0;
3442 }
3443 
3444 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3445 					   struct net_device *dev,
3446 					   struct cfg80211_chan_def *chandef,
3447 					   u32 cac_time_ms)
3448 {
3449 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3450 	struct ieee80211_chan_req chanreq = { .oper = *chandef };
3451 	struct ieee80211_local *local = sdata->local;
3452 	int err;
3453 
3454 	lockdep_assert_wiphy(local->hw.wiphy);
3455 
3456 	if (!list_empty(&local->roc_list) || local->scanning) {
3457 		err = -EBUSY;
3458 		goto out_unlock;
3459 	}
3460 
3461 	/* whatever, but channel contexts should not complain about that one */
3462 	sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
3463 	sdata->deflink.needed_rx_chains = local->rx_chains;
3464 
3465 	err = ieee80211_link_use_channel(&sdata->deflink, &chanreq,
3466 					 IEEE80211_CHANCTX_SHARED);
3467 	if (err)
3468 		goto out_unlock;
3469 
3470 	wiphy_delayed_work_queue(wiphy, &sdata->deflink.dfs_cac_timer_work,
3471 				 msecs_to_jiffies(cac_time_ms));
3472 
3473  out_unlock:
3474 	return err;
3475 }
3476 
3477 static void ieee80211_end_cac(struct wiphy *wiphy,
3478 			      struct net_device *dev)
3479 {
3480 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3481 	struct ieee80211_local *local = sdata->local;
3482 
3483 	lockdep_assert_wiphy(local->hw.wiphy);
3484 
3485 	list_for_each_entry(sdata, &local->interfaces, list) {
3486 		/* it might be waiting for the local->mtx, but then
3487 		 * by the time it gets it, sdata->wdev.cac_started
3488 		 * will no longer be true
3489 		 */
3490 		wiphy_delayed_work_cancel(wiphy,
3491 					  &sdata->deflink.dfs_cac_timer_work);
3492 
3493 		if (sdata->wdev.cac_started) {
3494 			ieee80211_link_release_channel(&sdata->deflink);
3495 			sdata->wdev.cac_started = false;
3496 		}
3497 	}
3498 }
3499 
3500 static struct cfg80211_beacon_data *
3501 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3502 {
3503 	struct cfg80211_beacon_data *new_beacon;
3504 	u8 *pos;
3505 	int len;
3506 
3507 	len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3508 	      beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3509 	      beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
3510 
3511 	if (beacon->mbssid_ies)
3512 		len += ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies,
3513 						       beacon->rnr_ies,
3514 						       beacon->mbssid_ies->cnt);
3515 
3516 	new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3517 	if (!new_beacon)
3518 		return NULL;
3519 
3520 	if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3521 		new_beacon->mbssid_ies =
3522 			kzalloc(struct_size(new_beacon->mbssid_ies,
3523 					    elem, beacon->mbssid_ies->cnt),
3524 				GFP_KERNEL);
3525 		if (!new_beacon->mbssid_ies) {
3526 			kfree(new_beacon);
3527 			return NULL;
3528 		}
3529 
3530 		if (beacon->rnr_ies && beacon->rnr_ies->cnt) {
3531 			new_beacon->rnr_ies =
3532 				kzalloc(struct_size(new_beacon->rnr_ies,
3533 						    elem, beacon->rnr_ies->cnt),
3534 					GFP_KERNEL);
3535 			if (!new_beacon->rnr_ies) {
3536 				kfree(new_beacon->mbssid_ies);
3537 				kfree(new_beacon);
3538 				return NULL;
3539 			}
3540 		}
3541 	}
3542 
3543 	pos = (u8 *)(new_beacon + 1);
3544 	if (beacon->head_len) {
3545 		new_beacon->head_len = beacon->head_len;
3546 		new_beacon->head = pos;
3547 		memcpy(pos, beacon->head, beacon->head_len);
3548 		pos += beacon->head_len;
3549 	}
3550 	if (beacon->tail_len) {
3551 		new_beacon->tail_len = beacon->tail_len;
3552 		new_beacon->tail = pos;
3553 		memcpy(pos, beacon->tail, beacon->tail_len);
3554 		pos += beacon->tail_len;
3555 	}
3556 	if (beacon->beacon_ies_len) {
3557 		new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3558 		new_beacon->beacon_ies = pos;
3559 		memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3560 		pos += beacon->beacon_ies_len;
3561 	}
3562 	if (beacon->proberesp_ies_len) {
3563 		new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3564 		new_beacon->proberesp_ies = pos;
3565 		memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3566 		pos += beacon->proberesp_ies_len;
3567 	}
3568 	if (beacon->assocresp_ies_len) {
3569 		new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3570 		new_beacon->assocresp_ies = pos;
3571 		memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3572 		pos += beacon->assocresp_ies_len;
3573 	}
3574 	if (beacon->probe_resp_len) {
3575 		new_beacon->probe_resp_len = beacon->probe_resp_len;
3576 		new_beacon->probe_resp = pos;
3577 		memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3578 		pos += beacon->probe_resp_len;
3579 	}
3580 	if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3581 		pos += ieee80211_copy_mbssid_beacon(pos,
3582 						    new_beacon->mbssid_ies,
3583 						    beacon->mbssid_ies);
3584 		if (beacon->rnr_ies && beacon->rnr_ies->cnt)
3585 			pos += ieee80211_copy_rnr_beacon(pos,
3586 							 new_beacon->rnr_ies,
3587 							 beacon->rnr_ies);
3588 	}
3589 
3590 	/* might copy -1, meaning no changes requested */
3591 	new_beacon->ftm_responder = beacon->ftm_responder;
3592 	if (beacon->lci) {
3593 		new_beacon->lci_len = beacon->lci_len;
3594 		new_beacon->lci = pos;
3595 		memcpy(pos, beacon->lci, beacon->lci_len);
3596 		pos += beacon->lci_len;
3597 	}
3598 	if (beacon->civicloc) {
3599 		new_beacon->civicloc_len = beacon->civicloc_len;
3600 		new_beacon->civicloc = pos;
3601 		memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3602 		pos += beacon->civicloc_len;
3603 	}
3604 
3605 	return new_beacon;
3606 }
3607 
3608 void ieee80211_csa_finish(struct ieee80211_vif *vif, unsigned int link_id)
3609 {
3610 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3611 	struct ieee80211_local *local = sdata->local;
3612 	struct ieee80211_link_data *link_data;
3613 
3614 	if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
3615 		return;
3616 
3617 	rcu_read_lock();
3618 
3619 	link_data = rcu_dereference(sdata->link[link_id]);
3620 	if (WARN_ON(!link_data)) {
3621 		rcu_read_unlock();
3622 		return;
3623 	}
3624 
3625 	/* TODO: MBSSID with MLO changes */
3626 	if (vif->mbssid_tx_vif == vif) {
3627 		/* Trigger ieee80211_csa_finish() on the non-transmitting
3628 		 * interfaces when channel switch is received on
3629 		 * transmitting interface
3630 		 */
3631 		struct ieee80211_sub_if_data *iter;
3632 
3633 		list_for_each_entry_rcu(iter, &local->interfaces, list) {
3634 			if (!ieee80211_sdata_running(iter))
3635 				continue;
3636 
3637 			if (iter == sdata || iter->vif.mbssid_tx_vif != vif)
3638 				continue;
3639 
3640 			wiphy_work_queue(iter->local->hw.wiphy,
3641 					 &iter->deflink.csa_finalize_work);
3642 		}
3643 	}
3644 	wiphy_work_queue(local->hw.wiphy, &link_data->csa_finalize_work);
3645 
3646 	rcu_read_unlock();
3647 }
3648 EXPORT_SYMBOL(ieee80211_csa_finish);
3649 
3650 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx)
3651 {
3652 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3653 	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3654 	struct ieee80211_local *local = sdata->local;
3655 
3656 	sdata->csa_blocked_queues = block_tx;
3657 	sdata_info(sdata, "channel switch failed, disconnecting\n");
3658 	wiphy_work_queue(local->hw.wiphy, &ifmgd->csa_connection_drop_work);
3659 }
3660 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
3661 
3662 static int ieee80211_set_after_csa_beacon(struct ieee80211_link_data *link_data,
3663 					  u64 *changed)
3664 {
3665 	struct ieee80211_sub_if_data *sdata = link_data->sdata;
3666 	int err;
3667 
3668 	switch (sdata->vif.type) {
3669 	case NL80211_IFTYPE_AP:
3670 		if (!link_data->u.ap.next_beacon)
3671 			return -EINVAL;
3672 
3673 		err = ieee80211_assign_beacon(sdata, link_data,
3674 					      link_data->u.ap.next_beacon,
3675 					      NULL, NULL, changed);
3676 		ieee80211_free_next_beacon(link_data);
3677 
3678 		if (err < 0)
3679 			return err;
3680 		break;
3681 	case NL80211_IFTYPE_ADHOC:
3682 		err = ieee80211_ibss_finish_csa(sdata, changed);
3683 		if (err < 0)
3684 			return err;
3685 		break;
3686 #ifdef CONFIG_MAC80211_MESH
3687 	case NL80211_IFTYPE_MESH_POINT:
3688 		err = ieee80211_mesh_finish_csa(sdata, changed);
3689 		if (err < 0)
3690 			return err;
3691 		break;
3692 #endif
3693 	default:
3694 		WARN_ON(1);
3695 		return -EINVAL;
3696 	}
3697 
3698 	return 0;
3699 }
3700 
3701 static int __ieee80211_csa_finalize(struct ieee80211_link_data *link_data)
3702 {
3703 	struct ieee80211_sub_if_data *sdata = link_data->sdata;
3704 	struct ieee80211_local *local = sdata->local;
3705 	struct ieee80211_bss_conf *link_conf = link_data->conf;
3706 	u64 changed = 0;
3707 	int err;
3708 
3709 	lockdep_assert_wiphy(local->hw.wiphy);
3710 
3711 	/*
3712 	 * using reservation isn't immediate as it may be deferred until later
3713 	 * with multi-vif. once reservation is complete it will re-schedule the
3714 	 * work with no reserved_chanctx so verify chandef to check if it
3715 	 * completed successfully
3716 	 */
3717 
3718 	if (link_data->reserved_chanctx) {
3719 		/*
3720 		 * with multi-vif csa driver may call ieee80211_csa_finish()
3721 		 * many times while waiting for other interfaces to use their
3722 		 * reservations
3723 		 */
3724 		if (link_data->reserved_ready)
3725 			return 0;
3726 
3727 		return ieee80211_link_use_reserved_context(link_data);
3728 	}
3729 
3730 	if (!cfg80211_chandef_identical(&link_conf->chanreq.oper,
3731 					&link_data->csa_chanreq.oper))
3732 		return -EINVAL;
3733 
3734 	link_conf->csa_active = false;
3735 
3736 	err = ieee80211_set_after_csa_beacon(link_data, &changed);
3737 	if (err)
3738 		return err;
3739 
3740 	ieee80211_link_info_change_notify(sdata, link_data, changed);
3741 
3742 	if (sdata->csa_blocked_queues) {
3743 		ieee80211_wake_vif_queues(local, sdata,
3744 					  IEEE80211_QUEUE_STOP_REASON_CSA);
3745 		sdata->csa_blocked_queues = false;
3746 	}
3747 
3748 	err = drv_post_channel_switch(link_data);
3749 	if (err)
3750 		return err;
3751 
3752 	cfg80211_ch_switch_notify(sdata->dev, &link_data->csa_chanreq.oper,
3753 				  link_data->link_id);
3754 
3755 	return 0;
3756 }
3757 
3758 static void ieee80211_csa_finalize(struct ieee80211_link_data *link_data)
3759 {
3760 	struct ieee80211_sub_if_data *sdata = link_data->sdata;
3761 
3762 	if (__ieee80211_csa_finalize(link_data)) {
3763 		sdata_info(sdata, "failed to finalize CSA on link %d, disconnecting\n",
3764 			   link_data->link_id);
3765 		cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3766 				    GFP_KERNEL);
3767 	}
3768 }
3769 
3770 void ieee80211_csa_finalize_work(struct wiphy *wiphy, struct wiphy_work *work)
3771 {
3772 	struct ieee80211_link_data *link =
3773 		container_of(work, struct ieee80211_link_data, csa_finalize_work);
3774 	struct ieee80211_sub_if_data *sdata = link->sdata;
3775 	struct ieee80211_local *local = sdata->local;
3776 
3777 	lockdep_assert_wiphy(local->hw.wiphy);
3778 
3779 	/* AP might have been stopped while waiting for the lock. */
3780 	if (!link->conf->csa_active)
3781 		return;
3782 
3783 	if (!ieee80211_sdata_running(sdata))
3784 		return;
3785 
3786 	ieee80211_csa_finalize(link);
3787 }
3788 
3789 static int ieee80211_set_csa_beacon(struct ieee80211_link_data *link_data,
3790 				    struct cfg80211_csa_settings *params,
3791 				    u64 *changed)
3792 {
3793 	struct ieee80211_sub_if_data *sdata = link_data->sdata;
3794 	struct ieee80211_csa_settings csa = {};
3795 	int err;
3796 
3797 	switch (sdata->vif.type) {
3798 	case NL80211_IFTYPE_AP:
3799 		link_data->u.ap.next_beacon =
3800 			cfg80211_beacon_dup(&params->beacon_after);
3801 		if (!link_data->u.ap.next_beacon)
3802 			return -ENOMEM;
3803 
3804 		/*
3805 		 * With a count of 0, we don't have to wait for any
3806 		 * TBTT before switching, so complete the CSA
3807 		 * immediately.  In theory, with a count == 1 we
3808 		 * should delay the switch until just before the next
3809 		 * TBTT, but that would complicate things so we switch
3810 		 * immediately too.  If we would delay the switch
3811 		 * until the next TBTT, we would have to set the probe
3812 		 * response here.
3813 		 *
3814 		 * TODO: A channel switch with count <= 1 without
3815 		 * sending a CSA action frame is kind of useless,
3816 		 * because the clients won't know we're changing
3817 		 * channels.  The action frame must be implemented
3818 		 * either here or in the userspace.
3819 		 */
3820 		if (params->count <= 1)
3821 			break;
3822 
3823 		if ((params->n_counter_offsets_beacon >
3824 		     IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
3825 		    (params->n_counter_offsets_presp >
3826 		     IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
3827 			ieee80211_free_next_beacon(link_data);
3828 			return -EINVAL;
3829 		}
3830 
3831 		csa.counter_offsets_beacon = params->counter_offsets_beacon;
3832 		csa.counter_offsets_presp = params->counter_offsets_presp;
3833 		csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3834 		csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3835 		csa.count = params->count;
3836 
3837 		err = ieee80211_assign_beacon(sdata, link_data,
3838 					      &params->beacon_csa, &csa,
3839 					      NULL, changed);
3840 		if (err < 0) {
3841 			ieee80211_free_next_beacon(link_data);
3842 			return err;
3843 		}
3844 
3845 		break;
3846 	case NL80211_IFTYPE_ADHOC:
3847 		if (!sdata->vif.cfg.ibss_joined)
3848 			return -EINVAL;
3849 
3850 		if (params->chandef.width != sdata->u.ibss.chandef.width)
3851 			return -EINVAL;
3852 
3853 		switch (params->chandef.width) {
3854 		case NL80211_CHAN_WIDTH_40:
3855 			if (cfg80211_get_chandef_type(&params->chandef) !=
3856 			    cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3857 				return -EINVAL;
3858 			break;
3859 		case NL80211_CHAN_WIDTH_5:
3860 		case NL80211_CHAN_WIDTH_10:
3861 		case NL80211_CHAN_WIDTH_20_NOHT:
3862 		case NL80211_CHAN_WIDTH_20:
3863 			break;
3864 		default:
3865 			return -EINVAL;
3866 		}
3867 
3868 		/* changes into another band are not supported */
3869 		if (sdata->u.ibss.chandef.chan->band !=
3870 		    params->chandef.chan->band)
3871 			return -EINVAL;
3872 
3873 		/* see comments in the NL80211_IFTYPE_AP block */
3874 		if (params->count > 1) {
3875 			err = ieee80211_ibss_csa_beacon(sdata, params, changed);
3876 			if (err < 0)
3877 				return err;
3878 		}
3879 
3880 		ieee80211_send_action_csa(sdata, params);
3881 
3882 		break;
3883 #ifdef CONFIG_MAC80211_MESH
3884 	case NL80211_IFTYPE_MESH_POINT: {
3885 		struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3886 
3887 		/* changes into another band are not supported */
3888 		if (sdata->vif.bss_conf.chanreq.oper.chan->band !=
3889 		    params->chandef.chan->band)
3890 			return -EINVAL;
3891 
3892 		if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3893 			ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3894 			if (!ifmsh->pre_value)
3895 				ifmsh->pre_value = 1;
3896 			else
3897 				ifmsh->pre_value++;
3898 		}
3899 
3900 		/* see comments in the NL80211_IFTYPE_AP block */
3901 		if (params->count > 1) {
3902 			err = ieee80211_mesh_csa_beacon(sdata, params, changed);
3903 			if (err < 0) {
3904 				ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3905 				return err;
3906 			}
3907 		}
3908 
3909 		if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3910 			ieee80211_send_action_csa(sdata, params);
3911 
3912 		break;
3913 		}
3914 #endif
3915 	default:
3916 		return -EOPNOTSUPP;
3917 	}
3918 
3919 	return 0;
3920 }
3921 
3922 static void ieee80211_color_change_abort(struct ieee80211_link_data *link)
3923 {
3924 	link->conf->color_change_active = false;
3925 
3926 	ieee80211_free_next_beacon(link);
3927 
3928 	cfg80211_color_change_aborted_notify(link->sdata->dev, link->link_id);
3929 }
3930 
3931 static int
3932 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3933 			   struct cfg80211_csa_settings *params)
3934 {
3935 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3936 	struct ieee80211_chan_req chanreq = { .oper = params->chandef };
3937 	struct ieee80211_local *local = sdata->local;
3938 	struct ieee80211_channel_switch ch_switch = {
3939 		.link_id = params->link_id,
3940 	};
3941 	struct ieee80211_chanctx_conf *conf;
3942 	struct ieee80211_chanctx *chanctx;
3943 	struct ieee80211_bss_conf *link_conf;
3944 	struct ieee80211_link_data *link_data;
3945 	u64 changed = 0;
3946 	u8 link_id = params->link_id;
3947 	int err;
3948 
3949 	lockdep_assert_wiphy(local->hw.wiphy);
3950 
3951 	if (!list_empty(&local->roc_list) || local->scanning)
3952 		return -EBUSY;
3953 
3954 	if (sdata->wdev.cac_started)
3955 		return -EBUSY;
3956 
3957 	if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
3958 		return -EINVAL;
3959 
3960 	link_data = wiphy_dereference(wiphy, sdata->link[link_id]);
3961 	if (!link_data)
3962 		return -ENOLINK;
3963 
3964 	link_conf = link_data->conf;
3965 
3966 	if (chanreq.oper.punctured && !link_conf->eht_support)
3967 		return -EINVAL;
3968 
3969 	/* don't allow another channel switch if one is already active. */
3970 	if (link_conf->csa_active)
3971 		return -EBUSY;
3972 
3973 	conf = wiphy_dereference(wiphy, link_conf->chanctx_conf);
3974 	if (!conf) {
3975 		err = -EBUSY;
3976 		goto out;
3977 	}
3978 
3979 	if (params->chandef.chan->freq_offset) {
3980 		/* this may work, but is untested */
3981 		err = -EOPNOTSUPP;
3982 		goto out;
3983 	}
3984 
3985 	chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3986 
3987 	ch_switch.timestamp = 0;
3988 	ch_switch.device_timestamp = 0;
3989 	ch_switch.block_tx = params->block_tx;
3990 	ch_switch.chandef = chanreq.oper;
3991 	ch_switch.count = params->count;
3992 
3993 	err = drv_pre_channel_switch(sdata, &ch_switch);
3994 	if (err)
3995 		goto out;
3996 
3997 	err = ieee80211_link_reserve_chanctx(link_data, &chanreq,
3998 					     chanctx->mode,
3999 					     params->radar_required);
4000 	if (err)
4001 		goto out;
4002 
4003 	/* if reservation is invalid then this will fail */
4004 	err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
4005 	if (err) {
4006 		ieee80211_link_unreserve_chanctx(link_data);
4007 		goto out;
4008 	}
4009 
4010 	/* if there is a color change in progress, abort it */
4011 	if (link_conf->color_change_active)
4012 		ieee80211_color_change_abort(link_data);
4013 
4014 	err = ieee80211_set_csa_beacon(link_data, params, &changed);
4015 	if (err) {
4016 		ieee80211_link_unreserve_chanctx(link_data);
4017 		goto out;
4018 	}
4019 
4020 	link_data->csa_chanreq = chanreq;
4021 	link_conf->csa_active = true;
4022 
4023 	if (params->block_tx &&
4024 	    !ieee80211_hw_check(&local->hw, HANDLES_QUIET_CSA)) {
4025 		ieee80211_stop_vif_queues(local, sdata,
4026 					  IEEE80211_QUEUE_STOP_REASON_CSA);
4027 		sdata->csa_blocked_queues = true;
4028 	}
4029 
4030 	cfg80211_ch_switch_started_notify(sdata->dev,
4031 					  &link_data->csa_chanreq.oper, link_id,
4032 					  params->count, params->block_tx);
4033 
4034 	if (changed) {
4035 		ieee80211_link_info_change_notify(sdata, link_data, changed);
4036 		drv_channel_switch_beacon(sdata, &link_data->csa_chanreq.oper);
4037 	} else {
4038 		/* if the beacon didn't change, we can finalize immediately */
4039 		ieee80211_csa_finalize(link_data);
4040 	}
4041 
4042 out:
4043 	return err;
4044 }
4045 
4046 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
4047 			     struct cfg80211_csa_settings *params)
4048 {
4049 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4050 	struct ieee80211_local *local = sdata->local;
4051 
4052 	lockdep_assert_wiphy(local->hw.wiphy);
4053 
4054 	return __ieee80211_channel_switch(wiphy, dev, params);
4055 }
4056 
4057 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
4058 {
4059 	lockdep_assert_wiphy(local->hw.wiphy);
4060 
4061 	local->roc_cookie_counter++;
4062 
4063 	/* wow, you wrapped 64 bits ... more likely a bug */
4064 	if (WARN_ON(local->roc_cookie_counter == 0))
4065 		local->roc_cookie_counter++;
4066 
4067 	return local->roc_cookie_counter;
4068 }
4069 
4070 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
4071 			     u64 *cookie, gfp_t gfp)
4072 {
4073 	unsigned long spin_flags;
4074 	struct sk_buff *ack_skb;
4075 	int id;
4076 
4077 	ack_skb = skb_copy(skb, gfp);
4078 	if (!ack_skb)
4079 		return -ENOMEM;
4080 
4081 	spin_lock_irqsave(&local->ack_status_lock, spin_flags);
4082 	id = idr_alloc(&local->ack_status_frames, ack_skb,
4083 		       1, 0x2000, GFP_ATOMIC);
4084 	spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
4085 
4086 	if (id < 0) {
4087 		kfree_skb(ack_skb);
4088 		return -ENOMEM;
4089 	}
4090 
4091 	IEEE80211_SKB_CB(skb)->status_data_idr = 1;
4092 	IEEE80211_SKB_CB(skb)->status_data = id;
4093 
4094 	*cookie = ieee80211_mgmt_tx_cookie(local);
4095 	IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
4096 
4097 	return 0;
4098 }
4099 
4100 static void
4101 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
4102 					  struct wireless_dev *wdev,
4103 					  struct mgmt_frame_regs *upd)
4104 {
4105 	struct ieee80211_local *local = wiphy_priv(wiphy);
4106 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4107 	u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
4108 	u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
4109 	bool global_change, intf_change;
4110 
4111 	global_change =
4112 		(local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
4113 		(local->rx_mcast_action_reg !=
4114 		 !!(upd->global_mcast_stypes & action_mask));
4115 	local->probe_req_reg = upd->global_stypes & preq_mask;
4116 	local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
4117 
4118 	intf_change = (sdata->vif.probe_req_reg !=
4119 		       !!(upd->interface_stypes & preq_mask)) ||
4120 		(sdata->vif.rx_mcast_action_reg !=
4121 		 !!(upd->interface_mcast_stypes & action_mask));
4122 	sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
4123 	sdata->vif.rx_mcast_action_reg =
4124 		upd->interface_mcast_stypes & action_mask;
4125 
4126 	if (!local->open_count)
4127 		return;
4128 
4129 	if (intf_change && ieee80211_sdata_running(sdata))
4130 		drv_config_iface_filter(local, sdata,
4131 					sdata->vif.probe_req_reg ?
4132 						FIF_PROBE_REQ : 0,
4133 					FIF_PROBE_REQ);
4134 
4135 	if (global_change)
4136 		ieee80211_configure_filter(local);
4137 }
4138 
4139 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
4140 {
4141 	struct ieee80211_local *local = wiphy_priv(wiphy);
4142 	int ret;
4143 
4144 	if (local->started)
4145 		return -EOPNOTSUPP;
4146 
4147 	ret = drv_set_antenna(local, tx_ant, rx_ant);
4148 	if (ret)
4149 		return ret;
4150 
4151 	local->rx_chains = hweight8(rx_ant);
4152 	return 0;
4153 }
4154 
4155 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
4156 {
4157 	struct ieee80211_local *local = wiphy_priv(wiphy);
4158 
4159 	return drv_get_antenna(local, tx_ant, rx_ant);
4160 }
4161 
4162 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
4163 				    struct net_device *dev,
4164 				    struct cfg80211_gtk_rekey_data *data)
4165 {
4166 	struct ieee80211_local *local = wiphy_priv(wiphy);
4167 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4168 
4169 	if (!local->ops->set_rekey_data)
4170 		return -EOPNOTSUPP;
4171 
4172 	drv_set_rekey_data(local, sdata, data);
4173 
4174 	return 0;
4175 }
4176 
4177 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
4178 				  const u8 *peer, u64 *cookie)
4179 {
4180 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4181 	struct ieee80211_local *local = sdata->local;
4182 	struct ieee80211_qos_hdr *nullfunc;
4183 	struct sk_buff *skb;
4184 	int size = sizeof(*nullfunc);
4185 	__le16 fc;
4186 	bool qos;
4187 	struct ieee80211_tx_info *info;
4188 	struct sta_info *sta;
4189 	struct ieee80211_chanctx_conf *chanctx_conf;
4190 	enum nl80211_band band;
4191 	int ret;
4192 
4193 	/* the lock is needed to assign the cookie later */
4194 	lockdep_assert_wiphy(local->hw.wiphy);
4195 
4196 	rcu_read_lock();
4197 	sta = sta_info_get_bss(sdata, peer);
4198 	if (!sta) {
4199 		ret = -ENOLINK;
4200 		goto unlock;
4201 	}
4202 
4203 	qos = sta->sta.wme;
4204 
4205 	chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
4206 	if (WARN_ON(!chanctx_conf)) {
4207 		ret = -EINVAL;
4208 		goto unlock;
4209 	}
4210 	band = chanctx_conf->def.chan->band;
4211 
4212 	if (qos) {
4213 		fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4214 				 IEEE80211_STYPE_QOS_NULLFUNC |
4215 				 IEEE80211_FCTL_FROMDS);
4216 	} else {
4217 		size -= 2;
4218 		fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4219 				 IEEE80211_STYPE_NULLFUNC |
4220 				 IEEE80211_FCTL_FROMDS);
4221 	}
4222 
4223 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
4224 	if (!skb) {
4225 		ret = -ENOMEM;
4226 		goto unlock;
4227 	}
4228 
4229 	skb->dev = dev;
4230 
4231 	skb_reserve(skb, local->hw.extra_tx_headroom);
4232 
4233 	nullfunc = skb_put(skb, size);
4234 	nullfunc->frame_control = fc;
4235 	nullfunc->duration_id = 0;
4236 	memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
4237 	memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
4238 	memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
4239 	nullfunc->seq_ctrl = 0;
4240 
4241 	info = IEEE80211_SKB_CB(skb);
4242 
4243 	info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
4244 		       IEEE80211_TX_INTFL_NL80211_FRAME_TX;
4245 	info->band = band;
4246 
4247 	skb_set_queue_mapping(skb, IEEE80211_AC_VO);
4248 	skb->priority = 7;
4249 	if (qos)
4250 		nullfunc->qos_ctrl = cpu_to_le16(7);
4251 
4252 	ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
4253 	if (ret) {
4254 		kfree_skb(skb);
4255 		goto unlock;
4256 	}
4257 
4258 	local_bh_disable();
4259 	ieee80211_xmit(sdata, sta, skb);
4260 	local_bh_enable();
4261 
4262 	ret = 0;
4263 unlock:
4264 	rcu_read_unlock();
4265 
4266 	return ret;
4267 }
4268 
4269 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
4270 				     struct wireless_dev *wdev,
4271 				     unsigned int link_id,
4272 				     struct cfg80211_chan_def *chandef)
4273 {
4274 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4275 	struct ieee80211_local *local = wiphy_priv(wiphy);
4276 	struct ieee80211_chanctx_conf *chanctx_conf;
4277 	struct ieee80211_link_data *link;
4278 	int ret = -ENODATA;
4279 
4280 	rcu_read_lock();
4281 	link = rcu_dereference(sdata->link[link_id]);
4282 	if (!link) {
4283 		ret = -ENOLINK;
4284 		goto out;
4285 	}
4286 
4287 	chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
4288 	if (chanctx_conf) {
4289 		*chandef = link->conf->chanreq.oper;
4290 		ret = 0;
4291 	} else if (local->open_count > 0 &&
4292 		   local->open_count == local->monitors &&
4293 		   sdata->vif.type == NL80211_IFTYPE_MONITOR) {
4294 		*chandef = local->monitor_chanreq.oper;
4295 		ret = 0;
4296 	}
4297 out:
4298 	rcu_read_unlock();
4299 
4300 	return ret;
4301 }
4302 
4303 #ifdef CONFIG_PM
4304 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
4305 {
4306 	drv_set_wakeup(wiphy_priv(wiphy), enabled);
4307 }
4308 #endif
4309 
4310 static int ieee80211_set_qos_map(struct wiphy *wiphy,
4311 				 struct net_device *dev,
4312 				 struct cfg80211_qos_map *qos_map)
4313 {
4314 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4315 	struct mac80211_qos_map *new_qos_map, *old_qos_map;
4316 
4317 	if (qos_map) {
4318 		new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
4319 		if (!new_qos_map)
4320 			return -ENOMEM;
4321 		memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
4322 	} else {
4323 		/* A NULL qos_map was passed to disable QoS mapping */
4324 		new_qos_map = NULL;
4325 	}
4326 
4327 	old_qos_map = sdata_dereference(sdata->qos_map, sdata);
4328 	rcu_assign_pointer(sdata->qos_map, new_qos_map);
4329 	if (old_qos_map)
4330 		kfree_rcu(old_qos_map, rcu_head);
4331 
4332 	return 0;
4333 }
4334 
4335 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
4336 				      struct net_device *dev,
4337 				      unsigned int link_id,
4338 				      struct cfg80211_chan_def *chandef)
4339 {
4340 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4341 	struct ieee80211_link_data *link;
4342 	struct ieee80211_chan_req chanreq = { .oper = *chandef };
4343 	int ret;
4344 	u64 changed = 0;
4345 
4346 	link = sdata_dereference(sdata->link[link_id], sdata);
4347 
4348 	ret = ieee80211_link_change_chanreq(link, &chanreq, &changed);
4349 	if (ret == 0)
4350 		ieee80211_link_info_change_notify(sdata, link, changed);
4351 
4352 	return ret;
4353 }
4354 
4355 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4356 			       u8 tsid, const u8 *peer, u8 up,
4357 			       u16 admitted_time)
4358 {
4359 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4360 	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4361 	int ac = ieee802_1d_to_ac[up];
4362 
4363 	if (sdata->vif.type != NL80211_IFTYPE_STATION)
4364 		return -EOPNOTSUPP;
4365 
4366 	if (!(sdata->wmm_acm & BIT(up)))
4367 		return -EINVAL;
4368 
4369 	if (ifmgd->tx_tspec[ac].admitted_time)
4370 		return -EBUSY;
4371 
4372 	if (admitted_time) {
4373 		ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4374 		ifmgd->tx_tspec[ac].tsid = tsid;
4375 		ifmgd->tx_tspec[ac].up = up;
4376 	}
4377 
4378 	return 0;
4379 }
4380 
4381 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4382 			       u8 tsid, const u8 *peer)
4383 {
4384 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4385 	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4386 	struct ieee80211_local *local = wiphy_priv(wiphy);
4387 	int ac;
4388 
4389 	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4390 		struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4391 
4392 		/* skip unused entries */
4393 		if (!tx_tspec->admitted_time)
4394 			continue;
4395 
4396 		if (tx_tspec->tsid != tsid)
4397 			continue;
4398 
4399 		/* due to this new packets will be reassigned to non-ACM ACs */
4400 		tx_tspec->up = -1;
4401 
4402 		/* Make sure that all packets have been sent to avoid to
4403 		 * restore the QoS params on packets that are still on the
4404 		 * queues.
4405 		 */
4406 		synchronize_net();
4407 		ieee80211_flush_queues(local, sdata, false);
4408 
4409 		/* restore the normal QoS parameters
4410 		 * (unconditionally to avoid races)
4411 		 */
4412 		tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4413 		tx_tspec->downgraded = false;
4414 		ieee80211_sta_handle_tspec_ac_params(sdata);
4415 
4416 		/* finally clear all the data */
4417 		memset(tx_tspec, 0, sizeof(*tx_tspec));
4418 
4419 		return 0;
4420 	}
4421 
4422 	return -ENOENT;
4423 }
4424 
4425 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4426 				   u8 inst_id,
4427 				   enum nl80211_nan_func_term_reason reason,
4428 				   gfp_t gfp)
4429 {
4430 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4431 	struct cfg80211_nan_func *func;
4432 	u64 cookie;
4433 
4434 	if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4435 		return;
4436 
4437 	spin_lock_bh(&sdata->u.nan.func_lock);
4438 
4439 	func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4440 	if (WARN_ON(!func)) {
4441 		spin_unlock_bh(&sdata->u.nan.func_lock);
4442 		return;
4443 	}
4444 
4445 	cookie = func->cookie;
4446 	idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4447 
4448 	spin_unlock_bh(&sdata->u.nan.func_lock);
4449 
4450 	cfg80211_free_nan_func(func);
4451 
4452 	cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4453 				     reason, cookie, gfp);
4454 }
4455 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4456 
4457 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4458 			      struct cfg80211_nan_match_params *match,
4459 			      gfp_t gfp)
4460 {
4461 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4462 	struct cfg80211_nan_func *func;
4463 
4464 	if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4465 		return;
4466 
4467 	spin_lock_bh(&sdata->u.nan.func_lock);
4468 
4469 	func = idr_find(&sdata->u.nan.function_inst_ids,  match->inst_id);
4470 	if (WARN_ON(!func)) {
4471 		spin_unlock_bh(&sdata->u.nan.func_lock);
4472 		return;
4473 	}
4474 	match->cookie = func->cookie;
4475 
4476 	spin_unlock_bh(&sdata->u.nan.func_lock);
4477 
4478 	cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4479 }
4480 EXPORT_SYMBOL(ieee80211_nan_func_match);
4481 
4482 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4483 					      struct net_device *dev,
4484 					      const bool enabled)
4485 {
4486 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4487 
4488 	sdata->u.ap.multicast_to_unicast = enabled;
4489 
4490 	return 0;
4491 }
4492 
4493 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4494 			      struct txq_info *txqi)
4495 {
4496 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4497 		txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4498 		txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4499 	}
4500 
4501 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4502 		txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4503 		txqstats->backlog_packets = txqi->tin.backlog_packets;
4504 	}
4505 
4506 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4507 		txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4508 		txqstats->flows = txqi->tin.flows;
4509 	}
4510 
4511 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4512 		txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4513 		txqstats->drops = txqi->cstats.drop_count;
4514 	}
4515 
4516 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4517 		txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4518 		txqstats->ecn_marks = txqi->cstats.ecn_mark;
4519 	}
4520 
4521 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4522 		txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4523 		txqstats->overlimit = txqi->tin.overlimit;
4524 	}
4525 
4526 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4527 		txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4528 		txqstats->collisions = txqi->tin.collisions;
4529 	}
4530 
4531 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4532 		txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4533 		txqstats->tx_bytes = txqi->tin.tx_bytes;
4534 	}
4535 
4536 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4537 		txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4538 		txqstats->tx_packets = txqi->tin.tx_packets;
4539 	}
4540 }
4541 
4542 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4543 				   struct wireless_dev *wdev,
4544 				   struct cfg80211_txq_stats *txqstats)
4545 {
4546 	struct ieee80211_local *local = wiphy_priv(wiphy);
4547 	struct ieee80211_sub_if_data *sdata;
4548 	int ret = 0;
4549 
4550 	spin_lock_bh(&local->fq.lock);
4551 	rcu_read_lock();
4552 
4553 	if (wdev) {
4554 		sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4555 		if (!sdata->vif.txq) {
4556 			ret = 1;
4557 			goto out;
4558 		}
4559 		ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4560 	} else {
4561 		/* phy stats */
4562 		txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4563 				    BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4564 				    BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4565 				    BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4566 				    BIT(NL80211_TXQ_STATS_COLLISIONS) |
4567 				    BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4568 		txqstats->backlog_packets = local->fq.backlog;
4569 		txqstats->backlog_bytes = local->fq.memory_usage;
4570 		txqstats->overlimit = local->fq.overlimit;
4571 		txqstats->overmemory = local->fq.overmemory;
4572 		txqstats->collisions = local->fq.collisions;
4573 		txqstats->max_flows = local->fq.flows_cnt;
4574 	}
4575 
4576 out:
4577 	rcu_read_unlock();
4578 	spin_unlock_bh(&local->fq.lock);
4579 
4580 	return ret;
4581 }
4582 
4583 static int
4584 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4585 				  struct net_device *dev,
4586 				  struct cfg80211_ftm_responder_stats *ftm_stats)
4587 {
4588 	struct ieee80211_local *local = wiphy_priv(wiphy);
4589 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4590 
4591 	return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4592 }
4593 
4594 static int
4595 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4596 		     struct cfg80211_pmsr_request *request)
4597 {
4598 	struct ieee80211_local *local = wiphy_priv(wiphy);
4599 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4600 
4601 	return drv_start_pmsr(local, sdata, request);
4602 }
4603 
4604 static void
4605 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4606 		     struct cfg80211_pmsr_request *request)
4607 {
4608 	struct ieee80211_local *local = wiphy_priv(wiphy);
4609 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4610 
4611 	return drv_abort_pmsr(local, sdata, request);
4612 }
4613 
4614 static int ieee80211_set_tid_config(struct wiphy *wiphy,
4615 				    struct net_device *dev,
4616 				    struct cfg80211_tid_config *tid_conf)
4617 {
4618 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4619 	struct sta_info *sta;
4620 
4621 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
4622 
4623 	if (!sdata->local->ops->set_tid_config)
4624 		return -EOPNOTSUPP;
4625 
4626 	if (!tid_conf->peer)
4627 		return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4628 
4629 	sta = sta_info_get_bss(sdata, tid_conf->peer);
4630 	if (!sta)
4631 		return -ENOENT;
4632 
4633 	return drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4634 }
4635 
4636 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4637 				      struct net_device *dev,
4638 				      const u8 *peer, u8 tids)
4639 {
4640 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4641 	struct sta_info *sta;
4642 
4643 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
4644 
4645 	if (!sdata->local->ops->reset_tid_config)
4646 		return -EOPNOTSUPP;
4647 
4648 	if (!peer)
4649 		return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
4650 
4651 	sta = sta_info_get_bss(sdata, peer);
4652 	if (!sta)
4653 		return -ENOENT;
4654 
4655 	return drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
4656 }
4657 
4658 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4659 				   struct cfg80211_sar_specs *sar)
4660 {
4661 	struct ieee80211_local *local = wiphy_priv(wiphy);
4662 
4663 	if (!local->ops->set_sar_specs)
4664 		return -EOPNOTSUPP;
4665 
4666 	return local->ops->set_sar_specs(&local->hw, sar);
4667 }
4668 
4669 static int
4670 ieee80211_set_after_color_change_beacon(struct ieee80211_link_data *link,
4671 					u64 *changed)
4672 {
4673 	struct ieee80211_sub_if_data *sdata = link->sdata;
4674 
4675 	switch (sdata->vif.type) {
4676 	case NL80211_IFTYPE_AP: {
4677 		int ret;
4678 
4679 		if (!link->u.ap.next_beacon)
4680 			return -EINVAL;
4681 
4682 		ret = ieee80211_assign_beacon(sdata, link,
4683 					      link->u.ap.next_beacon,
4684 					      NULL, NULL, changed);
4685 		ieee80211_free_next_beacon(link);
4686 
4687 		if (ret < 0)
4688 			return ret;
4689 
4690 		break;
4691 	}
4692 	default:
4693 		WARN_ON_ONCE(1);
4694 		return -EINVAL;
4695 	}
4696 
4697 	return 0;
4698 }
4699 
4700 static int
4701 ieee80211_set_color_change_beacon(struct ieee80211_link_data *link,
4702 				  struct cfg80211_color_change_settings *params,
4703 				  u64 *changed)
4704 {
4705 	struct ieee80211_sub_if_data *sdata = link->sdata;
4706 	struct ieee80211_color_change_settings color_change = {};
4707 	int err;
4708 
4709 	switch (sdata->vif.type) {
4710 	case NL80211_IFTYPE_AP:
4711 		link->u.ap.next_beacon =
4712 			cfg80211_beacon_dup(&params->beacon_next);
4713 		if (!link->u.ap.next_beacon)
4714 			return -ENOMEM;
4715 
4716 		if (params->count <= 1)
4717 			break;
4718 
4719 		color_change.counter_offset_beacon =
4720 			params->counter_offset_beacon;
4721 		color_change.counter_offset_presp =
4722 			params->counter_offset_presp;
4723 		color_change.count = params->count;
4724 
4725 		err = ieee80211_assign_beacon(sdata, link,
4726 					      &params->beacon_color_change,
4727 					      NULL, &color_change, changed);
4728 		if (err < 0) {
4729 			ieee80211_free_next_beacon(link);
4730 			return err;
4731 		}
4732 		break;
4733 	default:
4734 		return -EOPNOTSUPP;
4735 	}
4736 
4737 	return 0;
4738 }
4739 
4740 static void
4741 ieee80211_color_change_bss_config_notify(struct ieee80211_link_data *link,
4742 					 u8 color, int enable, u64 changed)
4743 {
4744 	struct ieee80211_sub_if_data *sdata = link->sdata;
4745 
4746 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
4747 
4748 	link->conf->he_bss_color.color = color;
4749 	link->conf->he_bss_color.enabled = enable;
4750 	changed |= BSS_CHANGED_HE_BSS_COLOR;
4751 
4752 	ieee80211_link_info_change_notify(sdata, link, changed);
4753 
4754 	if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4755 		struct ieee80211_sub_if_data *child;
4756 
4757 		list_for_each_entry(child, &sdata->local->interfaces, list) {
4758 			if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4759 				child->vif.bss_conf.he_bss_color.color = color;
4760 				child->vif.bss_conf.he_bss_color.enabled = enable;
4761 				ieee80211_link_info_change_notify(child,
4762 								  &child->deflink,
4763 								  BSS_CHANGED_HE_BSS_COLOR);
4764 			}
4765 		}
4766 	}
4767 }
4768 
4769 static int ieee80211_color_change_finalize(struct ieee80211_link_data *link)
4770 {
4771 	struct ieee80211_sub_if_data *sdata = link->sdata;
4772 	struct ieee80211_local *local = sdata->local;
4773 	u64 changed = 0;
4774 	int err;
4775 
4776 	lockdep_assert_wiphy(local->hw.wiphy);
4777 
4778 	link->conf->color_change_active = false;
4779 
4780 	err = ieee80211_set_after_color_change_beacon(link, &changed);
4781 	if (err) {
4782 		cfg80211_color_change_aborted_notify(sdata->dev, link->link_id);
4783 		return err;
4784 	}
4785 
4786 	ieee80211_color_change_bss_config_notify(link,
4787 						 link->conf->color_change_color,
4788 						 1, changed);
4789 	cfg80211_color_change_notify(sdata->dev, link->link_id);
4790 
4791 	return 0;
4792 }
4793 
4794 void ieee80211_color_change_finalize_work(struct wiphy *wiphy,
4795 					  struct wiphy_work *work)
4796 {
4797 	struct ieee80211_link_data *link =
4798 		container_of(work, struct ieee80211_link_data,
4799 			     color_change_finalize_work);
4800 	struct ieee80211_sub_if_data *sdata = link->sdata;
4801 	struct ieee80211_bss_conf *link_conf = link->conf;
4802 	struct ieee80211_local *local = sdata->local;
4803 
4804 	lockdep_assert_wiphy(local->hw.wiphy);
4805 
4806 	/* AP might have been stopped while waiting for the lock. */
4807 	if (!link_conf->color_change_active)
4808 		return;
4809 
4810 	if (!ieee80211_sdata_running(sdata))
4811 		return;
4812 
4813 	ieee80211_color_change_finalize(link);
4814 }
4815 
4816 void ieee80211_color_collision_detection_work(struct work_struct *work)
4817 {
4818 	struct delayed_work *delayed_work = to_delayed_work(work);
4819 	struct ieee80211_link_data *link =
4820 		container_of(delayed_work, struct ieee80211_link_data,
4821 			     color_collision_detect_work);
4822 	struct ieee80211_sub_if_data *sdata = link->sdata;
4823 
4824 	cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap,
4825 					     link->link_id);
4826 }
4827 
4828 void ieee80211_color_change_finish(struct ieee80211_vif *vif, u8 link_id)
4829 {
4830 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4831 	struct ieee80211_link_data *link;
4832 
4833 	if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
4834 		return;
4835 
4836 	rcu_read_lock();
4837 
4838 	link = rcu_dereference(sdata->link[link_id]);
4839 	if (WARN_ON(!link)) {
4840 		rcu_read_unlock();
4841 		return;
4842 	}
4843 
4844 	wiphy_work_queue(sdata->local->hw.wiphy,
4845 			 &link->color_change_finalize_work);
4846 
4847 	rcu_read_unlock();
4848 }
4849 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4850 
4851 void
4852 ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
4853 				      u64 color_bitmap, u8 link_id)
4854 {
4855 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4856 	struct ieee80211_link_data *link;
4857 
4858 	if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
4859 		return;
4860 
4861 	rcu_read_lock();
4862 
4863 	link = rcu_dereference(sdata->link[link_id]);
4864 	if (WARN_ON(!link)) {
4865 		rcu_read_unlock();
4866 		return;
4867 	}
4868 
4869 	if (link->conf->color_change_active || link->conf->csa_active) {
4870 		rcu_read_unlock();
4871 		return;
4872 	}
4873 
4874 	if (delayed_work_pending(&link->color_collision_detect_work)) {
4875 		rcu_read_unlock();
4876 		return;
4877 	}
4878 
4879 	link->color_bitmap = color_bitmap;
4880 	/* queue the color collision detection event every 500 ms in order to
4881 	 * avoid sending too much netlink messages to userspace.
4882 	 */
4883 	ieee80211_queue_delayed_work(&sdata->local->hw,
4884 				     &link->color_collision_detect_work,
4885 				     msecs_to_jiffies(500));
4886 
4887 	rcu_read_unlock();
4888 }
4889 EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify);
4890 
4891 static int
4892 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4893 		       struct cfg80211_color_change_settings *params)
4894 {
4895 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4896 	struct ieee80211_local *local = sdata->local;
4897 	struct ieee80211_bss_conf *link_conf;
4898 	struct ieee80211_link_data *link;
4899 	u8 link_id = params->link_id;
4900 	u64 changed = 0;
4901 	int err;
4902 
4903 	lockdep_assert_wiphy(local->hw.wiphy);
4904 
4905 	if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
4906 		return -EINVAL;
4907 
4908 	link = wiphy_dereference(wiphy, sdata->link[link_id]);
4909 	if (!link)
4910 		return -ENOLINK;
4911 
4912 	link_conf = link->conf;
4913 
4914 	if (link_conf->nontransmitted)
4915 		return -EINVAL;
4916 
4917 	/* don't allow another color change if one is already active or if csa
4918 	 * is active
4919 	 */
4920 	if (link_conf->color_change_active || link_conf->csa_active) {
4921 		err = -EBUSY;
4922 		goto out;
4923 	}
4924 
4925 	err = ieee80211_set_color_change_beacon(link, params, &changed);
4926 	if (err)
4927 		goto out;
4928 
4929 	link_conf->color_change_active = true;
4930 	link_conf->color_change_color = params->color;
4931 
4932 	cfg80211_color_change_started_notify(sdata->dev, params->count, link_id);
4933 
4934 	if (changed)
4935 		ieee80211_color_change_bss_config_notify(link, 0, 0, changed);
4936 	else
4937 		/* if the beacon didn't change, we can finalize immediately */
4938 		ieee80211_color_change_finalize(link);
4939 
4940 out:
4941 
4942 	return err;
4943 }
4944 
4945 static int
4946 ieee80211_set_radar_background(struct wiphy *wiphy,
4947 			       struct cfg80211_chan_def *chandef)
4948 {
4949 	struct ieee80211_local *local = wiphy_priv(wiphy);
4950 
4951 	if (!local->ops->set_radar_background)
4952 		return -EOPNOTSUPP;
4953 
4954 	return local->ops->set_radar_background(&local->hw, chandef);
4955 }
4956 
4957 static int ieee80211_add_intf_link(struct wiphy *wiphy,
4958 				   struct wireless_dev *wdev,
4959 				   unsigned int link_id)
4960 {
4961 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4962 
4963 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
4964 
4965 	if (wdev->use_4addr)
4966 		return -EOPNOTSUPP;
4967 
4968 	return ieee80211_vif_set_links(sdata, wdev->valid_links, 0);
4969 }
4970 
4971 static void ieee80211_del_intf_link(struct wiphy *wiphy,
4972 				    struct wireless_dev *wdev,
4973 				    unsigned int link_id)
4974 {
4975 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4976 
4977 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
4978 
4979 	ieee80211_vif_set_links(sdata, wdev->valid_links, 0);
4980 }
4981 
4982 static int sta_add_link_station(struct ieee80211_local *local,
4983 				struct ieee80211_sub_if_data *sdata,
4984 				struct link_station_parameters *params)
4985 {
4986 	struct sta_info *sta;
4987 	int ret;
4988 
4989 	sta = sta_info_get_bss(sdata, params->mld_mac);
4990 	if (!sta)
4991 		return -ENOENT;
4992 
4993 	if (!sta->sta.valid_links)
4994 		return -EINVAL;
4995 
4996 	if (sta->sta.valid_links & BIT(params->link_id))
4997 		return -EALREADY;
4998 
4999 	ret = ieee80211_sta_allocate_link(sta, params->link_id);
5000 	if (ret)
5001 		return ret;
5002 
5003 	ret = sta_link_apply_parameters(local, sta, true, params);
5004 	if (ret) {
5005 		ieee80211_sta_free_link(sta, params->link_id);
5006 		return ret;
5007 	}
5008 
5009 	/* ieee80211_sta_activate_link frees the link upon failure */
5010 	return ieee80211_sta_activate_link(sta, params->link_id);
5011 }
5012 
5013 static int
5014 ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev,
5015 			   struct link_station_parameters *params)
5016 {
5017 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5018 	struct ieee80211_local *local = wiphy_priv(wiphy);
5019 
5020 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
5021 
5022 	return sta_add_link_station(local, sdata, params);
5023 }
5024 
5025 static int sta_mod_link_station(struct ieee80211_local *local,
5026 				struct ieee80211_sub_if_data *sdata,
5027 				struct link_station_parameters *params)
5028 {
5029 	struct sta_info *sta;
5030 
5031 	sta = sta_info_get_bss(sdata, params->mld_mac);
5032 	if (!sta)
5033 		return -ENOENT;
5034 
5035 	if (!(sta->sta.valid_links & BIT(params->link_id)))
5036 		return -EINVAL;
5037 
5038 	return sta_link_apply_parameters(local, sta, false, params);
5039 }
5040 
5041 static int
5042 ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev,
5043 			   struct link_station_parameters *params)
5044 {
5045 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5046 	struct ieee80211_local *local = wiphy_priv(wiphy);
5047 
5048 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
5049 
5050 	return sta_mod_link_station(local, sdata, params);
5051 }
5052 
5053 static int sta_del_link_station(struct ieee80211_sub_if_data *sdata,
5054 				struct link_station_del_parameters *params)
5055 {
5056 	struct sta_info *sta;
5057 
5058 	sta = sta_info_get_bss(sdata, params->mld_mac);
5059 	if (!sta)
5060 		return -ENOENT;
5061 
5062 	if (!(sta->sta.valid_links & BIT(params->link_id)))
5063 		return -EINVAL;
5064 
5065 	/* must not create a STA without links */
5066 	if (sta->sta.valid_links == BIT(params->link_id))
5067 		return -EINVAL;
5068 
5069 	ieee80211_sta_remove_link(sta, params->link_id);
5070 
5071 	return 0;
5072 }
5073 
5074 static int
5075 ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev,
5076 			   struct link_station_del_parameters *params)
5077 {
5078 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5079 
5080 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
5081 
5082 	return sta_del_link_station(sdata, params);
5083 }
5084 
5085 static int ieee80211_set_hw_timestamp(struct wiphy *wiphy,
5086 				      struct net_device *dev,
5087 				      struct cfg80211_set_hw_timestamp *hwts)
5088 {
5089 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5090 	struct ieee80211_local *local = sdata->local;
5091 
5092 	if (!local->ops->set_hw_timestamp)
5093 		return -EOPNOTSUPP;
5094 
5095 	if (!check_sdata_in_driver(sdata))
5096 		return -EIO;
5097 
5098 	return local->ops->set_hw_timestamp(&local->hw, &sdata->vif, hwts);
5099 }
5100 
5101 static int
5102 ieee80211_set_ttlm(struct wiphy *wiphy, struct net_device *dev,
5103 		   struct cfg80211_ttlm_params *params)
5104 {
5105 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5106 
5107 	lockdep_assert_wiphy(sdata->local->hw.wiphy);
5108 
5109 	return ieee80211_req_neg_ttlm(sdata, params);
5110 }
5111 
5112 const struct cfg80211_ops mac80211_config_ops = {
5113 	.add_virtual_intf = ieee80211_add_iface,
5114 	.del_virtual_intf = ieee80211_del_iface,
5115 	.change_virtual_intf = ieee80211_change_iface,
5116 	.start_p2p_device = ieee80211_start_p2p_device,
5117 	.stop_p2p_device = ieee80211_stop_p2p_device,
5118 	.add_key = ieee80211_add_key,
5119 	.del_key = ieee80211_del_key,
5120 	.get_key = ieee80211_get_key,
5121 	.set_default_key = ieee80211_config_default_key,
5122 	.set_default_mgmt_key = ieee80211_config_default_mgmt_key,
5123 	.set_default_beacon_key = ieee80211_config_default_beacon_key,
5124 	.start_ap = ieee80211_start_ap,
5125 	.change_beacon = ieee80211_change_beacon,
5126 	.stop_ap = ieee80211_stop_ap,
5127 	.add_station = ieee80211_add_station,
5128 	.del_station = ieee80211_del_station,
5129 	.change_station = ieee80211_change_station,
5130 	.get_station = ieee80211_get_station,
5131 	.dump_station = ieee80211_dump_station,
5132 	.dump_survey = ieee80211_dump_survey,
5133 #ifdef CONFIG_MAC80211_MESH
5134 	.add_mpath = ieee80211_add_mpath,
5135 	.del_mpath = ieee80211_del_mpath,
5136 	.change_mpath = ieee80211_change_mpath,
5137 	.get_mpath = ieee80211_get_mpath,
5138 	.dump_mpath = ieee80211_dump_mpath,
5139 	.get_mpp = ieee80211_get_mpp,
5140 	.dump_mpp = ieee80211_dump_mpp,
5141 	.update_mesh_config = ieee80211_update_mesh_config,
5142 	.get_mesh_config = ieee80211_get_mesh_config,
5143 	.join_mesh = ieee80211_join_mesh,
5144 	.leave_mesh = ieee80211_leave_mesh,
5145 #endif
5146 	.join_ocb = ieee80211_join_ocb,
5147 	.leave_ocb = ieee80211_leave_ocb,
5148 	.change_bss = ieee80211_change_bss,
5149 	.inform_bss = ieee80211_inform_bss,
5150 	.set_txq_params = ieee80211_set_txq_params,
5151 	.set_monitor_channel = ieee80211_set_monitor_channel,
5152 	.suspend = ieee80211_suspend,
5153 	.resume = ieee80211_resume,
5154 	.scan = ieee80211_scan,
5155 	.abort_scan = ieee80211_abort_scan,
5156 	.sched_scan_start = ieee80211_sched_scan_start,
5157 	.sched_scan_stop = ieee80211_sched_scan_stop,
5158 	.auth = ieee80211_auth,
5159 	.assoc = ieee80211_assoc,
5160 	.deauth = ieee80211_deauth,
5161 	.disassoc = ieee80211_disassoc,
5162 	.join_ibss = ieee80211_join_ibss,
5163 	.leave_ibss = ieee80211_leave_ibss,
5164 	.set_mcast_rate = ieee80211_set_mcast_rate,
5165 	.set_wiphy_params = ieee80211_set_wiphy_params,
5166 	.set_tx_power = ieee80211_set_tx_power,
5167 	.get_tx_power = ieee80211_get_tx_power,
5168 	.rfkill_poll = ieee80211_rfkill_poll,
5169 	CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
5170 	CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
5171 	.set_power_mgmt = ieee80211_set_power_mgmt,
5172 	.set_bitrate_mask = ieee80211_set_bitrate_mask,
5173 	.remain_on_channel = ieee80211_remain_on_channel,
5174 	.cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
5175 	.mgmt_tx = ieee80211_mgmt_tx,
5176 	.mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
5177 	.set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
5178 	.set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
5179 	.update_mgmt_frame_registrations =
5180 		ieee80211_update_mgmt_frame_registrations,
5181 	.set_antenna = ieee80211_set_antenna,
5182 	.get_antenna = ieee80211_get_antenna,
5183 	.set_rekey_data = ieee80211_set_rekey_data,
5184 	.tdls_oper = ieee80211_tdls_oper,
5185 	.tdls_mgmt = ieee80211_tdls_mgmt,
5186 	.tdls_channel_switch = ieee80211_tdls_channel_switch,
5187 	.tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
5188 	.probe_client = ieee80211_probe_client,
5189 	.set_noack_map = ieee80211_set_noack_map,
5190 #ifdef CONFIG_PM
5191 	.set_wakeup = ieee80211_set_wakeup,
5192 #endif
5193 	.get_channel = ieee80211_cfg_get_channel,
5194 	.start_radar_detection = ieee80211_start_radar_detection,
5195 	.end_cac = ieee80211_end_cac,
5196 	.channel_switch = ieee80211_channel_switch,
5197 	.set_qos_map = ieee80211_set_qos_map,
5198 	.set_ap_chanwidth = ieee80211_set_ap_chanwidth,
5199 	.add_tx_ts = ieee80211_add_tx_ts,
5200 	.del_tx_ts = ieee80211_del_tx_ts,
5201 	.start_nan = ieee80211_start_nan,
5202 	.stop_nan = ieee80211_stop_nan,
5203 	.nan_change_conf = ieee80211_nan_change_conf,
5204 	.add_nan_func = ieee80211_add_nan_func,
5205 	.del_nan_func = ieee80211_del_nan_func,
5206 	.set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
5207 	.tx_control_port = ieee80211_tx_control_port,
5208 	.get_txq_stats = ieee80211_get_txq_stats,
5209 	.get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
5210 	.start_pmsr = ieee80211_start_pmsr,
5211 	.abort_pmsr = ieee80211_abort_pmsr,
5212 	.probe_mesh_link = ieee80211_probe_mesh_link,
5213 	.set_tid_config = ieee80211_set_tid_config,
5214 	.reset_tid_config = ieee80211_reset_tid_config,
5215 	.set_sar_specs = ieee80211_set_sar_specs,
5216 	.color_change = ieee80211_color_change,
5217 	.set_radar_background = ieee80211_set_radar_background,
5218 	.add_intf_link = ieee80211_add_intf_link,
5219 	.del_intf_link = ieee80211_del_intf_link,
5220 	.add_link_station = ieee80211_add_link_station,
5221 	.mod_link_station = ieee80211_mod_link_station,
5222 	.del_link_station = ieee80211_del_link_station,
5223 	.set_hw_timestamp = ieee80211_set_hw_timestamp,
5224 	.set_ttlm = ieee80211_set_ttlm,
5225 };
5226