18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * NXP Wireless LAN device driver: AP specific command handling
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 "main.h"
218c2ecf20Sopenharmony_ci#include "11ac.h"
228c2ecf20Sopenharmony_ci#include "11n.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* This function parses security related parameters from cfg80211_ap_settings
258c2ecf20Sopenharmony_ci * and sets into FW understandable bss_config structure.
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_ciint mwifiex_set_secure_params(struct mwifiex_private *priv,
288c2ecf20Sopenharmony_ci			      struct mwifiex_uap_bss_param *bss_config,
298c2ecf20Sopenharmony_ci			      struct cfg80211_ap_settings *params) {
308c2ecf20Sopenharmony_ci	int i;
318c2ecf20Sopenharmony_ci	struct mwifiex_wep_key wep_key;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	if (!params->privacy) {
348c2ecf20Sopenharmony_ci		bss_config->protocol = PROTOCOL_NO_SECURITY;
358c2ecf20Sopenharmony_ci		bss_config->key_mgmt = KEY_MGMT_NONE;
368c2ecf20Sopenharmony_ci		bss_config->wpa_cfg.length = 0;
378c2ecf20Sopenharmony_ci		priv->sec_info.wep_enabled = 0;
388c2ecf20Sopenharmony_ci		priv->sec_info.wpa_enabled = 0;
398c2ecf20Sopenharmony_ci		priv->sec_info.wpa2_enabled = 0;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci		return 0;
428c2ecf20Sopenharmony_ci	}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	switch (params->auth_type) {
458c2ecf20Sopenharmony_ci	case NL80211_AUTHTYPE_OPEN_SYSTEM:
468c2ecf20Sopenharmony_ci		bss_config->auth_mode = WLAN_AUTH_OPEN;
478c2ecf20Sopenharmony_ci		break;
488c2ecf20Sopenharmony_ci	case NL80211_AUTHTYPE_SHARED_KEY:
498c2ecf20Sopenharmony_ci		bss_config->auth_mode = WLAN_AUTH_SHARED_KEY;
508c2ecf20Sopenharmony_ci		break;
518c2ecf20Sopenharmony_ci	case NL80211_AUTHTYPE_NETWORK_EAP:
528c2ecf20Sopenharmony_ci		bss_config->auth_mode = WLAN_AUTH_LEAP;
538c2ecf20Sopenharmony_ci		break;
548c2ecf20Sopenharmony_ci	default:
558c2ecf20Sopenharmony_ci		bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO;
568c2ecf20Sopenharmony_ci		break;
578c2ecf20Sopenharmony_ci	}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	for (i = 0; i < params->crypto.n_akm_suites; i++) {
628c2ecf20Sopenharmony_ci		switch (params->crypto.akm_suites[i]) {
638c2ecf20Sopenharmony_ci		case WLAN_AKM_SUITE_8021X:
648c2ecf20Sopenharmony_ci			if (params->crypto.wpa_versions &
658c2ecf20Sopenharmony_ci			    NL80211_WPA_VERSION_1) {
668c2ecf20Sopenharmony_ci				bss_config->protocol = PROTOCOL_WPA;
678c2ecf20Sopenharmony_ci				bss_config->key_mgmt = KEY_MGMT_EAP;
688c2ecf20Sopenharmony_ci			}
698c2ecf20Sopenharmony_ci			if (params->crypto.wpa_versions &
708c2ecf20Sopenharmony_ci			    NL80211_WPA_VERSION_2) {
718c2ecf20Sopenharmony_ci				bss_config->protocol |= PROTOCOL_WPA2;
728c2ecf20Sopenharmony_ci				bss_config->key_mgmt = KEY_MGMT_EAP;
738c2ecf20Sopenharmony_ci			}
748c2ecf20Sopenharmony_ci			break;
758c2ecf20Sopenharmony_ci		case WLAN_AKM_SUITE_PSK:
768c2ecf20Sopenharmony_ci			if (params->crypto.wpa_versions &
778c2ecf20Sopenharmony_ci			    NL80211_WPA_VERSION_1) {
788c2ecf20Sopenharmony_ci				bss_config->protocol = PROTOCOL_WPA;
798c2ecf20Sopenharmony_ci				bss_config->key_mgmt = KEY_MGMT_PSK;
808c2ecf20Sopenharmony_ci			}
818c2ecf20Sopenharmony_ci			if (params->crypto.wpa_versions &
828c2ecf20Sopenharmony_ci			    NL80211_WPA_VERSION_2) {
838c2ecf20Sopenharmony_ci				bss_config->protocol |= PROTOCOL_WPA2;
848c2ecf20Sopenharmony_ci				bss_config->key_mgmt = KEY_MGMT_PSK;
858c2ecf20Sopenharmony_ci			}
868c2ecf20Sopenharmony_ci			break;
878c2ecf20Sopenharmony_ci		default:
888c2ecf20Sopenharmony_ci			break;
898c2ecf20Sopenharmony_ci		}
908c2ecf20Sopenharmony_ci	}
918c2ecf20Sopenharmony_ci	for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) {
928c2ecf20Sopenharmony_ci		switch (params->crypto.ciphers_pairwise[i]) {
938c2ecf20Sopenharmony_ci		case WLAN_CIPHER_SUITE_WEP40:
948c2ecf20Sopenharmony_ci		case WLAN_CIPHER_SUITE_WEP104:
958c2ecf20Sopenharmony_ci			break;
968c2ecf20Sopenharmony_ci		case WLAN_CIPHER_SUITE_TKIP:
978c2ecf20Sopenharmony_ci			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
988c2ecf20Sopenharmony_ci				bss_config->wpa_cfg.pairwise_cipher_wpa |=
998c2ecf20Sopenharmony_ci								CIPHER_TKIP;
1008c2ecf20Sopenharmony_ci			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1018c2ecf20Sopenharmony_ci				bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
1028c2ecf20Sopenharmony_ci								CIPHER_TKIP;
1038c2ecf20Sopenharmony_ci			break;
1048c2ecf20Sopenharmony_ci		case WLAN_CIPHER_SUITE_CCMP:
1058c2ecf20Sopenharmony_ci			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1068c2ecf20Sopenharmony_ci				bss_config->wpa_cfg.pairwise_cipher_wpa |=
1078c2ecf20Sopenharmony_ci								CIPHER_AES_CCMP;
1088c2ecf20Sopenharmony_ci			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1098c2ecf20Sopenharmony_ci				bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
1108c2ecf20Sopenharmony_ci								CIPHER_AES_CCMP;
1118c2ecf20Sopenharmony_ci		default:
1128c2ecf20Sopenharmony_ci			break;
1138c2ecf20Sopenharmony_ci		}
1148c2ecf20Sopenharmony_ci	}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	switch (params->crypto.cipher_group) {
1178c2ecf20Sopenharmony_ci	case WLAN_CIPHER_SUITE_WEP40:
1188c2ecf20Sopenharmony_ci	case WLAN_CIPHER_SUITE_WEP104:
1198c2ecf20Sopenharmony_ci		if (priv->sec_info.wep_enabled) {
1208c2ecf20Sopenharmony_ci			bss_config->protocol = PROTOCOL_STATIC_WEP;
1218c2ecf20Sopenharmony_ci			bss_config->key_mgmt = KEY_MGMT_NONE;
1228c2ecf20Sopenharmony_ci			bss_config->wpa_cfg.length = 0;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci			for (i = 0; i < NUM_WEP_KEYS; i++) {
1258c2ecf20Sopenharmony_ci				wep_key = priv->wep_key[i];
1268c2ecf20Sopenharmony_ci				bss_config->wep_cfg[i].key_index = i;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci				if (priv->wep_key_curr_index == i)
1298c2ecf20Sopenharmony_ci					bss_config->wep_cfg[i].is_default = 1;
1308c2ecf20Sopenharmony_ci				else
1318c2ecf20Sopenharmony_ci					bss_config->wep_cfg[i].is_default = 0;
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci				bss_config->wep_cfg[i].length =
1348c2ecf20Sopenharmony_ci							     wep_key.key_length;
1358c2ecf20Sopenharmony_ci				memcpy(&bss_config->wep_cfg[i].key,
1368c2ecf20Sopenharmony_ci				       &wep_key.key_material,
1378c2ecf20Sopenharmony_ci				       wep_key.key_length);
1388c2ecf20Sopenharmony_ci			}
1398c2ecf20Sopenharmony_ci		}
1408c2ecf20Sopenharmony_ci		break;
1418c2ecf20Sopenharmony_ci	case WLAN_CIPHER_SUITE_TKIP:
1428c2ecf20Sopenharmony_ci		bss_config->wpa_cfg.group_cipher = CIPHER_TKIP;
1438c2ecf20Sopenharmony_ci		break;
1448c2ecf20Sopenharmony_ci	case WLAN_CIPHER_SUITE_CCMP:
1458c2ecf20Sopenharmony_ci		bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP;
1468c2ecf20Sopenharmony_ci		break;
1478c2ecf20Sopenharmony_ci	default:
1488c2ecf20Sopenharmony_ci		break;
1498c2ecf20Sopenharmony_ci	}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	return 0;
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* This function updates 11n related parameters from IE and sets them into
1558c2ecf20Sopenharmony_ci * bss_config structure.
1568c2ecf20Sopenharmony_ci */
1578c2ecf20Sopenharmony_civoid
1588c2ecf20Sopenharmony_cimwifiex_set_ht_params(struct mwifiex_private *priv,
1598c2ecf20Sopenharmony_ci		      struct mwifiex_uap_bss_param *bss_cfg,
1608c2ecf20Sopenharmony_ci		      struct cfg80211_ap_settings *params)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	const u8 *ht_ie;
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
1658c2ecf20Sopenharmony_ci		return;
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
1688c2ecf20Sopenharmony_ci				 params->beacon.tail_len);
1698c2ecf20Sopenharmony_ci	if (ht_ie) {
1708c2ecf20Sopenharmony_ci		memcpy(&bss_cfg->ht_cap, ht_ie + 2,
1718c2ecf20Sopenharmony_ci		       sizeof(struct ieee80211_ht_cap));
1728c2ecf20Sopenharmony_ci		priv->ap_11n_enabled = 1;
1738c2ecf20Sopenharmony_ci	} else {
1748c2ecf20Sopenharmony_ci		memset(&bss_cfg->ht_cap, 0, sizeof(struct ieee80211_ht_cap));
1758c2ecf20Sopenharmony_ci		bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
1768c2ecf20Sopenharmony_ci		bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
1778c2ecf20Sopenharmony_ci	}
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	return;
1808c2ecf20Sopenharmony_ci}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* This function updates 11ac related parameters from IE
1838c2ecf20Sopenharmony_ci * and sets them into bss_config structure.
1848c2ecf20Sopenharmony_ci */
1858c2ecf20Sopenharmony_civoid mwifiex_set_vht_params(struct mwifiex_private *priv,
1868c2ecf20Sopenharmony_ci			    struct mwifiex_uap_bss_param *bss_cfg,
1878c2ecf20Sopenharmony_ci			    struct cfg80211_ap_settings *params)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	const u8 *vht_ie;
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	vht_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, params->beacon.tail,
1928c2ecf20Sopenharmony_ci				  params->beacon.tail_len);
1938c2ecf20Sopenharmony_ci	if (vht_ie) {
1948c2ecf20Sopenharmony_ci		memcpy(&bss_cfg->vht_cap, vht_ie + 2,
1958c2ecf20Sopenharmony_ci		       sizeof(struct ieee80211_vht_cap));
1968c2ecf20Sopenharmony_ci		priv->ap_11ac_enabled = 1;
1978c2ecf20Sopenharmony_ci	} else {
1988c2ecf20Sopenharmony_ci		priv->ap_11ac_enabled = 0;
1998c2ecf20Sopenharmony_ci	}
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	return;
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* This function updates 11ac related parameters from IE
2058c2ecf20Sopenharmony_ci * and sets them into bss_config structure.
2068c2ecf20Sopenharmony_ci */
2078c2ecf20Sopenharmony_civoid mwifiex_set_tpc_params(struct mwifiex_private *priv,
2088c2ecf20Sopenharmony_ci			    struct mwifiex_uap_bss_param *bss_cfg,
2098c2ecf20Sopenharmony_ci			    struct cfg80211_ap_settings *params)
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci	const u8 *tpc_ie;
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci	tpc_ie = cfg80211_find_ie(WLAN_EID_TPC_REQUEST, params->beacon.tail,
2148c2ecf20Sopenharmony_ci				  params->beacon.tail_len);
2158c2ecf20Sopenharmony_ci	if (tpc_ie)
2168c2ecf20Sopenharmony_ci		bss_cfg->power_constraint = *(tpc_ie + 2);
2178c2ecf20Sopenharmony_ci	else
2188c2ecf20Sopenharmony_ci		bss_cfg->power_constraint = 0;
2198c2ecf20Sopenharmony_ci}
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/* Enable VHT only when cfg80211_ap_settings has VHT IE.
2228c2ecf20Sopenharmony_ci * Otherwise disable VHT.
2238c2ecf20Sopenharmony_ci */
2248c2ecf20Sopenharmony_civoid mwifiex_set_vht_width(struct mwifiex_private *priv,
2258c2ecf20Sopenharmony_ci			   enum nl80211_chan_width width,
2268c2ecf20Sopenharmony_ci			   bool ap_11ac_enable)
2278c2ecf20Sopenharmony_ci{
2288c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter = priv->adapter;
2298c2ecf20Sopenharmony_ci	struct mwifiex_11ac_vht_cfg vht_cfg;
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci	vht_cfg.band_config = VHT_CFG_5GHZ;
2328c2ecf20Sopenharmony_ci	vht_cfg.cap_info = adapter->hw_dot_11ac_dev_cap;
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	if (!ap_11ac_enable) {
2358c2ecf20Sopenharmony_ci		vht_cfg.mcs_tx_set = DISABLE_VHT_MCS_SET;
2368c2ecf20Sopenharmony_ci		vht_cfg.mcs_rx_set = DISABLE_VHT_MCS_SET;
2378c2ecf20Sopenharmony_ci	} else {
2388c2ecf20Sopenharmony_ci		vht_cfg.mcs_tx_set = DEFAULT_VHT_MCS_SET;
2398c2ecf20Sopenharmony_ci		vht_cfg.mcs_rx_set = DEFAULT_VHT_MCS_SET;
2408c2ecf20Sopenharmony_ci	}
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	vht_cfg.misc_config  = VHT_CAP_UAP_ONLY;
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	if (ap_11ac_enable && width >= NL80211_CHAN_WIDTH_80)
2458c2ecf20Sopenharmony_ci		vht_cfg.misc_config |= VHT_BW_80_160_80P80;
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	mwifiex_send_cmd(priv, HostCmd_CMD_11AC_CFG,
2488c2ecf20Sopenharmony_ci			 HostCmd_ACT_GEN_SET, 0, &vht_cfg, true);
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	return;
2518c2ecf20Sopenharmony_ci}
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci/* This function finds supported rates IE from beacon parameter and sets
2548c2ecf20Sopenharmony_ci * these rates into bss_config structure.
2558c2ecf20Sopenharmony_ci */
2568c2ecf20Sopenharmony_civoid
2578c2ecf20Sopenharmony_cimwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
2588c2ecf20Sopenharmony_ci		      struct cfg80211_ap_settings *params)
2598c2ecf20Sopenharmony_ci{
2608c2ecf20Sopenharmony_ci	struct ieee_types_header *rate_ie;
2618c2ecf20Sopenharmony_ci	int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
2628c2ecf20Sopenharmony_ci	const u8 *var_pos = params->beacon.head + var_offset;
2638c2ecf20Sopenharmony_ci	int len = params->beacon.head_len - var_offset;
2648c2ecf20Sopenharmony_ci	u8 rate_len = 0;
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
2678c2ecf20Sopenharmony_ci	if (rate_ie) {
2688c2ecf20Sopenharmony_ci		if (rate_ie->len > MWIFIEX_SUPPORTED_RATES)
2698c2ecf20Sopenharmony_ci			return;
2708c2ecf20Sopenharmony_ci		memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
2718c2ecf20Sopenharmony_ci		rate_len = rate_ie->len;
2728c2ecf20Sopenharmony_ci	}
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	rate_ie = (void *)cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
2758c2ecf20Sopenharmony_ci					   params->beacon.tail,
2768c2ecf20Sopenharmony_ci					   params->beacon.tail_len);
2778c2ecf20Sopenharmony_ci	if (rate_ie) {
2788c2ecf20Sopenharmony_ci		if (rate_ie->len > MWIFIEX_SUPPORTED_RATES - rate_len)
2798c2ecf20Sopenharmony_ci			return;
2808c2ecf20Sopenharmony_ci		memcpy(bss_cfg->rates + rate_len, rate_ie + 1, rate_ie->len);
2818c2ecf20Sopenharmony_ci	}
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	return;
2848c2ecf20Sopenharmony_ci}
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci/* This function initializes some of mwifiex_uap_bss_param variables.
2878c2ecf20Sopenharmony_ci * This helps FW in ignoring invalid values. These values may or may not
2888c2ecf20Sopenharmony_ci * be get updated to valid ones at later stage.
2898c2ecf20Sopenharmony_ci */
2908c2ecf20Sopenharmony_civoid mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
2918c2ecf20Sopenharmony_ci{
2928c2ecf20Sopenharmony_ci	config->bcast_ssid_ctl = 0x7F;
2938c2ecf20Sopenharmony_ci	config->radio_ctl = 0x7F;
2948c2ecf20Sopenharmony_ci	config->dtim_period = 0x7F;
2958c2ecf20Sopenharmony_ci	config->beacon_period = 0x7FFF;
2968c2ecf20Sopenharmony_ci	config->auth_mode = 0x7F;
2978c2ecf20Sopenharmony_ci	config->rts_threshold = 0x7FFF;
2988c2ecf20Sopenharmony_ci	config->frag_threshold = 0x7FFF;
2998c2ecf20Sopenharmony_ci	config->retry_limit = 0x7F;
3008c2ecf20Sopenharmony_ci	config->qos_info = 0xFF;
3018c2ecf20Sopenharmony_ci}
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci/* This function parses BSS related parameters from structure
3048c2ecf20Sopenharmony_ci * and prepares TLVs specific to WPA/WPA2 security.
3058c2ecf20Sopenharmony_ci * These TLVs are appended to command buffer.
3068c2ecf20Sopenharmony_ci */
3078c2ecf20Sopenharmony_cistatic void
3088c2ecf20Sopenharmony_cimwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	struct host_cmd_tlv_pwk_cipher *pwk_cipher;
3118c2ecf20Sopenharmony_ci	struct host_cmd_tlv_gwk_cipher *gwk_cipher;
3128c2ecf20Sopenharmony_ci	struct host_cmd_tlv_passphrase *passphrase;
3138c2ecf20Sopenharmony_ci	struct host_cmd_tlv_akmp *tlv_akmp;
3148c2ecf20Sopenharmony_ci	struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
3158c2ecf20Sopenharmony_ci	u16 cmd_size = *param_size;
3168c2ecf20Sopenharmony_ci	u8 *tlv = *tlv_buf;
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
3198c2ecf20Sopenharmony_ci	tlv_akmp->header.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
3208c2ecf20Sopenharmony_ci	tlv_akmp->header.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
3218c2ecf20Sopenharmony_ci					sizeof(struct mwifiex_ie_types_header));
3228c2ecf20Sopenharmony_ci	tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
3238c2ecf20Sopenharmony_ci	tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
3248c2ecf20Sopenharmony_ci	cmd_size += sizeof(struct host_cmd_tlv_akmp);
3258c2ecf20Sopenharmony_ci	tlv += sizeof(struct host_cmd_tlv_akmp);
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
3288c2ecf20Sopenharmony_ci		pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
3298c2ecf20Sopenharmony_ci		pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
3308c2ecf20Sopenharmony_ci		pwk_cipher->header.len =
3318c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
3328c2ecf20Sopenharmony_ci				    sizeof(struct mwifiex_ie_types_header));
3338c2ecf20Sopenharmony_ci		pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
3348c2ecf20Sopenharmony_ci		pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
3358c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
3368c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
3378c2ecf20Sopenharmony_ci	}
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
3408c2ecf20Sopenharmony_ci		pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
3418c2ecf20Sopenharmony_ci		pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
3428c2ecf20Sopenharmony_ci		pwk_cipher->header.len =
3438c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
3448c2ecf20Sopenharmony_ci				    sizeof(struct mwifiex_ie_types_header));
3458c2ecf20Sopenharmony_ci		pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
3468c2ecf20Sopenharmony_ci		pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
3478c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
3488c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
3498c2ecf20Sopenharmony_ci	}
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
3528c2ecf20Sopenharmony_ci		gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
3538c2ecf20Sopenharmony_ci		gwk_cipher->header.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
3548c2ecf20Sopenharmony_ci		gwk_cipher->header.len =
3558c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
3568c2ecf20Sopenharmony_ci				    sizeof(struct mwifiex_ie_types_header));
3578c2ecf20Sopenharmony_ci		gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
3588c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
3598c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
3608c2ecf20Sopenharmony_ci	}
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci	if (bss_cfg->wpa_cfg.length) {
3638c2ecf20Sopenharmony_ci		passphrase = (struct host_cmd_tlv_passphrase *)tlv;
3648c2ecf20Sopenharmony_ci		passphrase->header.type =
3658c2ecf20Sopenharmony_ci				cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
3668c2ecf20Sopenharmony_ci		passphrase->header.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
3678c2ecf20Sopenharmony_ci		memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
3688c2ecf20Sopenharmony_ci		       bss_cfg->wpa_cfg.length);
3698c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct mwifiex_ie_types_header) +
3708c2ecf20Sopenharmony_ci			    bss_cfg->wpa_cfg.length;
3718c2ecf20Sopenharmony_ci		tlv += sizeof(struct mwifiex_ie_types_header) +
3728c2ecf20Sopenharmony_ci				bss_cfg->wpa_cfg.length;
3738c2ecf20Sopenharmony_ci	}
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	*param_size = cmd_size;
3768c2ecf20Sopenharmony_ci	*tlv_buf = tlv;
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci	return;
3798c2ecf20Sopenharmony_ci}
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci/* This function parses WMM related parameters from cfg80211_ap_settings
3828c2ecf20Sopenharmony_ci * structure and updates bss_config structure.
3838c2ecf20Sopenharmony_ci */
3848c2ecf20Sopenharmony_civoid
3858c2ecf20Sopenharmony_cimwifiex_set_wmm_params(struct mwifiex_private *priv,
3868c2ecf20Sopenharmony_ci		       struct mwifiex_uap_bss_param *bss_cfg,
3878c2ecf20Sopenharmony_ci		       struct cfg80211_ap_settings *params)
3888c2ecf20Sopenharmony_ci{
3898c2ecf20Sopenharmony_ci	const u8 *vendor_ie;
3908c2ecf20Sopenharmony_ci	const u8 *wmm_ie;
3918c2ecf20Sopenharmony_ci	u8 wmm_oui[] = {0x00, 0x50, 0xf2, 0x02};
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
3948c2ecf20Sopenharmony_ci					    WLAN_OUI_TYPE_MICROSOFT_WMM,
3958c2ecf20Sopenharmony_ci					    params->beacon.tail,
3968c2ecf20Sopenharmony_ci					    params->beacon.tail_len);
3978c2ecf20Sopenharmony_ci	if (vendor_ie) {
3988c2ecf20Sopenharmony_ci		wmm_ie = vendor_ie;
3998c2ecf20Sopenharmony_ci		if (*(wmm_ie + 1) > sizeof(struct mwifiex_types_wmm_info))
4008c2ecf20Sopenharmony_ci			return;
4018c2ecf20Sopenharmony_ci		memcpy(&bss_cfg->wmm_info, wmm_ie +
4028c2ecf20Sopenharmony_ci		       sizeof(struct ieee_types_header), *(wmm_ie + 1));
4038c2ecf20Sopenharmony_ci		priv->wmm_enabled = 1;
4048c2ecf20Sopenharmony_ci	} else {
4058c2ecf20Sopenharmony_ci		memset(&bss_cfg->wmm_info, 0, sizeof(bss_cfg->wmm_info));
4068c2ecf20Sopenharmony_ci		memcpy(&bss_cfg->wmm_info.oui, wmm_oui, sizeof(wmm_oui));
4078c2ecf20Sopenharmony_ci		bss_cfg->wmm_info.subtype = MWIFIEX_WMM_SUBTYPE;
4088c2ecf20Sopenharmony_ci		bss_cfg->wmm_info.version = MWIFIEX_WMM_VERSION;
4098c2ecf20Sopenharmony_ci		priv->wmm_enabled = 0;
4108c2ecf20Sopenharmony_ci	}
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	bss_cfg->qos_info = 0x00;
4138c2ecf20Sopenharmony_ci	return;
4148c2ecf20Sopenharmony_ci}
4158c2ecf20Sopenharmony_ci/* This function parses BSS related parameters from structure
4168c2ecf20Sopenharmony_ci * and prepares TLVs specific to WEP encryption.
4178c2ecf20Sopenharmony_ci * These TLVs are appended to command buffer.
4188c2ecf20Sopenharmony_ci */
4198c2ecf20Sopenharmony_cistatic void
4208c2ecf20Sopenharmony_cimwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
4218c2ecf20Sopenharmony_ci{
4228c2ecf20Sopenharmony_ci	struct host_cmd_tlv_wep_key *wep_key;
4238c2ecf20Sopenharmony_ci	u16 cmd_size = *param_size;
4248c2ecf20Sopenharmony_ci	int i;
4258c2ecf20Sopenharmony_ci	u8 *tlv = *tlv_buf;
4268c2ecf20Sopenharmony_ci	struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	for (i = 0; i < NUM_WEP_KEYS; i++) {
4298c2ecf20Sopenharmony_ci		if (bss_cfg->wep_cfg[i].length &&
4308c2ecf20Sopenharmony_ci		    (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
4318c2ecf20Sopenharmony_ci		     bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
4328c2ecf20Sopenharmony_ci			wep_key = (struct host_cmd_tlv_wep_key *)tlv;
4338c2ecf20Sopenharmony_ci			wep_key->header.type =
4348c2ecf20Sopenharmony_ci				cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
4358c2ecf20Sopenharmony_ci			wep_key->header.len =
4368c2ecf20Sopenharmony_ci				cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
4378c2ecf20Sopenharmony_ci			wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
4388c2ecf20Sopenharmony_ci			wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
4398c2ecf20Sopenharmony_ci			memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
4408c2ecf20Sopenharmony_ci			       bss_cfg->wep_cfg[i].length);
4418c2ecf20Sopenharmony_ci			cmd_size += sizeof(struct mwifiex_ie_types_header) + 2 +
4428c2ecf20Sopenharmony_ci				    bss_cfg->wep_cfg[i].length;
4438c2ecf20Sopenharmony_ci			tlv += sizeof(struct mwifiex_ie_types_header) + 2 +
4448c2ecf20Sopenharmony_ci				    bss_cfg->wep_cfg[i].length;
4458c2ecf20Sopenharmony_ci		}
4468c2ecf20Sopenharmony_ci	}
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	*param_size = cmd_size;
4498c2ecf20Sopenharmony_ci	*tlv_buf = tlv;
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci	return;
4528c2ecf20Sopenharmony_ci}
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci/* This function enable 11D if userspace set the country IE.
4558c2ecf20Sopenharmony_ci */
4568c2ecf20Sopenharmony_civoid mwifiex_config_uap_11d(struct mwifiex_private *priv,
4578c2ecf20Sopenharmony_ci			    struct cfg80211_beacon_data *beacon_data)
4588c2ecf20Sopenharmony_ci{
4598c2ecf20Sopenharmony_ci	enum state_11d_t state_11d;
4608c2ecf20Sopenharmony_ci	const u8 *country_ie;
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	country_ie = cfg80211_find_ie(WLAN_EID_COUNTRY, beacon_data->tail,
4638c2ecf20Sopenharmony_ci				      beacon_data->tail_len);
4648c2ecf20Sopenharmony_ci	if (country_ie) {
4658c2ecf20Sopenharmony_ci		/* Send cmd to FW to enable 11D function */
4668c2ecf20Sopenharmony_ci		state_11d = ENABLE_11D;
4678c2ecf20Sopenharmony_ci		if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
4688c2ecf20Sopenharmony_ci				     HostCmd_ACT_GEN_SET, DOT11D_I,
4698c2ecf20Sopenharmony_ci				     &state_11d, true)) {
4708c2ecf20Sopenharmony_ci			mwifiex_dbg(priv->adapter, ERROR,
4718c2ecf20Sopenharmony_ci				    "11D: failed to enable 11D\n");
4728c2ecf20Sopenharmony_ci		}
4738c2ecf20Sopenharmony_ci	}
4748c2ecf20Sopenharmony_ci}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci/* This function parses BSS related parameters from structure
4778c2ecf20Sopenharmony_ci * and prepares TLVs. These TLVs are appended to command buffer.
4788c2ecf20Sopenharmony_ci*/
4798c2ecf20Sopenharmony_cistatic int
4808c2ecf20Sopenharmony_cimwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
4818c2ecf20Sopenharmony_ci{
4828c2ecf20Sopenharmony_ci	struct host_cmd_tlv_mac_addr *mac_tlv;
4838c2ecf20Sopenharmony_ci	struct host_cmd_tlv_dtim_period *dtim_period;
4848c2ecf20Sopenharmony_ci	struct host_cmd_tlv_beacon_period *beacon_period;
4858c2ecf20Sopenharmony_ci	struct host_cmd_tlv_ssid *ssid;
4868c2ecf20Sopenharmony_ci	struct host_cmd_tlv_bcast_ssid *bcast_ssid;
4878c2ecf20Sopenharmony_ci	struct host_cmd_tlv_channel_band *chan_band;
4888c2ecf20Sopenharmony_ci	struct host_cmd_tlv_frag_threshold *frag_threshold;
4898c2ecf20Sopenharmony_ci	struct host_cmd_tlv_rts_threshold *rts_threshold;
4908c2ecf20Sopenharmony_ci	struct host_cmd_tlv_retry_limit *retry_limit;
4918c2ecf20Sopenharmony_ci	struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
4928c2ecf20Sopenharmony_ci	struct host_cmd_tlv_auth_type *auth_type;
4938c2ecf20Sopenharmony_ci	struct host_cmd_tlv_rates *tlv_rates;
4948c2ecf20Sopenharmony_ci	struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
4958c2ecf20Sopenharmony_ci	struct host_cmd_tlv_power_constraint *pwr_ct;
4968c2ecf20Sopenharmony_ci	struct mwifiex_ie_types_htcap *htcap;
4978c2ecf20Sopenharmony_ci	struct mwifiex_ie_types_wmmcap *wmm_cap;
4988c2ecf20Sopenharmony_ci	struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
4998c2ecf20Sopenharmony_ci	int i;
5008c2ecf20Sopenharmony_ci	u16 cmd_size = *param_size;
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci	mac_tlv = (struct host_cmd_tlv_mac_addr *)tlv;
5038c2ecf20Sopenharmony_ci	mac_tlv->header.type = cpu_to_le16(TLV_TYPE_UAP_MAC_ADDRESS);
5048c2ecf20Sopenharmony_ci	mac_tlv->header.len = cpu_to_le16(ETH_ALEN);
5058c2ecf20Sopenharmony_ci	memcpy(mac_tlv->mac_addr, bss_cfg->mac_addr, ETH_ALEN);
5068c2ecf20Sopenharmony_ci	cmd_size += sizeof(struct host_cmd_tlv_mac_addr);
5078c2ecf20Sopenharmony_ci	tlv += sizeof(struct host_cmd_tlv_mac_addr);
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	if (bss_cfg->ssid.ssid_len) {
5108c2ecf20Sopenharmony_ci		ssid = (struct host_cmd_tlv_ssid *)tlv;
5118c2ecf20Sopenharmony_ci		ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
5128c2ecf20Sopenharmony_ci		ssid->header.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
5138c2ecf20Sopenharmony_ci		memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
5148c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct mwifiex_ie_types_header) +
5158c2ecf20Sopenharmony_ci			    bss_cfg->ssid.ssid_len;
5168c2ecf20Sopenharmony_ci		tlv += sizeof(struct mwifiex_ie_types_header) +
5178c2ecf20Sopenharmony_ci				bss_cfg->ssid.ssid_len;
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci		bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
5208c2ecf20Sopenharmony_ci		bcast_ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
5218c2ecf20Sopenharmony_ci		bcast_ssid->header.len =
5228c2ecf20Sopenharmony_ci				cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
5238c2ecf20Sopenharmony_ci		bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
5248c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
5258c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
5268c2ecf20Sopenharmony_ci	}
5278c2ecf20Sopenharmony_ci	if (bss_cfg->rates[0]) {
5288c2ecf20Sopenharmony_ci		tlv_rates = (struct host_cmd_tlv_rates *)tlv;
5298c2ecf20Sopenharmony_ci		tlv_rates->header.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci		for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
5328c2ecf20Sopenharmony_ci		     i++)
5338c2ecf20Sopenharmony_ci			tlv_rates->rates[i] = bss_cfg->rates[i];
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci		tlv_rates->header.len = cpu_to_le16(i);
5368c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
5378c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_rates) + i;
5388c2ecf20Sopenharmony_ci	}
5398c2ecf20Sopenharmony_ci	if (bss_cfg->channel &&
5408c2ecf20Sopenharmony_ci	    (((bss_cfg->band_cfg & BIT(0)) == BAND_CONFIG_BG &&
5418c2ecf20Sopenharmony_ci	      bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
5428c2ecf20Sopenharmony_ci	    ((bss_cfg->band_cfg & BIT(0)) == BAND_CONFIG_A &&
5438c2ecf20Sopenharmony_ci	     bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
5448c2ecf20Sopenharmony_ci		chan_band = (struct host_cmd_tlv_channel_band *)tlv;
5458c2ecf20Sopenharmony_ci		chan_band->header.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
5468c2ecf20Sopenharmony_ci		chan_band->header.len =
5478c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
5488c2ecf20Sopenharmony_ci				    sizeof(struct mwifiex_ie_types_header));
5498c2ecf20Sopenharmony_ci		chan_band->band_config = bss_cfg->band_cfg;
5508c2ecf20Sopenharmony_ci		chan_band->channel = bss_cfg->channel;
5518c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_channel_band);
5528c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_channel_band);
5538c2ecf20Sopenharmony_ci	}
5548c2ecf20Sopenharmony_ci	if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
5558c2ecf20Sopenharmony_ci	    bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
5568c2ecf20Sopenharmony_ci		beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
5578c2ecf20Sopenharmony_ci		beacon_period->header.type =
5588c2ecf20Sopenharmony_ci					cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
5598c2ecf20Sopenharmony_ci		beacon_period->header.len =
5608c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
5618c2ecf20Sopenharmony_ci				    sizeof(struct mwifiex_ie_types_header));
5628c2ecf20Sopenharmony_ci		beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
5638c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
5648c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_beacon_period);
5658c2ecf20Sopenharmony_ci	}
5668c2ecf20Sopenharmony_ci	if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
5678c2ecf20Sopenharmony_ci	    bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
5688c2ecf20Sopenharmony_ci		dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
5698c2ecf20Sopenharmony_ci		dtim_period->header.type =
5708c2ecf20Sopenharmony_ci			cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
5718c2ecf20Sopenharmony_ci		dtim_period->header.len =
5728c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
5738c2ecf20Sopenharmony_ci				    sizeof(struct mwifiex_ie_types_header));
5748c2ecf20Sopenharmony_ci		dtim_period->period = bss_cfg->dtim_period;
5758c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
5768c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_dtim_period);
5778c2ecf20Sopenharmony_ci	}
5788c2ecf20Sopenharmony_ci	if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
5798c2ecf20Sopenharmony_ci		rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
5808c2ecf20Sopenharmony_ci		rts_threshold->header.type =
5818c2ecf20Sopenharmony_ci					cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
5828c2ecf20Sopenharmony_ci		rts_threshold->header.len =
5838c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
5848c2ecf20Sopenharmony_ci				    sizeof(struct mwifiex_ie_types_header));
5858c2ecf20Sopenharmony_ci		rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
5868c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
5878c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_frag_threshold);
5888c2ecf20Sopenharmony_ci	}
5898c2ecf20Sopenharmony_ci	if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
5908c2ecf20Sopenharmony_ci	    (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
5918c2ecf20Sopenharmony_ci		frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
5928c2ecf20Sopenharmony_ci		frag_threshold->header.type =
5938c2ecf20Sopenharmony_ci				cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
5948c2ecf20Sopenharmony_ci		frag_threshold->header.len =
5958c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
5968c2ecf20Sopenharmony_ci				    sizeof(struct mwifiex_ie_types_header));
5978c2ecf20Sopenharmony_ci		frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
5988c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
5998c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_frag_threshold);
6008c2ecf20Sopenharmony_ci	}
6018c2ecf20Sopenharmony_ci	if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
6028c2ecf20Sopenharmony_ci		retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
6038c2ecf20Sopenharmony_ci		retry_limit->header.type =
6048c2ecf20Sopenharmony_ci			cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
6058c2ecf20Sopenharmony_ci		retry_limit->header.len =
6068c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
6078c2ecf20Sopenharmony_ci				    sizeof(struct mwifiex_ie_types_header));
6088c2ecf20Sopenharmony_ci		retry_limit->limit = (u8)bss_cfg->retry_limit;
6098c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
6108c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_retry_limit);
6118c2ecf20Sopenharmony_ci	}
6128c2ecf20Sopenharmony_ci	if ((bss_cfg->protocol & PROTOCOL_WPA) ||
6138c2ecf20Sopenharmony_ci	    (bss_cfg->protocol & PROTOCOL_WPA2) ||
6148c2ecf20Sopenharmony_ci	    (bss_cfg->protocol & PROTOCOL_EAP))
6158c2ecf20Sopenharmony_ci		mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
6168c2ecf20Sopenharmony_ci	else
6178c2ecf20Sopenharmony_ci		mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci	if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
6208c2ecf20Sopenharmony_ci	    (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
6218c2ecf20Sopenharmony_ci		auth_type = (struct host_cmd_tlv_auth_type *)tlv;
6228c2ecf20Sopenharmony_ci		auth_type->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
6238c2ecf20Sopenharmony_ci		auth_type->header.len =
6248c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
6258c2ecf20Sopenharmony_ci			sizeof(struct mwifiex_ie_types_header));
6268c2ecf20Sopenharmony_ci		auth_type->auth_type = (u8)bss_cfg->auth_mode;
6278c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_auth_type);
6288c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_auth_type);
6298c2ecf20Sopenharmony_ci	}
6308c2ecf20Sopenharmony_ci	if (bss_cfg->protocol) {
6318c2ecf20Sopenharmony_ci		encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
6328c2ecf20Sopenharmony_ci		encrypt_protocol->header.type =
6338c2ecf20Sopenharmony_ci			cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
6348c2ecf20Sopenharmony_ci		encrypt_protocol->header.len =
6358c2ecf20Sopenharmony_ci			cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
6368c2ecf20Sopenharmony_ci			- sizeof(struct mwifiex_ie_types_header));
6378c2ecf20Sopenharmony_ci		encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
6388c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
6398c2ecf20Sopenharmony_ci		tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
6408c2ecf20Sopenharmony_ci	}
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci	if (bss_cfg->ht_cap.cap_info) {
6438c2ecf20Sopenharmony_ci		htcap = (struct mwifiex_ie_types_htcap *)tlv;
6448c2ecf20Sopenharmony_ci		htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
6458c2ecf20Sopenharmony_ci		htcap->header.len =
6468c2ecf20Sopenharmony_ci				cpu_to_le16(sizeof(struct ieee80211_ht_cap));
6478c2ecf20Sopenharmony_ci		htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
6488c2ecf20Sopenharmony_ci		htcap->ht_cap.ampdu_params_info =
6498c2ecf20Sopenharmony_ci					     bss_cfg->ht_cap.ampdu_params_info;
6508c2ecf20Sopenharmony_ci		memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
6518c2ecf20Sopenharmony_ci		       sizeof(struct ieee80211_mcs_info));
6528c2ecf20Sopenharmony_ci		htcap->ht_cap.extended_ht_cap_info =
6538c2ecf20Sopenharmony_ci					bss_cfg->ht_cap.extended_ht_cap_info;
6548c2ecf20Sopenharmony_ci		htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
6558c2ecf20Sopenharmony_ci		htcap->ht_cap.antenna_selection_info =
6568c2ecf20Sopenharmony_ci					bss_cfg->ht_cap.antenna_selection_info;
6578c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct mwifiex_ie_types_htcap);
6588c2ecf20Sopenharmony_ci		tlv += sizeof(struct mwifiex_ie_types_htcap);
6598c2ecf20Sopenharmony_ci	}
6608c2ecf20Sopenharmony_ci
6618c2ecf20Sopenharmony_ci	if (bss_cfg->wmm_info.qos_info != 0xFF) {
6628c2ecf20Sopenharmony_ci		wmm_cap = (struct mwifiex_ie_types_wmmcap *)tlv;
6638c2ecf20Sopenharmony_ci		wmm_cap->header.type = cpu_to_le16(WLAN_EID_VENDOR_SPECIFIC);
6648c2ecf20Sopenharmony_ci		wmm_cap->header.len = cpu_to_le16(sizeof(wmm_cap->wmm_info));
6658c2ecf20Sopenharmony_ci		memcpy(&wmm_cap->wmm_info, &bss_cfg->wmm_info,
6668c2ecf20Sopenharmony_ci		       sizeof(wmm_cap->wmm_info));
6678c2ecf20Sopenharmony_ci		cmd_size += sizeof(struct mwifiex_ie_types_wmmcap);
6688c2ecf20Sopenharmony_ci		tlv += sizeof(struct mwifiex_ie_types_wmmcap);
6698c2ecf20Sopenharmony_ci	}
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ci	if (bss_cfg->sta_ao_timer) {
6728c2ecf20Sopenharmony_ci		ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
6738c2ecf20Sopenharmony_ci		ao_timer->header.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
6748c2ecf20Sopenharmony_ci		ao_timer->header.len = cpu_to_le16(sizeof(*ao_timer) -
6758c2ecf20Sopenharmony_ci					sizeof(struct mwifiex_ie_types_header));
6768c2ecf20Sopenharmony_ci		ao_timer->sta_ao_timer = cpu_to_le32(bss_cfg->sta_ao_timer);
6778c2ecf20Sopenharmony_ci		cmd_size += sizeof(*ao_timer);
6788c2ecf20Sopenharmony_ci		tlv += sizeof(*ao_timer);
6798c2ecf20Sopenharmony_ci	}
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci	if (bss_cfg->power_constraint) {
6828c2ecf20Sopenharmony_ci		pwr_ct = (void *)tlv;
6838c2ecf20Sopenharmony_ci		pwr_ct->header.type = cpu_to_le16(TLV_TYPE_PWR_CONSTRAINT);
6848c2ecf20Sopenharmony_ci		pwr_ct->header.len = cpu_to_le16(sizeof(u8));
6858c2ecf20Sopenharmony_ci		pwr_ct->constraint = bss_cfg->power_constraint;
6868c2ecf20Sopenharmony_ci		cmd_size += sizeof(*pwr_ct);
6878c2ecf20Sopenharmony_ci		tlv += sizeof(*pwr_ct);
6888c2ecf20Sopenharmony_ci	}
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci	if (bss_cfg->ps_sta_ao_timer) {
6918c2ecf20Sopenharmony_ci		ps_ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
6928c2ecf20Sopenharmony_ci		ps_ao_timer->header.type =
6938c2ecf20Sopenharmony_ci				cpu_to_le16(TLV_TYPE_UAP_PS_AO_TIMER);
6948c2ecf20Sopenharmony_ci		ps_ao_timer->header.len = cpu_to_le16(sizeof(*ps_ao_timer) -
6958c2ecf20Sopenharmony_ci				sizeof(struct mwifiex_ie_types_header));
6968c2ecf20Sopenharmony_ci		ps_ao_timer->sta_ao_timer =
6978c2ecf20Sopenharmony_ci					cpu_to_le32(bss_cfg->ps_sta_ao_timer);
6988c2ecf20Sopenharmony_ci		cmd_size += sizeof(*ps_ao_timer);
6998c2ecf20Sopenharmony_ci		tlv += sizeof(*ps_ao_timer);
7008c2ecf20Sopenharmony_ci	}
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci	*param_size = cmd_size;
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_ci	return 0;
7058c2ecf20Sopenharmony_ci}
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ci/* This function parses custom IEs from IE list and prepares command buffer */
7088c2ecf20Sopenharmony_cistatic int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
7098c2ecf20Sopenharmony_ci{
7108c2ecf20Sopenharmony_ci	struct mwifiex_ie_list *ap_ie = cmd_buf;
7118c2ecf20Sopenharmony_ci	struct mwifiex_ie_types_header *tlv_ie = (void *)tlv;
7128c2ecf20Sopenharmony_ci
7138c2ecf20Sopenharmony_ci	if (!ap_ie || !ap_ie->len)
7148c2ecf20Sopenharmony_ci		return -1;
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci	*ie_size += le16_to_cpu(ap_ie->len) +
7178c2ecf20Sopenharmony_ci			sizeof(struct mwifiex_ie_types_header);
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_ci	tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
7208c2ecf20Sopenharmony_ci	tlv_ie->len = ap_ie->len;
7218c2ecf20Sopenharmony_ci	tlv += sizeof(struct mwifiex_ie_types_header);
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci	memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci	return 0;
7268c2ecf20Sopenharmony_ci}
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ci/* Parse AP config structure and prepare TLV based command structure
7298c2ecf20Sopenharmony_ci * to be sent to FW for uAP configuration
7308c2ecf20Sopenharmony_ci */
7318c2ecf20Sopenharmony_cistatic int
7328c2ecf20Sopenharmony_cimwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
7338c2ecf20Sopenharmony_ci			   u32 type, void *cmd_buf)
7348c2ecf20Sopenharmony_ci{
7358c2ecf20Sopenharmony_ci	u8 *tlv;
7368c2ecf20Sopenharmony_ci	u16 cmd_size, param_size, ie_size;
7378c2ecf20Sopenharmony_ci	struct host_cmd_ds_sys_config *sys_cfg;
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci	cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
7408c2ecf20Sopenharmony_ci	cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
7418c2ecf20Sopenharmony_ci	sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
7428c2ecf20Sopenharmony_ci	sys_cfg->action = cpu_to_le16(cmd_action);
7438c2ecf20Sopenharmony_ci	tlv = sys_cfg->tlv;
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_ci	switch (type) {
7468c2ecf20Sopenharmony_ci	case UAP_BSS_PARAMS_I:
7478c2ecf20Sopenharmony_ci		param_size = cmd_size;
7488c2ecf20Sopenharmony_ci		if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
7498c2ecf20Sopenharmony_ci			return -1;
7508c2ecf20Sopenharmony_ci		cmd->size = cpu_to_le16(param_size);
7518c2ecf20Sopenharmony_ci		break;
7528c2ecf20Sopenharmony_ci	case UAP_CUSTOM_IE_I:
7538c2ecf20Sopenharmony_ci		ie_size = cmd_size;
7548c2ecf20Sopenharmony_ci		if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
7558c2ecf20Sopenharmony_ci			return -1;
7568c2ecf20Sopenharmony_ci		cmd->size = cpu_to_le16(ie_size);
7578c2ecf20Sopenharmony_ci		break;
7588c2ecf20Sopenharmony_ci	default:
7598c2ecf20Sopenharmony_ci		return -1;
7608c2ecf20Sopenharmony_ci	}
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci	return 0;
7638c2ecf20Sopenharmony_ci}
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_ci/* This function prepares AP specific deauth command with mac supplied in
7668c2ecf20Sopenharmony_ci * function parameter.
7678c2ecf20Sopenharmony_ci */
7688c2ecf20Sopenharmony_cistatic int mwifiex_cmd_uap_sta_deauth(struct mwifiex_private *priv,
7698c2ecf20Sopenharmony_ci				      struct host_cmd_ds_command *cmd, u8 *mac)
7708c2ecf20Sopenharmony_ci{
7718c2ecf20Sopenharmony_ci	struct host_cmd_ds_sta_deauth *sta_deauth = &cmd->params.sta_deauth;
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ci	cmd->command = cpu_to_le16(HostCmd_CMD_UAP_STA_DEAUTH);
7748c2ecf20Sopenharmony_ci	memcpy(sta_deauth->mac, mac, ETH_ALEN);
7758c2ecf20Sopenharmony_ci	sta_deauth->reason = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_sta_deauth) +
7788c2ecf20Sopenharmony_ci				S_DS_GEN);
7798c2ecf20Sopenharmony_ci	return 0;
7808c2ecf20Sopenharmony_ci}
7818c2ecf20Sopenharmony_ci
7828c2ecf20Sopenharmony_ci/* This function prepares the AP specific commands before sending them
7838c2ecf20Sopenharmony_ci * to the firmware.
7848c2ecf20Sopenharmony_ci * This is a generic function which calls specific command preparation
7858c2ecf20Sopenharmony_ci * routines based upon the command number.
7868c2ecf20Sopenharmony_ci */
7878c2ecf20Sopenharmony_ciint mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
7888c2ecf20Sopenharmony_ci			    u16 cmd_action, u32 type,
7898c2ecf20Sopenharmony_ci			    void *data_buf, void *cmd_buf)
7908c2ecf20Sopenharmony_ci{
7918c2ecf20Sopenharmony_ci	struct host_cmd_ds_command *cmd = cmd_buf;
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_ci	switch (cmd_no) {
7948c2ecf20Sopenharmony_ci	case HostCmd_CMD_UAP_SYS_CONFIG:
7958c2ecf20Sopenharmony_ci		if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
7968c2ecf20Sopenharmony_ci			return -1;
7978c2ecf20Sopenharmony_ci		break;
7988c2ecf20Sopenharmony_ci	case HostCmd_CMD_UAP_BSS_START:
7998c2ecf20Sopenharmony_ci	case HostCmd_CMD_UAP_BSS_STOP:
8008c2ecf20Sopenharmony_ci	case HOST_CMD_APCMD_SYS_RESET:
8018c2ecf20Sopenharmony_ci	case HOST_CMD_APCMD_STA_LIST:
8028c2ecf20Sopenharmony_ci		cmd->command = cpu_to_le16(cmd_no);
8038c2ecf20Sopenharmony_ci		cmd->size = cpu_to_le16(S_DS_GEN);
8048c2ecf20Sopenharmony_ci		break;
8058c2ecf20Sopenharmony_ci	case HostCmd_CMD_UAP_STA_DEAUTH:
8068c2ecf20Sopenharmony_ci		if (mwifiex_cmd_uap_sta_deauth(priv, cmd, data_buf))
8078c2ecf20Sopenharmony_ci			return -1;
8088c2ecf20Sopenharmony_ci		break;
8098c2ecf20Sopenharmony_ci	case HostCmd_CMD_CHAN_REPORT_REQUEST:
8108c2ecf20Sopenharmony_ci		if (mwifiex_cmd_issue_chan_report_request(priv, cmd_buf,
8118c2ecf20Sopenharmony_ci							  data_buf))
8128c2ecf20Sopenharmony_ci			return -1;
8138c2ecf20Sopenharmony_ci		break;
8148c2ecf20Sopenharmony_ci	default:
8158c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
8168c2ecf20Sopenharmony_ci			    "PREP_CMD: unknown cmd %#x\n", cmd_no);
8178c2ecf20Sopenharmony_ci		return -1;
8188c2ecf20Sopenharmony_ci	}
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_ci	return 0;
8218c2ecf20Sopenharmony_ci}
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_civoid mwifiex_uap_set_channel(struct mwifiex_private *priv,
8248c2ecf20Sopenharmony_ci			     struct mwifiex_uap_bss_param *bss_cfg,
8258c2ecf20Sopenharmony_ci			     struct cfg80211_chan_def chandef)
8268c2ecf20Sopenharmony_ci{
8278c2ecf20Sopenharmony_ci	u8 config_bands = 0, old_bands = priv->adapter->config_bands;
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_ci	priv->bss_chandef = chandef;
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_ci	bss_cfg->channel = ieee80211_frequency_to_channel(
8328c2ecf20Sopenharmony_ci						     chandef.chan->center_freq);
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_ci	/* Set appropriate bands */
8358c2ecf20Sopenharmony_ci	if (chandef.chan->band == NL80211_BAND_2GHZ) {
8368c2ecf20Sopenharmony_ci		bss_cfg->band_cfg = BAND_CONFIG_BG;
8378c2ecf20Sopenharmony_ci		config_bands = BAND_B | BAND_G;
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci		if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
8408c2ecf20Sopenharmony_ci			config_bands |= BAND_GN;
8418c2ecf20Sopenharmony_ci	} else {
8428c2ecf20Sopenharmony_ci		bss_cfg->band_cfg = BAND_CONFIG_A;
8438c2ecf20Sopenharmony_ci		config_bands = BAND_A;
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci		if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
8468c2ecf20Sopenharmony_ci			config_bands |= BAND_AN;
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ci		if (chandef.width > NL80211_CHAN_WIDTH_40)
8498c2ecf20Sopenharmony_ci			config_bands |= BAND_AAC;
8508c2ecf20Sopenharmony_ci	}
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci	switch (chandef.width) {
8538c2ecf20Sopenharmony_ci	case NL80211_CHAN_WIDTH_5:
8548c2ecf20Sopenharmony_ci	case NL80211_CHAN_WIDTH_10:
8558c2ecf20Sopenharmony_ci	case NL80211_CHAN_WIDTH_20_NOHT:
8568c2ecf20Sopenharmony_ci	case NL80211_CHAN_WIDTH_20:
8578c2ecf20Sopenharmony_ci		break;
8588c2ecf20Sopenharmony_ci	case NL80211_CHAN_WIDTH_40:
8598c2ecf20Sopenharmony_ci		if (chandef.center_freq1 < chandef.chan->center_freq)
8608c2ecf20Sopenharmony_ci			bss_cfg->band_cfg |= MWIFIEX_SEC_CHAN_BELOW;
8618c2ecf20Sopenharmony_ci		else
8628c2ecf20Sopenharmony_ci			bss_cfg->band_cfg |= MWIFIEX_SEC_CHAN_ABOVE;
8638c2ecf20Sopenharmony_ci		break;
8648c2ecf20Sopenharmony_ci	case NL80211_CHAN_WIDTH_80:
8658c2ecf20Sopenharmony_ci	case NL80211_CHAN_WIDTH_80P80:
8668c2ecf20Sopenharmony_ci	case NL80211_CHAN_WIDTH_160:
8678c2ecf20Sopenharmony_ci		bss_cfg->band_cfg |=
8688c2ecf20Sopenharmony_ci		    mwifiex_get_sec_chan_offset(bss_cfg->channel) << 4;
8698c2ecf20Sopenharmony_ci		break;
8708c2ecf20Sopenharmony_ci	default:
8718c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter,
8728c2ecf20Sopenharmony_ci			    WARN, "Unknown channel width: %d\n",
8738c2ecf20Sopenharmony_ci			    chandef.width);
8748c2ecf20Sopenharmony_ci		break;
8758c2ecf20Sopenharmony_ci	}
8768c2ecf20Sopenharmony_ci
8778c2ecf20Sopenharmony_ci	priv->adapter->config_bands = config_bands;
8788c2ecf20Sopenharmony_ci
8798c2ecf20Sopenharmony_ci	if (old_bands != config_bands) {
8808c2ecf20Sopenharmony_ci		mwifiex_send_domain_info_cmd_fw(priv->adapter->wiphy);
8818c2ecf20Sopenharmony_ci		mwifiex_dnld_txpwr_table(priv);
8828c2ecf20Sopenharmony_ci	}
8838c2ecf20Sopenharmony_ci}
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_ciint mwifiex_config_start_uap(struct mwifiex_private *priv,
8868c2ecf20Sopenharmony_ci			     struct mwifiex_uap_bss_param *bss_cfg)
8878c2ecf20Sopenharmony_ci{
8888c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
8898c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET,
8908c2ecf20Sopenharmony_ci			     UAP_BSS_PARAMS_I, bss_cfg, true)) {
8918c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
8928c2ecf20Sopenharmony_ci			    "Failed to set AP configuration\n");
8938c2ecf20Sopenharmony_ci		return -1;
8948c2ecf20Sopenharmony_ci	}
8958c2ecf20Sopenharmony_ci
8968c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_START,
8978c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0, NULL, true)) {
8988c2ecf20Sopenharmony_ci		mwifiex_dbg(priv->adapter, ERROR,
8998c2ecf20Sopenharmony_ci			    "Failed to start the BSS\n");
9008c2ecf20Sopenharmony_ci		return -1;
9018c2ecf20Sopenharmony_ci	}
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci	if (priv->sec_info.wep_enabled)
9048c2ecf20Sopenharmony_ci		priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
9058c2ecf20Sopenharmony_ci	else
9068c2ecf20Sopenharmony_ci		priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
9078c2ecf20Sopenharmony_ci
9088c2ecf20Sopenharmony_ci	if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
9098c2ecf20Sopenharmony_ci			     HostCmd_ACT_GEN_SET, 0,
9108c2ecf20Sopenharmony_ci			     &priv->curr_pkt_filter, true))
9118c2ecf20Sopenharmony_ci		return -1;
9128c2ecf20Sopenharmony_ci
9138c2ecf20Sopenharmony_ci	return 0;
9148c2ecf20Sopenharmony_ci}
915