blob: a76d6a4340d022f0306dc20855fa4bcc825e2cca [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: station command handling
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2011-2014, Marvell International Ltd.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07005 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
Yogesh Ashok Powar83c78da2013-03-18 20:06:03 -070027#include "11ac.h"
Bing Zhao5e6e3a92011-03-21 18:00:50 -070028
Avinash Patil0b4155d2014-12-23 19:14:12 +053029static bool disable_auto_ds;
30module_param(disable_auto_ds, bool, 0);
31MODULE_PARM_DESC(disable_auto_ds,
32 "deepsleep enabled=0(default), deepsleep disabled=1");
Bing Zhao5e6e3a92011-03-21 18:00:50 -070033/*
34 * This function prepares command to set/get RSSI information.
35 *
36 * Preparation includes -
37 * - Setting command ID, action and proper size
38 * - Setting data/beacon average factors
39 * - Resetting SNR/NF/RSSI values in private structure
40 * - Ensuring correct endian-ness
41 */
42static int
43mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
44 struct host_cmd_ds_command *cmd, u16 cmd_action)
45{
46 cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
47 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
48 S_DS_GEN);
49 cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
50 cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
51 cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
52
53 /* Reset SNR/NF/RSSI values in private structure */
54 priv->data_rssi_last = 0;
55 priv->data_nf_last = 0;
56 priv->data_rssi_avg = 0;
57 priv->data_nf_avg = 0;
58 priv->bcn_rssi_last = 0;
59 priv->bcn_nf_last = 0;
60 priv->bcn_rssi_avg = 0;
61 priv->bcn_nf_avg = 0;
62
63 return 0;
64}
65
66/*
67 * This function prepares command to set MAC control.
68 *
69 * Preparation includes -
70 * - Setting command ID, action and proper size
71 * - Ensuring correct endian-ness
72 */
73static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
74 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -070075 u16 cmd_action, u16 *action)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070076{
77 struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070078
79 if (cmd_action != HostCmd_ACT_GEN_SET) {
80 dev_err(priv->adapter->dev,
81 "mac_control: only support set cmd\n");
82 return -1;
83 }
84
85 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
86 cmd->size =
87 cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -070088 mac_ctrl->action = cpu_to_le16(*action);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070089
90 return 0;
91}
92
93/*
94 * This function prepares command to set/get SNMP MIB.
95 *
96 * Preparation includes -
97 * - Setting command ID, action and proper size
98 * - Setting SNMP MIB OID number and value
99 * (as required)
100 * - Ensuring correct endian-ness
101 *
102 * The following SNMP MIB OIDs are supported -
103 * - FRAG_THRESH_I : Fragmentation threshold
104 * - RTS_THRESH_I : RTS threshold
105 * - SHORT_RETRY_LIM_I : Short retry limit
106 * - DOT11D_I : 11d support
107 */
108static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
109 struct host_cmd_ds_command *cmd,
110 u16 cmd_action, u32 cmd_oid,
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800111 u16 *ul_temp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700112{
113 struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700114
115 dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
116 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
117 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700118 - 1 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700119
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800120 snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700121 if (cmd_action == HostCmd_ACT_GEN_GET) {
122 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
123 snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800124 le16_add_cpu(&cmd->size, MAX_SNMP_BUF_SIZE);
125 } else if (cmd_action == HostCmd_ACT_GEN_SET) {
126 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
127 snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
128 *((__le16 *) (snmp_mib->value)) = cpu_to_le16(*ul_temp);
129 le16_add_cpu(&cmd->size, sizeof(u16));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700130 }
131
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700132 dev_dbg(priv->adapter->dev,
133 "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
134 " Value=0x%x\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700135 cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
136 le16_to_cpu(*(__le16 *) snmp_mib->value));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700137 return 0;
138}
139
140/*
141 * This function prepares command to get log.
142 *
143 * Preparation includes -
144 * - Setting command ID and proper size
145 * - Ensuring correct endian-ness
146 */
147static int
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700148mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700149{
150 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
151 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
152 S_DS_GEN);
153 return 0;
154}
155
156/*
157 * This function prepares command to set/get Tx data rate configuration.
158 *
159 * Preparation includes -
160 * - Setting command ID, action and proper size
161 * - Setting configuration index, rate scope and rate drop pattern
162 * parameters (as required)
163 * - Ensuring correct endian-ness
164 */
165static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
166 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700167 u16 cmd_action, u16 *pbitmap_rates)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700168{
169 struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
170 struct mwifiex_rate_scope *rate_scope;
171 struct mwifiex_rate_drop_pattern *rate_drop;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700172 u32 i;
173
174 cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
175
176 rate_cfg->action = cpu_to_le16(cmd_action);
177 rate_cfg->cfg_index = 0;
178
179 rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
180 sizeof(struct host_cmd_ds_tx_rate_cfg));
181 rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700182 rate_scope->length = cpu_to_le16
183 (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700184 if (pbitmap_rates != NULL) {
185 rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
186 rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
187 for (i = 0;
188 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
189 i++)
190 rate_scope->ht_mcs_rate_bitmap[i] =
191 cpu_to_le16(pbitmap_rates[2 + i]);
Amitkumar Karwara0b7315a2014-03-07 19:41:27 -0800192 if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
193 for (i = 0;
194 i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap);
195 i++)
196 rate_scope->vht_mcs_rate_bitmap[i] =
197 cpu_to_le16(pbitmap_rates[10 + i]);
198 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700199 } else {
200 rate_scope->hr_dsss_rate_bitmap =
201 cpu_to_le16(priv->bitmap_rates[0]);
202 rate_scope->ofdm_rate_bitmap =
203 cpu_to_le16(priv->bitmap_rates[1]);
204 for (i = 0;
205 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
206 i++)
207 rate_scope->ht_mcs_rate_bitmap[i] =
208 cpu_to_le16(priv->bitmap_rates[2 + i]);
Amitkumar Karwara0b7315a2014-03-07 19:41:27 -0800209 if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
210 for (i = 0;
211 i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap);
212 i++)
213 rate_scope->vht_mcs_rate_bitmap[i] =
214 cpu_to_le16(priv->bitmap_rates[10 + i]);
215 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700216 }
217
218 rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700219 sizeof(struct mwifiex_rate_scope));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700220 rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
221 rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
222 rate_drop->rate_drop_mode = 0;
223
224 cmd->size =
225 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
226 sizeof(struct mwifiex_rate_scope) +
227 sizeof(struct mwifiex_rate_drop_pattern));
228
229 return 0;
230}
231
232/*
233 * This function prepares command to set/get Tx power configuration.
234 *
235 * Preparation includes -
236 * - Setting command ID, action and proper size
237 * - Setting Tx power mode, power group TLV
238 * (as required)
239 * - Ensuring correct endian-ness
240 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700241static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700242 u16 cmd_action,
243 struct host_cmd_ds_txpwr_cfg *txp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700244{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700245 struct mwifiex_types_power_group *pg_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700246 struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
247
248 cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
249 cmd->size =
250 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
251 switch (cmd_action) {
252 case HostCmd_ACT_GEN_SET:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700253 if (txp->mode) {
254 pg_tlv = (struct mwifiex_types_power_group
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700255 *) ((unsigned long) txp +
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700256 sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700257 memmove(cmd_txp_cfg, txp,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700258 sizeof(struct host_cmd_ds_txpwr_cfg) +
259 sizeof(struct mwifiex_types_power_group) +
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700260 le16_to_cpu(pg_tlv->length));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700261
262 pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
263 cmd_txp_cfg +
264 sizeof(struct host_cmd_ds_txpwr_cfg));
265 cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
266 sizeof(struct mwifiex_types_power_group) +
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700267 le16_to_cpu(pg_tlv->length));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700268 } else {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700269 memmove(cmd_txp_cfg, txp, sizeof(*txp));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700270 }
271 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
272 break;
273 case HostCmd_ACT_GEN_GET:
274 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
275 break;
276 }
277
278 return 0;
279}
280
281/*
Amitkumar Karwarcaa89842012-06-27 19:57:57 -0700282 * This function prepares command to get RF Tx power.
283 */
284static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv,
285 struct host_cmd_ds_command *cmd,
286 u16 cmd_action, void *data_buf)
287{
288 struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp;
289
290 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr)
291 + S_DS_GEN);
292 cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR);
293 txp->action = cpu_to_le16(cmd_action);
294
295 return 0;
296}
297
298/*
Amitkumar Karwar8a279d52012-07-02 19:32:33 -0700299 * This function prepares command to set rf antenna.
300 */
301static int mwifiex_cmd_rf_antenna(struct mwifiex_private *priv,
302 struct host_cmd_ds_command *cmd,
303 u16 cmd_action,
304 struct mwifiex_ds_ant_cfg *ant_cfg)
305{
306 struct host_cmd_ds_rf_ant_mimo *ant_mimo = &cmd->params.ant_mimo;
307 struct host_cmd_ds_rf_ant_siso *ant_siso = &cmd->params.ant_siso;
308
309 cmd->command = cpu_to_le16(HostCmd_CMD_RF_ANTENNA);
310
311 if (cmd_action != HostCmd_ACT_GEN_SET)
312 return 0;
313
314 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
315 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_mimo) +
316 S_DS_GEN);
317 ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_SET_TX);
318 ant_mimo->tx_ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
319 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX);
320 ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg->rx_ant);
321 } else {
322 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_siso) +
323 S_DS_GEN);
324 ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH);
325 ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
326 }
327
328 return 0;
329}
330
331/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700332 * This function prepares command to set Host Sleep configuration.
333 *
334 * Preparation includes -
335 * - Setting command ID and proper size
336 * - Setting Host Sleep action, conditions, ARP filters
337 * (as required)
338 * - Ensuring correct endian-ness
339 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700340static int
341mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
342 struct host_cmd_ds_command *cmd,
343 u16 cmd_action,
344 struct mwifiex_hs_config_param *hscfg_param)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700345{
346 struct mwifiex_adapter *adapter = priv->adapter;
347 struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
Peter Senna Tschudinc8561972013-09-22 00:27:43 +0200348 bool hs_activate = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700349
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700350 if (!hscfg_param)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700351 /* New Activate command */
352 hs_activate = true;
353 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
354
355 if (!hs_activate &&
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800356 (hscfg_param->conditions != cpu_to_le32(HS_CFG_CANCEL)) &&
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700357 ((adapter->arp_filter_size > 0) &&
358 (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700359 dev_dbg(adapter->dev,
360 "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700361 adapter->arp_filter_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362 memcpy(((u8 *) hs_cfg) +
363 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
364 adapter->arp_filter, adapter->arp_filter_size);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700365 cmd->size = cpu_to_le16
366 (adapter->arp_filter_size +
367 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
368 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700369 } else {
370 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700371 host_cmd_ds_802_11_hs_cfg_enh));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700372 }
373 if (hs_activate) {
374 hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
Ujjal Roy4348d082013-12-02 23:17:48 -0800375 hs_cfg->params.hs_activate.resp_ctrl = cpu_to_le16(RESP_NEEDED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376 } else {
377 hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700378 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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700381 dev_dbg(adapter->dev,
382 "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
383 hs_cfg->params.hs_config.conditions,
384 hs_cfg->params.hs_config.gpio,
385 hs_cfg->params.hs_config.gap);
386 }
387
388 return 0;
389}
390
391/*
392 * This function prepares command to set/get MAC address.
393 *
394 * Preparation includes -
395 * - Setting command ID, action and proper size
396 * - Setting MAC address (for SET only)
397 * - Ensuring correct endian-ness
398 */
399static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
400 struct host_cmd_ds_command *cmd,
401 u16 cmd_action)
402{
403 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
404 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
405 S_DS_GEN);
406 cmd->result = 0;
407
408 cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
409
410 if (cmd_action == HostCmd_ACT_GEN_SET)
411 memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
412 ETH_ALEN);
413 return 0;
414}
415
416/*
417 * This function prepares command to set MAC multicast address.
418 *
419 * Preparation includes -
420 * - Setting command ID, action and proper size
421 * - Setting MAC multicast address
422 * - Ensuring correct endian-ness
423 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700424static int
425mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
426 u16 cmd_action,
427 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700428{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700429 struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
430
431 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
432 S_DS_GEN);
433 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
434
435 mcast_addr->action = cpu_to_le16(cmd_action);
436 mcast_addr->num_of_adrs =
437 cpu_to_le16((u16) mcast_list->num_multicast_addr);
438 memcpy(mcast_addr->mac_list, mcast_list->mac_list,
439 mcast_list->num_multicast_addr * ETH_ALEN);
440
441 return 0;
442}
443
444/*
445 * This function prepares command to deauthenticate.
446 *
447 * Preparation includes -
448 * - Setting command ID and proper size
449 * - Setting AP MAC address and reason code
450 * - Ensuring correct endian-ness
451 */
452static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
453 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700454 u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700455{
456 struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
457
458 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
459 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
460 + S_DS_GEN);
461
462 /* Set AP MAC address */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700463 memcpy(deauth->mac_addr, mac, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700464
465 dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
466
467 deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
468
469 return 0;
470}
471
472/*
473 * This function prepares command to stop Ad-Hoc network.
474 *
475 * Preparation includes -
476 * - Setting command ID and proper size
477 * - Ensuring correct endian-ness
478 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700479static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700480{
481 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
482 cmd->size = cpu_to_le16(S_DS_GEN);
483 return 0;
484}
485
486/*
487 * This function sets WEP key(s) to key parameter TLV(s).
488 *
489 * Multi-key parameter TLVs are supported, so we can send multiple
490 * WEP keys in a single buffer.
491 */
492static int
493mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
494 struct mwifiex_ie_type_key_param_set *key_param_set,
495 u16 *key_param_len)
496{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700497 int cur_key_param_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700498 u8 i;
499
500 /* Multi-key_param_set TLV is supported */
501 for (i = 0; i < NUM_WEP_KEYS; i++) {
502 if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
503 (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
504 key_param_set->type =
505 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
506/* Key_param_set WEP fixed length */
507#define KEYPARAMSET_WEP_FIXED_LEN 8
508 key_param_set->length = cpu_to_le16((u16)
509 (priv->wep_key[i].
510 key_length +
511 KEYPARAMSET_WEP_FIXED_LEN));
512 key_param_set->key_type_id =
513 cpu_to_le16(KEY_TYPE_ID_WEP);
514 key_param_set->key_info =
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700515 cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
516 KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700517 key_param_set->key_len =
518 cpu_to_le16(priv->wep_key[i].key_length);
519 /* Set WEP key index */
520 key_param_set->key[0] = i;
521 /* Set default Tx key flag */
522 if (i ==
523 (priv->
524 wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
525 key_param_set->key[1] = 1;
526 else
527 key_param_set->key[1] = 0;
528 memmove(&key_param_set->key[2],
529 priv->wep_key[i].key_material,
530 priv->wep_key[i].key_length);
531
532 cur_key_param_len = priv->wep_key[i].key_length +
533 KEYPARAMSET_WEP_FIXED_LEN +
534 sizeof(struct mwifiex_ie_types_header);
535 *key_param_len += (u16) cur_key_param_len;
536 key_param_set =
537 (struct mwifiex_ie_type_key_param_set *)
538 ((u8 *)key_param_set +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700539 cur_key_param_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700540 } else if (!priv->wep_key[i].key_length) {
541 continue;
542 } else {
543 dev_err(priv->adapter->dev,
544 "key%d Length = %d is incorrect\n",
545 (i + 1), priv->wep_key[i].key_length);
546 return -1;
547 }
548 }
549
550 return 0;
551}
552
Avinash Patile57f1732014-02-07 16:32:35 -0800553/* This function populates key material v2 command
554 * to set network key for AES & CMAC AES.
555 */
556static int mwifiex_set_aes_key_v2(struct mwifiex_private *priv,
557 struct host_cmd_ds_command *cmd,
558 struct mwifiex_ds_encrypt_key *enc_key,
559 struct host_cmd_ds_802_11_key_material_v2 *km)
560{
561 struct mwifiex_adapter *adapter = priv->adapter;
562 u16 size, len = KEY_PARAMS_FIXED_LEN;
563
564 if (enc_key->is_igtk_key) {
565 dev_dbg(adapter->dev, "%s: Set CMAC AES Key\n", __func__);
566 if (enc_key->is_rx_seq_valid)
567 memcpy(km->key_param_set.key_params.cmac_aes.ipn,
568 enc_key->pn, enc_key->pn_len);
569 km->key_param_set.key_info &= cpu_to_le16(~KEY_MCAST);
570 km->key_param_set.key_info |= cpu_to_le16(KEY_IGTK);
571 km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC;
572 km->key_param_set.key_params.cmac_aes.key_len =
573 cpu_to_le16(enc_key->key_len);
574 memcpy(km->key_param_set.key_params.cmac_aes.key,
575 enc_key->key_material, enc_key->key_len);
576 len += sizeof(struct mwifiex_cmac_aes_param);
577 } else {
578 dev_dbg(adapter->dev, "%s: Set AES Key\n", __func__);
579 if (enc_key->is_rx_seq_valid)
580 memcpy(km->key_param_set.key_params.aes.pn,
581 enc_key->pn, enc_key->pn_len);
582 km->key_param_set.key_type = KEY_TYPE_ID_AES;
583 km->key_param_set.key_params.aes.key_len =
584 cpu_to_le16(enc_key->key_len);
585 memcpy(km->key_param_set.key_params.aes.key,
586 enc_key->key_material, enc_key->key_len);
587 len += sizeof(struct mwifiex_aes_param);
588 }
589
590 km->key_param_set.len = cpu_to_le16(len);
591 size = len + sizeof(struct mwifiex_ie_types_header) +
592 sizeof(km->action) + S_DS_GEN;
593 cmd->size = cpu_to_le16(size);
594
595 return 0;
596}
597
598/* This function prepares command to set/get/reset network key(s).
599 * This function prepares key material command for V2 format.
600 * Preparation includes -
601 * - Setting command ID, action and proper size
602 * - Setting WEP keys, WAPI keys or WPA keys along with required
603 * encryption (TKIP, AES) (as required)
604 * - Ensuring correct endian-ness
605 */
606static int
607mwifiex_cmd_802_11_key_material_v2(struct mwifiex_private *priv,
608 struct host_cmd_ds_command *cmd,
609 u16 cmd_action, u32 cmd_oid,
610 struct mwifiex_ds_encrypt_key *enc_key)
611{
612 struct mwifiex_adapter *adapter = priv->adapter;
613 u8 *mac = enc_key->mac_addr;
614 u16 key_info, len = KEY_PARAMS_FIXED_LEN;
615 struct host_cmd_ds_802_11_key_material_v2 *km =
616 &cmd->params.key_material_v2;
617
618 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
619 km->action = cpu_to_le16(cmd_action);
620
621 if (cmd_action == HostCmd_ACT_GEN_GET) {
622 dev_dbg(adapter->dev, "%s: Get key\n", __func__);
623 km->key_param_set.key_idx =
624 enc_key->key_index & KEY_INDEX_MASK;
625 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
626 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
627 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
628
629 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
630 key_info = KEY_UNICAST;
631 else
632 key_info = KEY_MCAST;
633
634 if (enc_key->is_igtk_key)
635 key_info |= KEY_IGTK;
636
637 km->key_param_set.key_info = cpu_to_le16(key_info);
638
639 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
640 S_DS_GEN + KEY_PARAMS_FIXED_LEN +
641 sizeof(km->action));
642 return 0;
643 }
644
645 memset(&km->key_param_set, 0,
646 sizeof(struct mwifiex_ie_type_key_param_set_v2));
647
648 if (enc_key->key_disable) {
649 dev_dbg(adapter->dev, "%s: Remove key\n", __func__);
650 km->action = cpu_to_le16(HostCmd_ACT_GEN_REMOVE);
651 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
652 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
653 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
654 key_info = KEY_MCAST | KEY_UNICAST;
655 km->key_param_set.key_info = cpu_to_le16(key_info);
656 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
657 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
658 S_DS_GEN + KEY_PARAMS_FIXED_LEN +
659 sizeof(km->action));
660 return 0;
661 }
662
663 km->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
664 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
665 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
666 key_info = KEY_ENABLED;
667 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
668
669 if (enc_key->key_len <= WLAN_KEY_LEN_WEP104) {
670 dev_dbg(adapter->dev, "%s: Set WEP Key\n", __func__);
671 len += sizeof(struct mwifiex_wep_param);
672 km->key_param_set.len = cpu_to_le16(len);
673 km->key_param_set.key_type = KEY_TYPE_ID_WEP;
674
675 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
676 key_info |= KEY_MCAST | KEY_UNICAST;
677 } else {
678 if (enc_key->is_current_wep_key) {
679 key_info |= KEY_MCAST | KEY_UNICAST;
680 if (km->key_param_set.key_idx ==
681 (priv->wep_key_curr_index & KEY_INDEX_MASK))
682 key_info |= KEY_DEFAULT;
683 } else {
684 if (mac) {
685 if (is_broadcast_ether_addr(mac))
686 key_info |= KEY_MCAST;
687 else
688 key_info |= KEY_UNICAST |
689 KEY_DEFAULT;
690 } else {
691 key_info |= KEY_MCAST;
692 }
693 }
694 }
695 km->key_param_set.key_info = cpu_to_le16(key_info);
696
697 km->key_param_set.key_params.wep.key_len =
698 cpu_to_le16(enc_key->key_len);
699 memcpy(km->key_param_set.key_params.wep.key,
700 enc_key->key_material, enc_key->key_len);
701
702 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
703 len + sizeof(km->action) + S_DS_GEN);
704 return 0;
705 }
706
707 if (is_broadcast_ether_addr(mac))
708 key_info |= KEY_MCAST | KEY_RX_KEY;
709 else
710 key_info |= KEY_UNICAST | KEY_TX_KEY | KEY_RX_KEY;
711
712 if (enc_key->is_wapi_key) {
713 dev_dbg(adapter->dev, "%s: Set WAPI Key\n", __func__);
714 km->key_param_set.key_type = KEY_TYPE_ID_WAPI;
715 memcpy(km->key_param_set.key_params.wapi.pn, enc_key->pn,
716 PN_LEN);
717 km->key_param_set.key_params.wapi.key_len =
718 cpu_to_le16(enc_key->key_len);
719 memcpy(km->key_param_set.key_params.wapi.key,
720 enc_key->key_material, enc_key->key_len);
721 if (is_broadcast_ether_addr(mac))
722 priv->sec_info.wapi_key_on = true;
723
724 if (!priv->sec_info.wapi_key_on)
725 key_info |= KEY_DEFAULT;
726 km->key_param_set.key_info = cpu_to_le16(key_info);
727
728 len += sizeof(struct mwifiex_wapi_param);
729 km->key_param_set.len = cpu_to_le16(len);
730 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
731 len + sizeof(km->action) + S_DS_GEN);
732 return 0;
733 }
734
735 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
736 key_info |= KEY_DEFAULT;
737 /* Enable unicast bit for WPA-NONE/ADHOC_AES */
738 if (!priv->sec_info.wpa2_enabled &&
739 !is_broadcast_ether_addr(mac))
740 key_info |= KEY_UNICAST;
741 } else {
742 /* Enable default key for WPA/WPA2 */
743 if (!priv->wpa_is_gtk_set)
744 key_info |= KEY_DEFAULT;
745 }
746
747 km->key_param_set.key_info = cpu_to_le16(key_info);
748
749 if (enc_key->key_len == WLAN_KEY_LEN_CCMP)
750 return mwifiex_set_aes_key_v2(priv, cmd, enc_key, km);
751
752 if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
753 dev_dbg(adapter->dev, "%s: Set TKIP Key\n", __func__);
754 if (enc_key->is_rx_seq_valid)
755 memcpy(km->key_param_set.key_params.tkip.pn,
756 enc_key->pn, enc_key->pn_len);
757 km->key_param_set.key_type = KEY_TYPE_ID_TKIP;
758 km->key_param_set.key_params.tkip.key_len =
759 cpu_to_le16(enc_key->key_len);
760 memcpy(km->key_param_set.key_params.tkip.key,
761 enc_key->key_material, enc_key->key_len);
762
763 len += sizeof(struct mwifiex_tkip_param);
764 km->key_param_set.len = cpu_to_le16(len);
765 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
766 len + sizeof(km->action) + S_DS_GEN);
767 }
768
769 return 0;
770}
771
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700772/*
773 * This function prepares command to set/get/reset network key(s).
Avinash Patile57f1732014-02-07 16:32:35 -0800774 * This function prepares key material command for V1 format.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700775 *
776 * Preparation includes -
777 * - Setting command ID, action and proper size
778 * - Setting WEP keys, WAPI keys or WPA keys along with required
779 * encryption (TKIP, AES) (as required)
780 * - Ensuring correct endian-ness
781 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700782static int
Avinash Patile57f1732014-02-07 16:32:35 -0800783mwifiex_cmd_802_11_key_material_v1(struct mwifiex_private *priv,
784 struct host_cmd_ds_command *cmd,
785 u16 cmd_action, u32 cmd_oid,
786 struct mwifiex_ds_encrypt_key *enc_key)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700787{
788 struct host_cmd_ds_802_11_key_material *key_material =
789 &cmd->params.key_material;
Avinash Patil75edd2c2012-05-08 18:30:18 -0700790 struct host_cmd_tlv_mac_addr *tlv_mac;
791 u16 key_param_len = 0, cmd_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700792 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700793
794 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
795 key_material->action = cpu_to_le16(cmd_action);
796
797 if (cmd_action == HostCmd_ACT_GEN_GET) {
798 cmd->size =
799 cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
800 return ret;
801 }
802
803 if (!enc_key) {
804 memset(&key_material->key_param_set, 0,
805 (NUM_WEP_KEYS *
806 sizeof(struct mwifiex_ie_type_key_param_set)));
807 ret = mwifiex_set_keyparamset_wep(priv,
808 &key_material->key_param_set,
809 &key_param_len);
810 cmd->size = cpu_to_le16(key_param_len +
811 sizeof(key_material->action) + S_DS_GEN);
812 return ret;
813 } else
814 memset(&key_material->key_param_set, 0,
815 sizeof(struct mwifiex_ie_type_key_param_set));
816 if (enc_key->is_wapi_key) {
817 dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
818 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700819 cpu_to_le16(KEY_TYPE_ID_WAPI);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700820 if (cmd_oid == KEY_INFO_ENABLED)
821 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700822 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700823 else
824 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700825 cpu_to_le16(!KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700826
827 key_material->key_param_set.key[0] = enc_key->key_index;
828 if (!priv->sec_info.wapi_key_on)
829 key_material->key_param_set.key[1] = 1;
830 else
831 /* set 0 when re-key */
832 key_material->key_param_set.key[1] = 0;
833
Wei Yongjuna71bf902012-08-24 13:25:30 +0800834 if (!is_broadcast_ether_addr(enc_key->mac_addr)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700835 /* WAPI pairwise key: unicast */
836 key_material->key_param_set.key_info |=
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700837 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700838 } else { /* WAPI group key: multicast */
839 key_material->key_param_set.key_info |=
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700840 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700841 priv->sec_info.wapi_key_on = true;
842 }
843
844 key_material->key_param_set.type =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700845 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700846 key_material->key_param_set.key_len =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700847 cpu_to_le16(WAPI_KEY_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700848 memcpy(&key_material->key_param_set.key[2],
849 enc_key->key_material, enc_key->key_len);
850 memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
Ying Luo9d7aba62012-08-03 18:06:12 -0700851 enc_key->pn, PN_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700852 key_material->key_param_set.length =
853 cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
854
855 key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
856 sizeof(struct mwifiex_ie_types_header);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700857 cmd->size = cpu_to_le16(sizeof(key_material->action)
858 + S_DS_GEN + key_param_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700859 return ret;
860 }
861 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
Ying Luob877f4c2012-08-03 18:06:14 -0700862 if (enc_key->is_igtk_key) {
863 dev_dbg(priv->adapter->dev, "cmd: CMAC_AES\n");
864 key_material->key_param_set.key_type_id =
865 cpu_to_le16(KEY_TYPE_ID_AES_CMAC);
866 if (cmd_oid == KEY_INFO_ENABLED)
867 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700868 cpu_to_le16(KEY_ENABLED);
Ying Luob877f4c2012-08-03 18:06:14 -0700869 else
870 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700871 cpu_to_le16(!KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700872
Ying Luob877f4c2012-08-03 18:06:14 -0700873 key_material->key_param_set.key_info |=
874 cpu_to_le16(KEY_IGTK);
875 } else {
876 dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
877 key_material->key_param_set.key_type_id =
878 cpu_to_le16(KEY_TYPE_ID_AES);
879 if (cmd_oid == KEY_INFO_ENABLED)
880 key_material->key_param_set.key_info =
881 cpu_to_le16(KEY_ENABLED);
882 else
883 key_material->key_param_set.key_info =
884 cpu_to_le16(!KEY_ENABLED);
885
886 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700887 /* AES pairwise key: unicast */
Ying Luob877f4c2012-08-03 18:06:14 -0700888 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700889 cpu_to_le16(KEY_UNICAST);
Ying Luob877f4c2012-08-03 18:06:14 -0700890 else /* AES group key: multicast */
891 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700892 cpu_to_le16(KEY_MCAST);
Ying Luob877f4c2012-08-03 18:06:14 -0700893 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700894 } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
895 dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
896 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700897 cpu_to_le16(KEY_TYPE_ID_TKIP);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700898 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700899 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700900
901 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
902 /* TKIP pairwise key: unicast */
903 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700904 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700905 else /* TKIP group key: multicast */
906 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700907 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700908 }
909
910 if (key_material->key_param_set.key_type_id) {
911 key_material->key_param_set.type =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700912 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700913 key_material->key_param_set.key_len =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700914 cpu_to_le16((u16) enc_key->key_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700915 memcpy(key_material->key_param_set.key, enc_key->key_material,
916 enc_key->key_len);
917 key_material->key_param_set.length =
918 cpu_to_le16((u16) enc_key->key_len +
919 KEYPARAMSET_FIXED_LEN);
920
Avinash Patil75edd2c2012-05-08 18:30:18 -0700921 key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700922 + sizeof(struct mwifiex_ie_types_header);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700923
Ying Luob877f4c2012-08-03 18:06:14 -0700924 if (le16_to_cpu(key_material->key_param_set.key_type_id) ==
925 KEY_TYPE_ID_AES_CMAC) {
926 struct mwifiex_cmac_param *param =
927 (void *)key_material->key_param_set.key;
928
929 memcpy(param->ipn, enc_key->pn, IGTK_PN_LEN);
930 memcpy(param->key, enc_key->key_material,
Bing Zhao641c8692012-08-08 19:01:52 -0700931 WLAN_KEY_LEN_AES_CMAC);
Ying Luob877f4c2012-08-03 18:06:14 -0700932
933 key_param_len = sizeof(struct mwifiex_cmac_param);
934 key_material->key_param_set.key_len =
935 cpu_to_le16(key_param_len);
936 key_param_len += KEYPARAMSET_FIXED_LEN;
937 key_material->key_param_set.length =
938 cpu_to_le16(key_param_len);
939 key_param_len += sizeof(struct mwifiex_ie_types_header);
940 }
941
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700942 cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
943 + key_param_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -0700944
Maithili Hinge8342bda2014-09-30 16:29:38 +0530945 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
Avinash Patil75edd2c2012-05-08 18:30:18 -0700946 tlv_mac = (void *)((u8 *)&key_material->key_param_set +
947 key_param_len);
Amitkumar Karwar6b21a692013-07-22 19:17:57 -0700948 tlv_mac->header.type =
949 cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
950 tlv_mac->header.len = cpu_to_le16(ETH_ALEN);
Avinash Patil75edd2c2012-05-08 18:30:18 -0700951 memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
952 cmd_size = key_param_len + S_DS_GEN +
953 sizeof(key_material->action) +
954 sizeof(struct host_cmd_tlv_mac_addr);
955 } else {
956 cmd_size = key_param_len + S_DS_GEN +
957 sizeof(key_material->action);
958 }
959 cmd->size = cpu_to_le16(cmd_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700960 }
961
962 return ret;
963}
964
Avinash Patile57f1732014-02-07 16:32:35 -0800965/* Wrapper function for setting network key depending upon FW KEY API version */
966static int
967mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
968 struct host_cmd_ds_command *cmd,
969 u16 cmd_action, u32 cmd_oid,
970 struct mwifiex_ds_encrypt_key *enc_key)
971{
Amitkumar Karwar4b9fede2014-08-19 08:24:25 -0400972 if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
Avinash Patile57f1732014-02-07 16:32:35 -0800973 return mwifiex_cmd_802_11_key_material_v2(priv, cmd,
974 cmd_action, cmd_oid,
975 enc_key);
976
977 else
978 return mwifiex_cmd_802_11_key_material_v1(priv, cmd,
979 cmd_action, cmd_oid,
980 enc_key);
981}
982
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700983/*
984 * This function prepares command to set/get 11d domain information.
985 *
986 * Preparation includes -
987 * - Setting command ID, action and proper size
988 * - Setting domain information fields (for SET only)
989 * - Ensuring correct endian-ness
990 */
991static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
992 struct host_cmd_ds_command *cmd,
993 u16 cmd_action)
994{
995 struct mwifiex_adapter *adapter = priv->adapter;
996 struct host_cmd_ds_802_11d_domain_info *domain_info =
997 &cmd->params.domain_info;
998 struct mwifiex_ietypes_domain_param_set *domain =
999 &domain_info->domain;
1000 u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
1001
1002 dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
1003
1004 cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
1005 domain_info->action = cpu_to_le16(cmd_action);
1006 if (cmd_action == HostCmd_ACT_GEN_GET) {
1007 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1008 return 0;
1009 }
1010
1011 /* Set domain info fields */
1012 domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
1013 memcpy(domain->country_code, adapter->domain_reg.country_code,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001014 sizeof(domain->country_code));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001015
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001016 domain->header.len =
1017 cpu_to_le16((no_of_triplet *
1018 sizeof(struct ieee80211_country_ie_triplet))
1019 + sizeof(domain->country_code));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001020
1021 if (no_of_triplet) {
1022 memcpy(domain->triplet, adapter->domain_reg.triplet,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001023 no_of_triplet * sizeof(struct
1024 ieee80211_country_ie_triplet));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001025
1026 cmd->size = cpu_to_le16(sizeof(domain_info->action) +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001027 le16_to_cpu(domain->header.len) +
1028 sizeof(struct mwifiex_ie_types_header)
1029 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001030 } else {
1031 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1032 }
1033
1034 return 0;
1035}
1036
1037/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001038 * This function prepares command to set/get IBSS coalescing status.
1039 *
1040 * Preparation includes -
1041 * - Setting command ID, action and proper size
1042 * - Setting status to enable or disable (for SET only)
1043 * - Ensuring correct endian-ness
1044 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001045static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001046 u16 cmd_action, u16 *enable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001047{
1048 struct host_cmd_ds_802_11_ibss_status *ibss_coal =
1049 &(cmd->params.ibss_coalescing);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001050
1051 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
1052 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
1053 S_DS_GEN);
1054 cmd->result = 0;
1055 ibss_coal->action = cpu_to_le16(cmd_action);
1056
1057 switch (cmd_action) {
1058 case HostCmd_ACT_GEN_SET:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001059 if (enable)
1060 ibss_coal->enable = cpu_to_le16(*enable);
Dan Carpentera5e5aa62011-06-24 16:33:35 +03001061 else
1062 ibss_coal->enable = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001063 break;
1064
1065 /* In other case.. Nothing to do */
1066 case HostCmd_ACT_GEN_GET:
1067 default:
1068 break;
1069 }
1070
1071 return 0;
1072}
1073
Chin-ran Loc2c6c852015-05-12 00:48:17 +05301074/* This function prepares command buffer to get/set memory location value.
1075 */
1076static int
1077mwifiex_cmd_mem_access(struct host_cmd_ds_command *cmd, u16 cmd_action,
1078 void *pdata_buf)
1079{
1080 struct mwifiex_ds_mem_rw *mem_rw = (void *)pdata_buf;
1081 struct host_cmd_ds_mem_access *mem_access = (void *)&cmd->params.mem;
1082
1083 cmd->command = cpu_to_le16(HostCmd_CMD_MEM_ACCESS);
1084 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mem_access) +
1085 S_DS_GEN);
1086
1087 mem_access->action = cpu_to_le16(cmd_action);
1088 mem_access->addr = cpu_to_le32(mem_rw->addr);
1089 mem_access->value = cpu_to_le32(mem_rw->value);
1090
1091 return 0;
1092}
1093
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001094/*
1095 * This function prepares command to set/get register value.
1096 *
1097 * Preparation includes -
1098 * - Setting command ID, action and proper size
1099 * - Setting register offset (for both GET and SET) and
1100 * register value (for SET only)
1101 * - Ensuring correct endian-ness
1102 *
1103 * The following type of registers can be accessed with this function -
1104 * - MAC register
1105 * - BBP register
1106 * - RF register
1107 * - PMIC register
1108 * - CAU register
1109 * - EEPROM
1110 */
1111static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
1112 u16 cmd_action, void *data_buf)
1113{
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001114 struct mwifiex_ds_reg_rw *reg_rw = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001115
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001116 switch (le16_to_cpu(cmd->command)) {
1117 case HostCmd_CMD_MAC_REG_ACCESS:
1118 {
1119 struct host_cmd_ds_mac_reg_access *mac_reg;
1120
1121 cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001122 mac_reg = &cmd->params.mac_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001123 mac_reg->action = cpu_to_le16(cmd_action);
1124 mac_reg->offset =
1125 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
1126 mac_reg->value = reg_rw->value;
1127 break;
1128 }
1129 case HostCmd_CMD_BBP_REG_ACCESS:
1130 {
1131 struct host_cmd_ds_bbp_reg_access *bbp_reg;
1132
1133 cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001134 bbp_reg = &cmd->params.bbp_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001135 bbp_reg->action = cpu_to_le16(cmd_action);
1136 bbp_reg->offset =
1137 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
1138 bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
1139 break;
1140 }
1141 case HostCmd_CMD_RF_REG_ACCESS:
1142 {
1143 struct host_cmd_ds_rf_reg_access *rf_reg;
1144
1145 cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001146 rf_reg = &cmd->params.rf_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001147 rf_reg->action = cpu_to_le16(cmd_action);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001148 rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001149 rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
1150 break;
1151 }
1152 case HostCmd_CMD_PMIC_REG_ACCESS:
1153 {
1154 struct host_cmd_ds_pmic_reg_access *pmic_reg;
1155
1156 cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001157 pmic_reg = &cmd->params.pmic_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001158 pmic_reg->action = cpu_to_le16(cmd_action);
1159 pmic_reg->offset =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001160 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161 pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
1162 break;
1163 }
1164 case HostCmd_CMD_CAU_REG_ACCESS:
1165 {
1166 struct host_cmd_ds_rf_reg_access *cau_reg;
1167
1168 cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001169 cau_reg = &cmd->params.rf_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001170 cau_reg->action = cpu_to_le16(cmd_action);
1171 cau_reg->offset =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001172 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001173 cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
1174 break;
1175 }
1176 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1177 {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001178 struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001179 struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001180 &cmd->params.eeprom;
1181
1182 cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
1183 cmd_eeprom->action = cpu_to_le16(cmd_action);
1184 cmd_eeprom->offset = rd_eeprom->offset;
1185 cmd_eeprom->byte_count = rd_eeprom->byte_count;
1186 cmd_eeprom->value = 0;
1187 break;
1188 }
1189 default:
1190 return -1;
1191 }
1192
1193 return 0;
1194}
1195
1196/*
Amitkumar Karward930fae2011-10-11 17:41:21 -07001197 * This function prepares command to set PCI-Express
1198 * host buffer configuration
1199 *
1200 * Preparation includes -
1201 * - Setting command ID, action and proper size
1202 * - Setting host buffer configuration
1203 * - Ensuring correct endian-ness
1204 */
1205static int
1206mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001207 struct host_cmd_ds_command *cmd, u16 action)
Amitkumar Karward930fae2011-10-11 17:41:21 -07001208{
1209 struct host_cmd_ds_pcie_details *host_spec =
1210 &cmd->params.pcie_host_spec;
1211 struct pcie_service_card *card = priv->adapter->card;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001212
1213 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
1214 cmd->size = cpu_to_le16(sizeof(struct
1215 host_cmd_ds_pcie_details) + S_DS_GEN);
1216 cmd->result = 0;
1217
1218 memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
1219
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001220 if (action != HostCmd_ACT_GEN_SET)
1221 return 0;
1222
1223 /* Send the ring base addresses and count to firmware */
1224 host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
1225 host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
1226 host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
1227 host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
1228 host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
1229 host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
1230 host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
1231 host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
1232 host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
Avinash Patilfc331462013-01-03 21:21:30 -08001233 if (card->sleep_cookie_vbase) {
1234 host_spec->sleep_cookie_addr_lo =
1235 (u32)(card->sleep_cookie_pbase);
1236 host_spec->sleep_cookie_addr_hi =
1237 (u32)(((u64)(card->sleep_cookie_pbase)) >> 32);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001238 dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
1239 host_spec->sleep_cookie_addr_lo);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001240 }
1241
1242 return 0;
1243}
1244
1245/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001246 * This function prepares command for event subscription, configuration
1247 * and query. Events can be subscribed or unsubscribed. Current subscribed
1248 * events can be queried. Also, current subscribed events are reported in
1249 * every FW response.
1250 */
1251static int
1252mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
1253 struct host_cmd_ds_command *cmd,
1254 struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
1255{
1256 struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
1257 struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
1258 u16 event_bitmap;
1259 u8 *pos;
1260
1261 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
1262 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
1263 S_DS_GEN);
1264
1265 subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
1266 dev_dbg(priv->adapter->dev, "cmd: action: %d\n", subsc_evt_cfg->action);
1267
1268 /*For query requests, no configuration TLV structures are to be added.*/
1269 if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
1270 return 0;
1271
1272 subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
1273
1274 event_bitmap = subsc_evt_cfg->events;
1275 dev_dbg(priv->adapter->dev, "cmd: event bitmap : %16x\n",
1276 event_bitmap);
1277
1278 if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
1279 (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
1280 (event_bitmap == 0)) {
1281 dev_dbg(priv->adapter->dev, "Error: No event specified "
1282 "for bitwise action type\n");
1283 return -EINVAL;
1284 }
1285
1286 /*
1287 * Append TLV structures for each of the specified events for
1288 * subscribing or re-configuring. This is not required for
1289 * bitwise unsubscribing request.
1290 */
1291 if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
1292 return 0;
1293
1294 pos = ((u8 *)subsc_evt) +
1295 sizeof(struct host_cmd_ds_802_11_subsc_evt);
1296
1297 if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
1298 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1299
1300 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
1301 rssi_tlv->header.len =
1302 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1303 sizeof(struct mwifiex_ie_types_header));
1304 rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
1305 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
1306
1307 dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
1308 "RSSI:-%d dBm, Freq:%d\n",
1309 subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
1310 subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
1311
1312 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1313 le16_add_cpu(&cmd->size,
1314 sizeof(struct mwifiex_ie_types_rssi_threshold));
1315 }
1316
1317 if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
1318 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1319
1320 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1321 rssi_tlv->header.len =
1322 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1323 sizeof(struct mwifiex_ie_types_header));
1324 rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
1325 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
1326
Bing Zhaod35ccaa2012-04-09 20:06:53 -07001327 dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001328 "RSSI:-%d dBm, Freq:%d\n",
1329 subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
1330 subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
1331
1332 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1333 le16_add_cpu(&cmd->size,
1334 sizeof(struct mwifiex_ie_types_rssi_threshold));
1335 }
1336
1337 return 0;
1338}
1339
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001340static int
1341mwifiex_cmd_append_rpn_expression(struct mwifiex_private *priv,
1342 struct mwifiex_mef_entry *mef_entry,
1343 u8 **buffer)
1344{
1345 struct mwifiex_mef_filter *filter = mef_entry->filter;
1346 int i, byte_len;
1347 u8 *stack_ptr = *buffer;
1348
Amitkumar Karwar3f4e8542013-08-05 18:51:57 -07001349 for (i = 0; i < MWIFIEX_MEF_MAX_FILTERS; i++) {
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001350 filter = &mef_entry->filter[i];
1351 if (!filter->filt_type)
1352 break;
1353 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->repeat);
1354 stack_ptr += 4;
1355 *stack_ptr = TYPE_DNUM;
1356 stack_ptr += 1;
1357
Amitkumar Karwar3f4e8542013-08-05 18:51:57 -07001358 byte_len = filter->byte_seq[MWIFIEX_MEF_MAX_BYTESEQ];
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001359 memcpy(stack_ptr, filter->byte_seq, byte_len);
1360 stack_ptr += byte_len;
1361 *stack_ptr = byte_len;
1362 stack_ptr += 1;
1363 *stack_ptr = TYPE_BYTESEQ;
1364 stack_ptr += 1;
1365
1366 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->offset);
1367 stack_ptr += 4;
1368 *stack_ptr = TYPE_DNUM;
1369 stack_ptr += 1;
1370
1371 *stack_ptr = filter->filt_type;
1372 stack_ptr += 1;
1373
1374 if (filter->filt_action) {
1375 *stack_ptr = filter->filt_action;
1376 stack_ptr += 1;
1377 }
1378
1379 if (stack_ptr - *buffer > STACK_NBYTES)
1380 return -1;
1381 }
1382
1383 *buffer = stack_ptr;
1384 return 0;
1385}
1386
1387static int
1388mwifiex_cmd_mef_cfg(struct mwifiex_private *priv,
1389 struct host_cmd_ds_command *cmd,
1390 struct mwifiex_ds_mef_cfg *mef)
1391{
1392 struct host_cmd_ds_mef_cfg *mef_cfg = &cmd->params.mef_cfg;
Maithili Hingeb533be12015-03-12 00:38:39 -07001393 struct mwifiex_fw_mef_entry *mef_entry = NULL;
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001394 u8 *pos = (u8 *)mef_cfg;
Maithili Hingeb533be12015-03-12 00:38:39 -07001395 u16 i;
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001396
1397 cmd->command = cpu_to_le16(HostCmd_CMD_MEF_CFG);
1398
1399 mef_cfg->criteria = cpu_to_le32(mef->criteria);
1400 mef_cfg->num_entries = cpu_to_le16(mef->num_entries);
1401 pos += sizeof(*mef_cfg);
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001402
Maithili Hingeb533be12015-03-12 00:38:39 -07001403 for (i = 0; i < mef->num_entries; i++) {
1404 mef_entry = (struct mwifiex_fw_mef_entry *)pos;
1405 mef_entry->mode = mef->mef_entry[i].mode;
1406 mef_entry->action = mef->mef_entry[i].action;
1407 pos += sizeof(*mef_cfg->mef_entry);
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001408
Maithili Hingeb533be12015-03-12 00:38:39 -07001409 if (mwifiex_cmd_append_rpn_expression(priv,
1410 &mef->mef_entry[i], &pos))
1411 return -1;
1412
1413 mef_entry->exprsize =
1414 cpu_to_le16(pos - mef_entry->expr);
1415 }
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001416 cmd->size = cpu_to_le16((u16) (pos - (u8 *)mef_cfg) + S_DS_GEN);
1417
1418 return 0;
1419}
1420
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001421/* This function parse cal data from ASCII to hex */
1422static u32 mwifiex_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
1423{
1424 u8 *s = src, *d = dst;
1425
1426 while (s - src < len) {
1427 if (*s && (isspace(*s) || *s == '\t')) {
1428 s++;
1429 continue;
1430 }
1431 if (isxdigit(*s)) {
1432 *d++ = simple_strtol(s, NULL, 16);
1433 s += 2;
1434 } else {
1435 s++;
1436 }
1437 }
1438
1439 return d - dst;
1440}
1441
Bing Zhao82efa162013-12-13 18:33:02 -08001442int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv,
1443 struct device_node *node, const char *prefix)
Bing Zhao699b0272013-12-13 18:33:01 -08001444{
1445#ifdef CONFIG_OF
1446 struct property *prop;
1447 size_t len = strlen(prefix);
1448 int ret;
1449
1450 /* look for all matching property names */
1451 for_each_property_of_node(node, prop) {
1452 if (len > strlen(prop->name) ||
1453 strncmp(prop->name, prefix, len))
1454 continue;
1455
Bing Zhao63791cc2014-01-08 15:45:56 -08001456 /* property header is 6 bytes, data must fit in cmd buffer */
1457 if (prop && prop->value && prop->length > 6 &&
1458 prop->length <= MWIFIEX_SIZE_OF_CMD_BUFFER - S_DS_GEN) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001459 ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
1460 HostCmd_ACT_GEN_SET, 0,
1461 prop, true);
Bing Zhao699b0272013-12-13 18:33:01 -08001462 if (ret)
1463 return ret;
1464 }
1465 }
1466#endif
1467 return 0;
1468}
1469
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001470/* This function prepares command of set_cfg_data. */
1471static int mwifiex_cmd_cfg_data(struct mwifiex_private *priv,
Bing Zhao699b0272013-12-13 18:33:01 -08001472 struct host_cmd_ds_command *cmd, void *data_buf)
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001473{
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001474 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao699b0272013-12-13 18:33:01 -08001475 struct property *prop = data_buf;
Bing Zhaod39fbc82013-12-13 18:33:00 -08001476 u32 len;
1477 u8 *data = (u8 *)cmd + S_DS_GEN;
Bing Zhao699b0272013-12-13 18:33:01 -08001478 int ret;
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001479
Bing Zhao699b0272013-12-13 18:33:01 -08001480 if (prop) {
1481 len = prop->length;
1482 ret = of_property_read_u8_array(adapter->dt_node, prop->name,
1483 data, len);
1484 if (ret)
1485 return ret;
1486 dev_dbg(adapter->dev,
1487 "download cfg_data from device tree: %s\n", prop->name);
1488 } else if (adapter->cal_data->data && adapter->cal_data->size > 0) {
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001489 len = mwifiex_parse_cal_cfg((u8 *)adapter->cal_data->data,
Bing Zhaod39fbc82013-12-13 18:33:00 -08001490 adapter->cal_data->size, data);
Bing Zhao699b0272013-12-13 18:33:01 -08001491 dev_dbg(adapter->dev, "download cfg_data from config file\n");
1492 } else {
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001493 return -1;
Bing Zhao699b0272013-12-13 18:33:01 -08001494 }
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001495
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001496 cmd->command = cpu_to_le16(HostCmd_CMD_CFG_DATA);
Bing Zhaod39fbc82013-12-13 18:33:00 -08001497 cmd->size = cpu_to_le16(S_DS_GEN + len);
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001498
1499 return 0;
1500}
1501
Amitkumar Karwar562fc5b2013-08-05 18:52:00 -07001502static int
1503mwifiex_cmd_coalesce_cfg(struct mwifiex_private *priv,
1504 struct host_cmd_ds_command *cmd,
1505 u16 cmd_action, void *data_buf)
1506{
1507 struct host_cmd_ds_coalesce_cfg *coalesce_cfg =
1508 &cmd->params.coalesce_cfg;
1509 struct mwifiex_ds_coalesce_cfg *cfg = data_buf;
1510 struct coalesce_filt_field_param *param;
1511 u16 cnt, idx, length;
1512 struct coalesce_receive_filt_rule *rule;
1513
1514 cmd->command = cpu_to_le16(HostCmd_CMD_COALESCE_CFG);
1515 cmd->size = cpu_to_le16(S_DS_GEN);
1516
1517 coalesce_cfg->action = cpu_to_le16(cmd_action);
1518 coalesce_cfg->num_of_rules = cpu_to_le16(cfg->num_of_rules);
1519 rule = coalesce_cfg->rule;
1520
1521 for (cnt = 0; cnt < cfg->num_of_rules; cnt++) {
1522 rule->header.type = cpu_to_le16(TLV_TYPE_COALESCE_RULE);
1523 rule->max_coalescing_delay =
1524 cpu_to_le16(cfg->rule[cnt].max_coalescing_delay);
1525 rule->pkt_type = cfg->rule[cnt].pkt_type;
1526 rule->num_of_fields = cfg->rule[cnt].num_of_fields;
1527
1528 length = 0;
1529
1530 param = rule->params;
1531 for (idx = 0; idx < cfg->rule[cnt].num_of_fields; idx++) {
1532 param->operation = cfg->rule[cnt].params[idx].operation;
1533 param->operand_len =
1534 cfg->rule[cnt].params[idx].operand_len;
1535 param->offset =
1536 cpu_to_le16(cfg->rule[cnt].params[idx].offset);
1537 memcpy(param->operand_byte_stream,
1538 cfg->rule[cnt].params[idx].operand_byte_stream,
1539 param->operand_len);
1540
1541 length += sizeof(struct coalesce_filt_field_param);
1542
1543 param++;
1544 }
1545
1546 /* Total rule length is sizeof max_coalescing_delay(u16),
1547 * num_of_fields(u8), pkt_type(u8) and total length of the all
1548 * params
1549 */
1550 rule->header.len = cpu_to_le16(length + sizeof(u16) +
1551 sizeof(u8) + sizeof(u8));
1552
1553 /* Add the rule length to the command size*/
1554 le16_add_cpu(&cmd->size, le16_to_cpu(rule->header.len) +
1555 sizeof(struct mwifiex_ie_types_header));
1556
1557 rule = (void *)((u8 *)rule->params + length);
1558 }
1559
1560 /* Add sizeof action, num_of_rules to total command length */
1561 le16_add_cpu(&cmd->size, sizeof(u16) + sizeof(u16));
1562
1563 return 0;
1564}
1565
Avinash Patil429d90d2014-02-07 16:27:34 -08001566static int
1567mwifiex_cmd_tdls_oper(struct mwifiex_private *priv,
1568 struct host_cmd_ds_command *cmd,
1569 void *data_buf)
1570{
1571 struct host_cmd_ds_tdls_oper *tdls_oper = &cmd->params.tdls_oper;
1572 struct mwifiex_ds_tdls_oper *oper = data_buf;
1573 struct mwifiex_sta_node *sta_ptr;
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001574 struct host_cmd_tlv_rates *tlv_rates;
1575 struct mwifiex_ie_types_htcap *ht_capab;
1576 struct mwifiex_ie_types_qos_info *wmm_qos_info;
1577 struct mwifiex_ie_types_extcap *extcap;
Avinash Patil5f6d5982014-02-07 16:30:39 -08001578 struct mwifiex_ie_types_vhtcap *vht_capab;
1579 struct mwifiex_ie_types_aid *aid;
Avinash Patild29caf22014-05-06 22:02:43 -07001580 struct mwifiex_ie_types_tdls_idle_timeout *timeout;
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001581 u8 *pos, qos_info;
1582 u16 config_len = 0;
1583 struct station_parameters *params = priv->sta_params;
Avinash Patil429d90d2014-02-07 16:27:34 -08001584
1585 cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_OPER);
1586 cmd->size = cpu_to_le16(S_DS_GEN);
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001587 le16_add_cpu(&cmd->size, sizeof(struct host_cmd_ds_tdls_oper));
Avinash Patil429d90d2014-02-07 16:27:34 -08001588
1589 tdls_oper->reason = 0;
1590 memcpy(tdls_oper->peer_mac, oper->peer_mac, ETH_ALEN);
1591 sta_ptr = mwifiex_get_sta_entry(priv, oper->peer_mac);
1592
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001593 pos = (u8 *)tdls_oper + sizeof(struct host_cmd_ds_tdls_oper);
1594
Avinash Patil429d90d2014-02-07 16:27:34 -08001595 switch (oper->tdls_action) {
1596 case MWIFIEX_TDLS_DISABLE_LINK:
1597 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_DELETE);
1598 break;
Avinash Patile48e0de2014-02-07 16:30:33 -08001599 case MWIFIEX_TDLS_CREATE_LINK:
1600 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CREATE);
1601 break;
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001602 case MWIFIEX_TDLS_CONFIG_LINK:
1603 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CONFIG);
1604
1605 if (!params) {
1606 dev_err(priv->adapter->dev,
1607 "TDLS config params not available for %pM\n",
1608 oper->peer_mac);
1609 return -ENODATA;
1610 }
1611
1612 *(__le16 *)pos = cpu_to_le16(params->capability);
1613 config_len += sizeof(params->capability);
1614
1615 qos_info = params->uapsd_queues | (params->max_sp << 5);
1616 wmm_qos_info = (struct mwifiex_ie_types_qos_info *)(pos +
1617 config_len);
1618 wmm_qos_info->header.type = cpu_to_le16(WLAN_EID_QOS_CAPA);
1619 wmm_qos_info->header.len = cpu_to_le16(sizeof(qos_info));
1620 wmm_qos_info->qos_info = qos_info;
1621 config_len += sizeof(struct mwifiex_ie_types_qos_info);
1622
1623 if (params->ht_capa) {
1624 ht_capab = (struct mwifiex_ie_types_htcap *)(pos +
1625 config_len);
1626 ht_capab->header.type =
1627 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1628 ht_capab->header.len =
1629 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
1630 memcpy(&ht_capab->ht_cap, params->ht_capa,
1631 sizeof(struct ieee80211_ht_cap));
1632 config_len += sizeof(struct mwifiex_ie_types_htcap);
1633 }
1634
1635 if (params->supported_rates && params->supported_rates_len) {
1636 tlv_rates = (struct host_cmd_tlv_rates *)(pos +
1637 config_len);
1638 tlv_rates->header.type =
1639 cpu_to_le16(WLAN_EID_SUPP_RATES);
1640 tlv_rates->header.len =
1641 cpu_to_le16(params->supported_rates_len);
1642 memcpy(tlv_rates->rates, params->supported_rates,
1643 params->supported_rates_len);
1644 config_len += sizeof(struct host_cmd_tlv_rates) +
1645 params->supported_rates_len;
1646 }
1647
1648 if (params->ext_capab && params->ext_capab_len) {
1649 extcap = (struct mwifiex_ie_types_extcap *)(pos +
1650 config_len);
1651 extcap->header.type =
1652 cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
1653 extcap->header.len = cpu_to_le16(params->ext_capab_len);
1654 memcpy(extcap->ext_capab, params->ext_capab,
1655 params->ext_capab_len);
1656 config_len += sizeof(struct mwifiex_ie_types_extcap) +
1657 params->ext_capab_len;
1658 }
Avinash Patil5f6d5982014-02-07 16:30:39 -08001659 if (params->vht_capa) {
1660 vht_capab = (struct mwifiex_ie_types_vhtcap *)(pos +
1661 config_len);
1662 vht_capab->header.type =
1663 cpu_to_le16(WLAN_EID_VHT_CAPABILITY);
1664 vht_capab->header.len =
1665 cpu_to_le16(sizeof(struct ieee80211_vht_cap));
1666 memcpy(&vht_capab->vht_cap, params->vht_capa,
1667 sizeof(struct ieee80211_vht_cap));
1668 config_len += sizeof(struct mwifiex_ie_types_vhtcap);
1669 }
1670 if (params->aid) {
1671 aid = (struct mwifiex_ie_types_aid *)(pos + config_len);
1672 aid->header.type = cpu_to_le16(WLAN_EID_AID);
1673 aid->header.len = cpu_to_le16(sizeof(params->aid));
1674 aid->aid = cpu_to_le16(params->aid);
1675 config_len += sizeof(struct mwifiex_ie_types_aid);
1676 }
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001677
Avinash Patild29caf22014-05-06 22:02:43 -07001678 timeout = (void *)(pos + config_len);
1679 timeout->header.type = cpu_to_le16(TLV_TYPE_TDLS_IDLE_TIMEOUT);
1680 timeout->header.len = cpu_to_le16(sizeof(timeout->value));
Bing Zhao30fa51c2014-07-11 20:57:13 -07001681 timeout->value = cpu_to_le16(MWIFIEX_TDLS_IDLE_TIMEOUT_IN_SEC);
Avinash Patild29caf22014-05-06 22:02:43 -07001682 config_len += sizeof(struct mwifiex_ie_types_tdls_idle_timeout);
1683
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001684 break;
Avinash Patil429d90d2014-02-07 16:27:34 -08001685 default:
1686 dev_err(priv->adapter->dev, "Unknown TDLS operation\n");
1687 return -ENOTSUPP;
1688 }
1689
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001690 le16_add_cpu(&cmd->size, config_len);
Avinash Patil429d90d2014-02-07 16:27:34 -08001691
1692 return 0;
1693}
Zhaoyang Liu92263a82015-03-13 17:37:58 +05301694
1695/* This function prepares command of sdio rx aggr info. */
1696static int mwifiex_cmd_sdio_rx_aggr_cfg(struct host_cmd_ds_command *cmd,
1697 u16 cmd_action, void *data_buf)
1698{
1699 struct host_cmd_sdio_sp_rx_aggr_cfg *cfg =
1700 &cmd->params.sdio_rx_aggr_cfg;
1701
1702 cmd->command = cpu_to_le16(HostCmd_CMD_SDIO_SP_RX_AGGR_CFG);
1703 cmd->size =
1704 cpu_to_le16(sizeof(struct host_cmd_sdio_sp_rx_aggr_cfg) +
1705 S_DS_GEN);
1706 cfg->action = cmd_action;
1707 if (cmd_action == HostCmd_ACT_GEN_SET)
1708 cfg->enable = *(u8 *)data_buf;
1709
1710 return 0;
1711}
1712
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001713/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001714 * This function prepares the commands before sending them to the firmware.
1715 *
1716 * This is a generic function which calls specific command preparation
1717 * routines based upon the command number.
1718 */
1719int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1720 u16 cmd_action, u32 cmd_oid,
1721 void *data_buf, void *cmd_buf)
1722{
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001723 struct host_cmd_ds_command *cmd_ptr = cmd_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001724 int ret = 0;
1725
1726 /* Prepare command */
1727 switch (cmd_no) {
1728 case HostCmd_CMD_GET_HW_SPEC:
1729 ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
1730 break;
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001731 case HostCmd_CMD_CFG_DATA:
Bing Zhao699b0272013-12-13 18:33:01 -08001732 ret = mwifiex_cmd_cfg_data(priv, cmd_ptr, data_buf);
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001733 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001734 case HostCmd_CMD_MAC_CONTROL:
1735 ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
1736 data_buf);
1737 break;
1738 case HostCmd_CMD_802_11_MAC_ADDRESS:
1739 ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
1740 cmd_action);
1741 break;
1742 case HostCmd_CMD_MAC_MULTICAST_ADR:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001743 ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001744 data_buf);
1745 break;
1746 case HostCmd_CMD_TX_RATE_CFG:
1747 ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
1748 data_buf);
1749 break;
1750 case HostCmd_CMD_TXPWR_CFG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001751 ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001752 data_buf);
1753 break;
Amitkumar Karwarcaa89842012-06-27 19:57:57 -07001754 case HostCmd_CMD_RF_TX_PWR:
1755 ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
1756 data_buf);
1757 break;
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001758 case HostCmd_CMD_RF_ANTENNA:
1759 ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
1760 data_buf);
1761 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001762 case HostCmd_CMD_802_11_PS_MODE_ENH:
1763 ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
1764 (uint16_t)cmd_oid, data_buf);
1765 break;
1766 case HostCmd_CMD_802_11_HS_CFG_ENH:
1767 ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
1768 (struct mwifiex_hs_config_param *) data_buf);
1769 break;
1770 case HostCmd_CMD_802_11_SCAN:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001771 ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001772 break;
1773 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001774 ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001775 break;
1776 case HostCmd_CMD_802_11_ASSOCIATE:
1777 ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
1778 break;
1779 case HostCmd_CMD_802_11_DEAUTHENTICATE:
1780 ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
1781 data_buf);
1782 break;
1783 case HostCmd_CMD_802_11_AD_HOC_START:
1784 ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
1785 data_buf);
1786 break;
1787 case HostCmd_CMD_802_11_GET_LOG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001788 ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001789 break;
1790 case HostCmd_CMD_802_11_AD_HOC_JOIN:
1791 ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
1792 data_buf);
1793 break;
1794 case HostCmd_CMD_802_11_AD_HOC_STOP:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001795 ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001796 break;
1797 case HostCmd_CMD_RSSI_INFO:
1798 ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
1799 break;
1800 case HostCmd_CMD_802_11_SNMP_MIB:
1801 ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
1802 cmd_oid, data_buf);
1803 break;
1804 case HostCmd_CMD_802_11_TX_RATE_QUERY:
1805 cmd_ptr->command =
1806 cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
1807 cmd_ptr->size =
1808 cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
1809 S_DS_GEN);
1810 priv->tx_rate = 0;
1811 ret = 0;
1812 break;
1813 case HostCmd_CMD_VERSION_EXT:
1814 cmd_ptr->command = cpu_to_le16(cmd_no);
1815 cmd_ptr->params.verext.version_str_sel =
1816 (u8) (*((u32 *) data_buf));
1817 memcpy(&cmd_ptr->params, data_buf,
1818 sizeof(struct host_cmd_ds_version_ext));
1819 cmd_ptr->size =
1820 cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
1821 S_DS_GEN);
1822 ret = 0;
1823 break;
Stone Piao3cec6872012-09-25 20:23:34 -07001824 case HostCmd_CMD_MGMT_FRAME_REG:
1825 cmd_ptr->command = cpu_to_le16(cmd_no);
1826 cmd_ptr->params.reg_mask.action = cpu_to_le16(cmd_action);
1827 cmd_ptr->params.reg_mask.mask = cpu_to_le32(*(u32 *)data_buf);
1828 cmd_ptr->size =
1829 cpu_to_le16(sizeof(struct host_cmd_ds_mgmt_frame_reg) +
1830 S_DS_GEN);
1831 ret = 0;
1832 break;
Stone Piao7feb4c42012-09-25 20:23:36 -07001833 case HostCmd_CMD_REMAIN_ON_CHAN:
1834 cmd_ptr->command = cpu_to_le16(cmd_no);
1835 memcpy(&cmd_ptr->params, data_buf,
1836 sizeof(struct host_cmd_ds_remain_on_chan));
1837 cmd_ptr->size =
1838 cpu_to_le16(sizeof(struct host_cmd_ds_remain_on_chan) +
1839 S_DS_GEN);
1840 break;
Yogesh Ashok Powar83c78da2013-03-18 20:06:03 -07001841 case HostCmd_CMD_11AC_CFG:
1842 ret = mwifiex_cmd_11ac_cfg(priv, cmd_ptr, cmd_action, data_buf);
1843 break;
Stone Piaoe1a2b7a2012-09-25 20:23:41 -07001844 case HostCmd_CMD_P2P_MODE_CFG:
1845 cmd_ptr->command = cpu_to_le16(cmd_no);
1846 cmd_ptr->params.mode_cfg.action = cpu_to_le16(cmd_action);
1847 cmd_ptr->params.mode_cfg.mode = cpu_to_le16(*(u16 *)data_buf);
1848 cmd_ptr->size =
1849 cpu_to_le16(sizeof(struct host_cmd_ds_p2p_mode_cfg) +
1850 S_DS_GEN);
1851 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001852 case HostCmd_CMD_FUNC_INIT:
1853 if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
1854 priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
1855 cmd_ptr->command = cpu_to_le16(cmd_no);
1856 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1857 break;
1858 case HostCmd_CMD_FUNC_SHUTDOWN:
1859 priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
1860 cmd_ptr->command = cpu_to_le16(cmd_no);
1861 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1862 break;
1863 case HostCmd_CMD_11N_ADDBA_REQ:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001864 ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001865 break;
1866 case HostCmd_CMD_11N_DELBA:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001867 ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001868 break;
1869 case HostCmd_CMD_11N_ADDBA_RSP:
1870 ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
1871 break;
1872 case HostCmd_CMD_802_11_KEY_MATERIAL:
1873 ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001874 cmd_action, cmd_oid,
1875 data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001876 break;
1877 case HostCmd_CMD_802_11D_DOMAIN_INFO:
1878 ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001879 cmd_action);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001880 break;
1881 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
1882 ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
1883 data_buf);
1884 break;
1885 case HostCmd_CMD_AMSDU_AGGR_CTRL:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001886 ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001887 data_buf);
1888 break;
1889 case HostCmd_CMD_11N_CFG:
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08001890 ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001891 break;
1892 case HostCmd_CMD_WMM_GET_STATUS:
1893 dev_dbg(priv->adapter->dev,
1894 "cmd: WMM: WMM_GET_STATUS cmd sent\n");
1895 cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
1896 cmd_ptr->size =
1897 cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
1898 S_DS_GEN);
1899 ret = 0;
1900 break;
1901 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001902 ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
1903 data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001904 break;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08001905 case HostCmd_CMD_802_11_SCAN_EXT:
1906 ret = mwifiex_cmd_802_11_scan_ext(priv, cmd_ptr, data_buf);
1907 break;
Chin-ran Loc2c6c852015-05-12 00:48:17 +05301908 case HostCmd_CMD_MEM_ACCESS:
1909 ret = mwifiex_cmd_mem_access(cmd_ptr, cmd_action, data_buf);
1910 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001911 case HostCmd_CMD_MAC_REG_ACCESS:
1912 case HostCmd_CMD_BBP_REG_ACCESS:
1913 case HostCmd_CMD_RF_REG_ACCESS:
1914 case HostCmd_CMD_PMIC_REG_ACCESS:
1915 case HostCmd_CMD_CAU_REG_ACCESS:
1916 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1917 ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
1918 break;
1919 case HostCmd_CMD_SET_BSS_MODE:
1920 cmd_ptr->command = cpu_to_le16(cmd_no);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001921 if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001922 cmd_ptr->params.bss_mode.con_type =
1923 CONNECTION_TYPE_ADHOC;
Bing Zhaoeecd8252011-03-28 17:55:41 -07001924 else if (priv->bss_mode == NL80211_IFTYPE_STATION)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001925 cmd_ptr->params.bss_mode.con_type =
1926 CONNECTION_TYPE_INFRA;
Stone Piao9197ab92012-09-25 20:23:42 -07001927 else if (priv->bss_mode == NL80211_IFTYPE_AP)
1928 cmd_ptr->params.bss_mode.con_type = CONNECTION_TYPE_AP;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001929 cmd_ptr->size = cpu_to_le16(sizeof(struct
1930 host_cmd_ds_set_bss_mode) + S_DS_GEN);
1931 ret = 0;
1932 break;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001933 case HostCmd_CMD_PCIE_DESC_DETAILS:
1934 ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
1935 break;
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001936 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
1937 ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
1938 break;
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001939 case HostCmd_CMD_MEF_CFG:
1940 ret = mwifiex_cmd_mef_cfg(priv, cmd_ptr, data_buf);
1941 break;
Amitkumar Karwar562fc5b2013-08-05 18:52:00 -07001942 case HostCmd_CMD_COALESCE_CFG:
1943 ret = mwifiex_cmd_coalesce_cfg(priv, cmd_ptr, cmd_action,
1944 data_buf);
1945 break;
Avinash Patil429d90d2014-02-07 16:27:34 -08001946 case HostCmd_CMD_TDLS_OPER:
1947 ret = mwifiex_cmd_tdls_oper(priv, cmd_ptr, data_buf);
1948 break;
Avinash Patil85afb182015-01-28 15:54:21 +05301949 case HostCmd_CMD_CHAN_REPORT_REQUEST:
1950 ret = mwifiex_cmd_issue_chan_report_request(priv, cmd_ptr,
1951 data_buf);
1952 break;
Zhaoyang Liu92263a82015-03-13 17:37:58 +05301953 case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG:
1954 ret = mwifiex_cmd_sdio_rx_aggr_cfg(cmd_ptr, cmd_action,
1955 data_buf);
1956 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001957 default:
1958 dev_err(priv->adapter->dev,
1959 "PREP_CMD: unknown cmd- %#x\n", cmd_no);
1960 ret = -1;
1961 break;
1962 }
1963 return ret;
1964}
1965
1966/*
1967 * This function issues commands to initialize firmware.
1968 *
1969 * This is called after firmware download to bring the card to
1970 * working state.
Avinash Patil1247cc12015-01-28 15:42:02 +05301971 * Function is also called during reinitialization of virtual
1972 * interfaces.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001973 *
1974 * The following commands are issued sequentially -
Amitkumar Karward930fae2011-10-11 17:41:21 -07001975 * - Set PCI-Express host buffer configuration (PCIE only)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001976 * - Function init (for first interface only)
1977 * - Read MAC address (for first interface only)
1978 * - Reconfigure Tx buffer size (for first interface only)
1979 * - Enable auto deep sleep (for first interface only)
1980 * - Get Tx rate
1981 * - Get Tx power
1982 * - Set IBSS coalescing status
1983 * - Set AMSDU aggregation control
1984 * - Set 11d control
1985 * - Set MAC control (this must be the last command to initialize firmware)
1986 */
Avinash Patil1247cc12015-01-28 15:42:02 +05301987int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta, bool init)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001988{
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001989 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001990 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001991 u16 enable = true;
1992 struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
1993 struct mwifiex_ds_auto_ds auto_ds;
1994 enum state_11d_t state_11d;
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07001995 struct mwifiex_ds_11n_tx_cfg tx_cfg;
Zhaoyang Liu92263a82015-03-13 17:37:58 +05301996 u8 sdio_sp_rx_aggr_enable;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001997
1998 if (first_sta) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07001999 if (priv->adapter->iface_type == MWIFIEX_PCIE) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002000 ret = mwifiex_send_cmd(priv,
2001 HostCmd_CMD_PCIE_DESC_DETAILS,
2002 HostCmd_ACT_GEN_SET, 0, NULL,
2003 true);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002004 if (ret)
2005 return -1;
2006 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002007
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002008 ret = mwifiex_send_cmd(priv, HostCmd_CMD_FUNC_INIT,
2009 HostCmd_ACT_GEN_SET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002010 if (ret)
2011 return -1;
Amitkumar Karwar388ec382013-05-17 17:50:25 -07002012
Bing Zhao699b0272013-12-13 18:33:01 -08002013 /* Download calibration data to firmware.
2014 * The cal-data can be read from device tree and/or
2015 * a configuration file and downloaded to firmware.
2016 */
2017 adapter->dt_node =
2018 of_find_node_by_name(NULL, "marvell_cfgdata");
2019 if (adapter->dt_node) {
2020 ret = mwifiex_dnld_dt_cfgdata(priv, adapter->dt_node,
2021 "marvell,caldata");
2022 if (ret)
2023 return -1;
2024 }
2025
Amitkumar Karwar388ec382013-05-17 17:50:25 -07002026 if (adapter->cal_data) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002027 ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
2028 HostCmd_ACT_GEN_SET, 0, NULL,
2029 true);
Amitkumar Karwar388ec382013-05-17 17:50:25 -07002030 if (ret)
2031 return -1;
2032 }
2033
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002034 /* Read MAC address from HW */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002035 ret = mwifiex_send_cmd(priv, HostCmd_CMD_GET_HW_SPEC,
2036 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002037 if (ret)
2038 return -1;
2039
Zhaoyang Liu92263a82015-03-13 17:37:58 +05302040 /** Set SDIO Single Port RX Aggr Info */
2041 if (priv->adapter->iface_type == MWIFIEX_SDIO &&
2042 ISSUPP_SDIO_SPA_ENABLED(priv->adapter->fw_cap_info)) {
2043 sdio_sp_rx_aggr_enable = true;
2044 ret = mwifiex_send_cmd(priv,
2045 HostCmd_CMD_SDIO_SP_RX_AGGR_CFG,
2046 HostCmd_ACT_GEN_SET, 0,
2047 &sdio_sp_rx_aggr_enable,
2048 true);
2049 if (ret) {
2050 dev_err(priv->adapter->dev,
2051 "error while enabling SP aggregation..disable it");
2052 adapter->sdio_rx_aggr_enable = false;
2053 }
2054 }
2055
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002056 /* Reconfigure tx buf size */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002057 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
2058 HostCmd_ACT_GEN_SET, 0,
2059 &priv->adapter->tx_buf_size, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002060 if (ret)
2061 return -1;
2062
Avinash Patil03785382012-05-08 18:30:14 -07002063 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2064 /* Enable IEEE PS by default */
2065 priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002066 ret = mwifiex_send_cmd(priv,
2067 HostCmd_CMD_802_11_PS_MODE_ENH,
2068 EN_AUTO_PS, BITMAP_STA_PS, NULL,
2069 true);
Avinash Patil03785382012-05-08 18:30:14 -07002070 if (ret)
2071 return -1;
2072 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002073 }
2074
2075 /* get tx rate */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002076 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
2077 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002078 if (ret)
2079 return -1;
2080 priv->data_rate = 0;
2081
2082 /* get tx power */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002083 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
2084 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002085 if (ret)
2086 return -1;
2087
Avinash Patil03785382012-05-08 18:30:14 -07002088 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
2089 /* set ibss coalescing_status */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002090 ret = mwifiex_send_cmd(
2091 priv,
2092 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
2093 HostCmd_ACT_GEN_SET, 0, &enable, true);
Avinash Patil03785382012-05-08 18:30:14 -07002094 if (ret)
2095 return -1;
2096 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002097
2098 memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
2099 amsdu_aggr_ctrl.enable = true;
2100 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002101 ret = mwifiex_send_cmd(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
2102 HostCmd_ACT_GEN_SET, 0,
2103 &amsdu_aggr_ctrl, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002104 if (ret)
2105 return -1;
2106 /* MAC Control must be the last command in init_fw */
2107 /* set MAC Control */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002108 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
2109 HostCmd_ACT_GEN_SET, 0,
2110 &priv->curr_pkt_filter, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002111 if (ret)
2112 return -1;
2113
Avinash Patil0b4155d2014-12-23 19:14:12 +05302114 if (!disable_auto_ds &&
2115 first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
Avinash Patil03785382012-05-08 18:30:14 -07002116 priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002117 /* Enable auto deep sleep */
2118 auto_ds.auto_ds = DEEP_SLEEP_ON;
2119 auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002120 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
2121 EN_AUTO_PS, BITMAP_AUTO_DS,
2122 &auto_ds, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002123 if (ret)
2124 return -1;
2125 }
2126
Avinash Patil03785382012-05-08 18:30:14 -07002127 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2128 /* Send cmd to FW to enable/disable 11D function */
2129 state_11d = ENABLE_11D;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002130 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
2131 HostCmd_ACT_GEN_SET, DOT11D_I,
2132 &state_11d, true);
Avinash Patil03785382012-05-08 18:30:14 -07002133 if (ret)
2134 dev_err(priv->adapter->dev,
2135 "11D: failed to enable 11D\n");
2136 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002137
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07002138 /* Send cmd to FW to configure 11n specific configuration
2139 * (Short GI, Channel BW, Green field support etc.) for transmit
2140 */
2141 tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002142 ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_CFG,
2143 HostCmd_ACT_GEN_SET, 0, &tx_cfg, true);
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07002144
Avinash Patil1247cc12015-01-28 15:42:02 +05302145 if (init) {
2146 /* set last_init_cmd before sending the command */
2147 priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
2148 ret = -EINPROGRESS;
2149 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002150
2151 return ret;
2152}