blob: 8c658495bf6608b64c95d6fc49777659d5d7f31d [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 Patild5b036c2015-06-22 19:06:20 +053029static bool drcs;
30module_param(drcs, bool, 0644);
31MODULE_PARM_DESC(drcs, "multi-channel operation:1, single-channel operation:0");
32
Avinash Patil0b4155d2014-12-23 19:14:12 +053033static bool disable_auto_ds;
34module_param(disable_auto_ds, bool, 0);
35MODULE_PARM_DESC(disable_auto_ds,
36 "deepsleep enabled=0(default), deepsleep disabled=1");
Bing Zhao5e6e3a92011-03-21 18:00:50 -070037/*
38 * This function prepares command to set/get RSSI information.
39 *
40 * Preparation includes -
41 * - Setting command ID, action and proper size
42 * - Setting data/beacon average factors
43 * - Resetting SNR/NF/RSSI values in private structure
44 * - Ensuring correct endian-ness
45 */
46static int
47mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
48 struct host_cmd_ds_command *cmd, u16 cmd_action)
49{
50 cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
51 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
52 S_DS_GEN);
53 cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
54 cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
55 cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
56
57 /* Reset SNR/NF/RSSI values in private structure */
58 priv->data_rssi_last = 0;
59 priv->data_nf_last = 0;
60 priv->data_rssi_avg = 0;
61 priv->data_nf_avg = 0;
62 priv->bcn_rssi_last = 0;
63 priv->bcn_nf_last = 0;
64 priv->bcn_rssi_avg = 0;
65 priv->bcn_nf_avg = 0;
66
67 return 0;
68}
69
70/*
71 * This function prepares command to set MAC control.
72 *
73 * Preparation includes -
74 * - Setting command ID, action and proper size
75 * - Ensuring correct endian-ness
76 */
77static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
78 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -070079 u16 cmd_action, u16 *action)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070080{
81 struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070082
83 if (cmd_action != HostCmd_ACT_GEN_SET) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +053084 mwifiex_dbg(priv->adapter, ERROR,
85 "mac_control: only support set cmd\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -070086 return -1;
87 }
88
89 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
90 cmd->size =
91 cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -070092 mac_ctrl->action = cpu_to_le16(*action);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070093
94 return 0;
95}
96
97/*
98 * This function prepares command to set/get SNMP MIB.
99 *
100 * Preparation includes -
101 * - Setting command ID, action and proper size
102 * - Setting SNMP MIB OID number and value
103 * (as required)
104 * - Ensuring correct endian-ness
105 *
106 * The following SNMP MIB OIDs are supported -
107 * - FRAG_THRESH_I : Fragmentation threshold
108 * - RTS_THRESH_I : RTS threshold
109 * - SHORT_RETRY_LIM_I : Short retry limit
110 * - DOT11D_I : 11d support
111 */
112static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
113 struct host_cmd_ds_command *cmd,
114 u16 cmd_action, u32 cmd_oid,
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800115 u16 *ul_temp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700116{
117 struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700118
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530119 mwifiex_dbg(priv->adapter, CMD,
120 "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700121 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
122 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700123 - 1 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700124
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800125 snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700126 if (cmd_action == HostCmd_ACT_GEN_GET) {
127 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
128 snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800129 le16_add_cpu(&cmd->size, MAX_SNMP_BUF_SIZE);
130 } else if (cmd_action == HostCmd_ACT_GEN_SET) {
131 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
132 snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
133 *((__le16 *) (snmp_mib->value)) = cpu_to_le16(*ul_temp);
134 le16_add_cpu(&cmd->size, sizeof(u16));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700135 }
136
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530137 mwifiex_dbg(priv->adapter, CMD,
138 "cmd: SNMP_CMD: Action=0x%x, OID=0x%x,\t"
139 "OIDSize=0x%x, Value=0x%x\n",
140 cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
141 le16_to_cpu(*(__le16 *)snmp_mib->value));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700142 return 0;
143}
144
145/*
146 * This function prepares command to get log.
147 *
148 * Preparation includes -
149 * - Setting command ID and proper size
150 * - Ensuring correct endian-ness
151 */
152static int
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700153mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700154{
155 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
156 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
157 S_DS_GEN);
158 return 0;
159}
160
161/*
162 * This function prepares command to set/get Tx data rate configuration.
163 *
164 * Preparation includes -
165 * - Setting command ID, action and proper size
166 * - Setting configuration index, rate scope and rate drop pattern
167 * parameters (as required)
168 * - Ensuring correct endian-ness
169 */
170static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
171 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700172 u16 cmd_action, u16 *pbitmap_rates)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700173{
174 struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
175 struct mwifiex_rate_scope *rate_scope;
176 struct mwifiex_rate_drop_pattern *rate_drop;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700177 u32 i;
178
179 cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
180
181 rate_cfg->action = cpu_to_le16(cmd_action);
182 rate_cfg->cfg_index = 0;
183
184 rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
185 sizeof(struct host_cmd_ds_tx_rate_cfg));
186 rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700187 rate_scope->length = cpu_to_le16
188 (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700189 if (pbitmap_rates != NULL) {
190 rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
191 rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
192 for (i = 0;
193 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
194 i++)
195 rate_scope->ht_mcs_rate_bitmap[i] =
196 cpu_to_le16(pbitmap_rates[2 + i]);
Amitkumar Karwara0b7315a2014-03-07 19:41:27 -0800197 if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
198 for (i = 0;
199 i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap);
200 i++)
201 rate_scope->vht_mcs_rate_bitmap[i] =
202 cpu_to_le16(pbitmap_rates[10 + i]);
203 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700204 } else {
205 rate_scope->hr_dsss_rate_bitmap =
206 cpu_to_le16(priv->bitmap_rates[0]);
207 rate_scope->ofdm_rate_bitmap =
208 cpu_to_le16(priv->bitmap_rates[1]);
209 for (i = 0;
210 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
211 i++)
212 rate_scope->ht_mcs_rate_bitmap[i] =
213 cpu_to_le16(priv->bitmap_rates[2 + i]);
Amitkumar Karwara0b7315a2014-03-07 19:41:27 -0800214 if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
215 for (i = 0;
216 i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap);
217 i++)
218 rate_scope->vht_mcs_rate_bitmap[i] =
219 cpu_to_le16(priv->bitmap_rates[10 + i]);
220 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700221 }
222
223 rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700224 sizeof(struct mwifiex_rate_scope));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700225 rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
226 rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
227 rate_drop->rate_drop_mode = 0;
228
229 cmd->size =
230 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
231 sizeof(struct mwifiex_rate_scope) +
232 sizeof(struct mwifiex_rate_drop_pattern));
233
234 return 0;
235}
236
237/*
238 * This function prepares command to set/get Tx power configuration.
239 *
240 * Preparation includes -
241 * - Setting command ID, action and proper size
242 * - Setting Tx power mode, power group TLV
243 * (as required)
244 * - Ensuring correct endian-ness
245 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700246static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700247 u16 cmd_action,
248 struct host_cmd_ds_txpwr_cfg *txp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700249{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700250 struct mwifiex_types_power_group *pg_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700251 struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
252
253 cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
254 cmd->size =
255 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
256 switch (cmd_action) {
257 case HostCmd_ACT_GEN_SET:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700258 if (txp->mode) {
259 pg_tlv = (struct mwifiex_types_power_group
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700260 *) ((unsigned long) txp +
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700261 sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700262 memmove(cmd_txp_cfg, txp,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700263 sizeof(struct host_cmd_ds_txpwr_cfg) +
264 sizeof(struct mwifiex_types_power_group) +
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700265 le16_to_cpu(pg_tlv->length));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700266
267 pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
268 cmd_txp_cfg +
269 sizeof(struct host_cmd_ds_txpwr_cfg));
270 cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
271 sizeof(struct mwifiex_types_power_group) +
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700272 le16_to_cpu(pg_tlv->length));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700273 } else {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700274 memmove(cmd_txp_cfg, txp, sizeof(*txp));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700275 }
276 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
277 break;
278 case HostCmd_ACT_GEN_GET:
279 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
280 break;
281 }
282
283 return 0;
284}
285
286/*
Amitkumar Karwarcaa89842012-06-27 19:57:57 -0700287 * This function prepares command to get RF Tx power.
288 */
289static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv,
290 struct host_cmd_ds_command *cmd,
291 u16 cmd_action, void *data_buf)
292{
293 struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp;
294
295 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr)
296 + S_DS_GEN);
297 cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR);
298 txp->action = cpu_to_le16(cmd_action);
299
300 return 0;
301}
302
303/*
Amitkumar Karwar8a279d52012-07-02 19:32:33 -0700304 * This function prepares command to set rf antenna.
305 */
306static int mwifiex_cmd_rf_antenna(struct mwifiex_private *priv,
307 struct host_cmd_ds_command *cmd,
308 u16 cmd_action,
309 struct mwifiex_ds_ant_cfg *ant_cfg)
310{
311 struct host_cmd_ds_rf_ant_mimo *ant_mimo = &cmd->params.ant_mimo;
312 struct host_cmd_ds_rf_ant_siso *ant_siso = &cmd->params.ant_siso;
313
314 cmd->command = cpu_to_le16(HostCmd_CMD_RF_ANTENNA);
315
Shengzhen Li3ee71282016-06-06 13:02:38 -0400316 switch (cmd_action) {
317 case HostCmd_ACT_GEN_SET:
318 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
319 cmd->size = cpu_to_le16(sizeof(struct
320 host_cmd_ds_rf_ant_mimo)
321 + S_DS_GEN);
322 ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_SET_TX);
323 ant_mimo->tx_ant_mode = cpu_to_le16((u16)ant_cfg->
324 tx_ant);
325 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX);
326 ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg->
327 rx_ant);
328 } else {
329 cmd->size = cpu_to_le16(sizeof(struct
330 host_cmd_ds_rf_ant_siso) +
331 S_DS_GEN);
332 ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH);
333 ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
334 }
335 break;
336 case HostCmd_ACT_GEN_GET:
337 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
338 cmd->size = cpu_to_le16(sizeof(struct
339 host_cmd_ds_rf_ant_mimo) +
340 S_DS_GEN);
341 ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_GET_TX);
342 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_GET_RX);
343 } else {
344 cmd->size = cpu_to_le16(sizeof(struct
345 host_cmd_ds_rf_ant_siso) +
346 S_DS_GEN);
347 ant_siso->action = cpu_to_le16(HostCmd_ACT_GET_BOTH);
348 }
349 break;
Amitkumar Karwar8a279d52012-07-02 19:32:33 -0700350 }
Amitkumar Karwar8a279d52012-07-02 19:32:33 -0700351 return 0;
352}
353
354/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700355 * This function prepares command to set Host Sleep configuration.
356 *
357 * Preparation includes -
358 * - Setting command ID and proper size
359 * - Setting Host Sleep action, conditions, ARP filters
360 * (as required)
361 * - Ensuring correct endian-ness
362 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700363static int
364mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
365 struct host_cmd_ds_command *cmd,
366 u16 cmd_action,
367 struct mwifiex_hs_config_param *hscfg_param)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700368{
369 struct mwifiex_adapter *adapter = priv->adapter;
370 struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
Peter Senna Tschudinc8561972013-09-22 00:27:43 +0200371 bool hs_activate = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700372
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700373 if (!hscfg_param)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700374 /* New Activate command */
375 hs_activate = true;
376 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
377
378 if (!hs_activate &&
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800379 (hscfg_param->conditions != cpu_to_le32(HS_CFG_CANCEL)) &&
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700380 ((adapter->arp_filter_size > 0) &&
381 (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530382 mwifiex_dbg(adapter, CMD,
383 "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
384 adapter->arp_filter_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700385 memcpy(((u8 *) hs_cfg) +
386 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
387 adapter->arp_filter, adapter->arp_filter_size);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700388 cmd->size = cpu_to_le16
389 (adapter->arp_filter_size +
390 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
391 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700392 } else {
393 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700394 host_cmd_ds_802_11_hs_cfg_enh));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700395 }
396 if (hs_activate) {
397 hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
Ujjal Roy4348d082013-12-02 23:17:48 -0800398 hs_cfg->params.hs_activate.resp_ctrl = cpu_to_le16(RESP_NEEDED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700399 } else {
400 hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700401 hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
402 hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
403 hs_cfg->params.hs_config.gap = hscfg_param->gap;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530404 mwifiex_dbg(adapter, CMD,
405 "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
406 hs_cfg->params.hs_config.conditions,
407 hs_cfg->params.hs_config.gpio,
408 hs_cfg->params.hs_config.gap);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700409 }
410
411 return 0;
412}
413
414/*
415 * This function prepares command to set/get MAC address.
416 *
417 * Preparation includes -
418 * - Setting command ID, action and proper size
419 * - Setting MAC address (for SET only)
420 * - Ensuring correct endian-ness
421 */
422static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
423 struct host_cmd_ds_command *cmd,
424 u16 cmd_action)
425{
426 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
427 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
428 S_DS_GEN);
429 cmd->result = 0;
430
431 cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
432
433 if (cmd_action == HostCmd_ACT_GEN_SET)
434 memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
435 ETH_ALEN);
436 return 0;
437}
438
439/*
440 * This function prepares command to set MAC multicast address.
441 *
442 * Preparation includes -
443 * - Setting command ID, action and proper size
444 * - Setting MAC multicast address
445 * - Ensuring correct endian-ness
446 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700447static int
448mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
449 u16 cmd_action,
450 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700451{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700452 struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
453
454 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
455 S_DS_GEN);
456 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
457
458 mcast_addr->action = cpu_to_le16(cmd_action);
459 mcast_addr->num_of_adrs =
460 cpu_to_le16((u16) mcast_list->num_multicast_addr);
461 memcpy(mcast_addr->mac_list, mcast_list->mac_list,
462 mcast_list->num_multicast_addr * ETH_ALEN);
463
464 return 0;
465}
466
467/*
468 * This function prepares command to deauthenticate.
469 *
470 * Preparation includes -
471 * - Setting command ID and proper size
472 * - Setting AP MAC address and reason code
473 * - Ensuring correct endian-ness
474 */
475static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
476 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700477 u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700478{
479 struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
480
481 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
482 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
483 + S_DS_GEN);
484
485 /* Set AP MAC address */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700486 memcpy(deauth->mac_addr, mac, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700487
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530488 mwifiex_dbg(priv->adapter, CMD, "cmd: Deauth: %pM\n", deauth->mac_addr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700489
490 deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
491
492 return 0;
493}
494
495/*
496 * This function prepares command to stop Ad-Hoc network.
497 *
498 * Preparation includes -
499 * - Setting command ID and proper size
500 * - Ensuring correct endian-ness
501 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700502static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700503{
504 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
505 cmd->size = cpu_to_le16(S_DS_GEN);
506 return 0;
507}
508
509/*
510 * This function sets WEP key(s) to key parameter TLV(s).
511 *
512 * Multi-key parameter TLVs are supported, so we can send multiple
513 * WEP keys in a single buffer.
514 */
515static int
516mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
517 struct mwifiex_ie_type_key_param_set *key_param_set,
518 u16 *key_param_len)
519{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700520 int cur_key_param_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700521 u8 i;
522
523 /* Multi-key_param_set TLV is supported */
524 for (i = 0; i < NUM_WEP_KEYS; i++) {
525 if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
526 (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
527 key_param_set->type =
528 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
529/* Key_param_set WEP fixed length */
530#define KEYPARAMSET_WEP_FIXED_LEN 8
531 key_param_set->length = cpu_to_le16((u16)
532 (priv->wep_key[i].
533 key_length +
534 KEYPARAMSET_WEP_FIXED_LEN));
535 key_param_set->key_type_id =
536 cpu_to_le16(KEY_TYPE_ID_WEP);
537 key_param_set->key_info =
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700538 cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
539 KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700540 key_param_set->key_len =
541 cpu_to_le16(priv->wep_key[i].key_length);
542 /* Set WEP key index */
543 key_param_set->key[0] = i;
544 /* Set default Tx key flag */
545 if (i ==
546 (priv->
547 wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
548 key_param_set->key[1] = 1;
549 else
550 key_param_set->key[1] = 0;
551 memmove(&key_param_set->key[2],
552 priv->wep_key[i].key_material,
553 priv->wep_key[i].key_length);
554
555 cur_key_param_len = priv->wep_key[i].key_length +
556 KEYPARAMSET_WEP_FIXED_LEN +
557 sizeof(struct mwifiex_ie_types_header);
558 *key_param_len += (u16) cur_key_param_len;
559 key_param_set =
560 (struct mwifiex_ie_type_key_param_set *)
561 ((u8 *)key_param_set +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700562 cur_key_param_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700563 } else if (!priv->wep_key[i].key_length) {
564 continue;
565 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530566 mwifiex_dbg(priv->adapter, ERROR,
567 "key%d Length = %d is incorrect\n",
568 (i + 1), priv->wep_key[i].key_length);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700569 return -1;
570 }
571 }
572
573 return 0;
574}
575
Avinash Patile57f1732014-02-07 16:32:35 -0800576/* This function populates key material v2 command
577 * to set network key for AES & CMAC AES.
578 */
579static int mwifiex_set_aes_key_v2(struct mwifiex_private *priv,
580 struct host_cmd_ds_command *cmd,
581 struct mwifiex_ds_encrypt_key *enc_key,
582 struct host_cmd_ds_802_11_key_material_v2 *km)
583{
584 struct mwifiex_adapter *adapter = priv->adapter;
585 u16 size, len = KEY_PARAMS_FIXED_LEN;
586
587 if (enc_key->is_igtk_key) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530588 mwifiex_dbg(adapter, INFO,
589 "%s: Set CMAC AES Key\n", __func__);
Avinash Patile57f1732014-02-07 16:32:35 -0800590 if (enc_key->is_rx_seq_valid)
591 memcpy(km->key_param_set.key_params.cmac_aes.ipn,
592 enc_key->pn, enc_key->pn_len);
593 km->key_param_set.key_info &= cpu_to_le16(~KEY_MCAST);
594 km->key_param_set.key_info |= cpu_to_le16(KEY_IGTK);
595 km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC;
596 km->key_param_set.key_params.cmac_aes.key_len =
597 cpu_to_le16(enc_key->key_len);
598 memcpy(km->key_param_set.key_params.cmac_aes.key,
599 enc_key->key_material, enc_key->key_len);
600 len += sizeof(struct mwifiex_cmac_aes_param);
601 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530602 mwifiex_dbg(adapter, INFO,
603 "%s: Set AES Key\n", __func__);
Avinash Patile57f1732014-02-07 16:32:35 -0800604 if (enc_key->is_rx_seq_valid)
605 memcpy(km->key_param_set.key_params.aes.pn,
606 enc_key->pn, enc_key->pn_len);
607 km->key_param_set.key_type = KEY_TYPE_ID_AES;
608 km->key_param_set.key_params.aes.key_len =
609 cpu_to_le16(enc_key->key_len);
610 memcpy(km->key_param_set.key_params.aes.key,
611 enc_key->key_material, enc_key->key_len);
612 len += sizeof(struct mwifiex_aes_param);
613 }
614
615 km->key_param_set.len = cpu_to_le16(len);
616 size = len + sizeof(struct mwifiex_ie_types_header) +
617 sizeof(km->action) + S_DS_GEN;
618 cmd->size = cpu_to_le16(size);
619
620 return 0;
621}
622
623/* This function prepares command to set/get/reset network key(s).
624 * This function prepares key material command for V2 format.
625 * Preparation includes -
626 * - Setting command ID, action and proper size
627 * - Setting WEP keys, WAPI keys or WPA keys along with required
628 * encryption (TKIP, AES) (as required)
629 * - Ensuring correct endian-ness
630 */
631static int
632mwifiex_cmd_802_11_key_material_v2(struct mwifiex_private *priv,
633 struct host_cmd_ds_command *cmd,
634 u16 cmd_action, u32 cmd_oid,
635 struct mwifiex_ds_encrypt_key *enc_key)
636{
637 struct mwifiex_adapter *adapter = priv->adapter;
638 u8 *mac = enc_key->mac_addr;
639 u16 key_info, len = KEY_PARAMS_FIXED_LEN;
640 struct host_cmd_ds_802_11_key_material_v2 *km =
641 &cmd->params.key_material_v2;
642
643 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
644 km->action = cpu_to_le16(cmd_action);
645
646 if (cmd_action == HostCmd_ACT_GEN_GET) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530647 mwifiex_dbg(adapter, INFO, "%s: Get key\n", __func__);
Avinash Patile57f1732014-02-07 16:32:35 -0800648 km->key_param_set.key_idx =
649 enc_key->key_index & KEY_INDEX_MASK;
650 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
651 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
652 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
653
654 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
655 key_info = KEY_UNICAST;
656 else
657 key_info = KEY_MCAST;
658
659 if (enc_key->is_igtk_key)
660 key_info |= KEY_IGTK;
661
662 km->key_param_set.key_info = cpu_to_le16(key_info);
663
664 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
665 S_DS_GEN + KEY_PARAMS_FIXED_LEN +
666 sizeof(km->action));
667 return 0;
668 }
669
670 memset(&km->key_param_set, 0,
671 sizeof(struct mwifiex_ie_type_key_param_set_v2));
672
673 if (enc_key->key_disable) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530674 mwifiex_dbg(adapter, INFO, "%s: Remove key\n", __func__);
Avinash Patile57f1732014-02-07 16:32:35 -0800675 km->action = cpu_to_le16(HostCmd_ACT_GEN_REMOVE);
676 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
677 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
678 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
679 key_info = KEY_MCAST | KEY_UNICAST;
680 km->key_param_set.key_info = cpu_to_le16(key_info);
681 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
682 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
683 S_DS_GEN + KEY_PARAMS_FIXED_LEN +
684 sizeof(km->action));
685 return 0;
686 }
687
688 km->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
689 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
690 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
691 key_info = KEY_ENABLED;
692 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
693
694 if (enc_key->key_len <= WLAN_KEY_LEN_WEP104) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530695 mwifiex_dbg(adapter, INFO, "%s: Set WEP Key\n", __func__);
Avinash Patile57f1732014-02-07 16:32:35 -0800696 len += sizeof(struct mwifiex_wep_param);
697 km->key_param_set.len = cpu_to_le16(len);
698 km->key_param_set.key_type = KEY_TYPE_ID_WEP;
699
700 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
701 key_info |= KEY_MCAST | KEY_UNICAST;
702 } else {
703 if (enc_key->is_current_wep_key) {
704 key_info |= KEY_MCAST | KEY_UNICAST;
705 if (km->key_param_set.key_idx ==
706 (priv->wep_key_curr_index & KEY_INDEX_MASK))
707 key_info |= KEY_DEFAULT;
708 } else {
709 if (mac) {
710 if (is_broadcast_ether_addr(mac))
711 key_info |= KEY_MCAST;
712 else
713 key_info |= KEY_UNICAST |
714 KEY_DEFAULT;
715 } else {
716 key_info |= KEY_MCAST;
717 }
718 }
719 }
720 km->key_param_set.key_info = cpu_to_le16(key_info);
721
722 km->key_param_set.key_params.wep.key_len =
723 cpu_to_le16(enc_key->key_len);
724 memcpy(km->key_param_set.key_params.wep.key,
725 enc_key->key_material, enc_key->key_len);
726
727 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
728 len + sizeof(km->action) + S_DS_GEN);
729 return 0;
730 }
731
732 if (is_broadcast_ether_addr(mac))
733 key_info |= KEY_MCAST | KEY_RX_KEY;
734 else
735 key_info |= KEY_UNICAST | KEY_TX_KEY | KEY_RX_KEY;
736
737 if (enc_key->is_wapi_key) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530738 mwifiex_dbg(adapter, INFO, "%s: Set WAPI Key\n", __func__);
Avinash Patile57f1732014-02-07 16:32:35 -0800739 km->key_param_set.key_type = KEY_TYPE_ID_WAPI;
740 memcpy(km->key_param_set.key_params.wapi.pn, enc_key->pn,
741 PN_LEN);
742 km->key_param_set.key_params.wapi.key_len =
743 cpu_to_le16(enc_key->key_len);
744 memcpy(km->key_param_set.key_params.wapi.key,
745 enc_key->key_material, enc_key->key_len);
746 if (is_broadcast_ether_addr(mac))
747 priv->sec_info.wapi_key_on = true;
748
749 if (!priv->sec_info.wapi_key_on)
750 key_info |= KEY_DEFAULT;
751 km->key_param_set.key_info = cpu_to_le16(key_info);
752
753 len += sizeof(struct mwifiex_wapi_param);
754 km->key_param_set.len = cpu_to_le16(len);
755 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
756 len + sizeof(km->action) + S_DS_GEN);
757 return 0;
758 }
759
760 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
761 key_info |= KEY_DEFAULT;
762 /* Enable unicast bit for WPA-NONE/ADHOC_AES */
763 if (!priv->sec_info.wpa2_enabled &&
764 !is_broadcast_ether_addr(mac))
765 key_info |= KEY_UNICAST;
766 } else {
767 /* Enable default key for WPA/WPA2 */
768 if (!priv->wpa_is_gtk_set)
769 key_info |= KEY_DEFAULT;
770 }
771
772 km->key_param_set.key_info = cpu_to_le16(key_info);
773
774 if (enc_key->key_len == WLAN_KEY_LEN_CCMP)
775 return mwifiex_set_aes_key_v2(priv, cmd, enc_key, km);
776
777 if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530778 mwifiex_dbg(adapter, INFO,
779 "%s: Set TKIP Key\n", __func__);
Avinash Patile57f1732014-02-07 16:32:35 -0800780 if (enc_key->is_rx_seq_valid)
781 memcpy(km->key_param_set.key_params.tkip.pn,
782 enc_key->pn, enc_key->pn_len);
783 km->key_param_set.key_type = KEY_TYPE_ID_TKIP;
784 km->key_param_set.key_params.tkip.key_len =
785 cpu_to_le16(enc_key->key_len);
786 memcpy(km->key_param_set.key_params.tkip.key,
787 enc_key->key_material, enc_key->key_len);
788
789 len += sizeof(struct mwifiex_tkip_param);
790 km->key_param_set.len = cpu_to_le16(len);
791 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
792 len + sizeof(km->action) + S_DS_GEN);
793 }
794
795 return 0;
796}
797
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700798/*
799 * This function prepares command to set/get/reset network key(s).
Avinash Patile57f1732014-02-07 16:32:35 -0800800 * This function prepares key material command for V1 format.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700801 *
802 * Preparation includes -
803 * - Setting command ID, action and proper size
804 * - Setting WEP keys, WAPI keys or WPA keys along with required
805 * encryption (TKIP, AES) (as required)
806 * - Ensuring correct endian-ness
807 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700808static int
Avinash Patile57f1732014-02-07 16:32:35 -0800809mwifiex_cmd_802_11_key_material_v1(struct mwifiex_private *priv,
810 struct host_cmd_ds_command *cmd,
811 u16 cmd_action, u32 cmd_oid,
812 struct mwifiex_ds_encrypt_key *enc_key)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700813{
814 struct host_cmd_ds_802_11_key_material *key_material =
815 &cmd->params.key_material;
Avinash Patil75edd2c2012-05-08 18:30:18 -0700816 struct host_cmd_tlv_mac_addr *tlv_mac;
817 u16 key_param_len = 0, cmd_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700818 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700819
820 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
821 key_material->action = cpu_to_le16(cmd_action);
822
823 if (cmd_action == HostCmd_ACT_GEN_GET) {
824 cmd->size =
825 cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
826 return ret;
827 }
828
829 if (!enc_key) {
830 memset(&key_material->key_param_set, 0,
831 (NUM_WEP_KEYS *
832 sizeof(struct mwifiex_ie_type_key_param_set)));
833 ret = mwifiex_set_keyparamset_wep(priv,
834 &key_material->key_param_set,
835 &key_param_len);
836 cmd->size = cpu_to_le16(key_param_len +
837 sizeof(key_material->action) + S_DS_GEN);
838 return ret;
839 } else
840 memset(&key_material->key_param_set, 0,
841 sizeof(struct mwifiex_ie_type_key_param_set));
842 if (enc_key->is_wapi_key) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530843 mwifiex_dbg(priv->adapter, INFO, "info: Set WAPI Key\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700844 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700845 cpu_to_le16(KEY_TYPE_ID_WAPI);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700846 if (cmd_oid == KEY_INFO_ENABLED)
847 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700848 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700849 else
850 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700851 cpu_to_le16(!KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700852
853 key_material->key_param_set.key[0] = enc_key->key_index;
854 if (!priv->sec_info.wapi_key_on)
855 key_material->key_param_set.key[1] = 1;
856 else
857 /* set 0 when re-key */
858 key_material->key_param_set.key[1] = 0;
859
Wei Yongjuna71bf902012-08-24 13:25:30 +0800860 if (!is_broadcast_ether_addr(enc_key->mac_addr)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700861 /* WAPI pairwise key: unicast */
862 key_material->key_param_set.key_info |=
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700863 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700864 } else { /* WAPI group key: multicast */
865 key_material->key_param_set.key_info |=
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700866 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700867 priv->sec_info.wapi_key_on = true;
868 }
869
870 key_material->key_param_set.type =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700871 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700872 key_material->key_param_set.key_len =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700873 cpu_to_le16(WAPI_KEY_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700874 memcpy(&key_material->key_param_set.key[2],
875 enc_key->key_material, enc_key->key_len);
876 memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
Ying Luo9d7aba62012-08-03 18:06:12 -0700877 enc_key->pn, PN_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700878 key_material->key_param_set.length =
879 cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
880
881 key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
882 sizeof(struct mwifiex_ie_types_header);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700883 cmd->size = cpu_to_le16(sizeof(key_material->action)
884 + S_DS_GEN + key_param_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700885 return ret;
886 }
887 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
Ying Luob877f4c2012-08-03 18:06:14 -0700888 if (enc_key->is_igtk_key) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530889 mwifiex_dbg(priv->adapter, CMD, "cmd: CMAC_AES\n");
Ying Luob877f4c2012-08-03 18:06:14 -0700890 key_material->key_param_set.key_type_id =
891 cpu_to_le16(KEY_TYPE_ID_AES_CMAC);
892 if (cmd_oid == KEY_INFO_ENABLED)
893 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700894 cpu_to_le16(KEY_ENABLED);
Ying Luob877f4c2012-08-03 18:06:14 -0700895 else
896 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700897 cpu_to_le16(!KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700898
Ying Luob877f4c2012-08-03 18:06:14 -0700899 key_material->key_param_set.key_info |=
900 cpu_to_le16(KEY_IGTK);
901 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530902 mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_AES\n");
Ying Luob877f4c2012-08-03 18:06:14 -0700903 key_material->key_param_set.key_type_id =
904 cpu_to_le16(KEY_TYPE_ID_AES);
905 if (cmd_oid == KEY_INFO_ENABLED)
906 key_material->key_param_set.key_info =
907 cpu_to_le16(KEY_ENABLED);
908 else
909 key_material->key_param_set.key_info =
910 cpu_to_le16(!KEY_ENABLED);
911
912 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700913 /* AES pairwise key: unicast */
Ying Luob877f4c2012-08-03 18:06:14 -0700914 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700915 cpu_to_le16(KEY_UNICAST);
Ying Luob877f4c2012-08-03 18:06:14 -0700916 else /* AES group key: multicast */
917 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700918 cpu_to_le16(KEY_MCAST);
Ying Luob877f4c2012-08-03 18:06:14 -0700919 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700920 } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530921 mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_TKIP\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700922 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700923 cpu_to_le16(KEY_TYPE_ID_TKIP);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700924 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700925 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700926
927 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
928 /* TKIP pairwise key: unicast */
929 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700930 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700931 else /* TKIP group key: multicast */
932 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700933 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700934 }
935
936 if (key_material->key_param_set.key_type_id) {
937 key_material->key_param_set.type =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700938 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700939 key_material->key_param_set.key_len =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700940 cpu_to_le16((u16) enc_key->key_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700941 memcpy(key_material->key_param_set.key, enc_key->key_material,
942 enc_key->key_len);
943 key_material->key_param_set.length =
944 cpu_to_le16((u16) enc_key->key_len +
945 KEYPARAMSET_FIXED_LEN);
946
Avinash Patil75edd2c2012-05-08 18:30:18 -0700947 key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700948 + sizeof(struct mwifiex_ie_types_header);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700949
Ying Luob877f4c2012-08-03 18:06:14 -0700950 if (le16_to_cpu(key_material->key_param_set.key_type_id) ==
951 KEY_TYPE_ID_AES_CMAC) {
952 struct mwifiex_cmac_param *param =
953 (void *)key_material->key_param_set.key;
954
955 memcpy(param->ipn, enc_key->pn, IGTK_PN_LEN);
956 memcpy(param->key, enc_key->key_material,
Bing Zhao641c8692012-08-08 19:01:52 -0700957 WLAN_KEY_LEN_AES_CMAC);
Ying Luob877f4c2012-08-03 18:06:14 -0700958
959 key_param_len = sizeof(struct mwifiex_cmac_param);
960 key_material->key_param_set.key_len =
961 cpu_to_le16(key_param_len);
962 key_param_len += KEYPARAMSET_FIXED_LEN;
963 key_material->key_param_set.length =
964 cpu_to_le16(key_param_len);
965 key_param_len += sizeof(struct mwifiex_ie_types_header);
966 }
967
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700968 cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
969 + key_param_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -0700970
Maithili Hinge8342bda2014-09-30 16:29:38 +0530971 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
Avinash Patil75edd2c2012-05-08 18:30:18 -0700972 tlv_mac = (void *)((u8 *)&key_material->key_param_set +
973 key_param_len);
Amitkumar Karwar6b21a692013-07-22 19:17:57 -0700974 tlv_mac->header.type =
975 cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
976 tlv_mac->header.len = cpu_to_le16(ETH_ALEN);
Avinash Patil75edd2c2012-05-08 18:30:18 -0700977 memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
978 cmd_size = key_param_len + S_DS_GEN +
979 sizeof(key_material->action) +
980 sizeof(struct host_cmd_tlv_mac_addr);
981 } else {
982 cmd_size = key_param_len + S_DS_GEN +
983 sizeof(key_material->action);
984 }
985 cmd->size = cpu_to_le16(cmd_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700986 }
987
988 return ret;
989}
990
Avinash Patile57f1732014-02-07 16:32:35 -0800991/* Wrapper function for setting network key depending upon FW KEY API version */
992static int
993mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
994 struct host_cmd_ds_command *cmd,
995 u16 cmd_action, u32 cmd_oid,
996 struct mwifiex_ds_encrypt_key *enc_key)
997{
Amitkumar Karwar4b9fede2014-08-19 08:24:25 -0400998 if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
Avinash Patile57f1732014-02-07 16:32:35 -0800999 return mwifiex_cmd_802_11_key_material_v2(priv, cmd,
1000 cmd_action, cmd_oid,
1001 enc_key);
1002
1003 else
1004 return mwifiex_cmd_802_11_key_material_v1(priv, cmd,
1005 cmd_action, cmd_oid,
1006 enc_key);
1007}
1008
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001009/*
1010 * This function prepares command to set/get 11d domain information.
1011 *
1012 * Preparation includes -
1013 * - Setting command ID, action and proper size
1014 * - Setting domain information fields (for SET only)
1015 * - Ensuring correct endian-ness
1016 */
1017static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
1018 struct host_cmd_ds_command *cmd,
1019 u16 cmd_action)
1020{
1021 struct mwifiex_adapter *adapter = priv->adapter;
1022 struct host_cmd_ds_802_11d_domain_info *domain_info =
1023 &cmd->params.domain_info;
1024 struct mwifiex_ietypes_domain_param_set *domain =
1025 &domain_info->domain;
1026 u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
1027
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301028 mwifiex_dbg(adapter, INFO,
1029 "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001030
1031 cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
1032 domain_info->action = cpu_to_le16(cmd_action);
1033 if (cmd_action == HostCmd_ACT_GEN_GET) {
1034 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1035 return 0;
1036 }
1037
1038 /* Set domain info fields */
1039 domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
1040 memcpy(domain->country_code, adapter->domain_reg.country_code,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001041 sizeof(domain->country_code));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001042
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001043 domain->header.len =
1044 cpu_to_le16((no_of_triplet *
1045 sizeof(struct ieee80211_country_ie_triplet))
1046 + sizeof(domain->country_code));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001047
1048 if (no_of_triplet) {
1049 memcpy(domain->triplet, adapter->domain_reg.triplet,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001050 no_of_triplet * sizeof(struct
1051 ieee80211_country_ie_triplet));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001052
1053 cmd->size = cpu_to_le16(sizeof(domain_info->action) +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001054 le16_to_cpu(domain->header.len) +
1055 sizeof(struct mwifiex_ie_types_header)
1056 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001057 } else {
1058 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1059 }
1060
1061 return 0;
1062}
1063
1064/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001065 * This function prepares command to set/get IBSS coalescing status.
1066 *
1067 * Preparation includes -
1068 * - Setting command ID, action and proper size
1069 * - Setting status to enable or disable (for SET only)
1070 * - Ensuring correct endian-ness
1071 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001072static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001073 u16 cmd_action, u16 *enable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001074{
1075 struct host_cmd_ds_802_11_ibss_status *ibss_coal =
1076 &(cmd->params.ibss_coalescing);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001077
1078 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
1079 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
1080 S_DS_GEN);
1081 cmd->result = 0;
1082 ibss_coal->action = cpu_to_le16(cmd_action);
1083
1084 switch (cmd_action) {
1085 case HostCmd_ACT_GEN_SET:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001086 if (enable)
1087 ibss_coal->enable = cpu_to_le16(*enable);
Dan Carpentera5e5aa62011-06-24 16:33:35 +03001088 else
1089 ibss_coal->enable = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001090 break;
1091
1092 /* In other case.. Nothing to do */
1093 case HostCmd_ACT_GEN_GET:
1094 default:
1095 break;
1096 }
1097
1098 return 0;
1099}
1100
Chin-ran Loc2c6c852015-05-12 00:48:17 +05301101/* This function prepares command buffer to get/set memory location value.
1102 */
1103static int
1104mwifiex_cmd_mem_access(struct host_cmd_ds_command *cmd, u16 cmd_action,
1105 void *pdata_buf)
1106{
1107 struct mwifiex_ds_mem_rw *mem_rw = (void *)pdata_buf;
1108 struct host_cmd_ds_mem_access *mem_access = (void *)&cmd->params.mem;
1109
1110 cmd->command = cpu_to_le16(HostCmd_CMD_MEM_ACCESS);
1111 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mem_access) +
1112 S_DS_GEN);
1113
1114 mem_access->action = cpu_to_le16(cmd_action);
1115 mem_access->addr = cpu_to_le32(mem_rw->addr);
1116 mem_access->value = cpu_to_le32(mem_rw->value);
1117
1118 return 0;
1119}
1120
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001121/*
1122 * This function prepares command to set/get register value.
1123 *
1124 * Preparation includes -
1125 * - Setting command ID, action and proper size
1126 * - Setting register offset (for both GET and SET) and
1127 * register value (for SET only)
1128 * - Ensuring correct endian-ness
1129 *
1130 * The following type of registers can be accessed with this function -
1131 * - MAC register
1132 * - BBP register
1133 * - RF register
1134 * - PMIC register
1135 * - CAU register
1136 * - EEPROM
1137 */
1138static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
1139 u16 cmd_action, void *data_buf)
1140{
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001141 struct mwifiex_ds_reg_rw *reg_rw = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001142
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001143 switch (le16_to_cpu(cmd->command)) {
1144 case HostCmd_CMD_MAC_REG_ACCESS:
1145 {
1146 struct host_cmd_ds_mac_reg_access *mac_reg;
1147
1148 cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001149 mac_reg = &cmd->params.mac_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001150 mac_reg->action = cpu_to_le16(cmd_action);
1151 mac_reg->offset =
1152 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
1153 mac_reg->value = reg_rw->value;
1154 break;
1155 }
1156 case HostCmd_CMD_BBP_REG_ACCESS:
1157 {
1158 struct host_cmd_ds_bbp_reg_access *bbp_reg;
1159
1160 cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001161 bbp_reg = &cmd->params.bbp_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001162 bbp_reg->action = cpu_to_le16(cmd_action);
1163 bbp_reg->offset =
1164 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
1165 bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
1166 break;
1167 }
1168 case HostCmd_CMD_RF_REG_ACCESS:
1169 {
1170 struct host_cmd_ds_rf_reg_access *rf_reg;
1171
1172 cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001173 rf_reg = &cmd->params.rf_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001174 rf_reg->action = cpu_to_le16(cmd_action);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001175 rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001176 rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
1177 break;
1178 }
1179 case HostCmd_CMD_PMIC_REG_ACCESS:
1180 {
1181 struct host_cmd_ds_pmic_reg_access *pmic_reg;
1182
1183 cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001184 pmic_reg = &cmd->params.pmic_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001185 pmic_reg->action = cpu_to_le16(cmd_action);
1186 pmic_reg->offset =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001187 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001188 pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
1189 break;
1190 }
1191 case HostCmd_CMD_CAU_REG_ACCESS:
1192 {
1193 struct host_cmd_ds_rf_reg_access *cau_reg;
1194
1195 cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
Joe Perches2c208892012-06-04 12:44:17 +00001196 cau_reg = &cmd->params.rf_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001197 cau_reg->action = cpu_to_le16(cmd_action);
1198 cau_reg->offset =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001199 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001200 cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
1201 break;
1202 }
1203 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1204 {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001205 struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001206 struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207 &cmd->params.eeprom;
1208
1209 cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
1210 cmd_eeprom->action = cpu_to_le16(cmd_action);
1211 cmd_eeprom->offset = rd_eeprom->offset;
1212 cmd_eeprom->byte_count = rd_eeprom->byte_count;
1213 cmd_eeprom->value = 0;
1214 break;
1215 }
1216 default:
1217 return -1;
1218 }
1219
1220 return 0;
1221}
1222
1223/*
Amitkumar Karward930fae2011-10-11 17:41:21 -07001224 * This function prepares command to set PCI-Express
1225 * host buffer configuration
1226 *
1227 * Preparation includes -
1228 * - Setting command ID, action and proper size
1229 * - Setting host buffer configuration
1230 * - Ensuring correct endian-ness
1231 */
1232static int
1233mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001234 struct host_cmd_ds_command *cmd, u16 action)
Amitkumar Karward930fae2011-10-11 17:41:21 -07001235{
1236 struct host_cmd_ds_pcie_details *host_spec =
1237 &cmd->params.pcie_host_spec;
1238 struct pcie_service_card *card = priv->adapter->card;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001239
1240 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
1241 cmd->size = cpu_to_le16(sizeof(struct
1242 host_cmd_ds_pcie_details) + S_DS_GEN);
1243 cmd->result = 0;
1244
1245 memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
1246
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001247 if (action != HostCmd_ACT_GEN_SET)
1248 return 0;
1249
1250 /* Send the ring base addresses and count to firmware */
1251 host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
1252 host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
1253 host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
1254 host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
1255 host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
1256 host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
1257 host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
1258 host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
1259 host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
Avinash Patilfc331462013-01-03 21:21:30 -08001260 if (card->sleep_cookie_vbase) {
1261 host_spec->sleep_cookie_addr_lo =
1262 (u32)(card->sleep_cookie_pbase);
1263 host_spec->sleep_cookie_addr_hi =
1264 (u32)(((u64)(card->sleep_cookie_pbase)) >> 32);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301265 mwifiex_dbg(priv->adapter, INFO,
1266 "sleep_cook_lo phy addr: 0x%x\n",
1267 host_spec->sleep_cookie_addr_lo);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001268 }
1269
1270 return 0;
1271}
1272
1273/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001274 * This function prepares command for event subscription, configuration
1275 * and query. Events can be subscribed or unsubscribed. Current subscribed
1276 * events can be queried. Also, current subscribed events are reported in
1277 * every FW response.
1278 */
1279static int
1280mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
1281 struct host_cmd_ds_command *cmd,
1282 struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
1283{
1284 struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
1285 struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
1286 u16 event_bitmap;
1287 u8 *pos;
1288
1289 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
1290 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
1291 S_DS_GEN);
1292
1293 subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301294 mwifiex_dbg(priv->adapter, CMD,
1295 "cmd: action: %d\n", subsc_evt_cfg->action);
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001296
1297 /*For query requests, no configuration TLV structures are to be added.*/
1298 if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
1299 return 0;
1300
1301 subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
1302
1303 event_bitmap = subsc_evt_cfg->events;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301304 mwifiex_dbg(priv->adapter, CMD, "cmd: event bitmap : %16x\n",
1305 event_bitmap);
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001306
1307 if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
1308 (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
1309 (event_bitmap == 0)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301310 mwifiex_dbg(priv->adapter, ERROR,
1311 "Error: No event specified\t"
1312 "for bitwise action type\n");
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001313 return -EINVAL;
1314 }
1315
1316 /*
1317 * Append TLV structures for each of the specified events for
1318 * subscribing or re-configuring. This is not required for
1319 * bitwise unsubscribing request.
1320 */
1321 if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
1322 return 0;
1323
1324 pos = ((u8 *)subsc_evt) +
1325 sizeof(struct host_cmd_ds_802_11_subsc_evt);
1326
1327 if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
1328 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1329
1330 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
1331 rssi_tlv->header.len =
1332 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1333 sizeof(struct mwifiex_ie_types_header));
1334 rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
1335 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
1336
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301337 mwifiex_dbg(priv->adapter, EVENT,
1338 "Cfg Beacon Low Rssi event,\t"
1339 "RSSI:-%d dBm, Freq:%d\n",
1340 subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
1341 subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001342
1343 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1344 le16_add_cpu(&cmd->size,
1345 sizeof(struct mwifiex_ie_types_rssi_threshold));
1346 }
1347
1348 if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
1349 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1350
1351 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1352 rssi_tlv->header.len =
1353 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1354 sizeof(struct mwifiex_ie_types_header));
1355 rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
1356 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
1357
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301358 mwifiex_dbg(priv->adapter, EVENT,
1359 "Cfg Beacon High Rssi event,\t"
1360 "RSSI:-%d dBm, Freq:%d\n",
1361 subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
1362 subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001363
1364 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1365 le16_add_cpu(&cmd->size,
1366 sizeof(struct mwifiex_ie_types_rssi_threshold));
1367 }
1368
1369 return 0;
1370}
1371
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001372static int
1373mwifiex_cmd_append_rpn_expression(struct mwifiex_private *priv,
1374 struct mwifiex_mef_entry *mef_entry,
1375 u8 **buffer)
1376{
1377 struct mwifiex_mef_filter *filter = mef_entry->filter;
1378 int i, byte_len;
1379 u8 *stack_ptr = *buffer;
1380
Amitkumar Karwar3f4e8542013-08-05 18:51:57 -07001381 for (i = 0; i < MWIFIEX_MEF_MAX_FILTERS; i++) {
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001382 filter = &mef_entry->filter[i];
1383 if (!filter->filt_type)
1384 break;
1385 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->repeat);
1386 stack_ptr += 4;
1387 *stack_ptr = TYPE_DNUM;
1388 stack_ptr += 1;
1389
Amitkumar Karwar3f4e8542013-08-05 18:51:57 -07001390 byte_len = filter->byte_seq[MWIFIEX_MEF_MAX_BYTESEQ];
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001391 memcpy(stack_ptr, filter->byte_seq, byte_len);
1392 stack_ptr += byte_len;
1393 *stack_ptr = byte_len;
1394 stack_ptr += 1;
1395 *stack_ptr = TYPE_BYTESEQ;
1396 stack_ptr += 1;
1397
1398 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->offset);
1399 stack_ptr += 4;
1400 *stack_ptr = TYPE_DNUM;
1401 stack_ptr += 1;
1402
1403 *stack_ptr = filter->filt_type;
1404 stack_ptr += 1;
1405
1406 if (filter->filt_action) {
1407 *stack_ptr = filter->filt_action;
1408 stack_ptr += 1;
1409 }
1410
1411 if (stack_ptr - *buffer > STACK_NBYTES)
1412 return -1;
1413 }
1414
1415 *buffer = stack_ptr;
1416 return 0;
1417}
1418
1419static int
1420mwifiex_cmd_mef_cfg(struct mwifiex_private *priv,
1421 struct host_cmd_ds_command *cmd,
1422 struct mwifiex_ds_mef_cfg *mef)
1423{
1424 struct host_cmd_ds_mef_cfg *mef_cfg = &cmd->params.mef_cfg;
Maithili Hingeb533be12015-03-12 00:38:39 -07001425 struct mwifiex_fw_mef_entry *mef_entry = NULL;
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001426 u8 *pos = (u8 *)mef_cfg;
Maithili Hingeb533be12015-03-12 00:38:39 -07001427 u16 i;
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001428
1429 cmd->command = cpu_to_le16(HostCmd_CMD_MEF_CFG);
1430
1431 mef_cfg->criteria = cpu_to_le32(mef->criteria);
1432 mef_cfg->num_entries = cpu_to_le16(mef->num_entries);
1433 pos += sizeof(*mef_cfg);
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001434
Maithili Hingeb533be12015-03-12 00:38:39 -07001435 for (i = 0; i < mef->num_entries; i++) {
1436 mef_entry = (struct mwifiex_fw_mef_entry *)pos;
1437 mef_entry->mode = mef->mef_entry[i].mode;
1438 mef_entry->action = mef->mef_entry[i].action;
1439 pos += sizeof(*mef_cfg->mef_entry);
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001440
Maithili Hingeb533be12015-03-12 00:38:39 -07001441 if (mwifiex_cmd_append_rpn_expression(priv,
1442 &mef->mef_entry[i], &pos))
1443 return -1;
1444
1445 mef_entry->exprsize =
1446 cpu_to_le16(pos - mef_entry->expr);
1447 }
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08001448 cmd->size = cpu_to_le16((u16) (pos - (u8 *)mef_cfg) + S_DS_GEN);
1449
1450 return 0;
1451}
1452
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001453/* This function parse cal data from ASCII to hex */
1454static u32 mwifiex_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
1455{
1456 u8 *s = src, *d = dst;
1457
1458 while (s - src < len) {
1459 if (*s && (isspace(*s) || *s == '\t')) {
1460 s++;
1461 continue;
1462 }
1463 if (isxdigit(*s)) {
1464 *d++ = simple_strtol(s, NULL, 16);
1465 s += 2;
1466 } else {
1467 s++;
1468 }
1469 }
1470
1471 return d - dst;
1472}
1473
Bing Zhao82efa162013-12-13 18:33:02 -08001474int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv,
1475 struct device_node *node, const char *prefix)
Bing Zhao699b0272013-12-13 18:33:01 -08001476{
1477#ifdef CONFIG_OF
1478 struct property *prop;
1479 size_t len = strlen(prefix);
1480 int ret;
1481
1482 /* look for all matching property names */
1483 for_each_property_of_node(node, prop) {
1484 if (len > strlen(prop->name) ||
1485 strncmp(prop->name, prefix, len))
1486 continue;
1487
Bing Zhao63791cc2014-01-08 15:45:56 -08001488 /* property header is 6 bytes, data must fit in cmd buffer */
1489 if (prop && prop->value && prop->length > 6 &&
1490 prop->length <= MWIFIEX_SIZE_OF_CMD_BUFFER - S_DS_GEN) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001491 ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
1492 HostCmd_ACT_GEN_SET, 0,
1493 prop, true);
Bing Zhao699b0272013-12-13 18:33:01 -08001494 if (ret)
1495 return ret;
1496 }
1497 }
1498#endif
1499 return 0;
1500}
1501
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001502/* This function prepares command of set_cfg_data. */
1503static int mwifiex_cmd_cfg_data(struct mwifiex_private *priv,
Bing Zhao699b0272013-12-13 18:33:01 -08001504 struct host_cmd_ds_command *cmd, void *data_buf)
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001505{
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001506 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao699b0272013-12-13 18:33:01 -08001507 struct property *prop = data_buf;
Bing Zhaod39fbc82013-12-13 18:33:00 -08001508 u32 len;
1509 u8 *data = (u8 *)cmd + S_DS_GEN;
Bing Zhao699b0272013-12-13 18:33:01 -08001510 int ret;
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001511
Bing Zhao699b0272013-12-13 18:33:01 -08001512 if (prop) {
1513 len = prop->length;
1514 ret = of_property_read_u8_array(adapter->dt_node, prop->name,
1515 data, len);
1516 if (ret)
1517 return ret;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301518 mwifiex_dbg(adapter, INFO,
1519 "download cfg_data from device tree: %s\n",
1520 prop->name);
Bing Zhao699b0272013-12-13 18:33:01 -08001521 } else if (adapter->cal_data->data && adapter->cal_data->size > 0) {
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001522 len = mwifiex_parse_cal_cfg((u8 *)adapter->cal_data->data,
Bing Zhaod39fbc82013-12-13 18:33:00 -08001523 adapter->cal_data->size, data);
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301524 mwifiex_dbg(adapter, INFO,
1525 "download cfg_data from config file\n");
Bing Zhao699b0272013-12-13 18:33:01 -08001526 } else {
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001527 return -1;
Bing Zhao699b0272013-12-13 18:33:01 -08001528 }
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001529
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001530 cmd->command = cpu_to_le16(HostCmd_CMD_CFG_DATA);
Bing Zhaod39fbc82013-12-13 18:33:00 -08001531 cmd->size = cpu_to_le16(S_DS_GEN + len);
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001532
1533 return 0;
1534}
1535
Amitkumar Karwar562fc5b2013-08-05 18:52:00 -07001536static int
Avinash Patild5b036c2015-06-22 19:06:20 +05301537mwifiex_cmd_set_mc_policy(struct mwifiex_private *priv,
1538 struct host_cmd_ds_command *cmd,
1539 u16 cmd_action, void *data_buf)
1540{
1541 struct host_cmd_ds_multi_chan_policy *mc_pol = &cmd->params.mc_policy;
1542 const u16 *drcs_info = data_buf;
1543
1544 mc_pol->action = cpu_to_le16(cmd_action);
1545 mc_pol->policy = cpu_to_le16(*drcs_info);
1546 cmd->command = cpu_to_le16(HostCmd_CMD_MC_POLICY);
1547 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_multi_chan_policy) +
1548 S_DS_GEN);
1549 return 0;
1550}
1551
Amitkumar Karwar46dbe242015-10-09 04:26:23 -07001552static int mwifiex_cmd_robust_coex(struct mwifiex_private *priv,
1553 struct host_cmd_ds_command *cmd,
1554 u16 cmd_action, bool *is_timeshare)
1555{
1556 struct host_cmd_ds_robust_coex *coex = &cmd->params.coex;
1557 struct mwifiex_ie_types_robust_coex *coex_tlv;
1558
1559 cmd->command = cpu_to_le16(HostCmd_CMD_ROBUST_COEX);
1560 cmd->size = cpu_to_le16(sizeof(*coex) + sizeof(*coex_tlv) + S_DS_GEN);
1561
1562 coex->action = cpu_to_le16(cmd_action);
1563 coex_tlv = (struct mwifiex_ie_types_robust_coex *)
1564 ((u8 *)coex + sizeof(*coex));
1565 coex_tlv->header.type = cpu_to_le16(TLV_TYPE_ROBUST_COEX);
1566 coex_tlv->header.len = cpu_to_le16(sizeof(coex_tlv->mode));
1567
1568 if (coex->action == HostCmd_ACT_GEN_GET)
1569 return 0;
1570
1571 if (*is_timeshare)
1572 coex_tlv->mode = cpu_to_le32(MWIFIEX_COEX_MODE_TIMESHARE);
1573 else
1574 coex_tlv->mode = cpu_to_le32(MWIFIEX_COEX_MODE_SPATIAL);
1575
1576 return 0;
1577}
1578
Ganapathi Bhatf6b1cbe2016-04-05 01:04:34 -07001579static int mwifiex_cmd_gtk_rekey_offload(struct mwifiex_private *priv,
1580 struct host_cmd_ds_command *cmd,
1581 u16 cmd_action,
1582 struct cfg80211_gtk_rekey_data *data)
1583{
1584 struct host_cmd_ds_gtk_rekey_params *rekey = &cmd->params.rekey;
1585 u64 rekey_ctr;
1586
1587 cmd->command = cpu_to_le16(HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG);
1588 cmd->size = cpu_to_le16(sizeof(*rekey) + S_DS_GEN);
1589
1590 rekey->action = cpu_to_le16(cmd_action);
1591 if (cmd_action == HostCmd_ACT_GEN_SET) {
1592 memcpy(rekey->kek, data->kek, NL80211_KEK_LEN);
1593 memcpy(rekey->kck, data->kck, NL80211_KCK_LEN);
1594 rekey_ctr = be64_to_cpup((__be64 *)data->replay_ctr);
1595 rekey->replay_ctr_low = cpu_to_le32((u32)rekey_ctr);
1596 rekey->replay_ctr_high =
1597 cpu_to_le32((u32)((u64)rekey_ctr >> 32));
1598 }
1599
1600 return 0;
1601}
1602
Avinash Patild5b036c2015-06-22 19:06:20 +05301603static int
Amitkumar Karwar562fc5b2013-08-05 18:52:00 -07001604mwifiex_cmd_coalesce_cfg(struct mwifiex_private *priv,
1605 struct host_cmd_ds_command *cmd,
1606 u16 cmd_action, void *data_buf)
1607{
1608 struct host_cmd_ds_coalesce_cfg *coalesce_cfg =
1609 &cmd->params.coalesce_cfg;
1610 struct mwifiex_ds_coalesce_cfg *cfg = data_buf;
1611 struct coalesce_filt_field_param *param;
1612 u16 cnt, idx, length;
1613 struct coalesce_receive_filt_rule *rule;
1614
1615 cmd->command = cpu_to_le16(HostCmd_CMD_COALESCE_CFG);
1616 cmd->size = cpu_to_le16(S_DS_GEN);
1617
1618 coalesce_cfg->action = cpu_to_le16(cmd_action);
1619 coalesce_cfg->num_of_rules = cpu_to_le16(cfg->num_of_rules);
1620 rule = coalesce_cfg->rule;
1621
1622 for (cnt = 0; cnt < cfg->num_of_rules; cnt++) {
1623 rule->header.type = cpu_to_le16(TLV_TYPE_COALESCE_RULE);
1624 rule->max_coalescing_delay =
1625 cpu_to_le16(cfg->rule[cnt].max_coalescing_delay);
1626 rule->pkt_type = cfg->rule[cnt].pkt_type;
1627 rule->num_of_fields = cfg->rule[cnt].num_of_fields;
1628
1629 length = 0;
1630
1631 param = rule->params;
1632 for (idx = 0; idx < cfg->rule[cnt].num_of_fields; idx++) {
1633 param->operation = cfg->rule[cnt].params[idx].operation;
1634 param->operand_len =
1635 cfg->rule[cnt].params[idx].operand_len;
1636 param->offset =
1637 cpu_to_le16(cfg->rule[cnt].params[idx].offset);
1638 memcpy(param->operand_byte_stream,
1639 cfg->rule[cnt].params[idx].operand_byte_stream,
1640 param->operand_len);
1641
1642 length += sizeof(struct coalesce_filt_field_param);
1643
1644 param++;
1645 }
1646
1647 /* Total rule length is sizeof max_coalescing_delay(u16),
1648 * num_of_fields(u8), pkt_type(u8) and total length of the all
1649 * params
1650 */
1651 rule->header.len = cpu_to_le16(length + sizeof(u16) +
1652 sizeof(u8) + sizeof(u8));
1653
1654 /* Add the rule length to the command size*/
1655 le16_add_cpu(&cmd->size, le16_to_cpu(rule->header.len) +
1656 sizeof(struct mwifiex_ie_types_header));
1657
1658 rule = (void *)((u8 *)rule->params + length);
1659 }
1660
1661 /* Add sizeof action, num_of_rules to total command length */
1662 le16_add_cpu(&cmd->size, sizeof(u16) + sizeof(u16));
1663
1664 return 0;
1665}
1666
Avinash Patil429d90d2014-02-07 16:27:34 -08001667static int
Xinming Hu449b8bb2015-06-22 19:06:12 +05301668mwifiex_cmd_tdls_config(struct mwifiex_private *priv,
1669 struct host_cmd_ds_command *cmd,
1670 u16 cmd_action, void *data_buf)
1671{
1672 struct host_cmd_ds_tdls_config *tdls_config = &cmd->params.tdls_config;
1673 struct mwifiex_tdls_init_cs_params *config;
1674 struct mwifiex_tdls_config *init_config;
1675 u16 len;
1676
1677 cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_CONFIG);
1678 cmd->size = cpu_to_le16(S_DS_GEN);
1679 tdls_config->tdls_action = cpu_to_le16(cmd_action);
1680 le16_add_cpu(&cmd->size, sizeof(tdls_config->tdls_action));
1681
1682 switch (cmd_action) {
1683 case ACT_TDLS_CS_ENABLE_CONFIG:
1684 init_config = data_buf;
1685 len = sizeof(*init_config);
1686 memcpy(tdls_config->tdls_data, init_config, len);
1687 break;
1688 case ACT_TDLS_CS_INIT:
1689 config = data_buf;
1690 len = sizeof(*config);
1691 memcpy(tdls_config->tdls_data, config, len);
1692 break;
1693 case ACT_TDLS_CS_STOP:
1694 len = sizeof(struct mwifiex_tdls_stop_cs_params);
1695 memcpy(tdls_config->tdls_data, data_buf, len);
1696 break;
1697 case ACT_TDLS_CS_PARAMS:
1698 len = sizeof(struct mwifiex_tdls_config_cs_params);
1699 memcpy(tdls_config->tdls_data, data_buf, len);
1700 break;
1701 default:
1702 mwifiex_dbg(priv->adapter, ERROR,
1703 "Unknown TDLS configuration\n");
1704 return -ENOTSUPP;
1705 }
1706
1707 le16_add_cpu(&cmd->size, len);
1708 return 0;
1709}
1710
1711static int
Avinash Patil429d90d2014-02-07 16:27:34 -08001712mwifiex_cmd_tdls_oper(struct mwifiex_private *priv,
1713 struct host_cmd_ds_command *cmd,
1714 void *data_buf)
1715{
1716 struct host_cmd_ds_tdls_oper *tdls_oper = &cmd->params.tdls_oper;
1717 struct mwifiex_ds_tdls_oper *oper = data_buf;
1718 struct mwifiex_sta_node *sta_ptr;
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001719 struct host_cmd_tlv_rates *tlv_rates;
1720 struct mwifiex_ie_types_htcap *ht_capab;
1721 struct mwifiex_ie_types_qos_info *wmm_qos_info;
1722 struct mwifiex_ie_types_extcap *extcap;
Avinash Patil5f6d5982014-02-07 16:30:39 -08001723 struct mwifiex_ie_types_vhtcap *vht_capab;
1724 struct mwifiex_ie_types_aid *aid;
Avinash Patild29caf22014-05-06 22:02:43 -07001725 struct mwifiex_ie_types_tdls_idle_timeout *timeout;
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001726 u8 *pos, qos_info;
1727 u16 config_len = 0;
1728 struct station_parameters *params = priv->sta_params;
Avinash Patil429d90d2014-02-07 16:27:34 -08001729
1730 cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_OPER);
1731 cmd->size = cpu_to_le16(S_DS_GEN);
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001732 le16_add_cpu(&cmd->size, sizeof(struct host_cmd_ds_tdls_oper));
Avinash Patil429d90d2014-02-07 16:27:34 -08001733
1734 tdls_oper->reason = 0;
1735 memcpy(tdls_oper->peer_mac, oper->peer_mac, ETH_ALEN);
1736 sta_ptr = mwifiex_get_sta_entry(priv, oper->peer_mac);
1737
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001738 pos = (u8 *)tdls_oper + sizeof(struct host_cmd_ds_tdls_oper);
1739
Avinash Patil429d90d2014-02-07 16:27:34 -08001740 switch (oper->tdls_action) {
1741 case MWIFIEX_TDLS_DISABLE_LINK:
1742 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_DELETE);
1743 break;
Avinash Patile48e0de2014-02-07 16:30:33 -08001744 case MWIFIEX_TDLS_CREATE_LINK:
1745 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CREATE);
1746 break;
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001747 case MWIFIEX_TDLS_CONFIG_LINK:
1748 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CONFIG);
1749
1750 if (!params) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301751 mwifiex_dbg(priv->adapter, ERROR,
1752 "TDLS config params not available for %pM\n",
1753 oper->peer_mac);
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001754 return -ENODATA;
1755 }
1756
1757 *(__le16 *)pos = cpu_to_le16(params->capability);
1758 config_len += sizeof(params->capability);
1759
1760 qos_info = params->uapsd_queues | (params->max_sp << 5);
1761 wmm_qos_info = (struct mwifiex_ie_types_qos_info *)(pos +
1762 config_len);
1763 wmm_qos_info->header.type = cpu_to_le16(WLAN_EID_QOS_CAPA);
1764 wmm_qos_info->header.len = cpu_to_le16(sizeof(qos_info));
1765 wmm_qos_info->qos_info = qos_info;
1766 config_len += sizeof(struct mwifiex_ie_types_qos_info);
1767
1768 if (params->ht_capa) {
1769 ht_capab = (struct mwifiex_ie_types_htcap *)(pos +
1770 config_len);
1771 ht_capab->header.type =
1772 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1773 ht_capab->header.len =
1774 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
1775 memcpy(&ht_capab->ht_cap, params->ht_capa,
1776 sizeof(struct ieee80211_ht_cap));
1777 config_len += sizeof(struct mwifiex_ie_types_htcap);
1778 }
1779
1780 if (params->supported_rates && params->supported_rates_len) {
1781 tlv_rates = (struct host_cmd_tlv_rates *)(pos +
1782 config_len);
1783 tlv_rates->header.type =
1784 cpu_to_le16(WLAN_EID_SUPP_RATES);
1785 tlv_rates->header.len =
1786 cpu_to_le16(params->supported_rates_len);
1787 memcpy(tlv_rates->rates, params->supported_rates,
1788 params->supported_rates_len);
1789 config_len += sizeof(struct host_cmd_tlv_rates) +
1790 params->supported_rates_len;
1791 }
1792
1793 if (params->ext_capab && params->ext_capab_len) {
1794 extcap = (struct mwifiex_ie_types_extcap *)(pos +
1795 config_len);
1796 extcap->header.type =
1797 cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
1798 extcap->header.len = cpu_to_le16(params->ext_capab_len);
1799 memcpy(extcap->ext_capab, params->ext_capab,
1800 params->ext_capab_len);
1801 config_len += sizeof(struct mwifiex_ie_types_extcap) +
1802 params->ext_capab_len;
1803 }
Avinash Patil5f6d5982014-02-07 16:30:39 -08001804 if (params->vht_capa) {
1805 vht_capab = (struct mwifiex_ie_types_vhtcap *)(pos +
1806 config_len);
1807 vht_capab->header.type =
1808 cpu_to_le16(WLAN_EID_VHT_CAPABILITY);
1809 vht_capab->header.len =
1810 cpu_to_le16(sizeof(struct ieee80211_vht_cap));
1811 memcpy(&vht_capab->vht_cap, params->vht_capa,
1812 sizeof(struct ieee80211_vht_cap));
1813 config_len += sizeof(struct mwifiex_ie_types_vhtcap);
1814 }
1815 if (params->aid) {
1816 aid = (struct mwifiex_ie_types_aid *)(pos + config_len);
1817 aid->header.type = cpu_to_le16(WLAN_EID_AID);
1818 aid->header.len = cpu_to_le16(sizeof(params->aid));
1819 aid->aid = cpu_to_le16(params->aid);
1820 config_len += sizeof(struct mwifiex_ie_types_aid);
1821 }
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001822
Avinash Patild29caf22014-05-06 22:02:43 -07001823 timeout = (void *)(pos + config_len);
1824 timeout->header.type = cpu_to_le16(TLV_TYPE_TDLS_IDLE_TIMEOUT);
1825 timeout->header.len = cpu_to_le16(sizeof(timeout->value));
Bing Zhao30fa51c2014-07-11 20:57:13 -07001826 timeout->value = cpu_to_le16(MWIFIEX_TDLS_IDLE_TIMEOUT_IN_SEC);
Avinash Patild29caf22014-05-06 22:02:43 -07001827 config_len += sizeof(struct mwifiex_ie_types_tdls_idle_timeout);
1828
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001829 break;
Avinash Patil429d90d2014-02-07 16:27:34 -08001830 default:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301831 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS operation\n");
Avinash Patil429d90d2014-02-07 16:27:34 -08001832 return -ENOTSUPP;
1833 }
1834
Avinash Patil1f4dfd82014-02-07 16:30:34 -08001835 le16_add_cpu(&cmd->size, config_len);
Avinash Patil429d90d2014-02-07 16:27:34 -08001836
1837 return 0;
1838}
Zhaoyang Liu92263a82015-03-13 17:37:58 +05301839
1840/* This function prepares command of sdio rx aggr info. */
1841static int mwifiex_cmd_sdio_rx_aggr_cfg(struct host_cmd_ds_command *cmd,
1842 u16 cmd_action, void *data_buf)
1843{
1844 struct host_cmd_sdio_sp_rx_aggr_cfg *cfg =
1845 &cmd->params.sdio_rx_aggr_cfg;
1846
1847 cmd->command = cpu_to_le16(HostCmd_CMD_SDIO_SP_RX_AGGR_CFG);
1848 cmd->size =
1849 cpu_to_le16(sizeof(struct host_cmd_sdio_sp_rx_aggr_cfg) +
1850 S_DS_GEN);
1851 cfg->action = cmd_action;
1852 if (cmd_action == HostCmd_ACT_GEN_SET)
1853 cfg->enable = *(u8 *)data_buf;
1854
1855 return 0;
1856}
1857
chunfan chen8de00f12016-01-13 01:26:55 -08001858/* This function prepares command to get HS wakeup reason.
1859 *
1860 * Preparation includes -
1861 * - Setting command ID, action and proper size
1862 * - Ensuring correct endian-ness
1863 */
1864static int mwifiex_cmd_get_wakeup_reason(struct mwifiex_private *priv,
1865 struct host_cmd_ds_command *cmd)
1866{
1867 cmd->command = cpu_to_le16(HostCmd_CMD_HS_WAKEUP_REASON);
1868 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_wakeup_reason) +
1869 S_DS_GEN);
1870
1871 return 0;
1872}
1873
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001874/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001875 * This function prepares the commands before sending them to the firmware.
1876 *
1877 * This is a generic function which calls specific command preparation
1878 * routines based upon the command number.
1879 */
1880int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1881 u16 cmd_action, u32 cmd_oid,
1882 void *data_buf, void *cmd_buf)
1883{
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001884 struct host_cmd_ds_command *cmd_ptr = cmd_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001885 int ret = 0;
1886
1887 /* Prepare command */
1888 switch (cmd_no) {
1889 case HostCmd_CMD_GET_HW_SPEC:
1890 ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
1891 break;
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001892 case HostCmd_CMD_CFG_DATA:
Bing Zhao699b0272013-12-13 18:33:01 -08001893 ret = mwifiex_cmd_cfg_data(priv, cmd_ptr, data_buf);
Amitkumar Karwar388ec382013-05-17 17:50:25 -07001894 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001895 case HostCmd_CMD_MAC_CONTROL:
1896 ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
1897 data_buf);
1898 break;
1899 case HostCmd_CMD_802_11_MAC_ADDRESS:
1900 ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
1901 cmd_action);
1902 break;
1903 case HostCmd_CMD_MAC_MULTICAST_ADR:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001904 ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001905 data_buf);
1906 break;
1907 case HostCmd_CMD_TX_RATE_CFG:
1908 ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
1909 data_buf);
1910 break;
1911 case HostCmd_CMD_TXPWR_CFG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001912 ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001913 data_buf);
1914 break;
Amitkumar Karwarcaa89842012-06-27 19:57:57 -07001915 case HostCmd_CMD_RF_TX_PWR:
1916 ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
1917 data_buf);
1918 break;
Amitkumar Karwar8a279d52012-07-02 19:32:33 -07001919 case HostCmd_CMD_RF_ANTENNA:
1920 ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
1921 data_buf);
1922 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001923 case HostCmd_CMD_802_11_PS_MODE_ENH:
1924 ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
1925 (uint16_t)cmd_oid, data_buf);
1926 break;
1927 case HostCmd_CMD_802_11_HS_CFG_ENH:
1928 ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
1929 (struct mwifiex_hs_config_param *) data_buf);
1930 break;
1931 case HostCmd_CMD_802_11_SCAN:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001932 ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001933 break;
Xinming Hu0c9b7f22016-01-13 01:26:52 -08001934 case HostCmd_CMD_802_11_BG_SCAN_CONFIG:
1935 ret = mwifiex_cmd_802_11_bg_scan_config(priv, cmd_ptr,
1936 data_buf);
1937 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001938 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001939 ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001940 break;
1941 case HostCmd_CMD_802_11_ASSOCIATE:
1942 ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
1943 break;
1944 case HostCmd_CMD_802_11_DEAUTHENTICATE:
1945 ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
1946 data_buf);
1947 break;
1948 case HostCmd_CMD_802_11_AD_HOC_START:
1949 ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
1950 data_buf);
1951 break;
1952 case HostCmd_CMD_802_11_GET_LOG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001953 ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001954 break;
1955 case HostCmd_CMD_802_11_AD_HOC_JOIN:
1956 ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
1957 data_buf);
1958 break;
1959 case HostCmd_CMD_802_11_AD_HOC_STOP:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001960 ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001961 break;
1962 case HostCmd_CMD_RSSI_INFO:
1963 ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
1964 break;
1965 case HostCmd_CMD_802_11_SNMP_MIB:
1966 ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
1967 cmd_oid, data_buf);
1968 break;
1969 case HostCmd_CMD_802_11_TX_RATE_QUERY:
1970 cmd_ptr->command =
1971 cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
1972 cmd_ptr->size =
1973 cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
1974 S_DS_GEN);
1975 priv->tx_rate = 0;
1976 ret = 0;
1977 break;
1978 case HostCmd_CMD_VERSION_EXT:
1979 cmd_ptr->command = cpu_to_le16(cmd_no);
1980 cmd_ptr->params.verext.version_str_sel =
1981 (u8) (*((u32 *) data_buf));
1982 memcpy(&cmd_ptr->params, data_buf,
1983 sizeof(struct host_cmd_ds_version_ext));
1984 cmd_ptr->size =
1985 cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
1986 S_DS_GEN);
1987 ret = 0;
1988 break;
Stone Piao3cec6872012-09-25 20:23:34 -07001989 case HostCmd_CMD_MGMT_FRAME_REG:
1990 cmd_ptr->command = cpu_to_le16(cmd_no);
1991 cmd_ptr->params.reg_mask.action = cpu_to_le16(cmd_action);
1992 cmd_ptr->params.reg_mask.mask = cpu_to_le32(*(u32 *)data_buf);
1993 cmd_ptr->size =
1994 cpu_to_le16(sizeof(struct host_cmd_ds_mgmt_frame_reg) +
1995 S_DS_GEN);
1996 ret = 0;
1997 break;
Stone Piao7feb4c42012-09-25 20:23:36 -07001998 case HostCmd_CMD_REMAIN_ON_CHAN:
1999 cmd_ptr->command = cpu_to_le16(cmd_no);
2000 memcpy(&cmd_ptr->params, data_buf,
2001 sizeof(struct host_cmd_ds_remain_on_chan));
2002 cmd_ptr->size =
2003 cpu_to_le16(sizeof(struct host_cmd_ds_remain_on_chan) +
2004 S_DS_GEN);
2005 break;
Yogesh Ashok Powar83c78da2013-03-18 20:06:03 -07002006 case HostCmd_CMD_11AC_CFG:
2007 ret = mwifiex_cmd_11ac_cfg(priv, cmd_ptr, cmd_action, data_buf);
2008 break;
Stone Piaoe1a2b7a2012-09-25 20:23:41 -07002009 case HostCmd_CMD_P2P_MODE_CFG:
2010 cmd_ptr->command = cpu_to_le16(cmd_no);
2011 cmd_ptr->params.mode_cfg.action = cpu_to_le16(cmd_action);
2012 cmd_ptr->params.mode_cfg.mode = cpu_to_le16(*(u16 *)data_buf);
2013 cmd_ptr->size =
2014 cpu_to_le16(sizeof(struct host_cmd_ds_p2p_mode_cfg) +
2015 S_DS_GEN);
2016 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002017 case HostCmd_CMD_FUNC_INIT:
2018 if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
2019 priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
2020 cmd_ptr->command = cpu_to_le16(cmd_no);
2021 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
2022 break;
2023 case HostCmd_CMD_FUNC_SHUTDOWN:
2024 priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
2025 cmd_ptr->command = cpu_to_le16(cmd_no);
2026 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
2027 break;
2028 case HostCmd_CMD_11N_ADDBA_REQ:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07002029 ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002030 break;
2031 case HostCmd_CMD_11N_DELBA:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07002032 ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002033 break;
2034 case HostCmd_CMD_11N_ADDBA_RSP:
2035 ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
2036 break;
2037 case HostCmd_CMD_802_11_KEY_MATERIAL:
2038 ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07002039 cmd_action, cmd_oid,
2040 data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002041 break;
2042 case HostCmd_CMD_802_11D_DOMAIN_INFO:
2043 ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07002044 cmd_action);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002045 break;
2046 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
2047 ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
2048 data_buf);
2049 break;
2050 case HostCmd_CMD_AMSDU_AGGR_CTRL:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07002051 ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002052 data_buf);
2053 break;
2054 case HostCmd_CMD_11N_CFG:
Yogesh Ashok Powara5f39052013-02-15 21:44:30 -08002055 ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002056 break;
2057 case HostCmd_CMD_WMM_GET_STATUS:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302058 mwifiex_dbg(priv->adapter, CMD,
2059 "cmd: WMM: WMM_GET_STATUS cmd sent\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002060 cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
2061 cmd_ptr->size =
2062 cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
2063 S_DS_GEN);
2064 ret = 0;
2065 break;
2066 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07002067 ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
2068 data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002069 break;
Amitkumar Karwar21f58d202014-02-11 18:39:56 -08002070 case HostCmd_CMD_802_11_SCAN_EXT:
2071 ret = mwifiex_cmd_802_11_scan_ext(priv, cmd_ptr, data_buf);
2072 break;
Chin-ran Loc2c6c852015-05-12 00:48:17 +05302073 case HostCmd_CMD_MEM_ACCESS:
2074 ret = mwifiex_cmd_mem_access(cmd_ptr, cmd_action, data_buf);
2075 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002076 case HostCmd_CMD_MAC_REG_ACCESS:
2077 case HostCmd_CMD_BBP_REG_ACCESS:
2078 case HostCmd_CMD_RF_REG_ACCESS:
2079 case HostCmd_CMD_PMIC_REG_ACCESS:
2080 case HostCmd_CMD_CAU_REG_ACCESS:
2081 case HostCmd_CMD_802_11_EEPROM_ACCESS:
2082 ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
2083 break;
2084 case HostCmd_CMD_SET_BSS_MODE:
2085 cmd_ptr->command = cpu_to_le16(cmd_no);
Bing Zhaoeecd8252011-03-28 17:55:41 -07002086 if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002087 cmd_ptr->params.bss_mode.con_type =
2088 CONNECTION_TYPE_ADHOC;
Aniket Nagarnaikae86c582015-07-02 06:07:02 -07002089 else if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2090 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002091 cmd_ptr->params.bss_mode.con_type =
2092 CONNECTION_TYPE_INFRA;
Aniket Nagarnaikae86c582015-07-02 06:07:02 -07002093 else if (priv->bss_mode == NL80211_IFTYPE_AP ||
2094 priv->bss_mode == NL80211_IFTYPE_P2P_GO)
Stone Piao9197ab92012-09-25 20:23:42 -07002095 cmd_ptr->params.bss_mode.con_type = CONNECTION_TYPE_AP;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002096 cmd_ptr->size = cpu_to_le16(sizeof(struct
2097 host_cmd_ds_set_bss_mode) + S_DS_GEN);
2098 ret = 0;
2099 break;
Amitkumar Karward930fae2011-10-11 17:41:21 -07002100 case HostCmd_CMD_PCIE_DESC_DETAILS:
2101 ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
2102 break;
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07002103 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
2104 ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
2105 break;
Amitkumar Karwar7da060c2013-03-04 16:27:59 -08002106 case HostCmd_CMD_MEF_CFG:
2107 ret = mwifiex_cmd_mef_cfg(priv, cmd_ptr, data_buf);
2108 break;
Amitkumar Karwar562fc5b2013-08-05 18:52:00 -07002109 case HostCmd_CMD_COALESCE_CFG:
2110 ret = mwifiex_cmd_coalesce_cfg(priv, cmd_ptr, cmd_action,
2111 data_buf);
2112 break;
Avinash Patil429d90d2014-02-07 16:27:34 -08002113 case HostCmd_CMD_TDLS_OPER:
2114 ret = mwifiex_cmd_tdls_oper(priv, cmd_ptr, data_buf);
2115 break;
Xinming Hu449b8bb2015-06-22 19:06:12 +05302116 case HostCmd_CMD_TDLS_CONFIG:
2117 ret = mwifiex_cmd_tdls_config(priv, cmd_ptr, cmd_action,
2118 data_buf);
2119 break;
Avinash Patil85afb182015-01-28 15:54:21 +05302120 case HostCmd_CMD_CHAN_REPORT_REQUEST:
2121 ret = mwifiex_cmd_issue_chan_report_request(priv, cmd_ptr,
2122 data_buf);
2123 break;
Zhaoyang Liu92263a82015-03-13 17:37:58 +05302124 case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG:
2125 ret = mwifiex_cmd_sdio_rx_aggr_cfg(cmd_ptr, cmd_action,
2126 data_buf);
2127 break;
chunfan chen8de00f12016-01-13 01:26:55 -08002128 case HostCmd_CMD_HS_WAKEUP_REASON:
2129 ret = mwifiex_cmd_get_wakeup_reason(priv, cmd_ptr);
2130 break;
Avinash Patild5b036c2015-06-22 19:06:20 +05302131 case HostCmd_CMD_MC_POLICY:
2132 ret = mwifiex_cmd_set_mc_policy(priv, cmd_ptr, cmd_action,
2133 data_buf);
2134 break;
Amitkumar Karwar46dbe242015-10-09 04:26:23 -07002135 case HostCmd_CMD_ROBUST_COEX:
2136 ret = mwifiex_cmd_robust_coex(priv, cmd_ptr, cmd_action,
2137 data_buf);
2138 break;
Ganapathi Bhatf6b1cbe2016-04-05 01:04:34 -07002139 case HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG:
2140 ret = mwifiex_cmd_gtk_rekey_offload(priv, cmd_ptr, cmd_action,
2141 data_buf);
2142 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002143 default:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302144 mwifiex_dbg(priv->adapter, ERROR,
2145 "PREP_CMD: unknown cmd- %#x\n", cmd_no);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002146 ret = -1;
2147 break;
2148 }
2149 return ret;
2150}
2151
2152/*
2153 * This function issues commands to initialize firmware.
2154 *
2155 * This is called after firmware download to bring the card to
2156 * working state.
Avinash Patil1247cc12015-01-28 15:42:02 +05302157 * Function is also called during reinitialization of virtual
2158 * interfaces.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002159 *
2160 * The following commands are issued sequentially -
Amitkumar Karward930fae2011-10-11 17:41:21 -07002161 * - Set PCI-Express host buffer configuration (PCIE only)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002162 * - Function init (for first interface only)
2163 * - Read MAC address (for first interface only)
2164 * - Reconfigure Tx buffer size (for first interface only)
2165 * - Enable auto deep sleep (for first interface only)
2166 * - Get Tx rate
2167 * - Get Tx power
2168 * - Set IBSS coalescing status
2169 * - Set AMSDU aggregation control
2170 * - Set 11d control
2171 * - Set MAC control (this must be the last command to initialize firmware)
2172 */
Avinash Patil1247cc12015-01-28 15:42:02 +05302173int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta, bool init)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002174{
Amitkumar Karwar388ec382013-05-17 17:50:25 -07002175 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07002176 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002177 u16 enable = true;
2178 struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
2179 struct mwifiex_ds_auto_ds auto_ds;
2180 enum state_11d_t state_11d;
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07002181 struct mwifiex_ds_11n_tx_cfg tx_cfg;
Zhaoyang Liu92263a82015-03-13 17:37:58 +05302182 u8 sdio_sp_rx_aggr_enable;
Xinming Huce4f6f02016-04-18 05:22:23 -07002183 int data;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002184
2185 if (first_sta) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07002186 if (priv->adapter->iface_type == MWIFIEX_PCIE) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002187 ret = mwifiex_send_cmd(priv,
2188 HostCmd_CMD_PCIE_DESC_DETAILS,
2189 HostCmd_ACT_GEN_SET, 0, NULL,
2190 true);
Amitkumar Karward930fae2011-10-11 17:41:21 -07002191 if (ret)
2192 return -1;
2193 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002194
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002195 ret = mwifiex_send_cmd(priv, HostCmd_CMD_FUNC_INIT,
2196 HostCmd_ACT_GEN_SET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002197 if (ret)
2198 return -1;
Amitkumar Karwar388ec382013-05-17 17:50:25 -07002199
Bing Zhao699b0272013-12-13 18:33:01 -08002200 /* Download calibration data to firmware.
2201 * The cal-data can be read from device tree and/or
2202 * a configuration file and downloaded to firmware.
2203 */
Xinming Huce4f6f02016-04-18 05:22:23 -07002204 if (priv->adapter->iface_type == MWIFIEX_SDIO &&
2205 adapter->dev->of_node) {
2206 adapter->dt_node = adapter->dev->of_node;
2207 if (of_property_read_u32(adapter->dt_node,
2208 "marvell,wakeup-pin",
2209 &data) == 0) {
2210 pr_debug("Wakeup pin = 0x%x\n", data);
2211 adapter->hs_cfg.gpio = data;
2212 }
2213
Bing Zhao699b0272013-12-13 18:33:01 -08002214 ret = mwifiex_dnld_dt_cfgdata(priv, adapter->dt_node,
2215 "marvell,caldata");
2216 if (ret)
2217 return -1;
2218 }
2219
Amitkumar Karwar388ec382013-05-17 17:50:25 -07002220 if (adapter->cal_data) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002221 ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
2222 HostCmd_ACT_GEN_SET, 0, NULL,
2223 true);
Amitkumar Karwar388ec382013-05-17 17:50:25 -07002224 if (ret)
2225 return -1;
2226 }
2227
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002228 /* Read MAC address from HW */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002229 ret = mwifiex_send_cmd(priv, HostCmd_CMD_GET_HW_SPEC,
2230 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002231 if (ret)
2232 return -1;
2233
Zhaoyang Liu92263a82015-03-13 17:37:58 +05302234 /** Set SDIO Single Port RX Aggr Info */
2235 if (priv->adapter->iface_type == MWIFIEX_SDIO &&
Xinming Hu9a9053c2015-09-18 06:32:06 -07002236 ISSUPP_SDIO_SPA_ENABLED(priv->adapter->fw_cap_info) &&
2237 !priv->adapter->host_disable_sdio_rx_aggr) {
Zhaoyang Liu92263a82015-03-13 17:37:58 +05302238 sdio_sp_rx_aggr_enable = true;
2239 ret = mwifiex_send_cmd(priv,
2240 HostCmd_CMD_SDIO_SP_RX_AGGR_CFG,
2241 HostCmd_ACT_GEN_SET, 0,
2242 &sdio_sp_rx_aggr_enable,
2243 true);
2244 if (ret) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302245 mwifiex_dbg(priv->adapter, ERROR,
2246 "error while enabling SP aggregation..disable it");
Zhaoyang Liu92263a82015-03-13 17:37:58 +05302247 adapter->sdio_rx_aggr_enable = false;
2248 }
2249 }
2250
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002251 /* Reconfigure tx buf size */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002252 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
2253 HostCmd_ACT_GEN_SET, 0,
2254 &priv->adapter->tx_buf_size, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002255 if (ret)
2256 return -1;
2257
Avinash Patil03785382012-05-08 18:30:14 -07002258 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2259 /* Enable IEEE PS by default */
2260 priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002261 ret = mwifiex_send_cmd(priv,
2262 HostCmd_CMD_802_11_PS_MODE_ENH,
2263 EN_AUTO_PS, BITMAP_STA_PS, NULL,
2264 true);
Avinash Patil03785382012-05-08 18:30:14 -07002265 if (ret)
2266 return -1;
2267 }
Avinash Patild5b036c2015-06-22 19:06:20 +05302268
Avinash Patilde9e9932015-06-22 19:06:21 +05302269 if (drcs) {
2270 adapter->drcs_enabled = true;
2271 if (ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
2272 ret = mwifiex_send_cmd(priv,
2273 HostCmd_CMD_MC_POLICY,
2274 HostCmd_ACT_GEN_SET, 0,
2275 &adapter->drcs_enabled,
2276 true);
Avinash Patild5b036c2015-06-22 19:06:20 +05302277 if (ret)
2278 return -1;
Avinash Patilde9e9932015-06-22 19:06:21 +05302279 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002280 }
2281
2282 /* get tx rate */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002283 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
2284 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002285 if (ret)
2286 return -1;
2287 priv->data_rate = 0;
2288
2289 /* get tx power */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002290 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
2291 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002292 if (ret)
2293 return -1;
2294
Avinash Patil03785382012-05-08 18:30:14 -07002295 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
2296 /* set ibss coalescing_status */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002297 ret = mwifiex_send_cmd(
2298 priv,
2299 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
2300 HostCmd_ACT_GEN_SET, 0, &enable, true);
Avinash Patil03785382012-05-08 18:30:14 -07002301 if (ret)
2302 return -1;
2303 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002304
2305 memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
2306 amsdu_aggr_ctrl.enable = true;
2307 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002308 ret = mwifiex_send_cmd(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
2309 HostCmd_ACT_GEN_SET, 0,
2310 &amsdu_aggr_ctrl, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002311 if (ret)
2312 return -1;
2313 /* MAC Control must be the last command in init_fw */
2314 /* set MAC Control */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002315 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
2316 HostCmd_ACT_GEN_SET, 0,
2317 &priv->curr_pkt_filter, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002318 if (ret)
2319 return -1;
2320
Avinash Patil0b4155d2014-12-23 19:14:12 +05302321 if (!disable_auto_ds &&
2322 first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
Avinash Patil03785382012-05-08 18:30:14 -07002323 priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002324 /* Enable auto deep sleep */
2325 auto_ds.auto_ds = DEEP_SLEEP_ON;
2326 auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002327 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
2328 EN_AUTO_PS, BITMAP_AUTO_DS,
2329 &auto_ds, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002330 if (ret)
2331 return -1;
2332 }
2333
Avinash Patil03785382012-05-08 18:30:14 -07002334 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2335 /* Send cmd to FW to enable/disable 11D function */
2336 state_11d = ENABLE_11D;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002337 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
2338 HostCmd_ACT_GEN_SET, DOT11D_I,
2339 &state_11d, true);
Avinash Patil03785382012-05-08 18:30:14 -07002340 if (ret)
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05302341 mwifiex_dbg(priv->adapter, ERROR,
2342 "11D: failed to enable 11D\n");
Avinash Patil03785382012-05-08 18:30:14 -07002343 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002344
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07002345 /* Send cmd to FW to configure 11n specific configuration
2346 * (Short GI, Channel BW, Green field support etc.) for transmit
2347 */
2348 tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08002349 ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_CFG,
2350 HostCmd_ACT_GEN_SET, 0, &tx_cfg, true);
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07002351
Avinash Patil1247cc12015-01-28 15:42:02 +05302352 if (init) {
2353 /* set last_init_cmd before sending the command */
2354 priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
2355 ret = -EINPROGRESS;
2356 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07002357
2358 return ret;
2359}