Linux Audio

Check our new training course

Loading...
Note: File does not exist in v6.8.
  1/*
  2 * Marvell Wireless LAN device driver: AP specific command handling
  3 *
  4 * Copyright (C) 2012, Marvell International Ltd.
  5 *
  6 * This software file (the "File") is distributed by Marvell International
  7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8 * (the "License").  You may use, redistribute and/or modify this File in
  9 * accordance with the terms and conditions of the License, a copy of which
 10 * is available by writing to the Free Software Foundation, Inc.,
 11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
 12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
 13 *
 14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
 16 * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
 17 * this warranty disclaimer.
 18 */
 19
 20#include "main.h"
 21#include "11ac.h"
 22
 23/* This function parses security related parameters from cfg80211_ap_settings
 24 * and sets into FW understandable bss_config structure.
 25 */
 26int mwifiex_set_secure_params(struct mwifiex_private *priv,
 27			      struct mwifiex_uap_bss_param *bss_config,
 28			      struct cfg80211_ap_settings *params) {
 29	int i;
 30	struct mwifiex_wep_key wep_key;
 31
 32	if (!params->privacy) {
 33		bss_config->protocol = PROTOCOL_NO_SECURITY;
 34		bss_config->key_mgmt = KEY_MGMT_NONE;
 35		bss_config->wpa_cfg.length = 0;
 36		priv->sec_info.wep_enabled = 0;
 37		priv->sec_info.wpa_enabled = 0;
 38		priv->sec_info.wpa2_enabled = 0;
 39
 40		return 0;
 41	}
 42
 43	switch (params->auth_type) {
 44	case NL80211_AUTHTYPE_OPEN_SYSTEM:
 45		bss_config->auth_mode = WLAN_AUTH_OPEN;
 46		break;
 47	case NL80211_AUTHTYPE_SHARED_KEY:
 48		bss_config->auth_mode = WLAN_AUTH_SHARED_KEY;
 49		break;
 50	case NL80211_AUTHTYPE_NETWORK_EAP:
 51		bss_config->auth_mode = WLAN_AUTH_LEAP;
 52		break;
 53	default:
 54		bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO;
 55		break;
 56	}
 57
 58	bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
 59
 60	for (i = 0; i < params->crypto.n_akm_suites; i++) {
 61		switch (params->crypto.akm_suites[i]) {
 62		case WLAN_AKM_SUITE_8021X:
 63			if (params->crypto.wpa_versions &
 64			    NL80211_WPA_VERSION_1) {
 65				bss_config->protocol = PROTOCOL_WPA;
 66				bss_config->key_mgmt = KEY_MGMT_EAP;
 67			}
 68			if (params->crypto.wpa_versions &
 69			    NL80211_WPA_VERSION_2) {
 70				bss_config->protocol |= PROTOCOL_WPA2;
 71				bss_config->key_mgmt = KEY_MGMT_EAP;
 72			}
 73			break;
 74		case WLAN_AKM_SUITE_PSK:
 75			if (params->crypto.wpa_versions &
 76			    NL80211_WPA_VERSION_1) {
 77				bss_config->protocol = PROTOCOL_WPA;
 78				bss_config->key_mgmt = KEY_MGMT_PSK;
 79			}
 80			if (params->crypto.wpa_versions &
 81			    NL80211_WPA_VERSION_2) {
 82				bss_config->protocol |= PROTOCOL_WPA2;
 83				bss_config->key_mgmt = KEY_MGMT_PSK;
 84			}
 85			break;
 86		default:
 87			break;
 88		}
 89	}
 90	for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) {
 91		switch (params->crypto.ciphers_pairwise[i]) {
 92		case WLAN_CIPHER_SUITE_WEP40:
 93		case WLAN_CIPHER_SUITE_WEP104:
 94			break;
 95		case WLAN_CIPHER_SUITE_TKIP:
 96			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
 97				bss_config->wpa_cfg.pairwise_cipher_wpa |=
 98								CIPHER_TKIP;
 99			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
100				bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
101								CIPHER_TKIP;
102			break;
103		case WLAN_CIPHER_SUITE_CCMP:
104			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
105				bss_config->wpa_cfg.pairwise_cipher_wpa |=
106								CIPHER_AES_CCMP;
107			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
108				bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
109								CIPHER_AES_CCMP;
110		default:
111			break;
112		}
113	}
114
115	switch (params->crypto.cipher_group) {
116	case WLAN_CIPHER_SUITE_WEP40:
117	case WLAN_CIPHER_SUITE_WEP104:
118		if (priv->sec_info.wep_enabled) {
119			bss_config->protocol = PROTOCOL_STATIC_WEP;
120			bss_config->key_mgmt = KEY_MGMT_NONE;
121			bss_config->wpa_cfg.length = 0;
122
123			for (i = 0; i < NUM_WEP_KEYS; i++) {
124				wep_key = priv->wep_key[i];
125				bss_config->wep_cfg[i].key_index = i;
126
127				if (priv->wep_key_curr_index == i)
128					bss_config->wep_cfg[i].is_default = 1;
129				else
130					bss_config->wep_cfg[i].is_default = 0;
131
132				bss_config->wep_cfg[i].length =
133							     wep_key.key_length;
134				memcpy(&bss_config->wep_cfg[i].key,
135				       &wep_key.key_material,
136				       wep_key.key_length);
137			}
138		}
139		break;
140	case WLAN_CIPHER_SUITE_TKIP:
141		bss_config->wpa_cfg.group_cipher = CIPHER_TKIP;
142		break;
143	case WLAN_CIPHER_SUITE_CCMP:
144		bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP;
145		break;
146	default:
147		break;
148	}
149
150	return 0;
151}
152
153/* This function updates 11n related parameters from IE and sets them into
154 * bss_config structure.
155 */
156void
157mwifiex_set_ht_params(struct mwifiex_private *priv,
158		      struct mwifiex_uap_bss_param *bss_cfg,
159		      struct cfg80211_ap_settings *params)
160{
161	const u8 *ht_ie;
162	u16 cap_info;
163
164	if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
165		return;
166
167	ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
168				 params->beacon.tail_len);
169	if (ht_ie) {
170		memcpy(&bss_cfg->ht_cap, ht_ie + 2,
171		       sizeof(struct ieee80211_ht_cap));
172		cap_info = le16_to_cpu(bss_cfg->ht_cap.cap_info);
173		memset(&bss_cfg->ht_cap.mcs, 0,
174		       priv->adapter->number_of_antenna);
175		switch (GET_RXSTBC(cap_info)) {
176		case MWIFIEX_RX_STBC1:
177			/* HT_CAP 1X1 mode */
178			memset(&bss_cfg->ht_cap.mcs, 0xff, 1);
179			break;
180		case MWIFIEX_RX_STBC12:	/* fall through */
181		case MWIFIEX_RX_STBC123:
182			/* HT_CAP 2X2 mode */
183			memset(&bss_cfg->ht_cap.mcs, 0xff, 2);
184			break;
185		default:
186			dev_warn(priv->adapter->dev,
187				 "Unsupported RX-STBC, default to 2x2\n");
188			memset(&bss_cfg->ht_cap.mcs, 0xff, 2);
189			break;
190		}
191		priv->ap_11n_enabled = 1;
192	} else {
193		memset(&bss_cfg->ht_cap , 0, sizeof(struct ieee80211_ht_cap));
194		bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
195		bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
196	}
197
198	return;
199}
200
201/* This function updates 11ac related parameters from IE
202 * and sets them into bss_config structure.
203 */
204void mwifiex_set_vht_params(struct mwifiex_private *priv,
205			    struct mwifiex_uap_bss_param *bss_cfg,
206			    struct cfg80211_ap_settings *params)
207{
208	const u8 *vht_ie;
209
210	vht_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, params->beacon.tail,
211				  params->beacon.tail_len);
212	if (vht_ie) {
213		memcpy(&bss_cfg->vht_cap, vht_ie + 2,
214		       sizeof(struct ieee80211_vht_cap));
215		priv->ap_11ac_enabled = 1;
216	} else {
217		priv->ap_11ac_enabled = 0;
218	}
219
220	return;
221}
222
223/* Enable VHT only when cfg80211_ap_settings has VHT IE.
224 * Otherwise disable VHT.
225 */
226void mwifiex_set_vht_width(struct mwifiex_private *priv,
227			   enum nl80211_chan_width width,
228			   bool ap_11ac_enable)
229{
230	struct mwifiex_adapter *adapter = priv->adapter;
231	struct mwifiex_11ac_vht_cfg vht_cfg;
232
233	vht_cfg.band_config = VHT_CFG_5GHZ;
234	vht_cfg.cap_info = adapter->hw_dot_11ac_dev_cap;
235
236	if (!ap_11ac_enable) {
237		vht_cfg.mcs_tx_set = DISABLE_VHT_MCS_SET;
238		vht_cfg.mcs_rx_set = DISABLE_VHT_MCS_SET;
239	} else {
240		vht_cfg.mcs_tx_set = DEFAULT_VHT_MCS_SET;
241		vht_cfg.mcs_rx_set = DEFAULT_VHT_MCS_SET;
242	}
243
244	vht_cfg.misc_config  = VHT_CAP_UAP_ONLY;
245
246	if (ap_11ac_enable && width >= NL80211_CHAN_WIDTH_80)
247		vht_cfg.misc_config |= VHT_BW_80_160_80P80;
248
249	mwifiex_send_cmd(priv, HostCmd_CMD_11AC_CFG,
250			 HostCmd_ACT_GEN_SET, 0, &vht_cfg, true);
251
252	return;
253}
254
255/* This function finds supported rates IE from beacon parameter and sets
256 * these rates into bss_config structure.
257 */
258void
259mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
260		      struct cfg80211_ap_settings *params)
261{
262	struct ieee_types_header *rate_ie;
263	int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
264	const u8 *var_pos = params->beacon.head + var_offset;
265	int len = params->beacon.head_len - var_offset;
266	u8 rate_len = 0;
267
268	rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
269	if (rate_ie) {
270		memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
271		rate_len = rate_ie->len;
272	}
273
274	rate_ie = (void *)cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
275					   params->beacon.tail,
276					   params->beacon.tail_len);
277	if (rate_ie)
278		memcpy(bss_cfg->rates + rate_len, rate_ie + 1, rate_ie->len);
279
280	return;
281}
282
283/* This function initializes some of mwifiex_uap_bss_param variables.
284 * This helps FW in ignoring invalid values. These values may or may not
285 * be get updated to valid ones at later stage.
286 */
287void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
288{
289	config->bcast_ssid_ctl = 0x7F;
290	config->radio_ctl = 0x7F;
291	config->dtim_period = 0x7F;
292	config->beacon_period = 0x7FFF;
293	config->auth_mode = 0x7F;
294	config->rts_threshold = 0x7FFF;
295	config->frag_threshold = 0x7FFF;
296	config->retry_limit = 0x7F;
297	config->qos_info = 0xFF;
298}
299
300/* This function parses BSS related parameters from structure
301 * and prepares TLVs specific to WPA/WPA2 security.
302 * These TLVs are appended to command buffer.
303 */
304static void
305mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
306{
307	struct host_cmd_tlv_pwk_cipher *pwk_cipher;
308	struct host_cmd_tlv_gwk_cipher *gwk_cipher;
309	struct host_cmd_tlv_passphrase *passphrase;
310	struct host_cmd_tlv_akmp *tlv_akmp;
311	struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
312	u16 cmd_size = *param_size;
313	u8 *tlv = *tlv_buf;
314
315	tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
316	tlv_akmp->header.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
317	tlv_akmp->header.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
318					sizeof(struct mwifiex_ie_types_header));
319	tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
320	tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
321	cmd_size += sizeof(struct host_cmd_tlv_akmp);
322	tlv += sizeof(struct host_cmd_tlv_akmp);
323
324	if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
325		pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
326		pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
327		pwk_cipher->header.len =
328			cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
329				    sizeof(struct mwifiex_ie_types_header));
330		pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
331		pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
332		cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
333		tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
334	}
335
336	if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
337		pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
338		pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
339		pwk_cipher->header.len =
340			cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
341				    sizeof(struct mwifiex_ie_types_header));
342		pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
343		pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
344		cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
345		tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
346	}
347
348	if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
349		gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
350		gwk_cipher->header.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
351		gwk_cipher->header.len =
352			cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
353				    sizeof(struct mwifiex_ie_types_header));
354		gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
355		cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
356		tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
357	}
358
359	if (bss_cfg->wpa_cfg.length) {
360		passphrase = (struct host_cmd_tlv_passphrase *)tlv;
361		passphrase->header.type =
362				cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
363		passphrase->header.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
364		memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
365		       bss_cfg->wpa_cfg.length);
366		cmd_size += sizeof(struct mwifiex_ie_types_header) +
367			    bss_cfg->wpa_cfg.length;
368		tlv += sizeof(struct mwifiex_ie_types_header) +
369				bss_cfg->wpa_cfg.length;
370	}
371
372	*param_size = cmd_size;
373	*tlv_buf = tlv;
374
375	return;
376}
377
378/* This function parses WMM related parameters from cfg80211_ap_settings
379 * structure and updates bss_config structure.
380 */
381void
382mwifiex_set_wmm_params(struct mwifiex_private *priv,
383		       struct mwifiex_uap_bss_param *bss_cfg,
384		       struct cfg80211_ap_settings *params)
385{
386	const u8 *vendor_ie;
387	struct ieee_types_header *wmm_ie;
388	u8 wmm_oui[] = {0x00, 0x50, 0xf2, 0x02};
389
390	vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
391					    WLAN_OUI_TYPE_MICROSOFT_WMM,
392					    params->beacon.tail,
393					    params->beacon.tail_len);
394	if (vendor_ie) {
395		wmm_ie = (struct ieee_types_header *)vendor_ie;
396		memcpy(&bss_cfg->wmm_info, wmm_ie + 1,
397		       sizeof(bss_cfg->wmm_info));
398		priv->wmm_enabled = 1;
399	} else {
400		memset(&bss_cfg->wmm_info, 0, sizeof(bss_cfg->wmm_info));
401		memcpy(&bss_cfg->wmm_info.oui, wmm_oui, sizeof(wmm_oui));
402		bss_cfg->wmm_info.subtype = MWIFIEX_WMM_SUBTYPE;
403		bss_cfg->wmm_info.version = MWIFIEX_WMM_VERSION;
404		priv->wmm_enabled = 0;
405	}
406
407	bss_cfg->qos_info = 0x00;
408	return;
409}
410/* This function parses BSS related parameters from structure
411 * and prepares TLVs specific to WEP encryption.
412 * These TLVs are appended to command buffer.
413 */
414static void
415mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
416{
417	struct host_cmd_tlv_wep_key *wep_key;
418	u16 cmd_size = *param_size;
419	int i;
420	u8 *tlv = *tlv_buf;
421	struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
422
423	for (i = 0; i < NUM_WEP_KEYS; i++) {
424		if (bss_cfg->wep_cfg[i].length &&
425		    (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
426		     bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
427			wep_key = (struct host_cmd_tlv_wep_key *)tlv;
428			wep_key->header.type =
429				cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
430			wep_key->header.len =
431				cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
432			wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
433			wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
434			memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
435			       bss_cfg->wep_cfg[i].length);
436			cmd_size += sizeof(struct mwifiex_ie_types_header) + 2 +
437				    bss_cfg->wep_cfg[i].length;
438			tlv += sizeof(struct mwifiex_ie_types_header) + 2 +
439				    bss_cfg->wep_cfg[i].length;
440		}
441	}
442
443	*param_size = cmd_size;
444	*tlv_buf = tlv;
445
446	return;
447}
448
449/* This function parses BSS related parameters from structure
450 * and prepares TLVs. These TLVs are appended to command buffer.
451*/
452static int
453mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
454{
455	struct host_cmd_tlv_dtim_period *dtim_period;
456	struct host_cmd_tlv_beacon_period *beacon_period;
457	struct host_cmd_tlv_ssid *ssid;
458	struct host_cmd_tlv_bcast_ssid *bcast_ssid;
459	struct host_cmd_tlv_channel_band *chan_band;
460	struct host_cmd_tlv_frag_threshold *frag_threshold;
461	struct host_cmd_tlv_rts_threshold *rts_threshold;
462	struct host_cmd_tlv_retry_limit *retry_limit;
463	struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
464	struct host_cmd_tlv_auth_type *auth_type;
465	struct host_cmd_tlv_rates *tlv_rates;
466	struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
467	struct mwifiex_ie_types_htcap *htcap;
468	struct mwifiex_ie_types_wmmcap *wmm_cap;
469	struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
470	int i;
471	u16 cmd_size = *param_size;
472
473	if (bss_cfg->ssid.ssid_len) {
474		ssid = (struct host_cmd_tlv_ssid *)tlv;
475		ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
476		ssid->header.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
477		memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
478		cmd_size += sizeof(struct mwifiex_ie_types_header) +
479			    bss_cfg->ssid.ssid_len;
480		tlv += sizeof(struct mwifiex_ie_types_header) +
481				bss_cfg->ssid.ssid_len;
482
483		bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
484		bcast_ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
485		bcast_ssid->header.len =
486				cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
487		bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
488		cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
489		tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
490	}
491	if (bss_cfg->rates[0]) {
492		tlv_rates = (struct host_cmd_tlv_rates *)tlv;
493		tlv_rates->header.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
494
495		for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
496		     i++)
497			tlv_rates->rates[i] = bss_cfg->rates[i];
498
499		tlv_rates->header.len = cpu_to_le16(i);
500		cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
501		tlv += sizeof(struct host_cmd_tlv_rates) + i;
502	}
503	if (bss_cfg->channel &&
504	    ((bss_cfg->band_cfg == BAND_CONFIG_BG &&
505	      bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
506	    (bss_cfg->band_cfg == BAND_CONFIG_A &&
507	     bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
508		chan_band = (struct host_cmd_tlv_channel_band *)tlv;
509		chan_band->header.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
510		chan_band->header.len =
511			cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
512				    sizeof(struct mwifiex_ie_types_header));
513		chan_band->band_config = bss_cfg->band_cfg;
514		chan_band->channel = bss_cfg->channel;
515		cmd_size += sizeof(struct host_cmd_tlv_channel_band);
516		tlv += sizeof(struct host_cmd_tlv_channel_band);
517	}
518	if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
519	    bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
520		beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
521		beacon_period->header.type =
522					cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
523		beacon_period->header.len =
524			cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
525				    sizeof(struct mwifiex_ie_types_header));
526		beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
527		cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
528		tlv += sizeof(struct host_cmd_tlv_beacon_period);
529	}
530	if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
531	    bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
532		dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
533		dtim_period->header.type =
534			cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
535		dtim_period->header.len =
536			cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
537				    sizeof(struct mwifiex_ie_types_header));
538		dtim_period->period = bss_cfg->dtim_period;
539		cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
540		tlv += sizeof(struct host_cmd_tlv_dtim_period);
541	}
542	if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
543		rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
544		rts_threshold->header.type =
545					cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
546		rts_threshold->header.len =
547			cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
548				    sizeof(struct mwifiex_ie_types_header));
549		rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
550		cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
551		tlv += sizeof(struct host_cmd_tlv_frag_threshold);
552	}
553	if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
554	    (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
555		frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
556		frag_threshold->header.type =
557				cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
558		frag_threshold->header.len =
559			cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
560				    sizeof(struct mwifiex_ie_types_header));
561		frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
562		cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
563		tlv += sizeof(struct host_cmd_tlv_frag_threshold);
564	}
565	if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
566		retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
567		retry_limit->header.type =
568			cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
569		retry_limit->header.len =
570			cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
571				    sizeof(struct mwifiex_ie_types_header));
572		retry_limit->limit = (u8)bss_cfg->retry_limit;
573		cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
574		tlv += sizeof(struct host_cmd_tlv_retry_limit);
575	}
576	if ((bss_cfg->protocol & PROTOCOL_WPA) ||
577	    (bss_cfg->protocol & PROTOCOL_WPA2) ||
578	    (bss_cfg->protocol & PROTOCOL_EAP))
579		mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
580	else
581		mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
582
583	if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
584	    (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
585		auth_type = (struct host_cmd_tlv_auth_type *)tlv;
586		auth_type->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
587		auth_type->header.len =
588			cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
589			sizeof(struct mwifiex_ie_types_header));
590		auth_type->auth_type = (u8)bss_cfg->auth_mode;
591		cmd_size += sizeof(struct host_cmd_tlv_auth_type);
592		tlv += sizeof(struct host_cmd_tlv_auth_type);
593	}
594	if (bss_cfg->protocol) {
595		encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
596		encrypt_protocol->header.type =
597			cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
598		encrypt_protocol->header.len =
599			cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
600			- sizeof(struct mwifiex_ie_types_header));
601		encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
602		cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
603		tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
604	}
605
606	if (bss_cfg->ht_cap.cap_info) {
607		htcap = (struct mwifiex_ie_types_htcap *)tlv;
608		htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
609		htcap->header.len =
610				cpu_to_le16(sizeof(struct ieee80211_ht_cap));
611		htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
612		htcap->ht_cap.ampdu_params_info =
613					     bss_cfg->ht_cap.ampdu_params_info;
614		memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
615		       sizeof(struct ieee80211_mcs_info));
616		htcap->ht_cap.extended_ht_cap_info =
617					bss_cfg->ht_cap.extended_ht_cap_info;
618		htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
619		htcap->ht_cap.antenna_selection_info =
620					bss_cfg->ht_cap.antenna_selection_info;
621		cmd_size += sizeof(struct mwifiex_ie_types_htcap);
622		tlv += sizeof(struct mwifiex_ie_types_htcap);
623	}
624
625	if (bss_cfg->wmm_info.qos_info != 0xFF) {
626		wmm_cap = (struct mwifiex_ie_types_wmmcap *)tlv;
627		wmm_cap->header.type = cpu_to_le16(WLAN_EID_VENDOR_SPECIFIC);
628		wmm_cap->header.len = cpu_to_le16(sizeof(wmm_cap->wmm_info));
629		memcpy(&wmm_cap->wmm_info, &bss_cfg->wmm_info,
630		       sizeof(wmm_cap->wmm_info));
631		cmd_size += sizeof(struct mwifiex_ie_types_wmmcap);
632		tlv += sizeof(struct mwifiex_ie_types_wmmcap);
633	}
634
635	if (bss_cfg->sta_ao_timer) {
636		ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
637		ao_timer->header.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
638		ao_timer->header.len = cpu_to_le16(sizeof(*ao_timer) -
639					sizeof(struct mwifiex_ie_types_header));
640		ao_timer->sta_ao_timer = cpu_to_le32(bss_cfg->sta_ao_timer);
641		cmd_size += sizeof(*ao_timer);
642		tlv += sizeof(*ao_timer);
643	}
644
645	if (bss_cfg->ps_sta_ao_timer) {
646		ps_ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
647		ps_ao_timer->header.type =
648				cpu_to_le16(TLV_TYPE_UAP_PS_AO_TIMER);
649		ps_ao_timer->header.len = cpu_to_le16(sizeof(*ps_ao_timer) -
650				sizeof(struct mwifiex_ie_types_header));
651		ps_ao_timer->sta_ao_timer =
652					cpu_to_le32(bss_cfg->ps_sta_ao_timer);
653		cmd_size += sizeof(*ps_ao_timer);
654		tlv += sizeof(*ps_ao_timer);
655	}
656
657	*param_size = cmd_size;
658
659	return 0;
660}
661
662/* This function parses custom IEs from IE list and prepares command buffer */
663static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
664{
665	struct mwifiex_ie_list *ap_ie = cmd_buf;
666	struct mwifiex_ie_types_header *tlv_ie = (void *)tlv;
667
668	if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
669		return -1;
670
671	*ie_size += le16_to_cpu(ap_ie->len) +
672			sizeof(struct mwifiex_ie_types_header);
673
674	tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
675	tlv_ie->len = ap_ie->len;
676	tlv += sizeof(struct mwifiex_ie_types_header);
677
678	memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
679
680	return 0;
681}
682
683/* Parse AP config structure and prepare TLV based command structure
684 * to be sent to FW for uAP configuration
685 */
686static int
687mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
688			   u32 type, void *cmd_buf)
689{
690	u8 *tlv;
691	u16 cmd_size, param_size, ie_size;
692	struct host_cmd_ds_sys_config *sys_cfg;
693
694	cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
695	cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
696	sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
697	sys_cfg->action = cpu_to_le16(cmd_action);
698	tlv = sys_cfg->tlv;
699
700	switch (type) {
701	case UAP_BSS_PARAMS_I:
702		param_size = cmd_size;
703		if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
704			return -1;
705		cmd->size = cpu_to_le16(param_size);
706		break;
707	case UAP_CUSTOM_IE_I:
708		ie_size = cmd_size;
709		if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
710			return -1;
711		cmd->size = cpu_to_le16(ie_size);
712		break;
713	default:
714		return -1;
715	}
716
717	return 0;
718}
719
720/* This function prepares AP specific deauth command with mac supplied in
721 * function parameter.
722 */
723static int mwifiex_cmd_uap_sta_deauth(struct mwifiex_private *priv,
724				      struct host_cmd_ds_command *cmd, u8 *mac)
725{
726	struct host_cmd_ds_sta_deauth *sta_deauth = &cmd->params.sta_deauth;
727
728	cmd->command = cpu_to_le16(HostCmd_CMD_UAP_STA_DEAUTH);
729	memcpy(sta_deauth->mac, mac, ETH_ALEN);
730	sta_deauth->reason = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
731
732	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_sta_deauth) +
733				S_DS_GEN);
734	return 0;
735}
736
737/* This function prepares the AP specific commands before sending them
738 * to the firmware.
739 * This is a generic function which calls specific command preparation
740 * routines based upon the command number.
741 */
742int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
743			    u16 cmd_action, u32 type,
744			    void *data_buf, void *cmd_buf)
745{
746	struct host_cmd_ds_command *cmd = cmd_buf;
747
748	switch (cmd_no) {
749	case HostCmd_CMD_UAP_SYS_CONFIG:
750		if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
751			return -1;
752		break;
753	case HostCmd_CMD_UAP_BSS_START:
754	case HostCmd_CMD_UAP_BSS_STOP:
755		cmd->command = cpu_to_le16(cmd_no);
756		cmd->size = cpu_to_le16(S_DS_GEN);
757		break;
758	case HostCmd_CMD_UAP_STA_DEAUTH:
759		if (mwifiex_cmd_uap_sta_deauth(priv, cmd, data_buf))
760			return -1;
761		break;
762	default:
763		dev_err(priv->adapter->dev,
764			"PREP_CMD: unknown cmd %#x\n", cmd_no);
765		return -1;
766	}
767
768	return 0;
769}