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