Linux Audio

Check our new training course

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