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