1ff233cb5SSergey Matyukevich // SPDX-License-Identifier: GPL-2.0+
2ff233cb5SSergey Matyukevich /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
398f44cb0SIgor Mitsyanko 
498f44cb0SIgor Mitsyanko #include <linux/kernel.h>
598f44cb0SIgor Mitsyanko #include <linux/etherdevice.h>
698f44cb0SIgor Mitsyanko #include <linux/vmalloc.h>
798f44cb0SIgor Mitsyanko #include <linux/ieee80211.h>
898f44cb0SIgor Mitsyanko #include <net/cfg80211.h>
998f44cb0SIgor Mitsyanko #include <net/netlink.h>
1098f44cb0SIgor Mitsyanko 
1198f44cb0SIgor Mitsyanko #include "cfg80211.h"
1298f44cb0SIgor Mitsyanko #include "commands.h"
1398f44cb0SIgor Mitsyanko #include "core.h"
1498f44cb0SIgor Mitsyanko #include "util.h"
1598f44cb0SIgor Mitsyanko #include "bus.h"
1698f44cb0SIgor Mitsyanko 
1798f44cb0SIgor Mitsyanko /* Supported rates to be advertised to the cfg80211 */
1898f44cb0SIgor Mitsyanko static struct ieee80211_rate qtnf_rates_2g[] = {
1998f44cb0SIgor Mitsyanko 	{.bitrate = 10, .hw_value = 2, },
2098f44cb0SIgor Mitsyanko 	{.bitrate = 20, .hw_value = 4, },
2198f44cb0SIgor Mitsyanko 	{.bitrate = 55, .hw_value = 11, },
2298f44cb0SIgor Mitsyanko 	{.bitrate = 110, .hw_value = 22, },
2398f44cb0SIgor Mitsyanko 	{.bitrate = 60, .hw_value = 12, },
2498f44cb0SIgor Mitsyanko 	{.bitrate = 90, .hw_value = 18, },
2598f44cb0SIgor Mitsyanko 	{.bitrate = 120, .hw_value = 24, },
2698f44cb0SIgor Mitsyanko 	{.bitrate = 180, .hw_value = 36, },
2798f44cb0SIgor Mitsyanko 	{.bitrate = 240, .hw_value = 48, },
2898f44cb0SIgor Mitsyanko 	{.bitrate = 360, .hw_value = 72, },
2998f44cb0SIgor Mitsyanko 	{.bitrate = 480, .hw_value = 96, },
3098f44cb0SIgor Mitsyanko 	{.bitrate = 540, .hw_value = 108, },
3198f44cb0SIgor Mitsyanko };
3298f44cb0SIgor Mitsyanko 
3398f44cb0SIgor Mitsyanko /* Supported rates to be advertised to the cfg80211 */
3498f44cb0SIgor Mitsyanko static struct ieee80211_rate qtnf_rates_5g[] = {
3598f44cb0SIgor Mitsyanko 	{.bitrate = 60, .hw_value = 12, },
3698f44cb0SIgor Mitsyanko 	{.bitrate = 90, .hw_value = 18, },
3798f44cb0SIgor Mitsyanko 	{.bitrate = 120, .hw_value = 24, },
3898f44cb0SIgor Mitsyanko 	{.bitrate = 180, .hw_value = 36, },
3998f44cb0SIgor Mitsyanko 	{.bitrate = 240, .hw_value = 48, },
4098f44cb0SIgor Mitsyanko 	{.bitrate = 360, .hw_value = 72, },
4198f44cb0SIgor Mitsyanko 	{.bitrate = 480, .hw_value = 96, },
4298f44cb0SIgor Mitsyanko 	{.bitrate = 540, .hw_value = 108, },
4398f44cb0SIgor Mitsyanko };
4498f44cb0SIgor Mitsyanko 
4598f44cb0SIgor Mitsyanko /* Supported crypto cipher suits to be advertised to cfg80211 */
4698f44cb0SIgor Mitsyanko static const u32 qtnf_cipher_suites[] = {
4798f44cb0SIgor Mitsyanko 	WLAN_CIPHER_SUITE_TKIP,
4898f44cb0SIgor Mitsyanko 	WLAN_CIPHER_SUITE_CCMP,
4998f44cb0SIgor Mitsyanko 	WLAN_CIPHER_SUITE_AES_CMAC,
5098f44cb0SIgor Mitsyanko };
5198f44cb0SIgor Mitsyanko 
5298f44cb0SIgor Mitsyanko /* Supported mgmt frame types to be advertised to cfg80211 */
5398f44cb0SIgor Mitsyanko static const struct ieee80211_txrx_stypes
5498f44cb0SIgor Mitsyanko qtnf_mgmt_stypes[NUM_NL80211_IFTYPES] = {
5598f44cb0SIgor Mitsyanko 	[NL80211_IFTYPE_STATION] = {
5647b08e75SSergey Matyukevich 		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5747b08e75SSergey Matyukevich 		      BIT(IEEE80211_STYPE_AUTH >> 4),
5898f44cb0SIgor Mitsyanko 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5947b08e75SSergey Matyukevich 		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
6047b08e75SSergey Matyukevich 		      BIT(IEEE80211_STYPE_AUTH >> 4),
6198f44cb0SIgor Mitsyanko 	},
6298f44cb0SIgor Mitsyanko 	[NL80211_IFTYPE_AP] = {
63b3860e7aSSergey Matyukevich 		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
64b3860e7aSSergey Matyukevich 		      BIT(IEEE80211_STYPE_AUTH >> 4),
6598f44cb0SIgor Mitsyanko 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
663dd06cecSSergey Matyukevich 		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
673dd06cecSSergey Matyukevich 		      BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
683dd06cecSSergey Matyukevich 		      BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
693dd06cecSSergey Matyukevich 		      BIT(IEEE80211_STYPE_AUTH >> 4),
7098f44cb0SIgor Mitsyanko 	},
7198f44cb0SIgor Mitsyanko };
7298f44cb0SIgor Mitsyanko 
7398f44cb0SIgor Mitsyanko static int
qtnf_validate_iface_combinations(struct wiphy * wiphy,struct qtnf_vif * change_vif,enum nl80211_iftype new_type)7401efff52SSergey Matyukevich qtnf_validate_iface_combinations(struct wiphy *wiphy,
7501efff52SSergey Matyukevich 				 struct qtnf_vif *change_vif,
7601efff52SSergey Matyukevich 				 enum nl80211_iftype new_type)
7701efff52SSergey Matyukevich {
7801efff52SSergey Matyukevich 	struct qtnf_wmac *mac;
7901efff52SSergey Matyukevich 	struct qtnf_vif *vif;
8001efff52SSergey Matyukevich 	int i;
8101efff52SSergey Matyukevich 	int ret = 0;
8201efff52SSergey Matyukevich 	struct iface_combination_params params = {
8301efff52SSergey Matyukevich 		.num_different_channels = 1,
8401efff52SSergey Matyukevich 	};
8501efff52SSergey Matyukevich 
8601efff52SSergey Matyukevich 	mac = wiphy_priv(wiphy);
8701efff52SSergey Matyukevich 	if (!mac)
8801efff52SSergey Matyukevich 		return -EFAULT;
8901efff52SSergey Matyukevich 
9001efff52SSergey Matyukevich 	for (i = 0; i < QTNF_MAX_INTF; i++) {
9101efff52SSergey Matyukevich 		vif = &mac->iflist[i];
9201efff52SSergey Matyukevich 		if (vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
9301efff52SSergey Matyukevich 			params.iftype_num[vif->wdev.iftype]++;
9401efff52SSergey Matyukevich 	}
9501efff52SSergey Matyukevich 
9601efff52SSergey Matyukevich 	if (change_vif) {
9701efff52SSergey Matyukevich 		params.iftype_num[new_type]++;
9801efff52SSergey Matyukevich 		params.iftype_num[change_vif->wdev.iftype]--;
9901efff52SSergey Matyukevich 	} else {
10001efff52SSergey Matyukevich 		params.iftype_num[new_type]++;
10101efff52SSergey Matyukevich 	}
10201efff52SSergey Matyukevich 
10301efff52SSergey Matyukevich 	ret = cfg80211_check_combinations(wiphy, &params);
10401efff52SSergey Matyukevich 
1052d83dddfSDmitry Lebed 	if (ret)
1062d83dddfSDmitry Lebed 		return ret;
1072d83dddfSDmitry Lebed 
1082d83dddfSDmitry Lebed 	/* Check repeater interface combination: primary VIF should be STA only.
1092d83dddfSDmitry Lebed 	 * STA (primary) + AP (secondary) is OK.
1102d83dddfSDmitry Lebed 	 * AP (primary) + STA (secondary) is not supported.
1112d83dddfSDmitry Lebed 	 */
1122d83dddfSDmitry Lebed 	vif = qtnf_mac_get_base_vif(mac);
1132d83dddfSDmitry Lebed 	if (vif && vif->wdev.iftype == NL80211_IFTYPE_AP &&
1142d83dddfSDmitry Lebed 	    vif != change_vif && new_type == NL80211_IFTYPE_STATION) {
1152d83dddfSDmitry Lebed 		ret = -EINVAL;
1162d83dddfSDmitry Lebed 		pr_err("MAC%u invalid combination: AP as primary repeater interface is not supported\n",
1172d83dddfSDmitry Lebed 		       mac->macid);
1182d83dddfSDmitry Lebed 	}
1192d83dddfSDmitry Lebed 
12001efff52SSergey Matyukevich 	return ret;
12101efff52SSergey Matyukevich }
12201efff52SSergey Matyukevich 
12301efff52SSergey Matyukevich static int
qtnf_change_virtual_intf(struct wiphy * wiphy,struct net_device * dev,enum nl80211_iftype type,struct vif_params * params)12498f44cb0SIgor Mitsyanko qtnf_change_virtual_intf(struct wiphy *wiphy,
12598f44cb0SIgor Mitsyanko 			 struct net_device *dev,
12698f44cb0SIgor Mitsyanko 			 enum nl80211_iftype type,
12798f44cb0SIgor Mitsyanko 			 struct vif_params *params)
12898f44cb0SIgor Mitsyanko {
12998f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
130de624a35SSergey Matyukevich 	u8 *mac_addr = NULL;
131de624a35SSergey Matyukevich 	int use4addr = 0;
13298f44cb0SIgor Mitsyanko 	int ret;
13398f44cb0SIgor Mitsyanko 
13401efff52SSergey Matyukevich 	ret = qtnf_validate_iface_combinations(wiphy, vif, type);
13501efff52SSergey Matyukevich 	if (ret) {
13601efff52SSergey Matyukevich 		pr_err("VIF%u.%u combination check: failed to set type %d\n",
13701efff52SSergey Matyukevich 		       vif->mac->macid, vif->vifid, type);
13801efff52SSergey Matyukevich 		return ret;
13901efff52SSergey Matyukevich 	}
14001efff52SSergey Matyukevich 
141de624a35SSergey Matyukevich 	if (params) {
14298f44cb0SIgor Mitsyanko 		mac_addr = params->macaddr;
143de624a35SSergey Matyukevich 		use4addr = params->use_4addr;
144de624a35SSergey Matyukevich 	}
14598f44cb0SIgor Mitsyanko 
14698f44cb0SIgor Mitsyanko 	qtnf_scan_done(vif->mac, true);
14798f44cb0SIgor Mitsyanko 
148de624a35SSergey Matyukevich 	ret = qtnf_cmd_send_change_intf_type(vif, type, use4addr, mac_addr);
14998f44cb0SIgor Mitsyanko 	if (ret) {
150c6ed298fSSergey Matyukevich 		pr_err("VIF%u.%u: failed to change type to %d\n",
151c6ed298fSSergey Matyukevich 		       vif->mac->macid, vif->vifid, type);
15298f44cb0SIgor Mitsyanko 		return ret;
15398f44cb0SIgor Mitsyanko 	}
15498f44cb0SIgor Mitsyanko 
15598f44cb0SIgor Mitsyanko 	vif->wdev.iftype = type;
15698f44cb0SIgor Mitsyanko 	return 0;
15798f44cb0SIgor Mitsyanko }
15898f44cb0SIgor Mitsyanko 
qtnf_del_virtual_intf(struct wiphy * wiphy,struct wireless_dev * wdev)15998f44cb0SIgor Mitsyanko int qtnf_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
16098f44cb0SIgor Mitsyanko {
16198f44cb0SIgor Mitsyanko 	struct net_device *netdev =  wdev->netdev;
16298f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
163bc70732fSIgor Mitsyanko 	struct sk_buff *skb;
16498f44cb0SIgor Mitsyanko 
16598f44cb0SIgor Mitsyanko 	if (WARN_ON(!netdev))
16698f44cb0SIgor Mitsyanko 		return -EFAULT;
16798f44cb0SIgor Mitsyanko 
16898f44cb0SIgor Mitsyanko 	vif = qtnf_netdev_get_priv(wdev->netdev);
16998f44cb0SIgor Mitsyanko 
170a715b3a0SSergey Matyukevich 	qtnf_scan_done(vif->mac, true);
171a715b3a0SSergey Matyukevich 
17298f44cb0SIgor Mitsyanko 	/* Stop data */
17398f44cb0SIgor Mitsyanko 	netif_tx_stop_all_queues(netdev);
17498f44cb0SIgor Mitsyanko 	if (netif_carrier_ok(netdev))
17598f44cb0SIgor Mitsyanko 		netif_carrier_off(netdev);
17698f44cb0SIgor Mitsyanko 
177bc70732fSIgor Mitsyanko 	while ((skb = skb_dequeue(&vif->high_pri_tx_queue)))
178bc70732fSIgor Mitsyanko 		dev_kfree_skb_any(skb);
179bc70732fSIgor Mitsyanko 
180bc70732fSIgor Mitsyanko 	cancel_work_sync(&vif->high_pri_tx_work);
181bc70732fSIgor Mitsyanko 
18298f44cb0SIgor Mitsyanko 	if (netdev->reg_state == NETREG_REGISTERED)
1832fe8ef10SJohannes Berg 		cfg80211_unregister_netdevice(netdev);
18498f44cb0SIgor Mitsyanko 
18587affddeSVasily Ulyanov 	if (qtnf_cmd_send_del_intf(vif))
18687affddeSVasily Ulyanov 		pr_err("VIF%u.%u: failed to delete VIF\n", vif->mac->macid,
18787affddeSVasily Ulyanov 		       vif->vifid);
18887affddeSVasily Ulyanov 
18998f44cb0SIgor Mitsyanko 	vif->netdev->ieee80211_ptr = NULL;
19098f44cb0SIgor Mitsyanko 	vif->netdev = NULL;
19198f44cb0SIgor Mitsyanko 	vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
19298f44cb0SIgor Mitsyanko 
19398f44cb0SIgor Mitsyanko 	return 0;
19498f44cb0SIgor Mitsyanko }
19598f44cb0SIgor Mitsyanko 
qtnf_add_virtual_intf(struct wiphy * wiphy,const char * name,unsigned char name_assign_t,enum nl80211_iftype type,struct vif_params * params)19698f44cb0SIgor Mitsyanko static struct wireless_dev *qtnf_add_virtual_intf(struct wiphy *wiphy,
19798f44cb0SIgor Mitsyanko 						  const char *name,
19898f44cb0SIgor Mitsyanko 						  unsigned char name_assign_t,
19998f44cb0SIgor Mitsyanko 						  enum nl80211_iftype type,
20098f44cb0SIgor Mitsyanko 						  struct vif_params *params)
20198f44cb0SIgor Mitsyanko {
20298f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac;
20398f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
20498f44cb0SIgor Mitsyanko 	u8 *mac_addr = NULL;
205de624a35SSergey Matyukevich 	int use4addr = 0;
20601efff52SSergey Matyukevich 	int ret;
20798f44cb0SIgor Mitsyanko 
20898f44cb0SIgor Mitsyanko 	mac = wiphy_priv(wiphy);
20998f44cb0SIgor Mitsyanko 
21098f44cb0SIgor Mitsyanko 	if (!mac)
21198f44cb0SIgor Mitsyanko 		return ERR_PTR(-EFAULT);
21298f44cb0SIgor Mitsyanko 
21301efff52SSergey Matyukevich 	ret = qtnf_validate_iface_combinations(wiphy, NULL, type);
21401efff52SSergey Matyukevich 	if (ret) {
21501efff52SSergey Matyukevich 		pr_err("MAC%u invalid combination: failed to add type %d\n",
21601efff52SSergey Matyukevich 		       mac->macid, type);
21701efff52SSergey Matyukevich 		return ERR_PTR(ret);
21801efff52SSergey Matyukevich 	}
21901efff52SSergey Matyukevich 
22098f44cb0SIgor Mitsyanko 	switch (type) {
22198f44cb0SIgor Mitsyanko 	case NL80211_IFTYPE_STATION:
22298f44cb0SIgor Mitsyanko 	case NL80211_IFTYPE_AP:
22398f44cb0SIgor Mitsyanko 		vif = qtnf_mac_get_free_vif(mac);
22498f44cb0SIgor Mitsyanko 		if (!vif) {
22598f44cb0SIgor Mitsyanko 			pr_err("MAC%u: no free VIF available\n", mac->macid);
22698f44cb0SIgor Mitsyanko 			return ERR_PTR(-EFAULT);
22798f44cb0SIgor Mitsyanko 		}
22898f44cb0SIgor Mitsyanko 
22998f44cb0SIgor Mitsyanko 		eth_zero_addr(vif->mac_addr);
2309a3beeb5SSergey Matyukevich 		eth_zero_addr(vif->bssid);
23198f44cb0SIgor Mitsyanko 		vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
2329a3beeb5SSergey Matyukevich 		memset(&vif->wdev, 0, sizeof(vif->wdev));
23398f44cb0SIgor Mitsyanko 		vif->wdev.wiphy = wiphy;
23498f44cb0SIgor Mitsyanko 		vif->wdev.iftype = type;
23598f44cb0SIgor Mitsyanko 		break;
23698f44cb0SIgor Mitsyanko 	default:
23798f44cb0SIgor Mitsyanko 		pr_err("MAC%u: unsupported IF type %d\n", mac->macid, type);
23898f44cb0SIgor Mitsyanko 		return ERR_PTR(-ENOTSUPP);
23998f44cb0SIgor Mitsyanko 	}
24098f44cb0SIgor Mitsyanko 
241de624a35SSergey Matyukevich 	if (params) {
24298f44cb0SIgor Mitsyanko 		mac_addr = params->macaddr;
243de624a35SSergey Matyukevich 		use4addr = params->use_4addr;
244de624a35SSergey Matyukevich 	}
24598f44cb0SIgor Mitsyanko 
246de624a35SSergey Matyukevich 	ret = qtnf_cmd_send_add_intf(vif, type, use4addr, mac_addr);
247c6ed298fSSergey Matyukevich 	if (ret) {
248c6ed298fSSergey Matyukevich 		pr_err("VIF%u.%u: failed to add VIF %pM\n",
249c6ed298fSSergey Matyukevich 		       mac->macid, vif->vifid, mac_addr);
25098f44cb0SIgor Mitsyanko 		goto err_cmd;
25198f44cb0SIgor Mitsyanko 	}
25298f44cb0SIgor Mitsyanko 
25398f44cb0SIgor Mitsyanko 	if (!is_valid_ether_addr(vif->mac_addr)) {
25498f44cb0SIgor Mitsyanko 		pr_err("VIF%u.%u: FW reported bad MAC: %pM\n",
25598f44cb0SIgor Mitsyanko 		       mac->macid, vif->vifid, vif->mac_addr);
256c6ed298fSSergey Matyukevich 		ret = -EINVAL;
25745028223SIgor Mitsyanko 		goto error_del_vif;
25898f44cb0SIgor Mitsyanko 	}
25998f44cb0SIgor Mitsyanko 
260c6ed298fSSergey Matyukevich 	ret = qtnf_core_net_attach(mac, vif, name, name_assign_t);
261c6ed298fSSergey Matyukevich 	if (ret) {
26298f44cb0SIgor Mitsyanko 		pr_err("VIF%u.%u: failed to attach netdev\n", mac->macid,
26398f44cb0SIgor Mitsyanko 		       vif->vifid);
26445028223SIgor Mitsyanko 		goto error_del_vif;
26598f44cb0SIgor Mitsyanko 	}
26698f44cb0SIgor Mitsyanko 
267310cd5ddSIgor Mitsyanko 	if (qtnf_hwcap_is_set(&mac->bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE)) {
268decfc5c7SIgor Mitsyanko 		ret = qtnf_cmd_netdev_changeupper(vif, vif->netdev->ifindex);
269decfc5c7SIgor Mitsyanko 		if (ret) {
2702fe8ef10SJohannes Berg 			cfg80211_unregister_netdevice(vif->netdev);
271decfc5c7SIgor Mitsyanko 			vif->netdev = NULL;
272decfc5c7SIgor Mitsyanko 			goto error_del_vif;
273decfc5c7SIgor Mitsyanko 		}
274decfc5c7SIgor Mitsyanko 	}
275decfc5c7SIgor Mitsyanko 
27698f44cb0SIgor Mitsyanko 	vif->wdev.netdev = vif->netdev;
27798f44cb0SIgor Mitsyanko 	return &vif->wdev;
27898f44cb0SIgor Mitsyanko 
27945028223SIgor Mitsyanko error_del_vif:
28098f44cb0SIgor Mitsyanko 	qtnf_cmd_send_del_intf(vif);
28198f44cb0SIgor Mitsyanko err_cmd:
28298f44cb0SIgor Mitsyanko 	vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
28398f44cb0SIgor Mitsyanko 
284c6ed298fSSergey Matyukevich 	return ERR_PTR(ret);
28598f44cb0SIgor Mitsyanko }
28698f44cb0SIgor Mitsyanko 
qtnf_mgmt_set_appie(struct qtnf_vif * vif,const struct cfg80211_beacon_data * info)28798f44cb0SIgor Mitsyanko static int qtnf_mgmt_set_appie(struct qtnf_vif *vif,
28898f44cb0SIgor Mitsyanko 			       const struct cfg80211_beacon_data *info)
28998f44cb0SIgor Mitsyanko {
29098f44cb0SIgor Mitsyanko 	int ret = 0;
29198f44cb0SIgor Mitsyanko 
29298f44cb0SIgor Mitsyanko 	if (!info->beacon_ies || !info->beacon_ies_len) {
2934d1f0fabSIgor Mitsyanko 		ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
29498f44cb0SIgor Mitsyanko 						   NULL, 0);
29598f44cb0SIgor Mitsyanko 	} else {
2964d1f0fabSIgor Mitsyanko 		ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
29798f44cb0SIgor Mitsyanko 						   info->beacon_ies,
29898f44cb0SIgor Mitsyanko 						   info->beacon_ies_len);
29998f44cb0SIgor Mitsyanko 	}
30098f44cb0SIgor Mitsyanko 
30198f44cb0SIgor Mitsyanko 	if (ret)
30298f44cb0SIgor Mitsyanko 		goto out;
30398f44cb0SIgor Mitsyanko 
30498f44cb0SIgor Mitsyanko 	if (!info->proberesp_ies || !info->proberesp_ies_len) {
30598f44cb0SIgor Mitsyanko 		ret = qtnf_cmd_send_mgmt_set_appie(vif,
3064d1f0fabSIgor Mitsyanko 						   QLINK_IE_SET_PROBE_RESP_IES,
30798f44cb0SIgor Mitsyanko 						   NULL, 0);
30898f44cb0SIgor Mitsyanko 	} else {
30998f44cb0SIgor Mitsyanko 		ret = qtnf_cmd_send_mgmt_set_appie(vif,
3104d1f0fabSIgor Mitsyanko 						   QLINK_IE_SET_PROBE_RESP_IES,
31198f44cb0SIgor Mitsyanko 						   info->proberesp_ies,
31298f44cb0SIgor Mitsyanko 						   info->proberesp_ies_len);
31398f44cb0SIgor Mitsyanko 	}
31498f44cb0SIgor Mitsyanko 
31598f44cb0SIgor Mitsyanko 	if (ret)
31698f44cb0SIgor Mitsyanko 		goto out;
31798f44cb0SIgor Mitsyanko 
31898f44cb0SIgor Mitsyanko 	if (!info->assocresp_ies || !info->assocresp_ies_len) {
31998f44cb0SIgor Mitsyanko 		ret = qtnf_cmd_send_mgmt_set_appie(vif,
3204d1f0fabSIgor Mitsyanko 						   QLINK_IE_SET_ASSOC_RESP,
32198f44cb0SIgor Mitsyanko 						   NULL, 0);
32298f44cb0SIgor Mitsyanko 	} else {
32398f44cb0SIgor Mitsyanko 		ret = qtnf_cmd_send_mgmt_set_appie(vif,
3244d1f0fabSIgor Mitsyanko 						   QLINK_IE_SET_ASSOC_RESP,
32598f44cb0SIgor Mitsyanko 						   info->assocresp_ies,
32698f44cb0SIgor Mitsyanko 						   info->assocresp_ies_len);
32798f44cb0SIgor Mitsyanko 	}
32898f44cb0SIgor Mitsyanko 
32998f44cb0SIgor Mitsyanko out:
33098f44cb0SIgor Mitsyanko 	return ret;
33198f44cb0SIgor Mitsyanko }
33298f44cb0SIgor Mitsyanko 
qtnf_change_beacon(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_beacon_data * info)33398f44cb0SIgor Mitsyanko static int qtnf_change_beacon(struct wiphy *wiphy, struct net_device *dev,
33498f44cb0SIgor Mitsyanko 			      struct cfg80211_beacon_data *info)
33598f44cb0SIgor Mitsyanko {
33698f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
33798f44cb0SIgor Mitsyanko 
33898f44cb0SIgor Mitsyanko 	return qtnf_mgmt_set_appie(vif, info);
33998f44cb0SIgor Mitsyanko }
34098f44cb0SIgor Mitsyanko 
qtnf_start_ap(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_settings * settings)34198f44cb0SIgor Mitsyanko static int qtnf_start_ap(struct wiphy *wiphy, struct net_device *dev,
34298f44cb0SIgor Mitsyanko 			 struct cfg80211_ap_settings *settings)
34398f44cb0SIgor Mitsyanko {
34498f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
34598f44cb0SIgor Mitsyanko 	int ret;
34698f44cb0SIgor Mitsyanko 
34717011da0SIgor Mitsyanko 	ret = qtnf_cmd_send_start_ap(vif, settings);
348d7b80052SIgor Mitsyanko 	if (ret)
34998f44cb0SIgor Mitsyanko 		pr_err("VIF%u.%u: failed to start AP\n", vif->mac->macid,
35098f44cb0SIgor Mitsyanko 		       vif->vifid);
35198f44cb0SIgor Mitsyanko 
35298f44cb0SIgor Mitsyanko 	return ret;
35398f44cb0SIgor Mitsyanko }
35498f44cb0SIgor Mitsyanko 
qtnf_stop_ap(struct wiphy * wiphy,struct net_device * dev,unsigned int link_id)3557b0a0e3cSJohannes Berg static int qtnf_stop_ap(struct wiphy *wiphy, struct net_device *dev,
3567b0a0e3cSJohannes Berg 			unsigned int link_id)
35798f44cb0SIgor Mitsyanko {
35898f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
35998f44cb0SIgor Mitsyanko 	int ret;
36098f44cb0SIgor Mitsyanko 
361a715b3a0SSergey Matyukevich 	qtnf_scan_done(vif->mac, true);
362a715b3a0SSergey Matyukevich 
36398f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_stop_ap(vif);
364c6ed298fSSergey Matyukevich 	if (ret)
36598f44cb0SIgor Mitsyanko 		pr_err("VIF%u.%u: failed to stop AP operation in FW\n",
36698f44cb0SIgor Mitsyanko 		       vif->mac->macid, vif->vifid);
36798f44cb0SIgor Mitsyanko 
36898f44cb0SIgor Mitsyanko 	netif_carrier_off(vif->netdev);
36998f44cb0SIgor Mitsyanko 
37098f44cb0SIgor Mitsyanko 	return ret;
37198f44cb0SIgor Mitsyanko }
37298f44cb0SIgor Mitsyanko 
qtnf_set_wiphy_params(struct wiphy * wiphy,u32 changed)37398f44cb0SIgor Mitsyanko static int qtnf_set_wiphy_params(struct wiphy *wiphy, u32 changed)
37498f44cb0SIgor Mitsyanko {
37598f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
37698f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
37798f44cb0SIgor Mitsyanko 	int ret;
37898f44cb0SIgor Mitsyanko 
37998f44cb0SIgor Mitsyanko 	vif = qtnf_mac_get_base_vif(mac);
38098f44cb0SIgor Mitsyanko 	if (!vif) {
38198f44cb0SIgor Mitsyanko 		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
38298f44cb0SIgor Mitsyanko 		return -EFAULT;
38398f44cb0SIgor Mitsyanko 	}
38498f44cb0SIgor Mitsyanko 
38598f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_update_phy_params(mac, changed);
38698f44cb0SIgor Mitsyanko 	if (ret)
38798f44cb0SIgor Mitsyanko 		pr_err("MAC%u: failed to update PHY params\n", mac->macid);
38898f44cb0SIgor Mitsyanko 
38998f44cb0SIgor Mitsyanko 	return ret;
39098f44cb0SIgor Mitsyanko }
39198f44cb0SIgor Mitsyanko 
39298f44cb0SIgor Mitsyanko static void
qtnf_update_mgmt_frame_registrations(struct wiphy * wiphy,struct wireless_dev * wdev,struct mgmt_frame_regs * upd)3936cd536feSJohannes Berg qtnf_update_mgmt_frame_registrations(struct wiphy *wiphy,
3946cd536feSJohannes Berg 				     struct wireless_dev *wdev,
3956cd536feSJohannes Berg 				     struct mgmt_frame_regs *upd)
39698f44cb0SIgor Mitsyanko {
39798f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
3986cd536feSJohannes Berg 	u16 new_mask = upd->interface_stypes;
3996cd536feSJohannes Berg 	u16 old_mask = vif->mgmt_frames_bitmask;
4006cd536feSJohannes Berg 	static const struct {
4016cd536feSJohannes Berg 		u16 mask, qlink_type;
4026cd536feSJohannes Berg 	} updates[] = {
4036cd536feSJohannes Berg 		{
4046cd536feSJohannes Berg 			.mask = BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
4056cd536feSJohannes Berg 				BIT(IEEE80211_STYPE_ASSOC_REQ >> 4),
4066cd536feSJohannes Berg 			.qlink_type = QLINK_MGMT_FRAME_ASSOC_REQ,
4076cd536feSJohannes Berg 		},
4086cd536feSJohannes Berg 		{
4096cd536feSJohannes Berg 			.mask = BIT(IEEE80211_STYPE_AUTH >> 4),
4106cd536feSJohannes Berg 			.qlink_type = QLINK_MGMT_FRAME_AUTH,
4116cd536feSJohannes Berg 		},
4126cd536feSJohannes Berg 		{
4136cd536feSJohannes Berg 			.mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
4146cd536feSJohannes Berg 			.qlink_type = QLINK_MGMT_FRAME_PROBE_REQ,
4156cd536feSJohannes Berg 		},
4166cd536feSJohannes Berg 		{
4176cd536feSJohannes Berg 			.mask = BIT(IEEE80211_STYPE_ACTION >> 4),
4186cd536feSJohannes Berg 			.qlink_type = QLINK_MGMT_FRAME_ACTION,
4196cd536feSJohannes Berg 		},
4206cd536feSJohannes Berg 	};
4216cd536feSJohannes Berg 	unsigned int i;
42298f44cb0SIgor Mitsyanko 
4236cd536feSJohannes Berg 	if (new_mask == old_mask)
42498f44cb0SIgor Mitsyanko 		return;
42598f44cb0SIgor Mitsyanko 
4266cd536feSJohannes Berg 	for (i = 0; i < ARRAY_SIZE(updates); i++) {
4276cd536feSJohannes Berg 		u16 mask = updates[i].mask;
4286cd536feSJohannes Berg 		u16 qlink_frame_type = updates[i].qlink_type;
4296cd536feSJohannes Berg 		bool reg;
43098f44cb0SIgor Mitsyanko 
4316cd536feSJohannes Berg 		/* the ! are here due to the assoc/reassoc merge */
4326cd536feSJohannes Berg 		if (!(new_mask & mask) == !(old_mask & mask))
4336cd536feSJohannes Berg 			continue;
4346cd536feSJohannes Berg 
4356cd536feSJohannes Berg 		reg = new_mask & mask;
4366cd536feSJohannes Berg 
4376cd536feSJohannes Berg 		if (qtnf_cmd_send_register_mgmt(vif, qlink_frame_type, reg))
4386cd536feSJohannes Berg 			pr_warn("VIF%u.%u: failed to %sregister qlink frame type 0x%x\n",
43998f44cb0SIgor Mitsyanko 				vif->mac->macid, vif->vifid, reg ? "" : "un",
4406cd536feSJohannes Berg 				qlink_frame_type);
44198f44cb0SIgor Mitsyanko 	}
44298f44cb0SIgor Mitsyanko 
44398f44cb0SIgor Mitsyanko 	vif->mgmt_frames_bitmask = new_mask;
44498f44cb0SIgor Mitsyanko }
44598f44cb0SIgor Mitsyanko 
44698f44cb0SIgor Mitsyanko static int
qtnf_mgmt_tx(struct wiphy * wiphy,struct wireless_dev * wdev,struct cfg80211_mgmt_tx_params * params,u64 * cookie)44798f44cb0SIgor Mitsyanko qtnf_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
44898f44cb0SIgor Mitsyanko 	     struct cfg80211_mgmt_tx_params *params, u64 *cookie)
44998f44cb0SIgor Mitsyanko {
45098f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
45198f44cb0SIgor Mitsyanko 	const struct ieee80211_mgmt *mgmt_frame = (void *)params->buf;
452*a251c17aSJason A. Donenfeld 	u32 short_cookie = get_random_u32();
45398f44cb0SIgor Mitsyanko 	u16 flags = 0;
454e6e594afSIgor Mitsyanko 	u16 freq;
45598f44cb0SIgor Mitsyanko 
45698f44cb0SIgor Mitsyanko 	*cookie = short_cookie;
45798f44cb0SIgor Mitsyanko 
45898f44cb0SIgor Mitsyanko 	if (params->offchan)
459bc70732fSIgor Mitsyanko 		flags |= QLINK_FRAME_TX_FLAG_OFFCHAN;
46098f44cb0SIgor Mitsyanko 
46198f44cb0SIgor Mitsyanko 	if (params->no_cck)
462bc70732fSIgor Mitsyanko 		flags |= QLINK_FRAME_TX_FLAG_NO_CCK;
46398f44cb0SIgor Mitsyanko 
46498f44cb0SIgor Mitsyanko 	if (params->dont_wait_for_ack)
465bc70732fSIgor Mitsyanko 		flags |= QLINK_FRAME_TX_FLAG_ACK_NOWAIT;
46698f44cb0SIgor Mitsyanko 
467e6e594afSIgor Mitsyanko 	/* If channel is not specified, pass "freq = 0" to tell device
468e6e594afSIgor Mitsyanko 	 * firmware to use current channel.
469e6e594afSIgor Mitsyanko 	 */
470e6e594afSIgor Mitsyanko 	if (params->chan)
471e6e594afSIgor Mitsyanko 		freq = params->chan->center_freq;
472e6e594afSIgor Mitsyanko 	else
473e6e594afSIgor Mitsyanko 		freq = 0;
474e6e594afSIgor Mitsyanko 
47598f44cb0SIgor Mitsyanko 	pr_debug("%s freq:%u; FC:%.4X; DA:%pM; len:%zu; C:%.8X; FL:%.4X\n",
476e6e594afSIgor Mitsyanko 		 wdev->netdev->name, freq,
47798f44cb0SIgor Mitsyanko 		 le16_to_cpu(mgmt_frame->frame_control), mgmt_frame->da,
47898f44cb0SIgor Mitsyanko 		 params->len, short_cookie, flags);
47998f44cb0SIgor Mitsyanko 
480bc70732fSIgor Mitsyanko 	return qtnf_cmd_send_frame(vif, short_cookie, flags,
481bc70732fSIgor Mitsyanko 				   freq, params->buf, params->len);
48298f44cb0SIgor Mitsyanko }
48398f44cb0SIgor Mitsyanko 
48498f44cb0SIgor Mitsyanko static int
qtnf_get_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_info * sinfo)48598f44cb0SIgor Mitsyanko qtnf_get_station(struct wiphy *wiphy, struct net_device *dev,
48698f44cb0SIgor Mitsyanko 		 const u8 *mac, struct station_info *sinfo)
48798f44cb0SIgor Mitsyanko {
48898f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
48998f44cb0SIgor Mitsyanko 
4907a4d3a3bSIgor Mitsyanko 	sinfo->generation = vif->generation;
49198f44cb0SIgor Mitsyanko 	return qtnf_cmd_get_sta_info(vif, mac, sinfo);
49298f44cb0SIgor Mitsyanko }
49398f44cb0SIgor Mitsyanko 
49498f44cb0SIgor Mitsyanko static int
qtnf_dump_station(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * mac,struct station_info * sinfo)49598f44cb0SIgor Mitsyanko qtnf_dump_station(struct wiphy *wiphy, struct net_device *dev,
49698f44cb0SIgor Mitsyanko 		  int idx, u8 *mac, struct station_info *sinfo)
49798f44cb0SIgor Mitsyanko {
49898f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
49998f44cb0SIgor Mitsyanko 	const struct qtnf_sta_node *sta_node;
50098f44cb0SIgor Mitsyanko 	int ret;
50198f44cb0SIgor Mitsyanko 
502e1c02eb1SSergey Matyukevich 	switch (vif->wdev.iftype) {
503e1c02eb1SSergey Matyukevich 	case NL80211_IFTYPE_STATION:
5047b0a0e3cSJohannes Berg 		if (idx != 0 || !vif->wdev.connected)
505e1c02eb1SSergey Matyukevich 			return -ENOENT;
50698f44cb0SIgor Mitsyanko 
507e1c02eb1SSergey Matyukevich 		ether_addr_copy(mac, vif->bssid);
508e1c02eb1SSergey Matyukevich 		break;
509e1c02eb1SSergey Matyukevich 	case NL80211_IFTYPE_AP:
510e1c02eb1SSergey Matyukevich 		sta_node = qtnf_sta_list_lookup_index(&vif->sta_list, idx);
51198f44cb0SIgor Mitsyanko 		if (unlikely(!sta_node))
51298f44cb0SIgor Mitsyanko 			return -ENOENT;
51398f44cb0SIgor Mitsyanko 
51498f44cb0SIgor Mitsyanko 		ether_addr_copy(mac, sta_node->mac_addr);
515e1c02eb1SSergey Matyukevich 		break;
516e1c02eb1SSergey Matyukevich 	default:
517e1c02eb1SSergey Matyukevich 		return -ENOTSUPP;
518e1c02eb1SSergey Matyukevich 	}
51998f44cb0SIgor Mitsyanko 
520e1c02eb1SSergey Matyukevich 	ret = qtnf_cmd_get_sta_info(vif, mac, sinfo);
52198f44cb0SIgor Mitsyanko 
522e1c02eb1SSergey Matyukevich 	if (vif->wdev.iftype == NL80211_IFTYPE_AP) {
523e1c02eb1SSergey Matyukevich 		if (ret == -ENOENT) {
52498f44cb0SIgor Mitsyanko 			cfg80211_del_sta(vif->netdev, mac, GFP_KERNEL);
52598f44cb0SIgor Mitsyanko 			sinfo->filled = 0;
52698f44cb0SIgor Mitsyanko 		}
527e1c02eb1SSergey Matyukevich 	}
52898f44cb0SIgor Mitsyanko 
5297a4d3a3bSIgor Mitsyanko 	sinfo->generation = vif->generation;
5307a4d3a3bSIgor Mitsyanko 
53198f44cb0SIgor Mitsyanko 	return ret;
53298f44cb0SIgor Mitsyanko }
53398f44cb0SIgor Mitsyanko 
qtnf_add_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr,struct key_params * params)53498f44cb0SIgor Mitsyanko static int qtnf_add_key(struct wiphy *wiphy, struct net_device *dev,
535e7a7b84eSVeerendranath Jakkam 			int link_id, u8 key_index, bool pairwise,
536e7a7b84eSVeerendranath Jakkam 			const u8 *mac_addr, struct key_params *params)
53798f44cb0SIgor Mitsyanko {
53898f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
53998f44cb0SIgor Mitsyanko 	int ret;
54098f44cb0SIgor Mitsyanko 
54198f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_add_key(vif, key_index, pairwise, mac_addr, params);
54298f44cb0SIgor Mitsyanko 	if (ret)
54398f44cb0SIgor Mitsyanko 		pr_err("VIF%u.%u: failed to add key: cipher=%x idx=%u pw=%u\n",
54498f44cb0SIgor Mitsyanko 		       vif->mac->macid, vif->vifid, params->cipher, key_index,
54598f44cb0SIgor Mitsyanko 		       pairwise);
54698f44cb0SIgor Mitsyanko 
54798f44cb0SIgor Mitsyanko 	return ret;
54898f44cb0SIgor Mitsyanko }
54998f44cb0SIgor Mitsyanko 
qtnf_del_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_index,bool pairwise,const u8 * mac_addr)55098f44cb0SIgor Mitsyanko static int qtnf_del_key(struct wiphy *wiphy, struct net_device *dev,
551e7a7b84eSVeerendranath Jakkam 			int link_id, u8 key_index, bool pairwise,
552e7a7b84eSVeerendranath Jakkam 			const u8 *mac_addr)
55398f44cb0SIgor Mitsyanko {
55498f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
55598f44cb0SIgor Mitsyanko 	int ret;
55698f44cb0SIgor Mitsyanko 
55798f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_del_key(vif, key_index, pairwise, mac_addr);
55835da3fe6SSergey Matyukevich 	if (ret) {
55935da3fe6SSergey Matyukevich 		if (ret == -ENOENT) {
56035da3fe6SSergey Matyukevich 			pr_debug("VIF%u.%u: key index %d out of bounds\n",
56135da3fe6SSergey Matyukevich 				 vif->mac->macid, vif->vifid, key_index);
56235da3fe6SSergey Matyukevich 		} else {
56398f44cb0SIgor Mitsyanko 			pr_err("VIF%u.%u: failed to delete key: idx=%u pw=%u\n",
56435da3fe6SSergey Matyukevich 			       vif->mac->macid, vif->vifid,
56535da3fe6SSergey Matyukevich 			       key_index, pairwise);
56635da3fe6SSergey Matyukevich 		}
56735da3fe6SSergey Matyukevich 	}
56898f44cb0SIgor Mitsyanko 
56998f44cb0SIgor Mitsyanko 	return ret;
57098f44cb0SIgor Mitsyanko }
57198f44cb0SIgor Mitsyanko 
qtnf_set_default_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_index,bool unicast,bool multicast)57298f44cb0SIgor Mitsyanko static int qtnf_set_default_key(struct wiphy *wiphy, struct net_device *dev,
573e7a7b84eSVeerendranath Jakkam 				int link_id, u8 key_index, bool unicast,
574e7a7b84eSVeerendranath Jakkam 				bool multicast)
57598f44cb0SIgor Mitsyanko {
57698f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
57798f44cb0SIgor Mitsyanko 	int ret;
57898f44cb0SIgor Mitsyanko 
57998f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_set_default_key(vif, key_index, unicast, multicast);
58098f44cb0SIgor Mitsyanko 	if (ret)
58198f44cb0SIgor Mitsyanko 		pr_err("VIF%u.%u: failed to set dflt key: idx=%u uc=%u mc=%u\n",
58298f44cb0SIgor Mitsyanko 		       vif->mac->macid, vif->vifid, key_index, unicast,
58398f44cb0SIgor Mitsyanko 		       multicast);
58498f44cb0SIgor Mitsyanko 
58598f44cb0SIgor Mitsyanko 	return ret;
58698f44cb0SIgor Mitsyanko }
58798f44cb0SIgor Mitsyanko 
58898f44cb0SIgor Mitsyanko static int
qtnf_set_default_mgmt_key(struct wiphy * wiphy,struct net_device * dev,int link_id,u8 key_index)58998f44cb0SIgor Mitsyanko qtnf_set_default_mgmt_key(struct wiphy *wiphy, struct net_device *dev,
590e7a7b84eSVeerendranath Jakkam 			  int link_id, u8 key_index)
59198f44cb0SIgor Mitsyanko {
59298f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
59398f44cb0SIgor Mitsyanko 	int ret;
59498f44cb0SIgor Mitsyanko 
59598f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_set_default_mgmt_key(vif, key_index);
59698f44cb0SIgor Mitsyanko 	if (ret)
59798f44cb0SIgor Mitsyanko 		pr_err("VIF%u.%u: failed to set default MGMT key: idx=%u\n",
59898f44cb0SIgor Mitsyanko 		       vif->mac->macid, vif->vifid, key_index);
59998f44cb0SIgor Mitsyanko 
60098f44cb0SIgor Mitsyanko 	return ret;
60198f44cb0SIgor Mitsyanko }
60298f44cb0SIgor Mitsyanko 
60398f44cb0SIgor Mitsyanko static int
qtnf_change_station(struct wiphy * wiphy,struct net_device * dev,const u8 * mac,struct station_parameters * params)60498f44cb0SIgor Mitsyanko qtnf_change_station(struct wiphy *wiphy, struct net_device *dev,
60598f44cb0SIgor Mitsyanko 		    const u8 *mac, struct station_parameters *params)
60698f44cb0SIgor Mitsyanko {
60798f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
60898f44cb0SIgor Mitsyanko 	int ret;
60998f44cb0SIgor Mitsyanko 
61098f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_change_sta(vif, mac, params);
61198f44cb0SIgor Mitsyanko 	if (ret)
61298f44cb0SIgor Mitsyanko 		pr_err("VIF%u.%u: failed to change STA %pM\n",
61398f44cb0SIgor Mitsyanko 		       vif->mac->macid, vif->vifid, mac);
61498f44cb0SIgor Mitsyanko 
61598f44cb0SIgor Mitsyanko 	return ret;
61698f44cb0SIgor Mitsyanko }
61798f44cb0SIgor Mitsyanko 
61898f44cb0SIgor Mitsyanko static int
qtnf_del_station(struct wiphy * wiphy,struct net_device * dev,struct station_del_parameters * params)61998f44cb0SIgor Mitsyanko qtnf_del_station(struct wiphy *wiphy, struct net_device *dev,
62098f44cb0SIgor Mitsyanko 		 struct station_del_parameters *params)
62198f44cb0SIgor Mitsyanko {
62298f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
62398f44cb0SIgor Mitsyanko 	int ret;
62498f44cb0SIgor Mitsyanko 
62598f44cb0SIgor Mitsyanko 	if (params->mac &&
62698f44cb0SIgor Mitsyanko 	    (vif->wdev.iftype == NL80211_IFTYPE_AP) &&
62798f44cb0SIgor Mitsyanko 	    !is_broadcast_ether_addr(params->mac) &&
62898f44cb0SIgor Mitsyanko 	    !qtnf_sta_list_lookup(&vif->sta_list, params->mac))
62998f44cb0SIgor Mitsyanko 		return 0;
63098f44cb0SIgor Mitsyanko 
63198f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_del_sta(vif, params);
63298f44cb0SIgor Mitsyanko 	if (ret)
63398f44cb0SIgor Mitsyanko 		pr_err("VIF%u.%u: failed to delete STA %pM\n",
63498f44cb0SIgor Mitsyanko 		       vif->mac->macid, vif->vifid, params->mac);
635c6ed298fSSergey Matyukevich 
63698f44cb0SIgor Mitsyanko 	return ret;
63798f44cb0SIgor Mitsyanko }
63898f44cb0SIgor Mitsyanko 
63998f44cb0SIgor Mitsyanko static int
qtnf_scan(struct wiphy * wiphy,struct cfg80211_scan_request * request)64098f44cb0SIgor Mitsyanko qtnf_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
64198f44cb0SIgor Mitsyanko {
64298f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
643c6ed298fSSergey Matyukevich 	int ret;
64498f44cb0SIgor Mitsyanko 
645f2cddd54SIgor Mitsyanko 	cancel_delayed_work_sync(&mac->scan_timeout);
646f2cddd54SIgor Mitsyanko 
64798f44cb0SIgor Mitsyanko 	mac->scan_req = request;
64898f44cb0SIgor Mitsyanko 
649c6ed298fSSergey Matyukevich 	ret = qtnf_cmd_send_scan(mac);
650c6ed298fSSergey Matyukevich 	if (ret) {
65198f44cb0SIgor Mitsyanko 		pr_err("MAC%u: failed to start scan\n", mac->macid);
652c7ead2abSSergey Matyukevich 		mac->scan_req = NULL;
653c6ed298fSSergey Matyukevich 		goto out;
654c7ead2abSSergey Matyukevich 	}
65598f44cb0SIgor Mitsyanko 
656c6ed298fSSergey Matyukevich 	pr_debug("MAC%u: scan started\n", mac->macid);
657f2cddd54SIgor Mitsyanko 	queue_delayed_work(mac->bus->workqueue, &mac->scan_timeout,
658f2cddd54SIgor Mitsyanko 			   QTNF_SCAN_TIMEOUT_SEC * HZ);
659c7ead2abSSergey Matyukevich 
660c6ed298fSSergey Matyukevich out:
661c6ed298fSSergey Matyukevich 	return ret;
66298f44cb0SIgor Mitsyanko }
66398f44cb0SIgor Mitsyanko 
66498f44cb0SIgor Mitsyanko static int
qtnf_connect(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_connect_params * sme)66598f44cb0SIgor Mitsyanko qtnf_connect(struct wiphy *wiphy, struct net_device *dev,
66698f44cb0SIgor Mitsyanko 	     struct cfg80211_connect_params *sme)
66798f44cb0SIgor Mitsyanko {
66898f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
66998f44cb0SIgor Mitsyanko 	int ret;
67098f44cb0SIgor Mitsyanko 
67198f44cb0SIgor Mitsyanko 	if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
67298f44cb0SIgor Mitsyanko 		return -EOPNOTSUPP;
67398f44cb0SIgor Mitsyanko 
67447b08e75SSergey Matyukevich 	if (sme->auth_type == NL80211_AUTHTYPE_SAE &&
67547b08e75SSergey Matyukevich 	    !(sme->flags & CONNECT_REQ_EXTERNAL_AUTH_SUPPORT)) {
67647b08e75SSergey Matyukevich 		pr_err("can not offload authentication to userspace\n");
67747b08e75SSergey Matyukevich 		return -EOPNOTSUPP;
67847b08e75SSergey Matyukevich 	}
67947b08e75SSergey Matyukevich 
68098f44cb0SIgor Mitsyanko 	if (sme->bssid)
6819766d1ddSIgor Mitsyanko 		ether_addr_copy(vif->bssid, sme->bssid);
68298f44cb0SIgor Mitsyanko 	else
6839766d1ddSIgor Mitsyanko 		eth_zero_addr(vif->bssid);
68498f44cb0SIgor Mitsyanko 
68598f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_connect(vif, sme);
686a221d0afSwengjianfeng 	if (ret)
687c6ed298fSSergey Matyukevich 		pr_err("VIF%u.%u: failed to connect\n",
688c6ed298fSSergey Matyukevich 		       vif->mac->macid, vif->vifid);
68998f44cb0SIgor Mitsyanko 
690c6ed298fSSergey Matyukevich 	return ret;
69198f44cb0SIgor Mitsyanko }
69298f44cb0SIgor Mitsyanko 
69398f44cb0SIgor Mitsyanko static int
qtnf_external_auth(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_external_auth_params * auth)69447b08e75SSergey Matyukevich qtnf_external_auth(struct wiphy *wiphy, struct net_device *dev,
69547b08e75SSergey Matyukevich 		   struct cfg80211_external_auth_params *auth)
69647b08e75SSergey Matyukevich {
69747b08e75SSergey Matyukevich 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
69847b08e75SSergey Matyukevich 	int ret;
69947b08e75SSergey Matyukevich 
700b3860e7aSSergey Matyukevich 	if (vif->wdev.iftype == NL80211_IFTYPE_STATION &&
701b3860e7aSSergey Matyukevich 	    !ether_addr_equal(vif->bssid, auth->bssid))
70247b08e75SSergey Matyukevich 		pr_warn("unexpected bssid: %pM", auth->bssid);
70347b08e75SSergey Matyukevich 
70447b08e75SSergey Matyukevich 	ret = qtnf_cmd_send_external_auth(vif, auth);
705a221d0afSwengjianfeng 	if (ret)
70647b08e75SSergey Matyukevich 		pr_err("VIF%u.%u: failed to report external auth\n",
70747b08e75SSergey Matyukevich 		       vif->mac->macid, vif->vifid);
70847b08e75SSergey Matyukevich 
70947b08e75SSergey Matyukevich 	return ret;
71047b08e75SSergey Matyukevich }
71147b08e75SSergey Matyukevich 
71247b08e75SSergey Matyukevich static int
qtnf_disconnect(struct wiphy * wiphy,struct net_device * dev,u16 reason_code)71398f44cb0SIgor Mitsyanko qtnf_disconnect(struct wiphy *wiphy, struct net_device *dev,
71498f44cb0SIgor Mitsyanko 		u16 reason_code)
71598f44cb0SIgor Mitsyanko {
71698f44cb0SIgor Mitsyanko 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
71798f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif;
718480daa9cSSergey Matyukevich 	int ret = 0;
71998f44cb0SIgor Mitsyanko 
72098f44cb0SIgor Mitsyanko 	vif = qtnf_mac_get_base_vif(mac);
72198f44cb0SIgor Mitsyanko 	if (!vif) {
72298f44cb0SIgor Mitsyanko 		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
723c1e3f64fSGustavo A. R. Silva 		return -EFAULT;
72498f44cb0SIgor Mitsyanko 	}
72598f44cb0SIgor Mitsyanko 
7266b013c3dSSebin Sebastian 	if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
727a221d0afSwengjianfeng 		return -EOPNOTSUPP;
72898f44cb0SIgor Mitsyanko 
72998f44cb0SIgor Mitsyanko 	ret = qtnf_cmd_send_disconnect(vif, reason_code);
730d5f693bcSIgor Mitsyanko 	if (ret)
731c6ed298fSSergey Matyukevich 		pr_err("VIF%u.%u: failed to disconnect\n",
732c6ed298fSSergey Matyukevich 		       mac->macid, vif->vifid);
733d5f693bcSIgor Mitsyanko 
7347b0a0e3cSJohannes Berg 	if (vif->wdev.connected) {
735d5f693bcSIgor Mitsyanko 		netif_carrier_off(vif->netdev);
736d5f693bcSIgor Mitsyanko 		cfg80211_disconnected(vif->netdev, reason_code,
737d5f693bcSIgor Mitsyanko 				      NULL, 0, true, GFP_KERNEL);
73898f44cb0SIgor Mitsyanko 	}
73998f44cb0SIgor Mitsyanko 
740480daa9cSSergey Matyukevich 	return ret;
74198f44cb0SIgor Mitsyanko }
74298f44cb0SIgor Mitsyanko 
7437c04b439SSergey Matyukevich static int
qtnf_dump_survey(struct wiphy * wiphy,struct net_device * dev,int idx,struct survey_info * survey)7447c04b439SSergey Matyukevich qtnf_dump_survey(struct wiphy *wiphy, struct net_device *dev,
7457c04b439SSergey Matyukevich 		 int idx, struct survey_info *survey)
7467c04b439SSergey Matyukevich {
7477c04b439SSergey Matyukevich 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
748ef81e8e9SIgor Mitsyanko 	struct wireless_dev *wdev = dev->ieee80211_ptr;
7497c04b439SSergey Matyukevich 	struct ieee80211_supported_band *sband;
7507b0a0e3cSJohannes Berg 	const struct cfg80211_chan_def *chandef = wdev_chandef(wdev, 0);
7517c04b439SSergey Matyukevich 	struct ieee80211_channel *chan;
7527c04b439SSergey Matyukevich 	int ret;
7537c04b439SSergey Matyukevich 
7547c04b439SSergey Matyukevich 	sband = wiphy->bands[NL80211_BAND_2GHZ];
7557c04b439SSergey Matyukevich 	if (sband && idx >= sband->n_channels) {
7567c04b439SSergey Matyukevich 		idx -= sband->n_channels;
7577c04b439SSergey Matyukevich 		sband = NULL;
7587c04b439SSergey Matyukevich 	}
7597c04b439SSergey Matyukevich 
7607c04b439SSergey Matyukevich 	if (!sband)
7617c04b439SSergey Matyukevich 		sband = wiphy->bands[NL80211_BAND_5GHZ];
7627c04b439SSergey Matyukevich 
7637c04b439SSergey Matyukevich 	if (!sband || idx >= sband->n_channels)
7647c04b439SSergey Matyukevich 		return -ENOENT;
7657c04b439SSergey Matyukevich 
7667c04b439SSergey Matyukevich 	chan = &sband->channels[idx];
7677c04b439SSergey Matyukevich 	survey->channel = chan;
7687c04b439SSergey Matyukevich 	survey->filled = 0x0;
7697c04b439SSergey Matyukevich 
7707b0a0e3cSJohannes Berg 	if (chandef && chan == chandef->chan)
77134f1145bSSergey Matyukevich 		survey->filled = SURVEY_INFO_IN_USE;
77227894448SSergey Matyukevich 
773601ce21fSIgor Mitsyanko 	ret = qtnf_cmd_get_chan_stats(mac, chan->center_freq, survey);
774601ce21fSIgor Mitsyanko 	if (ret)
7757c04b439SSergey Matyukevich 		pr_debug("failed to get chan(%d) stats from card\n",
7767c04b439SSergey Matyukevich 			 chan->hw_value);
7777c04b439SSergey Matyukevich 
7787c04b439SSergey Matyukevich 	return ret;
7797c04b439SSergey Matyukevich }
7807c04b439SSergey Matyukevich 
78127894448SSergey Matyukevich static int
qtnf_get_channel(struct wiphy * wiphy,struct wireless_dev * wdev,unsigned int link_id,struct cfg80211_chan_def * chandef)78227894448SSergey Matyukevich qtnf_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
7837b0a0e3cSJohannes Berg 		 unsigned int link_id, struct cfg80211_chan_def *chandef)
78427894448SSergey Matyukevich {
78527894448SSergey Matyukevich 	struct net_device *ndev = wdev->netdev;
78627894448SSergey Matyukevich 	struct qtnf_vif *vif;
7879e5478b6SIgor Mitsyanko 	int ret;
78827894448SSergey Matyukevich 
78927894448SSergey Matyukevich 	if (!ndev)
79027894448SSergey Matyukevich 		return -ENODEV;
79127894448SSergey Matyukevich 
79227894448SSergey Matyukevich 	vif = qtnf_netdev_get_priv(wdev->netdev);
79327894448SSergey Matyukevich 
7949e5478b6SIgor Mitsyanko 	ret = qtnf_cmd_get_channel(vif, chandef);
7959e5478b6SIgor Mitsyanko 	if (ret) {
7969e5478b6SIgor Mitsyanko 		pr_err("%s: failed to get channel: %d\n", ndev->name, ret);
797c6ed298fSSergey Matyukevich 		ret = -ENODATA;
7989e5478b6SIgor Mitsyanko 		goto out;
79927894448SSergey Matyukevich 	}
80027894448SSergey Matyukevich 
8019e5478b6SIgor Mitsyanko 	if (!cfg80211_chandef_valid(chandef)) {
8025bf374abSSergey Matyukevich 		pr_err("%s: bad channel freq=%u cf1=%u cf2=%u bw=%u\n",
8035bf374abSSergey Matyukevich 		       ndev->name, chandef->chan->center_freq,
8049e5478b6SIgor Mitsyanko 		       chandef->center_freq1, chandef->center_freq2,
8059e5478b6SIgor Mitsyanko 		       chandef->width);
8069e5478b6SIgor Mitsyanko 		ret = -ENODATA;
807c6ed298fSSergey Matyukevich 		goto out;
80834f1145bSSergey Matyukevich 	}
80934f1145bSSergey Matyukevich 
8109e5478b6SIgor Mitsyanko out:
8119e5478b6SIgor Mitsyanko 	return ret;
81227894448SSergey Matyukevich }
81327894448SSergey Matyukevich 
qtnf_channel_switch(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_csa_settings * params)81497883695SSergey Matyukevich static int qtnf_channel_switch(struct wiphy *wiphy, struct net_device *dev,
81597883695SSergey Matyukevich 			       struct cfg80211_csa_settings *params)
81697883695SSergey Matyukevich {
81797883695SSergey Matyukevich 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
81897883695SSergey Matyukevich 	int ret;
81997883695SSergey Matyukevich 
82097883695SSergey Matyukevich 	pr_debug("%s: chan(%u) count(%u) radar(%u) block_tx(%u)\n", dev->name,
82197883695SSergey Matyukevich 		 params->chandef.chan->hw_value, params->count,
82297883695SSergey Matyukevich 		 params->radar_required, params->block_tx);
82397883695SSergey Matyukevich 
82497883695SSergey Matyukevich 	if (!cfg80211_chandef_valid(&params->chandef)) {
82597883695SSergey Matyukevich 		pr_err("%s: invalid channel\n", dev->name);
82697883695SSergey Matyukevich 		return -EINVAL;
82797883695SSergey Matyukevich 	}
82897883695SSergey Matyukevich 
8298c015b90SIgor Mitsyanko 	ret = qtnf_cmd_send_chan_switch(vif, params);
83097883695SSergey Matyukevich 	if (ret)
83197883695SSergey Matyukevich 		pr_warn("%s: failed to switch to channel (%u)\n",
83297883695SSergey Matyukevich 			dev->name, params->chandef.chan->hw_value);
83397883695SSergey Matyukevich 
83497883695SSergey Matyukevich 	return ret;
83597883695SSergey Matyukevich }
83697883695SSergey Matyukevich 
qtnf_start_radar_detection(struct wiphy * wiphy,struct net_device * ndev,struct cfg80211_chan_def * chandef,u32 cac_time_ms)837b05ee456SIgor Mitsyanko static int qtnf_start_radar_detection(struct wiphy *wiphy,
838b05ee456SIgor Mitsyanko 				      struct net_device *ndev,
839b05ee456SIgor Mitsyanko 				      struct cfg80211_chan_def *chandef,
840b05ee456SIgor Mitsyanko 				      u32 cac_time_ms)
841b05ee456SIgor Mitsyanko {
842b05ee456SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
843b05ee456SIgor Mitsyanko 	int ret;
844b05ee456SIgor Mitsyanko 
845fbb93020SDmitry Lebed 	if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
846fbb93020SDmitry Lebed 		return -ENOTSUPP;
847fbb93020SDmitry Lebed 
848b05ee456SIgor Mitsyanko 	ret = qtnf_cmd_start_cac(vif, chandef, cac_time_ms);
849b05ee456SIgor Mitsyanko 	if (ret)
850b05ee456SIgor Mitsyanko 		pr_err("%s: failed to start CAC ret=%d\n", ndev->name, ret);
851b05ee456SIgor Mitsyanko 
852b05ee456SIgor Mitsyanko 	return ret;
853b05ee456SIgor Mitsyanko }
854b05ee456SIgor Mitsyanko 
qtnf_set_mac_acl(struct wiphy * wiphy,struct net_device * dev,const struct cfg80211_acl_data * params)855f1398fd2SVasily Ulyanov static int qtnf_set_mac_acl(struct wiphy *wiphy,
856f1398fd2SVasily Ulyanov 			    struct net_device *dev,
857f1398fd2SVasily Ulyanov 			    const struct cfg80211_acl_data *params)
858f1398fd2SVasily Ulyanov {
859f1398fd2SVasily Ulyanov 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
860f1398fd2SVasily Ulyanov 	int ret;
861f1398fd2SVasily Ulyanov 
862f1398fd2SVasily Ulyanov 	ret = qtnf_cmd_set_mac_acl(vif, params);
863f1398fd2SVasily Ulyanov 	if (ret)
864f1398fd2SVasily Ulyanov 		pr_err("%s: failed to set mac ACL ret=%d\n", dev->name, ret);
865f1398fd2SVasily Ulyanov 
866f1398fd2SVasily Ulyanov 	return ret;
867f1398fd2SVasily Ulyanov }
868f1398fd2SVasily Ulyanov 
qtnf_set_power_mgmt(struct wiphy * wiphy,struct net_device * dev,bool enabled,int timeout)8694775ad06SSergei Maksimenko static int qtnf_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
8704775ad06SSergei Maksimenko 			       bool enabled, int timeout)
8714775ad06SSergei Maksimenko {
8724775ad06SSergei Maksimenko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
8734775ad06SSergei Maksimenko 	int ret;
8744775ad06SSergei Maksimenko 
8754775ad06SSergei Maksimenko 	ret = qtnf_cmd_send_pm_set(vif, enabled ? QLINK_PM_AUTO_STANDBY :
8764775ad06SSergei Maksimenko 				   QLINK_PM_OFF, timeout);
877c6ed298fSSergey Matyukevich 	if (ret)
8784775ad06SSergei Maksimenko 		pr_err("%s: failed to set PM mode ret=%d\n", dev->name, ret);
8794775ad06SSergei Maksimenko 
8804775ad06SSergei Maksimenko 	return ret;
8814775ad06SSergei Maksimenko }
8824775ad06SSergei Maksimenko 
qtnf_get_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,int * dbm)8830756e913SMikhail Karpenko static int qtnf_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
8840756e913SMikhail Karpenko 			     int *dbm)
8850756e913SMikhail Karpenko {
8860756e913SMikhail Karpenko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
8870756e913SMikhail Karpenko 	int ret;
8880756e913SMikhail Karpenko 
8890756e913SMikhail Karpenko 	ret = qtnf_cmd_get_tx_power(vif, dbm);
8900756e913SMikhail Karpenko 	if (ret)
8910756e913SMikhail Karpenko 		pr_err("MAC%u: failed to get Tx power\n", vif->mac->macid);
8920756e913SMikhail Karpenko 
8930756e913SMikhail Karpenko 	return ret;
8940756e913SMikhail Karpenko }
8950756e913SMikhail Karpenko 
qtnf_set_tx_power(struct wiphy * wiphy,struct wireless_dev * wdev,enum nl80211_tx_power_setting type,int mbm)8960756e913SMikhail Karpenko static int qtnf_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
8970756e913SMikhail Karpenko 			     enum nl80211_tx_power_setting type, int mbm)
8980756e913SMikhail Karpenko {
8990756e913SMikhail Karpenko 	struct qtnf_vif *vif;
9000756e913SMikhail Karpenko 	int ret;
9010756e913SMikhail Karpenko 
9020756e913SMikhail Karpenko 	if (wdev) {
9030756e913SMikhail Karpenko 		vif = qtnf_netdev_get_priv(wdev->netdev);
9040756e913SMikhail Karpenko 	} else {
9050756e913SMikhail Karpenko 		struct qtnf_wmac *mac = wiphy_priv(wiphy);
9060756e913SMikhail Karpenko 
9070756e913SMikhail Karpenko 		vif = qtnf_mac_get_base_vif(mac);
9080756e913SMikhail Karpenko 		if (!vif) {
9090756e913SMikhail Karpenko 			pr_err("MAC%u: primary VIF is not configured\n",
9100756e913SMikhail Karpenko 			       mac->macid);
9110756e913SMikhail Karpenko 			return -EFAULT;
9120756e913SMikhail Karpenko 		}
9130756e913SMikhail Karpenko 	}
9140756e913SMikhail Karpenko 
9150756e913SMikhail Karpenko 	ret = qtnf_cmd_set_tx_power(vif, type, mbm);
9160756e913SMikhail Karpenko 	if (ret)
9170756e913SMikhail Karpenko 		pr_err("MAC%u: failed to set Tx power\n", vif->mac->macid);
9180756e913SMikhail Karpenko 
9190756e913SMikhail Karpenko 	return ret;
9200756e913SMikhail Karpenko }
9210756e913SMikhail Karpenko 
qtnf_update_owe_info(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_update_owe_info * owe_info)92244d09764SSergey Matyukevich static int qtnf_update_owe_info(struct wiphy *wiphy, struct net_device *dev,
92344d09764SSergey Matyukevich 				struct cfg80211_update_owe_info *owe_info)
92444d09764SSergey Matyukevich {
92544d09764SSergey Matyukevich 	struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
92644d09764SSergey Matyukevich 	int ret;
92744d09764SSergey Matyukevich 
92844d09764SSergey Matyukevich 	if (vif->wdev.iftype != NL80211_IFTYPE_AP)
92944d09764SSergey Matyukevich 		return -EOPNOTSUPP;
93044d09764SSergey Matyukevich 
93144d09764SSergey Matyukevich 	ret = qtnf_cmd_send_update_owe(vif, owe_info);
932a221d0afSwengjianfeng 	if (ret)
93344d09764SSergey Matyukevich 		pr_err("VIF%u.%u: failed to update owe info\n",
93444d09764SSergey Matyukevich 		       vif->mac->macid, vif->vifid);
93544d09764SSergey Matyukevich 
93644d09764SSergey Matyukevich 	return ret;
93744d09764SSergey Matyukevich }
93844d09764SSergey Matyukevich 
93928b91884SSergey Matyukevich #ifdef CONFIG_PM
qtnf_suspend(struct wiphy * wiphy,struct cfg80211_wowlan * wowlan)94028b91884SSergey Matyukevich static int qtnf_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wowlan)
94128b91884SSergey Matyukevich {
94228b91884SSergey Matyukevich 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
94328b91884SSergey Matyukevich 	struct qtnf_vif *vif;
94428b91884SSergey Matyukevich 	int ret = 0;
94528b91884SSergey Matyukevich 
94628b91884SSergey Matyukevich 	vif = qtnf_mac_get_base_vif(mac);
94728b91884SSergey Matyukevich 	if (!vif) {
94828b91884SSergey Matyukevich 		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
94928b91884SSergey Matyukevich 		ret = -EFAULT;
95028b91884SSergey Matyukevich 		goto exit;
95128b91884SSergey Matyukevich 	}
95228b91884SSergey Matyukevich 
95328b91884SSergey Matyukevich 	if (!wowlan) {
95428b91884SSergey Matyukevich 		pr_debug("WoWLAN triggers are not enabled\n");
95528b91884SSergey Matyukevich 		qtnf_virtual_intf_cleanup(vif->netdev);
95628b91884SSergey Matyukevich 		goto exit;
95728b91884SSergey Matyukevich 	}
95828b91884SSergey Matyukevich 
95928b91884SSergey Matyukevich 	qtnf_scan_done(vif->mac, true);
96028b91884SSergey Matyukevich 
96128b91884SSergey Matyukevich 	ret = qtnf_cmd_send_wowlan_set(vif, wowlan);
96228b91884SSergey Matyukevich 	if (ret) {
96328b91884SSergey Matyukevich 		pr_err("MAC%u: failed to set WoWLAN triggers\n",
96428b91884SSergey Matyukevich 		       mac->macid);
96528b91884SSergey Matyukevich 		goto exit;
96628b91884SSergey Matyukevich 	}
96728b91884SSergey Matyukevich 
96828b91884SSergey Matyukevich exit:
96928b91884SSergey Matyukevich 	return ret;
97028b91884SSergey Matyukevich }
97128b91884SSergey Matyukevich 
qtnf_resume(struct wiphy * wiphy)97228b91884SSergey Matyukevich static int qtnf_resume(struct wiphy *wiphy)
97328b91884SSergey Matyukevich {
97428b91884SSergey Matyukevich 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
97528b91884SSergey Matyukevich 	struct qtnf_vif *vif;
97628b91884SSergey Matyukevich 	int ret = 0;
97728b91884SSergey Matyukevich 
97828b91884SSergey Matyukevich 	vif = qtnf_mac_get_base_vif(mac);
97928b91884SSergey Matyukevich 	if (!vif) {
98028b91884SSergey Matyukevich 		pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
981a221d0afSwengjianfeng 		return -EFAULT;
98228b91884SSergey Matyukevich 	}
98328b91884SSergey Matyukevich 
98428b91884SSergey Matyukevich 	ret = qtnf_cmd_send_wowlan_set(vif, NULL);
985a221d0afSwengjianfeng 	if (ret)
98628b91884SSergey Matyukevich 		pr_err("MAC%u: failed to reset WoWLAN triggers\n",
98728b91884SSergey Matyukevich 		       mac->macid);
98828b91884SSergey Matyukevich 
98928b91884SSergey Matyukevich 	return ret;
99028b91884SSergey Matyukevich }
99128b91884SSergey Matyukevich 
qtnf_set_wakeup(struct wiphy * wiphy,bool enabled)99228b91884SSergey Matyukevich static void qtnf_set_wakeup(struct wiphy *wiphy, bool enabled)
99328b91884SSergey Matyukevich {
99428b91884SSergey Matyukevich 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
99528b91884SSergey Matyukevich 	struct qtnf_bus *bus = mac->bus;
99628b91884SSergey Matyukevich 
99728b91884SSergey Matyukevich 	device_set_wakeup_enable(bus->dev, enabled);
99828b91884SSergey Matyukevich }
99928b91884SSergey Matyukevich #endif
100028b91884SSergey Matyukevich 
100198f44cb0SIgor Mitsyanko static struct cfg80211_ops qtn_cfg80211_ops = {
100298f44cb0SIgor Mitsyanko 	.add_virtual_intf	= qtnf_add_virtual_intf,
100398f44cb0SIgor Mitsyanko 	.change_virtual_intf	= qtnf_change_virtual_intf,
100498f44cb0SIgor Mitsyanko 	.del_virtual_intf	= qtnf_del_virtual_intf,
100598f44cb0SIgor Mitsyanko 	.start_ap		= qtnf_start_ap,
100698f44cb0SIgor Mitsyanko 	.change_beacon		= qtnf_change_beacon,
100798f44cb0SIgor Mitsyanko 	.stop_ap		= qtnf_stop_ap,
100898f44cb0SIgor Mitsyanko 	.set_wiphy_params	= qtnf_set_wiphy_params,
10096cd536feSJohannes Berg 	.update_mgmt_frame_registrations =
10106cd536feSJohannes Berg 		qtnf_update_mgmt_frame_registrations,
101198f44cb0SIgor Mitsyanko 	.mgmt_tx		= qtnf_mgmt_tx,
101298f44cb0SIgor Mitsyanko 	.change_station		= qtnf_change_station,
101398f44cb0SIgor Mitsyanko 	.del_station		= qtnf_del_station,
101498f44cb0SIgor Mitsyanko 	.get_station		= qtnf_get_station,
101598f44cb0SIgor Mitsyanko 	.dump_station		= qtnf_dump_station,
101698f44cb0SIgor Mitsyanko 	.add_key		= qtnf_add_key,
101798f44cb0SIgor Mitsyanko 	.del_key		= qtnf_del_key,
101898f44cb0SIgor Mitsyanko 	.set_default_key	= qtnf_set_default_key,
101998f44cb0SIgor Mitsyanko 	.set_default_mgmt_key	= qtnf_set_default_mgmt_key,
102098f44cb0SIgor Mitsyanko 	.scan			= qtnf_scan,
102198f44cb0SIgor Mitsyanko 	.connect		= qtnf_connect,
102247b08e75SSergey Matyukevich 	.external_auth		= qtnf_external_auth,
10237c04b439SSergey Matyukevich 	.disconnect		= qtnf_disconnect,
102427894448SSergey Matyukevich 	.dump_survey		= qtnf_dump_survey,
102597883695SSergey Matyukevich 	.get_channel		= qtnf_get_channel,
1026b05ee456SIgor Mitsyanko 	.channel_switch		= qtnf_channel_switch,
1027b05ee456SIgor Mitsyanko 	.start_radar_detection	= qtnf_start_radar_detection,
1028f1398fd2SVasily Ulyanov 	.set_mac_acl		= qtnf_set_mac_acl,
10294775ad06SSergei Maksimenko 	.set_power_mgmt		= qtnf_set_power_mgmt,
10300756e913SMikhail Karpenko 	.get_tx_power		= qtnf_get_tx_power,
10310756e913SMikhail Karpenko 	.set_tx_power		= qtnf_set_tx_power,
103244d09764SSergey Matyukevich 	.update_owe_info	= qtnf_update_owe_info,
103328b91884SSergey Matyukevich #ifdef CONFIG_PM
103428b91884SSergey Matyukevich 	.suspend		= qtnf_suspend,
103528b91884SSergey Matyukevich 	.resume			= qtnf_resume,
103628b91884SSergey Matyukevich 	.set_wakeup		= qtnf_set_wakeup,
103728b91884SSergey Matyukevich #endif
103898f44cb0SIgor Mitsyanko };
103998f44cb0SIgor Mitsyanko 
qtnf_cfg80211_reg_notifier(struct wiphy * wiphy,struct regulatory_request * req)1040d1231721SIgor Mitsyanko static void qtnf_cfg80211_reg_notifier(struct wiphy *wiphy,
104198f44cb0SIgor Mitsyanko 				       struct regulatory_request *req)
104298f44cb0SIgor Mitsyanko {
1043d1231721SIgor Mitsyanko 	struct qtnf_wmac *mac = wiphy_priv(wiphy);
104498f44cb0SIgor Mitsyanko 	enum nl80211_band band;
10454dd07d2bSSergey Matyukevich 	int ret;
104698f44cb0SIgor Mitsyanko 
104798f44cb0SIgor Mitsyanko 	pr_debug("MAC%u: initiator=%d alpha=%c%c\n", mac->macid, req->initiator,
104898f44cb0SIgor Mitsyanko 		 req->alpha2[0], req->alpha2[1]);
104998f44cb0SIgor Mitsyanko 
1050155b424cSSergey Matyukevich 	ret = qtnf_cmd_reg_notify(mac, req, qtnf_slave_radar_get(),
1051155b424cSSergey Matyukevich 				  qtnf_dfs_offload_get());
10524dd07d2bSSergey Matyukevich 	if (ret) {
1053642f15a5SIgor Mitsyanko 		pr_err("MAC%u: failed to update region to %c%c: %d\n",
1054642f15a5SIgor Mitsyanko 		       mac->macid, req->alpha2[0], req->alpha2[1], ret);
105598f44cb0SIgor Mitsyanko 		return;
105698f44cb0SIgor Mitsyanko 	}
105798f44cb0SIgor Mitsyanko 
105898f44cb0SIgor Mitsyanko 	for (band = 0; band < NUM_NL80211_BANDS; ++band) {
105998f44cb0SIgor Mitsyanko 		if (!wiphy->bands[band])
106098f44cb0SIgor Mitsyanko 			continue;
106198f44cb0SIgor Mitsyanko 
1062e294cbfdSIgor Mitsyanko 		ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
10634dd07d2bSSergey Matyukevich 		if (ret)
1064d1231721SIgor Mitsyanko 			pr_err("MAC%u: failed to update band %u\n",
1065d1231721SIgor Mitsyanko 			       mac->macid, band);
106698f44cb0SIgor Mitsyanko 	}
106798f44cb0SIgor Mitsyanko }
106898f44cb0SIgor Mitsyanko 
qtnf_wiphy_allocate(struct qtnf_bus * bus,struct platform_device * pdev)1069616f5701SSergey Matyukevich struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus,
1070616f5701SSergey Matyukevich 				  struct platform_device *pdev)
107198f44cb0SIgor Mitsyanko {
107298f44cb0SIgor Mitsyanko 	struct wiphy *wiphy;
107398f44cb0SIgor Mitsyanko 
1074155b424cSSergey Matyukevich 	if (qtnf_dfs_offload_get() &&
1075310cd5ddSIgor Mitsyanko 	    qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_DFS_OFFLOAD))
1076fbb93020SDmitry Lebed 		qtn_cfg80211_ops.start_radar_detection = NULL;
1077fbb93020SDmitry Lebed 
1078310cd5ddSIgor Mitsyanko 	if (!qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_PWR_MGMT))
10794775ad06SSergei Maksimenko 		qtn_cfg80211_ops.set_power_mgmt	= NULL;
10804775ad06SSergei Maksimenko 
108198f44cb0SIgor Mitsyanko 	wiphy = wiphy_new(&qtn_cfg80211_ops, sizeof(struct qtnf_wmac));
108298f44cb0SIgor Mitsyanko 	if (!wiphy)
108398f44cb0SIgor Mitsyanko 		return NULL;
108498f44cb0SIgor Mitsyanko 
1085616f5701SSergey Matyukevich 	if (pdev)
1086616f5701SSergey Matyukevich 		set_wiphy_dev(wiphy, &pdev->dev);
1087616f5701SSergey Matyukevich 	else
108898f44cb0SIgor Mitsyanko 		set_wiphy_dev(wiphy, bus->dev);
108998f44cb0SIgor Mitsyanko 
109098f44cb0SIgor Mitsyanko 	return wiphy;
109198f44cb0SIgor Mitsyanko }
109298f44cb0SIgor Mitsyanko 
1093537faf26SSergey Matyukevich static int
qtnf_wiphy_setup_if_comb(struct wiphy * wiphy,struct qtnf_mac_info * mac_info)1094537faf26SSergey Matyukevich qtnf_wiphy_setup_if_comb(struct wiphy *wiphy, struct qtnf_mac_info *mac_info)
109598f44cb0SIgor Mitsyanko {
1096537faf26SSergey Matyukevich 	struct ieee80211_iface_combination *if_comb;
1097537faf26SSergey Matyukevich 	size_t n_if_comb;
109898f44cb0SIgor Mitsyanko 	u16 interface_modes = 0;
1099537faf26SSergey Matyukevich 	size_t i, j;
110098f44cb0SIgor Mitsyanko 
1101537faf26SSergey Matyukevich 	if_comb = mac_info->if_comb;
1102537faf26SSergey Matyukevich 	n_if_comb = mac_info->n_if_comb;
1103537faf26SSergey Matyukevich 
1104537faf26SSergey Matyukevich 	if (!if_comb || !n_if_comb)
110598f44cb0SIgor Mitsyanko 		return -ENOENT;
110698f44cb0SIgor Mitsyanko 
1107537faf26SSergey Matyukevich 	for (i = 0; i < n_if_comb; i++) {
1108537faf26SSergey Matyukevich 		if_comb[i].radar_detect_widths = mac_info->radar_detect_widths;
110998f44cb0SIgor Mitsyanko 
1110537faf26SSergey Matyukevich 		for (j = 0; j < if_comb[i].n_limits; j++)
1111537faf26SSergey Matyukevich 			interface_modes |= if_comb[i].limits[j].types;
111298f44cb0SIgor Mitsyanko 	}
111398f44cb0SIgor Mitsyanko 
1114537faf26SSergey Matyukevich 	wiphy->iface_combinations = if_comb;
1115537faf26SSergey Matyukevich 	wiphy->n_iface_combinations = n_if_comb;
111698f44cb0SIgor Mitsyanko 	wiphy->interface_modes = interface_modes;
111798f44cb0SIgor Mitsyanko 
111898f44cb0SIgor Mitsyanko 	return 0;
111998f44cb0SIgor Mitsyanko }
112098f44cb0SIgor Mitsyanko 
qtnf_wiphy_register(struct qtnf_hw_info * hw_info,struct qtnf_wmac * mac)112198f44cb0SIgor Mitsyanko int qtnf_wiphy_register(struct qtnf_hw_info *hw_info, struct qtnf_wmac *mac)
112298f44cb0SIgor Mitsyanko {
112398f44cb0SIgor Mitsyanko 	struct wiphy *wiphy = priv_to_wiphy(mac);
1124d62b622cSSergey Matyukevich 	struct qtnf_mac_info *macinfo = &mac->macinfo;
112598f44cb0SIgor Mitsyanko 	int ret;
112648cefdfbSIgor Mitsyanko 	bool regdomain_is_known;
112798f44cb0SIgor Mitsyanko 
112898f44cb0SIgor Mitsyanko 	if (!wiphy) {
112998f44cb0SIgor Mitsyanko 		pr_err("invalid wiphy pointer\n");
113098f44cb0SIgor Mitsyanko 		return -EFAULT;
113198f44cb0SIgor Mitsyanko 	}
113298f44cb0SIgor Mitsyanko 
1133d62b622cSSergey Matyukevich 	wiphy->frag_threshold = macinfo->frag_thr;
1134d62b622cSSergey Matyukevich 	wiphy->rts_threshold = macinfo->rts_thr;
1135d62b622cSSergey Matyukevich 	wiphy->retry_short = macinfo->sretry_limit;
1136d62b622cSSergey Matyukevich 	wiphy->retry_long = macinfo->lretry_limit;
1137d62b622cSSergey Matyukevich 	wiphy->coverage_class = macinfo->coverage_class;
113898f44cb0SIgor Mitsyanko 
11398f1180e0SAndrey Shevchenko 	wiphy->max_scan_ssids =
11400d18a9c0SIgor Mitsyanko 		(macinfo->max_scan_ssids) ? macinfo->max_scan_ssids : 1;
114198f44cb0SIgor Mitsyanko 	wiphy->max_scan_ie_len = QTNF_MAX_VSIE_LEN;
114298f44cb0SIgor Mitsyanko 	wiphy->mgmt_stypes = qtnf_mgmt_stypes;
114398f44cb0SIgor Mitsyanko 	wiphy->max_remain_on_channel_duration = 5000;
1144d62b622cSSergey Matyukevich 	wiphy->max_acl_mac_addrs = macinfo->max_acl_mac_addrs;
114597883695SSergey Matyukevich 	wiphy->max_num_csa_counters = 2;
114698f44cb0SIgor Mitsyanko 
1147d62b622cSSergey Matyukevich 	ret = qtnf_wiphy_setup_if_comb(wiphy, macinfo);
1148537faf26SSergey Matyukevich 	if (ret)
1149537faf26SSergey Matyukevich 		goto out;
1150537faf26SSergey Matyukevich 
115198f44cb0SIgor Mitsyanko 	/* Initialize cipher suits */
115298f44cb0SIgor Mitsyanko 	wiphy->cipher_suites = qtnf_cipher_suites;
115398f44cb0SIgor Mitsyanko 	wiphy->n_cipher_suites = ARRAY_SIZE(qtnf_cipher_suites);
115498f44cb0SIgor Mitsyanko 	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
115598f44cb0SIgor Mitsyanko 	wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
115698f44cb0SIgor Mitsyanko 			WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
115797883695SSergey Matyukevich 			WIPHY_FLAG_AP_UAPSD |
1158de624a35SSergey Matyukevich 			WIPHY_FLAG_HAS_CHANNEL_SWITCH |
115972b3270eSSergey Matyukevich 			WIPHY_FLAG_4ADDR_STATION |
116072b3270eSSergey Matyukevich 			WIPHY_FLAG_NETNS_OK;
11614775ad06SSergei Maksimenko 	wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
116298f44cb0SIgor Mitsyanko 
1163155b424cSSergey Matyukevich 	if (qtnf_dfs_offload_get() &&
1164310cd5ddSIgor Mitsyanko 	    qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_DFS_OFFLOAD))
1165fbb93020SDmitry Lebed 		wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD);
1166fbb93020SDmitry Lebed 
1167310cd5ddSIgor Mitsyanko 	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_SCAN_DWELL))
11682525f188SSergey Matyukevich 		wiphy_ext_feature_set(wiphy,
11692525f188SSergey Matyukevich 				      NL80211_EXT_FEATURE_SET_SCAN_DWELL);
11702525f188SSergey Matyukevich 
117198f44cb0SIgor Mitsyanko 	wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
117298f44cb0SIgor Mitsyanko 				    NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
117398f44cb0SIgor Mitsyanko 
1174d62b622cSSergey Matyukevich 	wiphy->available_antennas_tx = macinfo->num_tx_chain;
1175d62b622cSSergey Matyukevich 	wiphy->available_antennas_rx = macinfo->num_rx_chain;
117698f44cb0SIgor Mitsyanko 
1177d62b622cSSergey Matyukevich 	wiphy->max_ap_assoc_sta = macinfo->max_ap_assoc_sta;
1178d62b622cSSergey Matyukevich 	wiphy->ht_capa_mod_mask = &macinfo->ht_cap_mod_mask;
1179d62b622cSSergey Matyukevich 	wiphy->vht_capa_mod_mask = &macinfo->vht_cap_mod_mask;
118098f44cb0SIgor Mitsyanko 
118198f44cb0SIgor Mitsyanko 	ether_addr_copy(wiphy->perm_addr, mac->macaddr);
118298f44cb0SIgor Mitsyanko 
1183310cd5ddSIgor Mitsyanko 	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_STA_INACT_TIMEOUT))
1184db5c6d4aSIgor Mitsyanko 		wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
1185db5c6d4aSIgor Mitsyanko 
1186310cd5ddSIgor Mitsyanko 	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_SCAN_RANDOM_MAC_ADDR))
11876fbef954SAndrey Shevchenko 		wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
11886fbef954SAndrey Shevchenko 
1189310cd5ddSIgor Mitsyanko 	if (!qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_OBSS_SCAN))
119092246b12SIgor Mitsyanko 		wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
119192246b12SIgor Mitsyanko 
1192310cd5ddSIgor Mitsyanko 	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_SAE))
119347b08e75SSergey Matyukevich 		wiphy->features |= NL80211_FEATURE_SAE;
119447b08e75SSergey Matyukevich 
119528b91884SSergey Matyukevich #ifdef CONFIG_PM
119628b91884SSergey Matyukevich 	if (macinfo->wowlan)
119728b91884SSergey Matyukevich 		wiphy->wowlan = macinfo->wowlan;
119828b91884SSergey Matyukevich #endif
119928b91884SSergey Matyukevich 
1200c698bce0SIgor Mitsyanko 	regdomain_is_known = isalpha(mac->rd->alpha2[0]) &&
1201c698bce0SIgor Mitsyanko 				isalpha(mac->rd->alpha2[1]);
120248cefdfbSIgor Mitsyanko 
1203310cd5ddSIgor Mitsyanko 	if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_REG_UPDATE)) {
120498f44cb0SIgor Mitsyanko 		wiphy->reg_notifier = qtnf_cfg80211_reg_notifier;
120548cefdfbSIgor Mitsyanko 
1206c698bce0SIgor Mitsyanko 		if (mac->rd->alpha2[0] == '9' && mac->rd->alpha2[1] == '9') {
120748cefdfbSIgor Mitsyanko 			wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
120848cefdfbSIgor Mitsyanko 				REGULATORY_STRICT_REG;
1209c698bce0SIgor Mitsyanko 			wiphy_apply_custom_regulatory(wiphy, mac->rd);
121048cefdfbSIgor Mitsyanko 		} else if (regdomain_is_known) {
121148cefdfbSIgor Mitsyanko 			wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
121248cefdfbSIgor Mitsyanko 		}
121398f44cb0SIgor Mitsyanko 	} else {
121498f44cb0SIgor Mitsyanko 		wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
121598f44cb0SIgor Mitsyanko 	}
121698f44cb0SIgor Mitsyanko 
1217ab1c64a1SSergey Matyukevich 	if (mac->macinfo.extended_capabilities_len) {
1218ab1c64a1SSergey Matyukevich 		wiphy->extended_capabilities =
1219ab1c64a1SSergey Matyukevich 			mac->macinfo.extended_capabilities;
1220ab1c64a1SSergey Matyukevich 		wiphy->extended_capabilities_mask =
1221ab1c64a1SSergey Matyukevich 			mac->macinfo.extended_capabilities_mask;
1222ab1c64a1SSergey Matyukevich 		wiphy->extended_capabilities_len =
1223ab1c64a1SSergey Matyukevich 			mac->macinfo.extended_capabilities_len;
1224ab1c64a1SSergey Matyukevich 	}
1225ab1c64a1SSergey Matyukevich 
1226bf99f11dSWolfram Sang 	strscpy(wiphy->fw_version, hw_info->fw_version,
12270b419d01SVasily Ulyanov 		sizeof(wiphy->fw_version));
12280b419d01SVasily Ulyanov 	wiphy->hw_version = hw_info->hw_version;
12290b419d01SVasily Ulyanov 
123098f44cb0SIgor Mitsyanko 	ret = wiphy_register(wiphy);
1231ea19479fSSergey Matyukevich 	if (ret < 0)
1232ea19479fSSergey Matyukevich 		goto out;
1233ea19479fSSergey Matyukevich 
1234ea19479fSSergey Matyukevich 	if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED)
1235c698bce0SIgor Mitsyanko 		ret = regulatory_set_wiphy_regd(wiphy, mac->rd);
123648cefdfbSIgor Mitsyanko 	else if (regdomain_is_known)
1237c698bce0SIgor Mitsyanko 		ret = regulatory_hint(wiphy, mac->rd->alpha2);
1238ea19479fSSergey Matyukevich 
123998f44cb0SIgor Mitsyanko out:
124098f44cb0SIgor Mitsyanko 	return ret;
124198f44cb0SIgor Mitsyanko }
124298f44cb0SIgor Mitsyanko 
qtnf_netdev_updown(struct net_device * ndev,bool up)124398f44cb0SIgor Mitsyanko void qtnf_netdev_updown(struct net_device *ndev, bool up)
124498f44cb0SIgor Mitsyanko {
124598f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
124698f44cb0SIgor Mitsyanko 
124798f44cb0SIgor Mitsyanko 	if (qtnf_cmd_send_updown_intf(vif, up))
1248c6ed298fSSergey Matyukevich 		pr_err("failed to send %s command to VIF%u.%u\n",
1249c6ed298fSSergey Matyukevich 		       up ? "UP" : "DOWN", vif->mac->macid, vif->vifid);
125098f44cb0SIgor Mitsyanko }
125198f44cb0SIgor Mitsyanko 
qtnf_virtual_intf_cleanup(struct net_device * ndev)125298f44cb0SIgor Mitsyanko void qtnf_virtual_intf_cleanup(struct net_device *ndev)
125398f44cb0SIgor Mitsyanko {
125498f44cb0SIgor Mitsyanko 	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
12554f8e2545SColin Ian King 	struct qtnf_wmac *mac = wiphy_priv(vif->wdev.wiphy);
125698f44cb0SIgor Mitsyanko 
1257d5f693bcSIgor Mitsyanko 	if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
125898f44cb0SIgor Mitsyanko 		qtnf_disconnect(vif->wdev.wiphy, ndev,
125998f44cb0SIgor Mitsyanko 				WLAN_REASON_DEAUTH_LEAVING);
1260a715b3a0SSergey Matyukevich 
1261a715b3a0SSergey Matyukevich 	qtnf_scan_done(mac, true);
126298f44cb0SIgor Mitsyanko }
126398f44cb0SIgor Mitsyanko 
qtnf_cfg80211_vif_reset(struct qtnf_vif * vif)126498f44cb0SIgor Mitsyanko void qtnf_cfg80211_vif_reset(struct qtnf_vif *vif)
126598f44cb0SIgor Mitsyanko {
1266263ee96bSSergey Matyukevich 	if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
1267263ee96bSSergey Matyukevich 		cfg80211_disconnected(vif->netdev, WLAN_REASON_DEAUTH_LEAVING,
126898f44cb0SIgor Mitsyanko 				      NULL, 0, 1, GFP_KERNEL);
126998f44cb0SIgor Mitsyanko 
127098f44cb0SIgor Mitsyanko 	cfg80211_shutdown_all_interfaces(vif->wdev.wiphy);
127198f44cb0SIgor Mitsyanko }
127298f44cb0SIgor Mitsyanko 
qtnf_band_init_rates(struct ieee80211_supported_band * band)127398f44cb0SIgor Mitsyanko void qtnf_band_init_rates(struct ieee80211_supported_band *band)
127498f44cb0SIgor Mitsyanko {
127598f44cb0SIgor Mitsyanko 	switch (band->band) {
127698f44cb0SIgor Mitsyanko 	case NL80211_BAND_2GHZ:
127798f44cb0SIgor Mitsyanko 		band->bitrates = qtnf_rates_2g;
127898f44cb0SIgor Mitsyanko 		band->n_bitrates = ARRAY_SIZE(qtnf_rates_2g);
127998f44cb0SIgor Mitsyanko 		break;
128098f44cb0SIgor Mitsyanko 	case NL80211_BAND_5GHZ:
128198f44cb0SIgor Mitsyanko 		band->bitrates = qtnf_rates_5g;
128298f44cb0SIgor Mitsyanko 		band->n_bitrates = ARRAY_SIZE(qtnf_rates_5g);
128398f44cb0SIgor Mitsyanko 		break;
128498f44cb0SIgor Mitsyanko 	default:
128598f44cb0SIgor Mitsyanko 		band->bitrates = NULL;
128698f44cb0SIgor Mitsyanko 		band->n_bitrates = 0;
128798f44cb0SIgor Mitsyanko 		break;
128898f44cb0SIgor Mitsyanko 	}
128998f44cb0SIgor Mitsyanko }
1290