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