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