xref: /linux/drivers/net/wireless/marvell/mwifiex/sta_cmd.c (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * NXP Wireless LAN device driver: station command handling
4  *
5  * Copyright 2011-2020 NXP
6  */
7 
8 #include "decl.h"
9 #include "ioctl.h"
10 #include "util.h"
11 #include "fw.h"
12 #include "main.h"
13 #include "wmm.h"
14 #include "11n.h"
15 #include "11ac.h"
16 
17 static bool drcs;
18 module_param(drcs, bool, 0644);
19 MODULE_PARM_DESC(drcs, "multi-channel operation:1, single-channel operation:0");
20 
21 static bool disable_auto_ds;
22 module_param(disable_auto_ds, bool, 0);
23 MODULE_PARM_DESC(disable_auto_ds,
24 		 "deepsleep enabled=0(default), deepsleep disabled=1");
25 /*
26  * This function prepares command to set/get RSSI information.
27  *
28  * Preparation includes -
29  *      - Setting command ID, action and proper size
30  *      - Setting data/beacon average factors
31  *      - Resetting SNR/NF/RSSI values in private structure
32  *      - Ensuring correct endian-ness
33  */
34 static int
mwifiex_cmd_802_11_rssi_info(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action)35 mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
36 			     struct host_cmd_ds_command *cmd, u16 cmd_action)
37 {
38 	cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
39 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
40 				S_DS_GEN);
41 	cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
42 	cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
43 	cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
44 
45 	/* Reset SNR/NF/RSSI values in private structure */
46 	priv->data_rssi_last = 0;
47 	priv->data_nf_last = 0;
48 	priv->data_rssi_avg = 0;
49 	priv->data_nf_avg = 0;
50 	priv->bcn_rssi_last = 0;
51 	priv->bcn_nf_last = 0;
52 	priv->bcn_rssi_avg = 0;
53 	priv->bcn_nf_avg = 0;
54 
55 	return 0;
56 }
57 
58 /*
59  * This function prepares command to set MAC control.
60  *
61  * Preparation includes -
62  *      - Setting command ID, action and proper size
63  *      - Ensuring correct endian-ness
64  */
mwifiex_cmd_mac_control(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,u32 * action)65 static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
66 				   struct host_cmd_ds_command *cmd,
67 				   u16 cmd_action, u32 *action)
68 {
69 	struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
70 
71 	if (cmd_action != HostCmd_ACT_GEN_SET) {
72 		mwifiex_dbg(priv->adapter, ERROR,
73 			    "mac_control: only support set cmd\n");
74 		return -1;
75 	}
76 
77 	cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
78 	cmd->size =
79 		cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
80 	mac_ctrl->action = cpu_to_le32(*action);
81 
82 	return 0;
83 }
84 
85 /*
86  * This function prepares command to set/get SNMP MIB.
87  *
88  * Preparation includes -
89  *      - Setting command ID, action and proper size
90  *      - Setting SNMP MIB OID number and value
91  *        (as required)
92  *      - Ensuring correct endian-ness
93  *
94  * The following SNMP MIB OIDs are supported -
95  *      - FRAG_THRESH_I     : Fragmentation threshold
96  *      - RTS_THRESH_I      : RTS threshold
97  *      - SHORT_RETRY_LIM_I : Short retry limit
98  *      - DOT11D_I          : 11d support
99  */
mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,u32 cmd_oid,u16 * ul_temp)100 static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
101 				       struct host_cmd_ds_command *cmd,
102 				       u16 cmd_action, u32 cmd_oid,
103 				       u16 *ul_temp)
104 {
105 	struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
106 
107 	mwifiex_dbg(priv->adapter, CMD,
108 		    "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
109 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
110 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
111 				- 1 + S_DS_GEN);
112 
113 	snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
114 	if (cmd_action == HostCmd_ACT_GEN_GET) {
115 		snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
116 		snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
117 		le16_unaligned_add_cpu(&cmd->size, MAX_SNMP_BUF_SIZE);
118 	} else if (cmd_action == HostCmd_ACT_GEN_SET) {
119 		snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
120 		snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
121 		put_unaligned_le16(*ul_temp, snmp_mib->value);
122 		le16_unaligned_add_cpu(&cmd->size, sizeof(u16));
123 	}
124 
125 	mwifiex_dbg(priv->adapter, CMD,
126 		    "cmd: SNMP_CMD: Action=0x%x, OID=0x%x,\t"
127 		    "OIDSize=0x%x, Value=0x%x\n",
128 		    cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
129 		    get_unaligned_le16(snmp_mib->value));
130 	return 0;
131 }
132 
133 /*
134  * This function prepares command to get log.
135  *
136  * Preparation includes -
137  *      - Setting command ID and proper size
138  *      - Ensuring correct endian-ness
139  */
140 static int
mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command * cmd)141 mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
142 {
143 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
144 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
145 				S_DS_GEN);
146 	return 0;
147 }
148 
149 /*
150  * This function prepares command to set/get Tx data rate configuration.
151  *
152  * Preparation includes -
153  *      - Setting command ID, action and proper size
154  *      - Setting configuration index, rate scope and rate drop pattern
155  *        parameters (as required)
156  *      - Ensuring correct endian-ness
157  */
mwifiex_cmd_tx_rate_cfg(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,const u16 * pbitmap_rates)158 static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
159 				   struct host_cmd_ds_command *cmd,
160 				   u16 cmd_action, const u16 *pbitmap_rates)
161 {
162 	struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
163 	struct mwifiex_rate_scope *rate_scope;
164 	struct mwifiex_rate_drop_pattern *rate_drop;
165 	u32 i;
166 
167 	cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
168 
169 	rate_cfg->action = cpu_to_le16(cmd_action);
170 	rate_cfg->cfg_index = 0;
171 
172 	rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
173 		      sizeof(struct host_cmd_ds_tx_rate_cfg));
174 	rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
175 	rate_scope->length = cpu_to_le16
176 		(sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
177 	if (!pbitmap_rates)
178 		pbitmap_rates = priv->bitmap_rates;
179 
180 	rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
181 	rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
182 
183 	for (i = 0; i < ARRAY_SIZE(rate_scope->ht_mcs_rate_bitmap); i++)
184 		rate_scope->ht_mcs_rate_bitmap[i] = cpu_to_le16(pbitmap_rates[2 + i]);
185 
186 	if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
187 		for (i = 0; i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap); i++)
188 			rate_scope->vht_mcs_rate_bitmap[i] =
189 				cpu_to_le16(pbitmap_rates[10 + i]);
190 	}
191 
192 	rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
193 					     sizeof(struct mwifiex_rate_scope));
194 	rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
195 	rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
196 	rate_drop->rate_drop_mode = 0;
197 
198 	cmd->size =
199 		cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
200 			    sizeof(struct mwifiex_rate_scope) +
201 			    sizeof(struct mwifiex_rate_drop_pattern));
202 
203 	return 0;
204 }
205 
206 /*
207  * This function prepares command to set/get Tx power configuration.
208  *
209  * Preparation includes -
210  *      - Setting command ID, action and proper size
211  *      - Setting Tx power mode, power group TLV
212  *        (as required)
213  *      - Ensuring correct endian-ness
214  */
mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command * cmd,u16 cmd_action,struct host_cmd_ds_txpwr_cfg * txp)215 static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
216 				    u16 cmd_action,
217 				    struct host_cmd_ds_txpwr_cfg *txp)
218 {
219 	struct mwifiex_types_power_group *pg_tlv;
220 	struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
221 
222 	cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
223 	cmd->size =
224 		cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
225 	switch (cmd_action) {
226 	case HostCmd_ACT_GEN_SET:
227 		if (txp->mode) {
228 			pg_tlv = (struct mwifiex_types_power_group
229 				  *) ((unsigned long) txp +
230 				     sizeof(struct host_cmd_ds_txpwr_cfg));
231 			memmove(cmd_txp_cfg, txp,
232 				sizeof(struct host_cmd_ds_txpwr_cfg) +
233 				sizeof(struct mwifiex_types_power_group) +
234 				le16_to_cpu(pg_tlv->length));
235 
236 			pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
237 				  cmd_txp_cfg +
238 				  sizeof(struct host_cmd_ds_txpwr_cfg));
239 			cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
240 				  sizeof(struct mwifiex_types_power_group) +
241 				  le16_to_cpu(pg_tlv->length));
242 		} else {
243 			memmove(cmd_txp_cfg, txp, sizeof(*txp));
244 		}
245 		cmd_txp_cfg->action = cpu_to_le16(cmd_action);
246 		break;
247 	case HostCmd_ACT_GEN_GET:
248 		cmd_txp_cfg->action = cpu_to_le16(cmd_action);
249 		break;
250 	}
251 
252 	return 0;
253 }
254 
255 /*
256  * This function prepares command to get RF Tx power.
257  */
mwifiex_cmd_rf_tx_power(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,void * data_buf)258 static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv,
259 				   struct host_cmd_ds_command *cmd,
260 				   u16 cmd_action, void *data_buf)
261 {
262 	struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp;
263 
264 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr)
265 				+ S_DS_GEN);
266 	cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR);
267 	txp->action = cpu_to_le16(cmd_action);
268 
269 	return 0;
270 }
271 
272 /*
273  * This function prepares command to set rf antenna.
274  */
mwifiex_cmd_rf_antenna(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,struct mwifiex_ds_ant_cfg * ant_cfg)275 static int mwifiex_cmd_rf_antenna(struct mwifiex_private *priv,
276 				  struct host_cmd_ds_command *cmd,
277 				  u16 cmd_action,
278 				  struct mwifiex_ds_ant_cfg *ant_cfg)
279 {
280 	struct host_cmd_ds_rf_ant_mimo *ant_mimo = &cmd->params.ant_mimo;
281 	struct host_cmd_ds_rf_ant_siso *ant_siso = &cmd->params.ant_siso;
282 
283 	cmd->command = cpu_to_le16(HostCmd_CMD_RF_ANTENNA);
284 
285 	switch (cmd_action) {
286 	case HostCmd_ACT_GEN_SET:
287 		if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
288 			cmd->size = cpu_to_le16(sizeof(struct
289 						host_cmd_ds_rf_ant_mimo)
290 						+ S_DS_GEN);
291 			ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_SET_TX);
292 			ant_mimo->tx_ant_mode = cpu_to_le16((u16)ant_cfg->
293 							    tx_ant);
294 			ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX);
295 			ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg->
296 							    rx_ant);
297 		} else {
298 			cmd->size = cpu_to_le16(sizeof(struct
299 						host_cmd_ds_rf_ant_siso) +
300 						S_DS_GEN);
301 			ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH);
302 			ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
303 		}
304 		break;
305 	case HostCmd_ACT_GEN_GET:
306 		if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
307 			cmd->size = cpu_to_le16(sizeof(struct
308 						host_cmd_ds_rf_ant_mimo) +
309 						S_DS_GEN);
310 			ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_GET_TX);
311 			ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_GET_RX);
312 		} else {
313 			cmd->size = cpu_to_le16(sizeof(struct
314 						host_cmd_ds_rf_ant_siso) +
315 						S_DS_GEN);
316 			ant_siso->action = cpu_to_le16(HostCmd_ACT_GET_BOTH);
317 		}
318 		break;
319 	}
320 	return 0;
321 }
322 
323 /*
324  * This function prepares command to set Host Sleep configuration.
325  *
326  * Preparation includes -
327  *      - Setting command ID and proper size
328  *      - Setting Host Sleep action, conditions, ARP filters
329  *        (as required)
330  *      - Ensuring correct endian-ness
331  */
332 static int
mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,struct mwifiex_hs_config_param * hscfg_param)333 mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
334 			  struct host_cmd_ds_command *cmd,
335 			  u16 cmd_action,
336 			  struct mwifiex_hs_config_param *hscfg_param)
337 {
338 	struct mwifiex_adapter *adapter = priv->adapter;
339 	struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
340 	u8 *tlv = (u8 *)hs_cfg + sizeof(struct host_cmd_ds_802_11_hs_cfg_enh);
341 	struct mwifiex_ps_param_in_hs *psparam_tlv = NULL;
342 	bool hs_activate = false;
343 	u16 size;
344 
345 	if (!hscfg_param)
346 		/* New Activate command */
347 		hs_activate = true;
348 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
349 
350 	if (!hs_activate &&
351 	    (hscfg_param->conditions != cpu_to_le32(HS_CFG_CANCEL)) &&
352 	    ((adapter->arp_filter_size > 0) &&
353 	     (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
354 		mwifiex_dbg(adapter, CMD,
355 			    "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
356 			    adapter->arp_filter_size);
357 		memcpy(((u8 *) hs_cfg) +
358 		       sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
359 		       adapter->arp_filter, adapter->arp_filter_size);
360 		size = adapter->arp_filter_size +
361 			sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
362 			+ S_DS_GEN;
363 		tlv = (u8 *)hs_cfg
364 			+ sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
365 			+ adapter->arp_filter_size;
366 	} else {
367 		size = S_DS_GEN + sizeof(struct host_cmd_ds_802_11_hs_cfg_enh);
368 	}
369 	if (hs_activate) {
370 		hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
371 		hs_cfg->params.hs_activate.resp_ctrl = cpu_to_le16(RESP_NEEDED);
372 
373 		adapter->hs_activated_manually = true;
374 		mwifiex_dbg(priv->adapter, CMD,
375 			    "cmd: Activating host sleep manually\n");
376 	} else {
377 		hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
378 		hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
379 		hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
380 		hs_cfg->params.hs_config.gap = hscfg_param->gap;
381 
382 		size += sizeof(struct mwifiex_ps_param_in_hs);
383 		psparam_tlv = (struct mwifiex_ps_param_in_hs *)tlv;
384 		psparam_tlv->header.type =
385 			cpu_to_le16(TLV_TYPE_PS_PARAMS_IN_HS);
386 		psparam_tlv->header.len =
387 			cpu_to_le16(sizeof(struct mwifiex_ps_param_in_hs)
388 				- sizeof(struct mwifiex_ie_types_header));
389 		psparam_tlv->hs_wake_int = cpu_to_le32(HS_DEF_WAKE_INTERVAL);
390 		psparam_tlv->hs_inact_timeout =
391 			cpu_to_le32(HS_DEF_INACTIVITY_TIMEOUT);
392 
393 		mwifiex_dbg(adapter, CMD,
394 			    "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
395 			    hs_cfg->params.hs_config.conditions,
396 			    hs_cfg->params.hs_config.gpio,
397 			    hs_cfg->params.hs_config.gap);
398 	}
399 	cmd->size = cpu_to_le16(size);
400 
401 	return 0;
402 }
403 
404 /*
405  * This function prepares command to set/get MAC address.
406  *
407  * Preparation includes -
408  *      - Setting command ID, action and proper size
409  *      - Setting MAC address (for SET only)
410  *      - Ensuring correct endian-ness
411  */
mwifiex_cmd_802_11_mac_address(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action)412 static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
413 					  struct host_cmd_ds_command *cmd,
414 					  u16 cmd_action)
415 {
416 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
417 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
418 				S_DS_GEN);
419 	cmd->result = 0;
420 
421 	cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
422 
423 	if (cmd_action == HostCmd_ACT_GEN_SET)
424 		memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
425 		       ETH_ALEN);
426 	return 0;
427 }
428 
429 /*
430  * This function prepares command to set MAC multicast address.
431  *
432  * Preparation includes -
433  *      - Setting command ID, action and proper size
434  *      - Setting MAC multicast address
435  *      - Ensuring correct endian-ness
436  */
437 static int
mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command * cmd,u16 cmd_action,struct mwifiex_multicast_list * mcast_list)438 mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
439 			      u16 cmd_action,
440 			      struct mwifiex_multicast_list *mcast_list)
441 {
442 	struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
443 
444 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
445 				S_DS_GEN);
446 	cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
447 
448 	mcast_addr->action = cpu_to_le16(cmd_action);
449 	mcast_addr->num_of_adrs =
450 		cpu_to_le16((u16) mcast_list->num_multicast_addr);
451 	memcpy(mcast_addr->mac_list, mcast_list->mac_list,
452 	       mcast_list->num_multicast_addr * ETH_ALEN);
453 
454 	return 0;
455 }
456 
457 /*
458  * This function prepares command to deauthenticate.
459  *
460  * Preparation includes -
461  *      - Setting command ID and proper size
462  *      - Setting AP MAC address and reason code
463  *      - Ensuring correct endian-ness
464  */
mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u8 * mac)465 static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
466 					     struct host_cmd_ds_command *cmd,
467 					     u8 *mac)
468 {
469 	struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
470 
471 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
472 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
473 				+ S_DS_GEN);
474 
475 	/* Set AP MAC address */
476 	memcpy(deauth->mac_addr, mac, ETH_ALEN);
477 
478 	mwifiex_dbg(priv->adapter, CMD, "cmd: Deauth: %pM\n", deauth->mac_addr);
479 
480 	deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
481 
482 	return 0;
483 }
484 
485 /*
486  * This function prepares command to stop Ad-Hoc network.
487  *
488  * Preparation includes -
489  *      - Setting command ID and proper size
490  *      - Ensuring correct endian-ness
491  */
mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command * cmd)492 static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
493 {
494 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
495 	cmd->size = cpu_to_le16(S_DS_GEN);
496 	return 0;
497 }
498 
499 /*
500  * This function sets WEP key(s) to key parameter TLV(s).
501  *
502  * Multi-key parameter TLVs are supported, so we can send multiple
503  * WEP keys in a single buffer.
504  */
505 static int
mwifiex_set_keyparamset_wep(struct mwifiex_private * priv,struct mwifiex_ie_type_key_param_set * key_param_set,u16 * key_param_len)506 mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
507 			    struct mwifiex_ie_type_key_param_set *key_param_set,
508 			    u16 *key_param_len)
509 {
510 	int cur_key_param_len;
511 	u8 i;
512 
513 	/* Multi-key_param_set TLV is supported */
514 	for (i = 0; i < NUM_WEP_KEYS; i++) {
515 		if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
516 		    (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
517 			key_param_set->type =
518 				cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
519 /* Key_param_set WEP fixed length */
520 #define KEYPARAMSET_WEP_FIXED_LEN 8
521 			key_param_set->length = cpu_to_le16((u16)
522 					(priv->wep_key[i].
523 					 key_length +
524 					 KEYPARAMSET_WEP_FIXED_LEN));
525 			key_param_set->key_type_id =
526 				cpu_to_le16(KEY_TYPE_ID_WEP);
527 			key_param_set->key_info =
528 				cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
529 					    KEY_MCAST);
530 			key_param_set->key_len =
531 				cpu_to_le16(priv->wep_key[i].key_length);
532 			/* Set WEP key index */
533 			key_param_set->key[0] = i;
534 			/* Set default Tx key flag */
535 			if (i ==
536 			    (priv->
537 			     wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
538 				key_param_set->key[1] = 1;
539 			else
540 				key_param_set->key[1] = 0;
541 			memmove(&key_param_set->key[2],
542 				priv->wep_key[i].key_material,
543 				priv->wep_key[i].key_length);
544 
545 			cur_key_param_len = priv->wep_key[i].key_length +
546 				KEYPARAMSET_WEP_FIXED_LEN +
547 				sizeof(struct mwifiex_ie_types_header);
548 			*key_param_len += (u16) cur_key_param_len;
549 			key_param_set =
550 				(struct mwifiex_ie_type_key_param_set *)
551 						((u8 *)key_param_set +
552 						 cur_key_param_len);
553 		} else if (!priv->wep_key[i].key_length) {
554 			continue;
555 		} else {
556 			mwifiex_dbg(priv->adapter, ERROR,
557 				    "key%d Length = %d is incorrect\n",
558 				    (i + 1), priv->wep_key[i].key_length);
559 			return -1;
560 		}
561 	}
562 
563 	return 0;
564 }
565 
566 /* This function populates key material v2 command
567  * to set network key for AES & CMAC AES.
568  */
mwifiex_set_aes_key_v2(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,struct mwifiex_ds_encrypt_key * enc_key,struct host_cmd_ds_802_11_key_material_v2 * km)569 static int mwifiex_set_aes_key_v2(struct mwifiex_private *priv,
570 				  struct host_cmd_ds_command *cmd,
571 				  struct mwifiex_ds_encrypt_key *enc_key,
572 				  struct host_cmd_ds_802_11_key_material_v2 *km)
573 {
574 	struct mwifiex_adapter *adapter = priv->adapter;
575 	u16 size, len = KEY_PARAMS_FIXED_LEN;
576 
577 	if (enc_key->is_igtk_key) {
578 		mwifiex_dbg(adapter, INFO,
579 			    "%s: Set CMAC AES Key\n", __func__);
580 		if (enc_key->is_rx_seq_valid)
581 			memcpy(km->key_param_set.key_params.cmac_aes.ipn,
582 			       enc_key->pn, enc_key->pn_len);
583 		km->key_param_set.key_info &= cpu_to_le16(~KEY_MCAST);
584 		km->key_param_set.key_info |= cpu_to_le16(KEY_IGTK);
585 		km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC;
586 		km->key_param_set.key_params.cmac_aes.key_len =
587 					  cpu_to_le16(enc_key->key_len);
588 		memcpy(km->key_param_set.key_params.cmac_aes.key,
589 		       enc_key->key_material, enc_key->key_len);
590 		len += sizeof(struct mwifiex_cmac_aes_param);
591 	} else if (enc_key->is_igtk_def_key) {
592 		mwifiex_dbg(adapter, INFO,
593 			    "%s: Set CMAC default Key index\n", __func__);
594 		km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC_DEF;
595 		km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
596 	} else {
597 		mwifiex_dbg(adapter, INFO,
598 			    "%s: Set AES Key\n", __func__);
599 		if (enc_key->is_rx_seq_valid)
600 			memcpy(km->key_param_set.key_params.aes.pn,
601 			       enc_key->pn, enc_key->pn_len);
602 		km->key_param_set.key_type = KEY_TYPE_ID_AES;
603 		km->key_param_set.key_params.aes.key_len =
604 					  cpu_to_le16(enc_key->key_len);
605 		memcpy(km->key_param_set.key_params.aes.key,
606 		       enc_key->key_material, enc_key->key_len);
607 		len += sizeof(struct mwifiex_aes_param);
608 	}
609 
610 	km->key_param_set.len = cpu_to_le16(len);
611 	size = len + sizeof(struct mwifiex_ie_types_header) +
612 	       sizeof(km->action) + S_DS_GEN;
613 	cmd->size = cpu_to_le16(size);
614 
615 	return 0;
616 }
617 
618 /* This function prepares command to set/get/reset network key(s).
619  * This function prepares key material command for V2 format.
620  * Preparation includes -
621  *      - Setting command ID, action and proper size
622  *      - Setting WEP keys, WAPI keys or WPA keys along with required
623  *        encryption (TKIP, AES) (as required)
624  *      - Ensuring correct endian-ness
625  */
626 static int
mwifiex_cmd_802_11_key_material_v2(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,u32 cmd_oid,struct mwifiex_ds_encrypt_key * enc_key)627 mwifiex_cmd_802_11_key_material_v2(struct mwifiex_private *priv,
628 				   struct host_cmd_ds_command *cmd,
629 				   u16 cmd_action, u32 cmd_oid,
630 				   struct mwifiex_ds_encrypt_key *enc_key)
631 {
632 	struct mwifiex_adapter *adapter = priv->adapter;
633 	u8 *mac = enc_key->mac_addr;
634 	u16 key_info, len = KEY_PARAMS_FIXED_LEN;
635 	struct host_cmd_ds_802_11_key_material_v2 *km =
636 						&cmd->params.key_material_v2;
637 
638 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
639 	km->action = cpu_to_le16(cmd_action);
640 
641 	if (cmd_action == HostCmd_ACT_GEN_GET) {
642 		mwifiex_dbg(adapter, INFO, "%s: Get key\n", __func__);
643 		km->key_param_set.key_idx =
644 					enc_key->key_index & KEY_INDEX_MASK;
645 		km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
646 		km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
647 		memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
648 
649 		if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
650 			key_info = KEY_UNICAST;
651 		else
652 			key_info = KEY_MCAST;
653 
654 		if (enc_key->is_igtk_key)
655 			key_info |= KEY_IGTK;
656 
657 		km->key_param_set.key_info = cpu_to_le16(key_info);
658 
659 		cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
660 					S_DS_GEN + KEY_PARAMS_FIXED_LEN +
661 					sizeof(km->action));
662 		return 0;
663 	}
664 
665 	memset(&km->key_param_set, 0,
666 	       sizeof(struct mwifiex_ie_type_key_param_set_v2));
667 
668 	if (enc_key->key_disable) {
669 		mwifiex_dbg(adapter, INFO, "%s: Remove key\n", __func__);
670 		km->action = cpu_to_le16(HostCmd_ACT_GEN_REMOVE);
671 		km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
672 		km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
673 		km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
674 		key_info = KEY_MCAST | KEY_UNICAST;
675 		km->key_param_set.key_info = cpu_to_le16(key_info);
676 		memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
677 		cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
678 					S_DS_GEN + KEY_PARAMS_FIXED_LEN +
679 					sizeof(km->action));
680 		return 0;
681 	}
682 
683 	km->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
684 	km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
685 	km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
686 	key_info = KEY_ENABLED;
687 	memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
688 
689 	if (enc_key->key_len <= WLAN_KEY_LEN_WEP104) {
690 		mwifiex_dbg(adapter, INFO, "%s: Set WEP Key\n", __func__);
691 		len += sizeof(struct mwifiex_wep_param);
692 		km->key_param_set.len = cpu_to_le16(len);
693 		km->key_param_set.key_type = KEY_TYPE_ID_WEP;
694 
695 		if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
696 				key_info |= KEY_MCAST | KEY_UNICAST;
697 		} else {
698 			if (enc_key->is_current_wep_key) {
699 				key_info |= KEY_MCAST | KEY_UNICAST;
700 				if (km->key_param_set.key_idx ==
701 				    (priv->wep_key_curr_index & KEY_INDEX_MASK))
702 					key_info |= KEY_DEFAULT;
703 			} else {
704 				if (is_broadcast_ether_addr(mac))
705 					key_info |= KEY_MCAST;
706 				else
707 					key_info |= KEY_UNICAST | KEY_DEFAULT;
708 			}
709 		}
710 		km->key_param_set.key_info = cpu_to_le16(key_info);
711 
712 		km->key_param_set.key_params.wep.key_len =
713 						  cpu_to_le16(enc_key->key_len);
714 		memcpy(km->key_param_set.key_params.wep.key,
715 		       enc_key->key_material, enc_key->key_len);
716 
717 		cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
718 					len + sizeof(km->action) + S_DS_GEN);
719 		return 0;
720 	}
721 
722 	if (is_broadcast_ether_addr(mac))
723 		key_info |= KEY_MCAST | KEY_RX_KEY;
724 	else
725 		key_info |= KEY_UNICAST | KEY_TX_KEY | KEY_RX_KEY;
726 
727 	if (enc_key->is_wapi_key) {
728 		mwifiex_dbg(adapter, INFO, "%s: Set WAPI Key\n", __func__);
729 		km->key_param_set.key_type = KEY_TYPE_ID_WAPI;
730 		memcpy(km->key_param_set.key_params.wapi.pn, enc_key->pn,
731 		       PN_LEN);
732 		km->key_param_set.key_params.wapi.key_len =
733 						cpu_to_le16(enc_key->key_len);
734 		memcpy(km->key_param_set.key_params.wapi.key,
735 		       enc_key->key_material, enc_key->key_len);
736 		if (is_broadcast_ether_addr(mac))
737 			priv->sec_info.wapi_key_on = true;
738 
739 		if (!priv->sec_info.wapi_key_on)
740 			key_info |= KEY_DEFAULT;
741 		km->key_param_set.key_info = cpu_to_le16(key_info);
742 
743 		len += sizeof(struct mwifiex_wapi_param);
744 		km->key_param_set.len = cpu_to_le16(len);
745 		cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
746 					len + sizeof(km->action) + S_DS_GEN);
747 		return 0;
748 	}
749 
750 	if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
751 		key_info |= KEY_DEFAULT;
752 		/* Enable unicast bit for WPA-NONE/ADHOC_AES */
753 		if (!priv->sec_info.wpa2_enabled &&
754 		    !is_broadcast_ether_addr(mac))
755 			key_info |= KEY_UNICAST;
756 	} else {
757 		/* Enable default key for WPA/WPA2 */
758 		if (!priv->wpa_is_gtk_set)
759 			key_info |= KEY_DEFAULT;
760 	}
761 
762 	km->key_param_set.key_info = cpu_to_le16(key_info);
763 
764 	if (enc_key->key_len == WLAN_KEY_LEN_CCMP)
765 		return mwifiex_set_aes_key_v2(priv, cmd, enc_key, km);
766 
767 	if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
768 		mwifiex_dbg(adapter, INFO,
769 			    "%s: Set TKIP Key\n", __func__);
770 		if (enc_key->is_rx_seq_valid)
771 			memcpy(km->key_param_set.key_params.tkip.pn,
772 			       enc_key->pn, enc_key->pn_len);
773 		km->key_param_set.key_type = KEY_TYPE_ID_TKIP;
774 		km->key_param_set.key_params.tkip.key_len =
775 						cpu_to_le16(enc_key->key_len);
776 		memcpy(km->key_param_set.key_params.tkip.key,
777 		       enc_key->key_material, enc_key->key_len);
778 
779 		len += sizeof(struct mwifiex_tkip_param);
780 		km->key_param_set.len = cpu_to_le16(len);
781 		cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
782 					len + sizeof(km->action) + S_DS_GEN);
783 	}
784 
785 	return 0;
786 }
787 
788 /*
789  * This function prepares command to set/get/reset network key(s).
790  * This function prepares key material command for V1 format.
791  *
792  * Preparation includes -
793  *      - Setting command ID, action and proper size
794  *      - Setting WEP keys, WAPI keys or WPA keys along with required
795  *        encryption (TKIP, AES) (as required)
796  *      - Ensuring correct endian-ness
797  */
798 static int
mwifiex_cmd_802_11_key_material_v1(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,u32 cmd_oid,struct mwifiex_ds_encrypt_key * enc_key)799 mwifiex_cmd_802_11_key_material_v1(struct mwifiex_private *priv,
800 				   struct host_cmd_ds_command *cmd,
801 				   u16 cmd_action, u32 cmd_oid,
802 				   struct mwifiex_ds_encrypt_key *enc_key)
803 {
804 	struct host_cmd_ds_802_11_key_material *key_material =
805 		&cmd->params.key_material;
806 	struct host_cmd_tlv_mac_addr *tlv_mac;
807 	u16 key_param_len = 0, cmd_size;
808 	int ret = 0;
809 
810 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
811 	key_material->action = cpu_to_le16(cmd_action);
812 
813 	if (cmd_action == HostCmd_ACT_GEN_GET) {
814 		cmd->size =
815 			cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
816 		return ret;
817 	}
818 
819 	if (!enc_key) {
820 		struct host_cmd_ds_802_11_key_material_wep *key_material_wep =
821 			(struct host_cmd_ds_802_11_key_material_wep *)key_material;
822 		memset(key_material_wep->key_param_set, 0,
823 		       sizeof(key_material_wep->key_param_set));
824 		ret = mwifiex_set_keyparamset_wep(priv,
825 						  &key_material_wep->key_param_set[0],
826 						  &key_param_len);
827 		cmd->size = cpu_to_le16(key_param_len +
828 				    sizeof(key_material_wep->action) + S_DS_GEN);
829 		return ret;
830 	} else
831 		memset(&key_material->key_param_set, 0,
832 		       sizeof(struct mwifiex_ie_type_key_param_set));
833 	if (enc_key->is_wapi_key) {
834 		struct mwifiex_ie_type_key_param_set *set;
835 
836 		mwifiex_dbg(priv->adapter, INFO, "info: Set WAPI Key\n");
837 		set = &key_material->key_param_set;
838 		set->key_type_id = cpu_to_le16(KEY_TYPE_ID_WAPI);
839 		if (cmd_oid == KEY_INFO_ENABLED)
840 			set->key_info = cpu_to_le16(KEY_ENABLED);
841 		else
842 			set->key_info = cpu_to_le16(!KEY_ENABLED);
843 
844 		set->key[0] = enc_key->key_index;
845 		if (!priv->sec_info.wapi_key_on)
846 			set->key[1] = 1;
847 		else
848 			/* set 0 when re-key */
849 			set->key[1] = 0;
850 
851 		if (!is_broadcast_ether_addr(enc_key->mac_addr)) {
852 			/* WAPI pairwise key: unicast */
853 			set->key_info |= cpu_to_le16(KEY_UNICAST);
854 		} else {	/* WAPI group key: multicast */
855 			set->key_info |= cpu_to_le16(KEY_MCAST);
856 			priv->sec_info.wapi_key_on = true;
857 		}
858 
859 		set->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
860 		set->key_len = cpu_to_le16(WAPI_KEY_LEN);
861 		memcpy(&set->key[2], enc_key->key_material, enc_key->key_len);
862 		memcpy(&set->key[2 + enc_key->key_len], enc_key->pn, PN_LEN);
863 		set->length = cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
864 
865 		key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
866 				 sizeof(struct mwifiex_ie_types_header);
867 		cmd->size = cpu_to_le16(sizeof(key_material->action)
868 					+ S_DS_GEN +  key_param_len);
869 		return ret;
870 	}
871 	if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
872 		if (enc_key->is_igtk_key) {
873 			mwifiex_dbg(priv->adapter, CMD, "cmd: CMAC_AES\n");
874 			key_material->key_param_set.key_type_id =
875 					cpu_to_le16(KEY_TYPE_ID_AES_CMAC);
876 			if (cmd_oid == KEY_INFO_ENABLED)
877 				key_material->key_param_set.key_info =
878 						cpu_to_le16(KEY_ENABLED);
879 			else
880 				key_material->key_param_set.key_info =
881 						cpu_to_le16(!KEY_ENABLED);
882 
883 			key_material->key_param_set.key_info |=
884 							cpu_to_le16(KEY_IGTK);
885 		} else {
886 			mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_AES\n");
887 			key_material->key_param_set.key_type_id =
888 						cpu_to_le16(KEY_TYPE_ID_AES);
889 			if (cmd_oid == KEY_INFO_ENABLED)
890 				key_material->key_param_set.key_info =
891 						cpu_to_le16(KEY_ENABLED);
892 			else
893 				key_material->key_param_set.key_info =
894 						cpu_to_le16(!KEY_ENABLED);
895 
896 			if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
897 				/* AES pairwise key: unicast */
898 				key_material->key_param_set.key_info |=
899 						cpu_to_le16(KEY_UNICAST);
900 			else	/* AES group key: multicast */
901 				key_material->key_param_set.key_info |=
902 							cpu_to_le16(KEY_MCAST);
903 		}
904 	} else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
905 		mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_TKIP\n");
906 		key_material->key_param_set.key_type_id =
907 						cpu_to_le16(KEY_TYPE_ID_TKIP);
908 		key_material->key_param_set.key_info =
909 						cpu_to_le16(KEY_ENABLED);
910 
911 		if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
912 				/* TKIP pairwise key: unicast */
913 			key_material->key_param_set.key_info |=
914 						cpu_to_le16(KEY_UNICAST);
915 		else		/* TKIP group key: multicast */
916 			key_material->key_param_set.key_info |=
917 							cpu_to_le16(KEY_MCAST);
918 	}
919 
920 	if (key_material->key_param_set.key_type_id) {
921 		key_material->key_param_set.type =
922 					cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
923 		key_material->key_param_set.key_len =
924 					cpu_to_le16((u16) enc_key->key_len);
925 		memcpy(key_material->key_param_set.key, enc_key->key_material,
926 		       enc_key->key_len);
927 		key_material->key_param_set.length =
928 			cpu_to_le16((u16) enc_key->key_len +
929 				    KEYPARAMSET_FIXED_LEN);
930 
931 		key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
932 				+ sizeof(struct mwifiex_ie_types_header);
933 
934 		if (le16_to_cpu(key_material->key_param_set.key_type_id) ==
935 							KEY_TYPE_ID_AES_CMAC) {
936 			struct mwifiex_cmac_param *param =
937 					(void *)key_material->key_param_set.key;
938 
939 			memcpy(param->ipn, enc_key->pn, IGTK_PN_LEN);
940 			memcpy(param->key, enc_key->key_material,
941 			       WLAN_KEY_LEN_AES_CMAC);
942 
943 			key_param_len = sizeof(struct mwifiex_cmac_param);
944 			key_material->key_param_set.key_len =
945 						cpu_to_le16(key_param_len);
946 			key_param_len += KEYPARAMSET_FIXED_LEN;
947 			key_material->key_param_set.length =
948 						cpu_to_le16(key_param_len);
949 			key_param_len += sizeof(struct mwifiex_ie_types_header);
950 		}
951 
952 		cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
953 					+ key_param_len);
954 
955 		if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
956 			tlv_mac = (void *)((u8 *)&key_material->key_param_set +
957 					   key_param_len);
958 			tlv_mac->header.type =
959 					cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
960 			tlv_mac->header.len = cpu_to_le16(ETH_ALEN);
961 			memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
962 			cmd_size = key_param_len + S_DS_GEN +
963 				   sizeof(key_material->action) +
964 				   sizeof(struct host_cmd_tlv_mac_addr);
965 		} else {
966 			cmd_size = key_param_len + S_DS_GEN +
967 				   sizeof(key_material->action);
968 		}
969 		cmd->size = cpu_to_le16(cmd_size);
970 	}
971 
972 	return ret;
973 }
974 
975 /* Wrapper function for setting network key depending upon FW KEY API version */
976 static int
mwifiex_cmd_802_11_key_material(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,u32 cmd_oid,struct mwifiex_ds_encrypt_key * enc_key)977 mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
978 				struct host_cmd_ds_command *cmd,
979 				u16 cmd_action, u32 cmd_oid,
980 				struct mwifiex_ds_encrypt_key *enc_key)
981 {
982 	if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
983 		return mwifiex_cmd_802_11_key_material_v2(priv, cmd,
984 							  cmd_action, cmd_oid,
985 							  enc_key);
986 
987 	else
988 		return mwifiex_cmd_802_11_key_material_v1(priv, cmd,
989 							  cmd_action, cmd_oid,
990 							  enc_key);
991 }
992 
993 /*
994  * This function prepares command to set/get 11d domain information.
995  *
996  * Preparation includes -
997  *      - Setting command ID, action and proper size
998  *      - Setting domain information fields (for SET only)
999  *      - Ensuring correct endian-ness
1000  */
mwifiex_cmd_802_11d_domain_info(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action)1001 static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
1002 					   struct host_cmd_ds_command *cmd,
1003 					   u16 cmd_action)
1004 {
1005 	struct mwifiex_adapter *adapter = priv->adapter;
1006 	struct host_cmd_ds_802_11d_domain_info *domain_info =
1007 		&cmd->params.domain_info;
1008 	struct mwifiex_ietypes_domain_param_set *domain =
1009 		&domain_info->domain;
1010 	u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
1011 
1012 	mwifiex_dbg(adapter, INFO,
1013 		    "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
1014 
1015 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
1016 	domain_info->action = cpu_to_le16(cmd_action);
1017 	if (cmd_action == HostCmd_ACT_GEN_GET) {
1018 		cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1019 		return 0;
1020 	}
1021 
1022 	/* Set domain info fields */
1023 	domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
1024 	memcpy(domain->country_code, adapter->domain_reg.country_code,
1025 	       sizeof(domain->country_code));
1026 
1027 	domain->header.len =
1028 		cpu_to_le16((no_of_triplet *
1029 			     sizeof(struct ieee80211_country_ie_triplet))
1030 			    + sizeof(domain->country_code));
1031 
1032 	if (no_of_triplet) {
1033 		memcpy(domain->triplet, adapter->domain_reg.triplet,
1034 		       no_of_triplet * sizeof(struct
1035 					      ieee80211_country_ie_triplet));
1036 
1037 		cmd->size = cpu_to_le16(sizeof(domain_info->action) +
1038 					le16_to_cpu(domain->header.len) +
1039 					sizeof(struct mwifiex_ie_types_header)
1040 					+ S_DS_GEN);
1041 	} else {
1042 		cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1043 	}
1044 
1045 	return 0;
1046 }
1047 
1048 /*
1049  * This function prepares command to set/get IBSS coalescing status.
1050  *
1051  * Preparation includes -
1052  *      - Setting command ID, action and proper size
1053  *      - Setting status to enable or disable (for SET only)
1054  *      - Ensuring correct endian-ness
1055  */
mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command * cmd,u16 cmd_action,u16 * enable)1056 static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
1057 					      u16 cmd_action, u16 *enable)
1058 {
1059 	struct host_cmd_ds_802_11_ibss_status *ibss_coal =
1060 		&(cmd->params.ibss_coalescing);
1061 
1062 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
1063 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
1064 				S_DS_GEN);
1065 	cmd->result = 0;
1066 	ibss_coal->action = cpu_to_le16(cmd_action);
1067 
1068 	switch (cmd_action) {
1069 	case HostCmd_ACT_GEN_SET:
1070 		if (enable)
1071 			ibss_coal->enable = cpu_to_le16(*enable);
1072 		else
1073 			ibss_coal->enable = 0;
1074 		break;
1075 
1076 		/* In other case.. Nothing to do */
1077 	case HostCmd_ACT_GEN_GET:
1078 	default:
1079 		break;
1080 	}
1081 
1082 	return 0;
1083 }
1084 
1085 /* This function prepares command buffer to get/set memory location value.
1086  */
1087 static int
mwifiex_cmd_mem_access(struct host_cmd_ds_command * cmd,u16 cmd_action,void * pdata_buf)1088 mwifiex_cmd_mem_access(struct host_cmd_ds_command *cmd, u16 cmd_action,
1089 		       void *pdata_buf)
1090 {
1091 	struct mwifiex_ds_mem_rw *mem_rw = (void *)pdata_buf;
1092 	struct host_cmd_ds_mem_access *mem_access = (void *)&cmd->params.mem;
1093 
1094 	cmd->command = cpu_to_le16(HostCmd_CMD_MEM_ACCESS);
1095 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mem_access) +
1096 				S_DS_GEN);
1097 
1098 	mem_access->action = cpu_to_le16(cmd_action);
1099 	mem_access->addr = cpu_to_le32(mem_rw->addr);
1100 	mem_access->value = cpu_to_le32(mem_rw->value);
1101 
1102 	return 0;
1103 }
1104 
1105 /*
1106  * This function prepares command to set/get register value.
1107  *
1108  * Preparation includes -
1109  *      - Setting command ID, action and proper size
1110  *      - Setting register offset (for both GET and SET) and
1111  *        register value (for SET only)
1112  *      - Ensuring correct endian-ness
1113  *
1114  * The following type of registers can be accessed with this function -
1115  *      - MAC register
1116  *      - BBP register
1117  *      - RF register
1118  *      - PMIC register
1119  *      - CAU register
1120  *      - EEPROM
1121  */
mwifiex_cmd_reg_access(struct host_cmd_ds_command * cmd,u16 cmd_action,void * data_buf)1122 static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
1123 				  u16 cmd_action, void *data_buf)
1124 {
1125 	struct mwifiex_ds_reg_rw *reg_rw = data_buf;
1126 
1127 	switch (le16_to_cpu(cmd->command)) {
1128 	case HostCmd_CMD_MAC_REG_ACCESS:
1129 	{
1130 		struct host_cmd_ds_mac_reg_access *mac_reg;
1131 
1132 		cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
1133 		mac_reg = &cmd->params.mac_reg;
1134 		mac_reg->action = cpu_to_le16(cmd_action);
1135 		mac_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1136 		mac_reg->value = cpu_to_le32(reg_rw->value);
1137 		break;
1138 	}
1139 	case HostCmd_CMD_BBP_REG_ACCESS:
1140 	{
1141 		struct host_cmd_ds_bbp_reg_access *bbp_reg;
1142 
1143 		cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
1144 		bbp_reg = &cmd->params.bbp_reg;
1145 		bbp_reg->action = cpu_to_le16(cmd_action);
1146 		bbp_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1147 		bbp_reg->value = (u8) reg_rw->value;
1148 		break;
1149 	}
1150 	case HostCmd_CMD_RF_REG_ACCESS:
1151 	{
1152 		struct host_cmd_ds_rf_reg_access *rf_reg;
1153 
1154 		cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
1155 		rf_reg = &cmd->params.rf_reg;
1156 		rf_reg->action = cpu_to_le16(cmd_action);
1157 		rf_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1158 		rf_reg->value = (u8) reg_rw->value;
1159 		break;
1160 	}
1161 	case HostCmd_CMD_PMIC_REG_ACCESS:
1162 	{
1163 		struct host_cmd_ds_pmic_reg_access *pmic_reg;
1164 
1165 		cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
1166 		pmic_reg = &cmd->params.pmic_reg;
1167 		pmic_reg->action = cpu_to_le16(cmd_action);
1168 		pmic_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1169 		pmic_reg->value = (u8) reg_rw->value;
1170 		break;
1171 	}
1172 	case HostCmd_CMD_CAU_REG_ACCESS:
1173 	{
1174 		struct host_cmd_ds_rf_reg_access *cau_reg;
1175 
1176 		cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
1177 		cau_reg = &cmd->params.rf_reg;
1178 		cau_reg->action = cpu_to_le16(cmd_action);
1179 		cau_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1180 		cau_reg->value = (u8) reg_rw->value;
1181 		break;
1182 	}
1183 	case HostCmd_CMD_802_11_EEPROM_ACCESS:
1184 	{
1185 		struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
1186 		struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
1187 			&cmd->params.eeprom;
1188 
1189 		cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
1190 		cmd_eeprom->action = cpu_to_le16(cmd_action);
1191 		cmd_eeprom->offset = cpu_to_le16(rd_eeprom->offset);
1192 		cmd_eeprom->byte_count = cpu_to_le16(rd_eeprom->byte_count);
1193 		cmd_eeprom->value = 0;
1194 		break;
1195 	}
1196 	default:
1197 		return -1;
1198 	}
1199 
1200 	return 0;
1201 }
1202 
1203 /*
1204  * This function prepares command to set PCI-Express
1205  * host buffer configuration
1206  *
1207  * Preparation includes -
1208  *      - Setting command ID, action and proper size
1209  *      - Setting host buffer configuration
1210  *      - Ensuring correct endian-ness
1211  */
1212 static int
mwifiex_cmd_pcie_host_spec(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 action)1213 mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
1214 			   struct host_cmd_ds_command *cmd, u16 action)
1215 {
1216 	struct host_cmd_ds_pcie_details *host_spec =
1217 					&cmd->params.pcie_host_spec;
1218 	struct pcie_service_card *card = priv->adapter->card;
1219 
1220 	cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
1221 	cmd->size = cpu_to_le16(sizeof(struct
1222 					host_cmd_ds_pcie_details) + S_DS_GEN);
1223 	cmd->result = 0;
1224 
1225 	memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
1226 
1227 	if (action != HostCmd_ACT_GEN_SET)
1228 		return 0;
1229 
1230 	/* Send the ring base addresses and count to firmware */
1231 	host_spec->txbd_addr_lo = cpu_to_le32((u32)(card->txbd_ring_pbase));
1232 	host_spec->txbd_addr_hi =
1233 			cpu_to_le32((u32)(((u64)card->txbd_ring_pbase) >> 32));
1234 	host_spec->txbd_count = cpu_to_le32(MWIFIEX_MAX_TXRX_BD);
1235 	host_spec->rxbd_addr_lo = cpu_to_le32((u32)(card->rxbd_ring_pbase));
1236 	host_spec->rxbd_addr_hi =
1237 			cpu_to_le32((u32)(((u64)card->rxbd_ring_pbase) >> 32));
1238 	host_spec->rxbd_count = cpu_to_le32(MWIFIEX_MAX_TXRX_BD);
1239 	host_spec->evtbd_addr_lo = cpu_to_le32((u32)(card->evtbd_ring_pbase));
1240 	host_spec->evtbd_addr_hi =
1241 			cpu_to_le32((u32)(((u64)card->evtbd_ring_pbase) >> 32));
1242 	host_spec->evtbd_count = cpu_to_le32(MWIFIEX_MAX_EVT_BD);
1243 	if (card->sleep_cookie_vbase) {
1244 		host_spec->sleep_cookie_addr_lo =
1245 				cpu_to_le32((u32)(card->sleep_cookie_pbase));
1246 		host_spec->sleep_cookie_addr_hi = cpu_to_le32((u32)(((u64)
1247 					(card->sleep_cookie_pbase)) >> 32));
1248 		mwifiex_dbg(priv->adapter, INFO,
1249 			    "sleep_cook_lo phy addr: 0x%x\n",
1250 			    host_spec->sleep_cookie_addr_lo);
1251 	}
1252 
1253 	return 0;
1254 }
1255 
1256 /*
1257  * This function prepares command for event subscription, configuration
1258  * and query. Events can be subscribed or unsubscribed. Current subscribed
1259  * events can be queried. Also, current subscribed events are reported in
1260  * every FW response.
1261  */
1262 static int
mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,struct mwifiex_ds_misc_subsc_evt * subsc_evt_cfg)1263 mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
1264 			     struct host_cmd_ds_command *cmd,
1265 			     struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
1266 {
1267 	struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
1268 	struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
1269 	u16 event_bitmap;
1270 	u8 *pos;
1271 
1272 	cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
1273 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
1274 				S_DS_GEN);
1275 
1276 	subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
1277 	mwifiex_dbg(priv->adapter, CMD,
1278 		    "cmd: action: %d\n", subsc_evt_cfg->action);
1279 
1280 	/*For query requests, no configuration TLV structures are to be added.*/
1281 	if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
1282 		return 0;
1283 
1284 	subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
1285 
1286 	event_bitmap = subsc_evt_cfg->events;
1287 	mwifiex_dbg(priv->adapter, CMD, "cmd: event bitmap : %16x\n",
1288 		    event_bitmap);
1289 
1290 	if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
1291 	     (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
1292 	    (event_bitmap == 0)) {
1293 		mwifiex_dbg(priv->adapter, ERROR,
1294 			    "Error: No event specified\t"
1295 			    "for bitwise action type\n");
1296 		return -EINVAL;
1297 	}
1298 
1299 	/*
1300 	 * Append TLV structures for each of the specified events for
1301 	 * subscribing or re-configuring. This is not required for
1302 	 * bitwise unsubscribing request.
1303 	 */
1304 	if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
1305 		return 0;
1306 
1307 	pos = ((u8 *)subsc_evt) +
1308 			sizeof(struct host_cmd_ds_802_11_subsc_evt);
1309 
1310 	if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
1311 		rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1312 
1313 		rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
1314 		rssi_tlv->header.len =
1315 		    cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1316 				sizeof(struct mwifiex_ie_types_header));
1317 		rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
1318 		rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
1319 
1320 		mwifiex_dbg(priv->adapter, EVENT,
1321 			    "Cfg Beacon Low Rssi event,\t"
1322 			    "RSSI:-%d dBm, Freq:%d\n",
1323 			    subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
1324 			    subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
1325 
1326 		pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1327 		le16_unaligned_add_cpu(&cmd->size,
1328 				       sizeof(
1329 				       struct mwifiex_ie_types_rssi_threshold));
1330 	}
1331 
1332 	if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
1333 		rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1334 
1335 		rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1336 		rssi_tlv->header.len =
1337 		    cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1338 				sizeof(struct mwifiex_ie_types_header));
1339 		rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
1340 		rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
1341 
1342 		mwifiex_dbg(priv->adapter, EVENT,
1343 			    "Cfg Beacon High Rssi event,\t"
1344 			    "RSSI:-%d dBm, Freq:%d\n",
1345 			    subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
1346 			    subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
1347 
1348 		pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1349 		le16_unaligned_add_cpu(&cmd->size,
1350 				       sizeof(
1351 				       struct mwifiex_ie_types_rssi_threshold));
1352 	}
1353 
1354 	return 0;
1355 }
1356 
1357 static int
mwifiex_cmd_append_rpn_expression(struct mwifiex_private * priv,struct mwifiex_mef_entry * mef_entry,u8 ** buffer)1358 mwifiex_cmd_append_rpn_expression(struct mwifiex_private *priv,
1359 				  struct mwifiex_mef_entry *mef_entry,
1360 				  u8 **buffer)
1361 {
1362 	struct mwifiex_mef_filter *filter = mef_entry->filter;
1363 	int i, byte_len;
1364 	u8 *stack_ptr = *buffer;
1365 
1366 	for (i = 0; i < MWIFIEX_MEF_MAX_FILTERS; i++) {
1367 		filter = &mef_entry->filter[i];
1368 		if (!filter->filt_type)
1369 			break;
1370 		put_unaligned_le32((u32)filter->repeat, stack_ptr);
1371 		stack_ptr += 4;
1372 		*stack_ptr = TYPE_DNUM;
1373 		stack_ptr += 1;
1374 
1375 		byte_len = filter->byte_seq[MWIFIEX_MEF_MAX_BYTESEQ];
1376 		memcpy(stack_ptr, filter->byte_seq, byte_len);
1377 		stack_ptr += byte_len;
1378 		*stack_ptr = byte_len;
1379 		stack_ptr += 1;
1380 		*stack_ptr = TYPE_BYTESEQ;
1381 		stack_ptr += 1;
1382 		put_unaligned_le32((u32)filter->offset, stack_ptr);
1383 		stack_ptr += 4;
1384 		*stack_ptr = TYPE_DNUM;
1385 		stack_ptr += 1;
1386 
1387 		*stack_ptr = filter->filt_type;
1388 		stack_ptr += 1;
1389 
1390 		if (filter->filt_action) {
1391 			*stack_ptr = filter->filt_action;
1392 			stack_ptr += 1;
1393 		}
1394 
1395 		if (stack_ptr - *buffer > STACK_NBYTES)
1396 			return -1;
1397 	}
1398 
1399 	*buffer = stack_ptr;
1400 	return 0;
1401 }
1402 
1403 static int
mwifiex_cmd_mef_cfg(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,struct mwifiex_ds_mef_cfg * mef)1404 mwifiex_cmd_mef_cfg(struct mwifiex_private *priv,
1405 		    struct host_cmd_ds_command *cmd,
1406 		    struct mwifiex_ds_mef_cfg *mef)
1407 {
1408 	struct host_cmd_ds_mef_cfg *mef_cfg = &cmd->params.mef_cfg;
1409 	struct mwifiex_fw_mef_entry *mef_entry = NULL;
1410 	u8 *pos = (u8 *)mef_cfg;
1411 	u16 i;
1412 
1413 	cmd->command = cpu_to_le16(HostCmd_CMD_MEF_CFG);
1414 
1415 	mef_cfg->criteria = cpu_to_le32(mef->criteria);
1416 	mef_cfg->num_entries = cpu_to_le16(mef->num_entries);
1417 	pos += sizeof(*mef_cfg);
1418 
1419 	for (i = 0; i < mef->num_entries; i++) {
1420 		mef_entry = (struct mwifiex_fw_mef_entry *)pos;
1421 		mef_entry->mode = mef->mef_entry[i].mode;
1422 		mef_entry->action = mef->mef_entry[i].action;
1423 		pos += sizeof(*mef_entry);
1424 
1425 		if (mwifiex_cmd_append_rpn_expression(priv,
1426 						      &mef->mef_entry[i], &pos))
1427 			return -1;
1428 
1429 		mef_entry->exprsize =
1430 			cpu_to_le16(pos - mef_entry->expr);
1431 	}
1432 	cmd->size = cpu_to_le16((u16) (pos - (u8 *)mef_cfg) + S_DS_GEN);
1433 
1434 	return 0;
1435 }
1436 
1437 /* This function parse cal data from ASCII to hex */
mwifiex_parse_cal_cfg(u8 * src,size_t len,u8 * dst)1438 static u32 mwifiex_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
1439 {
1440 	u8 *s = src, *d = dst;
1441 
1442 	while (s - src < len) {
1443 		if (*s && (isspace(*s) || *s == '\t')) {
1444 			s++;
1445 			continue;
1446 		}
1447 		if (isxdigit(*s)) {
1448 			*d++ = simple_strtol(s, NULL, 16);
1449 			s += 2;
1450 		} else {
1451 			s++;
1452 		}
1453 	}
1454 
1455 	return d - dst;
1456 }
1457 
mwifiex_dnld_dt_cfgdata(struct mwifiex_private * priv,struct device_node * node,const char * prefix)1458 int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv,
1459 			    struct device_node *node, const char *prefix)
1460 {
1461 #ifdef CONFIG_OF
1462 	struct property *prop;
1463 	size_t len = strlen(prefix);
1464 	int ret;
1465 
1466 	/* look for all matching property names */
1467 	for_each_property_of_node(node, prop) {
1468 		if (len > strlen(prop->name) ||
1469 		    strncmp(prop->name, prefix, len))
1470 			continue;
1471 
1472 		/* property header is 6 bytes, data must fit in cmd buffer */
1473 		if (prop->value && prop->length > 6 &&
1474 		    prop->length <= MWIFIEX_SIZE_OF_CMD_BUFFER - S_DS_GEN) {
1475 			ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
1476 					       HostCmd_ACT_GEN_SET, 0,
1477 					       prop, true);
1478 			if (ret)
1479 				return ret;
1480 		}
1481 	}
1482 #endif
1483 	return 0;
1484 }
1485 
1486 /* This function prepares command of set_cfg_data. */
mwifiex_cmd_cfg_data(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,void * data_buf)1487 static int mwifiex_cmd_cfg_data(struct mwifiex_private *priv,
1488 				struct host_cmd_ds_command *cmd, void *data_buf)
1489 {
1490 	struct mwifiex_adapter *adapter = priv->adapter;
1491 	struct property *prop = data_buf;
1492 	u32 len;
1493 	u8 *data = (u8 *)cmd + S_DS_GEN;
1494 	int ret;
1495 	struct host_cmd_ds_802_11_cfg_data *pcfg_data;
1496 
1497 	if (prop) {
1498 		len = prop->length;
1499 		ret = of_property_read_u8_array(adapter->dt_node, prop->name,
1500 						data, len);
1501 		if (ret)
1502 			return ret;
1503 
1504 		cmd->size = cpu_to_le16(S_DS_GEN + len);
1505 		mwifiex_dbg(adapter, INFO,
1506 			    "download cfg_data from device tree: %s\n",
1507 			    prop->name);
1508 	} else if (adapter->cal_data->data && adapter->cal_data->size > 0) {
1509 		len = mwifiex_parse_cal_cfg((u8 *)adapter->cal_data->data,
1510 					    adapter->cal_data->size,
1511 					    data + sizeof(*pcfg_data));
1512 		pcfg_data = &cmd->params.cfg_data;
1513 		pcfg_data->action = cpu_to_le16(HOST_CMD_ACT_GEN_SET);
1514 		pcfg_data->type = cpu_to_le16(MWIFIEX_CFG_TYPE_CAL);
1515 		pcfg_data->data_len = cpu_to_le16(len);
1516 		cmd->size = cpu_to_le16(S_DS_GEN + sizeof(*pcfg_data) + len);
1517 		mwifiex_dbg(adapter, INFO,
1518 			    "download cfg_data from config file\n");
1519 	} else {
1520 		return -1;
1521 	}
1522 
1523 	cmd->command = cpu_to_le16(HostCmd_CMD_CFG_DATA);
1524 
1525 	return 0;
1526 }
1527 
1528 static int
mwifiex_cmd_set_mc_policy(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,void * data_buf)1529 mwifiex_cmd_set_mc_policy(struct mwifiex_private *priv,
1530 			  struct host_cmd_ds_command *cmd,
1531 			  u16 cmd_action, void *data_buf)
1532 {
1533 	struct host_cmd_ds_multi_chan_policy *mc_pol = &cmd->params.mc_policy;
1534 	const u16 *drcs_info = data_buf;
1535 
1536 	mc_pol->action = cpu_to_le16(cmd_action);
1537 	mc_pol->policy = cpu_to_le16(*drcs_info);
1538 	cmd->command = cpu_to_le16(HostCmd_CMD_MC_POLICY);
1539 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_multi_chan_policy) +
1540 				S_DS_GEN);
1541 	return 0;
1542 }
1543 
mwifiex_cmd_robust_coex(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,bool * is_timeshare)1544 static int mwifiex_cmd_robust_coex(struct mwifiex_private *priv,
1545 				   struct host_cmd_ds_command *cmd,
1546 				   u16 cmd_action, bool *is_timeshare)
1547 {
1548 	struct host_cmd_ds_robust_coex *coex = &cmd->params.coex;
1549 	struct mwifiex_ie_types_robust_coex *coex_tlv;
1550 
1551 	cmd->command = cpu_to_le16(HostCmd_CMD_ROBUST_COEX);
1552 	cmd->size = cpu_to_le16(sizeof(*coex) + sizeof(*coex_tlv) + S_DS_GEN);
1553 
1554 	coex->action = cpu_to_le16(cmd_action);
1555 	coex_tlv = (struct mwifiex_ie_types_robust_coex *)
1556 				((u8 *)coex + sizeof(*coex));
1557 	coex_tlv->header.type = cpu_to_le16(TLV_TYPE_ROBUST_COEX);
1558 	coex_tlv->header.len = cpu_to_le16(sizeof(coex_tlv->mode));
1559 
1560 	if (coex->action == HostCmd_ACT_GEN_GET)
1561 		return 0;
1562 
1563 	if (*is_timeshare)
1564 		coex_tlv->mode = cpu_to_le32(MWIFIEX_COEX_MODE_TIMESHARE);
1565 	else
1566 		coex_tlv->mode = cpu_to_le32(MWIFIEX_COEX_MODE_SPATIAL);
1567 
1568 	return 0;
1569 }
1570 
mwifiex_cmd_gtk_rekey_offload(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,struct cfg80211_gtk_rekey_data * data)1571 static int mwifiex_cmd_gtk_rekey_offload(struct mwifiex_private *priv,
1572 					 struct host_cmd_ds_command *cmd,
1573 					 u16 cmd_action,
1574 					 struct cfg80211_gtk_rekey_data *data)
1575 {
1576 	struct host_cmd_ds_gtk_rekey_params *rekey = &cmd->params.rekey;
1577 	u64 rekey_ctr;
1578 
1579 	cmd->command = cpu_to_le16(HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG);
1580 	cmd->size = cpu_to_le16(sizeof(*rekey) + S_DS_GEN);
1581 
1582 	rekey->action = cpu_to_le16(cmd_action);
1583 	if (cmd_action == HostCmd_ACT_GEN_SET) {
1584 		memcpy(rekey->kek, data->kek, NL80211_KEK_LEN);
1585 		memcpy(rekey->kck, data->kck, NL80211_KCK_LEN);
1586 		rekey_ctr = be64_to_cpup((__be64 *)data->replay_ctr);
1587 		rekey->replay_ctr_low = cpu_to_le32((u32)rekey_ctr);
1588 		rekey->replay_ctr_high =
1589 			cpu_to_le32((u32)((u64)rekey_ctr >> 32));
1590 	}
1591 
1592 	return 0;
1593 }
1594 
mwifiex_cmd_chan_region_cfg(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action)1595 static int mwifiex_cmd_chan_region_cfg(struct mwifiex_private *priv,
1596 				       struct host_cmd_ds_command *cmd,
1597 				       u16 cmd_action)
1598 {
1599 	struct host_cmd_ds_chan_region_cfg *reg = &cmd->params.reg_cfg;
1600 
1601 	cmd->command = cpu_to_le16(HostCmd_CMD_CHAN_REGION_CFG);
1602 	cmd->size = cpu_to_le16(sizeof(*reg) + S_DS_GEN);
1603 
1604 	if (cmd_action == HostCmd_ACT_GEN_GET)
1605 		reg->action = cpu_to_le16(cmd_action);
1606 
1607 	return 0;
1608 }
1609 
1610 static int
mwifiex_cmd_coalesce_cfg(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,void * data_buf)1611 mwifiex_cmd_coalesce_cfg(struct mwifiex_private *priv,
1612 			 struct host_cmd_ds_command *cmd,
1613 			 u16 cmd_action, void *data_buf)
1614 {
1615 	struct host_cmd_ds_coalesce_cfg *coalesce_cfg =
1616 						&cmd->params.coalesce_cfg;
1617 	struct mwifiex_ds_coalesce_cfg *cfg = data_buf;
1618 	struct coalesce_filt_field_param *param;
1619 	u16 cnt, idx, length;
1620 	struct coalesce_receive_filt_rule *rule;
1621 
1622 	cmd->command = cpu_to_le16(HostCmd_CMD_COALESCE_CFG);
1623 	cmd->size = cpu_to_le16(S_DS_GEN);
1624 
1625 	coalesce_cfg->action = cpu_to_le16(cmd_action);
1626 	coalesce_cfg->num_of_rules = cpu_to_le16(cfg->num_of_rules);
1627 	rule = (void *)coalesce_cfg->rule_data;
1628 
1629 	for (cnt = 0; cnt < cfg->num_of_rules; cnt++) {
1630 		rule->header.type = cpu_to_le16(TLV_TYPE_COALESCE_RULE);
1631 		rule->max_coalescing_delay =
1632 			cpu_to_le16(cfg->rule[cnt].max_coalescing_delay);
1633 		rule->pkt_type = cfg->rule[cnt].pkt_type;
1634 		rule->num_of_fields = cfg->rule[cnt].num_of_fields;
1635 
1636 		length = 0;
1637 
1638 		param = rule->params;
1639 		for (idx = 0; idx < cfg->rule[cnt].num_of_fields; idx++) {
1640 			param->operation = cfg->rule[cnt].params[idx].operation;
1641 			param->operand_len =
1642 					cfg->rule[cnt].params[idx].operand_len;
1643 			param->offset =
1644 				cpu_to_le16(cfg->rule[cnt].params[idx].offset);
1645 			memcpy(param->operand_byte_stream,
1646 			       cfg->rule[cnt].params[idx].operand_byte_stream,
1647 			       param->operand_len);
1648 
1649 			length += sizeof(struct coalesce_filt_field_param);
1650 
1651 			param++;
1652 		}
1653 
1654 		/* Total rule length is sizeof max_coalescing_delay(u16),
1655 		 * num_of_fields(u8), pkt_type(u8) and total length of the all
1656 		 * params
1657 		 */
1658 		rule->header.len = cpu_to_le16(length + sizeof(u16) +
1659 					       sizeof(u8) + sizeof(u8));
1660 
1661 		/* Add the rule length to the command size*/
1662 		le16_unaligned_add_cpu(&cmd->size,
1663 				       le16_to_cpu(rule->header.len) +
1664 				       sizeof(struct mwifiex_ie_types_header));
1665 
1666 		rule = (void *)((u8 *)rule->params + length);
1667 	}
1668 
1669 	/* Add sizeof action, num_of_rules to total command length */
1670 	le16_unaligned_add_cpu(&cmd->size, sizeof(u16) + sizeof(u16));
1671 
1672 	return 0;
1673 }
1674 
1675 static int
mwifiex_cmd_tdls_config(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,u16 cmd_action,void * data_buf)1676 mwifiex_cmd_tdls_config(struct mwifiex_private *priv,
1677 			struct host_cmd_ds_command *cmd,
1678 			u16 cmd_action, void *data_buf)
1679 {
1680 	struct host_cmd_ds_tdls_config *tdls_config = &cmd->params.tdls_config;
1681 	struct mwifiex_tdls_init_cs_params *config;
1682 	struct mwifiex_tdls_config *init_config;
1683 	u16 len;
1684 
1685 	cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_CONFIG);
1686 	cmd->size = cpu_to_le16(S_DS_GEN);
1687 	tdls_config->tdls_action = cpu_to_le16(cmd_action);
1688 	le16_unaligned_add_cpu(&cmd->size, sizeof(tdls_config->tdls_action));
1689 
1690 	switch (cmd_action) {
1691 	case ACT_TDLS_CS_ENABLE_CONFIG:
1692 		init_config = data_buf;
1693 		len = sizeof(*init_config);
1694 		memcpy(tdls_config->tdls_data, init_config, len);
1695 		break;
1696 	case ACT_TDLS_CS_INIT:
1697 		config = data_buf;
1698 		len = sizeof(*config);
1699 		memcpy(tdls_config->tdls_data, config, len);
1700 		break;
1701 	case ACT_TDLS_CS_STOP:
1702 		len = sizeof(struct mwifiex_tdls_stop_cs_params);
1703 		memcpy(tdls_config->tdls_data, data_buf, len);
1704 		break;
1705 	case ACT_TDLS_CS_PARAMS:
1706 		len = sizeof(struct mwifiex_tdls_config_cs_params);
1707 		memcpy(tdls_config->tdls_data, data_buf, len);
1708 		break;
1709 	default:
1710 		mwifiex_dbg(priv->adapter, ERROR,
1711 			    "Unknown TDLS configuration\n");
1712 		return -EOPNOTSUPP;
1713 	}
1714 
1715 	le16_unaligned_add_cpu(&cmd->size, len);
1716 	return 0;
1717 }
1718 
1719 static int
mwifiex_cmd_tdls_oper(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd,void * data_buf)1720 mwifiex_cmd_tdls_oper(struct mwifiex_private *priv,
1721 		      struct host_cmd_ds_command *cmd,
1722 		      void *data_buf)
1723 {
1724 	struct host_cmd_ds_tdls_oper *tdls_oper = &cmd->params.tdls_oper;
1725 	struct mwifiex_ds_tdls_oper *oper = data_buf;
1726 	struct host_cmd_tlv_rates *tlv_rates;
1727 	struct mwifiex_ie_types_htcap *ht_capab;
1728 	struct mwifiex_ie_types_qos_info *wmm_qos_info;
1729 	struct mwifiex_ie_types_extcap *extcap;
1730 	struct mwifiex_ie_types_vhtcap *vht_capab;
1731 	struct mwifiex_ie_types_aid *aid;
1732 	struct mwifiex_ie_types_tdls_idle_timeout *timeout;
1733 	u8 *pos;
1734 	u16 config_len = 0;
1735 	struct station_parameters *params = priv->sta_params;
1736 
1737 	cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_OPER);
1738 	cmd->size = cpu_to_le16(S_DS_GEN);
1739 	le16_unaligned_add_cpu(&cmd->size,
1740 			       sizeof(struct host_cmd_ds_tdls_oper));
1741 
1742 	tdls_oper->reason = 0;
1743 	memcpy(tdls_oper->peer_mac, oper->peer_mac, ETH_ALEN);
1744 
1745 	pos = (u8 *)tdls_oper + sizeof(struct host_cmd_ds_tdls_oper);
1746 
1747 	switch (oper->tdls_action) {
1748 	case MWIFIEX_TDLS_DISABLE_LINK:
1749 		tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_DELETE);
1750 		break;
1751 	case MWIFIEX_TDLS_CREATE_LINK:
1752 		tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CREATE);
1753 		break;
1754 	case MWIFIEX_TDLS_CONFIG_LINK:
1755 		tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CONFIG);
1756 
1757 		if (!params) {
1758 			mwifiex_dbg(priv->adapter, ERROR,
1759 				    "TDLS config params not available for %pM\n",
1760 				    oper->peer_mac);
1761 			return -ENODATA;
1762 		}
1763 
1764 		put_unaligned_le16(params->capability, pos);
1765 		config_len += sizeof(params->capability);
1766 
1767 		wmm_qos_info = (void *)(pos + config_len);
1768 		wmm_qos_info->header.type = cpu_to_le16(WLAN_EID_QOS_CAPA);
1769 		wmm_qos_info->header.len =
1770 				cpu_to_le16(sizeof(wmm_qos_info->qos_info));
1771 		wmm_qos_info->qos_info = 0;
1772 		config_len += sizeof(struct mwifiex_ie_types_qos_info);
1773 
1774 		if (params->link_sta_params.ht_capa) {
1775 			ht_capab = (struct mwifiex_ie_types_htcap *)(pos +
1776 								    config_len);
1777 			ht_capab->header.type =
1778 					    cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1779 			ht_capab->header.len =
1780 				   cpu_to_le16(sizeof(struct ieee80211_ht_cap));
1781 			memcpy(&ht_capab->ht_cap, params->link_sta_params.ht_capa,
1782 			       sizeof(struct ieee80211_ht_cap));
1783 			config_len += sizeof(struct mwifiex_ie_types_htcap);
1784 		}
1785 
1786 		if (params->link_sta_params.supported_rates &&
1787 		    params->link_sta_params.supported_rates_len) {
1788 			tlv_rates = (struct host_cmd_tlv_rates *)(pos +
1789 								  config_len);
1790 			tlv_rates->header.type =
1791 					       cpu_to_le16(WLAN_EID_SUPP_RATES);
1792 			tlv_rates->header.len =
1793 				       cpu_to_le16(params->link_sta_params.supported_rates_len);
1794 			memcpy(tlv_rates->rates,
1795 			       params->link_sta_params.supported_rates,
1796 			       params->link_sta_params.supported_rates_len);
1797 			config_len += sizeof(struct host_cmd_tlv_rates) +
1798 				      params->link_sta_params.supported_rates_len;
1799 		}
1800 
1801 		if (params->ext_capab && params->ext_capab_len) {
1802 			extcap = (struct mwifiex_ie_types_extcap *)(pos +
1803 								    config_len);
1804 			extcap->header.type =
1805 					   cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
1806 			extcap->header.len = cpu_to_le16(params->ext_capab_len);
1807 			memcpy(extcap->ext_capab, params->ext_capab,
1808 			       params->ext_capab_len);
1809 			config_len += sizeof(struct mwifiex_ie_types_extcap) +
1810 				      params->ext_capab_len;
1811 		}
1812 		if (params->link_sta_params.vht_capa) {
1813 			vht_capab = (struct mwifiex_ie_types_vhtcap *)(pos +
1814 								    config_len);
1815 			vht_capab->header.type =
1816 					   cpu_to_le16(WLAN_EID_VHT_CAPABILITY);
1817 			vht_capab->header.len =
1818 				  cpu_to_le16(sizeof(struct ieee80211_vht_cap));
1819 			memcpy(&vht_capab->vht_cap, params->link_sta_params.vht_capa,
1820 			       sizeof(struct ieee80211_vht_cap));
1821 			config_len += sizeof(struct mwifiex_ie_types_vhtcap);
1822 		}
1823 		if (params->aid) {
1824 			aid = (struct mwifiex_ie_types_aid *)(pos + config_len);
1825 			aid->header.type = cpu_to_le16(WLAN_EID_AID);
1826 			aid->header.len = cpu_to_le16(sizeof(params->aid));
1827 			aid->aid = cpu_to_le16(params->aid);
1828 			config_len += sizeof(struct mwifiex_ie_types_aid);
1829 		}
1830 
1831 		timeout = (void *)(pos + config_len);
1832 		timeout->header.type = cpu_to_le16(TLV_TYPE_TDLS_IDLE_TIMEOUT);
1833 		timeout->header.len = cpu_to_le16(sizeof(timeout->value));
1834 		timeout->value = cpu_to_le16(MWIFIEX_TDLS_IDLE_TIMEOUT_IN_SEC);
1835 		config_len += sizeof(struct mwifiex_ie_types_tdls_idle_timeout);
1836 
1837 		break;
1838 	default:
1839 		mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS operation\n");
1840 		return -EOPNOTSUPP;
1841 	}
1842 
1843 	le16_unaligned_add_cpu(&cmd->size, config_len);
1844 
1845 	return 0;
1846 }
1847 
1848 /* This function prepares command of sdio rx aggr info. */
mwifiex_cmd_sdio_rx_aggr_cfg(struct host_cmd_ds_command * cmd,u16 cmd_action,void * data_buf)1849 static int mwifiex_cmd_sdio_rx_aggr_cfg(struct host_cmd_ds_command *cmd,
1850 					u16 cmd_action, void *data_buf)
1851 {
1852 	struct host_cmd_sdio_sp_rx_aggr_cfg *cfg =
1853 					&cmd->params.sdio_rx_aggr_cfg;
1854 
1855 	cmd->command = cpu_to_le16(HostCmd_CMD_SDIO_SP_RX_AGGR_CFG);
1856 	cmd->size =
1857 		cpu_to_le16(sizeof(struct host_cmd_sdio_sp_rx_aggr_cfg) +
1858 			    S_DS_GEN);
1859 	cfg->action = cmd_action;
1860 	if (cmd_action == HostCmd_ACT_GEN_SET)
1861 		cfg->enable = *(u8 *)data_buf;
1862 
1863 	return 0;
1864 }
1865 
1866 /* This function prepares command to get HS wakeup reason.
1867  *
1868  * Preparation includes -
1869  *      - Setting command ID, action and proper size
1870  *      - Ensuring correct endian-ness
1871  */
mwifiex_cmd_get_wakeup_reason(struct mwifiex_private * priv,struct host_cmd_ds_command * cmd)1872 static int mwifiex_cmd_get_wakeup_reason(struct mwifiex_private *priv,
1873 					 struct host_cmd_ds_command *cmd)
1874 {
1875 	cmd->command = cpu_to_le16(HostCmd_CMD_HS_WAKEUP_REASON);
1876 	cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_wakeup_reason) +
1877 				S_DS_GEN);
1878 
1879 	return 0;
1880 }
1881 
mwifiex_cmd_get_chan_info(struct host_cmd_ds_command * cmd,u16 cmd_action)1882 static int mwifiex_cmd_get_chan_info(struct host_cmd_ds_command *cmd,
1883 				     u16 cmd_action)
1884 {
1885 	struct host_cmd_ds_sta_configure *sta_cfg_cmd = &cmd->params.sta_cfg;
1886 	struct host_cmd_tlv_channel_band *tlv_band_channel =
1887 	(struct host_cmd_tlv_channel_band *)sta_cfg_cmd->tlv_buffer;
1888 
1889 	cmd->command = cpu_to_le16(HostCmd_CMD_STA_CONFIGURE);
1890 	cmd->size = cpu_to_le16(sizeof(*sta_cfg_cmd) +
1891 				sizeof(*tlv_band_channel) + S_DS_GEN);
1892 	sta_cfg_cmd->action = cpu_to_le16(cmd_action);
1893 	memset(tlv_band_channel, 0, sizeof(*tlv_band_channel));
1894 	tlv_band_channel->header.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
1895 	tlv_band_channel->header.len  = cpu_to_le16(sizeof(*tlv_band_channel) -
1896 					sizeof(struct mwifiex_ie_types_header));
1897 
1898 	return 0;
1899 }
1900 
1901 /* This function check if the command is supported by firmware */
mwifiex_is_cmd_supported(struct mwifiex_private * priv,u16 cmd_no)1902 static int mwifiex_is_cmd_supported(struct mwifiex_private *priv, u16 cmd_no)
1903 {
1904 	if (!ISSUPP_ADHOC_ENABLED(priv->adapter->fw_cap_info)) {
1905 		switch (cmd_no) {
1906 		case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
1907 		case HostCmd_CMD_802_11_AD_HOC_START:
1908 		case HostCmd_CMD_802_11_AD_HOC_JOIN:
1909 		case HostCmd_CMD_802_11_AD_HOC_STOP:
1910 			return -EOPNOTSUPP;
1911 		default:
1912 			break;
1913 		}
1914 	}
1915 
1916 	return 0;
1917 }
1918 
1919 /*
1920  * This function prepares the commands before sending them to the firmware.
1921  *
1922  * This is a generic function which calls specific command preparation
1923  * routines based upon the command number.
1924  */
mwifiex_sta_prepare_cmd(struct mwifiex_private * priv,uint16_t cmd_no,u16 cmd_action,u32 cmd_oid,void * data_buf,void * cmd_buf)1925 int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1926 			    u16 cmd_action, u32 cmd_oid,
1927 			    void *data_buf, void *cmd_buf)
1928 {
1929 	struct host_cmd_ds_command *cmd_ptr = cmd_buf;
1930 	int ret = 0;
1931 
1932 	if (mwifiex_is_cmd_supported(priv, cmd_no)) {
1933 		mwifiex_dbg(priv->adapter, ERROR,
1934 			    "0x%x command not supported by firmware\n",
1935 			    cmd_no);
1936 		return -EOPNOTSUPP;
1937 	}
1938 
1939 	/* Prepare command */
1940 	switch (cmd_no) {
1941 	case HostCmd_CMD_GET_HW_SPEC:
1942 		ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
1943 		break;
1944 	case HostCmd_CMD_CFG_DATA:
1945 		ret = mwifiex_cmd_cfg_data(priv, cmd_ptr, data_buf);
1946 		break;
1947 	case HostCmd_CMD_MAC_CONTROL:
1948 		ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
1949 					      data_buf);
1950 		break;
1951 	case HostCmd_CMD_802_11_MAC_ADDRESS:
1952 		ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
1953 						     cmd_action);
1954 		break;
1955 	case HostCmd_CMD_MAC_MULTICAST_ADR:
1956 		ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
1957 						    data_buf);
1958 		break;
1959 	case HostCmd_CMD_TX_RATE_CFG:
1960 		ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
1961 					      data_buf);
1962 		break;
1963 	case HostCmd_CMD_TXPWR_CFG:
1964 		ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
1965 					       data_buf);
1966 		break;
1967 	case HostCmd_CMD_RF_TX_PWR:
1968 		ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
1969 					      data_buf);
1970 		break;
1971 	case HostCmd_CMD_RF_ANTENNA:
1972 		ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
1973 					     data_buf);
1974 		break;
1975 	case HostCmd_CMD_802_11_PS_MODE_ENH:
1976 		ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
1977 						 (uint16_t)cmd_oid, data_buf);
1978 		break;
1979 	case HostCmd_CMD_802_11_HS_CFG_ENH:
1980 		ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
1981 				(struct mwifiex_hs_config_param *) data_buf);
1982 		break;
1983 	case HostCmd_CMD_802_11_SCAN:
1984 		ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
1985 		break;
1986 	case HostCmd_CMD_802_11_BG_SCAN_CONFIG:
1987 		ret = mwifiex_cmd_802_11_bg_scan_config(priv, cmd_ptr,
1988 							data_buf);
1989 		break;
1990 	case HostCmd_CMD_802_11_BG_SCAN_QUERY:
1991 		ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
1992 		break;
1993 	case HostCmd_CMD_802_11_ASSOCIATE:
1994 		ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
1995 		break;
1996 	case HostCmd_CMD_802_11_DEAUTHENTICATE:
1997 		ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
1998 							data_buf);
1999 		break;
2000 	case HostCmd_CMD_802_11_AD_HOC_START:
2001 		ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
2002 						      data_buf);
2003 		break;
2004 	case HostCmd_CMD_802_11_GET_LOG:
2005 		ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
2006 		break;
2007 	case HostCmd_CMD_802_11_AD_HOC_JOIN:
2008 		ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
2009 						     data_buf);
2010 		break;
2011 	case HostCmd_CMD_802_11_AD_HOC_STOP:
2012 		ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
2013 		break;
2014 	case HostCmd_CMD_RSSI_INFO:
2015 		ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
2016 		break;
2017 	case HostCmd_CMD_802_11_SNMP_MIB:
2018 		ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
2019 						  cmd_oid, data_buf);
2020 		break;
2021 	case HostCmd_CMD_802_11_TX_RATE_QUERY:
2022 		cmd_ptr->command =
2023 			cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
2024 		cmd_ptr->size =
2025 			cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
2026 				    S_DS_GEN);
2027 		priv->tx_rate = 0;
2028 		ret = 0;
2029 		break;
2030 	case HostCmd_CMD_VERSION_EXT:
2031 		cmd_ptr->command = cpu_to_le16(cmd_no);
2032 		cmd_ptr->params.verext.version_str_sel =
2033 			(u8)(get_unaligned((u32 *)data_buf));
2034 		memcpy(&cmd_ptr->params, data_buf,
2035 		       sizeof(struct host_cmd_ds_version_ext));
2036 		cmd_ptr->size =
2037 			cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
2038 				    S_DS_GEN);
2039 		ret = 0;
2040 		break;
2041 	case HostCmd_CMD_MGMT_FRAME_REG:
2042 		cmd_ptr->command = cpu_to_le16(cmd_no);
2043 		cmd_ptr->params.reg_mask.action = cpu_to_le16(cmd_action);
2044 		cmd_ptr->params.reg_mask.mask = cpu_to_le32(
2045 						get_unaligned((u32 *)data_buf));
2046 		cmd_ptr->size =
2047 			cpu_to_le16(sizeof(struct host_cmd_ds_mgmt_frame_reg) +
2048 				    S_DS_GEN);
2049 		ret = 0;
2050 		break;
2051 	case HostCmd_CMD_REMAIN_ON_CHAN:
2052 		cmd_ptr->command = cpu_to_le16(cmd_no);
2053 		memcpy(&cmd_ptr->params, data_buf,
2054 		       sizeof(struct host_cmd_ds_remain_on_chan));
2055 		cmd_ptr->size =
2056 		      cpu_to_le16(sizeof(struct host_cmd_ds_remain_on_chan) +
2057 				  S_DS_GEN);
2058 		break;
2059 	case HostCmd_CMD_11AC_CFG:
2060 		ret = mwifiex_cmd_11ac_cfg(priv, cmd_ptr, cmd_action, data_buf);
2061 		break;
2062 	case HostCmd_CMD_PACKET_AGGR_CTRL:
2063 		cmd_ptr->command = cpu_to_le16(cmd_no);
2064 		cmd_ptr->params.pkt_aggr_ctrl.action = cpu_to_le16(cmd_action);
2065 		cmd_ptr->params.pkt_aggr_ctrl.enable =
2066 						cpu_to_le16(*(u16 *)data_buf);
2067 		cmd_ptr->size =
2068 			cpu_to_le16(sizeof(struct host_cmd_ds_pkt_aggr_ctrl) +
2069 				    S_DS_GEN);
2070 		break;
2071 	case HostCmd_CMD_P2P_MODE_CFG:
2072 		cmd_ptr->command = cpu_to_le16(cmd_no);
2073 		cmd_ptr->params.mode_cfg.action = cpu_to_le16(cmd_action);
2074 		cmd_ptr->params.mode_cfg.mode = cpu_to_le16(
2075 						get_unaligned((u16 *)data_buf));
2076 		cmd_ptr->size =
2077 			cpu_to_le16(sizeof(struct host_cmd_ds_p2p_mode_cfg) +
2078 				    S_DS_GEN);
2079 		break;
2080 	case HostCmd_CMD_FUNC_INIT:
2081 		if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
2082 			priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
2083 		cmd_ptr->command = cpu_to_le16(cmd_no);
2084 		cmd_ptr->size = cpu_to_le16(S_DS_GEN);
2085 		break;
2086 	case HostCmd_CMD_FUNC_SHUTDOWN:
2087 		priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
2088 		cmd_ptr->command = cpu_to_le16(cmd_no);
2089 		cmd_ptr->size = cpu_to_le16(S_DS_GEN);
2090 		break;
2091 	case HostCmd_CMD_11N_ADDBA_REQ:
2092 		ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
2093 		break;
2094 	case HostCmd_CMD_11N_DELBA:
2095 		ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
2096 		break;
2097 	case HostCmd_CMD_11N_ADDBA_RSP:
2098 		ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
2099 		break;
2100 	case HostCmd_CMD_802_11_KEY_MATERIAL:
2101 		ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
2102 						      cmd_action, cmd_oid,
2103 						      data_buf);
2104 		break;
2105 	case HostCmd_CMD_802_11D_DOMAIN_INFO:
2106 		ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
2107 						      cmd_action);
2108 		break;
2109 	case HostCmd_CMD_RECONFIGURE_TX_BUFF:
2110 		ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
2111 					       data_buf);
2112 		break;
2113 	case HostCmd_CMD_AMSDU_AGGR_CTRL:
2114 		ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
2115 						  data_buf);
2116 		break;
2117 	case HostCmd_CMD_11N_CFG:
2118 		ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf);
2119 		break;
2120 	case HostCmd_CMD_WMM_GET_STATUS:
2121 		mwifiex_dbg(priv->adapter, CMD,
2122 			    "cmd: WMM: WMM_GET_STATUS cmd sent\n");
2123 		cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
2124 		cmd_ptr->size =
2125 			cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
2126 				    S_DS_GEN);
2127 		ret = 0;
2128 		break;
2129 	case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
2130 		ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
2131 							 data_buf);
2132 		break;
2133 	case HostCmd_CMD_802_11_SCAN_EXT:
2134 		ret = mwifiex_cmd_802_11_scan_ext(priv, cmd_ptr, data_buf);
2135 		break;
2136 	case HostCmd_CMD_MEM_ACCESS:
2137 		ret = mwifiex_cmd_mem_access(cmd_ptr, cmd_action, data_buf);
2138 		break;
2139 	case HostCmd_CMD_MAC_REG_ACCESS:
2140 	case HostCmd_CMD_BBP_REG_ACCESS:
2141 	case HostCmd_CMD_RF_REG_ACCESS:
2142 	case HostCmd_CMD_PMIC_REG_ACCESS:
2143 	case HostCmd_CMD_CAU_REG_ACCESS:
2144 	case HostCmd_CMD_802_11_EEPROM_ACCESS:
2145 		ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
2146 		break;
2147 	case HostCmd_CMD_SET_BSS_MODE:
2148 		cmd_ptr->command = cpu_to_le16(cmd_no);
2149 		if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
2150 			cmd_ptr->params.bss_mode.con_type =
2151 				CONNECTION_TYPE_ADHOC;
2152 		else if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2153 			 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT)
2154 			cmd_ptr->params.bss_mode.con_type =
2155 				CONNECTION_TYPE_INFRA;
2156 		else if (priv->bss_mode == NL80211_IFTYPE_AP ||
2157 			 priv->bss_mode == NL80211_IFTYPE_P2P_GO)
2158 			cmd_ptr->params.bss_mode.con_type = CONNECTION_TYPE_AP;
2159 		cmd_ptr->size = cpu_to_le16(sizeof(struct
2160 				host_cmd_ds_set_bss_mode) + S_DS_GEN);
2161 		ret = 0;
2162 		break;
2163 	case HostCmd_CMD_PCIE_DESC_DETAILS:
2164 		ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
2165 		break;
2166 	case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
2167 		ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
2168 		break;
2169 	case HostCmd_CMD_MEF_CFG:
2170 		ret = mwifiex_cmd_mef_cfg(priv, cmd_ptr, data_buf);
2171 		break;
2172 	case HostCmd_CMD_COALESCE_CFG:
2173 		ret = mwifiex_cmd_coalesce_cfg(priv, cmd_ptr, cmd_action,
2174 					       data_buf);
2175 		break;
2176 	case HostCmd_CMD_TDLS_OPER:
2177 		ret = mwifiex_cmd_tdls_oper(priv, cmd_ptr, data_buf);
2178 		break;
2179 	case HostCmd_CMD_TDLS_CONFIG:
2180 		ret = mwifiex_cmd_tdls_config(priv, cmd_ptr, cmd_action,
2181 					      data_buf);
2182 		break;
2183 	case HostCmd_CMD_CHAN_REPORT_REQUEST:
2184 		ret = mwifiex_cmd_issue_chan_report_request(priv, cmd_ptr,
2185 							    data_buf);
2186 		break;
2187 	case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG:
2188 		ret = mwifiex_cmd_sdio_rx_aggr_cfg(cmd_ptr, cmd_action,
2189 						   data_buf);
2190 		break;
2191 	case HostCmd_CMD_HS_WAKEUP_REASON:
2192 		ret = mwifiex_cmd_get_wakeup_reason(priv, cmd_ptr);
2193 		break;
2194 	case HostCmd_CMD_MC_POLICY:
2195 		ret = mwifiex_cmd_set_mc_policy(priv, cmd_ptr, cmd_action,
2196 						data_buf);
2197 		break;
2198 	case HostCmd_CMD_ROBUST_COEX:
2199 		ret = mwifiex_cmd_robust_coex(priv, cmd_ptr, cmd_action,
2200 					      data_buf);
2201 		break;
2202 	case HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG:
2203 		ret = mwifiex_cmd_gtk_rekey_offload(priv, cmd_ptr, cmd_action,
2204 						    data_buf);
2205 		break;
2206 	case HostCmd_CMD_CHAN_REGION_CFG:
2207 		ret = mwifiex_cmd_chan_region_cfg(priv, cmd_ptr, cmd_action);
2208 		break;
2209 	case HostCmd_CMD_FW_DUMP_EVENT:
2210 		cmd_ptr->command = cpu_to_le16(cmd_no);
2211 		cmd_ptr->size = cpu_to_le16(S_DS_GEN);
2212 		break;
2213 	case HostCmd_CMD_STA_CONFIGURE:
2214 		ret = mwifiex_cmd_get_chan_info(cmd_ptr, cmd_action);
2215 		break;
2216 	default:
2217 		mwifiex_dbg(priv->adapter, ERROR,
2218 			    "PREP_CMD: unknown cmd- %#x\n", cmd_no);
2219 		ret = -1;
2220 		break;
2221 	}
2222 	return ret;
2223 }
2224 
2225 /*
2226  * This function issues commands to initialize firmware.
2227  *
2228  * This is called after firmware download to bring the card to
2229  * working state.
2230  * Function is also called during reinitialization of virtual
2231  * interfaces.
2232  *
2233  * The following commands are issued sequentially -
2234  *      - Set PCI-Express host buffer configuration (PCIE only)
2235  *      - Function init (for first interface only)
2236  *      - Read MAC address (for first interface only)
2237  *      - Reconfigure Tx buffer size (for first interface only)
2238  *      - Enable auto deep sleep (for first interface only)
2239  *      - Get Tx rate
2240  *      - Get Tx power
2241  *      - Set IBSS coalescing status
2242  *      - Set AMSDU aggregation control
2243  *      - Set 11d control
2244  *      - Set MAC control (this must be the last command to initialize firmware)
2245  */
mwifiex_sta_init_cmd(struct mwifiex_private * priv,u8 first_sta)2246 int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
2247 {
2248 	struct mwifiex_adapter *adapter = priv->adapter;
2249 	int ret;
2250 	struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
2251 	struct mwifiex_ds_auto_ds auto_ds;
2252 	enum state_11d_t state_11d;
2253 	struct mwifiex_ds_11n_tx_cfg tx_cfg;
2254 	u8 sdio_sp_rx_aggr_enable;
2255 	u16 packet_aggr_enable;
2256 	int data;
2257 
2258 	if (first_sta) {
2259 		if (priv->adapter->iface_type == MWIFIEX_PCIE) {
2260 			ret = mwifiex_send_cmd(priv,
2261 					       HostCmd_CMD_PCIE_DESC_DETAILS,
2262 					       HostCmd_ACT_GEN_SET, 0, NULL,
2263 					       true);
2264 			if (ret)
2265 				return -1;
2266 		}
2267 
2268 		ret = mwifiex_send_cmd(priv, HostCmd_CMD_FUNC_INIT,
2269 				       HostCmd_ACT_GEN_SET, 0, NULL, true);
2270 		if (ret)
2271 			return -1;
2272 
2273 		/* Download calibration data to firmware.
2274 		 * The cal-data can be read from device tree and/or
2275 		 * a configuration file and downloaded to firmware.
2276 		 */
2277 		if (adapter->dt_node) {
2278 			if (of_property_read_u32(adapter->dt_node,
2279 						 "marvell,wakeup-pin",
2280 						 &data) == 0) {
2281 				pr_debug("Wakeup pin = 0x%x\n", data);
2282 				adapter->hs_cfg.gpio = data;
2283 			}
2284 
2285 			mwifiex_dnld_dt_cfgdata(priv, adapter->dt_node,
2286 						"marvell,caldata");
2287 		}
2288 
2289 		if (adapter->cal_data) {
2290 			mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
2291 					 HostCmd_ACT_GEN_SET, 0, NULL, true);
2292 			release_firmware(adapter->cal_data);
2293 			adapter->cal_data = NULL;
2294 		}
2295 
2296 
2297 		/* Read MAC address from HW */
2298 		ret = mwifiex_send_cmd(priv, HostCmd_CMD_GET_HW_SPEC,
2299 				       HostCmd_ACT_GEN_GET, 0, NULL, true);
2300 		if (ret)
2301 			return -1;
2302 
2303 		/** Set SDIO Single Port RX Aggr Info */
2304 		if (priv->adapter->iface_type == MWIFIEX_SDIO &&
2305 		    ISSUPP_SDIO_SPA_ENABLED(priv->adapter->fw_cap_info) &&
2306 		    !priv->adapter->host_disable_sdio_rx_aggr) {
2307 			sdio_sp_rx_aggr_enable = true;
2308 			ret = mwifiex_send_cmd(priv,
2309 					       HostCmd_CMD_SDIO_SP_RX_AGGR_CFG,
2310 					       HostCmd_ACT_GEN_SET, 0,
2311 					       &sdio_sp_rx_aggr_enable,
2312 					       true);
2313 			if (ret) {
2314 				mwifiex_dbg(priv->adapter, ERROR,
2315 					    "error while enabling SP aggregation..disable it");
2316 				adapter->sdio_rx_aggr_enable = false;
2317 			}
2318 		}
2319 
2320 		/* Reconfigure tx buf size */
2321 		ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
2322 				       HostCmd_ACT_GEN_SET, 0,
2323 				       &priv->adapter->tx_buf_size, true);
2324 		if (ret)
2325 			return -1;
2326 
2327 		if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2328 			/* Enable IEEE PS by default */
2329 			priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
2330 			ret = mwifiex_send_cmd(priv,
2331 					       HostCmd_CMD_802_11_PS_MODE_ENH,
2332 					       EN_AUTO_PS, BITMAP_STA_PS, NULL,
2333 					       true);
2334 			if (ret)
2335 				return -1;
2336 		}
2337 
2338 		if (drcs) {
2339 			adapter->drcs_enabled = true;
2340 			if (ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
2341 				ret = mwifiex_send_cmd(priv,
2342 						       HostCmd_CMD_MC_POLICY,
2343 						       HostCmd_ACT_GEN_SET, 0,
2344 						       &adapter->drcs_enabled,
2345 						       true);
2346 			if (ret)
2347 				return -1;
2348 		}
2349 
2350 		mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REGION_CFG,
2351 				 HostCmd_ACT_GEN_GET, 0, NULL, true);
2352 	}
2353 
2354 	/* get tx rate */
2355 	ret = mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
2356 			       HostCmd_ACT_GEN_GET, 0, NULL, true);
2357 	if (ret)
2358 		return -1;
2359 	priv->data_rate = 0;
2360 
2361 	/* get tx power */
2362 	ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
2363 			       HostCmd_ACT_GEN_GET, 0, NULL, true);
2364 	if (ret)
2365 		return -1;
2366 
2367 	memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
2368 	amsdu_aggr_ctrl.enable = true;
2369 	/* Send request to firmware */
2370 	ret = mwifiex_send_cmd(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
2371 			       HostCmd_ACT_GEN_SET, 0,
2372 			       &amsdu_aggr_ctrl, true);
2373 	if (ret)
2374 		return -1;
2375 	/* MAC Control must be the last command in init_fw */
2376 	/* set MAC Control */
2377 	ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
2378 			       HostCmd_ACT_GEN_SET, 0,
2379 			       &priv->curr_pkt_filter, true);
2380 	if (ret)
2381 		return -1;
2382 
2383 	if (!disable_auto_ds && first_sta &&
2384 	    priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2385 		/* Enable auto deep sleep */
2386 		auto_ds.auto_ds = DEEP_SLEEP_ON;
2387 		auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
2388 		ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
2389 				       EN_AUTO_PS, BITMAP_AUTO_DS,
2390 				       &auto_ds, true);
2391 		if (ret)
2392 			return -1;
2393 	}
2394 
2395 	if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2396 		/* Send cmd to FW to enable/disable 11D function */
2397 		state_11d = ENABLE_11D;
2398 		ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
2399 				       HostCmd_ACT_GEN_SET, DOT11D_I,
2400 				       &state_11d, true);
2401 		if (ret)
2402 			mwifiex_dbg(priv->adapter, ERROR,
2403 				    "11D: failed to enable 11D\n");
2404 	}
2405 
2406 	/* Pacekt aggregation handshake with firmware */
2407 	if (aggr_ctrl) {
2408 		packet_aggr_enable = true;
2409 		mwifiex_send_cmd(priv, HostCmd_CMD_PACKET_AGGR_CTRL,
2410 				 HostCmd_ACT_GEN_SET, 0,
2411 				 &packet_aggr_enable, true);
2412 	}
2413 
2414 	/* Send cmd to FW to configure 11n specific configuration
2415 	 * (Short GI, Channel BW, Green field support etc.) for transmit
2416 	 */
2417 	tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
2418 	ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_CFG,
2419 			       HostCmd_ACT_GEN_SET, 0, &tx_cfg, true);
2420 
2421 	return ret;
2422 }
2423