18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * NXP Wireless LAN device driver: CFG80211
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright 2011-2020 NXP
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software file (the "File") is distributed by NXP
78c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License Version 2, June 1991
88c2ecf20Sopenharmony_ci * (the "License").  You may use, redistribute and/or modify this File in
98c2ecf20Sopenharmony_ci * accordance with the terms and conditions of the License, a copy of which
108c2ecf20Sopenharmony_ci * is available by writing to the Free Software Foundation, Inc.,
118c2ecf20Sopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
128c2ecf20Sopenharmony_ci * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
158c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
168c2ecf20Sopenharmony_ci * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
178c2ecf20Sopenharmony_ci * this warranty disclaimer.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include "cfg80211.h"
218c2ecf20Sopenharmony_ci#include "main.h"
228c2ecf20Sopenharmony_ci#include "11n.h"
238c2ecf20Sopenharmony_ci#include "wmm.h"
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic char *reg_alpha2;
268c2ecf20Sopenharmony_cimodule_param(reg_alpha2, charp, 0);
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
298c2ecf20Sopenharmony_ci	{
308c2ecf20Sopenharmony_ci		.max = MWIFIEX_MAX_BSS_NUM,
318c2ecf20Sopenharmony_ci		.types = BIT(NL80211_IFTYPE_STATION) |
328c2ecf20Sopenharmony_ci				   BIT(NL80211_IFTYPE_P2P_GO) |
338c2ecf20Sopenharmony_ci				   BIT(NL80211_IFTYPE_P2P_CLIENT) |
348c2ecf20Sopenharmony_ci				   BIT(NL80211_IFTYPE_AP),
358c2ecf20Sopenharmony_ci	},
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistatic const struct ieee80211_iface_combination
398c2ecf20Sopenharmony_cimwifiex_iface_comb_ap_sta = {
408c2ecf20Sopenharmony_ci	.limits = mwifiex_ap_sta_limits,
418c2ecf20Sopenharmony_ci	.num_different_channels = 1,
428c2ecf20Sopenharmony_ci	.n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
438c2ecf20Sopenharmony_ci	.max_interfaces = MWIFIEX_MAX_BSS_NUM,
448c2ecf20Sopenharmony_ci	.beacon_int_infra_match = true,
458c2ecf20Sopenharmony_ci	.radar_detect_widths =	BIT(NL80211_CHAN_WIDTH_20_NOHT) |
468c2ecf20Sopenharmony_ci				BIT(NL80211_CHAN_WIDTH_20) |
478c2ecf20Sopenharmony_ci				BIT(NL80211_CHAN_WIDTH_40),
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic const struct ieee80211_iface_combination
518c2ecf20Sopenharmony_cimwifiex_iface_comb_ap_sta_vht = {
528c2ecf20Sopenharmony_ci	.limits = mwifiex_ap_sta_limits,
538c2ecf20Sopenharmony_ci	.num_different_channels = 1,
548c2ecf20Sopenharmony_ci	.n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
558c2ecf20Sopenharmony_ci	.max_interfaces = MWIFIEX_MAX_BSS_NUM,
568c2ecf20Sopenharmony_ci	.beacon_int_infra_match = true,
578c2ecf20Sopenharmony_ci	.radar_detect_widths =	BIT(NL80211_CHAN_WIDTH_20_NOHT) |
588c2ecf20Sopenharmony_ci				BIT(NL80211_CHAN_WIDTH_20) |
598c2ecf20Sopenharmony_ci				BIT(NL80211_CHAN_WIDTH_40) |
608c2ecf20Sopenharmony_ci				BIT(NL80211_CHAN_WIDTH_80),
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic const struct
648c2ecf20Sopenharmony_ciieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = {
658c2ecf20Sopenharmony_ci	.limits = mwifiex_ap_sta_limits,
668c2ecf20Sopenharmony_ci	.num_different_channels = 2,
678c2ecf20Sopenharmony_ci	.n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits),
688c2ecf20Sopenharmony_ci	.max_interfaces = MWIFIEX_MAX_BSS_NUM,
698c2ecf20Sopenharmony_ci	.beacon_int_infra_match = true,
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/*
738c2ecf20Sopenharmony_ci * This function maps the nl802.11 channel type into driver channel type.
748c2ecf20Sopenharmony_ci *
758c2ecf20Sopenharmony_ci * The mapping is as follows -
768c2ecf20Sopenharmony_ci *      NL80211_CHAN_NO_HT     -> IEEE80211_HT_PARAM_CHA_SEC_NONE
778c2ecf20Sopenharmony_ci *      NL80211_CHAN_HT20      -> IEEE80211_HT_PARAM_CHA_SEC_NONE
788c2ecf20Sopenharmony_ci *      NL80211_CHAN_HT40PLUS  -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE
798c2ecf20Sopenharmony_ci *      NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW
808c2ecf20Sopenharmony_ci *      Others                 -> IEEE80211_HT_PARAM_CHA_SEC_NONE
818c2ecf20Sopenharmony_ci */
828c2ecf20Sopenharmony_ciu8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	switch (chan_type) {
858c2ecf20Sopenharmony_ci	case NL80211_CHAN_NO_HT:
868c2ecf20Sopenharmony_ci	case NL80211_CHAN_HT20:
878c2ecf20Sopenharmony_ci		return IEEE80211_HT_PARAM_CHA_SEC_NONE;
888c2ecf20Sopenharmony_ci	case NL80211_CHAN_HT40PLUS:
898c2ecf20Sopenharmony_ci		return IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
908c2ecf20Sopenharmony_ci	case NL80211_CHAN_HT40MINUS:
918c2ecf20Sopenharmony_ci		return IEEE80211_HT_PARAM_CHA_SEC_BELOW;
928c2ecf20Sopenharmony_ci	default:
938c2ecf20Sopenharmony_ci		return IEEE80211_HT_PARAM_CHA_SEC_NONE;
948c2ecf20Sopenharmony_ci	}
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* This function maps IEEE HT secondary channel type to NL80211 channel type
988c2ecf20Sopenharmony_ci */
998c2ecf20Sopenharmony_ciu8 mwifiex_get_chan_type(struct mwifiex_private *priv)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	struct mwifiex_channel_band channel_band;
1028c2ecf20Sopenharmony_ci	int ret;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	ret = mwifiex_get_chan_info(priv, &channel_band);
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	if (!ret) {
1078c2ecf20Sopenharmony_ci		switch (channel_band.band_config.chan_width) {
1088c2ecf20Sopenharmony_ci		case CHAN_BW_20MHZ:
1098c2ecf20Sopenharmony_ci			if (IS_11N_ENABLED(priv))
1108c2ecf20Sopenharmony_ci				return NL80211_CHAN_HT20;
1118c2ecf20Sopenharmony_ci			else
1128c2ecf20Sopenharmony_ci				return NL80211_CHAN_NO_HT;
1138c2ecf20Sopenharmony_ci		case CHAN_BW_40MHZ:
1148c2ecf20Sopenharmony_ci			if (channel_band.band_config.chan2_offset ==
1158c2ecf20Sopenharmony_ci			    SEC_CHAN_ABOVE)
1168c2ecf20Sopenharmony_ci				return NL80211_CHAN_HT40PLUS;
1178c2ecf20Sopenharmony_ci			else
1188c2ecf20Sopenharmony_ci				return NL80211_CHAN_HT40MINUS;
1198c2ecf20Sopenharmony_ci		default:
1208c2ecf20Sopenharmony_ci			return NL80211_CHAN_HT20;
1218c2ecf20Sopenharmony_ci		}
1228c2ecf20Sopenharmony_ci	}
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	return NL80211_CHAN_HT20;
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/*
1288c2ecf20Sopenharmony_ci * This function checks whether WEP is set.
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_cistatic int
1318c2ecf20Sopenharmony_cimwifiex_is_alg_wep(u32 cipher)
1328c2ecf20Sopenharmony_ci{
1338c2ecf20Sopenharmony_ci	switch (cipher) {
1348c2ecf20Sopenharmony_ci	case WLAN_CIPHER_SUITE_WEP40:
1358c2ecf20Sopenharmony_ci	case WLAN_CIPHER_SUITE_WEP104:
1368c2ecf20Sopenharmony_ci		return 1;
1378c2ecf20Sopenharmony_ci	default:
1388c2ecf20Sopenharmony_ci		break;
1398c2ecf20Sopenharmony_ci	}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	return 0;
1428c2ecf20Sopenharmony_ci}
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/*
1458c2ecf20Sopenharmony_ci * This function retrieves the private structure from kernel wiphy structure.
1468c2ecf20Sopenharmony_ci */
1478c2ecf20Sopenharmony_cistatic void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci	return (void *) (*(unsigned long *) wiphy_priv(wiphy));
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/*
1538c2ecf20Sopenharmony_ci * CFG802.11 operation handler to delete a network key.
1548c2ecf20Sopenharmony_ci */
1558c2ecf20Sopenharmony_cistatic int
1568c2ecf20Sopenharmony_cimwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
1578c2ecf20Sopenharmony_ci			 u8 key_index, bool pairwise, const u8 *mac_addr)
1588c2ecf20Sopenharmony_ci{
1598c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
1608c2ecf20Sopenharmony_ci	static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1618c2ecf20Sopenharmony_ci	const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) {
1648c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n");
1658c2ecf20Sopenharmony_ci		return -EFAULT;
1668c2ecf20Sopenharmony_ci	}
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n");
1698c2ecf20Sopenharmony_ci	return 0;
1708c2ecf20Sopenharmony_ci}
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/*
1738c2ecf20Sopenharmony_ci * This function forms an skb for management frame.
1748c2ecf20Sopenharmony_ci */
1758c2ecf20Sopenharmony_cistatic int
1768c2ecf20Sopenharmony_cimwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
1778c2ecf20Sopenharmony_ci{
1788c2ecf20Sopenharmony_ci	u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1798c2ecf20Sopenharmony_ci	u16 pkt_len;
1808c2ecf20Sopenharmony_ci	u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	pkt_len = len + ETH_ALEN;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
1858c2ecf20Sopenharmony_ci		    MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
1868c2ecf20Sopenharmony_ci	memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	memcpy(skb_push(skb, sizeof(tx_control)),
1898c2ecf20Sopenharmony_ci	       &tx_control, sizeof(tx_control));
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	/* Add packet data and address4 */
1948c2ecf20Sopenharmony_ci	skb_put_data(skb, buf, sizeof(struct ieee80211_hdr_3addr));
1958c2ecf20Sopenharmony_ci	skb_put_data(skb, addr, ETH_ALEN);
1968c2ecf20Sopenharmony_ci	skb_put_data(skb, buf + sizeof(struct ieee80211_hdr_3addr),
1978c2ecf20Sopenharmony_ci		     len - sizeof(struct ieee80211_hdr_3addr));
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	skb->priority = LOW_PRIO_TID;
2008c2ecf20Sopenharmony_ci	__net_timestamp(skb);
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	return 0;
2038c2ecf20Sopenharmony_ci}
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci/*
2068c2ecf20Sopenharmony_ci * CFG802.11 operation handler to transmit a management frame.
2078c2ecf20Sopenharmony_ci */
2088c2ecf20Sopenharmony_cistatic int
2098c2ecf20Sopenharmony_cimwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
2108c2ecf20Sopenharmony_ci			 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
2118c2ecf20Sopenharmony_ci{
2128c2ecf20Sopenharmony_ci	const u8 *buf = params->buf;
2138c2ecf20Sopenharmony_ci	size_t len = params->len;
2148c2ecf20Sopenharmony_ci	struct sk_buff *skb;
2158c2ecf20Sopenharmony_ci	u16 pkt_len;
2168c2ecf20Sopenharmony_ci	const struct ieee80211_mgmt *mgmt;
2178c2ecf20Sopenharmony_ci	struct mwifiex_txinfo *tx_info;
2188c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	if (!buf || !len) {
2218c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n");
2228c2ecf20Sopenharmony_ci		return -EFAULT;
2238c2ecf20Sopenharmony_ci	}
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	mgmt = (const struct ieee80211_mgmt *)buf;
2268c2ecf20Sopenharmony_ci	if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
2278c2ecf20Sopenharmony_ci	    ieee80211_is_probe_resp(mgmt->frame_control)) {
2288c2ecf20Sopenharmony_ci		/* Since we support offload probe resp, we need to skip probe
2298c2ecf20Sopenharmony_ci		 * resp in AP or GO mode */
2308c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO,
2318c2ecf20Sopenharmony_ci			    "info: skip to send probe resp in AP or GO mode\n");
2328c2ecf20Sopenharmony_ci		return 0;
2338c2ecf20Sopenharmony_ci	}
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	pkt_len = len + ETH_ALEN;
2368c2ecf20Sopenharmony_ci	skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
2378c2ecf20Sopenharmony_ci			    MWIFIEX_MGMT_FRAME_HEADER_SIZE +
2388c2ecf20Sopenharmony_ci			    pkt_len + sizeof(pkt_len));
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	if (!skb) {
2418c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
2428c2ecf20Sopenharmony_ci			    "allocate skb failed for management frame\n");
2438c2ecf20Sopenharmony_ci		return -ENOMEM;
2448c2ecf20Sopenharmony_ci	}
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	tx_info = MWIFIEX_SKB_TXCB(skb);
2478c2ecf20Sopenharmony_ci	memset(tx_info, 0, sizeof(*tx_info));
2488c2ecf20Sopenharmony_ci	tx_info->bss_num = priv->bss_num;
2498c2ecf20Sopenharmony_ci	tx_info->bss_type = priv->bss_type;
2508c2ecf20Sopenharmony_ci	tx_info->pkt_len = pkt_len;
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	mwifiex_form_mgmt_frame(skb, buf, len);
2538c2ecf20Sopenharmony_ci	*cookie = prandom_u32() | 1;
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	if (ieee80211_is_action(mgmt->frame_control))
2568c2ecf20Sopenharmony_ci		skb = mwifiex_clone_skb_for_tx_status(priv,
2578c2ecf20Sopenharmony_ci						      skb,
2588c2ecf20Sopenharmony_ci				MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie);
2598c2ecf20Sopenharmony_ci	else
2608c2ecf20Sopenharmony_ci		cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
2618c2ecf20Sopenharmony_ci					GFP_ATOMIC);
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	mwifiex_queue_tx_pkt(priv, skb);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n");
2668c2ecf20Sopenharmony_ci	return 0;
2678c2ecf20Sopenharmony_ci}
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/*
2708c2ecf20Sopenharmony_ci * CFG802.11 operation handler to register a mgmt frame.
2718c2ecf20Sopenharmony_ci */
2728c2ecf20Sopenharmony_cistatic void
2738c2ecf20Sopenharmony_cimwifiex_cfg80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
2748c2ecf20Sopenharmony_ci						 struct wireless_dev *wdev,
2758c2ecf20Sopenharmony_ci						 struct mgmt_frame_regs *upd)
2768c2ecf20Sopenharmony_ci{
2778c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
2788c2ecf20Sopenharmony_ci	u32 mask = upd->interface_stypes;
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci	if (mask != priv->mgmt_frame_mask) {
2818c2ecf20Sopenharmony_ci		priv->mgmt_frame_mask = mask;
2828c2ecf20Sopenharmony_ci		mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
2838c2ecf20Sopenharmony_ci				 HostCmd_ACT_GEN_SET, 0,
2848c2ecf20Sopenharmony_ci				 &priv->mgmt_frame_mask, false);
2858c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n");
2868c2ecf20Sopenharmony_ci	}
2878c2ecf20Sopenharmony_ci}
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci/*
2908c2ecf20Sopenharmony_ci * CFG802.11 operation handler to remain on channel.
2918c2ecf20Sopenharmony_ci */
2928c2ecf20Sopenharmony_cistatic int
2938c2ecf20Sopenharmony_cimwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy,
2948c2ecf20Sopenharmony_ci				   struct wireless_dev *wdev,
2958c2ecf20Sopenharmony_ci				   struct ieee80211_channel *chan,
2968c2ecf20Sopenharmony_ci				   unsigned int duration, u64 *cookie)
2978c2ecf20Sopenharmony_ci{
2988c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
2998c2ecf20Sopenharmony_ci	int ret;
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	if (!chan || !cookie) {
3028c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n");
3038c2ecf20Sopenharmony_ci		return -EINVAL;
3048c2ecf20Sopenharmony_ci	}
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	if (priv->roc_cfg.cookie) {
3078c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO,
3088c2ecf20Sopenharmony_ci			    "info: ongoing ROC, cookie = 0x%llx\n",
3098c2ecf20Sopenharmony_ci			    priv->roc_cfg.cookie);
3108c2ecf20Sopenharmony_ci		return -EBUSY;
3118c2ecf20Sopenharmony_ci	}
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan,
3148c2ecf20Sopenharmony_ci					 duration);
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	if (!ret) {
3178c2ecf20Sopenharmony_ci		*cookie = prandom_u32() | 1;
3188c2ecf20Sopenharmony_ci		priv->roc_cfg.cookie = *cookie;
3198c2ecf20Sopenharmony_ci		priv->roc_cfg.chan = *chan;
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci		cfg80211_ready_on_channel(wdev, *cookie, chan,
3228c2ecf20Sopenharmony_ci					  duration, GFP_ATOMIC);
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO,
3258c2ecf20Sopenharmony_ci			    "info: ROC, cookie = 0x%llx\n", *cookie);
3268c2ecf20Sopenharmony_ci	}
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	return ret;
3298c2ecf20Sopenharmony_ci}
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci/*
3328c2ecf20Sopenharmony_ci * CFG802.11 operation handler to cancel remain on channel.
3338c2ecf20Sopenharmony_ci */
3348c2ecf20Sopenharmony_cistatic int
3358c2ecf20Sopenharmony_cimwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
3368c2ecf20Sopenharmony_ci					  struct wireless_dev *wdev, u64 cookie)
3378c2ecf20Sopenharmony_ci{
3388c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
3398c2ecf20Sopenharmony_ci	int ret;
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	if (cookie != priv->roc_cfg.cookie)
3428c2ecf20Sopenharmony_ci		return -ENOENT;
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE,
3458c2ecf20Sopenharmony_ci					 &priv->roc_cfg.chan, 0);
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	if (!ret) {
3488c2ecf20Sopenharmony_ci		cfg80211_remain_on_channel_expired(wdev, cookie,
3498c2ecf20Sopenharmony_ci						   &priv->roc_cfg.chan,
3508c2ecf20Sopenharmony_ci						   GFP_ATOMIC);
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci		memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg));
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO,
3558c2ecf20Sopenharmony_ci			    "info: cancel ROC, cookie = 0x%llx\n", cookie);
3568c2ecf20Sopenharmony_ci	}
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	return ret;
3598c2ecf20Sopenharmony_ci}
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci/*
3628c2ecf20Sopenharmony_ci * CFG802.11 operation handler to set Tx power.
3638c2ecf20Sopenharmony_ci */
3648c2ecf20Sopenharmony_cistatic int
3658c2ecf20Sopenharmony_cimwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
3668c2ecf20Sopenharmony_ci			      struct wireless_dev *wdev,
3678c2ecf20Sopenharmony_ci			      enum nl80211_tx_power_setting type,
3688c2ecf20Sopenharmony_ci			      int mbm)
3698c2ecf20Sopenharmony_ci{
3708c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
3718c2ecf20Sopenharmony_ci	struct mwifiex_private *priv;
3728c2ecf20Sopenharmony_ci	struct mwifiex_power_cfg power_cfg;
3738c2ecf20Sopenharmony_ci	int dbm = MBM_TO_DBM(mbm);
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	switch (type) {
3768c2ecf20Sopenharmony_ci	case NL80211_TX_POWER_FIXED:
3778c2ecf20Sopenharmony_ci		power_cfg.is_power_auto = 0;
3788c2ecf20Sopenharmony_ci		power_cfg.is_power_fixed = 1;
3798c2ecf20Sopenharmony_ci		power_cfg.power_level = dbm;
3808c2ecf20Sopenharmony_ci		break;
3818c2ecf20Sopenharmony_ci	case NL80211_TX_POWER_LIMITED:
3828c2ecf20Sopenharmony_ci		power_cfg.is_power_auto = 0;
3838c2ecf20Sopenharmony_ci		power_cfg.is_power_fixed = 0;
3848c2ecf20Sopenharmony_ci		power_cfg.power_level = dbm;
3858c2ecf20Sopenharmony_ci		break;
3868c2ecf20Sopenharmony_ci	case NL80211_TX_POWER_AUTOMATIC:
3878c2ecf20Sopenharmony_ci		power_cfg.is_power_auto = 1;
3888c2ecf20Sopenharmony_ci		break;
3898c2ecf20Sopenharmony_ci	}
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	return mwifiex_set_tx_power(priv, &power_cfg);
3948c2ecf20Sopenharmony_ci}
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci/*
3978c2ecf20Sopenharmony_ci * CFG802.11 operation handler to get Tx power.
3988c2ecf20Sopenharmony_ci */
3998c2ecf20Sopenharmony_cistatic int
4008c2ecf20Sopenharmony_cimwifiex_cfg80211_get_tx_power(struct wiphy *wiphy,
4018c2ecf20Sopenharmony_ci			      struct wireless_dev *wdev,
4028c2ecf20Sopenharmony_ci			      int *dbm)
4038c2ecf20Sopenharmony_ci{
4048c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
4058c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_get_priv(adapter,
4068c2ecf20Sopenharmony_ci							MWIFIEX_BSS_ROLE_ANY);
4078c2ecf20Sopenharmony_ci	int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
4088c2ecf20Sopenharmony_ci				   HostCmd_ACT_GEN_GET, 0, NULL, true);
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	if (ret < 0)
4118c2ecf20Sopenharmony_ci		return ret;
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci	/* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */
4148c2ecf20Sopenharmony_ci	*dbm = priv->tx_power_level;
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	return 0;
4178c2ecf20Sopenharmony_ci}
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci/*
4208c2ecf20Sopenharmony_ci * CFG802.11 operation handler to set Power Save option.
4218c2ecf20Sopenharmony_ci *
4228c2ecf20Sopenharmony_ci * The timeout value, if provided, is currently ignored.
4238c2ecf20Sopenharmony_ci */
4248c2ecf20Sopenharmony_cistatic int
4258c2ecf20Sopenharmony_cimwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
4268c2ecf20Sopenharmony_ci				struct net_device *dev,
4278c2ecf20Sopenharmony_ci				bool enabled, int timeout)
4288c2ecf20Sopenharmony_ci{
4298c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
4308c2ecf20Sopenharmony_ci	u32 ps_mode;
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci	if (timeout)
4338c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO,
4348c2ecf20Sopenharmony_ci			    "info: ignore timeout value for IEEE Power Save\n");
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	ps_mode = enabled;
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci	return mwifiex_drv_set_power(priv, &ps_mode);
4398c2ecf20Sopenharmony_ci}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci/*
4428c2ecf20Sopenharmony_ci * CFG802.11 operation handler to set the default network key.
4438c2ecf20Sopenharmony_ci */
4448c2ecf20Sopenharmony_cistatic int
4458c2ecf20Sopenharmony_cimwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
4468c2ecf20Sopenharmony_ci				 u8 key_index, bool unicast,
4478c2ecf20Sopenharmony_ci				 bool multicast)
4488c2ecf20Sopenharmony_ci{
4498c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci	/* Return if WEP key not configured */
4528c2ecf20Sopenharmony_ci	if (!priv->sec_info.wep_enabled)
4538c2ecf20Sopenharmony_ci		return 0;
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_ci	if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
4568c2ecf20Sopenharmony_ci		priv->wep_key_curr_index = key_index;
4578c2ecf20Sopenharmony_ci	} else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index,
4588c2ecf20Sopenharmony_ci				      NULL, 0)) {
4598c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n");
4608c2ecf20Sopenharmony_ci		return -EFAULT;
4618c2ecf20Sopenharmony_ci	}
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	return 0;
4648c2ecf20Sopenharmony_ci}
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci/*
4678c2ecf20Sopenharmony_ci * CFG802.11 operation handler to add a network key.
4688c2ecf20Sopenharmony_ci */
4698c2ecf20Sopenharmony_cistatic int
4708c2ecf20Sopenharmony_cimwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev,
4718c2ecf20Sopenharmony_ci			 u8 key_index, bool pairwise, const u8 *mac_addr,
4728c2ecf20Sopenharmony_ci			 struct key_params *params)
4738c2ecf20Sopenharmony_ci{
4748c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
4758c2ecf20Sopenharmony_ci	struct mwifiex_wep_key *wep_key;
4768c2ecf20Sopenharmony_ci	static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4778c2ecf20Sopenharmony_ci	const u8 *peer_mac = pairwise ? mac_addr : bc_mac;
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci	if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
4808c2ecf20Sopenharmony_ci	    (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4818c2ecf20Sopenharmony_ci	     params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
4828c2ecf20Sopenharmony_ci		if (params->key && params->key_len) {
4838c2ecf20Sopenharmony_ci			wep_key = &priv->wep_key[key_index];
4848c2ecf20Sopenharmony_ci			memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
4858c2ecf20Sopenharmony_ci			memcpy(wep_key->key_material, params->key,
4868c2ecf20Sopenharmony_ci			       params->key_len);
4878c2ecf20Sopenharmony_ci			wep_key->key_index = key_index;
4888c2ecf20Sopenharmony_ci			wep_key->key_length = params->key_len;
4898c2ecf20Sopenharmony_ci			priv->sec_info.wep_enabled = 1;
4908c2ecf20Sopenharmony_ci		}
4918c2ecf20Sopenharmony_ci		return 0;
4928c2ecf20Sopenharmony_ci	}
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	if (mwifiex_set_encode(priv, params, params->key, params->key_len,
4958c2ecf20Sopenharmony_ci			       key_index, peer_mac, 0)) {
4968c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n");
4978c2ecf20Sopenharmony_ci		return -EFAULT;
4988c2ecf20Sopenharmony_ci	}
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci	return 0;
5018c2ecf20Sopenharmony_ci}
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci/*
5048c2ecf20Sopenharmony_ci * CFG802.11 operation handler to set default mgmt key.
5058c2ecf20Sopenharmony_ci */
5068c2ecf20Sopenharmony_cistatic int
5078c2ecf20Sopenharmony_cimwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy,
5088c2ecf20Sopenharmony_ci				      struct net_device *netdev,
5098c2ecf20Sopenharmony_ci				      u8 key_index)
5108c2ecf20Sopenharmony_ci{
5118c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev);
5128c2ecf20Sopenharmony_ci	struct mwifiex_ds_encrypt_key encrypt_key;
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index);
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
5178c2ecf20Sopenharmony_ci	encrypt_key.key_len = WLAN_KEY_LEN_CCMP;
5188c2ecf20Sopenharmony_ci	encrypt_key.key_index = key_index;
5198c2ecf20Sopenharmony_ci	encrypt_key.is_igtk_def_key = true;
5208c2ecf20Sopenharmony_ci	eth_broadcast_addr(encrypt_key.mac_addr);
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci	return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
5238c2ecf20Sopenharmony_ci				HostCmd_ACT_GEN_SET, true, &encrypt_key, true);
5248c2ecf20Sopenharmony_ci}
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci/*
5278c2ecf20Sopenharmony_ci * This function sends domain information to the firmware.
5288c2ecf20Sopenharmony_ci *
5298c2ecf20Sopenharmony_ci * The following information are passed to the firmware -
5308c2ecf20Sopenharmony_ci *      - Country codes
5318c2ecf20Sopenharmony_ci *      - Sub bands (first channel, number of channels, maximum Tx power)
5328c2ecf20Sopenharmony_ci */
5338c2ecf20Sopenharmony_ciint mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy)
5348c2ecf20Sopenharmony_ci{
5358c2ecf20Sopenharmony_ci	u8 no_of_triplet = 0;
5368c2ecf20Sopenharmony_ci	struct ieee80211_country_ie_triplet *t;
5378c2ecf20Sopenharmony_ci	u8 no_of_parsed_chan = 0;
5388c2ecf20Sopenharmony_ci	u8 first_chan = 0, next_chan = 0, max_pwr = 0;
5398c2ecf20Sopenharmony_ci	u8 i, flag = 0;
5408c2ecf20Sopenharmony_ci	enum nl80211_band band;
5418c2ecf20Sopenharmony_ci	struct ieee80211_supported_band *sband;
5428c2ecf20Sopenharmony_ci	struct ieee80211_channel *ch;
5438c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
5448c2ecf20Sopenharmony_ci	struct mwifiex_private *priv;
5458c2ecf20Sopenharmony_ci	struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg;
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci	/* Set country code */
5488c2ecf20Sopenharmony_ci	domain_info->country_code[0] = adapter->country_code[0];
5498c2ecf20Sopenharmony_ci	domain_info->country_code[1] = adapter->country_code[1];
5508c2ecf20Sopenharmony_ci	domain_info->country_code[2] = ' ';
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci	band = mwifiex_band_to_radio_type(adapter->config_bands);
5538c2ecf20Sopenharmony_ci	if (!wiphy->bands[band]) {
5548c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
5558c2ecf20Sopenharmony_ci			    "11D: setting domain info in FW\n");
5568c2ecf20Sopenharmony_ci		return -1;
5578c2ecf20Sopenharmony_ci	}
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci	sband = wiphy->bands[band];
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci	for (i = 0; i < sband->n_channels ; i++) {
5628c2ecf20Sopenharmony_ci		ch = &sband->channels[i];
5638c2ecf20Sopenharmony_ci		if (ch->flags & IEEE80211_CHAN_DISABLED)
5648c2ecf20Sopenharmony_ci			continue;
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci		if (!flag) {
5678c2ecf20Sopenharmony_ci			flag = 1;
5688c2ecf20Sopenharmony_ci			first_chan = (u32) ch->hw_value;
5698c2ecf20Sopenharmony_ci			next_chan = first_chan;
5708c2ecf20Sopenharmony_ci			max_pwr = ch->max_power;
5718c2ecf20Sopenharmony_ci			no_of_parsed_chan = 1;
5728c2ecf20Sopenharmony_ci			continue;
5738c2ecf20Sopenharmony_ci		}
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci		if (ch->hw_value == next_chan + 1 &&
5768c2ecf20Sopenharmony_ci		    ch->max_power == max_pwr) {
5778c2ecf20Sopenharmony_ci			next_chan++;
5788c2ecf20Sopenharmony_ci			no_of_parsed_chan++;
5798c2ecf20Sopenharmony_ci		} else {
5808c2ecf20Sopenharmony_ci			t = &domain_info->triplet[no_of_triplet];
5818c2ecf20Sopenharmony_ci			t->chans.first_channel = first_chan;
5828c2ecf20Sopenharmony_ci			t->chans.num_channels = no_of_parsed_chan;
5838c2ecf20Sopenharmony_ci			t->chans.max_power = max_pwr;
5848c2ecf20Sopenharmony_ci			no_of_triplet++;
5858c2ecf20Sopenharmony_ci			first_chan = (u32) ch->hw_value;
5868c2ecf20Sopenharmony_ci			next_chan = first_chan;
5878c2ecf20Sopenharmony_ci			max_pwr = ch->max_power;
5888c2ecf20Sopenharmony_ci			no_of_parsed_chan = 1;
5898c2ecf20Sopenharmony_ci		}
5908c2ecf20Sopenharmony_ci	}
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ci	if (flag) {
5938c2ecf20Sopenharmony_ci		t = &domain_info->triplet[no_of_triplet];
5948c2ecf20Sopenharmony_ci		t->chans.first_channel = first_chan;
5958c2ecf20Sopenharmony_ci		t->chans.num_channels = no_of_parsed_chan;
5968c2ecf20Sopenharmony_ci		t->chans.max_power = max_pwr;
5978c2ecf20Sopenharmony_ci		no_of_triplet++;
5988c2ecf20Sopenharmony_ci	}
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	domain_info->no_of_triplet = no_of_triplet;
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci	priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
6058c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, NULL, false)) {
6068c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, INFO,
6078c2ecf20Sopenharmony_ci			    "11D: setting domain info in FW\n");
6088c2ecf20Sopenharmony_ci		return -1;
6098c2ecf20Sopenharmony_ci	}
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci	return 0;
6128c2ecf20Sopenharmony_ci}
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_cistatic void mwifiex_reg_apply_radar_flags(struct wiphy *wiphy)
6158c2ecf20Sopenharmony_ci{
6168c2ecf20Sopenharmony_ci	struct ieee80211_supported_band *sband;
6178c2ecf20Sopenharmony_ci	struct ieee80211_channel *chan;
6188c2ecf20Sopenharmony_ci	unsigned int i;
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci	if (!wiphy->bands[NL80211_BAND_5GHZ])
6218c2ecf20Sopenharmony_ci		return;
6228c2ecf20Sopenharmony_ci	sband = wiphy->bands[NL80211_BAND_5GHZ];
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci	for (i = 0; i < sband->n_channels; i++) {
6258c2ecf20Sopenharmony_ci		chan = &sband->channels[i];
6268c2ecf20Sopenharmony_ci		if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) &&
6278c2ecf20Sopenharmony_ci		    (chan->flags & IEEE80211_CHAN_RADAR))
6288c2ecf20Sopenharmony_ci			chan->flags |= IEEE80211_CHAN_NO_IR;
6298c2ecf20Sopenharmony_ci	}
6308c2ecf20Sopenharmony_ci}
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci/*
6338c2ecf20Sopenharmony_ci * CFG802.11 regulatory domain callback function.
6348c2ecf20Sopenharmony_ci *
6358c2ecf20Sopenharmony_ci * This function is called when the regulatory domain is changed due to the
6368c2ecf20Sopenharmony_ci * following reasons -
6378c2ecf20Sopenharmony_ci *      - Set by driver
6388c2ecf20Sopenharmony_ci *      - Set by system core
6398c2ecf20Sopenharmony_ci *      - Set by user
6408c2ecf20Sopenharmony_ci *      - Set bt Country IE
6418c2ecf20Sopenharmony_ci */
6428c2ecf20Sopenharmony_cistatic void mwifiex_reg_notifier(struct wiphy *wiphy,
6438c2ecf20Sopenharmony_ci				 struct regulatory_request *request)
6448c2ecf20Sopenharmony_ci{
6458c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
6468c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_get_priv(adapter,
6478c2ecf20Sopenharmony_ci							MWIFIEX_BSS_ROLE_ANY);
6488c2ecf20Sopenharmony_ci	mwifiex_dbg(adapter, INFO,
6498c2ecf20Sopenharmony_ci		    "info: cfg80211 regulatory domain callback for %c%c\n",
6508c2ecf20Sopenharmony_ci		    request->alpha2[0], request->alpha2[1]);
6518c2ecf20Sopenharmony_ci	mwifiex_reg_apply_radar_flags(wiphy);
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci	switch (request->initiator) {
6548c2ecf20Sopenharmony_ci	case NL80211_REGDOM_SET_BY_DRIVER:
6558c2ecf20Sopenharmony_ci	case NL80211_REGDOM_SET_BY_CORE:
6568c2ecf20Sopenharmony_ci	case NL80211_REGDOM_SET_BY_USER:
6578c2ecf20Sopenharmony_ci	case NL80211_REGDOM_SET_BY_COUNTRY_IE:
6588c2ecf20Sopenharmony_ci		break;
6598c2ecf20Sopenharmony_ci	default:
6608c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
6618c2ecf20Sopenharmony_ci			    "unknown regdom initiator: %d\n",
6628c2ecf20Sopenharmony_ci			    request->initiator);
6638c2ecf20Sopenharmony_ci		return;
6648c2ecf20Sopenharmony_ci	}
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci	/* Don't send world or same regdom info to firmware */
6678c2ecf20Sopenharmony_ci	if (strncmp(request->alpha2, "00", 2) &&
6688c2ecf20Sopenharmony_ci	    strncmp(request->alpha2, adapter->country_code,
6698c2ecf20Sopenharmony_ci		    sizeof(request->alpha2))) {
6708c2ecf20Sopenharmony_ci		memcpy(adapter->country_code, request->alpha2,
6718c2ecf20Sopenharmony_ci		       sizeof(request->alpha2));
6728c2ecf20Sopenharmony_ci		mwifiex_send_domain_info_cmd_fw(wiphy);
6738c2ecf20Sopenharmony_ci		mwifiex_dnld_txpwr_table(priv);
6748c2ecf20Sopenharmony_ci	}
6758c2ecf20Sopenharmony_ci}
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_ci/*
6788c2ecf20Sopenharmony_ci * This function sets the fragmentation threshold.
6798c2ecf20Sopenharmony_ci *
6808c2ecf20Sopenharmony_ci * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE
6818c2ecf20Sopenharmony_ci * and MWIFIEX_FRAG_MAX_VALUE.
6828c2ecf20Sopenharmony_ci */
6838c2ecf20Sopenharmony_cistatic int
6848c2ecf20Sopenharmony_cimwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr)
6858c2ecf20Sopenharmony_ci{
6868c2ecf20Sopenharmony_ci	if (frag_thr < MWIFIEX_FRAG_MIN_VALUE ||
6878c2ecf20Sopenharmony_ci	    frag_thr > MWIFIEX_FRAG_MAX_VALUE)
6888c2ecf20Sopenharmony_ci		frag_thr = MWIFIEX_FRAG_MAX_VALUE;
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci	return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
6918c2ecf20Sopenharmony_ci				HostCmd_ACT_GEN_SET, FRAG_THRESH_I,
6928c2ecf20Sopenharmony_ci				&frag_thr, true);
6938c2ecf20Sopenharmony_ci}
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci/*
6968c2ecf20Sopenharmony_ci * This function sets the RTS threshold.
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ci * The rts value must lie between MWIFIEX_RTS_MIN_VALUE
6998c2ecf20Sopenharmony_ci * and MWIFIEX_RTS_MAX_VALUE.
7008c2ecf20Sopenharmony_ci */
7018c2ecf20Sopenharmony_cistatic int
7028c2ecf20Sopenharmony_cimwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr)
7038c2ecf20Sopenharmony_ci{
7048c2ecf20Sopenharmony_ci	if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE)
7058c2ecf20Sopenharmony_ci		rts_thr = MWIFIEX_RTS_MAX_VALUE;
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ci	return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
7088c2ecf20Sopenharmony_ci				HostCmd_ACT_GEN_SET, RTS_THRESH_I,
7098c2ecf20Sopenharmony_ci				&rts_thr, true);
7108c2ecf20Sopenharmony_ci}
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci/*
7138c2ecf20Sopenharmony_ci * CFG802.11 operation handler to set wiphy parameters.
7148c2ecf20Sopenharmony_ci *
7158c2ecf20Sopenharmony_ci * This function can be used to set the RTS threshold and the
7168c2ecf20Sopenharmony_ci * Fragmentation threshold of the driver.
7178c2ecf20Sopenharmony_ci */
7188c2ecf20Sopenharmony_cistatic int
7198c2ecf20Sopenharmony_cimwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
7208c2ecf20Sopenharmony_ci{
7218c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
7228c2ecf20Sopenharmony_ci	struct mwifiex_private *priv;
7238c2ecf20Sopenharmony_ci	struct mwifiex_uap_bss_param *bss_cfg;
7248c2ecf20Sopenharmony_ci	int ret;
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci	priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ci	switch (priv->bss_role) {
7298c2ecf20Sopenharmony_ci	case MWIFIEX_BSS_ROLE_UAP:
7308c2ecf20Sopenharmony_ci		if (priv->bss_started) {
7318c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
7328c2ecf20Sopenharmony_ci				    "cannot change wiphy params when bss started");
7338c2ecf20Sopenharmony_ci			return -EINVAL;
7348c2ecf20Sopenharmony_ci		}
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci		bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL);
7378c2ecf20Sopenharmony_ci		if (!bss_cfg)
7388c2ecf20Sopenharmony_ci			return -ENOMEM;
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci		mwifiex_set_sys_config_invalid_data(bss_cfg);
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ci		if (changed & WIPHY_PARAM_RTS_THRESHOLD)
7438c2ecf20Sopenharmony_ci			bss_cfg->rts_threshold = wiphy->rts_threshold;
7448c2ecf20Sopenharmony_ci		if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
7458c2ecf20Sopenharmony_ci			bss_cfg->frag_threshold = wiphy->frag_threshold;
7468c2ecf20Sopenharmony_ci		if (changed & WIPHY_PARAM_RETRY_LONG)
7478c2ecf20Sopenharmony_ci			bss_cfg->retry_limit = wiphy->retry_long;
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci		ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
7508c2ecf20Sopenharmony_ci				       HostCmd_ACT_GEN_SET,
7518c2ecf20Sopenharmony_ci				       UAP_BSS_PARAMS_I, bss_cfg,
7528c2ecf20Sopenharmony_ci				       false);
7538c2ecf20Sopenharmony_ci
7548c2ecf20Sopenharmony_ci		kfree(bss_cfg);
7558c2ecf20Sopenharmony_ci		if (ret) {
7568c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
7578c2ecf20Sopenharmony_ci				    "Failed to set wiphy phy params\n");
7588c2ecf20Sopenharmony_ci			return ret;
7598c2ecf20Sopenharmony_ci		}
7608c2ecf20Sopenharmony_ci		break;
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci	case MWIFIEX_BSS_ROLE_STA:
7638c2ecf20Sopenharmony_ci		if (priv->media_connected) {
7648c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
7658c2ecf20Sopenharmony_ci				    "cannot change wiphy params when connected");
7668c2ecf20Sopenharmony_ci			return -EINVAL;
7678c2ecf20Sopenharmony_ci		}
7688c2ecf20Sopenharmony_ci		if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
7698c2ecf20Sopenharmony_ci			ret = mwifiex_set_rts(priv,
7708c2ecf20Sopenharmony_ci					      wiphy->rts_threshold);
7718c2ecf20Sopenharmony_ci			if (ret)
7728c2ecf20Sopenharmony_ci				return ret;
7738c2ecf20Sopenharmony_ci		}
7748c2ecf20Sopenharmony_ci		if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
7758c2ecf20Sopenharmony_ci			ret = mwifiex_set_frag(priv,
7768c2ecf20Sopenharmony_ci					       wiphy->frag_threshold);
7778c2ecf20Sopenharmony_ci			if (ret)
7788c2ecf20Sopenharmony_ci				return ret;
7798c2ecf20Sopenharmony_ci		}
7808c2ecf20Sopenharmony_ci		break;
7818c2ecf20Sopenharmony_ci	}
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	return 0;
7848c2ecf20Sopenharmony_ci}
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_cistatic int
7878c2ecf20Sopenharmony_cimwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv)
7888c2ecf20Sopenharmony_ci{
7898c2ecf20Sopenharmony_ci	u16 mode = P2P_MODE_DISABLE;
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
7928c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, &mode, true))
7938c2ecf20Sopenharmony_ci		return -1;
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_ci	return 0;
7968c2ecf20Sopenharmony_ci}
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci/*
7998c2ecf20Sopenharmony_ci * This function initializes the functionalities for P2P client.
8008c2ecf20Sopenharmony_ci * The P2P client initialization sequence is:
8018c2ecf20Sopenharmony_ci * disable -> device -> client
8028c2ecf20Sopenharmony_ci */
8038c2ecf20Sopenharmony_cistatic int
8048c2ecf20Sopenharmony_cimwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv)
8058c2ecf20Sopenharmony_ci{
8068c2ecf20Sopenharmony_ci	u16 mode;
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_ci	if (mwifiex_cfg80211_deinit_p2p(priv))
8098c2ecf20Sopenharmony_ci		return -1;
8108c2ecf20Sopenharmony_ci
8118c2ecf20Sopenharmony_ci	mode = P2P_MODE_DEVICE;
8128c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
8138c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, &mode, true))
8148c2ecf20Sopenharmony_ci		return -1;
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	mode = P2P_MODE_CLIENT;
8178c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
8188c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, &mode, true))
8198c2ecf20Sopenharmony_ci		return -1;
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci	return 0;
8228c2ecf20Sopenharmony_ci}
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ci/*
8258c2ecf20Sopenharmony_ci * This function initializes the functionalities for P2P GO.
8268c2ecf20Sopenharmony_ci * The P2P GO initialization sequence is:
8278c2ecf20Sopenharmony_ci * disable -> device -> GO
8288c2ecf20Sopenharmony_ci */
8298c2ecf20Sopenharmony_cistatic int
8308c2ecf20Sopenharmony_cimwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv)
8318c2ecf20Sopenharmony_ci{
8328c2ecf20Sopenharmony_ci	u16 mode;
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_ci	if (mwifiex_cfg80211_deinit_p2p(priv))
8358c2ecf20Sopenharmony_ci		return -1;
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_ci	mode = P2P_MODE_DEVICE;
8388c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
8398c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, &mode, true))
8408c2ecf20Sopenharmony_ci		return -1;
8418c2ecf20Sopenharmony_ci
8428c2ecf20Sopenharmony_ci	mode = P2P_MODE_GO;
8438c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG,
8448c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, &mode, true))
8458c2ecf20Sopenharmony_ci		return -1;
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci	return 0;
8488c2ecf20Sopenharmony_ci}
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_cistatic int mwifiex_deinit_priv_params(struct mwifiex_private *priv)
8518c2ecf20Sopenharmony_ci{
8528c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
8538c2ecf20Sopenharmony_ci	unsigned long flags;
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci	priv->mgmt_frame_mask = 0;
8568c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG,
8578c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0,
8588c2ecf20Sopenharmony_ci			     &priv->mgmt_frame_mask, false)) {
8598c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
8608c2ecf20Sopenharmony_ci			    "could not unregister mgmt frame rx\n");
8618c2ecf20Sopenharmony_ci		return -1;
8628c2ecf20Sopenharmony_ci	}
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_ci	mwifiex_deauthenticate(priv, NULL);
8658c2ecf20Sopenharmony_ci
8668c2ecf20Sopenharmony_ci	spin_lock_irqsave(&adapter->main_proc_lock, flags);
8678c2ecf20Sopenharmony_ci	adapter->main_locked = true;
8688c2ecf20Sopenharmony_ci	if (adapter->mwifiex_processing) {
8698c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
8708c2ecf20Sopenharmony_ci		flush_workqueue(adapter->workqueue);
8718c2ecf20Sopenharmony_ci	} else {
8728c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
8738c2ecf20Sopenharmony_ci	}
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_ci	spin_lock_bh(&adapter->rx_proc_lock);
8768c2ecf20Sopenharmony_ci	adapter->rx_locked = true;
8778c2ecf20Sopenharmony_ci	if (adapter->rx_processing) {
8788c2ecf20Sopenharmony_ci		spin_unlock_bh(&adapter->rx_proc_lock);
8798c2ecf20Sopenharmony_ci		flush_workqueue(adapter->rx_workqueue);
8808c2ecf20Sopenharmony_ci	} else {
8818c2ecf20Sopenharmony_ci	spin_unlock_bh(&adapter->rx_proc_lock);
8828c2ecf20Sopenharmony_ci	}
8838c2ecf20Sopenharmony_ci
8848c2ecf20Sopenharmony_ci	mwifiex_free_priv(priv);
8858c2ecf20Sopenharmony_ci	priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
8868c2ecf20Sopenharmony_ci	priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
8878c2ecf20Sopenharmony_ci	priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM;
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci	return 0;
8908c2ecf20Sopenharmony_ci}
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_cistatic int
8938c2ecf20Sopenharmony_cimwifiex_init_new_priv_params(struct mwifiex_private *priv,
8948c2ecf20Sopenharmony_ci			     struct net_device *dev,
8958c2ecf20Sopenharmony_ci			     enum nl80211_iftype type)
8968c2ecf20Sopenharmony_ci{
8978c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
8988c2ecf20Sopenharmony_ci	unsigned long flags;
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	mwifiex_init_priv(priv);
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_ci	priv->bss_mode = type;
9038c2ecf20Sopenharmony_ci	priv->wdev.iftype = type;
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_ci	mwifiex_init_priv_params(priv, priv->netdev);
9068c2ecf20Sopenharmony_ci	priv->bss_started = 0;
9078c2ecf20Sopenharmony_ci
9088c2ecf20Sopenharmony_ci	switch (type) {
9098c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
9108c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_ADHOC:
9118c2ecf20Sopenharmony_ci		priv->bss_role = MWIFIEX_BSS_ROLE_STA;
9128c2ecf20Sopenharmony_ci		priv->bss_type = MWIFIEX_BSS_TYPE_STA;
9138c2ecf20Sopenharmony_ci		break;
9148c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_CLIENT:
9158c2ecf20Sopenharmony_ci		priv->bss_role = MWIFIEX_BSS_ROLE_STA;
9168c2ecf20Sopenharmony_ci		priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
9178c2ecf20Sopenharmony_ci		break;
9188c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_GO:
9198c2ecf20Sopenharmony_ci		priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
9208c2ecf20Sopenharmony_ci		priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
9218c2ecf20Sopenharmony_ci		break;
9228c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
9238c2ecf20Sopenharmony_ci		priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
9248c2ecf20Sopenharmony_ci		priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
9258c2ecf20Sopenharmony_ci		break;
9268c2ecf20Sopenharmony_ci	default:
9278c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
9288c2ecf20Sopenharmony_ci			    "%s: changing to %d not supported\n",
9298c2ecf20Sopenharmony_ci			    dev->name, type);
9308c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
9318c2ecf20Sopenharmony_ci	}
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_ci	spin_lock_irqsave(&adapter->main_proc_lock, flags);
9348c2ecf20Sopenharmony_ci	adapter->main_locked = false;
9358c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
9368c2ecf20Sopenharmony_ci
9378c2ecf20Sopenharmony_ci	spin_lock_bh(&adapter->rx_proc_lock);
9388c2ecf20Sopenharmony_ci	adapter->rx_locked = false;
9398c2ecf20Sopenharmony_ci	spin_unlock_bh(&adapter->rx_proc_lock);
9408c2ecf20Sopenharmony_ci
9418c2ecf20Sopenharmony_ci	mwifiex_set_mac_address(priv, dev, false, NULL);
9428c2ecf20Sopenharmony_ci
9438c2ecf20Sopenharmony_ci	return 0;
9448c2ecf20Sopenharmony_ci}
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_cistatic int
9478c2ecf20Sopenharmony_cimwifiex_change_vif_to_p2p(struct net_device *dev,
9488c2ecf20Sopenharmony_ci			  enum nl80211_iftype curr_iftype,
9498c2ecf20Sopenharmony_ci			  enum nl80211_iftype type,
9508c2ecf20Sopenharmony_ci			  struct vif_params *params)
9518c2ecf20Sopenharmony_ci{
9528c2ecf20Sopenharmony_ci	struct mwifiex_private *priv;
9538c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter;
9548c2ecf20Sopenharmony_ci
9558c2ecf20Sopenharmony_ci	priv = mwifiex_netdev_get_priv(dev);
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	if (!priv)
9588c2ecf20Sopenharmony_ci		return -1;
9598c2ecf20Sopenharmony_ci
9608c2ecf20Sopenharmony_ci	adapter = priv->adapter;
9618c2ecf20Sopenharmony_ci
9628c2ecf20Sopenharmony_ci	if (adapter->curr_iface_comb.p2p_intf ==
9638c2ecf20Sopenharmony_ci	    adapter->iface_limit.p2p_intf) {
9648c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
9658c2ecf20Sopenharmony_ci			    "cannot create multiple P2P ifaces\n");
9668c2ecf20Sopenharmony_ci		return -1;
9678c2ecf20Sopenharmony_ci	}
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci	mwifiex_dbg(adapter, INFO,
9708c2ecf20Sopenharmony_ci		    "%s: changing role to p2p\n", dev->name);
9718c2ecf20Sopenharmony_ci
9728c2ecf20Sopenharmony_ci	if (mwifiex_deinit_priv_params(priv))
9738c2ecf20Sopenharmony_ci		return -1;
9748c2ecf20Sopenharmony_ci	if (mwifiex_init_new_priv_params(priv, dev, type))
9758c2ecf20Sopenharmony_ci		return -1;
9768c2ecf20Sopenharmony_ci
9778c2ecf20Sopenharmony_ci	switch (type) {
9788c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_CLIENT:
9798c2ecf20Sopenharmony_ci		if (mwifiex_cfg80211_init_p2p_client(priv))
9808c2ecf20Sopenharmony_ci			return -EFAULT;
9818c2ecf20Sopenharmony_ci		break;
9828c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_GO:
9838c2ecf20Sopenharmony_ci		if (mwifiex_cfg80211_init_p2p_go(priv))
9848c2ecf20Sopenharmony_ci			return -EFAULT;
9858c2ecf20Sopenharmony_ci		break;
9868c2ecf20Sopenharmony_ci	default:
9878c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
9888c2ecf20Sopenharmony_ci			    "%s: changing to %d not supported\n",
9898c2ecf20Sopenharmony_ci			    dev->name, type);
9908c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
9918c2ecf20Sopenharmony_ci	}
9928c2ecf20Sopenharmony_ci
9938c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
9948c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, NULL, true))
9958c2ecf20Sopenharmony_ci		return -1;
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_ci	if (mwifiex_sta_init_cmd(priv, false, false))
9988c2ecf20Sopenharmony_ci		return -1;
9998c2ecf20Sopenharmony_ci
10008c2ecf20Sopenharmony_ci	switch (curr_iftype) {
10018c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
10028c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_ADHOC:
10038c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.sta_intf--;
10048c2ecf20Sopenharmony_ci		break;
10058c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
10068c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.uap_intf--;
10078c2ecf20Sopenharmony_ci		break;
10088c2ecf20Sopenharmony_ci	default:
10098c2ecf20Sopenharmony_ci		break;
10108c2ecf20Sopenharmony_ci	}
10118c2ecf20Sopenharmony_ci
10128c2ecf20Sopenharmony_ci	adapter->curr_iface_comb.p2p_intf++;
10138c2ecf20Sopenharmony_ci	dev->ieee80211_ptr->iftype = type;
10148c2ecf20Sopenharmony_ci
10158c2ecf20Sopenharmony_ci	return 0;
10168c2ecf20Sopenharmony_ci}
10178c2ecf20Sopenharmony_ci
10188c2ecf20Sopenharmony_cistatic int
10198c2ecf20Sopenharmony_cimwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
10208c2ecf20Sopenharmony_ci				enum nl80211_iftype curr_iftype,
10218c2ecf20Sopenharmony_ci				enum nl80211_iftype type,
10228c2ecf20Sopenharmony_ci				struct vif_params *params)
10238c2ecf20Sopenharmony_ci{
10248c2ecf20Sopenharmony_ci	struct mwifiex_private *priv;
10258c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter;
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci	priv = mwifiex_netdev_get_priv(dev);
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_ci	if (!priv)
10308c2ecf20Sopenharmony_ci		return -1;
10318c2ecf20Sopenharmony_ci
10328c2ecf20Sopenharmony_ci	adapter = priv->adapter;
10338c2ecf20Sopenharmony_ci
10348c2ecf20Sopenharmony_ci	if ((curr_iftype != NL80211_IFTYPE_P2P_CLIENT &&
10358c2ecf20Sopenharmony_ci	     curr_iftype != NL80211_IFTYPE_P2P_GO) &&
10368c2ecf20Sopenharmony_ci	    (adapter->curr_iface_comb.sta_intf ==
10378c2ecf20Sopenharmony_ci	     adapter->iface_limit.sta_intf)) {
10388c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
10398c2ecf20Sopenharmony_ci			    "cannot create multiple station/adhoc ifaces\n");
10408c2ecf20Sopenharmony_ci		return -1;
10418c2ecf20Sopenharmony_ci	}
10428c2ecf20Sopenharmony_ci
10438c2ecf20Sopenharmony_ci	if (type == NL80211_IFTYPE_STATION)
10448c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, INFO,
10458c2ecf20Sopenharmony_ci			    "%s: changing role to station\n", dev->name);
10468c2ecf20Sopenharmony_ci	else
10478c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, INFO,
10488c2ecf20Sopenharmony_ci			    "%s: changing role to adhoc\n", dev->name);
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci	if (mwifiex_deinit_priv_params(priv))
10518c2ecf20Sopenharmony_ci		return -1;
10528c2ecf20Sopenharmony_ci	if (mwifiex_init_new_priv_params(priv, dev, type))
10538c2ecf20Sopenharmony_ci		return -1;
10548c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
10558c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, NULL, true))
10568c2ecf20Sopenharmony_ci		return -1;
10578c2ecf20Sopenharmony_ci	if (mwifiex_sta_init_cmd(priv, false, false))
10588c2ecf20Sopenharmony_ci		return -1;
10598c2ecf20Sopenharmony_ci
10608c2ecf20Sopenharmony_ci	switch (curr_iftype) {
10618c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_CLIENT:
10628c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_GO:
10638c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.p2p_intf--;
10648c2ecf20Sopenharmony_ci		break;
10658c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
10668c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.uap_intf--;
10678c2ecf20Sopenharmony_ci		break;
10688c2ecf20Sopenharmony_ci	default:
10698c2ecf20Sopenharmony_ci		break;
10708c2ecf20Sopenharmony_ci	}
10718c2ecf20Sopenharmony_ci
10728c2ecf20Sopenharmony_ci	adapter->curr_iface_comb.sta_intf++;
10738c2ecf20Sopenharmony_ci	dev->ieee80211_ptr->iftype = type;
10748c2ecf20Sopenharmony_ci	return 0;
10758c2ecf20Sopenharmony_ci}
10768c2ecf20Sopenharmony_ci
10778c2ecf20Sopenharmony_cistatic int
10788c2ecf20Sopenharmony_cimwifiex_change_vif_to_ap(struct net_device *dev,
10798c2ecf20Sopenharmony_ci			 enum nl80211_iftype curr_iftype,
10808c2ecf20Sopenharmony_ci			 enum nl80211_iftype type,
10818c2ecf20Sopenharmony_ci			 struct vif_params *params)
10828c2ecf20Sopenharmony_ci{
10838c2ecf20Sopenharmony_ci	struct mwifiex_private *priv;
10848c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter;
10858c2ecf20Sopenharmony_ci
10868c2ecf20Sopenharmony_ci	priv = mwifiex_netdev_get_priv(dev);
10878c2ecf20Sopenharmony_ci
10888c2ecf20Sopenharmony_ci	if (!priv)
10898c2ecf20Sopenharmony_ci		return -1;
10908c2ecf20Sopenharmony_ci
10918c2ecf20Sopenharmony_ci	adapter = priv->adapter;
10928c2ecf20Sopenharmony_ci
10938c2ecf20Sopenharmony_ci	if (adapter->curr_iface_comb.uap_intf ==
10948c2ecf20Sopenharmony_ci	    adapter->iface_limit.uap_intf) {
10958c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
10968c2ecf20Sopenharmony_ci			    "cannot create multiple AP ifaces\n");
10978c2ecf20Sopenharmony_ci		return -1;
10988c2ecf20Sopenharmony_ci	}
10998c2ecf20Sopenharmony_ci
11008c2ecf20Sopenharmony_ci	mwifiex_dbg(adapter, INFO,
11018c2ecf20Sopenharmony_ci		    "%s: changing role to AP\n", dev->name);
11028c2ecf20Sopenharmony_ci
11038c2ecf20Sopenharmony_ci	if (mwifiex_deinit_priv_params(priv))
11048c2ecf20Sopenharmony_ci		return -1;
11058c2ecf20Sopenharmony_ci	if (mwifiex_init_new_priv_params(priv, dev, type))
11068c2ecf20Sopenharmony_ci		return -1;
11078c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
11088c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, NULL, true))
11098c2ecf20Sopenharmony_ci		return -1;
11108c2ecf20Sopenharmony_ci	if (mwifiex_sta_init_cmd(priv, false, false))
11118c2ecf20Sopenharmony_ci		return -1;
11128c2ecf20Sopenharmony_ci
11138c2ecf20Sopenharmony_ci	switch (curr_iftype) {
11148c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_CLIENT:
11158c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_GO:
11168c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.p2p_intf--;
11178c2ecf20Sopenharmony_ci		break;
11188c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
11198c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_ADHOC:
11208c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.sta_intf--;
11218c2ecf20Sopenharmony_ci		break;
11228c2ecf20Sopenharmony_ci	default:
11238c2ecf20Sopenharmony_ci		break;
11248c2ecf20Sopenharmony_ci	}
11258c2ecf20Sopenharmony_ci
11268c2ecf20Sopenharmony_ci	adapter->curr_iface_comb.uap_intf++;
11278c2ecf20Sopenharmony_ci	dev->ieee80211_ptr->iftype = type;
11288c2ecf20Sopenharmony_ci	return 0;
11298c2ecf20Sopenharmony_ci}
11308c2ecf20Sopenharmony_ci/*
11318c2ecf20Sopenharmony_ci * CFG802.11 operation handler to change interface type.
11328c2ecf20Sopenharmony_ci */
11338c2ecf20Sopenharmony_cistatic int
11348c2ecf20Sopenharmony_cimwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
11358c2ecf20Sopenharmony_ci				     struct net_device *dev,
11368c2ecf20Sopenharmony_ci				     enum nl80211_iftype type,
11378c2ecf20Sopenharmony_ci				     struct vif_params *params)
11388c2ecf20Sopenharmony_ci{
11398c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
11408c2ecf20Sopenharmony_ci	enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype;
11418c2ecf20Sopenharmony_ci
11428c2ecf20Sopenharmony_ci	if (priv->scan_request) {
11438c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
11448c2ecf20Sopenharmony_ci			    "change virtual interface: scan in process\n");
11458c2ecf20Sopenharmony_ci		return -EBUSY;
11468c2ecf20Sopenharmony_ci	}
11478c2ecf20Sopenharmony_ci
11488c2ecf20Sopenharmony_ci	switch (curr_iftype) {
11498c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_ADHOC:
11508c2ecf20Sopenharmony_ci		switch (type) {
11518c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_STATION:
11528c2ecf20Sopenharmony_ci			priv->bss_mode = type;
11538c2ecf20Sopenharmony_ci			priv->sec_info.authentication_mode =
11548c2ecf20Sopenharmony_ci						   NL80211_AUTHTYPE_OPEN_SYSTEM;
11558c2ecf20Sopenharmony_ci			dev->ieee80211_ptr->iftype = type;
11568c2ecf20Sopenharmony_ci			mwifiex_deauthenticate(priv, NULL);
11578c2ecf20Sopenharmony_ci			return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
11588c2ecf20Sopenharmony_ci						HostCmd_ACT_GEN_SET, 0, NULL,
11598c2ecf20Sopenharmony_ci						true);
11608c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_P2P_CLIENT:
11618c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_P2P_GO:
11628c2ecf20Sopenharmony_ci			return mwifiex_change_vif_to_p2p(dev, curr_iftype,
11638c2ecf20Sopenharmony_ci							 type, params);
11648c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_AP:
11658c2ecf20Sopenharmony_ci			return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
11668c2ecf20Sopenharmony_ci							params);
11678c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_UNSPECIFIED:
11688c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, INFO,
11698c2ecf20Sopenharmony_ci				    "%s: kept type as IBSS\n", dev->name);
11708c2ecf20Sopenharmony_ci			fallthrough;
11718c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_ADHOC:	/* This shouldn't happen */
11728c2ecf20Sopenharmony_ci			return 0;
11738c2ecf20Sopenharmony_ci		default:
11748c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, ERROR,
11758c2ecf20Sopenharmony_ci				    "%s: changing to %d not supported\n",
11768c2ecf20Sopenharmony_ci				    dev->name, type);
11778c2ecf20Sopenharmony_ci			return -EOPNOTSUPP;
11788c2ecf20Sopenharmony_ci		}
11798c2ecf20Sopenharmony_ci		break;
11808c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
11818c2ecf20Sopenharmony_ci		switch (type) {
11828c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_ADHOC:
11838c2ecf20Sopenharmony_ci			priv->bss_mode = type;
11848c2ecf20Sopenharmony_ci			priv->sec_info.authentication_mode =
11858c2ecf20Sopenharmony_ci						   NL80211_AUTHTYPE_OPEN_SYSTEM;
11868c2ecf20Sopenharmony_ci			dev->ieee80211_ptr->iftype = type;
11878c2ecf20Sopenharmony_ci			mwifiex_deauthenticate(priv, NULL);
11888c2ecf20Sopenharmony_ci			return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
11898c2ecf20Sopenharmony_ci						HostCmd_ACT_GEN_SET, 0, NULL,
11908c2ecf20Sopenharmony_ci						true);
11918c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_P2P_CLIENT:
11928c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_P2P_GO:
11938c2ecf20Sopenharmony_ci			return mwifiex_change_vif_to_p2p(dev, curr_iftype,
11948c2ecf20Sopenharmony_ci							 type, params);
11958c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_AP:
11968c2ecf20Sopenharmony_ci			return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
11978c2ecf20Sopenharmony_ci							params);
11988c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_UNSPECIFIED:
11998c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, INFO,
12008c2ecf20Sopenharmony_ci				    "%s: kept type as STA\n", dev->name);
12018c2ecf20Sopenharmony_ci			fallthrough;
12028c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_STATION:	/* This shouldn't happen */
12038c2ecf20Sopenharmony_ci			return 0;
12048c2ecf20Sopenharmony_ci		default:
12058c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, ERROR,
12068c2ecf20Sopenharmony_ci				    "%s: changing to %d not supported\n",
12078c2ecf20Sopenharmony_ci				    dev->name, type);
12088c2ecf20Sopenharmony_ci			return -EOPNOTSUPP;
12098c2ecf20Sopenharmony_ci		}
12108c2ecf20Sopenharmony_ci		break;
12118c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
12128c2ecf20Sopenharmony_ci		switch (type) {
12138c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_ADHOC:
12148c2ecf20Sopenharmony_ci			return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
12158c2ecf20Sopenharmony_ci							       type, params);
12168c2ecf20Sopenharmony_ci			break;
12178c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_P2P_CLIENT:
12188c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_P2P_GO:
12198c2ecf20Sopenharmony_ci			return mwifiex_change_vif_to_p2p(dev, curr_iftype,
12208c2ecf20Sopenharmony_ci							 type, params);
12218c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_UNSPECIFIED:
12228c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, INFO,
12238c2ecf20Sopenharmony_ci				    "%s: kept type as AP\n", dev->name);
12248c2ecf20Sopenharmony_ci			fallthrough;
12258c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_AP:		/* This shouldn't happen */
12268c2ecf20Sopenharmony_ci			return 0;
12278c2ecf20Sopenharmony_ci		default:
12288c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, ERROR,
12298c2ecf20Sopenharmony_ci				    "%s: changing to %d not supported\n",
12308c2ecf20Sopenharmony_ci				    dev->name, type);
12318c2ecf20Sopenharmony_ci			return -EOPNOTSUPP;
12328c2ecf20Sopenharmony_ci		}
12338c2ecf20Sopenharmony_ci		break;
12348c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_CLIENT:
12358c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_GO:
12368c2ecf20Sopenharmony_ci		if (mwifiex_cfg80211_deinit_p2p(priv))
12378c2ecf20Sopenharmony_ci			return -EFAULT;
12388c2ecf20Sopenharmony_ci
12398c2ecf20Sopenharmony_ci		switch (type) {
12408c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_ADHOC:
12418c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_STATION:
12428c2ecf20Sopenharmony_ci			return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype,
12438c2ecf20Sopenharmony_ci							       type, params);
12448c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_AP:
12458c2ecf20Sopenharmony_ci			return mwifiex_change_vif_to_ap(dev, curr_iftype, type,
12468c2ecf20Sopenharmony_ci							params);
12478c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_UNSPECIFIED:
12488c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, INFO,
12498c2ecf20Sopenharmony_ci				    "%s: kept type as P2P\n", dev->name);
12508c2ecf20Sopenharmony_ci			fallthrough;
12518c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_P2P_CLIENT:
12528c2ecf20Sopenharmony_ci		case NL80211_IFTYPE_P2P_GO:
12538c2ecf20Sopenharmony_ci			return 0;
12548c2ecf20Sopenharmony_ci		default:
12558c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, ERROR,
12568c2ecf20Sopenharmony_ci				    "%s: changing to %d not supported\n",
12578c2ecf20Sopenharmony_ci				    dev->name, type);
12588c2ecf20Sopenharmony_ci			return -EOPNOTSUPP;
12598c2ecf20Sopenharmony_ci		}
12608c2ecf20Sopenharmony_ci		break;
12618c2ecf20Sopenharmony_ci	default:
12628c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
12638c2ecf20Sopenharmony_ci			    "%s: unknown iftype: %d\n",
12648c2ecf20Sopenharmony_ci			    dev->name, dev->ieee80211_ptr->iftype);
12658c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
12668c2ecf20Sopenharmony_ci	}
12678c2ecf20Sopenharmony_ci
12688c2ecf20Sopenharmony_ci
12698c2ecf20Sopenharmony_ci	return 0;
12708c2ecf20Sopenharmony_ci}
12718c2ecf20Sopenharmony_ci
12728c2ecf20Sopenharmony_cistatic void
12738c2ecf20Sopenharmony_cimwifiex_parse_htinfo(struct mwifiex_private *priv, u8 rateinfo, u8 htinfo,
12748c2ecf20Sopenharmony_ci		     struct rate_info *rate)
12758c2ecf20Sopenharmony_ci{
12768c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
12778c2ecf20Sopenharmony_ci
12788c2ecf20Sopenharmony_ci	if (adapter->is_hw_11ac_capable) {
12798c2ecf20Sopenharmony_ci		/* bit[1-0]: 00=LG 01=HT 10=VHT */
12808c2ecf20Sopenharmony_ci		if (htinfo & BIT(0)) {
12818c2ecf20Sopenharmony_ci			/* HT */
12828c2ecf20Sopenharmony_ci			rate->mcs = rateinfo;
12838c2ecf20Sopenharmony_ci			rate->flags |= RATE_INFO_FLAGS_MCS;
12848c2ecf20Sopenharmony_ci		}
12858c2ecf20Sopenharmony_ci		if (htinfo & BIT(1)) {
12868c2ecf20Sopenharmony_ci			/* VHT */
12878c2ecf20Sopenharmony_ci			rate->mcs = rateinfo & 0x0F;
12888c2ecf20Sopenharmony_ci			rate->flags |= RATE_INFO_FLAGS_VHT_MCS;
12898c2ecf20Sopenharmony_ci		}
12908c2ecf20Sopenharmony_ci
12918c2ecf20Sopenharmony_ci		if (htinfo & (BIT(1) | BIT(0))) {
12928c2ecf20Sopenharmony_ci			/* HT or VHT */
12938c2ecf20Sopenharmony_ci			switch (htinfo & (BIT(3) | BIT(2))) {
12948c2ecf20Sopenharmony_ci			case 0:
12958c2ecf20Sopenharmony_ci				rate->bw = RATE_INFO_BW_20;
12968c2ecf20Sopenharmony_ci				break;
12978c2ecf20Sopenharmony_ci			case (BIT(2)):
12988c2ecf20Sopenharmony_ci				rate->bw = RATE_INFO_BW_40;
12998c2ecf20Sopenharmony_ci				break;
13008c2ecf20Sopenharmony_ci			case (BIT(3)):
13018c2ecf20Sopenharmony_ci				rate->bw = RATE_INFO_BW_80;
13028c2ecf20Sopenharmony_ci				break;
13038c2ecf20Sopenharmony_ci			case (BIT(3) | BIT(2)):
13048c2ecf20Sopenharmony_ci				rate->bw = RATE_INFO_BW_160;
13058c2ecf20Sopenharmony_ci				break;
13068c2ecf20Sopenharmony_ci			}
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_ci			if (htinfo & BIT(4))
13098c2ecf20Sopenharmony_ci				rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
13108c2ecf20Sopenharmony_ci
13118c2ecf20Sopenharmony_ci			if ((rateinfo >> 4) == 1)
13128c2ecf20Sopenharmony_ci				rate->nss = 2;
13138c2ecf20Sopenharmony_ci			else
13148c2ecf20Sopenharmony_ci				rate->nss = 1;
13158c2ecf20Sopenharmony_ci		}
13168c2ecf20Sopenharmony_ci	} else {
13178c2ecf20Sopenharmony_ci		/*
13188c2ecf20Sopenharmony_ci		 * Bit 0 in htinfo indicates that current rate is 11n. Valid
13198c2ecf20Sopenharmony_ci		 * MCS index values for us are 0 to 15.
13208c2ecf20Sopenharmony_ci		 */
13218c2ecf20Sopenharmony_ci		if ((htinfo & BIT(0)) && (rateinfo < 16)) {
13228c2ecf20Sopenharmony_ci			rate->mcs = rateinfo;
13238c2ecf20Sopenharmony_ci			rate->flags |= RATE_INFO_FLAGS_MCS;
13248c2ecf20Sopenharmony_ci			rate->bw = RATE_INFO_BW_20;
13258c2ecf20Sopenharmony_ci			if (htinfo & BIT(1))
13268c2ecf20Sopenharmony_ci				rate->bw = RATE_INFO_BW_40;
13278c2ecf20Sopenharmony_ci			if (htinfo & BIT(2))
13288c2ecf20Sopenharmony_ci				rate->flags |= RATE_INFO_FLAGS_SHORT_GI;
13298c2ecf20Sopenharmony_ci		}
13308c2ecf20Sopenharmony_ci	}
13318c2ecf20Sopenharmony_ci
13328c2ecf20Sopenharmony_ci	/* Decode legacy rates for non-HT. */
13338c2ecf20Sopenharmony_ci	if (!(htinfo & (BIT(0) | BIT(1)))) {
13348c2ecf20Sopenharmony_ci		/* Bitrates in multiples of 100kb/s. */
13358c2ecf20Sopenharmony_ci		static const int legacy_rates[] = {
13368c2ecf20Sopenharmony_ci			[0] = 10,
13378c2ecf20Sopenharmony_ci			[1] = 20,
13388c2ecf20Sopenharmony_ci			[2] = 55,
13398c2ecf20Sopenharmony_ci			[3] = 110,
13408c2ecf20Sopenharmony_ci			[4] = 60, /* MWIFIEX_RATE_INDEX_OFDM0 */
13418c2ecf20Sopenharmony_ci			[5] = 60,
13428c2ecf20Sopenharmony_ci			[6] = 90,
13438c2ecf20Sopenharmony_ci			[7] = 120,
13448c2ecf20Sopenharmony_ci			[8] = 180,
13458c2ecf20Sopenharmony_ci			[9] = 240,
13468c2ecf20Sopenharmony_ci			[10] = 360,
13478c2ecf20Sopenharmony_ci			[11] = 480,
13488c2ecf20Sopenharmony_ci			[12] = 540,
13498c2ecf20Sopenharmony_ci		};
13508c2ecf20Sopenharmony_ci		if (rateinfo < ARRAY_SIZE(legacy_rates))
13518c2ecf20Sopenharmony_ci			rate->legacy = legacy_rates[rateinfo];
13528c2ecf20Sopenharmony_ci	}
13538c2ecf20Sopenharmony_ci}
13548c2ecf20Sopenharmony_ci
13558c2ecf20Sopenharmony_ci/*
13568c2ecf20Sopenharmony_ci * This function dumps the station information on a buffer.
13578c2ecf20Sopenharmony_ci *
13588c2ecf20Sopenharmony_ci * The following information are shown -
13598c2ecf20Sopenharmony_ci *      - Total bytes transmitted
13608c2ecf20Sopenharmony_ci *      - Total bytes received
13618c2ecf20Sopenharmony_ci *      - Total packets transmitted
13628c2ecf20Sopenharmony_ci *      - Total packets received
13638c2ecf20Sopenharmony_ci *      - Signal quality level
13648c2ecf20Sopenharmony_ci *      - Transmission rate
13658c2ecf20Sopenharmony_ci */
13668c2ecf20Sopenharmony_cistatic int
13678c2ecf20Sopenharmony_cimwifiex_dump_station_info(struct mwifiex_private *priv,
13688c2ecf20Sopenharmony_ci			  struct mwifiex_sta_node *node,
13698c2ecf20Sopenharmony_ci			  struct station_info *sinfo)
13708c2ecf20Sopenharmony_ci{
13718c2ecf20Sopenharmony_ci	u32 rate;
13728c2ecf20Sopenharmony_ci
13738c2ecf20Sopenharmony_ci	sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) | BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
13748c2ecf20Sopenharmony_ci			BIT_ULL(NL80211_STA_INFO_RX_PACKETS) | BIT_ULL(NL80211_STA_INFO_TX_PACKETS) |
13758c2ecf20Sopenharmony_ci			BIT_ULL(NL80211_STA_INFO_TX_BITRATE) |
13768c2ecf20Sopenharmony_ci			BIT_ULL(NL80211_STA_INFO_SIGNAL) | BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
13778c2ecf20Sopenharmony_ci
13788c2ecf20Sopenharmony_ci	if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
13798c2ecf20Sopenharmony_ci		if (!node)
13808c2ecf20Sopenharmony_ci			return -ENOENT;
13818c2ecf20Sopenharmony_ci
13828c2ecf20Sopenharmony_ci		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
13838c2ecf20Sopenharmony_ci				BIT_ULL(NL80211_STA_INFO_TX_FAILED);
13848c2ecf20Sopenharmony_ci		sinfo->inactive_time =
13858c2ecf20Sopenharmony_ci			jiffies_to_msecs(jiffies - node->stats.last_rx);
13868c2ecf20Sopenharmony_ci
13878c2ecf20Sopenharmony_ci		sinfo->signal = node->stats.rssi;
13888c2ecf20Sopenharmony_ci		sinfo->signal_avg = node->stats.rssi;
13898c2ecf20Sopenharmony_ci		sinfo->rx_bytes = node->stats.rx_bytes;
13908c2ecf20Sopenharmony_ci		sinfo->tx_bytes = node->stats.tx_bytes;
13918c2ecf20Sopenharmony_ci		sinfo->rx_packets = node->stats.rx_packets;
13928c2ecf20Sopenharmony_ci		sinfo->tx_packets = node->stats.tx_packets;
13938c2ecf20Sopenharmony_ci		sinfo->tx_failed = node->stats.tx_failed;
13948c2ecf20Sopenharmony_ci
13958c2ecf20Sopenharmony_ci		mwifiex_parse_htinfo(priv, priv->tx_rate,
13968c2ecf20Sopenharmony_ci				     node->stats.last_tx_htinfo,
13978c2ecf20Sopenharmony_ci				     &sinfo->txrate);
13988c2ecf20Sopenharmony_ci		sinfo->txrate.legacy = node->stats.last_tx_rate * 5;
13998c2ecf20Sopenharmony_ci
14008c2ecf20Sopenharmony_ci		return 0;
14018c2ecf20Sopenharmony_ci	}
14028c2ecf20Sopenharmony_ci
14038c2ecf20Sopenharmony_ci	/* Get signal information from the firmware */
14048c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
14058c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_GET, 0, NULL, true)) {
14068c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
14078c2ecf20Sopenharmony_ci			    "failed to get signal information\n");
14088c2ecf20Sopenharmony_ci		return -EFAULT;
14098c2ecf20Sopenharmony_ci	}
14108c2ecf20Sopenharmony_ci
14118c2ecf20Sopenharmony_ci	if (mwifiex_drv_get_data_rate(priv, &rate)) {
14128c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
14138c2ecf20Sopenharmony_ci			    "getting data rate error\n");
14148c2ecf20Sopenharmony_ci		return -EFAULT;
14158c2ecf20Sopenharmony_ci	}
14168c2ecf20Sopenharmony_ci
14178c2ecf20Sopenharmony_ci	/* Get DTIM period information from firmware */
14188c2ecf20Sopenharmony_ci	mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
14198c2ecf20Sopenharmony_ci			 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I,
14208c2ecf20Sopenharmony_ci			 &priv->dtim_period, true);
14218c2ecf20Sopenharmony_ci
14228c2ecf20Sopenharmony_ci	mwifiex_parse_htinfo(priv, priv->tx_rate, priv->tx_htinfo,
14238c2ecf20Sopenharmony_ci			     &sinfo->txrate);
14248c2ecf20Sopenharmony_ci
14258c2ecf20Sopenharmony_ci	sinfo->signal_avg = priv->bcn_rssi_avg;
14268c2ecf20Sopenharmony_ci	sinfo->rx_bytes = priv->stats.rx_bytes;
14278c2ecf20Sopenharmony_ci	sinfo->tx_bytes = priv->stats.tx_bytes;
14288c2ecf20Sopenharmony_ci	sinfo->rx_packets = priv->stats.rx_packets;
14298c2ecf20Sopenharmony_ci	sinfo->tx_packets = priv->stats.tx_packets;
14308c2ecf20Sopenharmony_ci	sinfo->signal = priv->bcn_rssi_avg;
14318c2ecf20Sopenharmony_ci	/* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
14328c2ecf20Sopenharmony_ci	sinfo->txrate.legacy = rate * 5;
14338c2ecf20Sopenharmony_ci
14348c2ecf20Sopenharmony_ci	sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
14358c2ecf20Sopenharmony_ci	mwifiex_parse_htinfo(priv, priv->rxpd_rate, priv->rxpd_htinfo,
14368c2ecf20Sopenharmony_ci			     &sinfo->rxrate);
14378c2ecf20Sopenharmony_ci
14388c2ecf20Sopenharmony_ci	if (priv->bss_mode == NL80211_IFTYPE_STATION) {
14398c2ecf20Sopenharmony_ci		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM);
14408c2ecf20Sopenharmony_ci		sinfo->bss_param.flags = 0;
14418c2ecf20Sopenharmony_ci		if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
14428c2ecf20Sopenharmony_ci						WLAN_CAPABILITY_SHORT_PREAMBLE)
14438c2ecf20Sopenharmony_ci			sinfo->bss_param.flags |=
14448c2ecf20Sopenharmony_ci					BSS_PARAM_FLAGS_SHORT_PREAMBLE;
14458c2ecf20Sopenharmony_ci		if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap &
14468c2ecf20Sopenharmony_ci						WLAN_CAPABILITY_SHORT_SLOT_TIME)
14478c2ecf20Sopenharmony_ci			sinfo->bss_param.flags |=
14488c2ecf20Sopenharmony_ci					BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
14498c2ecf20Sopenharmony_ci		sinfo->bss_param.dtim_period = priv->dtim_period;
14508c2ecf20Sopenharmony_ci		sinfo->bss_param.beacon_interval =
14518c2ecf20Sopenharmony_ci			priv->curr_bss_params.bss_descriptor.beacon_period;
14528c2ecf20Sopenharmony_ci	}
14538c2ecf20Sopenharmony_ci
14548c2ecf20Sopenharmony_ci	return 0;
14558c2ecf20Sopenharmony_ci}
14568c2ecf20Sopenharmony_ci
14578c2ecf20Sopenharmony_ci/*
14588c2ecf20Sopenharmony_ci * CFG802.11 operation handler to get station information.
14598c2ecf20Sopenharmony_ci *
14608c2ecf20Sopenharmony_ci * This function only works in connected mode, and dumps the
14618c2ecf20Sopenharmony_ci * requested station information, if available.
14628c2ecf20Sopenharmony_ci */
14638c2ecf20Sopenharmony_cistatic int
14648c2ecf20Sopenharmony_cimwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
14658c2ecf20Sopenharmony_ci			     const u8 *mac, struct station_info *sinfo)
14668c2ecf20Sopenharmony_ci{
14678c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
14688c2ecf20Sopenharmony_ci
14698c2ecf20Sopenharmony_ci	if (!priv->media_connected)
14708c2ecf20Sopenharmony_ci		return -ENOENT;
14718c2ecf20Sopenharmony_ci	if (memcmp(mac, priv->cfg_bssid, ETH_ALEN))
14728c2ecf20Sopenharmony_ci		return -ENOENT;
14738c2ecf20Sopenharmony_ci
14748c2ecf20Sopenharmony_ci	return mwifiex_dump_station_info(priv, NULL, sinfo);
14758c2ecf20Sopenharmony_ci}
14768c2ecf20Sopenharmony_ci
14778c2ecf20Sopenharmony_ci/*
14788c2ecf20Sopenharmony_ci * CFG802.11 operation handler to dump station information.
14798c2ecf20Sopenharmony_ci */
14808c2ecf20Sopenharmony_cistatic int
14818c2ecf20Sopenharmony_cimwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
14828c2ecf20Sopenharmony_ci			      int idx, u8 *mac, struct station_info *sinfo)
14838c2ecf20Sopenharmony_ci{
14848c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
14858c2ecf20Sopenharmony_ci	struct mwifiex_sta_node *node;
14868c2ecf20Sopenharmony_ci	int i;
14878c2ecf20Sopenharmony_ci
14888c2ecf20Sopenharmony_ci	if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
14898c2ecf20Sopenharmony_ci	    priv->media_connected && idx == 0) {
14908c2ecf20Sopenharmony_ci		ether_addr_copy(mac, priv->cfg_bssid);
14918c2ecf20Sopenharmony_ci		return mwifiex_dump_station_info(priv, NULL, sinfo);
14928c2ecf20Sopenharmony_ci	} else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
14938c2ecf20Sopenharmony_ci		mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST,
14948c2ecf20Sopenharmony_ci				 HostCmd_ACT_GEN_GET, 0, NULL, true);
14958c2ecf20Sopenharmony_ci
14968c2ecf20Sopenharmony_ci		i = 0;
14978c2ecf20Sopenharmony_ci		list_for_each_entry(node, &priv->sta_list, list) {
14988c2ecf20Sopenharmony_ci			if (i++ != idx)
14998c2ecf20Sopenharmony_ci				continue;
15008c2ecf20Sopenharmony_ci			ether_addr_copy(mac, node->mac_addr);
15018c2ecf20Sopenharmony_ci			return mwifiex_dump_station_info(priv, node, sinfo);
15028c2ecf20Sopenharmony_ci		}
15038c2ecf20Sopenharmony_ci	}
15048c2ecf20Sopenharmony_ci
15058c2ecf20Sopenharmony_ci	return -ENOENT;
15068c2ecf20Sopenharmony_ci}
15078c2ecf20Sopenharmony_ci
15088c2ecf20Sopenharmony_cistatic int
15098c2ecf20Sopenharmony_cimwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
15108c2ecf20Sopenharmony_ci			     int idx, struct survey_info *survey)
15118c2ecf20Sopenharmony_ci{
15128c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
15138c2ecf20Sopenharmony_ci	struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats;
15148c2ecf20Sopenharmony_ci	enum nl80211_band band;
15158c2ecf20Sopenharmony_ci
15168c2ecf20Sopenharmony_ci	mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx);
15178c2ecf20Sopenharmony_ci
15188c2ecf20Sopenharmony_ci	memset(survey, 0, sizeof(struct survey_info));
15198c2ecf20Sopenharmony_ci
15208c2ecf20Sopenharmony_ci	if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
15218c2ecf20Sopenharmony_ci	    priv->media_connected && idx == 0) {
15228c2ecf20Sopenharmony_ci			u8 curr_bss_band = priv->curr_bss_params.band;
15238c2ecf20Sopenharmony_ci			u32 chan = priv->curr_bss_params.bss_descriptor.channel;
15248c2ecf20Sopenharmony_ci
15258c2ecf20Sopenharmony_ci			band = mwifiex_band_to_radio_type(curr_bss_band);
15268c2ecf20Sopenharmony_ci			survey->channel = ieee80211_get_channel(wiphy,
15278c2ecf20Sopenharmony_ci				ieee80211_channel_to_frequency(chan, band));
15288c2ecf20Sopenharmony_ci
15298c2ecf20Sopenharmony_ci			if (priv->bcn_nf_last) {
15308c2ecf20Sopenharmony_ci				survey->filled = SURVEY_INFO_NOISE_DBM;
15318c2ecf20Sopenharmony_ci				survey->noise = priv->bcn_nf_last;
15328c2ecf20Sopenharmony_ci			}
15338c2ecf20Sopenharmony_ci			return 0;
15348c2ecf20Sopenharmony_ci	}
15358c2ecf20Sopenharmony_ci
15368c2ecf20Sopenharmony_ci	if (idx >= priv->adapter->num_in_chan_stats)
15378c2ecf20Sopenharmony_ci		return -ENOENT;
15388c2ecf20Sopenharmony_ci
15398c2ecf20Sopenharmony_ci	if (!pchan_stats[idx].cca_scan_dur)
15408c2ecf20Sopenharmony_ci		return 0;
15418c2ecf20Sopenharmony_ci
15428c2ecf20Sopenharmony_ci	band = pchan_stats[idx].bandcfg;
15438c2ecf20Sopenharmony_ci	survey->channel = ieee80211_get_channel(wiphy,
15448c2ecf20Sopenharmony_ci	    ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band));
15458c2ecf20Sopenharmony_ci	survey->filled = SURVEY_INFO_NOISE_DBM |
15468c2ecf20Sopenharmony_ci			 SURVEY_INFO_TIME |
15478c2ecf20Sopenharmony_ci			 SURVEY_INFO_TIME_BUSY;
15488c2ecf20Sopenharmony_ci	survey->noise = pchan_stats[idx].noise;
15498c2ecf20Sopenharmony_ci	survey->time = pchan_stats[idx].cca_scan_dur;
15508c2ecf20Sopenharmony_ci	survey->time_busy = pchan_stats[idx].cca_busy_dur;
15518c2ecf20Sopenharmony_ci
15528c2ecf20Sopenharmony_ci	return 0;
15538c2ecf20Sopenharmony_ci}
15548c2ecf20Sopenharmony_ci
15558c2ecf20Sopenharmony_ci/* Supported rates to be advertised to the cfg80211 */
15568c2ecf20Sopenharmony_cistatic struct ieee80211_rate mwifiex_rates[] = {
15578c2ecf20Sopenharmony_ci	{.bitrate = 10, .hw_value = 2, },
15588c2ecf20Sopenharmony_ci	{.bitrate = 20, .hw_value = 4, },
15598c2ecf20Sopenharmony_ci	{.bitrate = 55, .hw_value = 11, },
15608c2ecf20Sopenharmony_ci	{.bitrate = 110, .hw_value = 22, },
15618c2ecf20Sopenharmony_ci	{.bitrate = 60, .hw_value = 12, },
15628c2ecf20Sopenharmony_ci	{.bitrate = 90, .hw_value = 18, },
15638c2ecf20Sopenharmony_ci	{.bitrate = 120, .hw_value = 24, },
15648c2ecf20Sopenharmony_ci	{.bitrate = 180, .hw_value = 36, },
15658c2ecf20Sopenharmony_ci	{.bitrate = 240, .hw_value = 48, },
15668c2ecf20Sopenharmony_ci	{.bitrate = 360, .hw_value = 72, },
15678c2ecf20Sopenharmony_ci	{.bitrate = 480, .hw_value = 96, },
15688c2ecf20Sopenharmony_ci	{.bitrate = 540, .hw_value = 108, },
15698c2ecf20Sopenharmony_ci};
15708c2ecf20Sopenharmony_ci
15718c2ecf20Sopenharmony_ci/* Channel definitions to be advertised to cfg80211 */
15728c2ecf20Sopenharmony_cistatic struct ieee80211_channel mwifiex_channels_2ghz[] = {
15738c2ecf20Sopenharmony_ci	{.center_freq = 2412, .hw_value = 1, },
15748c2ecf20Sopenharmony_ci	{.center_freq = 2417, .hw_value = 2, },
15758c2ecf20Sopenharmony_ci	{.center_freq = 2422, .hw_value = 3, },
15768c2ecf20Sopenharmony_ci	{.center_freq = 2427, .hw_value = 4, },
15778c2ecf20Sopenharmony_ci	{.center_freq = 2432, .hw_value = 5, },
15788c2ecf20Sopenharmony_ci	{.center_freq = 2437, .hw_value = 6, },
15798c2ecf20Sopenharmony_ci	{.center_freq = 2442, .hw_value = 7, },
15808c2ecf20Sopenharmony_ci	{.center_freq = 2447, .hw_value = 8, },
15818c2ecf20Sopenharmony_ci	{.center_freq = 2452, .hw_value = 9, },
15828c2ecf20Sopenharmony_ci	{.center_freq = 2457, .hw_value = 10, },
15838c2ecf20Sopenharmony_ci	{.center_freq = 2462, .hw_value = 11, },
15848c2ecf20Sopenharmony_ci	{.center_freq = 2467, .hw_value = 12, },
15858c2ecf20Sopenharmony_ci	{.center_freq = 2472, .hw_value = 13, },
15868c2ecf20Sopenharmony_ci	{.center_freq = 2484, .hw_value = 14, },
15878c2ecf20Sopenharmony_ci};
15888c2ecf20Sopenharmony_ci
15898c2ecf20Sopenharmony_cistatic struct ieee80211_supported_band mwifiex_band_2ghz = {
15908c2ecf20Sopenharmony_ci	.channels = mwifiex_channels_2ghz,
15918c2ecf20Sopenharmony_ci	.n_channels = ARRAY_SIZE(mwifiex_channels_2ghz),
15928c2ecf20Sopenharmony_ci	.bitrates = mwifiex_rates,
15938c2ecf20Sopenharmony_ci	.n_bitrates = ARRAY_SIZE(mwifiex_rates),
15948c2ecf20Sopenharmony_ci};
15958c2ecf20Sopenharmony_ci
15968c2ecf20Sopenharmony_cistatic struct ieee80211_channel mwifiex_channels_5ghz[] = {
15978c2ecf20Sopenharmony_ci	{.center_freq = 5040, .hw_value = 8, },
15988c2ecf20Sopenharmony_ci	{.center_freq = 5060, .hw_value = 12, },
15998c2ecf20Sopenharmony_ci	{.center_freq = 5080, .hw_value = 16, },
16008c2ecf20Sopenharmony_ci	{.center_freq = 5170, .hw_value = 34, },
16018c2ecf20Sopenharmony_ci	{.center_freq = 5190, .hw_value = 38, },
16028c2ecf20Sopenharmony_ci	{.center_freq = 5210, .hw_value = 42, },
16038c2ecf20Sopenharmony_ci	{.center_freq = 5230, .hw_value = 46, },
16048c2ecf20Sopenharmony_ci	{.center_freq = 5180, .hw_value = 36, },
16058c2ecf20Sopenharmony_ci	{.center_freq = 5200, .hw_value = 40, },
16068c2ecf20Sopenharmony_ci	{.center_freq = 5220, .hw_value = 44, },
16078c2ecf20Sopenharmony_ci	{.center_freq = 5240, .hw_value = 48, },
16088c2ecf20Sopenharmony_ci	{.center_freq = 5260, .hw_value = 52, },
16098c2ecf20Sopenharmony_ci	{.center_freq = 5280, .hw_value = 56, },
16108c2ecf20Sopenharmony_ci	{.center_freq = 5300, .hw_value = 60, },
16118c2ecf20Sopenharmony_ci	{.center_freq = 5320, .hw_value = 64, },
16128c2ecf20Sopenharmony_ci	{.center_freq = 5500, .hw_value = 100, },
16138c2ecf20Sopenharmony_ci	{.center_freq = 5520, .hw_value = 104, },
16148c2ecf20Sopenharmony_ci	{.center_freq = 5540, .hw_value = 108, },
16158c2ecf20Sopenharmony_ci	{.center_freq = 5560, .hw_value = 112, },
16168c2ecf20Sopenharmony_ci	{.center_freq = 5580, .hw_value = 116, },
16178c2ecf20Sopenharmony_ci	{.center_freq = 5600, .hw_value = 120, },
16188c2ecf20Sopenharmony_ci	{.center_freq = 5620, .hw_value = 124, },
16198c2ecf20Sopenharmony_ci	{.center_freq = 5640, .hw_value = 128, },
16208c2ecf20Sopenharmony_ci	{.center_freq = 5660, .hw_value = 132, },
16218c2ecf20Sopenharmony_ci	{.center_freq = 5680, .hw_value = 136, },
16228c2ecf20Sopenharmony_ci	{.center_freq = 5700, .hw_value = 140, },
16238c2ecf20Sopenharmony_ci	{.center_freq = 5745, .hw_value = 149, },
16248c2ecf20Sopenharmony_ci	{.center_freq = 5765, .hw_value = 153, },
16258c2ecf20Sopenharmony_ci	{.center_freq = 5785, .hw_value = 157, },
16268c2ecf20Sopenharmony_ci	{.center_freq = 5805, .hw_value = 161, },
16278c2ecf20Sopenharmony_ci	{.center_freq = 5825, .hw_value = 165, },
16288c2ecf20Sopenharmony_ci};
16298c2ecf20Sopenharmony_ci
16308c2ecf20Sopenharmony_cistatic struct ieee80211_supported_band mwifiex_band_5ghz = {
16318c2ecf20Sopenharmony_ci	.channels = mwifiex_channels_5ghz,
16328c2ecf20Sopenharmony_ci	.n_channels = ARRAY_SIZE(mwifiex_channels_5ghz),
16338c2ecf20Sopenharmony_ci	.bitrates = mwifiex_rates + 4,
16348c2ecf20Sopenharmony_ci	.n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4,
16358c2ecf20Sopenharmony_ci};
16368c2ecf20Sopenharmony_ci
16378c2ecf20Sopenharmony_ci
16388c2ecf20Sopenharmony_ci/* Supported crypto cipher suits to be advertised to cfg80211 */
16398c2ecf20Sopenharmony_cistatic const u32 mwifiex_cipher_suites[] = {
16408c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_WEP40,
16418c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_WEP104,
16428c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_TKIP,
16438c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_CCMP,
16448c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_SMS4,
16458c2ecf20Sopenharmony_ci	WLAN_CIPHER_SUITE_AES_CMAC,
16468c2ecf20Sopenharmony_ci};
16478c2ecf20Sopenharmony_ci
16488c2ecf20Sopenharmony_ci/* Supported mgmt frame types to be advertised to cfg80211 */
16498c2ecf20Sopenharmony_cistatic const struct ieee80211_txrx_stypes
16508c2ecf20Sopenharmony_cimwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
16518c2ecf20Sopenharmony_ci	[NL80211_IFTYPE_STATION] = {
16528c2ecf20Sopenharmony_ci		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
16538c2ecf20Sopenharmony_ci		      BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
16548c2ecf20Sopenharmony_ci		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
16558c2ecf20Sopenharmony_ci		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
16568c2ecf20Sopenharmony_ci	},
16578c2ecf20Sopenharmony_ci	[NL80211_IFTYPE_AP] = {
16588c2ecf20Sopenharmony_ci		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
16598c2ecf20Sopenharmony_ci		      BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
16608c2ecf20Sopenharmony_ci		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
16618c2ecf20Sopenharmony_ci		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
16628c2ecf20Sopenharmony_ci	},
16638c2ecf20Sopenharmony_ci	[NL80211_IFTYPE_P2P_CLIENT] = {
16648c2ecf20Sopenharmony_ci		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
16658c2ecf20Sopenharmony_ci		      BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
16668c2ecf20Sopenharmony_ci		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
16678c2ecf20Sopenharmony_ci		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
16688c2ecf20Sopenharmony_ci	},
16698c2ecf20Sopenharmony_ci	[NL80211_IFTYPE_P2P_GO] = {
16708c2ecf20Sopenharmony_ci		.tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
16718c2ecf20Sopenharmony_ci		      BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
16728c2ecf20Sopenharmony_ci		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
16738c2ecf20Sopenharmony_ci		      BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
16748c2ecf20Sopenharmony_ci	},
16758c2ecf20Sopenharmony_ci};
16768c2ecf20Sopenharmony_ci
16778c2ecf20Sopenharmony_ci/*
16788c2ecf20Sopenharmony_ci * CFG802.11 operation handler for setting bit rates.
16798c2ecf20Sopenharmony_ci *
16808c2ecf20Sopenharmony_ci * Function configures data rates to firmware using bitrate mask
16818c2ecf20Sopenharmony_ci * provided by cfg80211.
16828c2ecf20Sopenharmony_ci */
16838c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
16848c2ecf20Sopenharmony_ci				struct net_device *dev,
16858c2ecf20Sopenharmony_ci				const u8 *peer,
16868c2ecf20Sopenharmony_ci				const struct cfg80211_bitrate_mask *mask)
16878c2ecf20Sopenharmony_ci{
16888c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
16898c2ecf20Sopenharmony_ci	u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
16908c2ecf20Sopenharmony_ci	enum nl80211_band band;
16918c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
16928c2ecf20Sopenharmony_ci
16938c2ecf20Sopenharmony_ci	if (!priv->media_connected) {
16948c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
16958c2ecf20Sopenharmony_ci			    "Can not set Tx data rate in disconnected state\n");
16968c2ecf20Sopenharmony_ci		return -EINVAL;
16978c2ecf20Sopenharmony_ci	}
16988c2ecf20Sopenharmony_ci
16998c2ecf20Sopenharmony_ci	band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
17008c2ecf20Sopenharmony_ci
17018c2ecf20Sopenharmony_ci	memset(bitmap_rates, 0, sizeof(bitmap_rates));
17028c2ecf20Sopenharmony_ci
17038c2ecf20Sopenharmony_ci	/* Fill HR/DSSS rates. */
17048c2ecf20Sopenharmony_ci	if (band == NL80211_BAND_2GHZ)
17058c2ecf20Sopenharmony_ci		bitmap_rates[0] = mask->control[band].legacy & 0x000f;
17068c2ecf20Sopenharmony_ci
17078c2ecf20Sopenharmony_ci	/* Fill OFDM rates */
17088c2ecf20Sopenharmony_ci	if (band == NL80211_BAND_2GHZ)
17098c2ecf20Sopenharmony_ci		bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
17108c2ecf20Sopenharmony_ci	else
17118c2ecf20Sopenharmony_ci		bitmap_rates[1] = mask->control[band].legacy;
17128c2ecf20Sopenharmony_ci
17138c2ecf20Sopenharmony_ci	/* Fill HT MCS rates */
17148c2ecf20Sopenharmony_ci	bitmap_rates[2] = mask->control[band].ht_mcs[0];
17158c2ecf20Sopenharmony_ci	if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
17168c2ecf20Sopenharmony_ci		bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8;
17178c2ecf20Sopenharmony_ci
17188c2ecf20Sopenharmony_ci       /* Fill VHT MCS rates */
17198c2ecf20Sopenharmony_ci	if (adapter->fw_api_ver == MWIFIEX_FW_V15) {
17208c2ecf20Sopenharmony_ci		bitmap_rates[10] = mask->control[band].vht_mcs[0];
17218c2ecf20Sopenharmony_ci		if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
17228c2ecf20Sopenharmony_ci			bitmap_rates[11] = mask->control[band].vht_mcs[1];
17238c2ecf20Sopenharmony_ci	}
17248c2ecf20Sopenharmony_ci
17258c2ecf20Sopenharmony_ci	return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
17268c2ecf20Sopenharmony_ci				HostCmd_ACT_GEN_SET, 0, bitmap_rates, true);
17278c2ecf20Sopenharmony_ci}
17288c2ecf20Sopenharmony_ci
17298c2ecf20Sopenharmony_ci/*
17308c2ecf20Sopenharmony_ci * CFG802.11 operation handler for connection quality monitoring.
17318c2ecf20Sopenharmony_ci *
17328c2ecf20Sopenharmony_ci * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
17338c2ecf20Sopenharmony_ci * events to FW.
17348c2ecf20Sopenharmony_ci */
17358c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
17368c2ecf20Sopenharmony_ci						struct net_device *dev,
17378c2ecf20Sopenharmony_ci						s32 rssi_thold, u32 rssi_hyst)
17388c2ecf20Sopenharmony_ci{
17398c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
17408c2ecf20Sopenharmony_ci	struct mwifiex_ds_misc_subsc_evt subsc_evt;
17418c2ecf20Sopenharmony_ci
17428c2ecf20Sopenharmony_ci	priv->cqm_rssi_thold = rssi_thold;
17438c2ecf20Sopenharmony_ci	priv->cqm_rssi_hyst = rssi_hyst;
17448c2ecf20Sopenharmony_ci
17458c2ecf20Sopenharmony_ci	memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
17468c2ecf20Sopenharmony_ci	subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
17478c2ecf20Sopenharmony_ci
17488c2ecf20Sopenharmony_ci	/* Subscribe/unsubscribe low and high rssi events */
17498c2ecf20Sopenharmony_ci	if (rssi_thold && rssi_hyst) {
17508c2ecf20Sopenharmony_ci		subsc_evt.action = HostCmd_ACT_BITWISE_SET;
17518c2ecf20Sopenharmony_ci		subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
17528c2ecf20Sopenharmony_ci		subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
17538c2ecf20Sopenharmony_ci		subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
17548c2ecf20Sopenharmony_ci		subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
17558c2ecf20Sopenharmony_ci		return mwifiex_send_cmd(priv,
17568c2ecf20Sopenharmony_ci					HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
17578c2ecf20Sopenharmony_ci					0, 0, &subsc_evt, true);
17588c2ecf20Sopenharmony_ci	} else {
17598c2ecf20Sopenharmony_ci		subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
17608c2ecf20Sopenharmony_ci		return mwifiex_send_cmd(priv,
17618c2ecf20Sopenharmony_ci					HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
17628c2ecf20Sopenharmony_ci					0, 0, &subsc_evt, true);
17638c2ecf20Sopenharmony_ci	}
17648c2ecf20Sopenharmony_ci
17658c2ecf20Sopenharmony_ci	return 0;
17668c2ecf20Sopenharmony_ci}
17678c2ecf20Sopenharmony_ci
17688c2ecf20Sopenharmony_ci/* cfg80211 operation handler for change_beacon.
17698c2ecf20Sopenharmony_ci * Function retrieves and sets modified management IEs to FW.
17708c2ecf20Sopenharmony_ci */
17718c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy,
17728c2ecf20Sopenharmony_ci					  struct net_device *dev,
17738c2ecf20Sopenharmony_ci					  struct cfg80211_beacon_data *data)
17748c2ecf20Sopenharmony_ci{
17758c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
17768c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
17778c2ecf20Sopenharmony_ci
17788c2ecf20Sopenharmony_ci	mwifiex_cancel_scan(adapter);
17798c2ecf20Sopenharmony_ci
17808c2ecf20Sopenharmony_ci	if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) {
17818c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
17828c2ecf20Sopenharmony_ci			    "%s: bss_type mismatched\n", __func__);
17838c2ecf20Sopenharmony_ci		return -EINVAL;
17848c2ecf20Sopenharmony_ci	}
17858c2ecf20Sopenharmony_ci
17868c2ecf20Sopenharmony_ci	if (!priv->bss_started) {
17878c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
17888c2ecf20Sopenharmony_ci			    "%s: bss not started\n", __func__);
17898c2ecf20Sopenharmony_ci		return -EINVAL;
17908c2ecf20Sopenharmony_ci	}
17918c2ecf20Sopenharmony_ci
17928c2ecf20Sopenharmony_ci	if (mwifiex_set_mgmt_ies(priv, data)) {
17938c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
17948c2ecf20Sopenharmony_ci			    "%s: setting mgmt ies failed\n", __func__);
17958c2ecf20Sopenharmony_ci		return -EFAULT;
17968c2ecf20Sopenharmony_ci	}
17978c2ecf20Sopenharmony_ci
17988c2ecf20Sopenharmony_ci	return 0;
17998c2ecf20Sopenharmony_ci}
18008c2ecf20Sopenharmony_ci
18018c2ecf20Sopenharmony_ci/* cfg80211 operation handler for del_station.
18028c2ecf20Sopenharmony_ci * Function deauthenticates station which value is provided in mac parameter.
18038c2ecf20Sopenharmony_ci * If mac is NULL/broadcast, all stations in associated station list are
18048c2ecf20Sopenharmony_ci * deauthenticated. If bss is not started or there are no stations in
18058c2ecf20Sopenharmony_ci * associated stations list, no action is taken.
18068c2ecf20Sopenharmony_ci */
18078c2ecf20Sopenharmony_cistatic int
18088c2ecf20Sopenharmony_cimwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev,
18098c2ecf20Sopenharmony_ci			     struct station_del_parameters *params)
18108c2ecf20Sopenharmony_ci{
18118c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
18128c2ecf20Sopenharmony_ci	struct mwifiex_sta_node *sta_node;
18138c2ecf20Sopenharmony_ci	u8 deauth_mac[ETH_ALEN];
18148c2ecf20Sopenharmony_ci
18158c2ecf20Sopenharmony_ci	if (!priv->bss_started && priv->wdev.cac_started) {
18168c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__);
18178c2ecf20Sopenharmony_ci		mwifiex_abort_cac(priv);
18188c2ecf20Sopenharmony_ci	}
18198c2ecf20Sopenharmony_ci
18208c2ecf20Sopenharmony_ci	if (list_empty(&priv->sta_list) || !priv->bss_started)
18218c2ecf20Sopenharmony_ci		return 0;
18228c2ecf20Sopenharmony_ci
18238c2ecf20Sopenharmony_ci	if (!params->mac || is_broadcast_ether_addr(params->mac))
18248c2ecf20Sopenharmony_ci		return 0;
18258c2ecf20Sopenharmony_ci
18268c2ecf20Sopenharmony_ci	mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n",
18278c2ecf20Sopenharmony_ci		    __func__, params->mac);
18288c2ecf20Sopenharmony_ci
18298c2ecf20Sopenharmony_ci	eth_zero_addr(deauth_mac);
18308c2ecf20Sopenharmony_ci
18318c2ecf20Sopenharmony_ci	spin_lock_bh(&priv->sta_list_spinlock);
18328c2ecf20Sopenharmony_ci	sta_node = mwifiex_get_sta_entry(priv, params->mac);
18338c2ecf20Sopenharmony_ci	if (sta_node)
18348c2ecf20Sopenharmony_ci		ether_addr_copy(deauth_mac, params->mac);
18358c2ecf20Sopenharmony_ci	spin_unlock_bh(&priv->sta_list_spinlock);
18368c2ecf20Sopenharmony_ci
18378c2ecf20Sopenharmony_ci	if (is_valid_ether_addr(deauth_mac)) {
18388c2ecf20Sopenharmony_ci		if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH,
18398c2ecf20Sopenharmony_ci				     HostCmd_ACT_GEN_SET, 0,
18408c2ecf20Sopenharmony_ci				     deauth_mac, true))
18418c2ecf20Sopenharmony_ci			return -1;
18428c2ecf20Sopenharmony_ci	}
18438c2ecf20Sopenharmony_ci
18448c2ecf20Sopenharmony_ci	return 0;
18458c2ecf20Sopenharmony_ci}
18468c2ecf20Sopenharmony_ci
18478c2ecf20Sopenharmony_cistatic int
18488c2ecf20Sopenharmony_cimwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
18498c2ecf20Sopenharmony_ci{
18508c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
18518c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_get_priv(adapter,
18528c2ecf20Sopenharmony_ci							MWIFIEX_BSS_ROLE_ANY);
18538c2ecf20Sopenharmony_ci	struct mwifiex_ds_ant_cfg ant_cfg;
18548c2ecf20Sopenharmony_ci
18558c2ecf20Sopenharmony_ci	if (!tx_ant || !rx_ant)
18568c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
18578c2ecf20Sopenharmony_ci
18588c2ecf20Sopenharmony_ci	if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
18598c2ecf20Sopenharmony_ci		/* Not a MIMO chip. User should provide specific antenna number
18608c2ecf20Sopenharmony_ci		 * for Tx/Rx path or enable all antennas for diversity
18618c2ecf20Sopenharmony_ci		 */
18628c2ecf20Sopenharmony_ci		if (tx_ant != rx_ant)
18638c2ecf20Sopenharmony_ci			return -EOPNOTSUPP;
18648c2ecf20Sopenharmony_ci
18658c2ecf20Sopenharmony_ci		if ((tx_ant & (tx_ant - 1)) &&
18668c2ecf20Sopenharmony_ci		    (tx_ant != BIT(adapter->number_of_antenna) - 1))
18678c2ecf20Sopenharmony_ci			return -EOPNOTSUPP;
18688c2ecf20Sopenharmony_ci
18698c2ecf20Sopenharmony_ci		if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
18708c2ecf20Sopenharmony_ci		    (priv->adapter->number_of_antenna > 1)) {
18718c2ecf20Sopenharmony_ci			tx_ant = RF_ANTENNA_AUTO;
18728c2ecf20Sopenharmony_ci			rx_ant = RF_ANTENNA_AUTO;
18738c2ecf20Sopenharmony_ci		}
18748c2ecf20Sopenharmony_ci	} else {
18758c2ecf20Sopenharmony_ci		struct ieee80211_sta_ht_cap *ht_info;
18768c2ecf20Sopenharmony_ci		int rx_mcs_supp;
18778c2ecf20Sopenharmony_ci		enum nl80211_band band;
18788c2ecf20Sopenharmony_ci
18798c2ecf20Sopenharmony_ci		if ((tx_ant == 0x1 && rx_ant == 0x1)) {
18808c2ecf20Sopenharmony_ci			adapter->user_dev_mcs_support = HT_STREAM_1X1;
18818c2ecf20Sopenharmony_ci			if (adapter->is_hw_11ac_capable)
18828c2ecf20Sopenharmony_ci				adapter->usr_dot_11ac_mcs_support =
18838c2ecf20Sopenharmony_ci						MWIFIEX_11AC_MCS_MAP_1X1;
18848c2ecf20Sopenharmony_ci		} else {
18858c2ecf20Sopenharmony_ci			adapter->user_dev_mcs_support = HT_STREAM_2X2;
18868c2ecf20Sopenharmony_ci			if (adapter->is_hw_11ac_capable)
18878c2ecf20Sopenharmony_ci				adapter->usr_dot_11ac_mcs_support =
18888c2ecf20Sopenharmony_ci						MWIFIEX_11AC_MCS_MAP_2X2;
18898c2ecf20Sopenharmony_ci		}
18908c2ecf20Sopenharmony_ci
18918c2ecf20Sopenharmony_ci		for (band = 0; band < NUM_NL80211_BANDS; band++) {
18928c2ecf20Sopenharmony_ci			if (!adapter->wiphy->bands[band])
18938c2ecf20Sopenharmony_ci				continue;
18948c2ecf20Sopenharmony_ci
18958c2ecf20Sopenharmony_ci			ht_info = &adapter->wiphy->bands[band]->ht_cap;
18968c2ecf20Sopenharmony_ci			rx_mcs_supp =
18978c2ecf20Sopenharmony_ci				GET_RXMCSSUPP(adapter->user_dev_mcs_support);
18988c2ecf20Sopenharmony_ci			memset(&ht_info->mcs, 0, adapter->number_of_antenna);
18998c2ecf20Sopenharmony_ci			memset(&ht_info->mcs, 0xff, rx_mcs_supp);
19008c2ecf20Sopenharmony_ci		}
19018c2ecf20Sopenharmony_ci	}
19028c2ecf20Sopenharmony_ci
19038c2ecf20Sopenharmony_ci	ant_cfg.tx_ant = tx_ant;
19048c2ecf20Sopenharmony_ci	ant_cfg.rx_ant = rx_ant;
19058c2ecf20Sopenharmony_ci
19068c2ecf20Sopenharmony_ci	return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
19078c2ecf20Sopenharmony_ci				HostCmd_ACT_GEN_SET, 0, &ant_cfg, true);
19088c2ecf20Sopenharmony_ci}
19098c2ecf20Sopenharmony_ci
19108c2ecf20Sopenharmony_cistatic int
19118c2ecf20Sopenharmony_cimwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
19128c2ecf20Sopenharmony_ci{
19138c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
19148c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_get_priv(adapter,
19158c2ecf20Sopenharmony_ci							MWIFIEX_BSS_ROLE_ANY);
19168c2ecf20Sopenharmony_ci	mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA,
19178c2ecf20Sopenharmony_ci			 HostCmd_ACT_GEN_GET, 0, NULL, true);
19188c2ecf20Sopenharmony_ci
19198c2ecf20Sopenharmony_ci	*tx_ant = priv->tx_ant;
19208c2ecf20Sopenharmony_ci	*rx_ant = priv->rx_ant;
19218c2ecf20Sopenharmony_ci
19228c2ecf20Sopenharmony_ci	return 0;
19238c2ecf20Sopenharmony_ci}
19248c2ecf20Sopenharmony_ci
19258c2ecf20Sopenharmony_ci/* cfg80211 operation handler for stop ap.
19268c2ecf20Sopenharmony_ci * Function stops BSS running at uAP interface.
19278c2ecf20Sopenharmony_ci */
19288c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
19298c2ecf20Sopenharmony_ci{
19308c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
19318c2ecf20Sopenharmony_ci
19328c2ecf20Sopenharmony_ci	mwifiex_abort_cac(priv);
19338c2ecf20Sopenharmony_ci
19348c2ecf20Sopenharmony_ci	if (mwifiex_del_mgmt_ies(priv))
19358c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
19368c2ecf20Sopenharmony_ci			    "Failed to delete mgmt IEs!\n");
19378c2ecf20Sopenharmony_ci
19388c2ecf20Sopenharmony_ci	priv->ap_11n_enabled = 0;
19398c2ecf20Sopenharmony_ci	memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg));
19408c2ecf20Sopenharmony_ci
19418c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP,
19428c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, NULL, true)) {
19438c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
19448c2ecf20Sopenharmony_ci			    "Failed to stop the BSS\n");
19458c2ecf20Sopenharmony_ci		return -1;
19468c2ecf20Sopenharmony_ci	}
19478c2ecf20Sopenharmony_ci
19488c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET,
19498c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, NULL, true)) {
19508c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
19518c2ecf20Sopenharmony_ci			    "Failed to reset BSS\n");
19528c2ecf20Sopenharmony_ci		return -1;
19538c2ecf20Sopenharmony_ci	}
19548c2ecf20Sopenharmony_ci
19558c2ecf20Sopenharmony_ci	if (netif_carrier_ok(priv->netdev))
19568c2ecf20Sopenharmony_ci		netif_carrier_off(priv->netdev);
19578c2ecf20Sopenharmony_ci	mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
19588c2ecf20Sopenharmony_ci
19598c2ecf20Sopenharmony_ci	return 0;
19608c2ecf20Sopenharmony_ci}
19618c2ecf20Sopenharmony_ci
19628c2ecf20Sopenharmony_ci/* cfg80211 operation handler for start_ap.
19638c2ecf20Sopenharmony_ci * Function sets beacon period, DTIM period, SSID and security into
19648c2ecf20Sopenharmony_ci * AP config structure.
19658c2ecf20Sopenharmony_ci * AP is configured with these settings and BSS is started.
19668c2ecf20Sopenharmony_ci */
19678c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_start_ap(struct wiphy *wiphy,
19688c2ecf20Sopenharmony_ci				     struct net_device *dev,
19698c2ecf20Sopenharmony_ci				     struct cfg80211_ap_settings *params)
19708c2ecf20Sopenharmony_ci{
19718c2ecf20Sopenharmony_ci	struct mwifiex_uap_bss_param *bss_cfg;
19728c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
19738c2ecf20Sopenharmony_ci
19748c2ecf20Sopenharmony_ci	if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP)
19758c2ecf20Sopenharmony_ci		return -1;
19768c2ecf20Sopenharmony_ci
19778c2ecf20Sopenharmony_ci	bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
19788c2ecf20Sopenharmony_ci	if (!bss_cfg)
19798c2ecf20Sopenharmony_ci		return -ENOMEM;
19808c2ecf20Sopenharmony_ci
19818c2ecf20Sopenharmony_ci	mwifiex_set_sys_config_invalid_data(bss_cfg);
19828c2ecf20Sopenharmony_ci
19838c2ecf20Sopenharmony_ci	memcpy(bss_cfg->mac_addr, priv->curr_addr, ETH_ALEN);
19848c2ecf20Sopenharmony_ci
19858c2ecf20Sopenharmony_ci	if (params->beacon_interval)
19868c2ecf20Sopenharmony_ci		bss_cfg->beacon_period = params->beacon_interval;
19878c2ecf20Sopenharmony_ci	if (params->dtim_period)
19888c2ecf20Sopenharmony_ci		bss_cfg->dtim_period = params->dtim_period;
19898c2ecf20Sopenharmony_ci
19908c2ecf20Sopenharmony_ci	if (params->ssid && params->ssid_len) {
19918c2ecf20Sopenharmony_ci		memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len);
19928c2ecf20Sopenharmony_ci		bss_cfg->ssid.ssid_len = params->ssid_len;
19938c2ecf20Sopenharmony_ci	}
19948c2ecf20Sopenharmony_ci	if (params->inactivity_timeout > 0) {
19958c2ecf20Sopenharmony_ci		/* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */
19968c2ecf20Sopenharmony_ci		bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout;
19978c2ecf20Sopenharmony_ci		bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout;
19988c2ecf20Sopenharmony_ci	}
19998c2ecf20Sopenharmony_ci
20008c2ecf20Sopenharmony_ci	switch (params->hidden_ssid) {
20018c2ecf20Sopenharmony_ci	case NL80211_HIDDEN_SSID_NOT_IN_USE:
20028c2ecf20Sopenharmony_ci		bss_cfg->bcast_ssid_ctl = 1;
20038c2ecf20Sopenharmony_ci		break;
20048c2ecf20Sopenharmony_ci	case NL80211_HIDDEN_SSID_ZERO_LEN:
20058c2ecf20Sopenharmony_ci		bss_cfg->bcast_ssid_ctl = 0;
20068c2ecf20Sopenharmony_ci		break;
20078c2ecf20Sopenharmony_ci	case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
20088c2ecf20Sopenharmony_ci		bss_cfg->bcast_ssid_ctl = 2;
20098c2ecf20Sopenharmony_ci		break;
20108c2ecf20Sopenharmony_ci	default:
20118c2ecf20Sopenharmony_ci		kfree(bss_cfg);
20128c2ecf20Sopenharmony_ci		return -EINVAL;
20138c2ecf20Sopenharmony_ci	}
20148c2ecf20Sopenharmony_ci
20158c2ecf20Sopenharmony_ci	mwifiex_uap_set_channel(priv, bss_cfg, params->chandef);
20168c2ecf20Sopenharmony_ci	mwifiex_set_uap_rates(bss_cfg, params);
20178c2ecf20Sopenharmony_ci
20188c2ecf20Sopenharmony_ci	if (mwifiex_set_secure_params(priv, bss_cfg, params)) {
20198c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
20208c2ecf20Sopenharmony_ci			    "Failed to parse security parameters!\n");
20218c2ecf20Sopenharmony_ci		goto out;
20228c2ecf20Sopenharmony_ci	}
20238c2ecf20Sopenharmony_ci
20248c2ecf20Sopenharmony_ci	mwifiex_set_ht_params(priv, bss_cfg, params);
20258c2ecf20Sopenharmony_ci
20268c2ecf20Sopenharmony_ci	if (priv->adapter->is_hw_11ac_capable) {
20278c2ecf20Sopenharmony_ci		mwifiex_set_vht_params(priv, bss_cfg, params);
20288c2ecf20Sopenharmony_ci		mwifiex_set_vht_width(priv, params->chandef.width,
20298c2ecf20Sopenharmony_ci				      priv->ap_11ac_enabled);
20308c2ecf20Sopenharmony_ci	}
20318c2ecf20Sopenharmony_ci
20328c2ecf20Sopenharmony_ci	if (priv->ap_11ac_enabled)
20338c2ecf20Sopenharmony_ci		mwifiex_set_11ac_ba_params(priv);
20348c2ecf20Sopenharmony_ci	else
20358c2ecf20Sopenharmony_ci		mwifiex_set_ba_params(priv);
20368c2ecf20Sopenharmony_ci
20378c2ecf20Sopenharmony_ci	mwifiex_set_wmm_params(priv, bss_cfg, params);
20388c2ecf20Sopenharmony_ci
20398c2ecf20Sopenharmony_ci	if (mwifiex_is_11h_active(priv))
20408c2ecf20Sopenharmony_ci		mwifiex_set_tpc_params(priv, bss_cfg, params);
20418c2ecf20Sopenharmony_ci
20428c2ecf20Sopenharmony_ci	if (mwifiex_is_11h_active(priv) &&
20438c2ecf20Sopenharmony_ci	    !cfg80211_chandef_dfs_required(wiphy, &params->chandef,
20448c2ecf20Sopenharmony_ci					   priv->bss_mode)) {
20458c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO,
20468c2ecf20Sopenharmony_ci			    "Disable 11h extensions in FW\n");
20478c2ecf20Sopenharmony_ci		if (mwifiex_11h_activate(priv, false)) {
20488c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, ERROR,
20498c2ecf20Sopenharmony_ci				    "Failed to disable 11h extensions!!");
20508c2ecf20Sopenharmony_ci			goto out;
20518c2ecf20Sopenharmony_ci		}
20528c2ecf20Sopenharmony_ci		priv->state_11h.is_11h_active = false;
20538c2ecf20Sopenharmony_ci	}
20548c2ecf20Sopenharmony_ci
20558c2ecf20Sopenharmony_ci	mwifiex_config_uap_11d(priv, &params->beacon);
20568c2ecf20Sopenharmony_ci
20578c2ecf20Sopenharmony_ci	if (mwifiex_config_start_uap(priv, bss_cfg)) {
20588c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
20598c2ecf20Sopenharmony_ci			    "Failed to start AP\n");
20608c2ecf20Sopenharmony_ci		goto out;
20618c2ecf20Sopenharmony_ci	}
20628c2ecf20Sopenharmony_ci
20638c2ecf20Sopenharmony_ci	if (mwifiex_set_mgmt_ies(priv, &params->beacon))
20648c2ecf20Sopenharmony_ci		goto out;
20658c2ecf20Sopenharmony_ci
20668c2ecf20Sopenharmony_ci	if (!netif_carrier_ok(priv->netdev))
20678c2ecf20Sopenharmony_ci		netif_carrier_on(priv->netdev);
20688c2ecf20Sopenharmony_ci	mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter);
20698c2ecf20Sopenharmony_ci
20708c2ecf20Sopenharmony_ci	memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg));
20718c2ecf20Sopenharmony_ci	kfree(bss_cfg);
20728c2ecf20Sopenharmony_ci	return 0;
20738c2ecf20Sopenharmony_ci
20748c2ecf20Sopenharmony_ciout:
20758c2ecf20Sopenharmony_ci	kfree(bss_cfg);
20768c2ecf20Sopenharmony_ci	return -1;
20778c2ecf20Sopenharmony_ci}
20788c2ecf20Sopenharmony_ci
20798c2ecf20Sopenharmony_ci/*
20808c2ecf20Sopenharmony_ci * CFG802.11 operation handler for disconnection request.
20818c2ecf20Sopenharmony_ci *
20828c2ecf20Sopenharmony_ci * This function does not work when there is already a disconnection
20838c2ecf20Sopenharmony_ci * procedure going on.
20848c2ecf20Sopenharmony_ci */
20858c2ecf20Sopenharmony_cistatic int
20868c2ecf20Sopenharmony_cimwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
20878c2ecf20Sopenharmony_ci			    u16 reason_code)
20888c2ecf20Sopenharmony_ci{
20898c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
20908c2ecf20Sopenharmony_ci
20918c2ecf20Sopenharmony_ci	if (!mwifiex_stop_bg_scan(priv))
20928c2ecf20Sopenharmony_ci		cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
20938c2ecf20Sopenharmony_ci
20948c2ecf20Sopenharmony_ci	if (mwifiex_deauthenticate(priv, NULL))
20958c2ecf20Sopenharmony_ci		return -EFAULT;
20968c2ecf20Sopenharmony_ci
20978c2ecf20Sopenharmony_ci	eth_zero_addr(priv->cfg_bssid);
20988c2ecf20Sopenharmony_ci	priv->hs2_enabled = false;
20998c2ecf20Sopenharmony_ci
21008c2ecf20Sopenharmony_ci	return 0;
21018c2ecf20Sopenharmony_ci}
21028c2ecf20Sopenharmony_ci
21038c2ecf20Sopenharmony_ci/*
21048c2ecf20Sopenharmony_ci * This function informs the CFG802.11 subsystem of a new IBSS.
21058c2ecf20Sopenharmony_ci *
21068c2ecf20Sopenharmony_ci * The following information are sent to the CFG802.11 subsystem
21078c2ecf20Sopenharmony_ci * to register the new IBSS. If we do not register the new IBSS,
21088c2ecf20Sopenharmony_ci * a kernel panic will result.
21098c2ecf20Sopenharmony_ci *      - SSID
21108c2ecf20Sopenharmony_ci *      - SSID length
21118c2ecf20Sopenharmony_ci *      - BSSID
21128c2ecf20Sopenharmony_ci *      - Channel
21138c2ecf20Sopenharmony_ci */
21148c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv)
21158c2ecf20Sopenharmony_ci{
21168c2ecf20Sopenharmony_ci	struct ieee80211_channel *chan;
21178c2ecf20Sopenharmony_ci	struct mwifiex_bss_info bss_info;
21188c2ecf20Sopenharmony_ci	struct cfg80211_bss *bss;
21198c2ecf20Sopenharmony_ci	int ie_len;
21208c2ecf20Sopenharmony_ci	u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)];
21218c2ecf20Sopenharmony_ci	enum nl80211_band band;
21228c2ecf20Sopenharmony_ci
21238c2ecf20Sopenharmony_ci	if (mwifiex_get_bss_info(priv, &bss_info))
21248c2ecf20Sopenharmony_ci		return -1;
21258c2ecf20Sopenharmony_ci
21268c2ecf20Sopenharmony_ci	ie_buf[0] = WLAN_EID_SSID;
21278c2ecf20Sopenharmony_ci	ie_buf[1] = bss_info.ssid.ssid_len;
21288c2ecf20Sopenharmony_ci
21298c2ecf20Sopenharmony_ci	memcpy(&ie_buf[sizeof(struct ieee_types_header)],
21308c2ecf20Sopenharmony_ci	       &bss_info.ssid.ssid, bss_info.ssid.ssid_len);
21318c2ecf20Sopenharmony_ci	ie_len = ie_buf[1] + sizeof(struct ieee_types_header);
21328c2ecf20Sopenharmony_ci
21338c2ecf20Sopenharmony_ci	band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
21348c2ecf20Sopenharmony_ci	chan = ieee80211_get_channel(priv->wdev.wiphy,
21358c2ecf20Sopenharmony_ci			ieee80211_channel_to_frequency(bss_info.bss_chan,
21368c2ecf20Sopenharmony_ci						       band));
21378c2ecf20Sopenharmony_ci
21388c2ecf20Sopenharmony_ci	bss = cfg80211_inform_bss(priv->wdev.wiphy, chan,
21398c2ecf20Sopenharmony_ci				  CFG80211_BSS_FTYPE_UNKNOWN,
21408c2ecf20Sopenharmony_ci				  bss_info.bssid, 0, WLAN_CAPABILITY_IBSS,
21418c2ecf20Sopenharmony_ci				  0, ie_buf, ie_len, 0, GFP_KERNEL);
21428c2ecf20Sopenharmony_ci	if (bss) {
21438c2ecf20Sopenharmony_ci		cfg80211_put_bss(priv->wdev.wiphy, bss);
21448c2ecf20Sopenharmony_ci		ether_addr_copy(priv->cfg_bssid, bss_info.bssid);
21458c2ecf20Sopenharmony_ci	}
21468c2ecf20Sopenharmony_ci
21478c2ecf20Sopenharmony_ci	return 0;
21488c2ecf20Sopenharmony_ci}
21498c2ecf20Sopenharmony_ci
21508c2ecf20Sopenharmony_ci/*
21518c2ecf20Sopenharmony_ci * This function connects with a BSS.
21528c2ecf20Sopenharmony_ci *
21538c2ecf20Sopenharmony_ci * This function handles both Infra and Ad-Hoc modes. It also performs
21548c2ecf20Sopenharmony_ci * validity checking on the provided parameters, disconnects from the
21558c2ecf20Sopenharmony_ci * current BSS (if any), sets up the association/scan parameters,
21568c2ecf20Sopenharmony_ci * including security settings, and performs specific SSID scan before
21578c2ecf20Sopenharmony_ci * trying to connect.
21588c2ecf20Sopenharmony_ci *
21598c2ecf20Sopenharmony_ci * For Infra mode, the function returns failure if the specified SSID
21608c2ecf20Sopenharmony_ci * is not found in scan table. However, for Ad-Hoc mode, it can create
21618c2ecf20Sopenharmony_ci * the IBSS if it does not exist. On successful completion in either case,
21628c2ecf20Sopenharmony_ci * the function notifies the CFG802.11 subsystem of the new BSS connection.
21638c2ecf20Sopenharmony_ci */
21648c2ecf20Sopenharmony_cistatic int
21658c2ecf20Sopenharmony_cimwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len,
21668c2ecf20Sopenharmony_ci		       const u8 *ssid, const u8 *bssid, int mode,
21678c2ecf20Sopenharmony_ci		       struct ieee80211_channel *channel,
21688c2ecf20Sopenharmony_ci		       struct cfg80211_connect_params *sme, bool privacy)
21698c2ecf20Sopenharmony_ci{
21708c2ecf20Sopenharmony_ci	struct cfg80211_ssid req_ssid;
21718c2ecf20Sopenharmony_ci	int ret, auth_type = 0;
21728c2ecf20Sopenharmony_ci	struct cfg80211_bss *bss = NULL;
21738c2ecf20Sopenharmony_ci	u8 is_scanning_required = 0;
21748c2ecf20Sopenharmony_ci
21758c2ecf20Sopenharmony_ci	memset(&req_ssid, 0, sizeof(struct cfg80211_ssid));
21768c2ecf20Sopenharmony_ci
21778c2ecf20Sopenharmony_ci	req_ssid.ssid_len = ssid_len;
21788c2ecf20Sopenharmony_ci	if (ssid_len > IEEE80211_MAX_SSID_LEN) {
21798c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
21808c2ecf20Sopenharmony_ci		return -EINVAL;
21818c2ecf20Sopenharmony_ci	}
21828c2ecf20Sopenharmony_ci
21838c2ecf20Sopenharmony_ci	memcpy(req_ssid.ssid, ssid, ssid_len);
21848c2ecf20Sopenharmony_ci	if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) {
21858c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n");
21868c2ecf20Sopenharmony_ci		return -EINVAL;
21878c2ecf20Sopenharmony_ci	}
21888c2ecf20Sopenharmony_ci
21898c2ecf20Sopenharmony_ci	/* As this is new association, clear locally stored
21908c2ecf20Sopenharmony_ci	 * keys and security related flags */
21918c2ecf20Sopenharmony_ci	priv->sec_info.wpa_enabled = false;
21928c2ecf20Sopenharmony_ci	priv->sec_info.wpa2_enabled = false;
21938c2ecf20Sopenharmony_ci	priv->wep_key_curr_index = 0;
21948c2ecf20Sopenharmony_ci	priv->sec_info.encryption_mode = 0;
21958c2ecf20Sopenharmony_ci	priv->sec_info.is_authtype_auto = 0;
21968c2ecf20Sopenharmony_ci	ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1);
21978c2ecf20Sopenharmony_ci
21988c2ecf20Sopenharmony_ci	if (mode == NL80211_IFTYPE_ADHOC) {
21998c2ecf20Sopenharmony_ci		u16 enable = true;
22008c2ecf20Sopenharmony_ci
22018c2ecf20Sopenharmony_ci		/* set ibss coalescing_status */
22028c2ecf20Sopenharmony_ci		ret = mwifiex_send_cmd(
22038c2ecf20Sopenharmony_ci				priv,
22048c2ecf20Sopenharmony_ci				HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
22058c2ecf20Sopenharmony_ci				HostCmd_ACT_GEN_SET, 0, &enable, true);
22068c2ecf20Sopenharmony_ci		if (ret)
22078c2ecf20Sopenharmony_ci			return ret;
22088c2ecf20Sopenharmony_ci
22098c2ecf20Sopenharmony_ci		/* "privacy" is set only for ad-hoc mode */
22108c2ecf20Sopenharmony_ci		if (privacy) {
22118c2ecf20Sopenharmony_ci			/*
22128c2ecf20Sopenharmony_ci			 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that
22138c2ecf20Sopenharmony_ci			 * the firmware can find a matching network from the
22148c2ecf20Sopenharmony_ci			 * scan. The cfg80211 does not give us the encryption
22158c2ecf20Sopenharmony_ci			 * mode at this stage so just setting it to WEP here.
22168c2ecf20Sopenharmony_ci			 */
22178c2ecf20Sopenharmony_ci			priv->sec_info.encryption_mode =
22188c2ecf20Sopenharmony_ci					WLAN_CIPHER_SUITE_WEP104;
22198c2ecf20Sopenharmony_ci			priv->sec_info.authentication_mode =
22208c2ecf20Sopenharmony_ci					NL80211_AUTHTYPE_OPEN_SYSTEM;
22218c2ecf20Sopenharmony_ci		}
22228c2ecf20Sopenharmony_ci
22238c2ecf20Sopenharmony_ci		goto done;
22248c2ecf20Sopenharmony_ci	}
22258c2ecf20Sopenharmony_ci
22268c2ecf20Sopenharmony_ci	/* Now handle infra mode. "sme" is valid for infra mode only */
22278c2ecf20Sopenharmony_ci	if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
22288c2ecf20Sopenharmony_ci		auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
22298c2ecf20Sopenharmony_ci		priv->sec_info.is_authtype_auto = 1;
22308c2ecf20Sopenharmony_ci	} else {
22318c2ecf20Sopenharmony_ci		auth_type = sme->auth_type;
22328c2ecf20Sopenharmony_ci	}
22338c2ecf20Sopenharmony_ci
22348c2ecf20Sopenharmony_ci	if (sme->crypto.n_ciphers_pairwise) {
22358c2ecf20Sopenharmony_ci		priv->sec_info.encryption_mode =
22368c2ecf20Sopenharmony_ci						sme->crypto.ciphers_pairwise[0];
22378c2ecf20Sopenharmony_ci		priv->sec_info.authentication_mode = auth_type;
22388c2ecf20Sopenharmony_ci	}
22398c2ecf20Sopenharmony_ci
22408c2ecf20Sopenharmony_ci	if (sme->crypto.cipher_group) {
22418c2ecf20Sopenharmony_ci		priv->sec_info.encryption_mode = sme->crypto.cipher_group;
22428c2ecf20Sopenharmony_ci		priv->sec_info.authentication_mode = auth_type;
22438c2ecf20Sopenharmony_ci	}
22448c2ecf20Sopenharmony_ci	if (sme->ie)
22458c2ecf20Sopenharmony_ci		ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len);
22468c2ecf20Sopenharmony_ci
22478c2ecf20Sopenharmony_ci	if (sme->key) {
22488c2ecf20Sopenharmony_ci		if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) {
22498c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, INFO,
22508c2ecf20Sopenharmony_ci				    "info: setting wep encryption\t"
22518c2ecf20Sopenharmony_ci				    "with key len %d\n", sme->key_len);
22528c2ecf20Sopenharmony_ci			priv->wep_key_curr_index = sme->key_idx;
22538c2ecf20Sopenharmony_ci			ret = mwifiex_set_encode(priv, NULL, sme->key,
22548c2ecf20Sopenharmony_ci						 sme->key_len, sme->key_idx,
22558c2ecf20Sopenharmony_ci						 NULL, 0);
22568c2ecf20Sopenharmony_ci		}
22578c2ecf20Sopenharmony_ci	}
22588c2ecf20Sopenharmony_cidone:
22598c2ecf20Sopenharmony_ci	/*
22608c2ecf20Sopenharmony_ci	 * Scan entries are valid for some time (15 sec). So we can save one
22618c2ecf20Sopenharmony_ci	 * active scan time if we just try cfg80211_get_bss first. If it fails
22628c2ecf20Sopenharmony_ci	 * then request scan and cfg80211_get_bss() again for final output.
22638c2ecf20Sopenharmony_ci	 */
22648c2ecf20Sopenharmony_ci	while (1) {
22658c2ecf20Sopenharmony_ci		if (is_scanning_required) {
22668c2ecf20Sopenharmony_ci			/* Do specific SSID scanning */
22678c2ecf20Sopenharmony_ci			if (mwifiex_request_scan(priv, &req_ssid)) {
22688c2ecf20Sopenharmony_ci				mwifiex_dbg(priv->adapter, ERROR, "scan error\n");
22698c2ecf20Sopenharmony_ci				return -EFAULT;
22708c2ecf20Sopenharmony_ci			}
22718c2ecf20Sopenharmony_ci		}
22728c2ecf20Sopenharmony_ci
22738c2ecf20Sopenharmony_ci		/* Find the BSS we want using available scan results */
22748c2ecf20Sopenharmony_ci		if (mode == NL80211_IFTYPE_ADHOC)
22758c2ecf20Sopenharmony_ci			bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
22768c2ecf20Sopenharmony_ci					       bssid, ssid, ssid_len,
22778c2ecf20Sopenharmony_ci					       IEEE80211_BSS_TYPE_IBSS,
22788c2ecf20Sopenharmony_ci					       IEEE80211_PRIVACY_ANY);
22798c2ecf20Sopenharmony_ci		else
22808c2ecf20Sopenharmony_ci			bss = cfg80211_get_bss(priv->wdev.wiphy, channel,
22818c2ecf20Sopenharmony_ci					       bssid, ssid, ssid_len,
22828c2ecf20Sopenharmony_ci					       IEEE80211_BSS_TYPE_ESS,
22838c2ecf20Sopenharmony_ci					       IEEE80211_PRIVACY_ANY);
22848c2ecf20Sopenharmony_ci
22858c2ecf20Sopenharmony_ci		if (!bss) {
22868c2ecf20Sopenharmony_ci			if (is_scanning_required) {
22878c2ecf20Sopenharmony_ci				mwifiex_dbg(priv->adapter, MSG,
22888c2ecf20Sopenharmony_ci					    "assoc: requested bss not found in scan results\n");
22898c2ecf20Sopenharmony_ci				break;
22908c2ecf20Sopenharmony_ci			}
22918c2ecf20Sopenharmony_ci			is_scanning_required = 1;
22928c2ecf20Sopenharmony_ci		} else {
22938c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, MSG,
22948c2ecf20Sopenharmony_ci				    "info: trying to associate to '%.*s' bssid %pM\n",
22958c2ecf20Sopenharmony_ci				    req_ssid.ssid_len, (char *)req_ssid.ssid,
22968c2ecf20Sopenharmony_ci				    bss->bssid);
22978c2ecf20Sopenharmony_ci			memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
22988c2ecf20Sopenharmony_ci			break;
22998c2ecf20Sopenharmony_ci		}
23008c2ecf20Sopenharmony_ci	}
23018c2ecf20Sopenharmony_ci
23028c2ecf20Sopenharmony_ci	ret = mwifiex_bss_start(priv, bss, &req_ssid);
23038c2ecf20Sopenharmony_ci	if (ret)
23048c2ecf20Sopenharmony_ci		return ret;
23058c2ecf20Sopenharmony_ci
23068c2ecf20Sopenharmony_ci	if (mode == NL80211_IFTYPE_ADHOC) {
23078c2ecf20Sopenharmony_ci		/* Inform the BSS information to kernel, otherwise
23088c2ecf20Sopenharmony_ci		 * kernel will give a panic after successful assoc */
23098c2ecf20Sopenharmony_ci		if (mwifiex_cfg80211_inform_ibss_bss(priv))
23108c2ecf20Sopenharmony_ci			return -EFAULT;
23118c2ecf20Sopenharmony_ci	}
23128c2ecf20Sopenharmony_ci
23138c2ecf20Sopenharmony_ci	return ret;
23148c2ecf20Sopenharmony_ci}
23158c2ecf20Sopenharmony_ci
23168c2ecf20Sopenharmony_ci/*
23178c2ecf20Sopenharmony_ci * CFG802.11 operation handler for association request.
23188c2ecf20Sopenharmony_ci *
23198c2ecf20Sopenharmony_ci * This function does not work when the current mode is set to Ad-Hoc, or
23208c2ecf20Sopenharmony_ci * when there is already an association procedure going on. The given BSS
23218c2ecf20Sopenharmony_ci * information is used to associate.
23228c2ecf20Sopenharmony_ci */
23238c2ecf20Sopenharmony_cistatic int
23248c2ecf20Sopenharmony_cimwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
23258c2ecf20Sopenharmony_ci			 struct cfg80211_connect_params *sme)
23268c2ecf20Sopenharmony_ci{
23278c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
23288c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
23298c2ecf20Sopenharmony_ci	int ret;
23308c2ecf20Sopenharmony_ci
23318c2ecf20Sopenharmony_ci	if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) {
23328c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
23338c2ecf20Sopenharmony_ci			    "%s: reject infra assoc request in non-STA role\n",
23348c2ecf20Sopenharmony_ci			    dev->name);
23358c2ecf20Sopenharmony_ci		return -EINVAL;
23368c2ecf20Sopenharmony_ci	}
23378c2ecf20Sopenharmony_ci
23388c2ecf20Sopenharmony_ci	if (priv->wdev.current_bss) {
23398c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
23408c2ecf20Sopenharmony_ci			    "%s: already connected\n", dev->name);
23418c2ecf20Sopenharmony_ci		return -EALREADY;
23428c2ecf20Sopenharmony_ci	}
23438c2ecf20Sopenharmony_ci
23448c2ecf20Sopenharmony_ci	if (priv->scan_block)
23458c2ecf20Sopenharmony_ci		priv->scan_block = false;
23468c2ecf20Sopenharmony_ci
23478c2ecf20Sopenharmony_ci	if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) ||
23488c2ecf20Sopenharmony_ci	    test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
23498c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
23508c2ecf20Sopenharmony_ci			    "%s: Ignore connection.\t"
23518c2ecf20Sopenharmony_ci			    "Card removed or FW in bad state\n",
23528c2ecf20Sopenharmony_ci			    dev->name);
23538c2ecf20Sopenharmony_ci		return -EFAULT;
23548c2ecf20Sopenharmony_ci	}
23558c2ecf20Sopenharmony_ci
23568c2ecf20Sopenharmony_ci	mwifiex_dbg(adapter, INFO,
23578c2ecf20Sopenharmony_ci		    "info: Trying to associate to %.*s and bssid %pM\n",
23588c2ecf20Sopenharmony_ci		    (int)sme->ssid_len, (char *)sme->ssid, sme->bssid);
23598c2ecf20Sopenharmony_ci
23608c2ecf20Sopenharmony_ci	if (!mwifiex_stop_bg_scan(priv))
23618c2ecf20Sopenharmony_ci		cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
23628c2ecf20Sopenharmony_ci
23638c2ecf20Sopenharmony_ci	ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid,
23648c2ecf20Sopenharmony_ci				     priv->bss_mode, sme->channel, sme, 0);
23658c2ecf20Sopenharmony_ci	if (!ret) {
23668c2ecf20Sopenharmony_ci		cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0,
23678c2ecf20Sopenharmony_ci					NULL, 0, WLAN_STATUS_SUCCESS,
23688c2ecf20Sopenharmony_ci					GFP_KERNEL);
23698c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, MSG,
23708c2ecf20Sopenharmony_ci			    "info: associated to bssid %pM successfully\n",
23718c2ecf20Sopenharmony_ci			    priv->cfg_bssid);
23728c2ecf20Sopenharmony_ci		if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
23738c2ecf20Sopenharmony_ci		    priv->adapter->auto_tdls &&
23748c2ecf20Sopenharmony_ci		    priv->bss_type == MWIFIEX_BSS_TYPE_STA)
23758c2ecf20Sopenharmony_ci			mwifiex_setup_auto_tdls_timer(priv);
23768c2ecf20Sopenharmony_ci	} else {
23778c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
23788c2ecf20Sopenharmony_ci			    "info: association to bssid %pM failed\n",
23798c2ecf20Sopenharmony_ci			    priv->cfg_bssid);
23808c2ecf20Sopenharmony_ci		eth_zero_addr(priv->cfg_bssid);
23818c2ecf20Sopenharmony_ci
23828c2ecf20Sopenharmony_ci		if (ret > 0)
23838c2ecf20Sopenharmony_ci			cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
23848c2ecf20Sopenharmony_ci						NULL, 0, NULL, 0, ret,
23858c2ecf20Sopenharmony_ci						GFP_KERNEL);
23868c2ecf20Sopenharmony_ci		else
23878c2ecf20Sopenharmony_ci			cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
23888c2ecf20Sopenharmony_ci						NULL, 0, NULL, 0,
23898c2ecf20Sopenharmony_ci						WLAN_STATUS_UNSPECIFIED_FAILURE,
23908c2ecf20Sopenharmony_ci						GFP_KERNEL);
23918c2ecf20Sopenharmony_ci	}
23928c2ecf20Sopenharmony_ci
23938c2ecf20Sopenharmony_ci	return 0;
23948c2ecf20Sopenharmony_ci}
23958c2ecf20Sopenharmony_ci
23968c2ecf20Sopenharmony_ci/*
23978c2ecf20Sopenharmony_ci * This function sets following parameters for ibss network.
23988c2ecf20Sopenharmony_ci *  -  channel
23998c2ecf20Sopenharmony_ci *  -  start band
24008c2ecf20Sopenharmony_ci *  -  11n flag
24018c2ecf20Sopenharmony_ci *  -  secondary channel offset
24028c2ecf20Sopenharmony_ci */
24038c2ecf20Sopenharmony_cistatic int mwifiex_set_ibss_params(struct mwifiex_private *priv,
24048c2ecf20Sopenharmony_ci				   struct cfg80211_ibss_params *params)
24058c2ecf20Sopenharmony_ci{
24068c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
24078c2ecf20Sopenharmony_ci	int index = 0, i;
24088c2ecf20Sopenharmony_ci	u8 config_bands = 0;
24098c2ecf20Sopenharmony_ci
24108c2ecf20Sopenharmony_ci	if (params->chandef.chan->band == NL80211_BAND_2GHZ) {
24118c2ecf20Sopenharmony_ci		if (!params->basic_rates) {
24128c2ecf20Sopenharmony_ci			config_bands = BAND_B | BAND_G;
24138c2ecf20Sopenharmony_ci		} else {
24148c2ecf20Sopenharmony_ci			for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
24158c2ecf20Sopenharmony_ci				/*
24168c2ecf20Sopenharmony_ci				 * Rates below 6 Mbps in the table are CCK
24178c2ecf20Sopenharmony_ci				 * rates; 802.11b and from 6 they are OFDM;
24188c2ecf20Sopenharmony_ci				 * 802.11G
24198c2ecf20Sopenharmony_ci				 */
24208c2ecf20Sopenharmony_ci				if (mwifiex_rates[i].bitrate == 60) {
24218c2ecf20Sopenharmony_ci					index = 1 << i;
24228c2ecf20Sopenharmony_ci					break;
24238c2ecf20Sopenharmony_ci				}
24248c2ecf20Sopenharmony_ci			}
24258c2ecf20Sopenharmony_ci
24268c2ecf20Sopenharmony_ci			if (params->basic_rates < index) {
24278c2ecf20Sopenharmony_ci				config_bands = BAND_B;
24288c2ecf20Sopenharmony_ci			} else {
24298c2ecf20Sopenharmony_ci				config_bands = BAND_G;
24308c2ecf20Sopenharmony_ci				if (params->basic_rates % index)
24318c2ecf20Sopenharmony_ci					config_bands |= BAND_B;
24328c2ecf20Sopenharmony_ci			}
24338c2ecf20Sopenharmony_ci		}
24348c2ecf20Sopenharmony_ci
24358c2ecf20Sopenharmony_ci		if (cfg80211_get_chandef_type(&params->chandef) !=
24368c2ecf20Sopenharmony_ci						NL80211_CHAN_NO_HT)
24378c2ecf20Sopenharmony_ci			config_bands |= BAND_G | BAND_GN;
24388c2ecf20Sopenharmony_ci	} else {
24398c2ecf20Sopenharmony_ci		if (cfg80211_get_chandef_type(&params->chandef) ==
24408c2ecf20Sopenharmony_ci						NL80211_CHAN_NO_HT)
24418c2ecf20Sopenharmony_ci			config_bands = BAND_A;
24428c2ecf20Sopenharmony_ci		else
24438c2ecf20Sopenharmony_ci			config_bands = BAND_AN | BAND_A;
24448c2ecf20Sopenharmony_ci	}
24458c2ecf20Sopenharmony_ci
24468c2ecf20Sopenharmony_ci	if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) {
24478c2ecf20Sopenharmony_ci		adapter->config_bands = config_bands;
24488c2ecf20Sopenharmony_ci		adapter->adhoc_start_band = config_bands;
24498c2ecf20Sopenharmony_ci
24508c2ecf20Sopenharmony_ci		if ((config_bands & BAND_GN) || (config_bands & BAND_AN))
24518c2ecf20Sopenharmony_ci			adapter->adhoc_11n_enabled = true;
24528c2ecf20Sopenharmony_ci		else
24538c2ecf20Sopenharmony_ci			adapter->adhoc_11n_enabled = false;
24548c2ecf20Sopenharmony_ci	}
24558c2ecf20Sopenharmony_ci
24568c2ecf20Sopenharmony_ci	adapter->sec_chan_offset =
24578c2ecf20Sopenharmony_ci		mwifiex_chan_type_to_sec_chan_offset(
24588c2ecf20Sopenharmony_ci			cfg80211_get_chandef_type(&params->chandef));
24598c2ecf20Sopenharmony_ci	priv->adhoc_channel = ieee80211_frequency_to_channel(
24608c2ecf20Sopenharmony_ci				params->chandef.chan->center_freq);
24618c2ecf20Sopenharmony_ci
24628c2ecf20Sopenharmony_ci	mwifiex_dbg(adapter, INFO,
24638c2ecf20Sopenharmony_ci		    "info: set ibss band %d, chan %d, chan offset %d\n",
24648c2ecf20Sopenharmony_ci		    config_bands, priv->adhoc_channel,
24658c2ecf20Sopenharmony_ci		    adapter->sec_chan_offset);
24668c2ecf20Sopenharmony_ci
24678c2ecf20Sopenharmony_ci	return 0;
24688c2ecf20Sopenharmony_ci}
24698c2ecf20Sopenharmony_ci
24708c2ecf20Sopenharmony_ci/*
24718c2ecf20Sopenharmony_ci * CFG802.11 operation handler to join an IBSS.
24728c2ecf20Sopenharmony_ci *
24738c2ecf20Sopenharmony_ci * This function does not work in any mode other than Ad-Hoc, or if
24748c2ecf20Sopenharmony_ci * a join operation is already in progress.
24758c2ecf20Sopenharmony_ci */
24768c2ecf20Sopenharmony_cistatic int
24778c2ecf20Sopenharmony_cimwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
24788c2ecf20Sopenharmony_ci			   struct cfg80211_ibss_params *params)
24798c2ecf20Sopenharmony_ci{
24808c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
24818c2ecf20Sopenharmony_ci	int ret = 0;
24828c2ecf20Sopenharmony_ci
24838c2ecf20Sopenharmony_ci	if (priv->bss_mode != NL80211_IFTYPE_ADHOC) {
24848c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
24858c2ecf20Sopenharmony_ci			    "request to join ibss received\t"
24868c2ecf20Sopenharmony_ci			    "when station is not in ibss mode\n");
24878c2ecf20Sopenharmony_ci		goto done;
24888c2ecf20Sopenharmony_ci	}
24898c2ecf20Sopenharmony_ci
24908c2ecf20Sopenharmony_ci	mwifiex_dbg(priv->adapter, MSG,
24918c2ecf20Sopenharmony_ci		    "info: trying to join to %.*s and bssid %pM\n",
24928c2ecf20Sopenharmony_ci		    params->ssid_len, (char *)params->ssid, params->bssid);
24938c2ecf20Sopenharmony_ci
24948c2ecf20Sopenharmony_ci	mwifiex_set_ibss_params(priv, params);
24958c2ecf20Sopenharmony_ci
24968c2ecf20Sopenharmony_ci	ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid,
24978c2ecf20Sopenharmony_ci				     params->bssid, priv->bss_mode,
24988c2ecf20Sopenharmony_ci				     params->chandef.chan, NULL,
24998c2ecf20Sopenharmony_ci				     params->privacy);
25008c2ecf20Sopenharmony_cidone:
25018c2ecf20Sopenharmony_ci	if (!ret) {
25028c2ecf20Sopenharmony_ci		cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
25038c2ecf20Sopenharmony_ci				     params->chandef.chan, GFP_KERNEL);
25048c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, MSG,
25058c2ecf20Sopenharmony_ci			    "info: joined/created adhoc network with bssid\t"
25068c2ecf20Sopenharmony_ci			    "%pM successfully\n", priv->cfg_bssid);
25078c2ecf20Sopenharmony_ci	} else {
25088c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
25098c2ecf20Sopenharmony_ci			    "info: failed creating/joining adhoc network\n");
25108c2ecf20Sopenharmony_ci	}
25118c2ecf20Sopenharmony_ci
25128c2ecf20Sopenharmony_ci	return ret;
25138c2ecf20Sopenharmony_ci}
25148c2ecf20Sopenharmony_ci
25158c2ecf20Sopenharmony_ci/*
25168c2ecf20Sopenharmony_ci * CFG802.11 operation handler to leave an IBSS.
25178c2ecf20Sopenharmony_ci *
25188c2ecf20Sopenharmony_ci * This function does not work if a leave operation is
25198c2ecf20Sopenharmony_ci * already in progress.
25208c2ecf20Sopenharmony_ci */
25218c2ecf20Sopenharmony_cistatic int
25228c2ecf20Sopenharmony_cimwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
25238c2ecf20Sopenharmony_ci{
25248c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
25258c2ecf20Sopenharmony_ci
25268c2ecf20Sopenharmony_ci	mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n",
25278c2ecf20Sopenharmony_ci		    priv->cfg_bssid);
25288c2ecf20Sopenharmony_ci	if (mwifiex_deauthenticate(priv, NULL))
25298c2ecf20Sopenharmony_ci		return -EFAULT;
25308c2ecf20Sopenharmony_ci
25318c2ecf20Sopenharmony_ci	eth_zero_addr(priv->cfg_bssid);
25328c2ecf20Sopenharmony_ci
25338c2ecf20Sopenharmony_ci	return 0;
25348c2ecf20Sopenharmony_ci}
25358c2ecf20Sopenharmony_ci
25368c2ecf20Sopenharmony_ci/*
25378c2ecf20Sopenharmony_ci * CFG802.11 operation handler for scan request.
25388c2ecf20Sopenharmony_ci *
25398c2ecf20Sopenharmony_ci * This function issues a scan request to the firmware based upon
25408c2ecf20Sopenharmony_ci * the user specified scan configuration. On successful completion,
25418c2ecf20Sopenharmony_ci * it also informs the results.
25428c2ecf20Sopenharmony_ci */
25438c2ecf20Sopenharmony_cistatic int
25448c2ecf20Sopenharmony_cimwifiex_cfg80211_scan(struct wiphy *wiphy,
25458c2ecf20Sopenharmony_ci		      struct cfg80211_scan_request *request)
25468c2ecf20Sopenharmony_ci{
25478c2ecf20Sopenharmony_ci	struct net_device *dev = request->wdev->netdev;
25488c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
25498c2ecf20Sopenharmony_ci	int i, offset, ret;
25508c2ecf20Sopenharmony_ci	struct ieee80211_channel *chan;
25518c2ecf20Sopenharmony_ci	struct ieee_types_header *ie;
25528c2ecf20Sopenharmony_ci	struct mwifiex_user_scan_cfg *user_scan_cfg;
25538c2ecf20Sopenharmony_ci	u8 mac_addr[ETH_ALEN];
25548c2ecf20Sopenharmony_ci
25558c2ecf20Sopenharmony_ci	mwifiex_dbg(priv->adapter, CMD,
25568c2ecf20Sopenharmony_ci		    "info: received scan request on %s\n", dev->name);
25578c2ecf20Sopenharmony_ci
25588c2ecf20Sopenharmony_ci	/* Block scan request if scan operation or scan cleanup when interface
25598c2ecf20Sopenharmony_ci	 * is disabled is in process
25608c2ecf20Sopenharmony_ci	 */
25618c2ecf20Sopenharmony_ci	if (priv->scan_request || priv->scan_aborting) {
25628c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, WARN,
25638c2ecf20Sopenharmony_ci			    "cmd: Scan already in process..\n");
25648c2ecf20Sopenharmony_ci		return -EBUSY;
25658c2ecf20Sopenharmony_ci	}
25668c2ecf20Sopenharmony_ci
25678c2ecf20Sopenharmony_ci	if (!priv->wdev.current_bss && priv->scan_block)
25688c2ecf20Sopenharmony_ci		priv->scan_block = false;
25698c2ecf20Sopenharmony_ci
25708c2ecf20Sopenharmony_ci	if (!mwifiex_stop_bg_scan(priv))
25718c2ecf20Sopenharmony_ci		cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0);
25728c2ecf20Sopenharmony_ci
25738c2ecf20Sopenharmony_ci	user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
25748c2ecf20Sopenharmony_ci	if (!user_scan_cfg)
25758c2ecf20Sopenharmony_ci		return -ENOMEM;
25768c2ecf20Sopenharmony_ci
25778c2ecf20Sopenharmony_ci	priv->scan_request = request;
25788c2ecf20Sopenharmony_ci
25798c2ecf20Sopenharmony_ci	if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
25808c2ecf20Sopenharmony_ci		get_random_mask_addr(mac_addr, request->mac_addr,
25818c2ecf20Sopenharmony_ci				     request->mac_addr_mask);
25828c2ecf20Sopenharmony_ci		ether_addr_copy(request->mac_addr, mac_addr);
25838c2ecf20Sopenharmony_ci		ether_addr_copy(user_scan_cfg->random_mac, mac_addr);
25848c2ecf20Sopenharmony_ci	}
25858c2ecf20Sopenharmony_ci
25868c2ecf20Sopenharmony_ci	user_scan_cfg->num_ssids = request->n_ssids;
25878c2ecf20Sopenharmony_ci	user_scan_cfg->ssid_list = request->ssids;
25888c2ecf20Sopenharmony_ci
25898c2ecf20Sopenharmony_ci	if (request->ie && request->ie_len) {
25908c2ecf20Sopenharmony_ci		offset = 0;
25918c2ecf20Sopenharmony_ci		for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
25928c2ecf20Sopenharmony_ci			if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
25938c2ecf20Sopenharmony_ci				continue;
25948c2ecf20Sopenharmony_ci			priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
25958c2ecf20Sopenharmony_ci			ie = (struct ieee_types_header *)(request->ie + offset);
25968c2ecf20Sopenharmony_ci			memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
25978c2ecf20Sopenharmony_ci			offset += sizeof(*ie) + ie->len;
25988c2ecf20Sopenharmony_ci
25998c2ecf20Sopenharmony_ci			if (offset >= request->ie_len)
26008c2ecf20Sopenharmony_ci				break;
26018c2ecf20Sopenharmony_ci		}
26028c2ecf20Sopenharmony_ci	}
26038c2ecf20Sopenharmony_ci
26048c2ecf20Sopenharmony_ci	for (i = 0; i < min_t(u32, request->n_channels,
26058c2ecf20Sopenharmony_ci			      MWIFIEX_USER_SCAN_CHAN_MAX); i++) {
26068c2ecf20Sopenharmony_ci		chan = request->channels[i];
26078c2ecf20Sopenharmony_ci		user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
26088c2ecf20Sopenharmony_ci		user_scan_cfg->chan_list[i].radio_type = chan->band;
26098c2ecf20Sopenharmony_ci
26108c2ecf20Sopenharmony_ci		if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
26118c2ecf20Sopenharmony_ci			user_scan_cfg->chan_list[i].scan_type =
26128c2ecf20Sopenharmony_ci						MWIFIEX_SCAN_TYPE_PASSIVE;
26138c2ecf20Sopenharmony_ci		else
26148c2ecf20Sopenharmony_ci			user_scan_cfg->chan_list[i].scan_type =
26158c2ecf20Sopenharmony_ci						MWIFIEX_SCAN_TYPE_ACTIVE;
26168c2ecf20Sopenharmony_ci
26178c2ecf20Sopenharmony_ci		user_scan_cfg->chan_list[i].scan_time = 0;
26188c2ecf20Sopenharmony_ci	}
26198c2ecf20Sopenharmony_ci
26208c2ecf20Sopenharmony_ci	if (priv->adapter->scan_chan_gap_enabled &&
26218c2ecf20Sopenharmony_ci	    mwifiex_is_any_intf_active(priv))
26228c2ecf20Sopenharmony_ci		user_scan_cfg->scan_chan_gap =
26238c2ecf20Sopenharmony_ci					      priv->adapter->scan_chan_gap_time;
26248c2ecf20Sopenharmony_ci
26258c2ecf20Sopenharmony_ci	ret = mwifiex_scan_networks(priv, user_scan_cfg);
26268c2ecf20Sopenharmony_ci	kfree(user_scan_cfg);
26278c2ecf20Sopenharmony_ci	if (ret) {
26288c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
26298c2ecf20Sopenharmony_ci			    "scan failed: %d\n", ret);
26308c2ecf20Sopenharmony_ci		priv->scan_aborting = false;
26318c2ecf20Sopenharmony_ci		priv->scan_request = NULL;
26328c2ecf20Sopenharmony_ci		return ret;
26338c2ecf20Sopenharmony_ci	}
26348c2ecf20Sopenharmony_ci
26358c2ecf20Sopenharmony_ci	if (request->ie && request->ie_len) {
26368c2ecf20Sopenharmony_ci		for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
26378c2ecf20Sopenharmony_ci			if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
26388c2ecf20Sopenharmony_ci				priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
26398c2ecf20Sopenharmony_ci				memset(&priv->vs_ie[i].ie, 0,
26408c2ecf20Sopenharmony_ci				       MWIFIEX_MAX_VSIE_LEN);
26418c2ecf20Sopenharmony_ci			}
26428c2ecf20Sopenharmony_ci		}
26438c2ecf20Sopenharmony_ci	}
26448c2ecf20Sopenharmony_ci	return 0;
26458c2ecf20Sopenharmony_ci}
26468c2ecf20Sopenharmony_ci
26478c2ecf20Sopenharmony_ci/* CFG802.11 operation handler for sched_scan_start.
26488c2ecf20Sopenharmony_ci *
26498c2ecf20Sopenharmony_ci * This function issues a bgscan config request to the firmware based upon
26508c2ecf20Sopenharmony_ci * the user specified sched_scan configuration. On successful completion,
26518c2ecf20Sopenharmony_ci * firmware will generate BGSCAN_REPORT event, driver should issue bgscan
26528c2ecf20Sopenharmony_ci * query command to get sched_scan results from firmware.
26538c2ecf20Sopenharmony_ci */
26548c2ecf20Sopenharmony_cistatic int
26558c2ecf20Sopenharmony_cimwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy,
26568c2ecf20Sopenharmony_ci				  struct net_device *dev,
26578c2ecf20Sopenharmony_ci				  struct cfg80211_sched_scan_request *request)
26588c2ecf20Sopenharmony_ci{
26598c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
26608c2ecf20Sopenharmony_ci	int i, offset;
26618c2ecf20Sopenharmony_ci	struct ieee80211_channel *chan;
26628c2ecf20Sopenharmony_ci	struct mwifiex_bg_scan_cfg *bgscan_cfg;
26638c2ecf20Sopenharmony_ci	struct ieee_types_header *ie;
26648c2ecf20Sopenharmony_ci
26658c2ecf20Sopenharmony_ci	if (!request || (!request->n_ssids && !request->n_match_sets)) {
26668c2ecf20Sopenharmony_ci		wiphy_err(wiphy, "%s : Invalid Sched_scan parameters",
26678c2ecf20Sopenharmony_ci			  __func__);
26688c2ecf20Sopenharmony_ci		return -EINVAL;
26698c2ecf20Sopenharmony_ci	}
26708c2ecf20Sopenharmony_ci
26718c2ecf20Sopenharmony_ci	wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ",
26728c2ecf20Sopenharmony_ci		   request->n_ssids, request->n_match_sets);
26738c2ecf20Sopenharmony_ci	wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n",
26748c2ecf20Sopenharmony_ci		   request->n_channels, request->scan_plans->interval,
26758c2ecf20Sopenharmony_ci		   (int)request->ie_len);
26768c2ecf20Sopenharmony_ci
26778c2ecf20Sopenharmony_ci	bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL);
26788c2ecf20Sopenharmony_ci	if (!bgscan_cfg)
26798c2ecf20Sopenharmony_ci		return -ENOMEM;
26808c2ecf20Sopenharmony_ci
26818c2ecf20Sopenharmony_ci	if (priv->scan_request || priv->scan_aborting)
26828c2ecf20Sopenharmony_ci		bgscan_cfg->start_later = true;
26838c2ecf20Sopenharmony_ci
26848c2ecf20Sopenharmony_ci	bgscan_cfg->num_ssids = request->n_match_sets;
26858c2ecf20Sopenharmony_ci	bgscan_cfg->ssid_list = request->match_sets;
26868c2ecf20Sopenharmony_ci
26878c2ecf20Sopenharmony_ci	if (request->ie && request->ie_len) {
26888c2ecf20Sopenharmony_ci		offset = 0;
26898c2ecf20Sopenharmony_ci		for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
26908c2ecf20Sopenharmony_ci			if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
26918c2ecf20Sopenharmony_ci				continue;
26928c2ecf20Sopenharmony_ci			priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN;
26938c2ecf20Sopenharmony_ci			ie = (struct ieee_types_header *)(request->ie + offset);
26948c2ecf20Sopenharmony_ci			memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len);
26958c2ecf20Sopenharmony_ci			offset += sizeof(*ie) + ie->len;
26968c2ecf20Sopenharmony_ci
26978c2ecf20Sopenharmony_ci			if (offset >= request->ie_len)
26988c2ecf20Sopenharmony_ci				break;
26998c2ecf20Sopenharmony_ci		}
27008c2ecf20Sopenharmony_ci	}
27018c2ecf20Sopenharmony_ci
27028c2ecf20Sopenharmony_ci	for (i = 0; i < min_t(u32, request->n_channels,
27038c2ecf20Sopenharmony_ci			      MWIFIEX_BG_SCAN_CHAN_MAX); i++) {
27048c2ecf20Sopenharmony_ci		chan = request->channels[i];
27058c2ecf20Sopenharmony_ci		bgscan_cfg->chan_list[i].chan_number = chan->hw_value;
27068c2ecf20Sopenharmony_ci		bgscan_cfg->chan_list[i].radio_type = chan->band;
27078c2ecf20Sopenharmony_ci
27088c2ecf20Sopenharmony_ci		if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids)
27098c2ecf20Sopenharmony_ci			bgscan_cfg->chan_list[i].scan_type =
27108c2ecf20Sopenharmony_ci						MWIFIEX_SCAN_TYPE_PASSIVE;
27118c2ecf20Sopenharmony_ci		else
27128c2ecf20Sopenharmony_ci			bgscan_cfg->chan_list[i].scan_type =
27138c2ecf20Sopenharmony_ci						MWIFIEX_SCAN_TYPE_ACTIVE;
27148c2ecf20Sopenharmony_ci
27158c2ecf20Sopenharmony_ci		bgscan_cfg->chan_list[i].scan_time = 0;
27168c2ecf20Sopenharmony_ci	}
27178c2ecf20Sopenharmony_ci
27188c2ecf20Sopenharmony_ci	bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels,
27198c2ecf20Sopenharmony_ci					  MWIFIEX_BG_SCAN_CHAN_MAX);
27208c2ecf20Sopenharmony_ci
27218c2ecf20Sopenharmony_ci	/* Use at least 15 second for per scan cycle */
27228c2ecf20Sopenharmony_ci	bgscan_cfg->scan_interval = (request->scan_plans->interval >
27238c2ecf20Sopenharmony_ci				     MWIFIEX_BGSCAN_INTERVAL) ?
27248c2ecf20Sopenharmony_ci				request->scan_plans->interval :
27258c2ecf20Sopenharmony_ci				MWIFIEX_BGSCAN_INTERVAL;
27268c2ecf20Sopenharmony_ci
27278c2ecf20Sopenharmony_ci	bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT;
27288c2ecf20Sopenharmony_ci	bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH |
27298c2ecf20Sopenharmony_ci				MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE;
27308c2ecf20Sopenharmony_ci	bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA;
27318c2ecf20Sopenharmony_ci	bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET;
27328c2ecf20Sopenharmony_ci	bgscan_cfg->enable = true;
27338c2ecf20Sopenharmony_ci	if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) {
27348c2ecf20Sopenharmony_ci		bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH;
27358c2ecf20Sopenharmony_ci		bgscan_cfg->rssi_threshold = request->min_rssi_thold;
27368c2ecf20Sopenharmony_ci	}
27378c2ecf20Sopenharmony_ci
27388c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG,
27398c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) {
27408c2ecf20Sopenharmony_ci		kfree(bgscan_cfg);
27418c2ecf20Sopenharmony_ci		return -EFAULT;
27428c2ecf20Sopenharmony_ci	}
27438c2ecf20Sopenharmony_ci
27448c2ecf20Sopenharmony_ci	priv->sched_scanning = true;
27458c2ecf20Sopenharmony_ci
27468c2ecf20Sopenharmony_ci	kfree(bgscan_cfg);
27478c2ecf20Sopenharmony_ci	return 0;
27488c2ecf20Sopenharmony_ci}
27498c2ecf20Sopenharmony_ci
27508c2ecf20Sopenharmony_ci/* CFG802.11 operation handler for sched_scan_stop.
27518c2ecf20Sopenharmony_ci *
27528c2ecf20Sopenharmony_ci * This function issues a bgscan config command to disable
27538c2ecf20Sopenharmony_ci * previous bgscan configuration in the firmware
27548c2ecf20Sopenharmony_ci */
27558c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy,
27568c2ecf20Sopenharmony_ci					    struct net_device *dev, u64 reqid)
27578c2ecf20Sopenharmony_ci{
27588c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
27598c2ecf20Sopenharmony_ci
27608c2ecf20Sopenharmony_ci	wiphy_info(wiphy, "sched scan stop!");
27618c2ecf20Sopenharmony_ci	mwifiex_stop_bg_scan(priv);
27628c2ecf20Sopenharmony_ci
27638c2ecf20Sopenharmony_ci	return 0;
27648c2ecf20Sopenharmony_ci}
27658c2ecf20Sopenharmony_ci
27668c2ecf20Sopenharmony_cistatic void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info,
27678c2ecf20Sopenharmony_ci				   struct mwifiex_private *priv)
27688c2ecf20Sopenharmony_ci{
27698c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
27708c2ecf20Sopenharmony_ci
27718c2ecf20Sopenharmony_ci	vht_info->vht_supported = true;
27728c2ecf20Sopenharmony_ci
27738c2ecf20Sopenharmony_ci	vht_info->cap = adapter->hw_dot_11ac_dev_cap;
27748c2ecf20Sopenharmony_ci	/* Update MCS support for VHT */
27758c2ecf20Sopenharmony_ci	vht_info->vht_mcs.rx_mcs_map = cpu_to_le16(
27768c2ecf20Sopenharmony_ci				adapter->hw_dot_11ac_mcs_support & 0xFFFF);
27778c2ecf20Sopenharmony_ci	vht_info->vht_mcs.rx_highest = 0;
27788c2ecf20Sopenharmony_ci	vht_info->vht_mcs.tx_mcs_map = cpu_to_le16(
27798c2ecf20Sopenharmony_ci				adapter->hw_dot_11ac_mcs_support >> 16);
27808c2ecf20Sopenharmony_ci	vht_info->vht_mcs.tx_highest = 0;
27818c2ecf20Sopenharmony_ci}
27828c2ecf20Sopenharmony_ci
27838c2ecf20Sopenharmony_ci/*
27848c2ecf20Sopenharmony_ci * This function sets up the CFG802.11 specific HT capability fields
27858c2ecf20Sopenharmony_ci * with default values.
27868c2ecf20Sopenharmony_ci *
27878c2ecf20Sopenharmony_ci * The following default values are set -
27888c2ecf20Sopenharmony_ci *      - HT Supported = True
27898c2ecf20Sopenharmony_ci *      - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K
27908c2ecf20Sopenharmony_ci *      - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE
27918c2ecf20Sopenharmony_ci *      - HT Capabilities supported by firmware
27928c2ecf20Sopenharmony_ci *      - MCS information, Rx mask = 0xff
27938c2ecf20Sopenharmony_ci *      - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01)
27948c2ecf20Sopenharmony_ci */
27958c2ecf20Sopenharmony_cistatic void
27968c2ecf20Sopenharmony_cimwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info,
27978c2ecf20Sopenharmony_ci		      struct mwifiex_private *priv)
27988c2ecf20Sopenharmony_ci{
27998c2ecf20Sopenharmony_ci	int rx_mcs_supp;
28008c2ecf20Sopenharmony_ci	struct ieee80211_mcs_info mcs_set;
28018c2ecf20Sopenharmony_ci	u8 *mcs = (u8 *)&mcs_set;
28028c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
28038c2ecf20Sopenharmony_ci
28048c2ecf20Sopenharmony_ci	ht_info->ht_supported = true;
28058c2ecf20Sopenharmony_ci	ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
28068c2ecf20Sopenharmony_ci	ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
28078c2ecf20Sopenharmony_ci
28088c2ecf20Sopenharmony_ci	memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
28098c2ecf20Sopenharmony_ci
28108c2ecf20Sopenharmony_ci	/* Fill HT capability information */
28118c2ecf20Sopenharmony_ci	if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
28128c2ecf20Sopenharmony_ci		ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
28138c2ecf20Sopenharmony_ci	else
28148c2ecf20Sopenharmony_ci		ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
28158c2ecf20Sopenharmony_ci
28168c2ecf20Sopenharmony_ci	if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap))
28178c2ecf20Sopenharmony_ci		ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
28188c2ecf20Sopenharmony_ci	else
28198c2ecf20Sopenharmony_ci		ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20;
28208c2ecf20Sopenharmony_ci
28218c2ecf20Sopenharmony_ci	if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap))
28228c2ecf20Sopenharmony_ci		ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
28238c2ecf20Sopenharmony_ci	else
28248c2ecf20Sopenharmony_ci		ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40;
28258c2ecf20Sopenharmony_ci
28268c2ecf20Sopenharmony_ci	if (adapter->user_dev_mcs_support == HT_STREAM_2X2)
28278c2ecf20Sopenharmony_ci		ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
28288c2ecf20Sopenharmony_ci	else
28298c2ecf20Sopenharmony_ci		ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT;
28308c2ecf20Sopenharmony_ci
28318c2ecf20Sopenharmony_ci	if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap))
28328c2ecf20Sopenharmony_ci		ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
28338c2ecf20Sopenharmony_ci	else
28348c2ecf20Sopenharmony_ci		ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC;
28358c2ecf20Sopenharmony_ci
28368c2ecf20Sopenharmony_ci	if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap))
28378c2ecf20Sopenharmony_ci		ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
28388c2ecf20Sopenharmony_ci	else
28398c2ecf20Sopenharmony_ci		ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD;
28408c2ecf20Sopenharmony_ci
28418c2ecf20Sopenharmony_ci	if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap))
28428c2ecf20Sopenharmony_ci		ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT;
28438c2ecf20Sopenharmony_ci	else
28448c2ecf20Sopenharmony_ci		ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT;
28458c2ecf20Sopenharmony_ci
28468c2ecf20Sopenharmony_ci	if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap))
28478c2ecf20Sopenharmony_ci		ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
28488c2ecf20Sopenharmony_ci	else
28498c2ecf20Sopenharmony_ci		ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING;
28508c2ecf20Sopenharmony_ci
28518c2ecf20Sopenharmony_ci	ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
28528c2ecf20Sopenharmony_ci	ht_info->cap |= IEEE80211_HT_CAP_SM_PS;
28538c2ecf20Sopenharmony_ci
28548c2ecf20Sopenharmony_ci	rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support);
28558c2ecf20Sopenharmony_ci	/* Set MCS for 1x1/2x2 */
28568c2ecf20Sopenharmony_ci	memset(mcs, 0xff, rx_mcs_supp);
28578c2ecf20Sopenharmony_ci	/* Clear all the other values */
28588c2ecf20Sopenharmony_ci	memset(&mcs[rx_mcs_supp], 0,
28598c2ecf20Sopenharmony_ci	       sizeof(struct ieee80211_mcs_info) - rx_mcs_supp);
28608c2ecf20Sopenharmony_ci	if (priv->bss_mode == NL80211_IFTYPE_STATION ||
28618c2ecf20Sopenharmony_ci	    ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap))
28628c2ecf20Sopenharmony_ci		/* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */
28638c2ecf20Sopenharmony_ci		SETHT_MCS32(mcs_set.rx_mask);
28648c2ecf20Sopenharmony_ci
28658c2ecf20Sopenharmony_ci	memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info));
28668c2ecf20Sopenharmony_ci
28678c2ecf20Sopenharmony_ci	ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
28688c2ecf20Sopenharmony_ci}
28698c2ecf20Sopenharmony_ci
28708c2ecf20Sopenharmony_ci/*
28718c2ecf20Sopenharmony_ci *  create a new virtual interface with the given name and name assign type
28728c2ecf20Sopenharmony_ci */
28738c2ecf20Sopenharmony_cistruct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
28748c2ecf20Sopenharmony_ci					      const char *name,
28758c2ecf20Sopenharmony_ci					      unsigned char name_assign_type,
28768c2ecf20Sopenharmony_ci					      enum nl80211_iftype type,
28778c2ecf20Sopenharmony_ci					      struct vif_params *params)
28788c2ecf20Sopenharmony_ci{
28798c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
28808c2ecf20Sopenharmony_ci	struct mwifiex_private *priv;
28818c2ecf20Sopenharmony_ci	struct net_device *dev;
28828c2ecf20Sopenharmony_ci	void *mdev_priv;
28838c2ecf20Sopenharmony_ci	int ret;
28848c2ecf20Sopenharmony_ci
28858c2ecf20Sopenharmony_ci	if (!adapter)
28868c2ecf20Sopenharmony_ci		return ERR_PTR(-EFAULT);
28878c2ecf20Sopenharmony_ci
28888c2ecf20Sopenharmony_ci	switch (type) {
28898c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_UNSPECIFIED:
28908c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
28918c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_ADHOC:
28928c2ecf20Sopenharmony_ci		if (adapter->curr_iface_comb.sta_intf ==
28938c2ecf20Sopenharmony_ci		    adapter->iface_limit.sta_intf) {
28948c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
28958c2ecf20Sopenharmony_ci				    "cannot create multiple sta/adhoc ifaces\n");
28968c2ecf20Sopenharmony_ci			return ERR_PTR(-EINVAL);
28978c2ecf20Sopenharmony_ci		}
28988c2ecf20Sopenharmony_ci
28998c2ecf20Sopenharmony_ci		priv = mwifiex_get_unused_priv_by_bss_type(
29008c2ecf20Sopenharmony_ci						adapter, MWIFIEX_BSS_TYPE_STA);
29018c2ecf20Sopenharmony_ci		if (!priv) {
29028c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
29038c2ecf20Sopenharmony_ci				    "could not get free private struct\n");
29048c2ecf20Sopenharmony_ci			return ERR_PTR(-EFAULT);
29058c2ecf20Sopenharmony_ci		}
29068c2ecf20Sopenharmony_ci
29078c2ecf20Sopenharmony_ci		priv->wdev.wiphy = wiphy;
29088c2ecf20Sopenharmony_ci		priv->wdev.iftype = NL80211_IFTYPE_STATION;
29098c2ecf20Sopenharmony_ci
29108c2ecf20Sopenharmony_ci		if (type == NL80211_IFTYPE_UNSPECIFIED)
29118c2ecf20Sopenharmony_ci			priv->bss_mode = NL80211_IFTYPE_STATION;
29128c2ecf20Sopenharmony_ci		else
29138c2ecf20Sopenharmony_ci			priv->bss_mode = type;
29148c2ecf20Sopenharmony_ci
29158c2ecf20Sopenharmony_ci		priv->bss_type = MWIFIEX_BSS_TYPE_STA;
29168c2ecf20Sopenharmony_ci		priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
29178c2ecf20Sopenharmony_ci		priv->bss_priority = 0;
29188c2ecf20Sopenharmony_ci		priv->bss_role = MWIFIEX_BSS_ROLE_STA;
29198c2ecf20Sopenharmony_ci
29208c2ecf20Sopenharmony_ci		break;
29218c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
29228c2ecf20Sopenharmony_ci		if (adapter->curr_iface_comb.uap_intf ==
29238c2ecf20Sopenharmony_ci		    adapter->iface_limit.uap_intf) {
29248c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
29258c2ecf20Sopenharmony_ci				    "cannot create multiple AP ifaces\n");
29268c2ecf20Sopenharmony_ci			return ERR_PTR(-EINVAL);
29278c2ecf20Sopenharmony_ci		}
29288c2ecf20Sopenharmony_ci
29298c2ecf20Sopenharmony_ci		priv = mwifiex_get_unused_priv_by_bss_type(
29308c2ecf20Sopenharmony_ci						adapter, MWIFIEX_BSS_TYPE_UAP);
29318c2ecf20Sopenharmony_ci		if (!priv) {
29328c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
29338c2ecf20Sopenharmony_ci				    "could not get free private struct\n");
29348c2ecf20Sopenharmony_ci			return ERR_PTR(-EFAULT);
29358c2ecf20Sopenharmony_ci		}
29368c2ecf20Sopenharmony_ci
29378c2ecf20Sopenharmony_ci		priv->wdev.wiphy = wiphy;
29388c2ecf20Sopenharmony_ci		priv->wdev.iftype = NL80211_IFTYPE_AP;
29398c2ecf20Sopenharmony_ci
29408c2ecf20Sopenharmony_ci		priv->bss_type = MWIFIEX_BSS_TYPE_UAP;
29418c2ecf20Sopenharmony_ci		priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
29428c2ecf20Sopenharmony_ci		priv->bss_priority = 0;
29438c2ecf20Sopenharmony_ci		priv->bss_role = MWIFIEX_BSS_ROLE_UAP;
29448c2ecf20Sopenharmony_ci		priv->bss_started = 0;
29458c2ecf20Sopenharmony_ci		priv->bss_mode = type;
29468c2ecf20Sopenharmony_ci
29478c2ecf20Sopenharmony_ci		break;
29488c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_CLIENT:
29498c2ecf20Sopenharmony_ci		if (adapter->curr_iface_comb.p2p_intf ==
29508c2ecf20Sopenharmony_ci		    adapter->iface_limit.p2p_intf) {
29518c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
29528c2ecf20Sopenharmony_ci				    "cannot create multiple P2P ifaces\n");
29538c2ecf20Sopenharmony_ci			return ERR_PTR(-EINVAL);
29548c2ecf20Sopenharmony_ci		}
29558c2ecf20Sopenharmony_ci
29568c2ecf20Sopenharmony_ci		priv = mwifiex_get_unused_priv_by_bss_type(
29578c2ecf20Sopenharmony_ci						adapter, MWIFIEX_BSS_TYPE_P2P);
29588c2ecf20Sopenharmony_ci		if (!priv) {
29598c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
29608c2ecf20Sopenharmony_ci				    "could not get free private struct\n");
29618c2ecf20Sopenharmony_ci			return ERR_PTR(-EFAULT);
29628c2ecf20Sopenharmony_ci		}
29638c2ecf20Sopenharmony_ci
29648c2ecf20Sopenharmony_ci		priv->wdev.wiphy = wiphy;
29658c2ecf20Sopenharmony_ci		/* At start-up, wpa_supplicant tries to change the interface
29668c2ecf20Sopenharmony_ci		 * to NL80211_IFTYPE_STATION if it is not managed mode.
29678c2ecf20Sopenharmony_ci		 */
29688c2ecf20Sopenharmony_ci		priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
29698c2ecf20Sopenharmony_ci		priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT;
29708c2ecf20Sopenharmony_ci
29718c2ecf20Sopenharmony_ci		/* Setting bss_type to P2P tells firmware that this interface
29728c2ecf20Sopenharmony_ci		 * is receiving P2P peers found during find phase and doing
29738c2ecf20Sopenharmony_ci		 * action frame handshake.
29748c2ecf20Sopenharmony_ci		 */
29758c2ecf20Sopenharmony_ci		priv->bss_type = MWIFIEX_BSS_TYPE_P2P;
29768c2ecf20Sopenharmony_ci
29778c2ecf20Sopenharmony_ci		priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II;
29788c2ecf20Sopenharmony_ci		priv->bss_priority = MWIFIEX_BSS_ROLE_STA;
29798c2ecf20Sopenharmony_ci		priv->bss_role = MWIFIEX_BSS_ROLE_STA;
29808c2ecf20Sopenharmony_ci		priv->bss_started = 0;
29818c2ecf20Sopenharmony_ci
29828c2ecf20Sopenharmony_ci		if (mwifiex_cfg80211_init_p2p_client(priv)) {
29838c2ecf20Sopenharmony_ci			memset(&priv->wdev, 0, sizeof(priv->wdev));
29848c2ecf20Sopenharmony_ci			priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
29858c2ecf20Sopenharmony_ci			return ERR_PTR(-EFAULT);
29868c2ecf20Sopenharmony_ci		}
29878c2ecf20Sopenharmony_ci
29888c2ecf20Sopenharmony_ci		break;
29898c2ecf20Sopenharmony_ci	default:
29908c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR, "type not supported\n");
29918c2ecf20Sopenharmony_ci		return ERR_PTR(-EINVAL);
29928c2ecf20Sopenharmony_ci	}
29938c2ecf20Sopenharmony_ci
29948c2ecf20Sopenharmony_ci	dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
29958c2ecf20Sopenharmony_ci			       name_assign_type, ether_setup,
29968c2ecf20Sopenharmony_ci			       IEEE80211_NUM_ACS, 1);
29978c2ecf20Sopenharmony_ci	if (!dev) {
29988c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
29998c2ecf20Sopenharmony_ci			    "no memory available for netdevice\n");
30008c2ecf20Sopenharmony_ci		ret = -ENOMEM;
30018c2ecf20Sopenharmony_ci		goto err_alloc_netdev;
30028c2ecf20Sopenharmony_ci	}
30038c2ecf20Sopenharmony_ci
30048c2ecf20Sopenharmony_ci	mwifiex_init_priv_params(priv, dev);
30058c2ecf20Sopenharmony_ci
30068c2ecf20Sopenharmony_ci	priv->netdev = dev;
30078c2ecf20Sopenharmony_ci
30088c2ecf20Sopenharmony_ci	if (!adapter->mfg_mode) {
30098c2ecf20Sopenharmony_ci		mwifiex_set_mac_address(priv, dev, false, NULL);
30108c2ecf20Sopenharmony_ci
30118c2ecf20Sopenharmony_ci		ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
30128c2ecf20Sopenharmony_ci				       HostCmd_ACT_GEN_SET, 0, NULL, true);
30138c2ecf20Sopenharmony_ci		if (ret)
30148c2ecf20Sopenharmony_ci			goto err_set_bss_mode;
30158c2ecf20Sopenharmony_ci
30168c2ecf20Sopenharmony_ci		ret = mwifiex_sta_init_cmd(priv, false, false);
30178c2ecf20Sopenharmony_ci		if (ret)
30188c2ecf20Sopenharmony_ci			goto err_sta_init;
30198c2ecf20Sopenharmony_ci	}
30208c2ecf20Sopenharmony_ci
30218c2ecf20Sopenharmony_ci	mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv);
30228c2ecf20Sopenharmony_ci	if (adapter->is_hw_11ac_capable)
30238c2ecf20Sopenharmony_ci		mwifiex_setup_vht_caps(
30248c2ecf20Sopenharmony_ci			&wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv);
30258c2ecf20Sopenharmony_ci
30268c2ecf20Sopenharmony_ci	if (adapter->config_bands & BAND_A)
30278c2ecf20Sopenharmony_ci		mwifiex_setup_ht_caps(
30288c2ecf20Sopenharmony_ci			&wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv);
30298c2ecf20Sopenharmony_ci
30308c2ecf20Sopenharmony_ci	if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable)
30318c2ecf20Sopenharmony_ci		mwifiex_setup_vht_caps(
30328c2ecf20Sopenharmony_ci			&wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv);
30338c2ecf20Sopenharmony_ci
30348c2ecf20Sopenharmony_ci	dev_net_set(dev, wiphy_net(wiphy));
30358c2ecf20Sopenharmony_ci	dev->ieee80211_ptr = &priv->wdev;
30368c2ecf20Sopenharmony_ci	dev->ieee80211_ptr->iftype = priv->bss_mode;
30378c2ecf20Sopenharmony_ci	SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
30388c2ecf20Sopenharmony_ci
30398c2ecf20Sopenharmony_ci	dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
30408c2ecf20Sopenharmony_ci	dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT;
30418c2ecf20Sopenharmony_ci	dev->needed_headroom = MWIFIEX_MIN_DATA_HEADER_LEN;
30428c2ecf20Sopenharmony_ci	dev->ethtool_ops = &mwifiex_ethtool_ops;
30438c2ecf20Sopenharmony_ci
30448c2ecf20Sopenharmony_ci	mdev_priv = netdev_priv(dev);
30458c2ecf20Sopenharmony_ci	*((unsigned long *) mdev_priv) = (unsigned long) priv;
30468c2ecf20Sopenharmony_ci
30478c2ecf20Sopenharmony_ci	SET_NETDEV_DEV(dev, adapter->dev);
30488c2ecf20Sopenharmony_ci
30498c2ecf20Sopenharmony_ci	priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s",
30508c2ecf20Sopenharmony_ci						  WQ_HIGHPRI |
30518c2ecf20Sopenharmony_ci						  WQ_MEM_RECLAIM |
30528c2ecf20Sopenharmony_ci						  WQ_UNBOUND, 1, name);
30538c2ecf20Sopenharmony_ci	if (!priv->dfs_cac_workqueue) {
30548c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR, "cannot alloc DFS CAC queue\n");
30558c2ecf20Sopenharmony_ci		ret = -ENOMEM;
30568c2ecf20Sopenharmony_ci		goto err_alloc_cac;
30578c2ecf20Sopenharmony_ci	}
30588c2ecf20Sopenharmony_ci
30598c2ecf20Sopenharmony_ci	INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue);
30608c2ecf20Sopenharmony_ci
30618c2ecf20Sopenharmony_ci	priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s",
30628c2ecf20Sopenharmony_ci						      WQ_HIGHPRI | WQ_UNBOUND |
30638c2ecf20Sopenharmony_ci						      WQ_MEM_RECLAIM, 1, name);
30648c2ecf20Sopenharmony_ci	if (!priv->dfs_chan_sw_workqueue) {
30658c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR, "cannot alloc DFS channel sw queue\n");
30668c2ecf20Sopenharmony_ci		ret = -ENOMEM;
30678c2ecf20Sopenharmony_ci		goto err_alloc_chsw;
30688c2ecf20Sopenharmony_ci	}
30698c2ecf20Sopenharmony_ci
30708c2ecf20Sopenharmony_ci	INIT_DELAYED_WORK(&priv->dfs_chan_sw_work,
30718c2ecf20Sopenharmony_ci			  mwifiex_dfs_chan_sw_work_queue);
30728c2ecf20Sopenharmony_ci
30738c2ecf20Sopenharmony_ci	mutex_init(&priv->async_mutex);
30748c2ecf20Sopenharmony_ci
30758c2ecf20Sopenharmony_ci	/* Register network device */
30768c2ecf20Sopenharmony_ci	if (register_netdevice(dev)) {
30778c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR, "cannot register network device\n");
30788c2ecf20Sopenharmony_ci		ret = -EFAULT;
30798c2ecf20Sopenharmony_ci		goto err_reg_netdev;
30808c2ecf20Sopenharmony_ci	}
30818c2ecf20Sopenharmony_ci
30828c2ecf20Sopenharmony_ci	mwifiex_dbg(adapter, INFO,
30838c2ecf20Sopenharmony_ci		    "info: %s: Marvell 802.11 Adapter\n", dev->name);
30848c2ecf20Sopenharmony_ci
30858c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
30868c2ecf20Sopenharmony_ci	mwifiex_dev_debugfs_init(priv);
30878c2ecf20Sopenharmony_ci#endif
30888c2ecf20Sopenharmony_ci
30898c2ecf20Sopenharmony_ci	switch (type) {
30908c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_UNSPECIFIED:
30918c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
30928c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_ADHOC:
30938c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.sta_intf++;
30948c2ecf20Sopenharmony_ci		break;
30958c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
30968c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.uap_intf++;
30978c2ecf20Sopenharmony_ci		break;
30988c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_CLIENT:
30998c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.p2p_intf++;
31008c2ecf20Sopenharmony_ci		break;
31018c2ecf20Sopenharmony_ci	default:
31028c2ecf20Sopenharmony_ci		/* This should be dead code; checked above */
31038c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR, "type not supported\n");
31048c2ecf20Sopenharmony_ci		return ERR_PTR(-EINVAL);
31058c2ecf20Sopenharmony_ci	}
31068c2ecf20Sopenharmony_ci
31078c2ecf20Sopenharmony_ci	return &priv->wdev;
31088c2ecf20Sopenharmony_ci
31098c2ecf20Sopenharmony_cierr_reg_netdev:
31108c2ecf20Sopenharmony_ci	destroy_workqueue(priv->dfs_chan_sw_workqueue);
31118c2ecf20Sopenharmony_ci	priv->dfs_chan_sw_workqueue = NULL;
31128c2ecf20Sopenharmony_cierr_alloc_chsw:
31138c2ecf20Sopenharmony_ci	destroy_workqueue(priv->dfs_cac_workqueue);
31148c2ecf20Sopenharmony_ci	priv->dfs_cac_workqueue = NULL;
31158c2ecf20Sopenharmony_cierr_alloc_cac:
31168c2ecf20Sopenharmony_ci	free_netdev(dev);
31178c2ecf20Sopenharmony_ci	priv->netdev = NULL;
31188c2ecf20Sopenharmony_cierr_sta_init:
31198c2ecf20Sopenharmony_cierr_set_bss_mode:
31208c2ecf20Sopenharmony_cierr_alloc_netdev:
31218c2ecf20Sopenharmony_ci	memset(&priv->wdev, 0, sizeof(priv->wdev));
31228c2ecf20Sopenharmony_ci	priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
31238c2ecf20Sopenharmony_ci	priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
31248c2ecf20Sopenharmony_ci	return ERR_PTR(ret);
31258c2ecf20Sopenharmony_ci}
31268c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
31278c2ecf20Sopenharmony_ci
31288c2ecf20Sopenharmony_ci/*
31298c2ecf20Sopenharmony_ci * del_virtual_intf: remove the virtual interface determined by dev
31308c2ecf20Sopenharmony_ci */
31318c2ecf20Sopenharmony_ciint mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
31328c2ecf20Sopenharmony_ci{
31338c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
31348c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
31358c2ecf20Sopenharmony_ci	struct sk_buff *skb, *tmp;
31368c2ecf20Sopenharmony_ci
31378c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
31388c2ecf20Sopenharmony_ci	mwifiex_dev_debugfs_remove(priv);
31398c2ecf20Sopenharmony_ci#endif
31408c2ecf20Sopenharmony_ci
31418c2ecf20Sopenharmony_ci	if (priv->sched_scanning)
31428c2ecf20Sopenharmony_ci		priv->sched_scanning = false;
31438c2ecf20Sopenharmony_ci
31448c2ecf20Sopenharmony_ci	mwifiex_stop_net_dev_queue(priv->netdev, adapter);
31458c2ecf20Sopenharmony_ci
31468c2ecf20Sopenharmony_ci	skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
31478c2ecf20Sopenharmony_ci		skb_unlink(skb, &priv->bypass_txq);
31488c2ecf20Sopenharmony_ci		mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
31498c2ecf20Sopenharmony_ci	}
31508c2ecf20Sopenharmony_ci
31518c2ecf20Sopenharmony_ci	if (netif_carrier_ok(priv->netdev))
31528c2ecf20Sopenharmony_ci		netif_carrier_off(priv->netdev);
31538c2ecf20Sopenharmony_ci
31548c2ecf20Sopenharmony_ci	if (wdev->netdev->reg_state == NETREG_REGISTERED)
31558c2ecf20Sopenharmony_ci		unregister_netdevice(wdev->netdev);
31568c2ecf20Sopenharmony_ci
31578c2ecf20Sopenharmony_ci	if (priv->dfs_cac_workqueue) {
31588c2ecf20Sopenharmony_ci		flush_workqueue(priv->dfs_cac_workqueue);
31598c2ecf20Sopenharmony_ci		destroy_workqueue(priv->dfs_cac_workqueue);
31608c2ecf20Sopenharmony_ci		priv->dfs_cac_workqueue = NULL;
31618c2ecf20Sopenharmony_ci	}
31628c2ecf20Sopenharmony_ci
31638c2ecf20Sopenharmony_ci	if (priv->dfs_chan_sw_workqueue) {
31648c2ecf20Sopenharmony_ci		flush_workqueue(priv->dfs_chan_sw_workqueue);
31658c2ecf20Sopenharmony_ci		destroy_workqueue(priv->dfs_chan_sw_workqueue);
31668c2ecf20Sopenharmony_ci		priv->dfs_chan_sw_workqueue = NULL;
31678c2ecf20Sopenharmony_ci	}
31688c2ecf20Sopenharmony_ci	/* Clear the priv in adapter */
31698c2ecf20Sopenharmony_ci	priv->netdev = NULL;
31708c2ecf20Sopenharmony_ci
31718c2ecf20Sopenharmony_ci	switch (priv->bss_mode) {
31728c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_UNSPECIFIED:
31738c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_STATION:
31748c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_ADHOC:
31758c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.sta_intf--;
31768c2ecf20Sopenharmony_ci		break;
31778c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_AP:
31788c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.uap_intf--;
31798c2ecf20Sopenharmony_ci		break;
31808c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_CLIENT:
31818c2ecf20Sopenharmony_ci	case NL80211_IFTYPE_P2P_GO:
31828c2ecf20Sopenharmony_ci		adapter->curr_iface_comb.p2p_intf--;
31838c2ecf20Sopenharmony_ci		break;
31848c2ecf20Sopenharmony_ci	default:
31858c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
31868c2ecf20Sopenharmony_ci			    "del_virtual_intf: type not supported\n");
31878c2ecf20Sopenharmony_ci		break;
31888c2ecf20Sopenharmony_ci	}
31898c2ecf20Sopenharmony_ci
31908c2ecf20Sopenharmony_ci	priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
31918c2ecf20Sopenharmony_ci
31928c2ecf20Sopenharmony_ci	if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
31938c2ecf20Sopenharmony_ci	    GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
31948c2ecf20Sopenharmony_ci		kfree(priv->hist_data);
31958c2ecf20Sopenharmony_ci
31968c2ecf20Sopenharmony_ci	return 0;
31978c2ecf20Sopenharmony_ci}
31988c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
31998c2ecf20Sopenharmony_ci
32008c2ecf20Sopenharmony_cistatic bool
32018c2ecf20Sopenharmony_cimwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq,
32028c2ecf20Sopenharmony_ci			     u8 max_byte_seq)
32038c2ecf20Sopenharmony_ci{
32048c2ecf20Sopenharmony_ci	int j, k, valid_byte_cnt = 0;
32058c2ecf20Sopenharmony_ci	bool dont_care_byte = false;
32068c2ecf20Sopenharmony_ci
32078c2ecf20Sopenharmony_ci	for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) {
32088c2ecf20Sopenharmony_ci		for (k = 0; k < 8; k++) {
32098c2ecf20Sopenharmony_ci			if (pat->mask[j] & 1 << k) {
32108c2ecf20Sopenharmony_ci				memcpy(byte_seq + valid_byte_cnt,
32118c2ecf20Sopenharmony_ci				       &pat->pattern[j * 8 + k], 1);
32128c2ecf20Sopenharmony_ci				valid_byte_cnt++;
32138c2ecf20Sopenharmony_ci				if (dont_care_byte)
32148c2ecf20Sopenharmony_ci					return false;
32158c2ecf20Sopenharmony_ci			} else {
32168c2ecf20Sopenharmony_ci				if (valid_byte_cnt)
32178c2ecf20Sopenharmony_ci					dont_care_byte = true;
32188c2ecf20Sopenharmony_ci			}
32198c2ecf20Sopenharmony_ci
32208c2ecf20Sopenharmony_ci			/* wildcard bytes record as the offset
32218c2ecf20Sopenharmony_ci			 * before the valid byte
32228c2ecf20Sopenharmony_ci			 */
32238c2ecf20Sopenharmony_ci			if (!valid_byte_cnt && !dont_care_byte)
32248c2ecf20Sopenharmony_ci				pat->pkt_offset++;
32258c2ecf20Sopenharmony_ci
32268c2ecf20Sopenharmony_ci			if (valid_byte_cnt > max_byte_seq)
32278c2ecf20Sopenharmony_ci				return false;
32288c2ecf20Sopenharmony_ci		}
32298c2ecf20Sopenharmony_ci	}
32308c2ecf20Sopenharmony_ci
32318c2ecf20Sopenharmony_ci	byte_seq[max_byte_seq] = valid_byte_cnt;
32328c2ecf20Sopenharmony_ci
32338c2ecf20Sopenharmony_ci	return true;
32348c2ecf20Sopenharmony_ci}
32358c2ecf20Sopenharmony_ci
32368c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
32378c2ecf20Sopenharmony_cistatic void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv,
32388c2ecf20Sopenharmony_ci					   struct mwifiex_mef_entry *mef_entry)
32398c2ecf20Sopenharmony_ci{
32408c2ecf20Sopenharmony_ci	int i, filt_num = 0, num_ipv4 = 0;
32418c2ecf20Sopenharmony_ci	struct in_device *in_dev;
32428c2ecf20Sopenharmony_ci	struct in_ifaddr *ifa;
32438c2ecf20Sopenharmony_ci	__be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR];
32448c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
32458c2ecf20Sopenharmony_ci
32468c2ecf20Sopenharmony_ci	mef_entry->mode = MEF_MODE_HOST_SLEEP;
32478c2ecf20Sopenharmony_ci	mef_entry->action = MEF_ACTION_AUTO_ARP;
32488c2ecf20Sopenharmony_ci
32498c2ecf20Sopenharmony_ci	/* Enable ARP offload feature */
32508c2ecf20Sopenharmony_ci	memset(ips, 0, sizeof(ips));
32518c2ecf20Sopenharmony_ci	for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
32528c2ecf20Sopenharmony_ci		if (adapter->priv[i]->netdev) {
32538c2ecf20Sopenharmony_ci			in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev);
32548c2ecf20Sopenharmony_ci			if (!in_dev)
32558c2ecf20Sopenharmony_ci				continue;
32568c2ecf20Sopenharmony_ci			ifa = rtnl_dereference(in_dev->ifa_list);
32578c2ecf20Sopenharmony_ci			if (!ifa || !ifa->ifa_local)
32588c2ecf20Sopenharmony_ci				continue;
32598c2ecf20Sopenharmony_ci			ips[i] = ifa->ifa_local;
32608c2ecf20Sopenharmony_ci			num_ipv4++;
32618c2ecf20Sopenharmony_ci		}
32628c2ecf20Sopenharmony_ci	}
32638c2ecf20Sopenharmony_ci
32648c2ecf20Sopenharmony_ci	for (i = 0; i < num_ipv4; i++) {
32658c2ecf20Sopenharmony_ci		if (!ips[i])
32668c2ecf20Sopenharmony_ci			continue;
32678c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].repeat = 1;
32688c2ecf20Sopenharmony_ci		memcpy(mef_entry->filter[filt_num].byte_seq,
32698c2ecf20Sopenharmony_ci		       (u8 *)&ips[i], sizeof(ips[i]));
32708c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].
32718c2ecf20Sopenharmony_ci			byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
32728c2ecf20Sopenharmony_ci			sizeof(ips[i]);
32738c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].offset = 46;
32748c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].filt_type = TYPE_EQ;
32758c2ecf20Sopenharmony_ci		if (filt_num) {
32768c2ecf20Sopenharmony_ci			mef_entry->filter[filt_num].filt_action =
32778c2ecf20Sopenharmony_ci				TYPE_OR;
32788c2ecf20Sopenharmony_ci		}
32798c2ecf20Sopenharmony_ci		filt_num++;
32808c2ecf20Sopenharmony_ci	}
32818c2ecf20Sopenharmony_ci
32828c2ecf20Sopenharmony_ci	mef_entry->filter[filt_num].repeat = 1;
32838c2ecf20Sopenharmony_ci	mef_entry->filter[filt_num].byte_seq[0] = 0x08;
32848c2ecf20Sopenharmony_ci	mef_entry->filter[filt_num].byte_seq[1] = 0x06;
32858c2ecf20Sopenharmony_ci	mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2;
32868c2ecf20Sopenharmony_ci	mef_entry->filter[filt_num].offset = 20;
32878c2ecf20Sopenharmony_ci	mef_entry->filter[filt_num].filt_type = TYPE_EQ;
32888c2ecf20Sopenharmony_ci	mef_entry->filter[filt_num].filt_action = TYPE_AND;
32898c2ecf20Sopenharmony_ci}
32908c2ecf20Sopenharmony_ci
32918c2ecf20Sopenharmony_cistatic int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv,
32928c2ecf20Sopenharmony_ci					struct mwifiex_ds_mef_cfg *mef_cfg,
32938c2ecf20Sopenharmony_ci					struct mwifiex_mef_entry *mef_entry,
32948c2ecf20Sopenharmony_ci					struct cfg80211_wowlan *wowlan)
32958c2ecf20Sopenharmony_ci{
32968c2ecf20Sopenharmony_ci	int i, filt_num = 0, ret = 0;
32978c2ecf20Sopenharmony_ci	bool first_pat = true;
32988c2ecf20Sopenharmony_ci	u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1];
32998c2ecf20Sopenharmony_ci	static const u8 ipv4_mc_mac[] = {0x33, 0x33};
33008c2ecf20Sopenharmony_ci	static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
33018c2ecf20Sopenharmony_ci
33028c2ecf20Sopenharmony_ci	mef_entry->mode = MEF_MODE_HOST_SLEEP;
33038c2ecf20Sopenharmony_ci	mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST;
33048c2ecf20Sopenharmony_ci
33058c2ecf20Sopenharmony_ci	for (i = 0; i < wowlan->n_patterns; i++) {
33068c2ecf20Sopenharmony_ci		memset(byte_seq, 0, sizeof(byte_seq));
33078c2ecf20Sopenharmony_ci		if (!mwifiex_is_pattern_supported(&wowlan->patterns[i],
33088c2ecf20Sopenharmony_ci					byte_seq,
33098c2ecf20Sopenharmony_ci					MWIFIEX_MEF_MAX_BYTESEQ)) {
33108c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, ERROR,
33118c2ecf20Sopenharmony_ci				    "Pattern not supported\n");
33128c2ecf20Sopenharmony_ci			return -EOPNOTSUPP;
33138c2ecf20Sopenharmony_ci		}
33148c2ecf20Sopenharmony_ci
33158c2ecf20Sopenharmony_ci		if (!wowlan->patterns[i].pkt_offset) {
33168c2ecf20Sopenharmony_ci			if (!(byte_seq[0] & 0x01) &&
33178c2ecf20Sopenharmony_ci			    (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) {
33188c2ecf20Sopenharmony_ci				mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
33198c2ecf20Sopenharmony_ci				continue;
33208c2ecf20Sopenharmony_ci			} else if (is_broadcast_ether_addr(byte_seq)) {
33218c2ecf20Sopenharmony_ci				mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST;
33228c2ecf20Sopenharmony_ci				continue;
33238c2ecf20Sopenharmony_ci			} else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
33248c2ecf20Sopenharmony_ci				    (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) ||
33258c2ecf20Sopenharmony_ci				   (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
33268c2ecf20Sopenharmony_ci				    (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) {
33278c2ecf20Sopenharmony_ci				mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST;
33288c2ecf20Sopenharmony_ci				continue;
33298c2ecf20Sopenharmony_ci			}
33308c2ecf20Sopenharmony_ci		}
33318c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].repeat = 1;
33328c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].offset =
33338c2ecf20Sopenharmony_ci			wowlan->patterns[i].pkt_offset;
33348c2ecf20Sopenharmony_ci		memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq,
33358c2ecf20Sopenharmony_ci				sizeof(byte_seq));
33368c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].filt_type = TYPE_EQ;
33378c2ecf20Sopenharmony_ci
33388c2ecf20Sopenharmony_ci		if (first_pat) {
33398c2ecf20Sopenharmony_ci			first_pat = false;
33408c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n");
33418c2ecf20Sopenharmony_ci		} else {
33428c2ecf20Sopenharmony_ci			mef_entry->filter[filt_num].filt_action = TYPE_AND;
33438c2ecf20Sopenharmony_ci		}
33448c2ecf20Sopenharmony_ci
33458c2ecf20Sopenharmony_ci		filt_num++;
33468c2ecf20Sopenharmony_ci	}
33478c2ecf20Sopenharmony_ci
33488c2ecf20Sopenharmony_ci	if (wowlan->magic_pkt) {
33498c2ecf20Sopenharmony_ci		mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST;
33508c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].repeat = 16;
33518c2ecf20Sopenharmony_ci		memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
33528c2ecf20Sopenharmony_ci				ETH_ALEN);
33538c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
33548c2ecf20Sopenharmony_ci			ETH_ALEN;
33558c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].offset = 28;
33568c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].filt_type = TYPE_EQ;
33578c2ecf20Sopenharmony_ci		if (filt_num)
33588c2ecf20Sopenharmony_ci			mef_entry->filter[filt_num].filt_action = TYPE_OR;
33598c2ecf20Sopenharmony_ci
33608c2ecf20Sopenharmony_ci		filt_num++;
33618c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].repeat = 16;
33628c2ecf20Sopenharmony_ci		memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr,
33638c2ecf20Sopenharmony_ci				ETH_ALEN);
33648c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] =
33658c2ecf20Sopenharmony_ci			ETH_ALEN;
33668c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].offset = 56;
33678c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].filt_type = TYPE_EQ;
33688c2ecf20Sopenharmony_ci		mef_entry->filter[filt_num].filt_action = TYPE_OR;
33698c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n");
33708c2ecf20Sopenharmony_ci	}
33718c2ecf20Sopenharmony_ci	return ret;
33728c2ecf20Sopenharmony_ci}
33738c2ecf20Sopenharmony_ci
33748c2ecf20Sopenharmony_cistatic int mwifiex_set_mef_filter(struct mwifiex_private *priv,
33758c2ecf20Sopenharmony_ci				  struct cfg80211_wowlan *wowlan)
33768c2ecf20Sopenharmony_ci{
33778c2ecf20Sopenharmony_ci	int ret = 0, num_entries = 1;
33788c2ecf20Sopenharmony_ci	struct mwifiex_ds_mef_cfg mef_cfg;
33798c2ecf20Sopenharmony_ci	struct mwifiex_mef_entry *mef_entry;
33808c2ecf20Sopenharmony_ci
33818c2ecf20Sopenharmony_ci	if (wowlan->n_patterns || wowlan->magic_pkt)
33828c2ecf20Sopenharmony_ci		num_entries++;
33838c2ecf20Sopenharmony_ci
33848c2ecf20Sopenharmony_ci	mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL);
33858c2ecf20Sopenharmony_ci	if (!mef_entry)
33868c2ecf20Sopenharmony_ci		return -ENOMEM;
33878c2ecf20Sopenharmony_ci
33888c2ecf20Sopenharmony_ci	memset(&mef_cfg, 0, sizeof(mef_cfg));
33898c2ecf20Sopenharmony_ci	mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST |
33908c2ecf20Sopenharmony_ci		MWIFIEX_CRITERIA_UNICAST;
33918c2ecf20Sopenharmony_ci	mef_cfg.num_entries = num_entries;
33928c2ecf20Sopenharmony_ci	mef_cfg.mef_entry = mef_entry;
33938c2ecf20Sopenharmony_ci
33948c2ecf20Sopenharmony_ci	mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]);
33958c2ecf20Sopenharmony_ci
33968c2ecf20Sopenharmony_ci	if (wowlan->n_patterns || wowlan->magic_pkt) {
33978c2ecf20Sopenharmony_ci		ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg,
33988c2ecf20Sopenharmony_ci						   &mef_entry[1], wowlan);
33998c2ecf20Sopenharmony_ci		if (ret)
34008c2ecf20Sopenharmony_ci			goto err;
34018c2ecf20Sopenharmony_ci	}
34028c2ecf20Sopenharmony_ci
34038c2ecf20Sopenharmony_ci	if (!mef_cfg.criteria)
34048c2ecf20Sopenharmony_ci		mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST |
34058c2ecf20Sopenharmony_ci			MWIFIEX_CRITERIA_UNICAST |
34068c2ecf20Sopenharmony_ci			MWIFIEX_CRITERIA_MULTICAST;
34078c2ecf20Sopenharmony_ci
34088c2ecf20Sopenharmony_ci	ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG,
34098c2ecf20Sopenharmony_ci			HostCmd_ACT_GEN_SET, 0,
34108c2ecf20Sopenharmony_ci			&mef_cfg, true);
34118c2ecf20Sopenharmony_ci
34128c2ecf20Sopenharmony_cierr:
34138c2ecf20Sopenharmony_ci	kfree(mef_entry);
34148c2ecf20Sopenharmony_ci	return ret;
34158c2ecf20Sopenharmony_ci}
34168c2ecf20Sopenharmony_ci
34178c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_suspend(struct wiphy *wiphy,
34188c2ecf20Sopenharmony_ci				    struct cfg80211_wowlan *wowlan)
34198c2ecf20Sopenharmony_ci{
34208c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
34218c2ecf20Sopenharmony_ci	struct mwifiex_ds_hs_cfg hs_cfg;
34228c2ecf20Sopenharmony_ci	int i, ret = 0, retry_num = 10;
34238c2ecf20Sopenharmony_ci	struct mwifiex_private *priv;
34248c2ecf20Sopenharmony_ci	struct mwifiex_private *sta_priv =
34258c2ecf20Sopenharmony_ci			mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
34268c2ecf20Sopenharmony_ci
34278c2ecf20Sopenharmony_ci	sta_priv->scan_aborting = true;
34288c2ecf20Sopenharmony_ci	for (i = 0; i < adapter->priv_num; i++) {
34298c2ecf20Sopenharmony_ci		priv = adapter->priv[i];
34308c2ecf20Sopenharmony_ci		mwifiex_abort_cac(priv);
34318c2ecf20Sopenharmony_ci	}
34328c2ecf20Sopenharmony_ci
34338c2ecf20Sopenharmony_ci	mwifiex_cancel_all_pending_cmd(adapter);
34348c2ecf20Sopenharmony_ci
34358c2ecf20Sopenharmony_ci	for (i = 0; i < adapter->priv_num; i++) {
34368c2ecf20Sopenharmony_ci		priv = adapter->priv[i];
34378c2ecf20Sopenharmony_ci		if (priv && priv->netdev)
34388c2ecf20Sopenharmony_ci			netif_device_detach(priv->netdev);
34398c2ecf20Sopenharmony_ci	}
34408c2ecf20Sopenharmony_ci
34418c2ecf20Sopenharmony_ci	for (i = 0; i < retry_num; i++) {
34428c2ecf20Sopenharmony_ci		if (!mwifiex_wmm_lists_empty(adapter) ||
34438c2ecf20Sopenharmony_ci		    !mwifiex_bypass_txlist_empty(adapter) ||
34448c2ecf20Sopenharmony_ci		    !skb_queue_empty(&adapter->tx_data_q))
34458c2ecf20Sopenharmony_ci			usleep_range(10000, 15000);
34468c2ecf20Sopenharmony_ci		else
34478c2ecf20Sopenharmony_ci			break;
34488c2ecf20Sopenharmony_ci	}
34498c2ecf20Sopenharmony_ci
34508c2ecf20Sopenharmony_ci	if (!wowlan) {
34518c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
34528c2ecf20Sopenharmony_ci			    "None of the WOWLAN triggers enabled\n");
34538c2ecf20Sopenharmony_ci		ret = 0;
34548c2ecf20Sopenharmony_ci		goto done;
34558c2ecf20Sopenharmony_ci	}
34568c2ecf20Sopenharmony_ci
34578c2ecf20Sopenharmony_ci	if (!sta_priv->media_connected && !wowlan->nd_config) {
34588c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
34598c2ecf20Sopenharmony_ci			    "Can not configure WOWLAN in disconnected state\n");
34608c2ecf20Sopenharmony_ci		ret = 0;
34618c2ecf20Sopenharmony_ci		goto done;
34628c2ecf20Sopenharmony_ci	}
34638c2ecf20Sopenharmony_ci
34648c2ecf20Sopenharmony_ci	ret = mwifiex_set_mef_filter(sta_priv, wowlan);
34658c2ecf20Sopenharmony_ci	if (ret) {
34668c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n");
34678c2ecf20Sopenharmony_ci		goto done;
34688c2ecf20Sopenharmony_ci	}
34698c2ecf20Sopenharmony_ci
34708c2ecf20Sopenharmony_ci	memset(&hs_cfg, 0, sizeof(hs_cfg));
34718c2ecf20Sopenharmony_ci	hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions);
34728c2ecf20Sopenharmony_ci
34738c2ecf20Sopenharmony_ci	if (wowlan->nd_config) {
34748c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, INFO, "Wake on net detect\n");
34758c2ecf20Sopenharmony_ci		hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
34768c2ecf20Sopenharmony_ci		mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev,
34778c2ecf20Sopenharmony_ci						  wowlan->nd_config);
34788c2ecf20Sopenharmony_ci	}
34798c2ecf20Sopenharmony_ci
34808c2ecf20Sopenharmony_ci	if (wowlan->disconnect) {
34818c2ecf20Sopenharmony_ci		hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT;
34828c2ecf20Sopenharmony_ci		mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n");
34838c2ecf20Sopenharmony_ci	}
34848c2ecf20Sopenharmony_ci
34858c2ecf20Sopenharmony_ci	hs_cfg.is_invoke_hostcmd = false;
34868c2ecf20Sopenharmony_ci	hs_cfg.gpio = adapter->hs_cfg.gpio;
34878c2ecf20Sopenharmony_ci	hs_cfg.gap = adapter->hs_cfg.gap;
34888c2ecf20Sopenharmony_ci	ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET,
34898c2ecf20Sopenharmony_ci				    MWIFIEX_SYNC_CMD, &hs_cfg);
34908c2ecf20Sopenharmony_ci	if (ret)
34918c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n");
34928c2ecf20Sopenharmony_ci
34938c2ecf20Sopenharmony_cidone:
34948c2ecf20Sopenharmony_ci	sta_priv->scan_aborting = false;
34958c2ecf20Sopenharmony_ci	return ret;
34968c2ecf20Sopenharmony_ci}
34978c2ecf20Sopenharmony_ci
34988c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_resume(struct wiphy *wiphy)
34998c2ecf20Sopenharmony_ci{
35008c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
35018c2ecf20Sopenharmony_ci	struct mwifiex_private *priv;
35028c2ecf20Sopenharmony_ci	struct mwifiex_ds_wakeup_reason wakeup_reason;
35038c2ecf20Sopenharmony_ci	struct cfg80211_wowlan_wakeup wakeup_report;
35048c2ecf20Sopenharmony_ci	int i;
35058c2ecf20Sopenharmony_ci	bool report_wakeup_reason = true;
35068c2ecf20Sopenharmony_ci
35078c2ecf20Sopenharmony_ci	for (i = 0; i < adapter->priv_num; i++) {
35088c2ecf20Sopenharmony_ci		priv = adapter->priv[i];
35098c2ecf20Sopenharmony_ci		if (priv && priv->netdev)
35108c2ecf20Sopenharmony_ci			netif_device_attach(priv->netdev);
35118c2ecf20Sopenharmony_ci	}
35128c2ecf20Sopenharmony_ci
35138c2ecf20Sopenharmony_ci	if (!wiphy->wowlan_config)
35148c2ecf20Sopenharmony_ci		goto done;
35158c2ecf20Sopenharmony_ci
35168c2ecf20Sopenharmony_ci	priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
35178c2ecf20Sopenharmony_ci	mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD,
35188c2ecf20Sopenharmony_ci				  &wakeup_reason);
35198c2ecf20Sopenharmony_ci	memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup));
35208c2ecf20Sopenharmony_ci
35218c2ecf20Sopenharmony_ci	wakeup_report.pattern_idx = -1;
35228c2ecf20Sopenharmony_ci
35238c2ecf20Sopenharmony_ci	switch (wakeup_reason.hs_wakeup_reason) {
35248c2ecf20Sopenharmony_ci	case NO_HSWAKEUP_REASON:
35258c2ecf20Sopenharmony_ci		break;
35268c2ecf20Sopenharmony_ci	case BCAST_DATA_MATCHED:
35278c2ecf20Sopenharmony_ci		break;
35288c2ecf20Sopenharmony_ci	case MCAST_DATA_MATCHED:
35298c2ecf20Sopenharmony_ci		break;
35308c2ecf20Sopenharmony_ci	case UCAST_DATA_MATCHED:
35318c2ecf20Sopenharmony_ci		break;
35328c2ecf20Sopenharmony_ci	case MASKTABLE_EVENT_MATCHED:
35338c2ecf20Sopenharmony_ci		break;
35348c2ecf20Sopenharmony_ci	case NON_MASKABLE_EVENT_MATCHED:
35358c2ecf20Sopenharmony_ci		if (wiphy->wowlan_config->disconnect)
35368c2ecf20Sopenharmony_ci			wakeup_report.disconnect = true;
35378c2ecf20Sopenharmony_ci		if (wiphy->wowlan_config->nd_config)
35388c2ecf20Sopenharmony_ci			wakeup_report.net_detect = adapter->nd_info;
35398c2ecf20Sopenharmony_ci		break;
35408c2ecf20Sopenharmony_ci	case NON_MASKABLE_CONDITION_MATCHED:
35418c2ecf20Sopenharmony_ci		break;
35428c2ecf20Sopenharmony_ci	case MAGIC_PATTERN_MATCHED:
35438c2ecf20Sopenharmony_ci		if (wiphy->wowlan_config->magic_pkt)
35448c2ecf20Sopenharmony_ci			wakeup_report.magic_pkt = true;
35458c2ecf20Sopenharmony_ci		if (wiphy->wowlan_config->n_patterns)
35468c2ecf20Sopenharmony_ci			wakeup_report.pattern_idx = 1;
35478c2ecf20Sopenharmony_ci		break;
35488c2ecf20Sopenharmony_ci	case GTK_REKEY_FAILURE:
35498c2ecf20Sopenharmony_ci		if (wiphy->wowlan_config->gtk_rekey_failure)
35508c2ecf20Sopenharmony_ci			wakeup_report.gtk_rekey_failure = true;
35518c2ecf20Sopenharmony_ci		break;
35528c2ecf20Sopenharmony_ci	default:
35538c2ecf20Sopenharmony_ci		report_wakeup_reason = false;
35548c2ecf20Sopenharmony_ci		break;
35558c2ecf20Sopenharmony_ci	}
35568c2ecf20Sopenharmony_ci
35578c2ecf20Sopenharmony_ci	if (report_wakeup_reason)
35588c2ecf20Sopenharmony_ci		cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report,
35598c2ecf20Sopenharmony_ci					      GFP_KERNEL);
35608c2ecf20Sopenharmony_ci
35618c2ecf20Sopenharmony_cidone:
35628c2ecf20Sopenharmony_ci	if (adapter->nd_info) {
35638c2ecf20Sopenharmony_ci		for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
35648c2ecf20Sopenharmony_ci			kfree(adapter->nd_info->matches[i]);
35658c2ecf20Sopenharmony_ci		kfree(adapter->nd_info);
35668c2ecf20Sopenharmony_ci		adapter->nd_info = NULL;
35678c2ecf20Sopenharmony_ci	}
35688c2ecf20Sopenharmony_ci
35698c2ecf20Sopenharmony_ci	return 0;
35708c2ecf20Sopenharmony_ci}
35718c2ecf20Sopenharmony_ci
35728c2ecf20Sopenharmony_cistatic void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy,
35738c2ecf20Sopenharmony_ci				       bool enabled)
35748c2ecf20Sopenharmony_ci{
35758c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
35768c2ecf20Sopenharmony_ci
35778c2ecf20Sopenharmony_ci	device_set_wakeup_enable(adapter->dev, enabled);
35788c2ecf20Sopenharmony_ci}
35798c2ecf20Sopenharmony_ci
35808c2ecf20Sopenharmony_cistatic int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev,
35818c2ecf20Sopenharmony_ci				  struct cfg80211_gtk_rekey_data *data)
35828c2ecf20Sopenharmony_ci{
35838c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
35848c2ecf20Sopenharmony_ci
35858c2ecf20Sopenharmony_ci	if (!ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
35868c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
35878c2ecf20Sopenharmony_ci
35888c2ecf20Sopenharmony_ci	return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
35898c2ecf20Sopenharmony_ci				HostCmd_ACT_GEN_SET, 0, data, true);
35908c2ecf20Sopenharmony_ci}
35918c2ecf20Sopenharmony_ci
35928c2ecf20Sopenharmony_ci#endif
35938c2ecf20Sopenharmony_ci
35948c2ecf20Sopenharmony_cistatic int mwifiex_get_coalesce_pkt_type(u8 *byte_seq)
35958c2ecf20Sopenharmony_ci{
35968c2ecf20Sopenharmony_ci	static const u8 ipv4_mc_mac[] = {0x33, 0x33};
35978c2ecf20Sopenharmony_ci	static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e};
35988c2ecf20Sopenharmony_ci	static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff};
35998c2ecf20Sopenharmony_ci
36008c2ecf20Sopenharmony_ci	if ((byte_seq[0] & 0x01) &&
36018c2ecf20Sopenharmony_ci	    (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1))
36028c2ecf20Sopenharmony_ci		return PACKET_TYPE_UNICAST;
36038c2ecf20Sopenharmony_ci	else if (!memcmp(byte_seq, bc_mac, 4))
36048c2ecf20Sopenharmony_ci		return PACKET_TYPE_BROADCAST;
36058c2ecf20Sopenharmony_ci	else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) &&
36068c2ecf20Sopenharmony_ci		  byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) ||
36078c2ecf20Sopenharmony_ci		 (!memcmp(byte_seq, ipv6_mc_mac, 3) &&
36088c2ecf20Sopenharmony_ci		  byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3))
36098c2ecf20Sopenharmony_ci		return PACKET_TYPE_MULTICAST;
36108c2ecf20Sopenharmony_ci
36118c2ecf20Sopenharmony_ci	return 0;
36128c2ecf20Sopenharmony_ci}
36138c2ecf20Sopenharmony_ci
36148c2ecf20Sopenharmony_cistatic int
36158c2ecf20Sopenharmony_cimwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv,
36168c2ecf20Sopenharmony_ci				struct cfg80211_coalesce_rules *crule,
36178c2ecf20Sopenharmony_ci				struct mwifiex_coalesce_rule *mrule)
36188c2ecf20Sopenharmony_ci{
36198c2ecf20Sopenharmony_ci	u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1];
36208c2ecf20Sopenharmony_ci	struct filt_field_param *param;
36218c2ecf20Sopenharmony_ci	int i;
36228c2ecf20Sopenharmony_ci
36238c2ecf20Sopenharmony_ci	mrule->max_coalescing_delay = crule->delay;
36248c2ecf20Sopenharmony_ci
36258c2ecf20Sopenharmony_ci	param = mrule->params;
36268c2ecf20Sopenharmony_ci
36278c2ecf20Sopenharmony_ci	for (i = 0; i < crule->n_patterns; i++) {
36288c2ecf20Sopenharmony_ci		memset(byte_seq, 0, sizeof(byte_seq));
36298c2ecf20Sopenharmony_ci		if (!mwifiex_is_pattern_supported(&crule->patterns[i],
36308c2ecf20Sopenharmony_ci						  byte_seq,
36318c2ecf20Sopenharmony_ci						MWIFIEX_COALESCE_MAX_BYTESEQ)) {
36328c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, ERROR,
36338c2ecf20Sopenharmony_ci				    "Pattern not supported\n");
36348c2ecf20Sopenharmony_ci			return -EOPNOTSUPP;
36358c2ecf20Sopenharmony_ci		}
36368c2ecf20Sopenharmony_ci
36378c2ecf20Sopenharmony_ci		if (!crule->patterns[i].pkt_offset) {
36388c2ecf20Sopenharmony_ci			u8 pkt_type;
36398c2ecf20Sopenharmony_ci
36408c2ecf20Sopenharmony_ci			pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq);
36418c2ecf20Sopenharmony_ci			if (pkt_type && mrule->pkt_type) {
36428c2ecf20Sopenharmony_ci				mwifiex_dbg(priv->adapter, ERROR,
36438c2ecf20Sopenharmony_ci					    "Multiple packet types not allowed\n");
36448c2ecf20Sopenharmony_ci				return -EOPNOTSUPP;
36458c2ecf20Sopenharmony_ci			} else if (pkt_type) {
36468c2ecf20Sopenharmony_ci				mrule->pkt_type = pkt_type;
36478c2ecf20Sopenharmony_ci				continue;
36488c2ecf20Sopenharmony_ci			}
36498c2ecf20Sopenharmony_ci		}
36508c2ecf20Sopenharmony_ci
36518c2ecf20Sopenharmony_ci		if (crule->condition == NL80211_COALESCE_CONDITION_MATCH)
36528c2ecf20Sopenharmony_ci			param->operation = RECV_FILTER_MATCH_TYPE_EQ;
36538c2ecf20Sopenharmony_ci		else
36548c2ecf20Sopenharmony_ci			param->operation = RECV_FILTER_MATCH_TYPE_NE;
36558c2ecf20Sopenharmony_ci
36568c2ecf20Sopenharmony_ci		param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ];
36578c2ecf20Sopenharmony_ci		memcpy(param->operand_byte_stream, byte_seq,
36588c2ecf20Sopenharmony_ci		       param->operand_len);
36598c2ecf20Sopenharmony_ci		param->offset = crule->patterns[i].pkt_offset;
36608c2ecf20Sopenharmony_ci		param++;
36618c2ecf20Sopenharmony_ci
36628c2ecf20Sopenharmony_ci		mrule->num_of_fields++;
36638c2ecf20Sopenharmony_ci	}
36648c2ecf20Sopenharmony_ci
36658c2ecf20Sopenharmony_ci	if (!mrule->pkt_type) {
36668c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
36678c2ecf20Sopenharmony_ci			    "Packet type can not be determined\n");
36688c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
36698c2ecf20Sopenharmony_ci	}
36708c2ecf20Sopenharmony_ci
36718c2ecf20Sopenharmony_ci	return 0;
36728c2ecf20Sopenharmony_ci}
36738c2ecf20Sopenharmony_ci
36748c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy,
36758c2ecf20Sopenharmony_ci					 struct cfg80211_coalesce *coalesce)
36768c2ecf20Sopenharmony_ci{
36778c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy);
36788c2ecf20Sopenharmony_ci	int i, ret;
36798c2ecf20Sopenharmony_ci	struct mwifiex_ds_coalesce_cfg coalesce_cfg;
36808c2ecf20Sopenharmony_ci	struct mwifiex_private *priv =
36818c2ecf20Sopenharmony_ci			mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA);
36828c2ecf20Sopenharmony_ci
36838c2ecf20Sopenharmony_ci	memset(&coalesce_cfg, 0, sizeof(coalesce_cfg));
36848c2ecf20Sopenharmony_ci	if (!coalesce) {
36858c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, WARN,
36868c2ecf20Sopenharmony_ci			    "Disable coalesce and reset all previous rules\n");
36878c2ecf20Sopenharmony_ci		return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
36888c2ecf20Sopenharmony_ci					HostCmd_ACT_GEN_SET, 0,
36898c2ecf20Sopenharmony_ci					&coalesce_cfg, true);
36908c2ecf20Sopenharmony_ci	}
36918c2ecf20Sopenharmony_ci
36928c2ecf20Sopenharmony_ci	coalesce_cfg.num_of_rules = coalesce->n_rules;
36938c2ecf20Sopenharmony_ci	for (i = 0; i < coalesce->n_rules; i++) {
36948c2ecf20Sopenharmony_ci		ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i],
36958c2ecf20Sopenharmony_ci						      &coalesce_cfg.rule[i]);
36968c2ecf20Sopenharmony_ci		if (ret) {
36978c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, ERROR,
36988c2ecf20Sopenharmony_ci				    "Recheck the patterns provided for rule %d\n",
36998c2ecf20Sopenharmony_ci				i + 1);
37008c2ecf20Sopenharmony_ci			return ret;
37018c2ecf20Sopenharmony_ci		}
37028c2ecf20Sopenharmony_ci	}
37038c2ecf20Sopenharmony_ci
37048c2ecf20Sopenharmony_ci	return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG,
37058c2ecf20Sopenharmony_ci				HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true);
37068c2ecf20Sopenharmony_ci}
37078c2ecf20Sopenharmony_ci
37088c2ecf20Sopenharmony_ci/* cfg80211 ops handler for tdls_mgmt.
37098c2ecf20Sopenharmony_ci * Function prepares TDLS action frame packets and forwards them to FW
37108c2ecf20Sopenharmony_ci */
37118c2ecf20Sopenharmony_cistatic int
37128c2ecf20Sopenharmony_cimwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
37138c2ecf20Sopenharmony_ci			   const u8 *peer, u8 action_code, u8 dialog_token,
37148c2ecf20Sopenharmony_ci			   u16 status_code, u32 peer_capability,
37158c2ecf20Sopenharmony_ci			   bool initiator, const u8 *extra_ies,
37168c2ecf20Sopenharmony_ci			   size_t extra_ies_len)
37178c2ecf20Sopenharmony_ci{
37188c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
37198c2ecf20Sopenharmony_ci	int ret;
37208c2ecf20Sopenharmony_ci
37218c2ecf20Sopenharmony_ci	if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
37228c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
37238c2ecf20Sopenharmony_ci
37248c2ecf20Sopenharmony_ci	/* make sure we are in station mode and connected */
37258c2ecf20Sopenharmony_ci	if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
37268c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
37278c2ecf20Sopenharmony_ci
37288c2ecf20Sopenharmony_ci	switch (action_code) {
37298c2ecf20Sopenharmony_ci	case WLAN_TDLS_SETUP_REQUEST:
37308c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, MSG,
37318c2ecf20Sopenharmony_ci			    "Send TDLS Setup Request to %pM status_code=%d\n",
37328c2ecf20Sopenharmony_ci			    peer, status_code);
37338c2ecf20Sopenharmony_ci		mwifiex_add_auto_tdls_peer(priv, peer);
37348c2ecf20Sopenharmony_ci		ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
37358c2ecf20Sopenharmony_ci						   dialog_token, status_code,
37368c2ecf20Sopenharmony_ci						   extra_ies, extra_ies_len);
37378c2ecf20Sopenharmony_ci		break;
37388c2ecf20Sopenharmony_ci	case WLAN_TDLS_SETUP_RESPONSE:
37398c2ecf20Sopenharmony_ci		mwifiex_add_auto_tdls_peer(priv, peer);
37408c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, MSG,
37418c2ecf20Sopenharmony_ci			    "Send TDLS Setup Response to %pM status_code=%d\n",
37428c2ecf20Sopenharmony_ci			    peer, status_code);
37438c2ecf20Sopenharmony_ci		ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
37448c2ecf20Sopenharmony_ci						   dialog_token, status_code,
37458c2ecf20Sopenharmony_ci						   extra_ies, extra_ies_len);
37468c2ecf20Sopenharmony_ci		break;
37478c2ecf20Sopenharmony_ci	case WLAN_TDLS_SETUP_CONFIRM:
37488c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, MSG,
37498c2ecf20Sopenharmony_ci			    "Send TDLS Confirm to %pM status_code=%d\n", peer,
37508c2ecf20Sopenharmony_ci			    status_code);
37518c2ecf20Sopenharmony_ci		ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
37528c2ecf20Sopenharmony_ci						   dialog_token, status_code,
37538c2ecf20Sopenharmony_ci						   extra_ies, extra_ies_len);
37548c2ecf20Sopenharmony_ci		break;
37558c2ecf20Sopenharmony_ci	case WLAN_TDLS_TEARDOWN:
37568c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, MSG,
37578c2ecf20Sopenharmony_ci			    "Send TDLS Tear down to %pM\n", peer);
37588c2ecf20Sopenharmony_ci		ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
37598c2ecf20Sopenharmony_ci						   dialog_token, status_code,
37608c2ecf20Sopenharmony_ci						   extra_ies, extra_ies_len);
37618c2ecf20Sopenharmony_ci		break;
37628c2ecf20Sopenharmony_ci	case WLAN_TDLS_DISCOVERY_REQUEST:
37638c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, MSG,
37648c2ecf20Sopenharmony_ci			    "Send TDLS Discovery Request to %pM\n", peer);
37658c2ecf20Sopenharmony_ci		ret = mwifiex_send_tdls_data_frame(priv, peer, action_code,
37668c2ecf20Sopenharmony_ci						   dialog_token, status_code,
37678c2ecf20Sopenharmony_ci						   extra_ies, extra_ies_len);
37688c2ecf20Sopenharmony_ci		break;
37698c2ecf20Sopenharmony_ci	case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
37708c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, MSG,
37718c2ecf20Sopenharmony_ci			    "Send TDLS Discovery Response to %pM\n", peer);
37728c2ecf20Sopenharmony_ci		ret = mwifiex_send_tdls_action_frame(priv, peer, action_code,
37738c2ecf20Sopenharmony_ci						   dialog_token, status_code,
37748c2ecf20Sopenharmony_ci						   extra_ies, extra_ies_len);
37758c2ecf20Sopenharmony_ci		break;
37768c2ecf20Sopenharmony_ci	default:
37778c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
37788c2ecf20Sopenharmony_ci			    "Unknown TDLS mgmt/action frame %pM\n", peer);
37798c2ecf20Sopenharmony_ci		ret = -EINVAL;
37808c2ecf20Sopenharmony_ci		break;
37818c2ecf20Sopenharmony_ci	}
37828c2ecf20Sopenharmony_ci
37838c2ecf20Sopenharmony_ci	return ret;
37848c2ecf20Sopenharmony_ci}
37858c2ecf20Sopenharmony_ci
37868c2ecf20Sopenharmony_cistatic int
37878c2ecf20Sopenharmony_cimwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
37888c2ecf20Sopenharmony_ci			   const u8 *peer, enum nl80211_tdls_operation action)
37898c2ecf20Sopenharmony_ci{
37908c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
37918c2ecf20Sopenharmony_ci
37928c2ecf20Sopenharmony_ci	if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
37938c2ecf20Sopenharmony_ci	    !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
37948c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
37958c2ecf20Sopenharmony_ci
37968c2ecf20Sopenharmony_ci	/* make sure we are in station mode and connected */
37978c2ecf20Sopenharmony_ci	if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
37988c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
37998c2ecf20Sopenharmony_ci
38008c2ecf20Sopenharmony_ci	mwifiex_dbg(priv->adapter, MSG,
38018c2ecf20Sopenharmony_ci		    "TDLS peer=%pM, oper=%d\n", peer, action);
38028c2ecf20Sopenharmony_ci
38038c2ecf20Sopenharmony_ci	switch (action) {
38048c2ecf20Sopenharmony_ci	case NL80211_TDLS_ENABLE_LINK:
38058c2ecf20Sopenharmony_ci		action = MWIFIEX_TDLS_ENABLE_LINK;
38068c2ecf20Sopenharmony_ci		break;
38078c2ecf20Sopenharmony_ci	case NL80211_TDLS_DISABLE_LINK:
38088c2ecf20Sopenharmony_ci		action = MWIFIEX_TDLS_DISABLE_LINK;
38098c2ecf20Sopenharmony_ci		break;
38108c2ecf20Sopenharmony_ci	case NL80211_TDLS_TEARDOWN:
38118c2ecf20Sopenharmony_ci		/* shouldn't happen!*/
38128c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
38138c2ecf20Sopenharmony_ci			    "tdls_oper: teardown from driver not supported\n");
38148c2ecf20Sopenharmony_ci		return -EINVAL;
38158c2ecf20Sopenharmony_ci	case NL80211_TDLS_SETUP:
38168c2ecf20Sopenharmony_ci		/* shouldn't happen!*/
38178c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
38188c2ecf20Sopenharmony_ci			    "tdls_oper: setup from driver not supported\n");
38198c2ecf20Sopenharmony_ci		return -EINVAL;
38208c2ecf20Sopenharmony_ci	case NL80211_TDLS_DISCOVERY_REQ:
38218c2ecf20Sopenharmony_ci		/* shouldn't happen!*/
38228c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
38238c2ecf20Sopenharmony_ci			    "tdls_oper: discovery from driver not supported\n");
38248c2ecf20Sopenharmony_ci		return -EINVAL;
38258c2ecf20Sopenharmony_ci	default:
38268c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
38278c2ecf20Sopenharmony_ci			    "tdls_oper: operation not supported\n");
38288c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
38298c2ecf20Sopenharmony_ci	}
38308c2ecf20Sopenharmony_ci
38318c2ecf20Sopenharmony_ci	return mwifiex_tdls_oper(priv, peer, action);
38328c2ecf20Sopenharmony_ci}
38338c2ecf20Sopenharmony_ci
38348c2ecf20Sopenharmony_cistatic int
38358c2ecf20Sopenharmony_cimwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev,
38368c2ecf20Sopenharmony_ci				  const u8 *addr, u8 oper_class,
38378c2ecf20Sopenharmony_ci				  struct cfg80211_chan_def *chandef)
38388c2ecf20Sopenharmony_ci{
38398c2ecf20Sopenharmony_ci	struct mwifiex_sta_node *sta_ptr;
38408c2ecf20Sopenharmony_ci	u16 chan;
38418c2ecf20Sopenharmony_ci	u8 second_chan_offset, band;
38428c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
38438c2ecf20Sopenharmony_ci
38448c2ecf20Sopenharmony_ci	spin_lock_bh(&priv->sta_list_spinlock);
38458c2ecf20Sopenharmony_ci	sta_ptr = mwifiex_get_sta_entry(priv, addr);
38468c2ecf20Sopenharmony_ci	if (!sta_ptr) {
38478c2ecf20Sopenharmony_ci		spin_unlock_bh(&priv->sta_list_spinlock);
38488c2ecf20Sopenharmony_ci		wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
38498c2ecf20Sopenharmony_ci			  __func__, addr);
38508c2ecf20Sopenharmony_ci		return -ENOENT;
38518c2ecf20Sopenharmony_ci	}
38528c2ecf20Sopenharmony_ci
38538c2ecf20Sopenharmony_ci	if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] &
38548c2ecf20Sopenharmony_ci	      WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) {
38558c2ecf20Sopenharmony_ci		spin_unlock_bh(&priv->sta_list_spinlock);
38568c2ecf20Sopenharmony_ci		wiphy_err(wiphy, "%pM do not support tdls cs\n", addr);
38578c2ecf20Sopenharmony_ci		return -ENOENT;
38588c2ecf20Sopenharmony_ci	}
38598c2ecf20Sopenharmony_ci
38608c2ecf20Sopenharmony_ci	if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
38618c2ecf20Sopenharmony_ci	    sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) {
38628c2ecf20Sopenharmony_ci		spin_unlock_bh(&priv->sta_list_spinlock);
38638c2ecf20Sopenharmony_ci		wiphy_err(wiphy, "channel switch is running, abort request\n");
38648c2ecf20Sopenharmony_ci		return -EALREADY;
38658c2ecf20Sopenharmony_ci	}
38668c2ecf20Sopenharmony_ci	spin_unlock_bh(&priv->sta_list_spinlock);
38678c2ecf20Sopenharmony_ci
38688c2ecf20Sopenharmony_ci	chan = chandef->chan->hw_value;
38698c2ecf20Sopenharmony_ci	second_chan_offset = mwifiex_get_sec_chan_offset(chan);
38708c2ecf20Sopenharmony_ci	band = chandef->chan->band;
38718c2ecf20Sopenharmony_ci	mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band);
38728c2ecf20Sopenharmony_ci
38738c2ecf20Sopenharmony_ci	return 0;
38748c2ecf20Sopenharmony_ci}
38758c2ecf20Sopenharmony_ci
38768c2ecf20Sopenharmony_cistatic void
38778c2ecf20Sopenharmony_cimwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy,
38788c2ecf20Sopenharmony_ci					 struct net_device *dev,
38798c2ecf20Sopenharmony_ci					 const u8 *addr)
38808c2ecf20Sopenharmony_ci{
38818c2ecf20Sopenharmony_ci	struct mwifiex_sta_node *sta_ptr;
38828c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
38838c2ecf20Sopenharmony_ci
38848c2ecf20Sopenharmony_ci	spin_lock_bh(&priv->sta_list_spinlock);
38858c2ecf20Sopenharmony_ci	sta_ptr = mwifiex_get_sta_entry(priv, addr);
38868c2ecf20Sopenharmony_ci	if (!sta_ptr) {
38878c2ecf20Sopenharmony_ci		spin_unlock_bh(&priv->sta_list_spinlock);
38888c2ecf20Sopenharmony_ci		wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n",
38898c2ecf20Sopenharmony_ci			  __func__, addr);
38908c2ecf20Sopenharmony_ci	} else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING ||
38918c2ecf20Sopenharmony_ci		     sta_ptr->tdls_status == TDLS_IN_BASE_CHAN ||
38928c2ecf20Sopenharmony_ci		     sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) {
38938c2ecf20Sopenharmony_ci		spin_unlock_bh(&priv->sta_list_spinlock);
38948c2ecf20Sopenharmony_ci		wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n",
38958c2ecf20Sopenharmony_ci			  addr);
38968c2ecf20Sopenharmony_ci	} else {
38978c2ecf20Sopenharmony_ci		spin_unlock_bh(&priv->sta_list_spinlock);
38988c2ecf20Sopenharmony_ci		mwifiex_stop_tdls_cs(priv, addr);
38998c2ecf20Sopenharmony_ci	}
39008c2ecf20Sopenharmony_ci}
39018c2ecf20Sopenharmony_ci
39028c2ecf20Sopenharmony_cistatic int
39038c2ecf20Sopenharmony_cimwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev,
39048c2ecf20Sopenharmony_ci			     const u8 *mac, struct station_parameters *params)
39058c2ecf20Sopenharmony_ci{
39068c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
39078c2ecf20Sopenharmony_ci
39088c2ecf20Sopenharmony_ci	if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
39098c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
39108c2ecf20Sopenharmony_ci
39118c2ecf20Sopenharmony_ci	/* make sure we are in station mode and connected */
39128c2ecf20Sopenharmony_ci	if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
39138c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
39148c2ecf20Sopenharmony_ci
39158c2ecf20Sopenharmony_ci	return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK);
39168c2ecf20Sopenharmony_ci}
39178c2ecf20Sopenharmony_ci
39188c2ecf20Sopenharmony_cistatic int
39198c2ecf20Sopenharmony_cimwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
39208c2ecf20Sopenharmony_ci				struct cfg80211_csa_settings *params)
39218c2ecf20Sopenharmony_ci{
39228c2ecf20Sopenharmony_ci	struct ieee_types_header *chsw_ie;
39238c2ecf20Sopenharmony_ci	struct ieee80211_channel_sw_ie *channel_sw;
39248c2ecf20Sopenharmony_ci	int chsw_msec;
39258c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
39268c2ecf20Sopenharmony_ci
39278c2ecf20Sopenharmony_ci	if (priv->adapter->scan_processing) {
39288c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
39298c2ecf20Sopenharmony_ci			    "radar detection: scan in process...\n");
39308c2ecf20Sopenharmony_ci		return -EBUSY;
39318c2ecf20Sopenharmony_ci	}
39328c2ecf20Sopenharmony_ci
39338c2ecf20Sopenharmony_ci	if (priv->wdev.cac_started)
39348c2ecf20Sopenharmony_ci		return -EBUSY;
39358c2ecf20Sopenharmony_ci
39368c2ecf20Sopenharmony_ci	if (cfg80211_chandef_identical(&params->chandef,
39378c2ecf20Sopenharmony_ci				       &priv->dfs_chandef))
39388c2ecf20Sopenharmony_ci		return -EINVAL;
39398c2ecf20Sopenharmony_ci
39408c2ecf20Sopenharmony_ci	chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH,
39418c2ecf20Sopenharmony_ci					   params->beacon_csa.tail,
39428c2ecf20Sopenharmony_ci					   params->beacon_csa.tail_len);
39438c2ecf20Sopenharmony_ci	if (!chsw_ie) {
39448c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
39458c2ecf20Sopenharmony_ci			    "Could not parse channel switch announcement IE\n");
39468c2ecf20Sopenharmony_ci		return -EINVAL;
39478c2ecf20Sopenharmony_ci	}
39488c2ecf20Sopenharmony_ci
39498c2ecf20Sopenharmony_ci	channel_sw = (void *)(chsw_ie + 1);
39508c2ecf20Sopenharmony_ci	if (channel_sw->mode) {
39518c2ecf20Sopenharmony_ci		if (netif_carrier_ok(priv->netdev))
39528c2ecf20Sopenharmony_ci			netif_carrier_off(priv->netdev);
39538c2ecf20Sopenharmony_ci		mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
39548c2ecf20Sopenharmony_ci	}
39558c2ecf20Sopenharmony_ci
39568c2ecf20Sopenharmony_ci	if (mwifiex_del_mgmt_ies(priv))
39578c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
39588c2ecf20Sopenharmony_ci			    "Failed to delete mgmt IEs!\n");
39598c2ecf20Sopenharmony_ci
39608c2ecf20Sopenharmony_ci	if (mwifiex_set_mgmt_ies(priv, &params->beacon_csa)) {
39618c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
39628c2ecf20Sopenharmony_ci			    "%s: setting mgmt ies failed\n", __func__);
39638c2ecf20Sopenharmony_ci		return -EFAULT;
39648c2ecf20Sopenharmony_ci	}
39658c2ecf20Sopenharmony_ci
39668c2ecf20Sopenharmony_ci	memcpy(&priv->dfs_chandef, &params->chandef, sizeof(priv->dfs_chandef));
39678c2ecf20Sopenharmony_ci	memcpy(&priv->beacon_after, &params->beacon_after,
39688c2ecf20Sopenharmony_ci	       sizeof(priv->beacon_after));
39698c2ecf20Sopenharmony_ci
39708c2ecf20Sopenharmony_ci	chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100);
39718c2ecf20Sopenharmony_ci	queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work,
39728c2ecf20Sopenharmony_ci			   msecs_to_jiffies(chsw_msec));
39738c2ecf20Sopenharmony_ci	return 0;
39748c2ecf20Sopenharmony_ci}
39758c2ecf20Sopenharmony_ci
39768c2ecf20Sopenharmony_cistatic int mwifiex_cfg80211_get_channel(struct wiphy *wiphy,
39778c2ecf20Sopenharmony_ci					struct wireless_dev *wdev,
39788c2ecf20Sopenharmony_ci					struct cfg80211_chan_def *chandef)
39798c2ecf20Sopenharmony_ci{
39808c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
39818c2ecf20Sopenharmony_ci	struct mwifiex_bssdescriptor *curr_bss;
39828c2ecf20Sopenharmony_ci	struct ieee80211_channel *chan;
39838c2ecf20Sopenharmony_ci	enum nl80211_channel_type chan_type;
39848c2ecf20Sopenharmony_ci	enum nl80211_band band;
39858c2ecf20Sopenharmony_ci	int freq;
39868c2ecf20Sopenharmony_ci	int ret = -ENODATA;
39878c2ecf20Sopenharmony_ci
39888c2ecf20Sopenharmony_ci	if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP &&
39898c2ecf20Sopenharmony_ci	    cfg80211_chandef_valid(&priv->bss_chandef)) {
39908c2ecf20Sopenharmony_ci		*chandef = priv->bss_chandef;
39918c2ecf20Sopenharmony_ci		ret = 0;
39928c2ecf20Sopenharmony_ci	} else if (priv->media_connected) {
39938c2ecf20Sopenharmony_ci		curr_bss = &priv->curr_bss_params.bss_descriptor;
39948c2ecf20Sopenharmony_ci		band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
39958c2ecf20Sopenharmony_ci		freq = ieee80211_channel_to_frequency(curr_bss->channel, band);
39968c2ecf20Sopenharmony_ci		chan = ieee80211_get_channel(wiphy, freq);
39978c2ecf20Sopenharmony_ci
39988c2ecf20Sopenharmony_ci		if (priv->ht_param_present) {
39998c2ecf20Sopenharmony_ci			chan_type = mwifiex_get_chan_type(priv);
40008c2ecf20Sopenharmony_ci			cfg80211_chandef_create(chandef, chan, chan_type);
40018c2ecf20Sopenharmony_ci		} else {
40028c2ecf20Sopenharmony_ci			cfg80211_chandef_create(chandef, chan,
40038c2ecf20Sopenharmony_ci						NL80211_CHAN_NO_HT);
40048c2ecf20Sopenharmony_ci		}
40058c2ecf20Sopenharmony_ci		ret = 0;
40068c2ecf20Sopenharmony_ci	}
40078c2ecf20Sopenharmony_ci
40088c2ecf20Sopenharmony_ci	return ret;
40098c2ecf20Sopenharmony_ci}
40108c2ecf20Sopenharmony_ci
40118c2ecf20Sopenharmony_ci#ifdef CONFIG_NL80211_TESTMODE
40128c2ecf20Sopenharmony_ci
40138c2ecf20Sopenharmony_cienum mwifiex_tm_attr {
40148c2ecf20Sopenharmony_ci	__MWIFIEX_TM_ATTR_INVALID	= 0,
40158c2ecf20Sopenharmony_ci	MWIFIEX_TM_ATTR_CMD		= 1,
40168c2ecf20Sopenharmony_ci	MWIFIEX_TM_ATTR_DATA		= 2,
40178c2ecf20Sopenharmony_ci
40188c2ecf20Sopenharmony_ci	/* keep last */
40198c2ecf20Sopenharmony_ci	__MWIFIEX_TM_ATTR_AFTER_LAST,
40208c2ecf20Sopenharmony_ci	MWIFIEX_TM_ATTR_MAX		= __MWIFIEX_TM_ATTR_AFTER_LAST - 1,
40218c2ecf20Sopenharmony_ci};
40228c2ecf20Sopenharmony_ci
40238c2ecf20Sopenharmony_cistatic const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = {
40248c2ecf20Sopenharmony_ci	[MWIFIEX_TM_ATTR_CMD]		= { .type = NLA_U32 },
40258c2ecf20Sopenharmony_ci	[MWIFIEX_TM_ATTR_DATA]		= { .type = NLA_BINARY,
40268c2ecf20Sopenharmony_ci					    .len = MWIFIEX_SIZE_OF_CMD_BUFFER },
40278c2ecf20Sopenharmony_ci};
40288c2ecf20Sopenharmony_ci
40298c2ecf20Sopenharmony_cienum mwifiex_tm_command {
40308c2ecf20Sopenharmony_ci	MWIFIEX_TM_CMD_HOSTCMD	= 0,
40318c2ecf20Sopenharmony_ci};
40328c2ecf20Sopenharmony_ci
40338c2ecf20Sopenharmony_cistatic int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
40348c2ecf20Sopenharmony_ci			  void *data, int len)
40358c2ecf20Sopenharmony_ci{
40368c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev);
40378c2ecf20Sopenharmony_ci	struct mwifiex_ds_misc_cmd *hostcmd;
40388c2ecf20Sopenharmony_ci	struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1];
40398c2ecf20Sopenharmony_ci	struct sk_buff *skb;
40408c2ecf20Sopenharmony_ci	int err;
40418c2ecf20Sopenharmony_ci
40428c2ecf20Sopenharmony_ci	if (!priv)
40438c2ecf20Sopenharmony_ci		return -EINVAL;
40448c2ecf20Sopenharmony_ci
40458c2ecf20Sopenharmony_ci	err = nla_parse_deprecated(tb, MWIFIEX_TM_ATTR_MAX, data, len,
40468c2ecf20Sopenharmony_ci				   mwifiex_tm_policy, NULL);
40478c2ecf20Sopenharmony_ci	if (err)
40488c2ecf20Sopenharmony_ci		return err;
40498c2ecf20Sopenharmony_ci
40508c2ecf20Sopenharmony_ci	if (!tb[MWIFIEX_TM_ATTR_CMD])
40518c2ecf20Sopenharmony_ci		return -EINVAL;
40528c2ecf20Sopenharmony_ci
40538c2ecf20Sopenharmony_ci	switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) {
40548c2ecf20Sopenharmony_ci	case MWIFIEX_TM_CMD_HOSTCMD:
40558c2ecf20Sopenharmony_ci		if (!tb[MWIFIEX_TM_ATTR_DATA])
40568c2ecf20Sopenharmony_ci			return -EINVAL;
40578c2ecf20Sopenharmony_ci
40588c2ecf20Sopenharmony_ci		hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL);
40598c2ecf20Sopenharmony_ci		if (!hostcmd)
40608c2ecf20Sopenharmony_ci			return -ENOMEM;
40618c2ecf20Sopenharmony_ci
40628c2ecf20Sopenharmony_ci		hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]);
40638c2ecf20Sopenharmony_ci		memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]),
40648c2ecf20Sopenharmony_ci		       hostcmd->len);
40658c2ecf20Sopenharmony_ci
40668c2ecf20Sopenharmony_ci		if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
40678c2ecf20Sopenharmony_ci			dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
40688c2ecf20Sopenharmony_ci			kfree(hostcmd);
40698c2ecf20Sopenharmony_ci			return -EFAULT;
40708c2ecf20Sopenharmony_ci		}
40718c2ecf20Sopenharmony_ci
40728c2ecf20Sopenharmony_ci		/* process hostcmd response*/
40738c2ecf20Sopenharmony_ci		skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
40748c2ecf20Sopenharmony_ci		if (!skb) {
40758c2ecf20Sopenharmony_ci			kfree(hostcmd);
40768c2ecf20Sopenharmony_ci			return -ENOMEM;
40778c2ecf20Sopenharmony_ci		}
40788c2ecf20Sopenharmony_ci		err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
40798c2ecf20Sopenharmony_ci			      hostcmd->len, hostcmd->cmd);
40808c2ecf20Sopenharmony_ci		if (err) {
40818c2ecf20Sopenharmony_ci			kfree(hostcmd);
40828c2ecf20Sopenharmony_ci			kfree_skb(skb);
40838c2ecf20Sopenharmony_ci			return -EMSGSIZE;
40848c2ecf20Sopenharmony_ci		}
40858c2ecf20Sopenharmony_ci
40868c2ecf20Sopenharmony_ci		err = cfg80211_testmode_reply(skb);
40878c2ecf20Sopenharmony_ci		kfree(hostcmd);
40888c2ecf20Sopenharmony_ci		return err;
40898c2ecf20Sopenharmony_ci	default:
40908c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
40918c2ecf20Sopenharmony_ci	}
40928c2ecf20Sopenharmony_ci}
40938c2ecf20Sopenharmony_ci#endif
40948c2ecf20Sopenharmony_ci
40958c2ecf20Sopenharmony_cistatic int
40968c2ecf20Sopenharmony_cimwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy,
40978c2ecf20Sopenharmony_ci				       struct net_device *dev,
40988c2ecf20Sopenharmony_ci				       struct cfg80211_chan_def *chandef,
40998c2ecf20Sopenharmony_ci				       u32 cac_time_ms)
41008c2ecf20Sopenharmony_ci{
41018c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
41028c2ecf20Sopenharmony_ci	struct mwifiex_radar_params radar_params;
41038c2ecf20Sopenharmony_ci
41048c2ecf20Sopenharmony_ci	if (priv->adapter->scan_processing) {
41058c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
41068c2ecf20Sopenharmony_ci			    "radar detection: scan already in process...\n");
41078c2ecf20Sopenharmony_ci		return -EBUSY;
41088c2ecf20Sopenharmony_ci	}
41098c2ecf20Sopenharmony_ci
41108c2ecf20Sopenharmony_ci	if (!mwifiex_is_11h_active(priv)) {
41118c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, INFO,
41128c2ecf20Sopenharmony_ci			    "Enable 11h extensions in FW\n");
41138c2ecf20Sopenharmony_ci		if (mwifiex_11h_activate(priv, true)) {
41148c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, ERROR,
41158c2ecf20Sopenharmony_ci				    "Failed to activate 11h extensions!!");
41168c2ecf20Sopenharmony_ci			return -1;
41178c2ecf20Sopenharmony_ci		}
41188c2ecf20Sopenharmony_ci		priv->state_11h.is_11h_active = true;
41198c2ecf20Sopenharmony_ci	}
41208c2ecf20Sopenharmony_ci
41218c2ecf20Sopenharmony_ci	memset(&radar_params, 0, sizeof(struct mwifiex_radar_params));
41228c2ecf20Sopenharmony_ci	radar_params.chandef = chandef;
41238c2ecf20Sopenharmony_ci	radar_params.cac_time_ms = cac_time_ms;
41248c2ecf20Sopenharmony_ci
41258c2ecf20Sopenharmony_ci	memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef));
41268c2ecf20Sopenharmony_ci
41278c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST,
41288c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, &radar_params, true))
41298c2ecf20Sopenharmony_ci		return -1;
41308c2ecf20Sopenharmony_ci
41318c2ecf20Sopenharmony_ci	queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work,
41328c2ecf20Sopenharmony_ci			   msecs_to_jiffies(cac_time_ms));
41338c2ecf20Sopenharmony_ci	return 0;
41348c2ecf20Sopenharmony_ci}
41358c2ecf20Sopenharmony_ci
41368c2ecf20Sopenharmony_cistatic int
41378c2ecf20Sopenharmony_cimwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev,
41388c2ecf20Sopenharmony_ci				const u8 *mac,
41398c2ecf20Sopenharmony_ci				struct station_parameters *params)
41408c2ecf20Sopenharmony_ci{
41418c2ecf20Sopenharmony_ci	int ret;
41428c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
41438c2ecf20Sopenharmony_ci
41448c2ecf20Sopenharmony_ci	/* we support change_station handler only for TDLS peers*/
41458c2ecf20Sopenharmony_ci	if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
41468c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
41478c2ecf20Sopenharmony_ci
41488c2ecf20Sopenharmony_ci	/* make sure we are in station mode and connected */
41498c2ecf20Sopenharmony_ci	if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected)
41508c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
41518c2ecf20Sopenharmony_ci
41528c2ecf20Sopenharmony_ci	priv->sta_params = params;
41538c2ecf20Sopenharmony_ci
41548c2ecf20Sopenharmony_ci	ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK);
41558c2ecf20Sopenharmony_ci	priv->sta_params = NULL;
41568c2ecf20Sopenharmony_ci
41578c2ecf20Sopenharmony_ci	return ret;
41588c2ecf20Sopenharmony_ci}
41598c2ecf20Sopenharmony_ci
41608c2ecf20Sopenharmony_ci/* station cfg80211 operations */
41618c2ecf20Sopenharmony_cistatic struct cfg80211_ops mwifiex_cfg80211_ops = {
41628c2ecf20Sopenharmony_ci	.add_virtual_intf = mwifiex_add_virtual_intf,
41638c2ecf20Sopenharmony_ci	.del_virtual_intf = mwifiex_del_virtual_intf,
41648c2ecf20Sopenharmony_ci	.change_virtual_intf = mwifiex_cfg80211_change_virtual_intf,
41658c2ecf20Sopenharmony_ci	.scan = mwifiex_cfg80211_scan,
41668c2ecf20Sopenharmony_ci	.connect = mwifiex_cfg80211_connect,
41678c2ecf20Sopenharmony_ci	.disconnect = mwifiex_cfg80211_disconnect,
41688c2ecf20Sopenharmony_ci	.get_station = mwifiex_cfg80211_get_station,
41698c2ecf20Sopenharmony_ci	.dump_station = mwifiex_cfg80211_dump_station,
41708c2ecf20Sopenharmony_ci	.dump_survey = mwifiex_cfg80211_dump_survey,
41718c2ecf20Sopenharmony_ci	.set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
41728c2ecf20Sopenharmony_ci	.join_ibss = mwifiex_cfg80211_join_ibss,
41738c2ecf20Sopenharmony_ci	.leave_ibss = mwifiex_cfg80211_leave_ibss,
41748c2ecf20Sopenharmony_ci	.add_key = mwifiex_cfg80211_add_key,
41758c2ecf20Sopenharmony_ci	.del_key = mwifiex_cfg80211_del_key,
41768c2ecf20Sopenharmony_ci	.set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key,
41778c2ecf20Sopenharmony_ci	.mgmt_tx = mwifiex_cfg80211_mgmt_tx,
41788c2ecf20Sopenharmony_ci	.update_mgmt_frame_registrations =
41798c2ecf20Sopenharmony_ci		mwifiex_cfg80211_update_mgmt_frame_registrations,
41808c2ecf20Sopenharmony_ci	.remain_on_channel = mwifiex_cfg80211_remain_on_channel,
41818c2ecf20Sopenharmony_ci	.cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel,
41828c2ecf20Sopenharmony_ci	.set_default_key = mwifiex_cfg80211_set_default_key,
41838c2ecf20Sopenharmony_ci	.set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
41848c2ecf20Sopenharmony_ci	.set_tx_power = mwifiex_cfg80211_set_tx_power,
41858c2ecf20Sopenharmony_ci	.get_tx_power = mwifiex_cfg80211_get_tx_power,
41868c2ecf20Sopenharmony_ci	.set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
41878c2ecf20Sopenharmony_ci	.start_ap = mwifiex_cfg80211_start_ap,
41888c2ecf20Sopenharmony_ci	.stop_ap = mwifiex_cfg80211_stop_ap,
41898c2ecf20Sopenharmony_ci	.change_beacon = mwifiex_cfg80211_change_beacon,
41908c2ecf20Sopenharmony_ci	.set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
41918c2ecf20Sopenharmony_ci	.set_antenna = mwifiex_cfg80211_set_antenna,
41928c2ecf20Sopenharmony_ci	.get_antenna = mwifiex_cfg80211_get_antenna,
41938c2ecf20Sopenharmony_ci	.del_station = mwifiex_cfg80211_del_station,
41948c2ecf20Sopenharmony_ci	.sched_scan_start = mwifiex_cfg80211_sched_scan_start,
41958c2ecf20Sopenharmony_ci	.sched_scan_stop = mwifiex_cfg80211_sched_scan_stop,
41968c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
41978c2ecf20Sopenharmony_ci	.suspend = mwifiex_cfg80211_suspend,
41988c2ecf20Sopenharmony_ci	.resume = mwifiex_cfg80211_resume,
41998c2ecf20Sopenharmony_ci	.set_wakeup = mwifiex_cfg80211_set_wakeup,
42008c2ecf20Sopenharmony_ci	.set_rekey_data = mwifiex_set_rekey_data,
42018c2ecf20Sopenharmony_ci#endif
42028c2ecf20Sopenharmony_ci	.set_coalesce = mwifiex_cfg80211_set_coalesce,
42038c2ecf20Sopenharmony_ci	.tdls_mgmt = mwifiex_cfg80211_tdls_mgmt,
42048c2ecf20Sopenharmony_ci	.tdls_oper = mwifiex_cfg80211_tdls_oper,
42058c2ecf20Sopenharmony_ci	.tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch,
42068c2ecf20Sopenharmony_ci	.tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch,
42078c2ecf20Sopenharmony_ci	.add_station = mwifiex_cfg80211_add_station,
42088c2ecf20Sopenharmony_ci	.change_station = mwifiex_cfg80211_change_station,
42098c2ecf20Sopenharmony_ci	CFG80211_TESTMODE_CMD(mwifiex_tm_cmd)
42108c2ecf20Sopenharmony_ci	.get_channel = mwifiex_cfg80211_get_channel,
42118c2ecf20Sopenharmony_ci	.start_radar_detection = mwifiex_cfg80211_start_radar_detection,
42128c2ecf20Sopenharmony_ci	.channel_switch = mwifiex_cfg80211_channel_switch,
42138c2ecf20Sopenharmony_ci};
42148c2ecf20Sopenharmony_ci
42158c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
42168c2ecf20Sopenharmony_cistatic const struct wiphy_wowlan_support mwifiex_wowlan_support = {
42178c2ecf20Sopenharmony_ci	.flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
42188c2ecf20Sopenharmony_ci		WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
42198c2ecf20Sopenharmony_ci		WIPHY_WOWLAN_GTK_REKEY_FAILURE,
42208c2ecf20Sopenharmony_ci	.n_patterns = MWIFIEX_MEF_MAX_FILTERS,
42218c2ecf20Sopenharmony_ci	.pattern_min_len = 1,
42228c2ecf20Sopenharmony_ci	.pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
42238c2ecf20Sopenharmony_ci	.max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
42248c2ecf20Sopenharmony_ci	.max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
42258c2ecf20Sopenharmony_ci};
42268c2ecf20Sopenharmony_ci
42278c2ecf20Sopenharmony_cistatic const struct wiphy_wowlan_support mwifiex_wowlan_support_no_gtk = {
42288c2ecf20Sopenharmony_ci	.flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT |
42298c2ecf20Sopenharmony_ci		 WIPHY_WOWLAN_NET_DETECT,
42308c2ecf20Sopenharmony_ci	.n_patterns = MWIFIEX_MEF_MAX_FILTERS,
42318c2ecf20Sopenharmony_ci	.pattern_min_len = 1,
42328c2ecf20Sopenharmony_ci	.pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
42338c2ecf20Sopenharmony_ci	.max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
42348c2ecf20Sopenharmony_ci	.max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS,
42358c2ecf20Sopenharmony_ci};
42368c2ecf20Sopenharmony_ci#endif
42378c2ecf20Sopenharmony_ci
42388c2ecf20Sopenharmony_cistatic bool mwifiex_is_valid_alpha2(const char *alpha2)
42398c2ecf20Sopenharmony_ci{
42408c2ecf20Sopenharmony_ci	if (!alpha2 || strlen(alpha2) != 2)
42418c2ecf20Sopenharmony_ci		return false;
42428c2ecf20Sopenharmony_ci
42438c2ecf20Sopenharmony_ci	if (isalpha(alpha2[0]) && isalpha(alpha2[1]))
42448c2ecf20Sopenharmony_ci		return true;
42458c2ecf20Sopenharmony_ci
42468c2ecf20Sopenharmony_ci	return false;
42478c2ecf20Sopenharmony_ci}
42488c2ecf20Sopenharmony_ci
42498c2ecf20Sopenharmony_cistatic const struct wiphy_coalesce_support mwifiex_coalesce_support = {
42508c2ecf20Sopenharmony_ci	.n_rules = MWIFIEX_COALESCE_MAX_RULES,
42518c2ecf20Sopenharmony_ci	.max_delay = MWIFIEX_MAX_COALESCING_DELAY,
42528c2ecf20Sopenharmony_ci	.n_patterns = MWIFIEX_COALESCE_MAX_FILTERS,
42538c2ecf20Sopenharmony_ci	.pattern_min_len = 1,
42548c2ecf20Sopenharmony_ci	.pattern_max_len = MWIFIEX_MAX_PATTERN_LEN,
42558c2ecf20Sopenharmony_ci	.max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN,
42568c2ecf20Sopenharmony_ci};
42578c2ecf20Sopenharmony_ci
42588c2ecf20Sopenharmony_ciint mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
42598c2ecf20Sopenharmony_ci{
42608c2ecf20Sopenharmony_ci	u32 n_channels_bg, n_channels_a = 0;
42618c2ecf20Sopenharmony_ci
42628c2ecf20Sopenharmony_ci	n_channels_bg = mwifiex_band_2ghz.n_channels;
42638c2ecf20Sopenharmony_ci
42648c2ecf20Sopenharmony_ci	if (adapter->config_bands & BAND_A)
42658c2ecf20Sopenharmony_ci		n_channels_a = mwifiex_band_5ghz.n_channels;
42668c2ecf20Sopenharmony_ci
42678c2ecf20Sopenharmony_ci	/* allocate twice the number total channels, since the driver issues an
42688c2ecf20Sopenharmony_ci	 * additional active scan request for hidden SSIDs on passive channels.
42698c2ecf20Sopenharmony_ci	 */
42708c2ecf20Sopenharmony_ci	adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
42718c2ecf20Sopenharmony_ci	adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats),
42728c2ecf20Sopenharmony_ci						 adapter->num_in_chan_stats));
42738c2ecf20Sopenharmony_ci
42748c2ecf20Sopenharmony_ci	if (!adapter->chan_stats)
42758c2ecf20Sopenharmony_ci		return -ENOMEM;
42768c2ecf20Sopenharmony_ci
42778c2ecf20Sopenharmony_ci	return 0;
42788c2ecf20Sopenharmony_ci}
42798c2ecf20Sopenharmony_ci
42808c2ecf20Sopenharmony_ci/*
42818c2ecf20Sopenharmony_ci * This function registers the device with CFG802.11 subsystem.
42828c2ecf20Sopenharmony_ci *
42838c2ecf20Sopenharmony_ci * The function creates the wireless device/wiphy, populates it with
42848c2ecf20Sopenharmony_ci * default parameters and handler function pointers, and finally
42858c2ecf20Sopenharmony_ci * registers the device.
42868c2ecf20Sopenharmony_ci */
42878c2ecf20Sopenharmony_ci
42888c2ecf20Sopenharmony_ciint mwifiex_register_cfg80211(struct mwifiex_adapter *adapter)
42898c2ecf20Sopenharmony_ci{
42908c2ecf20Sopenharmony_ci	int ret;
42918c2ecf20Sopenharmony_ci	void *wdev_priv;
42928c2ecf20Sopenharmony_ci	struct wiphy *wiphy;
42938c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA];
42948c2ecf20Sopenharmony_ci	u8 *country_code;
42958c2ecf20Sopenharmony_ci	u32 thr, retry;
42968c2ecf20Sopenharmony_ci
42978c2ecf20Sopenharmony_ci	/* create a new wiphy for use with cfg80211 */
42988c2ecf20Sopenharmony_ci	wiphy = wiphy_new(&mwifiex_cfg80211_ops,
42998c2ecf20Sopenharmony_ci			  sizeof(struct mwifiex_adapter *));
43008c2ecf20Sopenharmony_ci	if (!wiphy) {
43018c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
43028c2ecf20Sopenharmony_ci			    "%s: creating new wiphy\n", __func__);
43038c2ecf20Sopenharmony_ci		return -ENOMEM;
43048c2ecf20Sopenharmony_ci	}
43058c2ecf20Sopenharmony_ci	wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
43068c2ecf20Sopenharmony_ci	wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
43078c2ecf20Sopenharmony_ci	wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
43088c2ecf20Sopenharmony_ci	wiphy->max_remain_on_channel_duration = 5000;
43098c2ecf20Sopenharmony_ci	wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
43108c2ecf20Sopenharmony_ci				 BIT(NL80211_IFTYPE_P2P_CLIENT) |
43118c2ecf20Sopenharmony_ci				 BIT(NL80211_IFTYPE_P2P_GO) |
43128c2ecf20Sopenharmony_ci				 BIT(NL80211_IFTYPE_AP);
43138c2ecf20Sopenharmony_ci
43148c2ecf20Sopenharmony_ci	if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
43158c2ecf20Sopenharmony_ci		wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
43168c2ecf20Sopenharmony_ci
43178c2ecf20Sopenharmony_ci	wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz;
43188c2ecf20Sopenharmony_ci	if (adapter->config_bands & BAND_A)
43198c2ecf20Sopenharmony_ci		wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz;
43208c2ecf20Sopenharmony_ci	else
43218c2ecf20Sopenharmony_ci		wiphy->bands[NL80211_BAND_5GHZ] = NULL;
43228c2ecf20Sopenharmony_ci
43238c2ecf20Sopenharmony_ci	if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
43248c2ecf20Sopenharmony_ci		wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs;
43258c2ecf20Sopenharmony_ci	else if (adapter->is_hw_11ac_capable)
43268c2ecf20Sopenharmony_ci		wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht;
43278c2ecf20Sopenharmony_ci	else
43288c2ecf20Sopenharmony_ci		wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta;
43298c2ecf20Sopenharmony_ci	wiphy->n_iface_combinations = 1;
43308c2ecf20Sopenharmony_ci
43318c2ecf20Sopenharmony_ci	if (adapter->max_sta_conn > adapter->max_p2p_conn)
43328c2ecf20Sopenharmony_ci		wiphy->max_ap_assoc_sta = adapter->max_sta_conn;
43338c2ecf20Sopenharmony_ci	else
43348c2ecf20Sopenharmony_ci		wiphy->max_ap_assoc_sta = adapter->max_p2p_conn;
43358c2ecf20Sopenharmony_ci
43368c2ecf20Sopenharmony_ci	/* Initialize cipher suits */
43378c2ecf20Sopenharmony_ci	wiphy->cipher_suites = mwifiex_cipher_suites;
43388c2ecf20Sopenharmony_ci	wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites);
43398c2ecf20Sopenharmony_ci
43408c2ecf20Sopenharmony_ci	if (adapter->regd) {
43418c2ecf20Sopenharmony_ci		wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
43428c2ecf20Sopenharmony_ci					   REGULATORY_DISABLE_BEACON_HINTS |
43438c2ecf20Sopenharmony_ci					   REGULATORY_COUNTRY_IE_IGNORE;
43448c2ecf20Sopenharmony_ci		wiphy_apply_custom_regulatory(wiphy, adapter->regd);
43458c2ecf20Sopenharmony_ci	}
43468c2ecf20Sopenharmony_ci
43478c2ecf20Sopenharmony_ci	ether_addr_copy(wiphy->perm_addr, adapter->perm_addr);
43488c2ecf20Sopenharmony_ci	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
43498c2ecf20Sopenharmony_ci	wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
43508c2ecf20Sopenharmony_ci			WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
43518c2ecf20Sopenharmony_ci			WIPHY_FLAG_AP_UAPSD |
43528c2ecf20Sopenharmony_ci			WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
43538c2ecf20Sopenharmony_ci			WIPHY_FLAG_HAS_CHANNEL_SWITCH |
43548c2ecf20Sopenharmony_ci			WIPHY_FLAG_PS_ON_BY_DEFAULT;
43558c2ecf20Sopenharmony_ci
43568c2ecf20Sopenharmony_ci	if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
43578c2ecf20Sopenharmony_ci		wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
43588c2ecf20Sopenharmony_ci				WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
43598c2ecf20Sopenharmony_ci
43608c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
43618c2ecf20Sopenharmony_ci	if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info))
43628c2ecf20Sopenharmony_ci		wiphy->wowlan = &mwifiex_wowlan_support;
43638c2ecf20Sopenharmony_ci	else
43648c2ecf20Sopenharmony_ci		wiphy->wowlan = &mwifiex_wowlan_support_no_gtk;
43658c2ecf20Sopenharmony_ci#endif
43668c2ecf20Sopenharmony_ci
43678c2ecf20Sopenharmony_ci	wiphy->coalesce = &mwifiex_coalesce_support;
43688c2ecf20Sopenharmony_ci
43698c2ecf20Sopenharmony_ci	wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
43708c2ecf20Sopenharmony_ci				    NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
43718c2ecf20Sopenharmony_ci				    NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
43728c2ecf20Sopenharmony_ci
43738c2ecf20Sopenharmony_ci	wiphy->max_sched_scan_reqs = 1;
43748c2ecf20Sopenharmony_ci	wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH;
43758c2ecf20Sopenharmony_ci	wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
43768c2ecf20Sopenharmony_ci	wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH;
43778c2ecf20Sopenharmony_ci
43788c2ecf20Sopenharmony_ci	wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1;
43798c2ecf20Sopenharmony_ci	wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1;
43808c2ecf20Sopenharmony_ci
43818c2ecf20Sopenharmony_ci	wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER |
43828c2ecf20Sopenharmony_ci			   NL80211_FEATURE_LOW_PRIORITY_SCAN |
43838c2ecf20Sopenharmony_ci			   NL80211_FEATURE_NEED_OBSS_SCAN;
43848c2ecf20Sopenharmony_ci
43858c2ecf20Sopenharmony_ci	if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info))
43868c2ecf20Sopenharmony_ci		wiphy->features |= NL80211_FEATURE_HT_IBSS;
43878c2ecf20Sopenharmony_ci
43888c2ecf20Sopenharmony_ci	if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info))
43898c2ecf20Sopenharmony_ci		wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
43908c2ecf20Sopenharmony_ci				   NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
43918c2ecf20Sopenharmony_ci				   NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
43928c2ecf20Sopenharmony_ci
43938c2ecf20Sopenharmony_ci	if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info))
43948c2ecf20Sopenharmony_ci		wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
43958c2ecf20Sopenharmony_ci
43968c2ecf20Sopenharmony_ci	if (adapter->fw_api_ver == MWIFIEX_FW_V15)
43978c2ecf20Sopenharmony_ci		wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
43988c2ecf20Sopenharmony_ci
43998c2ecf20Sopenharmony_ci	/* Reserve space for mwifiex specific private data for BSS */
44008c2ecf20Sopenharmony_ci	wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
44018c2ecf20Sopenharmony_ci
44028c2ecf20Sopenharmony_ci	wiphy->reg_notifier = mwifiex_reg_notifier;
44038c2ecf20Sopenharmony_ci
44048c2ecf20Sopenharmony_ci	/* Set struct mwifiex_adapter pointer in wiphy_priv */
44058c2ecf20Sopenharmony_ci	wdev_priv = wiphy_priv(wiphy);
44068c2ecf20Sopenharmony_ci	*(unsigned long *)wdev_priv = (unsigned long)adapter;
44078c2ecf20Sopenharmony_ci
44088c2ecf20Sopenharmony_ci	set_wiphy_dev(wiphy, priv->adapter->dev);
44098c2ecf20Sopenharmony_ci
44108c2ecf20Sopenharmony_ci	ret = wiphy_register(wiphy);
44118c2ecf20Sopenharmony_ci	if (ret < 0) {
44128c2ecf20Sopenharmony_ci		mwifiex_dbg(adapter, ERROR,
44138c2ecf20Sopenharmony_ci			    "%s: wiphy_register failed: %d\n", __func__, ret);
44148c2ecf20Sopenharmony_ci		wiphy_free(wiphy);
44158c2ecf20Sopenharmony_ci		return ret;
44168c2ecf20Sopenharmony_ci	}
44178c2ecf20Sopenharmony_ci
44188c2ecf20Sopenharmony_ci	if (!adapter->regd) {
44198c2ecf20Sopenharmony_ci		if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) {
44208c2ecf20Sopenharmony_ci			mwifiex_dbg(adapter, INFO,
44218c2ecf20Sopenharmony_ci				    "driver hint alpha2: %2.2s\n", reg_alpha2);
44228c2ecf20Sopenharmony_ci			regulatory_hint(wiphy, reg_alpha2);
44238c2ecf20Sopenharmony_ci		} else {
44248c2ecf20Sopenharmony_ci			if (adapter->region_code == 0x00) {
44258c2ecf20Sopenharmony_ci				mwifiex_dbg(adapter, WARN,
44268c2ecf20Sopenharmony_ci					    "Ignore world regulatory domain\n");
44278c2ecf20Sopenharmony_ci			} else {
44288c2ecf20Sopenharmony_ci				wiphy->regulatory_flags |=
44298c2ecf20Sopenharmony_ci					REGULATORY_DISABLE_BEACON_HINTS |
44308c2ecf20Sopenharmony_ci					REGULATORY_COUNTRY_IE_IGNORE;
44318c2ecf20Sopenharmony_ci				country_code =
44328c2ecf20Sopenharmony_ci					mwifiex_11d_code_2_region(
44338c2ecf20Sopenharmony_ci						adapter->region_code);
44348c2ecf20Sopenharmony_ci				if (country_code &&
44358c2ecf20Sopenharmony_ci				    regulatory_hint(wiphy, country_code))
44368c2ecf20Sopenharmony_ci					mwifiex_dbg(priv->adapter, ERROR,
44378c2ecf20Sopenharmony_ci						    "regulatory_hint() failed\n");
44388c2ecf20Sopenharmony_ci			}
44398c2ecf20Sopenharmony_ci		}
44408c2ecf20Sopenharmony_ci	}
44418c2ecf20Sopenharmony_ci
44428c2ecf20Sopenharmony_ci	mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
44438c2ecf20Sopenharmony_ci			 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true);
44448c2ecf20Sopenharmony_ci	wiphy->frag_threshold = thr;
44458c2ecf20Sopenharmony_ci	mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
44468c2ecf20Sopenharmony_ci			 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true);
44478c2ecf20Sopenharmony_ci	wiphy->rts_threshold = thr;
44488c2ecf20Sopenharmony_ci	mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
44498c2ecf20Sopenharmony_ci			 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true);
44508c2ecf20Sopenharmony_ci	wiphy->retry_short = (u8) retry;
44518c2ecf20Sopenharmony_ci	mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
44528c2ecf20Sopenharmony_ci			 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true);
44538c2ecf20Sopenharmony_ci	wiphy->retry_long = (u8) retry;
44548c2ecf20Sopenharmony_ci
44558c2ecf20Sopenharmony_ci	adapter->wiphy = wiphy;
44568c2ecf20Sopenharmony_ci	return ret;
44578c2ecf20Sopenharmony_ci}
4458