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