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