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