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