• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * NXP Wireless LAN device driver: AP specific command handling
3  *
4  * Copyright 2011-2020 NXP
5  *
6  * This software file (the "File") is distributed by NXP
7  * 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 #include "11n.h"
23 
24 /* This function parses security related parameters from cfg80211_ap_settings
25  * and sets into FW understandable bss_config structure.
26  */
mwifiex_set_secure_params(struct mwifiex_private * priv,struct mwifiex_uap_bss_param * bss_config,struct cfg80211_ap_settings * params)27 int mwifiex_set_secure_params(struct mwifiex_private *priv,
28 			      struct mwifiex_uap_bss_param *bss_config,
29 			      struct cfg80211_ap_settings *params) {
30 	int i;
31 	struct mwifiex_wep_key wep_key;
32 
33 	if (!params->privacy) {
34 		bss_config->protocol = PROTOCOL_NO_SECURITY;
35 		bss_config->key_mgmt = KEY_MGMT_NONE;
36 		bss_config->wpa_cfg.length = 0;
37 		priv->sec_info.wep_enabled = 0;
38 		priv->sec_info.wpa_enabled = 0;
39 		priv->sec_info.wpa2_enabled = 0;
40 
41 		return 0;
42 	}
43 
44 	switch (params->auth_type) {
45 	case NL80211_AUTHTYPE_OPEN_SYSTEM:
46 		bss_config->auth_mode = WLAN_AUTH_OPEN;
47 		break;
48 	case NL80211_AUTHTYPE_SHARED_KEY:
49 		bss_config->auth_mode = WLAN_AUTH_SHARED_KEY;
50 		break;
51 	case NL80211_AUTHTYPE_NETWORK_EAP:
52 		bss_config->auth_mode = WLAN_AUTH_LEAP;
53 		break;
54 	default:
55 		bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO;
56 		break;
57 	}
58 
59 	bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
60 
61 	for (i = 0; i < params->crypto.n_akm_suites; i++) {
62 		switch (params->crypto.akm_suites[i]) {
63 		case WLAN_AKM_SUITE_8021X:
64 			if (params->crypto.wpa_versions &
65 			    NL80211_WPA_VERSION_1) {
66 				bss_config->protocol = PROTOCOL_WPA;
67 				bss_config->key_mgmt = KEY_MGMT_EAP;
68 			}
69 			if (params->crypto.wpa_versions &
70 			    NL80211_WPA_VERSION_2) {
71 				bss_config->protocol |= PROTOCOL_WPA2;
72 				bss_config->key_mgmt = KEY_MGMT_EAP;
73 			}
74 			break;
75 		case WLAN_AKM_SUITE_PSK:
76 			if (params->crypto.wpa_versions &
77 			    NL80211_WPA_VERSION_1) {
78 				bss_config->protocol = PROTOCOL_WPA;
79 				bss_config->key_mgmt = KEY_MGMT_PSK;
80 			}
81 			if (params->crypto.wpa_versions &
82 			    NL80211_WPA_VERSION_2) {
83 				bss_config->protocol |= PROTOCOL_WPA2;
84 				bss_config->key_mgmt = KEY_MGMT_PSK;
85 			}
86 			break;
87 		default:
88 			break;
89 		}
90 	}
91 	for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) {
92 		switch (params->crypto.ciphers_pairwise[i]) {
93 		case WLAN_CIPHER_SUITE_WEP40:
94 		case WLAN_CIPHER_SUITE_WEP104:
95 			break;
96 		case WLAN_CIPHER_SUITE_TKIP:
97 			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
98 				bss_config->wpa_cfg.pairwise_cipher_wpa |=
99 								CIPHER_TKIP;
100 			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
101 				bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
102 								CIPHER_TKIP;
103 			break;
104 		case WLAN_CIPHER_SUITE_CCMP:
105 			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
106 				bss_config->wpa_cfg.pairwise_cipher_wpa |=
107 								CIPHER_AES_CCMP;
108 			if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
109 				bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
110 								CIPHER_AES_CCMP;
111 			break;
112 		default:
113 			break;
114 		}
115 	}
116 
117 	switch (params->crypto.cipher_group) {
118 	case WLAN_CIPHER_SUITE_WEP40:
119 	case WLAN_CIPHER_SUITE_WEP104:
120 		if (priv->sec_info.wep_enabled) {
121 			bss_config->protocol = PROTOCOL_STATIC_WEP;
122 			bss_config->key_mgmt = KEY_MGMT_NONE;
123 			bss_config->wpa_cfg.length = 0;
124 
125 			for (i = 0; i < NUM_WEP_KEYS; i++) {
126 				wep_key = priv->wep_key[i];
127 				bss_config->wep_cfg[i].key_index = i;
128 
129 				if (priv->wep_key_curr_index == i)
130 					bss_config->wep_cfg[i].is_default = 1;
131 				else
132 					bss_config->wep_cfg[i].is_default = 0;
133 
134 				bss_config->wep_cfg[i].length =
135 							     wep_key.key_length;
136 				memcpy(&bss_config->wep_cfg[i].key,
137 				       &wep_key.key_material,
138 				       wep_key.key_length);
139 			}
140 		}
141 		break;
142 	case WLAN_CIPHER_SUITE_TKIP:
143 		bss_config->wpa_cfg.group_cipher = CIPHER_TKIP;
144 		break;
145 	case WLAN_CIPHER_SUITE_CCMP:
146 		bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP;
147 		break;
148 	default:
149 		break;
150 	}
151 
152 	return 0;
153 }
154 
155 /* This function updates 11n related parameters from IE and sets them into
156  * bss_config structure.
157  */
158 void
mwifiex_set_ht_params(struct mwifiex_private * priv,struct mwifiex_uap_bss_param * bss_cfg,struct cfg80211_ap_settings * params)159 mwifiex_set_ht_params(struct mwifiex_private *priv,
160 		      struct mwifiex_uap_bss_param *bss_cfg,
161 		      struct cfg80211_ap_settings *params)
162 {
163 	const u8 *ht_ie;
164 
165 	if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
166 		return;
167 
168 	ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
169 				 params->beacon.tail_len);
170 	if (ht_ie) {
171 		memcpy(&bss_cfg->ht_cap, ht_ie + 2,
172 		       sizeof(struct ieee80211_ht_cap));
173 		priv->ap_11n_enabled = 1;
174 	} else {
175 		memset(&bss_cfg->ht_cap, 0, sizeof(struct ieee80211_ht_cap));
176 		bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
177 		bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
178 	}
179 
180 	return;
181 }
182 
183 /* This function updates 11ac related parameters from IE
184  * and sets them into bss_config structure.
185  */
mwifiex_set_vht_params(struct mwifiex_private * priv,struct mwifiex_uap_bss_param * bss_cfg,struct cfg80211_ap_settings * params)186 void mwifiex_set_vht_params(struct mwifiex_private *priv,
187 			    struct mwifiex_uap_bss_param *bss_cfg,
188 			    struct cfg80211_ap_settings *params)
189 {
190 	const u8 *vht_ie;
191 
192 	vht_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, params->beacon.tail,
193 				  params->beacon.tail_len);
194 	if (vht_ie) {
195 		memcpy(&bss_cfg->vht_cap, vht_ie + 2,
196 		       sizeof(struct ieee80211_vht_cap));
197 		priv->ap_11ac_enabled = 1;
198 	} else {
199 		priv->ap_11ac_enabled = 0;
200 	}
201 
202 	return;
203 }
204 
205 /* This function updates 11ac related parameters from IE
206  * and sets them into bss_config structure.
207  */
mwifiex_set_tpc_params(struct mwifiex_private * priv,struct mwifiex_uap_bss_param * bss_cfg,struct cfg80211_ap_settings * params)208 void mwifiex_set_tpc_params(struct mwifiex_private *priv,
209 			    struct mwifiex_uap_bss_param *bss_cfg,
210 			    struct cfg80211_ap_settings *params)
211 {
212 	const u8 *tpc_ie;
213 
214 	tpc_ie = cfg80211_find_ie(WLAN_EID_TPC_REQUEST, params->beacon.tail,
215 				  params->beacon.tail_len);
216 	if (tpc_ie)
217 		bss_cfg->power_constraint = *(tpc_ie + 2);
218 	else
219 		bss_cfg->power_constraint = 0;
220 }
221 
222 /* Enable VHT only when cfg80211_ap_settings has VHT IE.
223  * Otherwise disable VHT.
224  */
mwifiex_set_vht_width(struct mwifiex_private * priv,enum nl80211_chan_width width,bool ap_11ac_enable)225 void mwifiex_set_vht_width(struct mwifiex_private *priv,
226 			   enum nl80211_chan_width width,
227 			   bool ap_11ac_enable)
228 {
229 	struct mwifiex_adapter *adapter = priv->adapter;
230 	struct mwifiex_11ac_vht_cfg vht_cfg;
231 
232 	vht_cfg.band_config = VHT_CFG_5GHZ;
233 	vht_cfg.cap_info = adapter->hw_dot_11ac_dev_cap;
234 
235 	if (!ap_11ac_enable) {
236 		vht_cfg.mcs_tx_set = DISABLE_VHT_MCS_SET;
237 		vht_cfg.mcs_rx_set = DISABLE_VHT_MCS_SET;
238 	} else {
239 		vht_cfg.mcs_tx_set = DEFAULT_VHT_MCS_SET;
240 		vht_cfg.mcs_rx_set = DEFAULT_VHT_MCS_SET;
241 	}
242 
243 	vht_cfg.misc_config  = VHT_CAP_UAP_ONLY;
244 
245 	if (ap_11ac_enable && width >= NL80211_CHAN_WIDTH_80)
246 		vht_cfg.misc_config |= VHT_BW_80_160_80P80;
247 
248 	mwifiex_send_cmd(priv, HostCmd_CMD_11AC_CFG,
249 			 HostCmd_ACT_GEN_SET, 0, &vht_cfg, true);
250 
251 	return;
252 }
253 
254 /* This function finds supported rates IE from beacon parameter and sets
255  * these rates into bss_config structure.
256  */
257 void
mwifiex_set_uap_rates(struct mwifiex_uap_bss_param * bss_cfg,struct cfg80211_ap_settings * params)258 mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
259 		      struct cfg80211_ap_settings *params)
260 {
261 	struct ieee_types_header *rate_ie;
262 	int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
263 	const u8 *var_pos = params->beacon.head + var_offset;
264 	int len = params->beacon.head_len - var_offset;
265 	u8 rate_len = 0;
266 
267 	rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
268 	if (rate_ie) {
269 		if (rate_ie->len > MWIFIEX_SUPPORTED_RATES)
270 			return;
271 		memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
272 		rate_len = rate_ie->len;
273 	}
274 
275 	rate_ie = (void *)cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
276 					   params->beacon.tail,
277 					   params->beacon.tail_len);
278 	if (rate_ie) {
279 		if (rate_ie->len > MWIFIEX_SUPPORTED_RATES - rate_len)
280 			return;
281 		memcpy(bss_cfg->rates + rate_len, rate_ie + 1, rate_ie->len);
282 	}
283 
284 	return;
285 }
286 
287 /* This function initializes some of mwifiex_uap_bss_param variables.
288  * This helps FW in ignoring invalid values. These values may or may not
289  * be get updated to valid ones at later stage.
290  */
mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param * config)291 void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
292 {
293 	config->bcast_ssid_ctl = 0x7F;
294 	config->radio_ctl = 0x7F;
295 	config->dtim_period = 0x7F;
296 	config->beacon_period = 0x7FFF;
297 	config->auth_mode = 0x7F;
298 	config->rts_threshold = 0x7FFF;
299 	config->frag_threshold = 0x7FFF;
300 	config->retry_limit = 0x7F;
301 	config->qos_info = 0xFF;
302 }
303 
304 /* This function parses BSS related parameters from structure
305  * and prepares TLVs specific to WPA/WPA2 security.
306  * These TLVs are appended to command buffer.
307  */
308 static void
mwifiex_uap_bss_wpa(u8 ** tlv_buf,void * cmd_buf,u16 * param_size)309 mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
310 {
311 	struct host_cmd_tlv_pwk_cipher *pwk_cipher;
312 	struct host_cmd_tlv_gwk_cipher *gwk_cipher;
313 	struct host_cmd_tlv_passphrase *passphrase;
314 	struct host_cmd_tlv_akmp *tlv_akmp;
315 	struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
316 	u16 cmd_size = *param_size;
317 	u8 *tlv = *tlv_buf;
318 
319 	tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
320 	tlv_akmp->header.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
321 	tlv_akmp->header.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
322 					sizeof(struct mwifiex_ie_types_header));
323 	tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
324 	tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
325 	cmd_size += sizeof(struct host_cmd_tlv_akmp);
326 	tlv += sizeof(struct host_cmd_tlv_akmp);
327 
328 	if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
329 		pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
330 		pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
331 		pwk_cipher->header.len =
332 			cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
333 				    sizeof(struct mwifiex_ie_types_header));
334 		pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
335 		pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
336 		cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
337 		tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
338 	}
339 
340 	if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
341 		pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
342 		pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
343 		pwk_cipher->header.len =
344 			cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
345 				    sizeof(struct mwifiex_ie_types_header));
346 		pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
347 		pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
348 		cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
349 		tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
350 	}
351 
352 	if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
353 		gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
354 		gwk_cipher->header.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
355 		gwk_cipher->header.len =
356 			cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
357 				    sizeof(struct mwifiex_ie_types_header));
358 		gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
359 		cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
360 		tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
361 	}
362 
363 	if (bss_cfg->wpa_cfg.length) {
364 		passphrase = (struct host_cmd_tlv_passphrase *)tlv;
365 		passphrase->header.type =
366 				cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
367 		passphrase->header.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
368 		memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
369 		       bss_cfg->wpa_cfg.length);
370 		cmd_size += sizeof(struct mwifiex_ie_types_header) +
371 			    bss_cfg->wpa_cfg.length;
372 		tlv += sizeof(struct mwifiex_ie_types_header) +
373 				bss_cfg->wpa_cfg.length;
374 	}
375 
376 	*param_size = cmd_size;
377 	*tlv_buf = tlv;
378 
379 	return;
380 }
381 
382 /* This function parses WMM related parameters from cfg80211_ap_settings
383  * structure and updates bss_config structure.
384  */
385 void
mwifiex_set_wmm_params(struct mwifiex_private * priv,struct mwifiex_uap_bss_param * bss_cfg,struct cfg80211_ap_settings * params)386 mwifiex_set_wmm_params(struct mwifiex_private *priv,
387 		       struct mwifiex_uap_bss_param *bss_cfg,
388 		       struct cfg80211_ap_settings *params)
389 {
390 	const u8 *vendor_ie;
391 	const u8 *wmm_ie;
392 	u8 wmm_oui[] = {0x00, 0x50, 0xf2, 0x02};
393 
394 	vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
395 					    WLAN_OUI_TYPE_MICROSOFT_WMM,
396 					    params->beacon.tail,
397 					    params->beacon.tail_len);
398 	if (vendor_ie) {
399 		wmm_ie = vendor_ie;
400 		if (*(wmm_ie + 1) > sizeof(struct mwifiex_types_wmm_info))
401 			return;
402 		memcpy(&bss_cfg->wmm_info, wmm_ie +
403 		       sizeof(struct ieee_types_header), *(wmm_ie + 1));
404 		priv->wmm_enabled = 1;
405 	} else {
406 		memset(&bss_cfg->wmm_info, 0, sizeof(bss_cfg->wmm_info));
407 		memcpy(&bss_cfg->wmm_info.oui, wmm_oui, sizeof(wmm_oui));
408 		bss_cfg->wmm_info.subtype = MWIFIEX_WMM_SUBTYPE;
409 		bss_cfg->wmm_info.version = MWIFIEX_WMM_VERSION;
410 		priv->wmm_enabled = 0;
411 	}
412 
413 	bss_cfg->qos_info = 0x00;
414 	return;
415 }
416 /* This function parses BSS related parameters from structure
417  * and prepares TLVs specific to WEP encryption.
418  * These TLVs are appended to command buffer.
419  */
420 static void
mwifiex_uap_bss_wep(u8 ** tlv_buf,void * cmd_buf,u16 * param_size)421 mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
422 {
423 	struct host_cmd_tlv_wep_key *wep_key;
424 	u16 cmd_size = *param_size;
425 	int i;
426 	u8 *tlv = *tlv_buf;
427 	struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
428 
429 	for (i = 0; i < NUM_WEP_KEYS; i++) {
430 		if (bss_cfg->wep_cfg[i].length &&
431 		    (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
432 		     bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
433 			wep_key = (struct host_cmd_tlv_wep_key *)tlv;
434 			wep_key->header.type =
435 				cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
436 			wep_key->header.len =
437 				cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
438 			wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
439 			wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
440 			memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
441 			       bss_cfg->wep_cfg[i].length);
442 			cmd_size += sizeof(struct mwifiex_ie_types_header) + 2 +
443 				    bss_cfg->wep_cfg[i].length;
444 			tlv += sizeof(struct mwifiex_ie_types_header) + 2 +
445 				    bss_cfg->wep_cfg[i].length;
446 		}
447 	}
448 
449 	*param_size = cmd_size;
450 	*tlv_buf = tlv;
451 
452 	return;
453 }
454 
455 /* This function enable 11D if userspace set the country IE.
456  */
mwifiex_config_uap_11d(struct mwifiex_private * priv,struct cfg80211_beacon_data * beacon_data)457 void mwifiex_config_uap_11d(struct mwifiex_private *priv,
458 			    struct cfg80211_beacon_data *beacon_data)
459 {
460 	enum state_11d_t state_11d;
461 	const u8 *country_ie;
462 
463 	country_ie = cfg80211_find_ie(WLAN_EID_COUNTRY, beacon_data->tail,
464 				      beacon_data->tail_len);
465 	if (country_ie) {
466 		/* Send cmd to FW to enable 11D function */
467 		state_11d = ENABLE_11D;
468 		if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
469 				     HostCmd_ACT_GEN_SET, DOT11D_I,
470 				     &state_11d, true)) {
471 			mwifiex_dbg(priv->adapter, ERROR,
472 				    "11D: failed to enable 11D\n");
473 		}
474 	}
475 }
476 
477 /* This function parses BSS related parameters from structure
478  * and prepares TLVs. These TLVs are appended to command buffer.
479 */
480 static int
mwifiex_uap_bss_param_prepare(u8 * tlv,void * cmd_buf,u16 * param_size)481 mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
482 {
483 	struct host_cmd_tlv_mac_addr *mac_tlv;
484 	struct host_cmd_tlv_dtim_period *dtim_period;
485 	struct host_cmd_tlv_beacon_period *beacon_period;
486 	struct host_cmd_tlv_ssid *ssid;
487 	struct host_cmd_tlv_bcast_ssid *bcast_ssid;
488 	struct host_cmd_tlv_channel_band *chan_band;
489 	struct host_cmd_tlv_frag_threshold *frag_threshold;
490 	struct host_cmd_tlv_rts_threshold *rts_threshold;
491 	struct host_cmd_tlv_retry_limit *retry_limit;
492 	struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
493 	struct host_cmd_tlv_auth_type *auth_type;
494 	struct host_cmd_tlv_rates *tlv_rates;
495 	struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
496 	struct host_cmd_tlv_power_constraint *pwr_ct;
497 	struct mwifiex_ie_types_htcap *htcap;
498 	struct mwifiex_ie_types_wmmcap *wmm_cap;
499 	struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
500 	int i;
501 	u16 cmd_size = *param_size;
502 
503 	mac_tlv = (struct host_cmd_tlv_mac_addr *)tlv;
504 	mac_tlv->header.type = cpu_to_le16(TLV_TYPE_UAP_MAC_ADDRESS);
505 	mac_tlv->header.len = cpu_to_le16(ETH_ALEN);
506 	memcpy(mac_tlv->mac_addr, bss_cfg->mac_addr, ETH_ALEN);
507 	cmd_size += sizeof(struct host_cmd_tlv_mac_addr);
508 	tlv += sizeof(struct host_cmd_tlv_mac_addr);
509 
510 	if (bss_cfg->ssid.ssid_len) {
511 		ssid = (struct host_cmd_tlv_ssid *)tlv;
512 		ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
513 		ssid->header.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
514 		memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
515 		cmd_size += sizeof(struct mwifiex_ie_types_header) +
516 			    bss_cfg->ssid.ssid_len;
517 		tlv += sizeof(struct mwifiex_ie_types_header) +
518 				bss_cfg->ssid.ssid_len;
519 
520 		bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
521 		bcast_ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
522 		bcast_ssid->header.len =
523 				cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
524 		bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
525 		cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
526 		tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
527 	}
528 	if (bss_cfg->rates[0]) {
529 		tlv_rates = (struct host_cmd_tlv_rates *)tlv;
530 		tlv_rates->header.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
531 
532 		for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
533 		     i++)
534 			tlv_rates->rates[i] = bss_cfg->rates[i];
535 
536 		tlv_rates->header.len = cpu_to_le16(i);
537 		cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
538 		tlv += sizeof(struct host_cmd_tlv_rates) + i;
539 	}
540 	if (bss_cfg->channel &&
541 	    (((bss_cfg->band_cfg & BIT(0)) == BAND_CONFIG_BG &&
542 	      bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
543 	    ((bss_cfg->band_cfg & BIT(0)) == BAND_CONFIG_A &&
544 	     bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
545 		chan_band = (struct host_cmd_tlv_channel_band *)tlv;
546 		chan_band->header.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
547 		chan_band->header.len =
548 			cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
549 				    sizeof(struct mwifiex_ie_types_header));
550 		chan_band->band_config = bss_cfg->band_cfg;
551 		chan_band->channel = bss_cfg->channel;
552 		cmd_size += sizeof(struct host_cmd_tlv_channel_band);
553 		tlv += sizeof(struct host_cmd_tlv_channel_band);
554 	}
555 	if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
556 	    bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
557 		beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
558 		beacon_period->header.type =
559 					cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
560 		beacon_period->header.len =
561 			cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
562 				    sizeof(struct mwifiex_ie_types_header));
563 		beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
564 		cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
565 		tlv += sizeof(struct host_cmd_tlv_beacon_period);
566 	}
567 	if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
568 	    bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
569 		dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
570 		dtim_period->header.type =
571 			cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
572 		dtim_period->header.len =
573 			cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
574 				    sizeof(struct mwifiex_ie_types_header));
575 		dtim_period->period = bss_cfg->dtim_period;
576 		cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
577 		tlv += sizeof(struct host_cmd_tlv_dtim_period);
578 	}
579 	if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
580 		rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
581 		rts_threshold->header.type =
582 					cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
583 		rts_threshold->header.len =
584 			cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
585 				    sizeof(struct mwifiex_ie_types_header));
586 		rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
587 		cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
588 		tlv += sizeof(struct host_cmd_tlv_frag_threshold);
589 	}
590 	if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
591 	    (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
592 		frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
593 		frag_threshold->header.type =
594 				cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
595 		frag_threshold->header.len =
596 			cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
597 				    sizeof(struct mwifiex_ie_types_header));
598 		frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
599 		cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
600 		tlv += sizeof(struct host_cmd_tlv_frag_threshold);
601 	}
602 	if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
603 		retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
604 		retry_limit->header.type =
605 			cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
606 		retry_limit->header.len =
607 			cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
608 				    sizeof(struct mwifiex_ie_types_header));
609 		retry_limit->limit = (u8)bss_cfg->retry_limit;
610 		cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
611 		tlv += sizeof(struct host_cmd_tlv_retry_limit);
612 	}
613 	if ((bss_cfg->protocol & PROTOCOL_WPA) ||
614 	    (bss_cfg->protocol & PROTOCOL_WPA2) ||
615 	    (bss_cfg->protocol & PROTOCOL_EAP))
616 		mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
617 	else
618 		mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
619 
620 	if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
621 	    (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
622 		auth_type = (struct host_cmd_tlv_auth_type *)tlv;
623 		auth_type->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
624 		auth_type->header.len =
625 			cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
626 			sizeof(struct mwifiex_ie_types_header));
627 		auth_type->auth_type = (u8)bss_cfg->auth_mode;
628 		cmd_size += sizeof(struct host_cmd_tlv_auth_type);
629 		tlv += sizeof(struct host_cmd_tlv_auth_type);
630 	}
631 	if (bss_cfg->protocol) {
632 		encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
633 		encrypt_protocol->header.type =
634 			cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
635 		encrypt_protocol->header.len =
636 			cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
637 			- sizeof(struct mwifiex_ie_types_header));
638 		encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
639 		cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
640 		tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
641 	}
642 
643 	if (bss_cfg->ht_cap.cap_info) {
644 		htcap = (struct mwifiex_ie_types_htcap *)tlv;
645 		htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
646 		htcap->header.len =
647 				cpu_to_le16(sizeof(struct ieee80211_ht_cap));
648 		htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
649 		htcap->ht_cap.ampdu_params_info =
650 					     bss_cfg->ht_cap.ampdu_params_info;
651 		memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
652 		       sizeof(struct ieee80211_mcs_info));
653 		htcap->ht_cap.extended_ht_cap_info =
654 					bss_cfg->ht_cap.extended_ht_cap_info;
655 		htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
656 		htcap->ht_cap.antenna_selection_info =
657 					bss_cfg->ht_cap.antenna_selection_info;
658 		cmd_size += sizeof(struct mwifiex_ie_types_htcap);
659 		tlv += sizeof(struct mwifiex_ie_types_htcap);
660 	}
661 
662 	if (bss_cfg->wmm_info.qos_info != 0xFF) {
663 		wmm_cap = (struct mwifiex_ie_types_wmmcap *)tlv;
664 		wmm_cap->header.type = cpu_to_le16(WLAN_EID_VENDOR_SPECIFIC);
665 		wmm_cap->header.len = cpu_to_le16(sizeof(wmm_cap->wmm_info));
666 		memcpy(&wmm_cap->wmm_info, &bss_cfg->wmm_info,
667 		       sizeof(wmm_cap->wmm_info));
668 		cmd_size += sizeof(struct mwifiex_ie_types_wmmcap);
669 		tlv += sizeof(struct mwifiex_ie_types_wmmcap);
670 	}
671 
672 	if (bss_cfg->sta_ao_timer) {
673 		ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
674 		ao_timer->header.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
675 		ao_timer->header.len = cpu_to_le16(sizeof(*ao_timer) -
676 					sizeof(struct mwifiex_ie_types_header));
677 		ao_timer->sta_ao_timer = cpu_to_le32(bss_cfg->sta_ao_timer);
678 		cmd_size += sizeof(*ao_timer);
679 		tlv += sizeof(*ao_timer);
680 	}
681 
682 	if (bss_cfg->power_constraint) {
683 		pwr_ct = (void *)tlv;
684 		pwr_ct->header.type = cpu_to_le16(TLV_TYPE_PWR_CONSTRAINT);
685 		pwr_ct->header.len = cpu_to_le16(sizeof(u8));
686 		pwr_ct->constraint = bss_cfg->power_constraint;
687 		cmd_size += sizeof(*pwr_ct);
688 		tlv += sizeof(*pwr_ct);
689 	}
690 
691 	if (bss_cfg->ps_sta_ao_timer) {
692 		ps_ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
693 		ps_ao_timer->header.type =
694 				cpu_to_le16(TLV_TYPE_UAP_PS_AO_TIMER);
695 		ps_ao_timer->header.len = cpu_to_le16(sizeof(*ps_ao_timer) -
696 				sizeof(struct mwifiex_ie_types_header));
697 		ps_ao_timer->sta_ao_timer =
698 					cpu_to_le32(bss_cfg->ps_sta_ao_timer);
699 		cmd_size += sizeof(*ps_ao_timer);
700 		tlv += sizeof(*ps_ao_timer);
701 	}
702 
703 	*param_size = cmd_size;
704 
705 	return 0;
706 }
707 
708 /* This function parses custom IEs from IE list and prepares command buffer */
mwifiex_uap_custom_ie_prepare(u8 * tlv,void * cmd_buf,u16 * ie_size)709 static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
710 {
711 	struct mwifiex_ie_list *ap_ie = cmd_buf;
712 	struct mwifiex_ie_types_header *tlv_ie = (void *)tlv;
713 
714 	if (!ap_ie || !ap_ie->len)
715 		return -1;
716 
717 	*ie_size += le16_to_cpu(ap_ie->len) +
718 			sizeof(struct mwifiex_ie_types_header);
719 
720 	tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
721 	tlv_ie->len = ap_ie->len;
722 	tlv += sizeof(struct mwifiex_ie_types_header);
723 
724 	memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
725 
726 	return 0;
727 }
728 
729 /* Parse AP config structure and prepare TLV based command structure
730  * to be sent to FW for uAP configuration
731  */
732 static int
mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command * cmd,u16 cmd_action,u32 type,void * cmd_buf)733 mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
734 			   u32 type, void *cmd_buf)
735 {
736 	u8 *tlv;
737 	u16 cmd_size, param_size, ie_size;
738 	struct host_cmd_ds_sys_config *sys_cfg;
739 
740 	cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
741 	cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
742 	sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
743 	sys_cfg->action = cpu_to_le16(cmd_action);
744 	tlv = sys_cfg->tlv;
745 
746 	switch (type) {
747 	case UAP_BSS_PARAMS_I:
748 		param_size = cmd_size;
749 		if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
750 			return -1;
751 		cmd->size = cpu_to_le16(param_size);
752 		break;
753 	case UAP_CUSTOM_IE_I:
754 		ie_size = cmd_size;
755 		if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
756 			return -1;
757 		cmd->size = cpu_to_le16(ie_size);
758 		break;
759 	default:
760 		return -1;
761 	}
762 
763 	return 0;
764 }
765 
766 /* This function prepares AP specific deauth command with mac supplied in
767  * function parameter.
768  */
mwifiex_cmd_uap_sta_deauth(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u8 * mac)769 static int mwifiex_cmd_uap_sta_deauth(struct mwifiex_private *priv,
770 				      struct host_cmd_ds_command *cmd, u8 *mac)
771 {
772 	struct host_cmd_ds_sta_deauth *sta_deauth = &cmd->params.sta_deauth;
773 
774 	cmd->command = cpu_to_le16(HostCmd_CMD_UAP_STA_DEAUTH);
775 	memcpy(sta_deauth->mac, mac, ETH_ALEN);
776 	sta_deauth->reason = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
777 
778 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_sta_deauth) +
779 				S_DS_GEN);
780 	return 0;
781 }
782 
783 /* This function prepares the AP specific commands before sending them
784  * to the firmware.
785  * This is a generic function which calls specific command preparation
786  * routines based upon the command number.
787  */
mwifiex_uap_prepare_cmd(struct mwifiex_private * priv,u16 cmd_no,u16 cmd_action,u32 type,void * data_buf,void * cmd_buf)788 int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
789 			    u16 cmd_action, u32 type,
790 			    void *data_buf, void *cmd_buf)
791 {
792 	struct host_cmd_ds_command *cmd = cmd_buf;
793 
794 	switch (cmd_no) {
795 	case HostCmd_CMD_UAP_SYS_CONFIG:
796 		if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
797 			return -1;
798 		break;
799 	case HostCmd_CMD_UAP_BSS_START:
800 	case HostCmd_CMD_UAP_BSS_STOP:
801 	case HOST_CMD_APCMD_SYS_RESET:
802 	case HOST_CMD_APCMD_STA_LIST:
803 		cmd->command = cpu_to_le16(cmd_no);
804 		cmd->size = cpu_to_le16(S_DS_GEN);
805 		break;
806 	case HostCmd_CMD_UAP_STA_DEAUTH:
807 		if (mwifiex_cmd_uap_sta_deauth(priv, cmd, data_buf))
808 			return -1;
809 		break;
810 	case HostCmd_CMD_CHAN_REPORT_REQUEST:
811 		if (mwifiex_cmd_issue_chan_report_request(priv, cmd_buf,
812 							  data_buf))
813 			return -1;
814 		break;
815 	default:
816 		mwifiex_dbg(priv->adapter, ERROR,
817 			    "PREP_CMD: unknown cmd %#x\n", cmd_no);
818 		return -1;
819 	}
820 
821 	return 0;
822 }
823 
mwifiex_uap_set_channel(struct mwifiex_private * priv,struct mwifiex_uap_bss_param * bss_cfg,struct cfg80211_chan_def chandef)824 void mwifiex_uap_set_channel(struct mwifiex_private *priv,
825 			     struct mwifiex_uap_bss_param *bss_cfg,
826 			     struct cfg80211_chan_def chandef)
827 {
828 	u8 config_bands = 0, old_bands = priv->adapter->config_bands;
829 
830 	priv->bss_chandef = chandef;
831 
832 	bss_cfg->channel = ieee80211_frequency_to_channel(
833 						     chandef.chan->center_freq);
834 
835 	/* Set appropriate bands */
836 	if (chandef.chan->band == NL80211_BAND_2GHZ) {
837 		bss_cfg->band_cfg = BAND_CONFIG_BG;
838 		config_bands = BAND_B | BAND_G;
839 
840 		if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
841 			config_bands |= BAND_GN;
842 	} else {
843 		bss_cfg->band_cfg = BAND_CONFIG_A;
844 		config_bands = BAND_A;
845 
846 		if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
847 			config_bands |= BAND_AN;
848 
849 		if (chandef.width > NL80211_CHAN_WIDTH_40)
850 			config_bands |= BAND_AAC;
851 	}
852 
853 	switch (chandef.width) {
854 	case NL80211_CHAN_WIDTH_5:
855 	case NL80211_CHAN_WIDTH_10:
856 	case NL80211_CHAN_WIDTH_20_NOHT:
857 	case NL80211_CHAN_WIDTH_20:
858 		break;
859 	case NL80211_CHAN_WIDTH_40:
860 		if (chandef.center_freq1 < chandef.chan->center_freq)
861 			bss_cfg->band_cfg |= MWIFIEX_SEC_CHAN_BELOW;
862 		else
863 			bss_cfg->band_cfg |= MWIFIEX_SEC_CHAN_ABOVE;
864 		break;
865 	case NL80211_CHAN_WIDTH_80:
866 	case NL80211_CHAN_WIDTH_80P80:
867 	case NL80211_CHAN_WIDTH_160:
868 		bss_cfg->band_cfg |=
869 		    mwifiex_get_sec_chan_offset(bss_cfg->channel) << 4;
870 		break;
871 	default:
872 		mwifiex_dbg(priv->adapter,
873 			    WARN, "Unknown channel width: %d\n",
874 			    chandef.width);
875 		break;
876 	}
877 
878 	priv->adapter->config_bands = config_bands;
879 
880 	if (old_bands != config_bands) {
881 		mwifiex_send_domain_info_cmd_fw(priv->adapter->wiphy);
882 		mwifiex_dnld_txpwr_table(priv);
883 	}
884 }
885 
mwifiex_config_start_uap(struct mwifiex_private * priv,struct mwifiex_uap_bss_param * bss_cfg)886 int mwifiex_config_start_uap(struct mwifiex_private *priv,
887 			     struct mwifiex_uap_bss_param *bss_cfg)
888 {
889 	if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
890 			     HostCmd_ACT_GEN_SET,
891 			     UAP_BSS_PARAMS_I, bss_cfg, true)) {
892 		mwifiex_dbg(priv->adapter, ERROR,
893 			    "Failed to set AP configuration\n");
894 		return -1;
895 	}
896 
897 	if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_START,
898 			     HostCmd_ACT_GEN_SET, 0, NULL, true)) {
899 		mwifiex_dbg(priv->adapter, ERROR,
900 			    "Failed to start the BSS\n");
901 		return -1;
902 	}
903 
904 	if (priv->sec_info.wep_enabled)
905 		priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
906 	else
907 		priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
908 
909 	if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
910 			     HostCmd_ACT_GEN_SET, 0,
911 			     &priv->curr_pkt_filter, true))
912 		return -1;
913 
914 	return 0;
915 }
916