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