File Index
Files and directories
Sign in
FILE

cfg80211.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/wireless/quantenna/qtnfmac/cfg80211.c C
   1// SPDX-License-Identifier: GPL-2.0+
   2/* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
   3
   4#include <linux/kernel.h>
   5#include <linux/etherdevice.h>
   6#include <linux/vmalloc.h>
   7#include <linux/ieee80211.h>
   8#include <net/cfg80211.h>
   9#include <net/netlink.h>
  10
  11#include "cfg80211.h"
  12#include "commands.h"
  13#include "core.h"
  14#include "util.h"
  15#include "bus.h"
  16
  17/* Supported rates to be advertised to the cfg80211 */
  18static struct ieee80211_rate qtnf_rates_2g[] = {
  19	{.bitrate = 10, .hw_value = 2, },
  20	{.bitrate = 20, .hw_value = 4, },
  21	{.bitrate = 55, .hw_value = 11, },
  22	{.bitrate = 110, .hw_value = 22, },
  23	{.bitrate = 60, .hw_value = 12, },
  24	{.bitrate = 90, .hw_value = 18, },
  25	{.bitrate = 120, .hw_value = 24, },
  26	{.bitrate = 180, .hw_value = 36, },
  27	{.bitrate = 240, .hw_value = 48, },
  28	{.bitrate = 360, .hw_value = 72, },
  29	{.bitrate = 480, .hw_value = 96, },
  30	{.bitrate = 540, .hw_value = 108, },
  31};
  32
  33/* Supported rates to be advertised to the cfg80211 */
  34static struct ieee80211_rate qtnf_rates_5g[] = {
  35	{.bitrate = 60, .hw_value = 12, },
  36	{.bitrate = 90, .hw_value = 18, },
  37	{.bitrate = 120, .hw_value = 24, },
  38	{.bitrate = 180, .hw_value = 36, },
  39	{.bitrate = 240, .hw_value = 48, },
  40	{.bitrate = 360, .hw_value = 72, },
  41	{.bitrate = 480, .hw_value = 96, },
  42	{.bitrate = 540, .hw_value = 108, },
  43};
  44
  45/* Supported crypto cipher suits to be advertised to cfg80211 */
  46static const u32 qtnf_cipher_suites[] = {
  47	WLAN_CIPHER_SUITE_TKIP,
  48	WLAN_CIPHER_SUITE_CCMP,
  49	WLAN_CIPHER_SUITE_AES_CMAC,
  50};
  51
  52/* Supported mgmt frame types to be advertised to cfg80211 */
  53static const struct ieee80211_txrx_stypes
  54qtnf_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  55	[NL80211_IFTYPE_STATION] = {
  56		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  57		      BIT(IEEE80211_STYPE_AUTH >> 4),
  58		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  59		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  60		      BIT(IEEE80211_STYPE_AUTH >> 4),
  61	},
  62	[NL80211_IFTYPE_AP] = {
  63		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  64		      BIT(IEEE80211_STYPE_AUTH >> 4),
  65		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  66		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  67		      BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  68		      BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  69		      BIT(IEEE80211_STYPE_AUTH >> 4),
  70	},
  71};
  72
  73static int
  74qtnf_validate_iface_combinations(struct wiphy *wiphy,
  75				 struct qtnf_vif *change_vif,
  76				 enum nl80211_iftype new_type)
  77{
  78	struct qtnf_wmac *mac;
  79	struct qtnf_vif *vif;
  80	int i;
  81	int ret = 0;
  82	struct iface_combination_params params = {
  83		.num_different_channels = 1,
  84	};
  85
  86	mac = wiphy_priv(wiphy);
  87	if (!mac)
  88		return -EFAULT;
  89
  90	for (i = 0; i < QTNF_MAX_INTF; i++) {
  91		vif = &mac->iflist[i];
  92		if (vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
  93			params.iftype_num[vif->wdev.iftype]++;
  94	}
  95
  96	if (change_vif) {
  97		params.iftype_num[new_type]++;
  98		params.iftype_num[change_vif->wdev.iftype]--;
  99	} else {
 100		params.iftype_num[new_type]++;
 101	}
 102
 103	ret = cfg80211_check_combinations(wiphy, &params);
 104
 105	if (ret)
 106		return ret;
 107
 108	/* Check repeater interface combination: primary VIF should be STA only.
 109	 * STA (primary) + AP (secondary) is OK.
 110	 * AP (primary) + STA (secondary) is not supported.
 111	 */
 112	vif = qtnf_mac_get_base_vif(mac);
 113	if (vif && vif->wdev.iftype == NL80211_IFTYPE_AP &&
 114	    vif != change_vif && new_type == NL80211_IFTYPE_STATION) {
 115		ret = -EINVAL;
 116		pr_err("MAC%u invalid combination: AP as primary repeater interface is not supported\n",
 117		       mac->macid);
 118	}
 119
 120	return ret;
 121}
 122
 123static int
 124qtnf_change_virtual_intf(struct wiphy *wiphy,
 125			 struct net_device *dev,
 126			 enum nl80211_iftype type,
 127			 struct vif_params *params)
 128{
 129	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 130	u8 *mac_addr = NULL;
 131	int use4addr = 0;
 132	int ret;
 133
 134	ret = qtnf_validate_iface_combinations(wiphy, vif, type);
 135	if (ret) {
 136		pr_err("VIF%u.%u combination check: failed to set type %d\n",
 137		       vif->mac->macid, vif->vifid, type);
 138		return ret;
 139	}
 140
 141	if (params) {
 142		mac_addr = params->macaddr;
 143		use4addr = params->use_4addr;
 144	}
 145
 146	qtnf_scan_done(vif->mac, true);
 147
 148	ret = qtnf_cmd_send_change_intf_type(vif, type, use4addr, mac_addr);
 149	if (ret) {
 150		pr_err("VIF%u.%u: failed to change type to %d\n",
 151		       vif->mac->macid, vif->vifid, type);
 152		return ret;
 153	}
 154
 155	vif->wdev.iftype = type;
 156	return 0;
 157}
 158
 159int qtnf_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
 160{
 161	struct net_device *netdev =  wdev->netdev;
 162	struct qtnf_vif *vif;
 163	struct sk_buff *skb;
 164
 165	if (WARN_ON(!netdev))
 166		return -EFAULT;
 167
 168	vif = qtnf_netdev_get_priv(wdev->netdev);
 169
 170	qtnf_scan_done(vif->mac, true);
 171
 172	/* Stop data */
 173	netif_tx_stop_all_queues(netdev);
 174	if (netif_carrier_ok(netdev))
 175		netif_carrier_off(netdev);
 176
 177	while ((skb = skb_dequeue(&vif->high_pri_tx_queue)))
 178		dev_kfree_skb_any(skb);
 179
 180	cancel_work_sync(&vif->high_pri_tx_work);
 181
 182	if (netdev->reg_state == NETREG_REGISTERED)
 183		cfg80211_unregister_netdevice(netdev);
 184
 185	if (qtnf_cmd_send_del_intf(vif))
 186		pr_err("VIF%u.%u: failed to delete VIF\n", vif->mac->macid,
 187		       vif->vifid);
 188
 189	vif->netdev->ieee80211_ptr = NULL;
 190	vif->netdev = NULL;
 191	vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
 192
 193	return 0;
 194}
 195
 196static struct wireless_dev *qtnf_add_virtual_intf(struct wiphy *wiphy,
 197						  const char *name,
 198						  unsigned char name_assign_t,
 199						  enum nl80211_iftype type,
 200						  struct vif_params *params)
 201{
 202	struct qtnf_wmac *mac;
 203	struct qtnf_vif *vif;
 204	u8 *mac_addr = NULL;
 205	int use4addr = 0;
 206	int ret;
 207
 208	mac = wiphy_priv(wiphy);
 209
 210	if (!mac)
 211		return ERR_PTR(-EFAULT);
 212
 213	ret = qtnf_validate_iface_combinations(wiphy, NULL, type);
 214	if (ret) {
 215		pr_err("MAC%u invalid combination: failed to add type %d\n",
 216		       mac->macid, type);
 217		return ERR_PTR(ret);
 218	}
 219
 220	switch (type) {
 221	case NL80211_IFTYPE_STATION:
 222	case NL80211_IFTYPE_AP:
 223		vif = qtnf_mac_get_free_vif(mac);
 224		if (!vif) {
 225			pr_err("MAC%u: no free VIF available\n", mac->macid);
 226			return ERR_PTR(-EFAULT);
 227		}
 228
 229		eth_zero_addr(vif->mac_addr);
 230		eth_zero_addr(vif->bssid);
 231		vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
 232		memset(&vif->wdev, 0, sizeof(vif->wdev));
 233		vif->wdev.wiphy = wiphy;
 234		vif->wdev.iftype = type;
 235		break;
 236	default:
 237		pr_err("MAC%u: unsupported IF type %d\n", mac->macid, type);
 238		return ERR_PTR(-ENOTSUPP);
 239	}
 240
 241	if (params) {
 242		mac_addr = params->macaddr;
 243		use4addr = params->use_4addr;
 244	}
 245
 246	ret = qtnf_cmd_send_add_intf(vif, type, use4addr, mac_addr);
 247	if (ret) {
 248		pr_err("VIF%u.%u: failed to add VIF %pM\n",
 249		       mac->macid, vif->vifid, mac_addr);
 250		goto err_cmd;
 251	}
 252
 253	if (!is_valid_ether_addr(vif->mac_addr)) {
 254		pr_err("VIF%u.%u: FW reported bad MAC: %pM\n",
 255		       mac->macid, vif->vifid, vif->mac_addr);
 256		ret = -EINVAL;
 257		goto error_del_vif;
 258	}
 259
 260	ret = qtnf_core_net_attach(mac, vif, name, name_assign_t);
 261	if (ret) {
 262		pr_err("VIF%u.%u: failed to attach netdev\n", mac->macid,
 263		       vif->vifid);
 264		goto error_del_vif;
 265	}
 266
 267	if (qtnf_hwcap_is_set(&mac->bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE)) {
 268		ret = qtnf_cmd_netdev_changeupper(vif, vif->netdev->ifindex);
 269		if (ret) {
 270			cfg80211_unregister_netdevice(vif->netdev);
 271			vif->netdev = NULL;
 272			goto error_del_vif;
 273		}
 274	}
 275
 276	vif->wdev.netdev = vif->netdev;
 277	return &vif->wdev;
 278
 279error_del_vif:
 280	qtnf_cmd_send_del_intf(vif);
 281err_cmd:
 282	vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
 283
 284	return ERR_PTR(ret);
 285}
 286
 287static int qtnf_mgmt_set_appie(struct qtnf_vif *vif,
 288			       const struct cfg80211_beacon_data *info)
 289{
 290	int ret = 0;
 291
 292	if (!info->beacon_ies || !info->beacon_ies_len) {
 293		ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
 294						   NULL, 0);
 295	} else {
 296		ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
 297						   info->beacon_ies,
 298						   info->beacon_ies_len);
 299	}
 300
 301	if (ret)
 302		goto out;
 303
 304	if (!info->proberesp_ies || !info->proberesp_ies_len) {
 305		ret = qtnf_cmd_send_mgmt_set_appie(vif,
 306						   QLINK_IE_SET_PROBE_RESP_IES,
 307						   NULL, 0);
 308	} else {
 309		ret = qtnf_cmd_send_mgmt_set_appie(vif,
 310						   QLINK_IE_SET_PROBE_RESP_IES,
 311						   info->proberesp_ies,
 312						   info->proberesp_ies_len);
 313	}
 314
 315	if (ret)
 316		goto out;
 317
 318	if (!info->assocresp_ies || !info->assocresp_ies_len) {
 319		ret = qtnf_cmd_send_mgmt_set_appie(vif,
 320						   QLINK_IE_SET_ASSOC_RESP,
 321						   NULL, 0);
 322	} else {
 323		ret = qtnf_cmd_send_mgmt_set_appie(vif,
 324						   QLINK_IE_SET_ASSOC_RESP,
 325						   info->assocresp_ies,
 326						   info->assocresp_ies_len);
 327	}
 328
 329out:
 330	return ret;
 331}
 332
 333static int qtnf_change_beacon(struct wiphy *wiphy, struct net_device *dev,
 334			      struct cfg80211_ap_update *info)
 335{
 336	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 337
 338	return qtnf_mgmt_set_appie(vif, &info->beacon);
 339}
 340
 341static int qtnf_start_ap(struct wiphy *wiphy, struct net_device *dev,
 342			 struct cfg80211_ap_settings *settings)
 343{
 344	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 345	int ret;
 346
 347	ret = qtnf_cmd_send_start_ap(vif, settings);
 348	if (ret)
 349		pr_err("VIF%u.%u: failed to start AP\n", vif->mac->macid,
 350		       vif->vifid);
 351
 352	return ret;
 353}
 354
 355static int qtnf_stop_ap(struct wiphy *wiphy, struct net_device *dev,
 356			unsigned int link_id)
 357{
 358	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 359	int ret;
 360
 361	qtnf_scan_done(vif->mac, true);
 362
 363	ret = qtnf_cmd_send_stop_ap(vif);
 364	if (ret)
 365		pr_err("VIF%u.%u: failed to stop AP operation in FW\n",
 366		       vif->mac->macid, vif->vifid);
 367
 368	netif_carrier_off(vif->netdev);
 369
 370	return ret;
 371}
 372
 373static int qtnf_set_wiphy_params(struct wiphy *wiphy, int radio_idx,
 374				 u32 changed)
 375{
 376	struct qtnf_wmac *mac = wiphy_priv(wiphy);
 377	struct qtnf_vif *vif;
 378	int ret;
 379
 380	vif = qtnf_mac_get_base_vif(mac);
 381	if (!vif) {
 382		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
 383		return -EFAULT;
 384	}
 385
 386	ret = qtnf_cmd_send_update_phy_params(mac, changed);
 387	if (ret)
 388		pr_err("MAC%u: failed to update PHY params\n", mac->macid);
 389
 390	return ret;
 391}
 392
 393static void
 394qtnf_update_mgmt_frame_registrations(struct wiphy *wiphy,
 395				     struct wireless_dev *wdev,
 396				     struct mgmt_frame_regs *upd)
 397{
 398	struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
 399	u16 new_mask = upd->interface_stypes;
 400	u16 old_mask = vif->mgmt_frames_bitmask;
 401	static const struct {
 402		u16 mask, qlink_type;
 403	} updates[] = {
 404		{
 405			.mask = BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
 406				BIT(IEEE80211_STYPE_ASSOC_REQ >> 4),
 407			.qlink_type = QLINK_MGMT_FRAME_ASSOC_REQ,
 408		},
 409		{
 410			.mask = BIT(IEEE80211_STYPE_AUTH >> 4),
 411			.qlink_type = QLINK_MGMT_FRAME_AUTH,
 412		},
 413		{
 414			.mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
 415			.qlink_type = QLINK_MGMT_FRAME_PROBE_REQ,
 416		},
 417		{
 418			.mask = BIT(IEEE80211_STYPE_ACTION >> 4),
 419			.qlink_type = QLINK_MGMT_FRAME_ACTION,
 420		},
 421	};
 422	unsigned int i;
 423
 424	if (new_mask == old_mask)
 425		return;
 426
 427	for (i = 0; i < ARRAY_SIZE(updates); i++) {
 428		u16 mask = updates[i].mask;
 429		u16 qlink_frame_type = updates[i].qlink_type;
 430		bool reg;
 431
 432		/* the ! are here due to the assoc/reassoc merge */
 433		if (!(new_mask & mask) == !(old_mask & mask))
 434			continue;
 435
 436		reg = new_mask & mask;
 437
 438		if (qtnf_cmd_send_register_mgmt(vif, qlink_frame_type, reg))
 439			pr_warn("VIF%u.%u: failed to %sregister qlink frame type 0x%x\n",
 440				vif->mac->macid, vif->vifid, reg ? "" : "un",
 441				qlink_frame_type);
 442	}
 443
 444	vif->mgmt_frames_bitmask = new_mask;
 445}
 446
 447static int
 448qtnf_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
 449	     struct cfg80211_mgmt_tx_params *params, u64 *cookie)
 450{
 451	struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
 452	const struct ieee80211_mgmt *mgmt_frame = (void *)params->buf;
 453	u32 short_cookie = get_random_u32();
 454	u16 flags = 0;
 455	u16 freq;
 456
 457	*cookie = short_cookie;
 458
 459	if (params->offchan)
 460		flags |= QLINK_FRAME_TX_FLAG_OFFCHAN;
 461
 462	if (params->no_cck)
 463		flags |= QLINK_FRAME_TX_FLAG_NO_CCK;
 464
 465	if (params->dont_wait_for_ack)
 466		flags |= QLINK_FRAME_TX_FLAG_ACK_NOWAIT;
 467
 468	/* If channel is not specified, pass "freq = 0" to tell device
 469	 * firmware to use current channel.
 470	 */
 471	if (params->chan)
 472		freq = params->chan->center_freq;
 473	else
 474		freq = 0;
 475
 476	pr_debug("%s freq:%u; FC:%.4X; DA:%pM; len:%zu; C:%.8X; FL:%.4X\n",
 477		 wdev->netdev->name, freq,
 478		 le16_to_cpu(mgmt_frame->frame_control), mgmt_frame->da,
 479		 params->len, short_cookie, flags);
 480
 481	return qtnf_cmd_send_frame(vif, short_cookie, flags,
 482				   freq, params->buf, params->len);
 483}
 484
 485static int
 486qtnf_get_station(struct wiphy *wiphy, struct net_device *dev,
 487		 const u8 *mac, struct station_info *sinfo)
 488{
 489	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 490
 491	sinfo->generation = vif->generation;
 492	return qtnf_cmd_get_sta_info(vif, mac, sinfo);
 493}
 494
 495static int
 496qtnf_dump_station(struct wiphy *wiphy, struct net_device *dev,
 497		  int idx, u8 *mac, struct station_info *sinfo)
 498{
 499	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 500	const struct qtnf_sta_node *sta_node;
 501	int ret;
 502
 503	switch (vif->wdev.iftype) {
 504	case NL80211_IFTYPE_STATION:
 505		if (idx != 0 || !vif->wdev.connected)
 506			return -ENOENT;
 507
 508		ether_addr_copy(mac, vif->bssid);
 509		break;
 510	case NL80211_IFTYPE_AP:
 511		sta_node = qtnf_sta_list_lookup_index(&vif->sta_list, idx);
 512		if (unlikely(!sta_node))
 513			return -ENOENT;
 514
 515		ether_addr_copy(mac, sta_node->mac_addr);
 516		break;
 517	default:
 518		return -ENOTSUPP;
 519	}
 520
 521	ret = qtnf_cmd_get_sta_info(vif, mac, sinfo);
 522
 523	if (vif->wdev.iftype == NL80211_IFTYPE_AP) {
 524		if (ret == -ENOENT) {
 525			cfg80211_del_sta(vif->netdev, mac, GFP_KERNEL);
 526			sinfo->filled = 0;
 527		}
 528	}
 529
 530	sinfo->generation = vif->generation;
 531
 532	return ret;
 533}
 534
 535static int qtnf_add_key(struct wiphy *wiphy, struct net_device *dev,
 536			int link_id, u8 key_index, bool pairwise,
 537			const u8 *mac_addr, struct key_params *params)
 538{
 539	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 540	int ret;
 541
 542	ret = qtnf_cmd_send_add_key(vif, key_index, pairwise, mac_addr, params);
 543	if (ret)
 544		pr_err("VIF%u.%u: failed to add key: cipher=%x idx=%u pw=%u\n",
 545		       vif->mac->macid, vif->vifid, params->cipher, key_index,
 546		       pairwise);
 547
 548	return ret;
 549}
 550
 551static int qtnf_del_key(struct wiphy *wiphy, struct net_device *dev,
 552			int link_id, u8 key_index, bool pairwise,
 553			const u8 *mac_addr)
 554{
 555	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 556	int ret;
 557
 558	ret = qtnf_cmd_send_del_key(vif, key_index, pairwise, mac_addr);
 559	if (ret) {
 560		if (ret == -ENOENT) {
 561			pr_debug("VIF%u.%u: key index %d out of bounds\n",
 562				 vif->mac->macid, vif->vifid, key_index);
 563		} else {
 564			pr_err("VIF%u.%u: failed to delete key: idx=%u pw=%u\n",
 565			       vif->mac->macid, vif->vifid,
 566			       key_index, pairwise);
 567		}
 568	}
 569
 570	return ret;
 571}
 572
 573static int qtnf_set_default_key(struct wiphy *wiphy, struct net_device *dev,
 574				int link_id, u8 key_index, bool unicast,
 575				bool multicast)
 576{
 577	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 578	int ret;
 579
 580	ret = qtnf_cmd_send_set_default_key(vif, key_index, unicast, multicast);
 581	if (ret)
 582		pr_err("VIF%u.%u: failed to set dflt key: idx=%u uc=%u mc=%u\n",
 583		       vif->mac->macid, vif->vifid, key_index, unicast,
 584		       multicast);
 585
 586	return ret;
 587}
 588
 589static int
 590qtnf_set_default_mgmt_key(struct wiphy *wiphy, struct net_device *dev,
 591			  int link_id, u8 key_index)
 592{
 593	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 594	int ret;
 595
 596	ret = qtnf_cmd_send_set_default_mgmt_key(vif, key_index);
 597	if (ret)
 598		pr_err("VIF%u.%u: failed to set default MGMT key: idx=%u\n",
 599		       vif->mac->macid, vif->vifid, key_index);
 600
 601	return ret;
 602}
 603
 604static int
 605qtnf_change_station(struct wiphy *wiphy, struct net_device *dev,
 606		    const u8 *mac, struct station_parameters *params)
 607{
 608	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 609	int ret;
 610
 611	ret = qtnf_cmd_send_change_sta(vif, mac, params);
 612	if (ret)
 613		pr_err("VIF%u.%u: failed to change STA %pM\n",
 614		       vif->mac->macid, vif->vifid, mac);
 615
 616	return ret;
 617}
 618
 619static int
 620qtnf_del_station(struct wiphy *wiphy, struct net_device *dev,
 621		 struct station_del_parameters *params)
 622{
 623	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 624	int ret;
 625
 626	if (params->mac &&
 627	    (vif->wdev.iftype == NL80211_IFTYPE_AP) &&
 628	    !is_broadcast_ether_addr(params->mac) &&
 629	    !qtnf_sta_list_lookup(&vif->sta_list, params->mac))
 630		return 0;
 631
 632	ret = qtnf_cmd_send_del_sta(vif, params);
 633	if (ret)
 634		pr_err("VIF%u.%u: failed to delete STA %pM\n",
 635		       vif->mac->macid, vif->vifid, params->mac);
 636
 637	return ret;
 638}
 639
 640static int
 641qtnf_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
 642{
 643	struct qtnf_wmac *mac = wiphy_priv(wiphy);
 644	int ret;
 645
 646	cancel_delayed_work_sync(&mac->scan_timeout);
 647
 648	mac->scan_req = request;
 649
 650	ret = qtnf_cmd_send_scan(mac);
 651	if (ret) {
 652		pr_err("MAC%u: failed to start scan\n", mac->macid);
 653		mac->scan_req = NULL;
 654		goto out;
 655	}
 656
 657	pr_debug("MAC%u: scan started\n", mac->macid);
 658	queue_delayed_work(mac->bus->workqueue, &mac->scan_timeout,
 659			   QTNF_SCAN_TIMEOUT_SEC * HZ);
 660
 661out:
 662	return ret;
 663}
 664
 665static int
 666qtnf_connect(struct wiphy *wiphy, struct net_device *dev,
 667	     struct cfg80211_connect_params *sme)
 668{
 669	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 670	int ret;
 671
 672	if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
 673		return -EOPNOTSUPP;
 674
 675	if (sme->auth_type == NL80211_AUTHTYPE_SAE &&
 676	    !(sme->flags & CONNECT_REQ_EXTERNAL_AUTH_SUPPORT)) {
 677		pr_err("can not offload authentication to userspace\n");
 678		return -EOPNOTSUPP;
 679	}
 680
 681	if (sme->bssid)
 682		ether_addr_copy(vif->bssid, sme->bssid);
 683	else
 684		eth_zero_addr(vif->bssid);
 685
 686	ret = qtnf_cmd_send_connect(vif, sme);
 687	if (ret)
 688		pr_err("VIF%u.%u: failed to connect\n",
 689		       vif->mac->macid, vif->vifid);
 690
 691	return ret;
 692}
 693
 694static int
 695qtnf_external_auth(struct wiphy *wiphy, struct net_device *dev,
 696		   struct cfg80211_external_auth_params *auth)
 697{
 698	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 699	int ret;
 700
 701	if (vif->wdev.iftype == NL80211_IFTYPE_STATION &&
 702	    !ether_addr_equal(vif->bssid, auth->bssid))
 703		pr_warn("unexpected bssid: %pM", auth->bssid);
 704
 705	ret = qtnf_cmd_send_external_auth(vif, auth);
 706	if (ret)
 707		pr_err("VIF%u.%u: failed to report external auth\n",
 708		       vif->mac->macid, vif->vifid);
 709
 710	return ret;
 711}
 712
 713static int
 714qtnf_disconnect(struct wiphy *wiphy, struct net_device *dev,
 715		u16 reason_code)
 716{
 717	struct qtnf_wmac *mac = wiphy_priv(wiphy);
 718	struct qtnf_vif *vif;
 719	int ret = 0;
 720
 721	vif = qtnf_mac_get_base_vif(mac);
 722	if (!vif) {
 723		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
 724		return -EFAULT;
 725	}
 726
 727	if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
 728		return -EOPNOTSUPP;
 729
 730	ret = qtnf_cmd_send_disconnect(vif, reason_code);
 731	if (ret)
 732		pr_err("VIF%u.%u: failed to disconnect\n",
 733		       mac->macid, vif->vifid);
 734
 735	if (vif->wdev.connected) {
 736		netif_carrier_off(vif->netdev);
 737		cfg80211_disconnected(vif->netdev, reason_code,
 738				      NULL, 0, true, GFP_KERNEL);
 739	}
 740
 741	return ret;
 742}
 743
 744static int
 745qtnf_dump_survey(struct wiphy *wiphy, struct net_device *dev,
 746		 int idx, struct survey_info *survey)
 747{
 748	struct qtnf_wmac *mac = wiphy_priv(wiphy);
 749	struct wireless_dev *wdev = dev->ieee80211_ptr;
 750	struct ieee80211_supported_band *sband;
 751	const struct cfg80211_chan_def *chandef = wdev_chandef(wdev, 0);
 752	struct ieee80211_channel *chan;
 753	int ret;
 754
 755	sband = wiphy->bands[NL80211_BAND_2GHZ];
 756	if (sband && idx >= sband->n_channels) {
 757		idx -= sband->n_channels;
 758		sband = NULL;
 759	}
 760
 761	if (!sband)
 762		sband = wiphy->bands[NL80211_BAND_5GHZ];
 763
 764	if (!sband || idx >= sband->n_channels)
 765		return -ENOENT;
 766
 767	chan = &sband->channels[idx];
 768	survey->channel = chan;
 769	survey->filled = 0x0;
 770
 771	if (chandef && chan == chandef->chan)
 772		survey->filled = SURVEY_INFO_IN_USE;
 773
 774	ret = qtnf_cmd_get_chan_stats(mac, chan->center_freq, survey);
 775	if (ret)
 776		pr_debug("failed to get chan(%d) stats from card\n",
 777			 chan->hw_value);
 778
 779	return ret;
 780}
 781
 782static int
 783qtnf_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
 784		 unsigned int link_id, struct cfg80211_chan_def *chandef)
 785{
 786	struct net_device *ndev = wdev->netdev;
 787	struct qtnf_vif *vif;
 788	int ret;
 789
 790	if (!ndev)
 791		return -ENODEV;
 792
 793	vif = qtnf_netdev_get_priv(wdev->netdev);
 794
 795	ret = qtnf_cmd_get_channel(vif, chandef);
 796	if (ret) {
 797		pr_err("%s: failed to get channel: %d\n", ndev->name, ret);
 798		ret = -ENODATA;
 799		goto out;
 800	}
 801
 802	if (!cfg80211_chandef_valid(chandef)) {
 803		pr_err("%s: bad channel freq=%u cf1=%u cf2=%u bw=%u\n",
 804		       ndev->name, chandef->chan->center_freq,
 805		       chandef->center_freq1, chandef->center_freq2,
 806		       chandef->width);
 807		ret = -ENODATA;
 808		goto out;
 809	}
 810
 811out:
 812	return ret;
 813}
 814
 815static int qtnf_channel_switch(struct wiphy *wiphy, struct net_device *dev,
 816			       struct cfg80211_csa_settings *params)
 817{
 818	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 819	int ret;
 820
 821	pr_debug("%s: chan(%u) count(%u) radar(%u) block_tx(%u)\n", dev->name,
 822		 params->chandef.chan->hw_value, params->count,
 823		 params->radar_required, params->block_tx);
 824
 825	if (!cfg80211_chandef_valid(&params->chandef)) {
 826		pr_err("%s: invalid channel\n", dev->name);
 827		return -EINVAL;
 828	}
 829
 830	ret = qtnf_cmd_send_chan_switch(vif, params);
 831	if (ret)
 832		pr_warn("%s: failed to switch to channel (%u)\n",
 833			dev->name, params->chandef.chan->hw_value);
 834
 835	return ret;
 836}
 837
 838static int qtnf_start_radar_detection(struct wiphy *wiphy,
 839				      struct net_device *ndev,
 840				      struct cfg80211_chan_def *chandef,
 841				      u32 cac_time_ms, int link_id)
 842{
 843	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
 844	int ret;
 845
 846	if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
 847		return -ENOTSUPP;
 848
 849	ret = qtnf_cmd_start_cac(vif, chandef, cac_time_ms);
 850	if (ret)
 851		pr_err("%s: failed to start CAC ret=%d\n", ndev->name, ret);
 852
 853	return ret;
 854}
 855
 856static int qtnf_set_mac_acl(struct wiphy *wiphy,
 857			    struct net_device *dev,
 858			    const struct cfg80211_acl_data *params)
 859{
 860	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 861	int ret;
 862
 863	ret = qtnf_cmd_set_mac_acl(vif, params);
 864	if (ret)
 865		pr_err("%s: failed to set mac ACL ret=%d\n", dev->name, ret);
 866
 867	return ret;
 868}
 869
 870static int qtnf_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
 871			       bool enabled, int timeout)
 872{
 873	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 874	int ret;
 875
 876	ret = qtnf_cmd_send_pm_set(vif, enabled ? QLINK_PM_AUTO_STANDBY :
 877				   QLINK_PM_OFF, timeout);
 878	if (ret)
 879		pr_err("%s: failed to set PM mode ret=%d\n", dev->name, ret);
 880
 881	return ret;
 882}
 883
 884static int qtnf_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
 885			     int radio_idx, unsigned int link_id, int *dbm)
 886{
 887	struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
 888	int ret;
 889
 890	ret = qtnf_cmd_get_tx_power(vif, dbm);
 891	if (ret)
 892		pr_err("MAC%u: failed to get Tx power\n", vif->mac->macid);
 893
 894	return ret;
 895}
 896
 897static int qtnf_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
 898			     int radio_idx, enum nl80211_tx_power_setting type,
 899			     int mbm)
 900{
 901	struct qtnf_vif *vif;
 902	int ret;
 903
 904	if (wdev) {
 905		vif = qtnf_netdev_get_priv(wdev->netdev);
 906	} else {
 907		struct qtnf_wmac *mac = wiphy_priv(wiphy);
 908
 909		vif = qtnf_mac_get_base_vif(mac);
 910		if (!vif) {
 911			pr_err("MAC%u: primary VIF is not configured\n",
 912			       mac->macid);
 913			return -EFAULT;
 914		}
 915	}
 916
 917	ret = qtnf_cmd_set_tx_power(vif, type, mbm);
 918	if (ret)
 919		pr_err("MAC%u: failed to set Tx power\n", vif->mac->macid);
 920
 921	return ret;
 922}
 923
 924static int qtnf_update_owe_info(struct wiphy *wiphy, struct net_device *dev,
 925				struct cfg80211_update_owe_info *owe_info)
 926{
 927	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
 928	int ret;
 929
 930	if (vif->wdev.iftype != NL80211_IFTYPE_AP)
 931		return -EOPNOTSUPP;
 932
 933	ret = qtnf_cmd_send_update_owe(vif, owe_info);
 934	if (ret)
 935		pr_err("VIF%u.%u: failed to update owe info\n",
 936		       vif->mac->macid, vif->vifid);
 937
 938	return ret;
 939}
 940
 941#ifdef CONFIG_PM
 942static int qtnf_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wowlan)
 943{
 944	struct qtnf_wmac *mac = wiphy_priv(wiphy);
 945	struct qtnf_vif *vif;
 946	int ret = 0;
 947
 948	vif = qtnf_mac_get_base_vif(mac);
 949	if (!vif) {
 950		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
 951		ret = -EFAULT;
 952		goto exit;
 953	}
 954
 955	if (!wowlan) {
 956		pr_debug("WoWLAN triggers are not enabled\n");
 957		qtnf_virtual_intf_cleanup(vif->netdev);
 958		goto exit;
 959	}
 960
 961	qtnf_scan_done(vif->mac, true);
 962
 963	ret = qtnf_cmd_send_wowlan_set(vif, wowlan);
 964	if (ret) {
 965		pr_err("MAC%u: failed to set WoWLAN triggers\n",
 966		       mac->macid);
 967		goto exit;
 968	}
 969
 970exit:
 971	return ret;
 972}
 973
 974static int qtnf_resume(struct wiphy *wiphy)
 975{
 976	struct qtnf_wmac *mac = wiphy_priv(wiphy);
 977	struct qtnf_vif *vif;
 978	int ret = 0;
 979
 980	vif = qtnf_mac_get_base_vif(mac);
 981	if (!vif) {
 982		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
 983		return -EFAULT;
 984	}
 985
 986	ret = qtnf_cmd_send_wowlan_set(vif, NULL);
 987	if (ret)
 988		pr_err("MAC%u: failed to reset WoWLAN triggers\n",
 989		       mac->macid);
 990
 991	return ret;
 992}
 993
 994static void qtnf_set_wakeup(struct wiphy *wiphy, bool enabled)
 995{
 996	struct qtnf_wmac *mac = wiphy_priv(wiphy);
 997	struct qtnf_bus *bus = mac->bus;
 998
 999	device_set_wakeup_enable(bus->dev, enabled);
1000}
1001#endif
1002
1003static struct cfg80211_ops qtn_cfg80211_ops = {
1004	.add_virtual_intf	= qtnf_add_virtual_intf,
1005	.change_virtual_intf	= qtnf_change_virtual_intf,
1006	.del_virtual_intf	= qtnf_del_virtual_intf,
1007	.start_ap		= qtnf_start_ap,
1008	.change_beacon		= qtnf_change_beacon,
1009	.stop_ap		= qtnf_stop_ap,
1010	.set_wiphy_params	= qtnf_set_wiphy_params,
1011	.update_mgmt_frame_registrations =
1012		qtnf_update_mgmt_frame_registrations,
1013	.mgmt_tx		= qtnf_mgmt_tx,
1014	.change_station		= qtnf_change_station,
1015	.del_station		= qtnf_del_station,
1016	.get_station		= qtnf_get_station,
1017	.dump_station		= qtnf_dump_station,
1018	.add_key		= qtnf_add_key,
1019	.del_key		= qtnf_del_key,
1020	.set_default_key	= qtnf_set_default_key,
1021	.set_default_mgmt_key	= qtnf_set_default_mgmt_key,
1022	.scan			= qtnf_scan,
1023	.connect		= qtnf_connect,
1024	.external_auth		= qtnf_external_auth,
1025	.disconnect		= qtnf_disconnect,
1026	.dump_survey		= qtnf_dump_survey,
1027	.get_channel		= qtnf_get_channel,
1028	.channel_switch		= qtnf_channel_switch,
1029	.start_radar_detection	= qtnf_start_radar_detection,
1030	.set_mac_acl		= qtnf_set_mac_acl,
1031	.set_power_mgmt		= qtnf_set_power_mgmt,
1032	.get_tx_power		= qtnf_get_tx_power,
1033	.set_tx_power		= qtnf_set_tx_power,
1034	.update_owe_info	= qtnf_update_owe_info,
1035#ifdef CONFIG_PM
1036	.suspend		= qtnf_suspend,
1037	.resume			= qtnf_resume,
1038	.set_wakeup		= qtnf_set_wakeup,
1039#endif
1040};
1041
1042static void qtnf_cfg80211_reg_notifier(struct wiphy *wiphy,
1043				       struct regulatory_request *req)
1044{
1045	struct qtnf_wmac *mac = wiphy_priv(wiphy);
1046	enum nl80211_band band;
1047	int ret;
1048
1049	pr_debug("MAC%u: initiator=%d alpha=%c%c\n", mac->macid, req->initiator,
1050		 req->alpha2[0], req->alpha2[1]);
1051
1052	ret = qtnf_cmd_reg_notify(mac, req, qtnf_slave_radar_get(),
1053				  qtnf_dfs_offload_get());
1054	if (ret) {
1055		pr_err("MAC%u: failed to update region to %c%c: %d\n",
1056		       mac->macid, req->alpha2[0], req->alpha2[1], ret);
1057		return;
1058	}
1059
1060	for (band = 0; band < NUM_NL80211_BANDS; ++band) {
1061		if (!wiphy->bands[band])
1062			continue;
1063
1064		ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
1065		if (ret)
1066			pr_err("MAC%u: failed to update band %u\n",
1067			       mac->macid, band);
1068	}
1069}
1070
1071struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus,
1072				  struct platform_device *pdev)
1073{
1074	struct wiphy *wiphy;
1075
1076	if (qtnf_dfs_offload_get() &&
1077	    qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_DFS_OFFLOAD))
1078		qtn_cfg80211_ops.start_radar_detection = NULL;
1079
1080	if (!qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_PWR_MGMT))
1081		qtn_cfg80211_ops.set_power_mgmt	= NULL;
1082
1083	wiphy = wiphy_new(&qtn_cfg80211_ops, sizeof(struct qtnf_wmac));
1084	if (!wiphy)
1085		return NULL;
1086
1087	if (pdev)
1088		set_wiphy_dev(wiphy, &pdev->dev);
1089	else
1090		set_wiphy_dev(wiphy, bus->dev);
1091
1092	return wiphy;
1093}
1094
1095static int
1096qtnf_wiphy_setup_if_comb(struct wiphy *wiphy, struct qtnf_mac_info *mac_info)
1097{
1098	struct ieee80211_iface_combination *if_comb;
1099	size_t n_if_comb;
1100	u16 interface_modes = 0;
1101	size_t i, j;
1102
1103	if_comb = mac_info->if_comb;
1104	n_if_comb = mac_info->n_if_comb;
1105
1106	if (!if_comb || !n_if_comb)
1107		return -ENOENT;
1108
1109	for (i = 0; i < n_if_comb; i++) {
1110		if_comb[i].radar_detect_widths = mac_info->radar_detect_widths;
1111
1112		for (j = 0; j < if_comb[i].n_limits; j++)
1113			interface_modes |= if_comb[i].limits[j].types;
1114	}
1115
1116	wiphy->iface_combinations = if_comb;
1117	wiphy->n_iface_combinations = n_if_comb;
1118	wiphy->interface_modes = interface_modes;
1119
1120	return 0;
1121}
1122
1123int qtnf_wiphy_register(struct qtnf_hw_info *hw_info, struct qtnf_wmac *mac)
1124{
1125	struct wiphy *wiphy = priv_to_wiphy(mac);
1126	struct qtnf_mac_info *macinfo = &mac->macinfo;
1127	int ret;
1128	bool regdomain_is_known;
1129
1130	if (!wiphy) {
1131		pr_err("invalid wiphy pointer\n");
1132		return -EFAULT;
1133	}
1134
1135	wiphy->frag_threshold = macinfo->frag_thr;
1136	wiphy->rts_threshold = macinfo->rts_thr;
1137	wiphy->retry_short = macinfo->sretry_limit;
1138	wiphy->retry_long = macinfo->lretry_limit;
1139	wiphy->coverage_class = macinfo->coverage_class;
1140
1141	wiphy->max_scan_ssids =
1142		(macinfo->max_scan_ssids) ? macinfo->max_scan_ssids : 1;
1143	wiphy->max_scan_ie_len = QTNF_MAX_VSIE_LEN;
1144	wiphy->mgmt_stypes = qtnf_mgmt_stypes;
1145	wiphy->max_remain_on_channel_duration = 5000;
1146	wiphy->max_acl_mac_addrs = macinfo->max_acl_mac_addrs;
1147	wiphy->max_num_csa_counters = 2;
1148
1149	ret = qtnf_wiphy_setup_if_comb(wiphy, macinfo);
1150	if (ret)
1151		goto out;
1152
1153	/* Initialize cipher suits */
1154	wiphy->cipher_suites = qtnf_cipher_suites;
1155	wiphy->n_cipher_suites = ARRAY_SIZE(qtnf_cipher_suites);
1156	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1157	wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
1158			WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
1159			WIPHY_FLAG_AP_UAPSD |
1160			WIPHY_FLAG_HAS_CHANNEL_SWITCH |
1161			WIPHY_FLAG_4ADDR_STATION |
1162			WIPHY_FLAG_NETNS_OK;
1163	wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
1164
1165	if (qtnf_dfs_offload_get() &&
1166	    qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_DFS_OFFLOAD))
1167		wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD);
1168
1169	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_SCAN_DWELL))
1170		wiphy_ext_feature_set(wiphy,
1171				      NL80211_EXT_FEATURE_SET_SCAN_DWELL);
1172
1173	wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1174				    NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
1175
1176	wiphy->available_antennas_tx = macinfo->num_tx_chain;
1177	wiphy->available_antennas_rx = macinfo->num_rx_chain;
1178
1179	wiphy->max_ap_assoc_sta = macinfo->max_ap_assoc_sta;
1180	wiphy->ht_capa_mod_mask = &macinfo->ht_cap_mod_mask;
1181	wiphy->vht_capa_mod_mask = &macinfo->vht_cap_mod_mask;
1182
1183	ether_addr_copy(wiphy->perm_addr, mac->macaddr);
1184
1185	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_STA_INACT_TIMEOUT))
1186		wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
1187
1188	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_SCAN_RANDOM_MAC_ADDR))
1189		wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
1190
1191	if (!qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_OBSS_SCAN))
1192		wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
1193
1194	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_SAE))
1195		wiphy->features |= NL80211_FEATURE_SAE;
1196
1197#ifdef CONFIG_PM
1198	if (macinfo->wowlan)
1199		wiphy->wowlan = macinfo->wowlan;
1200#endif
1201
1202	regdomain_is_known = isalpha(mac->rd->alpha2[0]) &&
1203				isalpha(mac->rd->alpha2[1]);
1204
1205	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_REG_UPDATE)) {
1206		wiphy->reg_notifier = qtnf_cfg80211_reg_notifier;
1207
1208		if (mac->rd->alpha2[0] == '9' && mac->rd->alpha2[1] == '9') {
1209			wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
1210				REGULATORY_STRICT_REG;
1211			wiphy_apply_custom_regulatory(wiphy, mac->rd);
1212		} else if (regdomain_is_known) {
1213			wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
1214		}
1215	} else {
1216		wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
1217	}
1218
1219	if (mac->macinfo.extended_capabilities_len) {
1220		wiphy->extended_capabilities =
1221			mac->macinfo.extended_capabilities;
1222		wiphy->extended_capabilities_mask =
1223			mac->macinfo.extended_capabilities_mask;
1224		wiphy->extended_capabilities_len =
1225			mac->macinfo.extended_capabilities_len;
1226	}
1227
1228	strscpy(wiphy->fw_version, hw_info->fw_version,
1229		sizeof(wiphy->fw_version));
1230	wiphy->hw_version = hw_info->hw_version;
1231
1232	ret = wiphy_register(wiphy);
1233	if (ret < 0)
1234		goto out;
1235
1236	if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED)
1237		ret = regulatory_set_wiphy_regd(wiphy, mac->rd);
1238	else if (regdomain_is_known)
1239		ret = regulatory_hint(wiphy, mac->rd->alpha2);
1240
1241out:
1242	return ret;
1243}
1244
1245void qtnf_netdev_updown(struct net_device *ndev, bool up)
1246{
1247	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1248
1249	if (qtnf_cmd_send_updown_intf(vif, up))
1250		pr_err("failed to send %s command to VIF%u.%u\n",
1251		       up ? "UP" : "DOWN", vif->mac->macid, vif->vifid);
1252}
1253
1254void qtnf_virtual_intf_cleanup(struct net_device *ndev)
1255{
1256	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1257	struct qtnf_wmac *mac = wiphy_priv(vif->wdev.wiphy);
1258
1259	if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
1260		qtnf_disconnect(vif->wdev.wiphy, ndev,
1261				WLAN_REASON_DEAUTH_LEAVING);
1262
1263	qtnf_scan_done(mac, true);
1264}
1265
1266void qtnf_cfg80211_vif_reset(struct qtnf_vif *vif)
1267{
1268	if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
1269		cfg80211_disconnected(vif->netdev, WLAN_REASON_DEAUTH_LEAVING,
1270				      NULL, 0, 1, GFP_KERNEL);
1271
1272	cfg80211_shutdown_all_interfaces(vif->wdev.wiphy);
1273}
1274
1275void qtnf_band_init_rates(struct ieee80211_supported_band *band)
1276{
1277	switch (band->band) {
1278	case NL80211_BAND_2GHZ:
1279		band->bitrates = qtnf_rates_2g;
1280		band->n_bitrates = ARRAY_SIZE(qtnf_rates_2g);
1281		break;
1282	case NL80211_BAND_5GHZ:
1283		band->bitrates = qtnf_rates_5g;
1284		band->n_bitrates = ARRAY_SIZE(qtnf_rates_5g);
1285		break;
1286	default:
1287		band->bitrates = NULL;
1288		band->n_bitrates = 0;
1289		break;
1290	}
1291}
~/ Read-only file preview.