Linux Audio

Check our new training course

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