xref: /openbmc/linux/net/mac80211/cfg.c (revision f019679ea5f2ab650c3348a79e7d9c3625f62899)
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-2022 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 	struct ieee80211_key *key;
442 	int err;
443 
444 	if (!ieee80211_sdata_running(sdata))
445 		return -ENETDOWN;
446 
447 	if (pairwise && params->mode == NL80211_KEY_SET_TX)
448 		return ieee80211_set_tx(sdata, mac_addr, key_idx);
449 
450 	/* reject WEP and TKIP keys if WEP failed to initialize */
451 	switch (params->cipher) {
452 	case WLAN_CIPHER_SUITE_WEP40:
453 	case WLAN_CIPHER_SUITE_TKIP:
454 	case WLAN_CIPHER_SUITE_WEP104:
455 		if (WARN_ON_ONCE(fips_enabled))
456 			return -EINVAL;
457 		break;
458 	default:
459 		break;
460 	}
461 
462 	key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
463 				  params->key, params->seq_len, params->seq);
464 	if (IS_ERR(key))
465 		return PTR_ERR(key);
466 
467 	if (pairwise)
468 		key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
469 
470 	if (params->mode == NL80211_KEY_NO_TX)
471 		key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
472 
473 	mutex_lock(&local->sta_mtx);
474 
475 	if (mac_addr) {
476 		sta = sta_info_get_bss(sdata, mac_addr);
477 		/*
478 		 * The ASSOC test makes sure the driver is ready to
479 		 * receive the key. When wpa_supplicant has roamed
480 		 * using FT, it attempts to set the key before
481 		 * association has completed, this rejects that attempt
482 		 * so it will set the key again after association.
483 		 *
484 		 * TODO: accept the key if we have a station entry and
485 		 *       add it to the device after the station.
486 		 */
487 		if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
488 			ieee80211_key_free_unused(key);
489 			err = -ENOENT;
490 			goto out_unlock;
491 		}
492 	}
493 
494 	switch (sdata->vif.type) {
495 	case NL80211_IFTYPE_STATION:
496 		if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
497 			key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
498 		break;
499 	case NL80211_IFTYPE_AP:
500 	case NL80211_IFTYPE_AP_VLAN:
501 		/* Keys without a station are used for TX only */
502 		if (sta && test_sta_flag(sta, WLAN_STA_MFP))
503 			key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
504 		break;
505 	case NL80211_IFTYPE_ADHOC:
506 		/* no MFP (yet) */
507 		break;
508 	case NL80211_IFTYPE_MESH_POINT:
509 #ifdef CONFIG_MAC80211_MESH
510 		if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
511 			key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
512 		break;
513 #endif
514 	case NL80211_IFTYPE_WDS:
515 	case NL80211_IFTYPE_MONITOR:
516 	case NL80211_IFTYPE_P2P_DEVICE:
517 	case NL80211_IFTYPE_NAN:
518 	case NL80211_IFTYPE_UNSPECIFIED:
519 	case NUM_NL80211_IFTYPES:
520 	case NL80211_IFTYPE_P2P_CLIENT:
521 	case NL80211_IFTYPE_P2P_GO:
522 	case NL80211_IFTYPE_OCB:
523 		/* shouldn't happen */
524 		WARN_ON_ONCE(1);
525 		break;
526 	}
527 
528 	err = ieee80211_key_link(key, sdata, sta);
529 
530  out_unlock:
531 	mutex_unlock(&local->sta_mtx);
532 
533 	return err;
534 }
535 
536 static struct ieee80211_key *
537 ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata,
538 		     u8 key_idx, bool pairwise, const u8 *mac_addr)
539 {
540 	struct ieee80211_local *local = sdata->local;
541 	struct sta_info *sta;
542 
543 	if (mac_addr) {
544 		sta = sta_info_get_bss(sdata, mac_addr);
545 		if (!sta)
546 			return NULL;
547 
548 		if (pairwise && key_idx < NUM_DEFAULT_KEYS)
549 			return rcu_dereference_check_key_mtx(local,
550 							     sta->ptk[key_idx]);
551 
552 		if (!pairwise &&
553 		    key_idx < NUM_DEFAULT_KEYS +
554 			      NUM_DEFAULT_MGMT_KEYS +
555 			      NUM_DEFAULT_BEACON_KEYS)
556 			return rcu_dereference_check_key_mtx(local,
557 							     sta->deflink.gtk[key_idx]);
558 
559 		return NULL;
560 	}
561 
562 	if (key_idx < NUM_DEFAULT_KEYS +
563 		      NUM_DEFAULT_MGMT_KEYS +
564 		      NUM_DEFAULT_BEACON_KEYS)
565 		return rcu_dereference_check_key_mtx(local,
566 						     sdata->keys[key_idx]);
567 
568 	return NULL;
569 }
570 
571 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
572 			     u8 key_idx, bool pairwise, const u8 *mac_addr)
573 {
574 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
575 	struct ieee80211_local *local = sdata->local;
576 	struct ieee80211_key *key;
577 	int ret;
578 
579 	mutex_lock(&local->sta_mtx);
580 	mutex_lock(&local->key_mtx);
581 
582 	key = ieee80211_lookup_key(sdata, key_idx, pairwise, mac_addr);
583 	if (!key) {
584 		ret = -ENOENT;
585 		goto out_unlock;
586 	}
587 
588 	ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
589 
590 	ret = 0;
591  out_unlock:
592 	mutex_unlock(&local->key_mtx);
593 	mutex_unlock(&local->sta_mtx);
594 
595 	return ret;
596 }
597 
598 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
599 			     u8 key_idx, bool pairwise, const u8 *mac_addr,
600 			     void *cookie,
601 			     void (*callback)(void *cookie,
602 					      struct key_params *params))
603 {
604 	struct ieee80211_sub_if_data *sdata;
605 	u8 seq[6] = {0};
606 	struct key_params params;
607 	struct ieee80211_key *key;
608 	u64 pn64;
609 	u32 iv32;
610 	u16 iv16;
611 	int err = -ENOENT;
612 	struct ieee80211_key_seq kseq = {};
613 
614 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
615 
616 	rcu_read_lock();
617 
618 	key = ieee80211_lookup_key(sdata, key_idx, pairwise, mac_addr);
619 	if (!key)
620 		goto out;
621 
622 	memset(&params, 0, sizeof(params));
623 
624 	params.cipher = key->conf.cipher;
625 
626 	switch (key->conf.cipher) {
627 	case WLAN_CIPHER_SUITE_TKIP:
628 		pn64 = atomic64_read(&key->conf.tx_pn);
629 		iv32 = TKIP_PN_TO_IV32(pn64);
630 		iv16 = TKIP_PN_TO_IV16(pn64);
631 
632 		if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
633 		    !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
634 			drv_get_key_seq(sdata->local, key, &kseq);
635 			iv32 = kseq.tkip.iv32;
636 			iv16 = kseq.tkip.iv16;
637 		}
638 
639 		seq[0] = iv16 & 0xff;
640 		seq[1] = (iv16 >> 8) & 0xff;
641 		seq[2] = iv32 & 0xff;
642 		seq[3] = (iv32 >> 8) & 0xff;
643 		seq[4] = (iv32 >> 16) & 0xff;
644 		seq[5] = (iv32 >> 24) & 0xff;
645 		params.seq = seq;
646 		params.seq_len = 6;
647 		break;
648 	case WLAN_CIPHER_SUITE_CCMP:
649 	case WLAN_CIPHER_SUITE_CCMP_256:
650 	case WLAN_CIPHER_SUITE_AES_CMAC:
651 	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
652 		BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
653 			     offsetof(typeof(kseq), aes_cmac));
654 		fallthrough;
655 	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
656 	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
657 		BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
658 			     offsetof(typeof(kseq), aes_gmac));
659 		fallthrough;
660 	case WLAN_CIPHER_SUITE_GCMP:
661 	case WLAN_CIPHER_SUITE_GCMP_256:
662 		BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
663 			     offsetof(typeof(kseq), gcmp));
664 
665 		if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
666 		    !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
667 			drv_get_key_seq(sdata->local, key, &kseq);
668 			memcpy(seq, kseq.ccmp.pn, 6);
669 		} else {
670 			pn64 = atomic64_read(&key->conf.tx_pn);
671 			seq[0] = pn64;
672 			seq[1] = pn64 >> 8;
673 			seq[2] = pn64 >> 16;
674 			seq[3] = pn64 >> 24;
675 			seq[4] = pn64 >> 32;
676 			seq[5] = pn64 >> 40;
677 		}
678 		params.seq = seq;
679 		params.seq_len = 6;
680 		break;
681 	default:
682 		if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
683 			break;
684 		if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
685 			break;
686 		drv_get_key_seq(sdata->local, key, &kseq);
687 		params.seq = kseq.hw.seq;
688 		params.seq_len = kseq.hw.seq_len;
689 		break;
690 	}
691 
692 	params.key = key->conf.key;
693 	params.key_len = key->conf.keylen;
694 
695 	callback(cookie, &params);
696 	err = 0;
697 
698  out:
699 	rcu_read_unlock();
700 	return err;
701 }
702 
703 static int ieee80211_config_default_key(struct wiphy *wiphy,
704 					struct net_device *dev,
705 					u8 key_idx, bool uni,
706 					bool multi)
707 {
708 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
709 
710 	ieee80211_set_default_key(sdata, key_idx, uni, multi);
711 
712 	return 0;
713 }
714 
715 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
716 					     struct net_device *dev,
717 					     u8 key_idx)
718 {
719 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
720 
721 	ieee80211_set_default_mgmt_key(sdata, key_idx);
722 
723 	return 0;
724 }
725 
726 static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
727 					       struct net_device *dev,
728 					       u8 key_idx)
729 {
730 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
731 
732 	ieee80211_set_default_beacon_key(sdata, key_idx);
733 
734 	return 0;
735 }
736 
737 void sta_set_rate_info_tx(struct sta_info *sta,
738 			  const struct ieee80211_tx_rate *rate,
739 			  struct rate_info *rinfo)
740 {
741 	rinfo->flags = 0;
742 	if (rate->flags & IEEE80211_TX_RC_MCS) {
743 		rinfo->flags |= RATE_INFO_FLAGS_MCS;
744 		rinfo->mcs = rate->idx;
745 	} else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
746 		rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
747 		rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
748 		rinfo->nss = ieee80211_rate_get_vht_nss(rate);
749 	} else {
750 		struct ieee80211_supported_band *sband;
751 		int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
752 		u16 brate;
753 
754 		sband = ieee80211_get_sband(sta->sdata);
755 		WARN_ON_ONCE(sband && !sband->bitrates);
756 		if (sband && sband->bitrates) {
757 			brate = sband->bitrates[rate->idx].bitrate;
758 			rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
759 		}
760 	}
761 	if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
762 		rinfo->bw = RATE_INFO_BW_40;
763 	else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
764 		rinfo->bw = RATE_INFO_BW_80;
765 	else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
766 		rinfo->bw = RATE_INFO_BW_160;
767 	else
768 		rinfo->bw = RATE_INFO_BW_20;
769 	if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
770 		rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
771 }
772 
773 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
774 				  int idx, u8 *mac, struct station_info *sinfo)
775 {
776 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
777 	struct ieee80211_local *local = sdata->local;
778 	struct sta_info *sta;
779 	int ret = -ENOENT;
780 
781 	mutex_lock(&local->sta_mtx);
782 
783 	sta = sta_info_get_by_idx(sdata, idx);
784 	if (sta) {
785 		ret = 0;
786 		memcpy(mac, sta->sta.addr, ETH_ALEN);
787 		sta_set_sinfo(sta, sinfo, true);
788 	}
789 
790 	mutex_unlock(&local->sta_mtx);
791 
792 	return ret;
793 }
794 
795 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
796 				 int idx, struct survey_info *survey)
797 {
798 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
799 
800 	return drv_get_survey(local, idx, survey);
801 }
802 
803 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
804 				 const u8 *mac, struct station_info *sinfo)
805 {
806 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
807 	struct ieee80211_local *local = sdata->local;
808 	struct sta_info *sta;
809 	int ret = -ENOENT;
810 
811 	mutex_lock(&local->sta_mtx);
812 
813 	sta = sta_info_get_bss(sdata, mac);
814 	if (sta) {
815 		ret = 0;
816 		sta_set_sinfo(sta, sinfo, true);
817 	}
818 
819 	mutex_unlock(&local->sta_mtx);
820 
821 	return ret;
822 }
823 
824 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
825 					 struct cfg80211_chan_def *chandef)
826 {
827 	struct ieee80211_local *local = wiphy_priv(wiphy);
828 	struct ieee80211_sub_if_data *sdata;
829 	int ret = 0;
830 
831 	if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
832 		return 0;
833 
834 	mutex_lock(&local->mtx);
835 	if (local->use_chanctx) {
836 		sdata = wiphy_dereference(local->hw.wiphy,
837 					  local->monitor_sdata);
838 		if (sdata) {
839 			ieee80211_vif_release_channel(sdata);
840 			ret = ieee80211_vif_use_channel(sdata, chandef,
841 					IEEE80211_CHANCTX_EXCLUSIVE);
842 		}
843 	} else if (local->open_count == local->monitors) {
844 		local->_oper_chandef = *chandef;
845 		ieee80211_hw_config(local, 0);
846 	}
847 
848 	if (ret == 0)
849 		local->monitor_chandef = *chandef;
850 	mutex_unlock(&local->mtx);
851 
852 	return ret;
853 }
854 
855 static int
856 ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
857 			 const u8 *resp, size_t resp_len,
858 			 const struct ieee80211_csa_settings *csa,
859 			 const struct ieee80211_color_change_settings *cca)
860 {
861 	struct probe_resp *new, *old;
862 
863 	if (!resp || !resp_len)
864 		return 1;
865 
866 	old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
867 
868 	new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
869 	if (!new)
870 		return -ENOMEM;
871 
872 	new->len = resp_len;
873 	memcpy(new->data, resp, resp_len);
874 
875 	if (csa)
876 		memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
877 		       csa->n_counter_offsets_presp *
878 		       sizeof(new->cntdwn_counter_offsets[0]));
879 	else if (cca)
880 		new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
881 
882 	rcu_assign_pointer(sdata->u.ap.probe_resp, new);
883 	if (old)
884 		kfree_rcu(old, rcu_head);
885 
886 	return 0;
887 }
888 
889 static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
890 					struct cfg80211_fils_discovery *params)
891 {
892 	struct fils_discovery_data *new, *old = NULL;
893 	struct ieee80211_fils_discovery *fd;
894 
895 	if (!params->tmpl || !params->tmpl_len)
896 		return -EINVAL;
897 
898 	fd = &sdata->vif.bss_conf.fils_discovery;
899 	fd->min_interval = params->min_interval;
900 	fd->max_interval = params->max_interval;
901 
902 	old = sdata_dereference(sdata->u.ap.fils_discovery, sdata);
903 	new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
904 	if (!new)
905 		return -ENOMEM;
906 	new->len = params->tmpl_len;
907 	memcpy(new->data, params->tmpl, params->tmpl_len);
908 	rcu_assign_pointer(sdata->u.ap.fils_discovery, new);
909 
910 	if (old)
911 		kfree_rcu(old, rcu_head);
912 
913 	return 0;
914 }
915 
916 static int
917 ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
918 				     struct cfg80211_unsol_bcast_probe_resp *params)
919 {
920 	struct unsol_bcast_probe_resp_data *new, *old = NULL;
921 
922 	if (!params->tmpl || !params->tmpl_len)
923 		return -EINVAL;
924 
925 	old = sdata_dereference(sdata->u.ap.unsol_bcast_probe_resp, sdata);
926 	new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
927 	if (!new)
928 		return -ENOMEM;
929 	new->len = params->tmpl_len;
930 	memcpy(new->data, params->tmpl, params->tmpl_len);
931 	rcu_assign_pointer(sdata->u.ap.unsol_bcast_probe_resp, new);
932 
933 	if (old)
934 		kfree_rcu(old, rcu_head);
935 
936 	sdata->vif.bss_conf.unsol_bcast_probe_resp_interval =
937 							params->interval;
938 
939 	return 0;
940 }
941 
942 static int ieee80211_set_ftm_responder_params(
943 				struct ieee80211_sub_if_data *sdata,
944 				const u8 *lci, size_t lci_len,
945 				const u8 *civicloc, size_t civicloc_len)
946 {
947 	struct ieee80211_ftm_responder_params *new, *old;
948 	struct ieee80211_bss_conf *bss_conf;
949 	u8 *pos;
950 	int len;
951 
952 	if (!lci_len && !civicloc_len)
953 		return 0;
954 
955 	bss_conf = &sdata->vif.bss_conf;
956 	old = bss_conf->ftmr_params;
957 	len = lci_len + civicloc_len;
958 
959 	new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
960 	if (!new)
961 		return -ENOMEM;
962 
963 	pos = (u8 *)(new + 1);
964 	if (lci_len) {
965 		new->lci_len = lci_len;
966 		new->lci = pos;
967 		memcpy(pos, lci, lci_len);
968 		pos += lci_len;
969 	}
970 
971 	if (civicloc_len) {
972 		new->civicloc_len = civicloc_len;
973 		new->civicloc = pos;
974 		memcpy(pos, civicloc, civicloc_len);
975 		pos += civicloc_len;
976 	}
977 
978 	bss_conf->ftmr_params = new;
979 	kfree(old);
980 
981 	return 0;
982 }
983 
984 static int
985 ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
986 			     struct cfg80211_mbssid_elems *src)
987 {
988 	int i, offset = 0;
989 
990 	for (i = 0; i < src->cnt; i++) {
991 		memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
992 		dst->elem[i].len = src->elem[i].len;
993 		dst->elem[i].data = pos + offset;
994 		offset += dst->elem[i].len;
995 	}
996 	dst->cnt = src->cnt;
997 
998 	return offset;
999 }
1000 
1001 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
1002 				   struct cfg80211_beacon_data *params,
1003 				   const struct ieee80211_csa_settings *csa,
1004 				   const struct ieee80211_color_change_settings *cca)
1005 {
1006 	struct cfg80211_mbssid_elems *mbssid = NULL;
1007 	struct beacon_data *new, *old;
1008 	int new_head_len, new_tail_len;
1009 	int size, err;
1010 	u32 changed = BSS_CHANGED_BEACON;
1011 
1012 	old = sdata_dereference(sdata->u.ap.beacon, sdata);
1013 
1014 
1015 	/* Need to have a beacon head if we don't have one yet */
1016 	if (!params->head && !old)
1017 		return -EINVAL;
1018 
1019 	/* new or old head? */
1020 	if (params->head)
1021 		new_head_len = params->head_len;
1022 	else
1023 		new_head_len = old->head_len;
1024 
1025 	/* new or old tail? */
1026 	if (params->tail || !old)
1027 		/* params->tail_len will be zero for !params->tail */
1028 		new_tail_len = params->tail_len;
1029 	else
1030 		new_tail_len = old->tail_len;
1031 
1032 	size = sizeof(*new) + new_head_len + new_tail_len;
1033 
1034 	/* new or old multiple BSSID elements? */
1035 	if (params->mbssid_ies) {
1036 		mbssid = params->mbssid_ies;
1037 		size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1038 		size += ieee80211_get_mbssid_beacon_len(mbssid);
1039 	} else if (old && old->mbssid_ies) {
1040 		mbssid = old->mbssid_ies;
1041 		size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1042 		size += ieee80211_get_mbssid_beacon_len(mbssid);
1043 	}
1044 
1045 	new = kzalloc(size, GFP_KERNEL);
1046 	if (!new)
1047 		return -ENOMEM;
1048 
1049 	/* start filling the new info now */
1050 
1051 	/*
1052 	 * pointers go into the block we allocated,
1053 	 * memory is | beacon_data | head | tail | mbssid_ies
1054 	 */
1055 	new->head = ((u8 *) new) + sizeof(*new);
1056 	new->tail = new->head + new_head_len;
1057 	new->head_len = new_head_len;
1058 	new->tail_len = new_tail_len;
1059 	/* copy in optional mbssid_ies */
1060 	if (mbssid) {
1061 		u8 *pos = new->tail + new->tail_len;
1062 
1063 		new->mbssid_ies = (void *)pos;
1064 		pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1065 		ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, mbssid);
1066 		/* update bssid_indicator */
1067 		sdata->vif.bss_conf.bssid_indicator =
1068 			ilog2(__roundup_pow_of_two(mbssid->cnt + 1));
1069 	}
1070 
1071 	if (csa) {
1072 		new->cntdwn_current_counter = csa->count;
1073 		memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
1074 		       csa->n_counter_offsets_beacon *
1075 		       sizeof(new->cntdwn_counter_offsets[0]));
1076 	} else if (cca) {
1077 		new->cntdwn_current_counter = cca->count;
1078 		new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
1079 	}
1080 
1081 	/* copy in head */
1082 	if (params->head)
1083 		memcpy(new->head, params->head, new_head_len);
1084 	else
1085 		memcpy(new->head, old->head, new_head_len);
1086 
1087 	/* copy in optional tail */
1088 	if (params->tail)
1089 		memcpy(new->tail, params->tail, new_tail_len);
1090 	else
1091 		if (old)
1092 			memcpy(new->tail, old->tail, new_tail_len);
1093 
1094 	err = ieee80211_set_probe_resp(sdata, params->probe_resp,
1095 				       params->probe_resp_len, csa, cca);
1096 	if (err < 0) {
1097 		kfree(new);
1098 		return err;
1099 	}
1100 	if (err == 0)
1101 		changed |= BSS_CHANGED_AP_PROBE_RESP;
1102 
1103 	if (params->ftm_responder != -1) {
1104 		sdata->vif.bss_conf.ftm_responder = params->ftm_responder;
1105 		err = ieee80211_set_ftm_responder_params(sdata,
1106 							 params->lci,
1107 							 params->lci_len,
1108 							 params->civicloc,
1109 							 params->civicloc_len);
1110 
1111 		if (err < 0) {
1112 			kfree(new);
1113 			return err;
1114 		}
1115 
1116 		changed |= BSS_CHANGED_FTM_RESPONDER;
1117 	}
1118 
1119 	rcu_assign_pointer(sdata->u.ap.beacon, new);
1120 
1121 	if (old)
1122 		kfree_rcu(old, rcu_head);
1123 
1124 	return changed;
1125 }
1126 
1127 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1128 			      struct cfg80211_ap_settings *params)
1129 {
1130 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1131 	struct ieee80211_local *local = sdata->local;
1132 	struct beacon_data *old;
1133 	struct ieee80211_sub_if_data *vlan;
1134 	u32 changed = BSS_CHANGED_BEACON_INT |
1135 		      BSS_CHANGED_BEACON_ENABLED |
1136 		      BSS_CHANGED_BEACON |
1137 		      BSS_CHANGED_SSID |
1138 		      BSS_CHANGED_P2P_PS |
1139 		      BSS_CHANGED_TXPOWER |
1140 		      BSS_CHANGED_TWT;
1141 	int i, err;
1142 	int prev_beacon_int;
1143 
1144 	old = sdata_dereference(sdata->u.ap.beacon, sdata);
1145 	if (old)
1146 		return -EALREADY;
1147 
1148 	if (params->smps_mode != NL80211_SMPS_OFF)
1149 		return -ENOTSUPP;
1150 
1151 	sdata->smps_mode = IEEE80211_SMPS_OFF;
1152 
1153 	sdata->needed_rx_chains = sdata->local->rx_chains;
1154 
1155 	prev_beacon_int = sdata->vif.bss_conf.beacon_int;
1156 	sdata->vif.bss_conf.beacon_int = params->beacon_interval;
1157 
1158 	if (params->he_cap && params->he_oper) {
1159 		sdata->vif.bss_conf.he_support = true;
1160 		sdata->vif.bss_conf.htc_trig_based_pkt_ext =
1161 			le32_get_bits(params->he_oper->he_oper_params,
1162 			      IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
1163 		sdata->vif.bss_conf.frame_time_rts_th =
1164 			le32_get_bits(params->he_oper->he_oper_params,
1165 			      IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
1166 		changed |= BSS_CHANGED_HE_OBSS_PD;
1167 
1168 		if (params->beacon.he_bss_color.enabled)
1169 			changed |= BSS_CHANGED_HE_BSS_COLOR;
1170 	}
1171 
1172 	if (sdata->vif.type == NL80211_IFTYPE_AP &&
1173 	    params->mbssid_config.tx_wdev) {
1174 		err = ieee80211_set_ap_mbssid_options(sdata,
1175 						      params->mbssid_config);
1176 		if (err)
1177 			return err;
1178 	}
1179 
1180 	mutex_lock(&local->mtx);
1181 	err = ieee80211_vif_use_channel(sdata, &params->chandef,
1182 					IEEE80211_CHANCTX_SHARED);
1183 	if (!err)
1184 		ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
1185 	mutex_unlock(&local->mtx);
1186 	if (err) {
1187 		sdata->vif.bss_conf.beacon_int = prev_beacon_int;
1188 		return err;
1189 	}
1190 
1191 	/*
1192 	 * Apply control port protocol, this allows us to
1193 	 * not encrypt dynamic WEP control frames.
1194 	 */
1195 	sdata->control_port_protocol = params->crypto.control_port_ethertype;
1196 	sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1197 	sdata->control_port_over_nl80211 =
1198 				params->crypto.control_port_over_nl80211;
1199 	sdata->control_port_no_preauth =
1200 				params->crypto.control_port_no_preauth;
1201 
1202 	list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1203 		vlan->control_port_protocol =
1204 			params->crypto.control_port_ethertype;
1205 		vlan->control_port_no_encrypt =
1206 			params->crypto.control_port_no_encrypt;
1207 		vlan->control_port_over_nl80211 =
1208 			params->crypto.control_port_over_nl80211;
1209 		vlan->control_port_no_preauth =
1210 			params->crypto.control_port_no_preauth;
1211 	}
1212 
1213 	sdata->vif.bss_conf.dtim_period = params->dtim_period;
1214 	sdata->vif.bss_conf.enable_beacon = true;
1215 	sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
1216 	sdata->vif.bss_conf.twt_responder = params->twt_responder;
1217 	sdata->vif.bss_conf.he_obss_pd = params->he_obss_pd;
1218 	sdata->vif.bss_conf.he_bss_color = params->beacon.he_bss_color;
1219 	sdata->vif.bss_conf.s1g = params->chandef.chan->band ==
1220 				  NL80211_BAND_S1GHZ;
1221 
1222 	sdata->vif.bss_conf.ssid_len = params->ssid_len;
1223 	if (params->ssid_len)
1224 		memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1225 		       params->ssid_len);
1226 	sdata->vif.bss_conf.hidden_ssid =
1227 		(params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1228 
1229 	memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1230 	       sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1231 	sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1232 		params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1233 	if (params->p2p_opp_ps)
1234 		sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1235 					IEEE80211_P2P_OPPPS_ENABLE_BIT;
1236 
1237 	sdata->beacon_rate_set = false;
1238 	if (wiphy_ext_feature_isset(local->hw.wiphy,
1239 				    NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1240 		for (i = 0; i < NUM_NL80211_BANDS; i++) {
1241 			sdata->beacon_rateidx_mask[i] =
1242 				params->beacon_rate.control[i].legacy;
1243 			if (sdata->beacon_rateidx_mask[i])
1244 				sdata->beacon_rate_set = true;
1245 		}
1246 	}
1247 
1248 	if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
1249 		sdata->vif.bss_conf.beacon_tx_rate = params->beacon_rate;
1250 
1251 	err = ieee80211_assign_beacon(sdata, &params->beacon, NULL, NULL);
1252 	if (err < 0)
1253 		goto error;
1254 	changed |= err;
1255 
1256 	if (params->fils_discovery.max_interval) {
1257 		err = ieee80211_set_fils_discovery(sdata,
1258 						   &params->fils_discovery);
1259 		if (err < 0)
1260 			goto error;
1261 		changed |= BSS_CHANGED_FILS_DISCOVERY;
1262 	}
1263 
1264 	if (params->unsol_bcast_probe_resp.interval) {
1265 		err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1266 							   &params->unsol_bcast_probe_resp);
1267 		if (err < 0)
1268 			goto error;
1269 		changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1270 	}
1271 
1272 	err = drv_start_ap(sdata->local, sdata);
1273 	if (err) {
1274 		old = sdata_dereference(sdata->u.ap.beacon, sdata);
1275 
1276 		if (old)
1277 			kfree_rcu(old, rcu_head);
1278 		RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1279 		goto error;
1280 	}
1281 
1282 	ieee80211_recalc_dtim(local, sdata);
1283 	ieee80211_bss_info_change_notify(sdata, changed);
1284 
1285 	netif_carrier_on(dev);
1286 	list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1287 		netif_carrier_on(vlan->dev);
1288 
1289 	return 0;
1290 
1291 error:
1292 	mutex_lock(&local->mtx);
1293 	ieee80211_vif_release_channel(sdata);
1294 	mutex_unlock(&local->mtx);
1295 
1296 	return err;
1297 }
1298 
1299 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1300 				   struct cfg80211_beacon_data *params)
1301 {
1302 	struct ieee80211_sub_if_data *sdata;
1303 	struct ieee80211_bss_conf *bss_conf;
1304 	struct beacon_data *old;
1305 	int err;
1306 
1307 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1308 	sdata_assert_lock(sdata);
1309 
1310 	/* don't allow changing the beacon while a countdown is in place - offset
1311 	 * of channel switch counter may change
1312 	 */
1313 	if (sdata->vif.csa_active || sdata->vif.color_change_active)
1314 		return -EBUSY;
1315 
1316 	old = sdata_dereference(sdata->u.ap.beacon, sdata);
1317 	if (!old)
1318 		return -ENOENT;
1319 
1320 	err = ieee80211_assign_beacon(sdata, params, NULL, NULL);
1321 	if (err < 0)
1322 		return err;
1323 
1324 	bss_conf = &sdata->vif.bss_conf;
1325 	if (params->he_bss_color_valid &&
1326 	    params->he_bss_color.enabled != bss_conf->he_bss_color.enabled) {
1327 		bss_conf->he_bss_color.enabled = params->he_bss_color.enabled;
1328 		err |= BSS_CHANGED_HE_BSS_COLOR;
1329 	}
1330 
1331 	ieee80211_bss_info_change_notify(sdata, err);
1332 	return 0;
1333 }
1334 
1335 static void ieee80211_free_next_beacon(struct ieee80211_sub_if_data *sdata)
1336 {
1337 	if (!sdata->u.ap.next_beacon)
1338 		return;
1339 
1340 	kfree(sdata->u.ap.next_beacon->mbssid_ies);
1341 	kfree(sdata->u.ap.next_beacon);
1342 	sdata->u.ap.next_beacon = NULL;
1343 }
1344 
1345 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1346 {
1347 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1348 	struct ieee80211_sub_if_data *vlan;
1349 	struct ieee80211_local *local = sdata->local;
1350 	struct beacon_data *old_beacon;
1351 	struct probe_resp *old_probe_resp;
1352 	struct fils_discovery_data *old_fils_discovery;
1353 	struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
1354 	struct cfg80211_chan_def chandef;
1355 
1356 	sdata_assert_lock(sdata);
1357 
1358 	old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
1359 	if (!old_beacon)
1360 		return -ENOENT;
1361 	old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
1362 	old_fils_discovery = sdata_dereference(sdata->u.ap.fils_discovery,
1363 					       sdata);
1364 	old_unsol_bcast_probe_resp =
1365 		sdata_dereference(sdata->u.ap.unsol_bcast_probe_resp,
1366 				  sdata);
1367 
1368 	/* abort any running channel switch */
1369 	mutex_lock(&local->mtx);
1370 	sdata->vif.csa_active = false;
1371 	if (sdata->csa_block_tx) {
1372 		ieee80211_wake_vif_queues(local, sdata,
1373 					  IEEE80211_QUEUE_STOP_REASON_CSA);
1374 		sdata->csa_block_tx = false;
1375 	}
1376 
1377 	mutex_unlock(&local->mtx);
1378 
1379 	ieee80211_free_next_beacon(sdata);
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.deflink.txpwr.type = params->txpwr.type;
1732 		if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1733 			sta->sta.deflink.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.deflink.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.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 		if (!sdata->u.ap.next_beacon)
3310 			return -EINVAL;
3311 
3312 		err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
3313 					      NULL, NULL);
3314 		ieee80211_free_next_beacon(sdata);
3315 
3316 		if (err < 0)
3317 			return err;
3318 		*changed |= err;
3319 		break;
3320 	case NL80211_IFTYPE_ADHOC:
3321 		err = ieee80211_ibss_finish_csa(sdata);
3322 		if (err < 0)
3323 			return err;
3324 		*changed |= err;
3325 		break;
3326 #ifdef CONFIG_MAC80211_MESH
3327 	case NL80211_IFTYPE_MESH_POINT:
3328 		err = ieee80211_mesh_finish_csa(sdata);
3329 		if (err < 0)
3330 			return err;
3331 		*changed |= err;
3332 		break;
3333 #endif
3334 	default:
3335 		WARN_ON(1);
3336 		return -EINVAL;
3337 	}
3338 
3339 	return 0;
3340 }
3341 
3342 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3343 {
3344 	struct ieee80211_local *local = sdata->local;
3345 	u32 changed = 0;
3346 	int err;
3347 
3348 	sdata_assert_lock(sdata);
3349 	lockdep_assert_held(&local->mtx);
3350 	lockdep_assert_held(&local->chanctx_mtx);
3351 
3352 	/*
3353 	 * using reservation isn't immediate as it may be deferred until later
3354 	 * with multi-vif. once reservation is complete it will re-schedule the
3355 	 * work with no reserved_chanctx so verify chandef to check if it
3356 	 * completed successfully
3357 	 */
3358 
3359 	if (sdata->reserved_chanctx) {
3360 		/*
3361 		 * with multi-vif csa driver may call ieee80211_csa_finish()
3362 		 * many times while waiting for other interfaces to use their
3363 		 * reservations
3364 		 */
3365 		if (sdata->reserved_ready)
3366 			return 0;
3367 
3368 		return ieee80211_vif_use_reserved_context(sdata);
3369 	}
3370 
3371 	if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3372 					&sdata->csa_chandef))
3373 		return -EINVAL;
3374 
3375 	sdata->vif.csa_active = false;
3376 
3377 	err = ieee80211_set_after_csa_beacon(sdata, &changed);
3378 	if (err)
3379 		return err;
3380 
3381 	ieee80211_bss_info_change_notify(sdata, changed);
3382 
3383 	if (sdata->csa_block_tx) {
3384 		ieee80211_wake_vif_queues(local, sdata,
3385 					  IEEE80211_QUEUE_STOP_REASON_CSA);
3386 		sdata->csa_block_tx = false;
3387 	}
3388 
3389 	err = drv_post_channel_switch(sdata);
3390 	if (err)
3391 		return err;
3392 
3393 	cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3394 
3395 	return 0;
3396 }
3397 
3398 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3399 {
3400 	if (__ieee80211_csa_finalize(sdata)) {
3401 		sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3402 		cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3403 				    GFP_KERNEL);
3404 	}
3405 }
3406 
3407 void ieee80211_csa_finalize_work(struct work_struct *work)
3408 {
3409 	struct ieee80211_sub_if_data *sdata =
3410 		container_of(work, struct ieee80211_sub_if_data,
3411 			     csa_finalize_work);
3412 	struct ieee80211_local *local = sdata->local;
3413 
3414 	sdata_lock(sdata);
3415 	mutex_lock(&local->mtx);
3416 	mutex_lock(&local->chanctx_mtx);
3417 
3418 	/* AP might have been stopped while waiting for the lock. */
3419 	if (!sdata->vif.csa_active)
3420 		goto unlock;
3421 
3422 	if (!ieee80211_sdata_running(sdata))
3423 		goto unlock;
3424 
3425 	ieee80211_csa_finalize(sdata);
3426 
3427 unlock:
3428 	mutex_unlock(&local->chanctx_mtx);
3429 	mutex_unlock(&local->mtx);
3430 	sdata_unlock(sdata);
3431 }
3432 
3433 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3434 				    struct cfg80211_csa_settings *params,
3435 				    u32 *changed)
3436 {
3437 	struct ieee80211_csa_settings csa = {};
3438 	int err;
3439 
3440 	switch (sdata->vif.type) {
3441 	case NL80211_IFTYPE_AP:
3442 		sdata->u.ap.next_beacon =
3443 			cfg80211_beacon_dup(&params->beacon_after);
3444 		if (!sdata->u.ap.next_beacon)
3445 			return -ENOMEM;
3446 
3447 		/*
3448 		 * With a count of 0, we don't have to wait for any
3449 		 * TBTT before switching, so complete the CSA
3450 		 * immediately.  In theory, with a count == 1 we
3451 		 * should delay the switch until just before the next
3452 		 * TBTT, but that would complicate things so we switch
3453 		 * immediately too.  If we would delay the switch
3454 		 * until the next TBTT, we would have to set the probe
3455 		 * response here.
3456 		 *
3457 		 * TODO: A channel switch with count <= 1 without
3458 		 * sending a CSA action frame is kind of useless,
3459 		 * because the clients won't know we're changing
3460 		 * channels.  The action frame must be implemented
3461 		 * either here or in the userspace.
3462 		 */
3463 		if (params->count <= 1)
3464 			break;
3465 
3466 		if ((params->n_counter_offsets_beacon >
3467 		     IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
3468 		    (params->n_counter_offsets_presp >
3469 		     IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
3470 			ieee80211_free_next_beacon(sdata);
3471 			return -EINVAL;
3472 		}
3473 
3474 		csa.counter_offsets_beacon = params->counter_offsets_beacon;
3475 		csa.counter_offsets_presp = params->counter_offsets_presp;
3476 		csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3477 		csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3478 		csa.count = params->count;
3479 
3480 		err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa, NULL);
3481 		if (err < 0) {
3482 			ieee80211_free_next_beacon(sdata);
3483 			return err;
3484 		}
3485 		*changed |= err;
3486 
3487 		break;
3488 	case NL80211_IFTYPE_ADHOC:
3489 		if (!sdata->vif.bss_conf.ibss_joined)
3490 			return -EINVAL;
3491 
3492 		if (params->chandef.width != sdata->u.ibss.chandef.width)
3493 			return -EINVAL;
3494 
3495 		switch (params->chandef.width) {
3496 		case NL80211_CHAN_WIDTH_40:
3497 			if (cfg80211_get_chandef_type(&params->chandef) !=
3498 			    cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3499 				return -EINVAL;
3500 			break;
3501 		case NL80211_CHAN_WIDTH_5:
3502 		case NL80211_CHAN_WIDTH_10:
3503 		case NL80211_CHAN_WIDTH_20_NOHT:
3504 		case NL80211_CHAN_WIDTH_20:
3505 			break;
3506 		default:
3507 			return -EINVAL;
3508 		}
3509 
3510 		/* changes into another band are not supported */
3511 		if (sdata->u.ibss.chandef.chan->band !=
3512 		    params->chandef.chan->band)
3513 			return -EINVAL;
3514 
3515 		/* see comments in the NL80211_IFTYPE_AP block */
3516 		if (params->count > 1) {
3517 			err = ieee80211_ibss_csa_beacon(sdata, params);
3518 			if (err < 0)
3519 				return err;
3520 			*changed |= err;
3521 		}
3522 
3523 		ieee80211_send_action_csa(sdata, params);
3524 
3525 		break;
3526 #ifdef CONFIG_MAC80211_MESH
3527 	case NL80211_IFTYPE_MESH_POINT: {
3528 		struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3529 
3530 		if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3531 			return -EINVAL;
3532 
3533 		/* changes into another band are not supported */
3534 		if (sdata->vif.bss_conf.chandef.chan->band !=
3535 		    params->chandef.chan->band)
3536 			return -EINVAL;
3537 
3538 		if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3539 			ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3540 			if (!ifmsh->pre_value)
3541 				ifmsh->pre_value = 1;
3542 			else
3543 				ifmsh->pre_value++;
3544 		}
3545 
3546 		/* see comments in the NL80211_IFTYPE_AP block */
3547 		if (params->count > 1) {
3548 			err = ieee80211_mesh_csa_beacon(sdata, params);
3549 			if (err < 0) {
3550 				ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3551 				return err;
3552 			}
3553 			*changed |= err;
3554 		}
3555 
3556 		if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3557 			ieee80211_send_action_csa(sdata, params);
3558 
3559 		break;
3560 		}
3561 #endif
3562 	default:
3563 		return -EOPNOTSUPP;
3564 	}
3565 
3566 	return 0;
3567 }
3568 
3569 static void ieee80211_color_change_abort(struct ieee80211_sub_if_data  *sdata)
3570 {
3571 	sdata->vif.color_change_active = false;
3572 
3573 	ieee80211_free_next_beacon(sdata);
3574 
3575 	cfg80211_color_change_aborted_notify(sdata->dev);
3576 }
3577 
3578 static int
3579 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3580 			   struct cfg80211_csa_settings *params)
3581 {
3582 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3583 	struct ieee80211_local *local = sdata->local;
3584 	struct ieee80211_channel_switch ch_switch;
3585 	struct ieee80211_chanctx_conf *conf;
3586 	struct ieee80211_chanctx *chanctx;
3587 	u32 changed = 0;
3588 	int err;
3589 
3590 	sdata_assert_lock(sdata);
3591 	lockdep_assert_held(&local->mtx);
3592 
3593 	if (!list_empty(&local->roc_list) || local->scanning)
3594 		return -EBUSY;
3595 
3596 	if (sdata->wdev.cac_started)
3597 		return -EBUSY;
3598 
3599 	if (cfg80211_chandef_identical(&params->chandef,
3600 				       &sdata->vif.bss_conf.chandef))
3601 		return -EINVAL;
3602 
3603 	/* don't allow another channel switch if one is already active. */
3604 	if (sdata->vif.csa_active)
3605 		return -EBUSY;
3606 
3607 	mutex_lock(&local->chanctx_mtx);
3608 	conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3609 					 lockdep_is_held(&local->chanctx_mtx));
3610 	if (!conf) {
3611 		err = -EBUSY;
3612 		goto out;
3613 	}
3614 
3615 	if (params->chandef.chan->freq_offset) {
3616 		/* this may work, but is untested */
3617 		err = -EOPNOTSUPP;
3618 		goto out;
3619 	}
3620 
3621 	chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3622 
3623 	ch_switch.timestamp = 0;
3624 	ch_switch.device_timestamp = 0;
3625 	ch_switch.block_tx = params->block_tx;
3626 	ch_switch.chandef = params->chandef;
3627 	ch_switch.count = params->count;
3628 
3629 	err = drv_pre_channel_switch(sdata, &ch_switch);
3630 	if (err)
3631 		goto out;
3632 
3633 	err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3634 					    chanctx->mode,
3635 					    params->radar_required);
3636 	if (err)
3637 		goto out;
3638 
3639 	/* if reservation is invalid then this will fail */
3640 	err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3641 	if (err) {
3642 		ieee80211_vif_unreserve_chanctx(sdata);
3643 		goto out;
3644 	}
3645 
3646 	/* if there is a color change in progress, abort it */
3647 	if (sdata->vif.color_change_active)
3648 		ieee80211_color_change_abort(sdata);
3649 
3650 	err = ieee80211_set_csa_beacon(sdata, params, &changed);
3651 	if (err) {
3652 		ieee80211_vif_unreserve_chanctx(sdata);
3653 		goto out;
3654 	}
3655 
3656 	sdata->csa_chandef = params->chandef;
3657 	sdata->csa_block_tx = params->block_tx;
3658 	sdata->vif.csa_active = true;
3659 
3660 	if (sdata->csa_block_tx)
3661 		ieee80211_stop_vif_queues(local, sdata,
3662 					  IEEE80211_QUEUE_STOP_REASON_CSA);
3663 
3664 	cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3665 					  params->count, params->block_tx);
3666 
3667 	if (changed) {
3668 		ieee80211_bss_info_change_notify(sdata, changed);
3669 		drv_channel_switch_beacon(sdata, &params->chandef);
3670 	} else {
3671 		/* if the beacon didn't change, we can finalize immediately */
3672 		ieee80211_csa_finalize(sdata);
3673 	}
3674 
3675 out:
3676 	mutex_unlock(&local->chanctx_mtx);
3677 	return err;
3678 }
3679 
3680 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3681 			     struct cfg80211_csa_settings *params)
3682 {
3683 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3684 	struct ieee80211_local *local = sdata->local;
3685 	int err;
3686 
3687 	mutex_lock(&local->mtx);
3688 	err = __ieee80211_channel_switch(wiphy, dev, params);
3689 	mutex_unlock(&local->mtx);
3690 
3691 	return err;
3692 }
3693 
3694 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3695 {
3696 	lockdep_assert_held(&local->mtx);
3697 
3698 	local->roc_cookie_counter++;
3699 
3700 	/* wow, you wrapped 64 bits ... more likely a bug */
3701 	if (WARN_ON(local->roc_cookie_counter == 0))
3702 		local->roc_cookie_counter++;
3703 
3704 	return local->roc_cookie_counter;
3705 }
3706 
3707 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3708 			     u64 *cookie, gfp_t gfp)
3709 {
3710 	unsigned long spin_flags;
3711 	struct sk_buff *ack_skb;
3712 	int id;
3713 
3714 	ack_skb = skb_copy(skb, gfp);
3715 	if (!ack_skb)
3716 		return -ENOMEM;
3717 
3718 	spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3719 	id = idr_alloc(&local->ack_status_frames, ack_skb,
3720 		       1, 0x2000, GFP_ATOMIC);
3721 	spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3722 
3723 	if (id < 0) {
3724 		kfree_skb(ack_skb);
3725 		return -ENOMEM;
3726 	}
3727 
3728 	IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3729 
3730 	*cookie = ieee80211_mgmt_tx_cookie(local);
3731 	IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3732 
3733 	return 0;
3734 }
3735 
3736 static void
3737 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
3738 					  struct wireless_dev *wdev,
3739 					  struct mgmt_frame_regs *upd)
3740 {
3741 	struct ieee80211_local *local = wiphy_priv(wiphy);
3742 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3743 	u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
3744 	u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
3745 	bool global_change, intf_change;
3746 
3747 	global_change =
3748 		(local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
3749 		(local->rx_mcast_action_reg !=
3750 		 !!(upd->global_mcast_stypes & action_mask));
3751 	local->probe_req_reg = upd->global_stypes & preq_mask;
3752 	local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
3753 
3754 	intf_change = (sdata->vif.probe_req_reg !=
3755 		       !!(upd->interface_stypes & preq_mask)) ||
3756 		(sdata->vif.rx_mcast_action_reg !=
3757 		 !!(upd->interface_mcast_stypes & action_mask));
3758 	sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
3759 	sdata->vif.rx_mcast_action_reg =
3760 		upd->interface_mcast_stypes & action_mask;
3761 
3762 	if (!local->open_count)
3763 		return;
3764 
3765 	if (intf_change && ieee80211_sdata_running(sdata))
3766 		drv_config_iface_filter(local, sdata,
3767 					sdata->vif.probe_req_reg ?
3768 						FIF_PROBE_REQ : 0,
3769 					FIF_PROBE_REQ);
3770 
3771 	if (global_change)
3772 		ieee80211_configure_filter(local);
3773 }
3774 
3775 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3776 {
3777 	struct ieee80211_local *local = wiphy_priv(wiphy);
3778 
3779 	if (local->started)
3780 		return -EOPNOTSUPP;
3781 
3782 	return drv_set_antenna(local, tx_ant, rx_ant);
3783 }
3784 
3785 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3786 {
3787 	struct ieee80211_local *local = wiphy_priv(wiphy);
3788 
3789 	return drv_get_antenna(local, tx_ant, rx_ant);
3790 }
3791 
3792 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3793 				    struct net_device *dev,
3794 				    struct cfg80211_gtk_rekey_data *data)
3795 {
3796 	struct ieee80211_local *local = wiphy_priv(wiphy);
3797 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3798 
3799 	if (!local->ops->set_rekey_data)
3800 		return -EOPNOTSUPP;
3801 
3802 	drv_set_rekey_data(local, sdata, data);
3803 
3804 	return 0;
3805 }
3806 
3807 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3808 				  const u8 *peer, u64 *cookie)
3809 {
3810 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3811 	struct ieee80211_local *local = sdata->local;
3812 	struct ieee80211_qos_hdr *nullfunc;
3813 	struct sk_buff *skb;
3814 	int size = sizeof(*nullfunc);
3815 	__le16 fc;
3816 	bool qos;
3817 	struct ieee80211_tx_info *info;
3818 	struct sta_info *sta;
3819 	struct ieee80211_chanctx_conf *chanctx_conf;
3820 	enum nl80211_band band;
3821 	int ret;
3822 
3823 	/* the lock is needed to assign the cookie later */
3824 	mutex_lock(&local->mtx);
3825 
3826 	rcu_read_lock();
3827 	chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3828 	if (WARN_ON(!chanctx_conf)) {
3829 		ret = -EINVAL;
3830 		goto unlock;
3831 	}
3832 	band = chanctx_conf->def.chan->band;
3833 	sta = sta_info_get_bss(sdata, peer);
3834 	if (sta) {
3835 		qos = sta->sta.wme;
3836 	} else {
3837 		ret = -ENOLINK;
3838 		goto unlock;
3839 	}
3840 
3841 	if (qos) {
3842 		fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3843 				 IEEE80211_STYPE_QOS_NULLFUNC |
3844 				 IEEE80211_FCTL_FROMDS);
3845 	} else {
3846 		size -= 2;
3847 		fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3848 				 IEEE80211_STYPE_NULLFUNC |
3849 				 IEEE80211_FCTL_FROMDS);
3850 	}
3851 
3852 	skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3853 	if (!skb) {
3854 		ret = -ENOMEM;
3855 		goto unlock;
3856 	}
3857 
3858 	skb->dev = dev;
3859 
3860 	skb_reserve(skb, local->hw.extra_tx_headroom);
3861 
3862 	nullfunc = skb_put(skb, size);
3863 	nullfunc->frame_control = fc;
3864 	nullfunc->duration_id = 0;
3865 	memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3866 	memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3867 	memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3868 	nullfunc->seq_ctrl = 0;
3869 
3870 	info = IEEE80211_SKB_CB(skb);
3871 
3872 	info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3873 		       IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3874 	info->band = band;
3875 
3876 	skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3877 	skb->priority = 7;
3878 	if (qos)
3879 		nullfunc->qos_ctrl = cpu_to_le16(7);
3880 
3881 	ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3882 	if (ret) {
3883 		kfree_skb(skb);
3884 		goto unlock;
3885 	}
3886 
3887 	local_bh_disable();
3888 	ieee80211_xmit(sdata, sta, skb);
3889 	local_bh_enable();
3890 
3891 	ret = 0;
3892 unlock:
3893 	rcu_read_unlock();
3894 	mutex_unlock(&local->mtx);
3895 
3896 	return ret;
3897 }
3898 
3899 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3900 				     struct wireless_dev *wdev,
3901 				     struct cfg80211_chan_def *chandef)
3902 {
3903 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3904 	struct ieee80211_local *local = wiphy_priv(wiphy);
3905 	struct ieee80211_chanctx_conf *chanctx_conf;
3906 	int ret = -ENODATA;
3907 
3908 	rcu_read_lock();
3909 	chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3910 	if (chanctx_conf) {
3911 		*chandef = sdata->vif.bss_conf.chandef;
3912 		ret = 0;
3913 	} else if (local->open_count > 0 &&
3914 		   local->open_count == local->monitors &&
3915 		   sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3916 		if (local->use_chanctx)
3917 			*chandef = local->monitor_chandef;
3918 		else
3919 			*chandef = local->_oper_chandef;
3920 		ret = 0;
3921 	}
3922 	rcu_read_unlock();
3923 
3924 	return ret;
3925 }
3926 
3927 #ifdef CONFIG_PM
3928 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3929 {
3930 	drv_set_wakeup(wiphy_priv(wiphy), enabled);
3931 }
3932 #endif
3933 
3934 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3935 				 struct net_device *dev,
3936 				 struct cfg80211_qos_map *qos_map)
3937 {
3938 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3939 	struct mac80211_qos_map *new_qos_map, *old_qos_map;
3940 
3941 	if (qos_map) {
3942 		new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3943 		if (!new_qos_map)
3944 			return -ENOMEM;
3945 		memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3946 	} else {
3947 		/* A NULL qos_map was passed to disable QoS mapping */
3948 		new_qos_map = NULL;
3949 	}
3950 
3951 	old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3952 	rcu_assign_pointer(sdata->qos_map, new_qos_map);
3953 	if (old_qos_map)
3954 		kfree_rcu(old_qos_map, rcu_head);
3955 
3956 	return 0;
3957 }
3958 
3959 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3960 				      struct net_device *dev,
3961 				      struct cfg80211_chan_def *chandef)
3962 {
3963 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3964 	int ret;
3965 	u32 changed = 0;
3966 
3967 	ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3968 	if (ret == 0)
3969 		ieee80211_bss_info_change_notify(sdata, changed);
3970 
3971 	return ret;
3972 }
3973 
3974 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3975 			       u8 tsid, const u8 *peer, u8 up,
3976 			       u16 admitted_time)
3977 {
3978 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3979 	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3980 	int ac = ieee802_1d_to_ac[up];
3981 
3982 	if (sdata->vif.type != NL80211_IFTYPE_STATION)
3983 		return -EOPNOTSUPP;
3984 
3985 	if (!(sdata->wmm_acm & BIT(up)))
3986 		return -EINVAL;
3987 
3988 	if (ifmgd->tx_tspec[ac].admitted_time)
3989 		return -EBUSY;
3990 
3991 	if (admitted_time) {
3992 		ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3993 		ifmgd->tx_tspec[ac].tsid = tsid;
3994 		ifmgd->tx_tspec[ac].up = up;
3995 	}
3996 
3997 	return 0;
3998 }
3999 
4000 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4001 			       u8 tsid, const u8 *peer)
4002 {
4003 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4004 	struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4005 	struct ieee80211_local *local = wiphy_priv(wiphy);
4006 	int ac;
4007 
4008 	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4009 		struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4010 
4011 		/* skip unused entries */
4012 		if (!tx_tspec->admitted_time)
4013 			continue;
4014 
4015 		if (tx_tspec->tsid != tsid)
4016 			continue;
4017 
4018 		/* due to this new packets will be reassigned to non-ACM ACs */
4019 		tx_tspec->up = -1;
4020 
4021 		/* Make sure that all packets have been sent to avoid to
4022 		 * restore the QoS params on packets that are still on the
4023 		 * queues.
4024 		 */
4025 		synchronize_net();
4026 		ieee80211_flush_queues(local, sdata, false);
4027 
4028 		/* restore the normal QoS parameters
4029 		 * (unconditionally to avoid races)
4030 		 */
4031 		tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4032 		tx_tspec->downgraded = false;
4033 		ieee80211_sta_handle_tspec_ac_params(sdata);
4034 
4035 		/* finally clear all the data */
4036 		memset(tx_tspec, 0, sizeof(*tx_tspec));
4037 
4038 		return 0;
4039 	}
4040 
4041 	return -ENOENT;
4042 }
4043 
4044 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4045 				   u8 inst_id,
4046 				   enum nl80211_nan_func_term_reason reason,
4047 				   gfp_t gfp)
4048 {
4049 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4050 	struct cfg80211_nan_func *func;
4051 	u64 cookie;
4052 
4053 	if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4054 		return;
4055 
4056 	spin_lock_bh(&sdata->u.nan.func_lock);
4057 
4058 	func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4059 	if (WARN_ON(!func)) {
4060 		spin_unlock_bh(&sdata->u.nan.func_lock);
4061 		return;
4062 	}
4063 
4064 	cookie = func->cookie;
4065 	idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4066 
4067 	spin_unlock_bh(&sdata->u.nan.func_lock);
4068 
4069 	cfg80211_free_nan_func(func);
4070 
4071 	cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4072 				     reason, cookie, gfp);
4073 }
4074 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4075 
4076 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4077 			      struct cfg80211_nan_match_params *match,
4078 			      gfp_t gfp)
4079 {
4080 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4081 	struct cfg80211_nan_func *func;
4082 
4083 	if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4084 		return;
4085 
4086 	spin_lock_bh(&sdata->u.nan.func_lock);
4087 
4088 	func = idr_find(&sdata->u.nan.function_inst_ids,  match->inst_id);
4089 	if (WARN_ON(!func)) {
4090 		spin_unlock_bh(&sdata->u.nan.func_lock);
4091 		return;
4092 	}
4093 	match->cookie = func->cookie;
4094 
4095 	spin_unlock_bh(&sdata->u.nan.func_lock);
4096 
4097 	cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4098 }
4099 EXPORT_SYMBOL(ieee80211_nan_func_match);
4100 
4101 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4102 					      struct net_device *dev,
4103 					      const bool enabled)
4104 {
4105 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4106 
4107 	sdata->u.ap.multicast_to_unicast = enabled;
4108 
4109 	return 0;
4110 }
4111 
4112 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4113 			      struct txq_info *txqi)
4114 {
4115 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4116 		txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4117 		txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4118 	}
4119 
4120 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4121 		txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4122 		txqstats->backlog_packets = txqi->tin.backlog_packets;
4123 	}
4124 
4125 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4126 		txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4127 		txqstats->flows = txqi->tin.flows;
4128 	}
4129 
4130 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4131 		txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4132 		txqstats->drops = txqi->cstats.drop_count;
4133 	}
4134 
4135 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4136 		txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4137 		txqstats->ecn_marks = txqi->cstats.ecn_mark;
4138 	}
4139 
4140 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4141 		txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4142 		txqstats->overlimit = txqi->tin.overlimit;
4143 	}
4144 
4145 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4146 		txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4147 		txqstats->collisions = txqi->tin.collisions;
4148 	}
4149 
4150 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4151 		txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4152 		txqstats->tx_bytes = txqi->tin.tx_bytes;
4153 	}
4154 
4155 	if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4156 		txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4157 		txqstats->tx_packets = txqi->tin.tx_packets;
4158 	}
4159 }
4160 
4161 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4162 				   struct wireless_dev *wdev,
4163 				   struct cfg80211_txq_stats *txqstats)
4164 {
4165 	struct ieee80211_local *local = wiphy_priv(wiphy);
4166 	struct ieee80211_sub_if_data *sdata;
4167 	int ret = 0;
4168 
4169 	if (!local->ops->wake_tx_queue)
4170 		return 1;
4171 
4172 	spin_lock_bh(&local->fq.lock);
4173 	rcu_read_lock();
4174 
4175 	if (wdev) {
4176 		sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4177 		if (!sdata->vif.txq) {
4178 			ret = 1;
4179 			goto out;
4180 		}
4181 		ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4182 	} else {
4183 		/* phy stats */
4184 		txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4185 				    BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4186 				    BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4187 				    BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4188 				    BIT(NL80211_TXQ_STATS_COLLISIONS) |
4189 				    BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4190 		txqstats->backlog_packets = local->fq.backlog;
4191 		txqstats->backlog_bytes = local->fq.memory_usage;
4192 		txqstats->overlimit = local->fq.overlimit;
4193 		txqstats->overmemory = local->fq.overmemory;
4194 		txqstats->collisions = local->fq.collisions;
4195 		txqstats->max_flows = local->fq.flows_cnt;
4196 	}
4197 
4198 out:
4199 	rcu_read_unlock();
4200 	spin_unlock_bh(&local->fq.lock);
4201 
4202 	return ret;
4203 }
4204 
4205 static int
4206 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4207 				  struct net_device *dev,
4208 				  struct cfg80211_ftm_responder_stats *ftm_stats)
4209 {
4210 	struct ieee80211_local *local = wiphy_priv(wiphy);
4211 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4212 
4213 	return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4214 }
4215 
4216 static int
4217 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4218 		     struct cfg80211_pmsr_request *request)
4219 {
4220 	struct ieee80211_local *local = wiphy_priv(wiphy);
4221 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4222 
4223 	return drv_start_pmsr(local, sdata, request);
4224 }
4225 
4226 static void
4227 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4228 		     struct cfg80211_pmsr_request *request)
4229 {
4230 	struct ieee80211_local *local = wiphy_priv(wiphy);
4231 	struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4232 
4233 	return drv_abort_pmsr(local, sdata, request);
4234 }
4235 
4236 static int ieee80211_set_tid_config(struct wiphy *wiphy,
4237 				    struct net_device *dev,
4238 				    struct cfg80211_tid_config *tid_conf)
4239 {
4240 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4241 	struct sta_info *sta;
4242 	int ret;
4243 
4244 	if (!sdata->local->ops->set_tid_config)
4245 		return -EOPNOTSUPP;
4246 
4247 	if (!tid_conf->peer)
4248 		return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4249 
4250 	mutex_lock(&sdata->local->sta_mtx);
4251 	sta = sta_info_get_bss(sdata, tid_conf->peer);
4252 	if (!sta) {
4253 		mutex_unlock(&sdata->local->sta_mtx);
4254 		return -ENOENT;
4255 	}
4256 
4257 	ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4258 	mutex_unlock(&sdata->local->sta_mtx);
4259 
4260 	return ret;
4261 }
4262 
4263 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4264 				      struct net_device *dev,
4265 				      const u8 *peer, u8 tids)
4266 {
4267 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4268 	struct sta_info *sta;
4269 	int ret;
4270 
4271 	if (!sdata->local->ops->reset_tid_config)
4272 		return -EOPNOTSUPP;
4273 
4274 	if (!peer)
4275 		return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
4276 
4277 	mutex_lock(&sdata->local->sta_mtx);
4278 	sta = sta_info_get_bss(sdata, peer);
4279 	if (!sta) {
4280 		mutex_unlock(&sdata->local->sta_mtx);
4281 		return -ENOENT;
4282 	}
4283 
4284 	ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
4285 	mutex_unlock(&sdata->local->sta_mtx);
4286 
4287 	return ret;
4288 }
4289 
4290 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4291 				   struct cfg80211_sar_specs *sar)
4292 {
4293 	struct ieee80211_local *local = wiphy_priv(wiphy);
4294 
4295 	if (!local->ops->set_sar_specs)
4296 		return -EOPNOTSUPP;
4297 
4298 	return local->ops->set_sar_specs(&local->hw, sar);
4299 }
4300 
4301 static int
4302 ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4303 					u32 *changed)
4304 {
4305 	switch (sdata->vif.type) {
4306 	case NL80211_IFTYPE_AP: {
4307 		int ret;
4308 
4309 		if (!sdata->u.ap.next_beacon)
4310 			return -EINVAL;
4311 
4312 		ret = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
4313 					      NULL, NULL);
4314 		ieee80211_free_next_beacon(sdata);
4315 
4316 		if (ret < 0)
4317 			return ret;
4318 
4319 		*changed |= ret;
4320 		break;
4321 	}
4322 	default:
4323 		WARN_ON_ONCE(1);
4324 		return -EINVAL;
4325 	}
4326 
4327 	return 0;
4328 }
4329 
4330 static int
4331 ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4332 				  struct cfg80211_color_change_settings *params,
4333 				  u32 *changed)
4334 {
4335 	struct ieee80211_color_change_settings color_change = {};
4336 	int err;
4337 
4338 	switch (sdata->vif.type) {
4339 	case NL80211_IFTYPE_AP:
4340 		sdata->u.ap.next_beacon =
4341 			cfg80211_beacon_dup(&params->beacon_next);
4342 		if (!sdata->u.ap.next_beacon)
4343 			return -ENOMEM;
4344 
4345 		if (params->count <= 1)
4346 			break;
4347 
4348 		color_change.counter_offset_beacon =
4349 			params->counter_offset_beacon;
4350 		color_change.counter_offset_presp =
4351 			params->counter_offset_presp;
4352 		color_change.count = params->count;
4353 
4354 		err = ieee80211_assign_beacon(sdata, &params->beacon_color_change,
4355 					      NULL, &color_change);
4356 		if (err < 0) {
4357 			ieee80211_free_next_beacon(sdata);
4358 			return err;
4359 		}
4360 		*changed |= err;
4361 		break;
4362 	default:
4363 		return -EOPNOTSUPP;
4364 	}
4365 
4366 	return 0;
4367 }
4368 
4369 static void
4370 ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata,
4371 					 u8 color, int enable, u32 changed)
4372 {
4373 	sdata->vif.bss_conf.he_bss_color.color = color;
4374 	sdata->vif.bss_conf.he_bss_color.enabled = enable;
4375 	changed |= BSS_CHANGED_HE_BSS_COLOR;
4376 
4377 	ieee80211_bss_info_change_notify(sdata, changed);
4378 
4379 	if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4380 		struct ieee80211_sub_if_data *child;
4381 
4382 		mutex_lock(&sdata->local->iflist_mtx);
4383 		list_for_each_entry(child, &sdata->local->interfaces, list) {
4384 			if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4385 				child->vif.bss_conf.he_bss_color.color = color;
4386 				child->vif.bss_conf.he_bss_color.enabled = enable;
4387 				ieee80211_bss_info_change_notify(child,
4388 								 BSS_CHANGED_HE_BSS_COLOR);
4389 			}
4390 		}
4391 		mutex_unlock(&sdata->local->iflist_mtx);
4392 	}
4393 }
4394 
4395 static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
4396 {
4397 	struct ieee80211_local *local = sdata->local;
4398 	u32 changed = 0;
4399 	int err;
4400 
4401 	sdata_assert_lock(sdata);
4402 	lockdep_assert_held(&local->mtx);
4403 
4404 	sdata->vif.color_change_active = false;
4405 
4406 	err = ieee80211_set_after_color_change_beacon(sdata, &changed);
4407 	if (err) {
4408 		cfg80211_color_change_aborted_notify(sdata->dev);
4409 		return err;
4410 	}
4411 
4412 	ieee80211_color_change_bss_config_notify(sdata,
4413 						 sdata->vif.color_change_color,
4414 						 1, changed);
4415 	cfg80211_color_change_notify(sdata->dev);
4416 
4417 	return 0;
4418 }
4419 
4420 void ieee80211_color_change_finalize_work(struct work_struct *work)
4421 {
4422 	struct ieee80211_sub_if_data *sdata =
4423 		container_of(work, struct ieee80211_sub_if_data,
4424 			     color_change_finalize_work);
4425 	struct ieee80211_local *local = sdata->local;
4426 
4427 	sdata_lock(sdata);
4428 	mutex_lock(&local->mtx);
4429 
4430 	/* AP might have been stopped while waiting for the lock. */
4431 	if (!sdata->vif.color_change_active)
4432 		goto unlock;
4433 
4434 	if (!ieee80211_sdata_running(sdata))
4435 		goto unlock;
4436 
4437 	ieee80211_color_change_finalize(sdata);
4438 
4439 unlock:
4440 	mutex_unlock(&local->mtx);
4441 	sdata_unlock(sdata);
4442 }
4443 
4444 void ieee80211_color_change_finish(struct ieee80211_vif *vif)
4445 {
4446 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4447 
4448 	ieee80211_queue_work(&sdata->local->hw,
4449 			     &sdata->color_change_finalize_work);
4450 }
4451 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4452 
4453 void
4454 ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
4455 				       u64 color_bitmap)
4456 {
4457 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4458 
4459 	if (sdata->vif.color_change_active || sdata->vif.csa_active)
4460 		return;
4461 
4462 	cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap);
4463 }
4464 EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify);
4465 
4466 static int
4467 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4468 		       struct cfg80211_color_change_settings *params)
4469 {
4470 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4471 	struct ieee80211_local *local = sdata->local;
4472 	u32 changed = 0;
4473 	int err;
4474 
4475 	sdata_assert_lock(sdata);
4476 
4477 	if (sdata->vif.bss_conf.nontransmitted)
4478 		return -EINVAL;
4479 
4480 	mutex_lock(&local->mtx);
4481 
4482 	/* don't allow another color change if one is already active or if csa
4483 	 * is active
4484 	 */
4485 	if (sdata->vif.color_change_active || sdata->vif.csa_active) {
4486 		err = -EBUSY;
4487 		goto out;
4488 	}
4489 
4490 	err = ieee80211_set_color_change_beacon(sdata, params, &changed);
4491 	if (err)
4492 		goto out;
4493 
4494 	sdata->vif.color_change_active = true;
4495 	sdata->vif.color_change_color = params->color;
4496 
4497 	cfg80211_color_change_started_notify(sdata->dev, params->count);
4498 
4499 	if (changed)
4500 		ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed);
4501 	else
4502 		/* if the beacon didn't change, we can finalize immediately */
4503 		ieee80211_color_change_finalize(sdata);
4504 
4505 out:
4506 	mutex_unlock(&local->mtx);
4507 
4508 	return err;
4509 }
4510 
4511 static int
4512 ieee80211_set_radar_background(struct wiphy *wiphy,
4513 			       struct cfg80211_chan_def *chandef)
4514 {
4515 	struct ieee80211_local *local = wiphy_priv(wiphy);
4516 
4517 	if (!local->ops->set_radar_background)
4518 		return -EOPNOTSUPP;
4519 
4520 	return local->ops->set_radar_background(&local->hw, chandef);
4521 }
4522 
4523 const struct cfg80211_ops mac80211_config_ops = {
4524 	.add_virtual_intf = ieee80211_add_iface,
4525 	.del_virtual_intf = ieee80211_del_iface,
4526 	.change_virtual_intf = ieee80211_change_iface,
4527 	.start_p2p_device = ieee80211_start_p2p_device,
4528 	.stop_p2p_device = ieee80211_stop_p2p_device,
4529 	.add_key = ieee80211_add_key,
4530 	.del_key = ieee80211_del_key,
4531 	.get_key = ieee80211_get_key,
4532 	.set_default_key = ieee80211_config_default_key,
4533 	.set_default_mgmt_key = ieee80211_config_default_mgmt_key,
4534 	.set_default_beacon_key = ieee80211_config_default_beacon_key,
4535 	.start_ap = ieee80211_start_ap,
4536 	.change_beacon = ieee80211_change_beacon,
4537 	.stop_ap = ieee80211_stop_ap,
4538 	.add_station = ieee80211_add_station,
4539 	.del_station = ieee80211_del_station,
4540 	.change_station = ieee80211_change_station,
4541 	.get_station = ieee80211_get_station,
4542 	.dump_station = ieee80211_dump_station,
4543 	.dump_survey = ieee80211_dump_survey,
4544 #ifdef CONFIG_MAC80211_MESH
4545 	.add_mpath = ieee80211_add_mpath,
4546 	.del_mpath = ieee80211_del_mpath,
4547 	.change_mpath = ieee80211_change_mpath,
4548 	.get_mpath = ieee80211_get_mpath,
4549 	.dump_mpath = ieee80211_dump_mpath,
4550 	.get_mpp = ieee80211_get_mpp,
4551 	.dump_mpp = ieee80211_dump_mpp,
4552 	.update_mesh_config = ieee80211_update_mesh_config,
4553 	.get_mesh_config = ieee80211_get_mesh_config,
4554 	.join_mesh = ieee80211_join_mesh,
4555 	.leave_mesh = ieee80211_leave_mesh,
4556 #endif
4557 	.join_ocb = ieee80211_join_ocb,
4558 	.leave_ocb = ieee80211_leave_ocb,
4559 	.change_bss = ieee80211_change_bss,
4560 	.set_txq_params = ieee80211_set_txq_params,
4561 	.set_monitor_channel = ieee80211_set_monitor_channel,
4562 	.suspend = ieee80211_suspend,
4563 	.resume = ieee80211_resume,
4564 	.scan = ieee80211_scan,
4565 	.abort_scan = ieee80211_abort_scan,
4566 	.sched_scan_start = ieee80211_sched_scan_start,
4567 	.sched_scan_stop = ieee80211_sched_scan_stop,
4568 	.auth = ieee80211_auth,
4569 	.assoc = ieee80211_assoc,
4570 	.deauth = ieee80211_deauth,
4571 	.disassoc = ieee80211_disassoc,
4572 	.join_ibss = ieee80211_join_ibss,
4573 	.leave_ibss = ieee80211_leave_ibss,
4574 	.set_mcast_rate = ieee80211_set_mcast_rate,
4575 	.set_wiphy_params = ieee80211_set_wiphy_params,
4576 	.set_tx_power = ieee80211_set_tx_power,
4577 	.get_tx_power = ieee80211_get_tx_power,
4578 	.rfkill_poll = ieee80211_rfkill_poll,
4579 	CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
4580 	CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
4581 	.set_power_mgmt = ieee80211_set_power_mgmt,
4582 	.set_bitrate_mask = ieee80211_set_bitrate_mask,
4583 	.remain_on_channel = ieee80211_remain_on_channel,
4584 	.cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
4585 	.mgmt_tx = ieee80211_mgmt_tx,
4586 	.mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
4587 	.set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
4588 	.set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
4589 	.update_mgmt_frame_registrations =
4590 		ieee80211_update_mgmt_frame_registrations,
4591 	.set_antenna = ieee80211_set_antenna,
4592 	.get_antenna = ieee80211_get_antenna,
4593 	.set_rekey_data = ieee80211_set_rekey_data,
4594 	.tdls_oper = ieee80211_tdls_oper,
4595 	.tdls_mgmt = ieee80211_tdls_mgmt,
4596 	.tdls_channel_switch = ieee80211_tdls_channel_switch,
4597 	.tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
4598 	.probe_client = ieee80211_probe_client,
4599 	.set_noack_map = ieee80211_set_noack_map,
4600 #ifdef CONFIG_PM
4601 	.set_wakeup = ieee80211_set_wakeup,
4602 #endif
4603 	.get_channel = ieee80211_cfg_get_channel,
4604 	.start_radar_detection = ieee80211_start_radar_detection,
4605 	.end_cac = ieee80211_end_cac,
4606 	.channel_switch = ieee80211_channel_switch,
4607 	.set_qos_map = ieee80211_set_qos_map,
4608 	.set_ap_chanwidth = ieee80211_set_ap_chanwidth,
4609 	.add_tx_ts = ieee80211_add_tx_ts,
4610 	.del_tx_ts = ieee80211_del_tx_ts,
4611 	.start_nan = ieee80211_start_nan,
4612 	.stop_nan = ieee80211_stop_nan,
4613 	.nan_change_conf = ieee80211_nan_change_conf,
4614 	.add_nan_func = ieee80211_add_nan_func,
4615 	.del_nan_func = ieee80211_del_nan_func,
4616 	.set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
4617 	.tx_control_port = ieee80211_tx_control_port,
4618 	.get_txq_stats = ieee80211_get_txq_stats,
4619 	.get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
4620 	.start_pmsr = ieee80211_start_pmsr,
4621 	.abort_pmsr = ieee80211_abort_pmsr,
4622 	.probe_mesh_link = ieee80211_probe_mesh_link,
4623 	.set_tid_config = ieee80211_set_tid_config,
4624 	.reset_tid_config = ieee80211_reset_tid_config,
4625 	.set_sar_specs = ieee80211_set_sar_specs,
4626 	.color_change = ieee80211_color_change,
4627 	.set_radar_background = ieee80211_set_radar_background,
4628 };
4629