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