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