mwifiex: minor corrections in multiport aggregation code
[deliverable/linux.git] / drivers / net / wireless / mwifiex / sta_cmd.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: station command handling
3 *
65da33f5 4 * Copyright (C) 2011-2014, Marvell International Ltd.
5e6e3a92
BZ
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "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"
83c78da9 27#include "11ac.h"
5e6e3a92 28
d5b036c4
AP
29static bool drcs;
30module_param(drcs, bool, 0644);
31MODULE_PARM_DESC(drcs, "multi-channel operation:1, single-channel operation:0");
32
0b4155d1
AP
33static 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");
5e6e3a92
BZ
37/*
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,
a5ffddb7 79 u16 cmd_action, u16 *action)
5e6e3a92
BZ
80{
81 struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
5e6e3a92
BZ
82
83 if (cmd_action != HostCmd_ACT_GEN_SET) {
acebe8c1
ZL
84 mwifiex_dbg(priv->adapter, ERROR,
85 "mac_control: only support set cmd\n");
5e6e3a92
BZ
86 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);
a5ffddb7 92 mac_ctrl->action = cpu_to_le16(*action);
5e6e3a92
BZ
93
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,
f3c8d259 115 u16 *ul_temp)
5e6e3a92
BZ
116{
117 struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
5e6e3a92 118
acebe8c1
ZL
119 mwifiex_dbg(priv->adapter, CMD,
120 "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
5e6e3a92
BZ
121 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)
9c05fd72 123 - 1 + S_DS_GEN);
5e6e3a92 124
f3c8d259 125 snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
5e6e3a92
BZ
126 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);
f3c8d259
AK
129 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));
5e6e3a92
BZ
135 }
136
acebe8c1
ZL
137 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));
5e6e3a92
BZ
142 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
572e8f3e 153mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
5e6e3a92
BZ
154{
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,
a5ffddb7 172 u16 cmd_action, u16 *pbitmap_rates)
5e6e3a92
BZ
173{
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;
5e6e3a92
BZ
177 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);
9c05fd72
YAP
187 rate_scope->length = cpu_to_le16
188 (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
5e6e3a92
BZ
189 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]);
a0b7315a
AK
197 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 }
5e6e3a92
BZ
204 } 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]);
a0b7315a
AK
214 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 }
5e6e3a92
BZ
221 }
222
223 rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
9c05fd72 224 sizeof(struct mwifiex_rate_scope));
5e6e3a92
BZ
225 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 */
572e8f3e 246static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
a5ffddb7
AK
247 u16 cmd_action,
248 struct host_cmd_ds_txpwr_cfg *txp)
5e6e3a92 249{
270e58e8 250 struct mwifiex_types_power_group *pg_tlv;
5e6e3a92
BZ
251 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:
5e6e3a92
BZ
258 if (txp->mode) {
259 pg_tlv = (struct mwifiex_types_power_group
a5ffddb7 260 *) ((unsigned long) txp +
5e6e3a92 261 sizeof(struct host_cmd_ds_txpwr_cfg));
a5ffddb7 262 memmove(cmd_txp_cfg, txp,
5e6e3a92
BZ
263 sizeof(struct host_cmd_ds_txpwr_cfg) +
264 sizeof(struct mwifiex_types_power_group) +
930fd35c 265 le16_to_cpu(pg_tlv->length));
5e6e3a92
BZ
266
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) +
930fd35c 272 le16_to_cpu(pg_tlv->length));
5e6e3a92 273 } else {
a5ffddb7 274 memmove(cmd_txp_cfg, txp, sizeof(*txp));
5e6e3a92
BZ
275 }
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
caa8984f
AK
286/*
287 * 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
8a279d5b
AK
303/*
304 * 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
316 if (cmd_action != HostCmd_ACT_GEN_SET)
317 return 0;
318
319 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
320 cmd->size = cpu_to_le16(sizeof(struct 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->tx_ant);
324 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX);
325 ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg->rx_ant);
326 } else {
327 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_siso) +
328 S_DS_GEN);
329 ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH);
330 ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
331 }
332
333 return 0;
334}
335
5e6e3a92
BZ
336/*
337 * This function prepares command to set Host Sleep configuration.
338 *
339 * Preparation includes -
340 * - Setting command ID and proper size
341 * - Setting Host Sleep action, conditions, ARP filters
342 * (as required)
343 * - Ensuring correct endian-ness
344 */
a5ffddb7
AK
345static int
346mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
347 struct host_cmd_ds_command *cmd,
348 u16 cmd_action,
349 struct mwifiex_hs_config_param *hscfg_param)
5e6e3a92
BZ
350{
351 struct mwifiex_adapter *adapter = priv->adapter;
352 struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
c856197d 353 bool hs_activate = false;
5e6e3a92 354
a5ffddb7 355 if (!hscfg_param)
5e6e3a92
BZ
356 /* New Activate command */
357 hs_activate = true;
358 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
359
360 if (!hs_activate &&
cc0b5a64 361 (hscfg_param->conditions != cpu_to_le32(HS_CFG_CANCEL)) &&
9c05fd72
YAP
362 ((adapter->arp_filter_size > 0) &&
363 (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
acebe8c1
ZL
364 mwifiex_dbg(adapter, CMD,
365 "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
366 adapter->arp_filter_size);
5e6e3a92
BZ
367 memcpy(((u8 *) hs_cfg) +
368 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
369 adapter->arp_filter, adapter->arp_filter_size);
9c05fd72
YAP
370 cmd->size = cpu_to_le16
371 (adapter->arp_filter_size +
372 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
373 + S_DS_GEN);
5e6e3a92
BZ
374 } else {
375 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
9c05fd72 376 host_cmd_ds_802_11_hs_cfg_enh));
5e6e3a92
BZ
377 }
378 if (hs_activate) {
379 hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
4348d085 380 hs_cfg->params.hs_activate.resp_ctrl = cpu_to_le16(RESP_NEEDED);
5e6e3a92
BZ
381 } else {
382 hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
a5ffddb7
AK
383 hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
384 hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
385 hs_cfg->params.hs_config.gap = hscfg_param->gap;
acebe8c1
ZL
386 mwifiex_dbg(adapter, CMD,
387 "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
388 hs_cfg->params.hs_config.conditions,
389 hs_cfg->params.hs_config.gpio,
390 hs_cfg->params.hs_config.gap);
5e6e3a92
BZ
391 }
392
393 return 0;
394}
395
396/*
397 * This function prepares command to set/get MAC address.
398 *
399 * Preparation includes -
400 * - Setting command ID, action and proper size
401 * - Setting MAC address (for SET only)
402 * - Ensuring correct endian-ness
403 */
404static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
405 struct host_cmd_ds_command *cmd,
406 u16 cmd_action)
407{
408 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
409 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
410 S_DS_GEN);
411 cmd->result = 0;
412
413 cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
414
415 if (cmd_action == HostCmd_ACT_GEN_SET)
416 memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
417 ETH_ALEN);
418 return 0;
419}
420
421/*
422 * This function prepares command to set MAC multicast address.
423 *
424 * Preparation includes -
425 * - Setting command ID, action and proper size
426 * - Setting MAC multicast address
427 * - Ensuring correct endian-ness
428 */
a5ffddb7
AK
429static int
430mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
431 u16 cmd_action,
432 struct mwifiex_multicast_list *mcast_list)
5e6e3a92 433{
5e6e3a92
BZ
434 struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
435
436 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
437 S_DS_GEN);
438 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
439
440 mcast_addr->action = cpu_to_le16(cmd_action);
441 mcast_addr->num_of_adrs =
442 cpu_to_le16((u16) mcast_list->num_multicast_addr);
443 memcpy(mcast_addr->mac_list, mcast_list->mac_list,
444 mcast_list->num_multicast_addr * ETH_ALEN);
445
446 return 0;
447}
448
449/*
450 * This function prepares command to deauthenticate.
451 *
452 * Preparation includes -
453 * - Setting command ID and proper size
454 * - Setting AP MAC address and reason code
455 * - Ensuring correct endian-ness
456 */
457static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
458 struct host_cmd_ds_command *cmd,
a5ffddb7 459 u8 *mac)
5e6e3a92
BZ
460{
461 struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
462
463 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
464 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
465 + S_DS_GEN);
466
467 /* Set AP MAC address */
a5ffddb7 468 memcpy(deauth->mac_addr, mac, ETH_ALEN);
5e6e3a92 469
acebe8c1 470 mwifiex_dbg(priv->adapter, CMD, "cmd: Deauth: %pM\n", deauth->mac_addr);
5e6e3a92
BZ
471
472 deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
473
474 return 0;
475}
476
477/*
478 * This function prepares command to stop Ad-Hoc network.
479 *
480 * Preparation includes -
481 * - Setting command ID and proper size
482 * - Ensuring correct endian-ness
483 */
572e8f3e 484static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
5e6e3a92
BZ
485{
486 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
487 cmd->size = cpu_to_le16(S_DS_GEN);
488 return 0;
489}
490
491/*
492 * This function sets WEP key(s) to key parameter TLV(s).
493 *
494 * Multi-key parameter TLVs are supported, so we can send multiple
495 * WEP keys in a single buffer.
496 */
497static int
498mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
499 struct mwifiex_ie_type_key_param_set *key_param_set,
500 u16 *key_param_len)
501{
270e58e8 502 int cur_key_param_len;
5e6e3a92
BZ
503 u8 i;
504
505 /* Multi-key_param_set TLV is supported */
506 for (i = 0; i < NUM_WEP_KEYS; i++) {
507 if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
508 (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
509 key_param_set->type =
510 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
511/* Key_param_set WEP fixed length */
512#define KEYPARAMSET_WEP_FIXED_LEN 8
513 key_param_set->length = cpu_to_le16((u16)
514 (priv->wep_key[i].
515 key_length +
516 KEYPARAMSET_WEP_FIXED_LEN));
517 key_param_set->key_type_id =
518 cpu_to_le16(KEY_TYPE_ID_WEP);
519 key_param_set->key_info =
6a35a0ac
YAP
520 cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
521 KEY_MCAST);
5e6e3a92
BZ
522 key_param_set->key_len =
523 cpu_to_le16(priv->wep_key[i].key_length);
524 /* Set WEP key index */
525 key_param_set->key[0] = i;
526 /* Set default Tx key flag */
527 if (i ==
528 (priv->
529 wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
530 key_param_set->key[1] = 1;
531 else
532 key_param_set->key[1] = 0;
533 memmove(&key_param_set->key[2],
534 priv->wep_key[i].key_material,
535 priv->wep_key[i].key_length);
536
537 cur_key_param_len = priv->wep_key[i].key_length +
538 KEYPARAMSET_WEP_FIXED_LEN +
539 sizeof(struct mwifiex_ie_types_header);
540 *key_param_len += (u16) cur_key_param_len;
541 key_param_set =
542 (struct mwifiex_ie_type_key_param_set *)
543 ((u8 *)key_param_set +
9c05fd72 544 cur_key_param_len);
5e6e3a92
BZ
545 } else if (!priv->wep_key[i].key_length) {
546 continue;
547 } else {
acebe8c1
ZL
548 mwifiex_dbg(priv->adapter, ERROR,
549 "key%d Length = %d is incorrect\n",
550 (i + 1), priv->wep_key[i].key_length);
5e6e3a92
BZ
551 return -1;
552 }
553 }
554
555 return 0;
556}
557
e57f1734
AP
558/* This function populates key material v2 command
559 * to set network key for AES & CMAC AES.
560 */
561static int mwifiex_set_aes_key_v2(struct mwifiex_private *priv,
562 struct host_cmd_ds_command *cmd,
563 struct mwifiex_ds_encrypt_key *enc_key,
564 struct host_cmd_ds_802_11_key_material_v2 *km)
565{
566 struct mwifiex_adapter *adapter = priv->adapter;
567 u16 size, len = KEY_PARAMS_FIXED_LEN;
568
569 if (enc_key->is_igtk_key) {
acebe8c1
ZL
570 mwifiex_dbg(adapter, INFO,
571 "%s: Set CMAC AES Key\n", __func__);
e57f1734
AP
572 if (enc_key->is_rx_seq_valid)
573 memcpy(km->key_param_set.key_params.cmac_aes.ipn,
574 enc_key->pn, enc_key->pn_len);
575 km->key_param_set.key_info &= cpu_to_le16(~KEY_MCAST);
576 km->key_param_set.key_info |= cpu_to_le16(KEY_IGTK);
577 km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC;
578 km->key_param_set.key_params.cmac_aes.key_len =
579 cpu_to_le16(enc_key->key_len);
580 memcpy(km->key_param_set.key_params.cmac_aes.key,
581 enc_key->key_material, enc_key->key_len);
582 len += sizeof(struct mwifiex_cmac_aes_param);
583 } else {
acebe8c1
ZL
584 mwifiex_dbg(adapter, INFO,
585 "%s: Set AES Key\n", __func__);
e57f1734
AP
586 if (enc_key->is_rx_seq_valid)
587 memcpy(km->key_param_set.key_params.aes.pn,
588 enc_key->pn, enc_key->pn_len);
589 km->key_param_set.key_type = KEY_TYPE_ID_AES;
590 km->key_param_set.key_params.aes.key_len =
591 cpu_to_le16(enc_key->key_len);
592 memcpy(km->key_param_set.key_params.aes.key,
593 enc_key->key_material, enc_key->key_len);
594 len += sizeof(struct mwifiex_aes_param);
595 }
596
597 km->key_param_set.len = cpu_to_le16(len);
598 size = len + sizeof(struct mwifiex_ie_types_header) +
599 sizeof(km->action) + S_DS_GEN;
600 cmd->size = cpu_to_le16(size);
601
602 return 0;
603}
604
605/* This function prepares command to set/get/reset network key(s).
606 * This function prepares key material command for V2 format.
607 * Preparation includes -
608 * - Setting command ID, action and proper size
609 * - Setting WEP keys, WAPI keys or WPA keys along with required
610 * encryption (TKIP, AES) (as required)
611 * - Ensuring correct endian-ness
612 */
613static int
614mwifiex_cmd_802_11_key_material_v2(struct mwifiex_private *priv,
615 struct host_cmd_ds_command *cmd,
616 u16 cmd_action, u32 cmd_oid,
617 struct mwifiex_ds_encrypt_key *enc_key)
618{
619 struct mwifiex_adapter *adapter = priv->adapter;
620 u8 *mac = enc_key->mac_addr;
621 u16 key_info, len = KEY_PARAMS_FIXED_LEN;
622 struct host_cmd_ds_802_11_key_material_v2 *km =
623 &cmd->params.key_material_v2;
624
625 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
626 km->action = cpu_to_le16(cmd_action);
627
628 if (cmd_action == HostCmd_ACT_GEN_GET) {
acebe8c1 629 mwifiex_dbg(adapter, INFO, "%s: Get key\n", __func__);
e57f1734
AP
630 km->key_param_set.key_idx =
631 enc_key->key_index & KEY_INDEX_MASK;
632 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
633 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
634 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
635
636 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
637 key_info = KEY_UNICAST;
638 else
639 key_info = KEY_MCAST;
640
641 if (enc_key->is_igtk_key)
642 key_info |= KEY_IGTK;
643
644 km->key_param_set.key_info = cpu_to_le16(key_info);
645
646 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
647 S_DS_GEN + KEY_PARAMS_FIXED_LEN +
648 sizeof(km->action));
649 return 0;
650 }
651
652 memset(&km->key_param_set, 0,
653 sizeof(struct mwifiex_ie_type_key_param_set_v2));
654
655 if (enc_key->key_disable) {
acebe8c1 656 mwifiex_dbg(adapter, INFO, "%s: Remove key\n", __func__);
e57f1734
AP
657 km->action = cpu_to_le16(HostCmd_ACT_GEN_REMOVE);
658 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
659 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
660 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
661 key_info = KEY_MCAST | KEY_UNICAST;
662 km->key_param_set.key_info = cpu_to_le16(key_info);
663 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
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 km->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
671 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
672 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
673 key_info = KEY_ENABLED;
674 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
675
676 if (enc_key->key_len <= WLAN_KEY_LEN_WEP104) {
acebe8c1 677 mwifiex_dbg(adapter, INFO, "%s: Set WEP Key\n", __func__);
e57f1734
AP
678 len += sizeof(struct mwifiex_wep_param);
679 km->key_param_set.len = cpu_to_le16(len);
680 km->key_param_set.key_type = KEY_TYPE_ID_WEP;
681
682 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
683 key_info |= KEY_MCAST | KEY_UNICAST;
684 } else {
685 if (enc_key->is_current_wep_key) {
686 key_info |= KEY_MCAST | KEY_UNICAST;
687 if (km->key_param_set.key_idx ==
688 (priv->wep_key_curr_index & KEY_INDEX_MASK))
689 key_info |= KEY_DEFAULT;
690 } else {
691 if (mac) {
692 if (is_broadcast_ether_addr(mac))
693 key_info |= KEY_MCAST;
694 else
695 key_info |= KEY_UNICAST |
696 KEY_DEFAULT;
697 } else {
698 key_info |= KEY_MCAST;
699 }
700 }
701 }
702 km->key_param_set.key_info = cpu_to_le16(key_info);
703
704 km->key_param_set.key_params.wep.key_len =
705 cpu_to_le16(enc_key->key_len);
706 memcpy(km->key_param_set.key_params.wep.key,
707 enc_key->key_material, enc_key->key_len);
708
709 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
710 len + sizeof(km->action) + S_DS_GEN);
711 return 0;
712 }
713
714 if (is_broadcast_ether_addr(mac))
715 key_info |= KEY_MCAST | KEY_RX_KEY;
716 else
717 key_info |= KEY_UNICAST | KEY_TX_KEY | KEY_RX_KEY;
718
719 if (enc_key->is_wapi_key) {
acebe8c1 720 mwifiex_dbg(adapter, INFO, "%s: Set WAPI Key\n", __func__);
e57f1734
AP
721 km->key_param_set.key_type = KEY_TYPE_ID_WAPI;
722 memcpy(km->key_param_set.key_params.wapi.pn, enc_key->pn,
723 PN_LEN);
724 km->key_param_set.key_params.wapi.key_len =
725 cpu_to_le16(enc_key->key_len);
726 memcpy(km->key_param_set.key_params.wapi.key,
727 enc_key->key_material, enc_key->key_len);
728 if (is_broadcast_ether_addr(mac))
729 priv->sec_info.wapi_key_on = true;
730
731 if (!priv->sec_info.wapi_key_on)
732 key_info |= KEY_DEFAULT;
733 km->key_param_set.key_info = cpu_to_le16(key_info);
734
735 len += sizeof(struct mwifiex_wapi_param);
736 km->key_param_set.len = cpu_to_le16(len);
737 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
738 len + sizeof(km->action) + S_DS_GEN);
739 return 0;
740 }
741
742 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
743 key_info |= KEY_DEFAULT;
744 /* Enable unicast bit for WPA-NONE/ADHOC_AES */
745 if (!priv->sec_info.wpa2_enabled &&
746 !is_broadcast_ether_addr(mac))
747 key_info |= KEY_UNICAST;
748 } else {
749 /* Enable default key for WPA/WPA2 */
750 if (!priv->wpa_is_gtk_set)
751 key_info |= KEY_DEFAULT;
752 }
753
754 km->key_param_set.key_info = cpu_to_le16(key_info);
755
756 if (enc_key->key_len == WLAN_KEY_LEN_CCMP)
757 return mwifiex_set_aes_key_v2(priv, cmd, enc_key, km);
758
759 if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
acebe8c1
ZL
760 mwifiex_dbg(adapter, INFO,
761 "%s: Set TKIP Key\n", __func__);
e57f1734
AP
762 if (enc_key->is_rx_seq_valid)
763 memcpy(km->key_param_set.key_params.tkip.pn,
764 enc_key->pn, enc_key->pn_len);
765 km->key_param_set.key_type = KEY_TYPE_ID_TKIP;
766 km->key_param_set.key_params.tkip.key_len =
767 cpu_to_le16(enc_key->key_len);
768 memcpy(km->key_param_set.key_params.tkip.key,
769 enc_key->key_material, enc_key->key_len);
770
771 len += sizeof(struct mwifiex_tkip_param);
772 km->key_param_set.len = cpu_to_le16(len);
773 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
774 len + sizeof(km->action) + S_DS_GEN);
775 }
776
777 return 0;
778}
779
5e6e3a92
BZ
780/*
781 * This function prepares command to set/get/reset network key(s).
e57f1734 782 * This function prepares key material command for V1 format.
5e6e3a92
BZ
783 *
784 * Preparation includes -
785 * - Setting command ID, action and proper size
786 * - Setting WEP keys, WAPI keys or WPA keys along with required
787 * encryption (TKIP, AES) (as required)
788 * - Ensuring correct endian-ness
789 */
a5ffddb7 790static int
e57f1734
AP
791mwifiex_cmd_802_11_key_material_v1(struct mwifiex_private *priv,
792 struct host_cmd_ds_command *cmd,
793 u16 cmd_action, u32 cmd_oid,
794 struct mwifiex_ds_encrypt_key *enc_key)
5e6e3a92
BZ
795{
796 struct host_cmd_ds_802_11_key_material *key_material =
797 &cmd->params.key_material;
75edd2c6
AP
798 struct host_cmd_tlv_mac_addr *tlv_mac;
799 u16 key_param_len = 0, cmd_size;
5e6e3a92 800 int ret = 0;
5e6e3a92
BZ
801
802 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
803 key_material->action = cpu_to_le16(cmd_action);
804
805 if (cmd_action == HostCmd_ACT_GEN_GET) {
806 cmd->size =
807 cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
808 return ret;
809 }
810
811 if (!enc_key) {
812 memset(&key_material->key_param_set, 0,
813 (NUM_WEP_KEYS *
814 sizeof(struct mwifiex_ie_type_key_param_set)));
815 ret = mwifiex_set_keyparamset_wep(priv,
816 &key_material->key_param_set,
817 &key_param_len);
818 cmd->size = cpu_to_le16(key_param_len +
819 sizeof(key_material->action) + S_DS_GEN);
820 return ret;
821 } else
822 memset(&key_material->key_param_set, 0,
823 sizeof(struct mwifiex_ie_type_key_param_set));
824 if (enc_key->is_wapi_key) {
acebe8c1 825 mwifiex_dbg(priv->adapter, INFO, "info: Set WAPI Key\n");
5e6e3a92 826 key_material->key_param_set.key_type_id =
9c05fd72 827 cpu_to_le16(KEY_TYPE_ID_WAPI);
5e6e3a92
BZ
828 if (cmd_oid == KEY_INFO_ENABLED)
829 key_material->key_param_set.key_info =
9c05fd72 830 cpu_to_le16(KEY_ENABLED);
5e6e3a92
BZ
831 else
832 key_material->key_param_set.key_info =
9c05fd72 833 cpu_to_le16(!KEY_ENABLED);
5e6e3a92
BZ
834
835 key_material->key_param_set.key[0] = enc_key->key_index;
836 if (!priv->sec_info.wapi_key_on)
837 key_material->key_param_set.key[1] = 1;
838 else
839 /* set 0 when re-key */
840 key_material->key_param_set.key[1] = 0;
841
a71bf90f 842 if (!is_broadcast_ether_addr(enc_key->mac_addr)) {
5e6e3a92
BZ
843 /* WAPI pairwise key: unicast */
844 key_material->key_param_set.key_info |=
6a35a0ac 845 cpu_to_le16(KEY_UNICAST);
5e6e3a92
BZ
846 } else { /* WAPI group key: multicast */
847 key_material->key_param_set.key_info |=
6a35a0ac 848 cpu_to_le16(KEY_MCAST);
5e6e3a92
BZ
849 priv->sec_info.wapi_key_on = true;
850 }
851
852 key_material->key_param_set.type =
9c05fd72 853 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
5e6e3a92 854 key_material->key_param_set.key_len =
9c05fd72 855 cpu_to_le16(WAPI_KEY_LEN);
5e6e3a92
BZ
856 memcpy(&key_material->key_param_set.key[2],
857 enc_key->key_material, enc_key->key_len);
858 memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
9d7aba63 859 enc_key->pn, PN_LEN);
5e6e3a92
BZ
860 key_material->key_param_set.length =
861 cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
862
863 key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
864 sizeof(struct mwifiex_ie_types_header);
9c05fd72
YAP
865 cmd->size = cpu_to_le16(sizeof(key_material->action)
866 + S_DS_GEN + key_param_len);
5e6e3a92
BZ
867 return ret;
868 }
869 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
b877f4cf 870 if (enc_key->is_igtk_key) {
acebe8c1 871 mwifiex_dbg(priv->adapter, CMD, "cmd: CMAC_AES\n");
b877f4cf
YL
872 key_material->key_param_set.key_type_id =
873 cpu_to_le16(KEY_TYPE_ID_AES_CMAC);
874 if (cmd_oid == KEY_INFO_ENABLED)
875 key_material->key_param_set.key_info =
876 cpu_to_le16(KEY_ENABLED);
877 else
878 key_material->key_param_set.key_info =
879 cpu_to_le16(!KEY_ENABLED);
880
881 key_material->key_param_set.key_info |=
882 cpu_to_le16(KEY_IGTK);
883 } else {
acebe8c1 884 mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_AES\n");
b877f4cf 885 key_material->key_param_set.key_type_id =
9c05fd72 886 cpu_to_le16(KEY_TYPE_ID_AES);
b877f4cf
YL
887 if (cmd_oid == KEY_INFO_ENABLED)
888 key_material->key_param_set.key_info =
9c05fd72 889 cpu_to_le16(KEY_ENABLED);
b877f4cf
YL
890 else
891 key_material->key_param_set.key_info =
9c05fd72 892 cpu_to_le16(!KEY_ENABLED);
5e6e3a92 893
b877f4cf 894 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
5e6e3a92 895 /* AES pairwise key: unicast */
b877f4cf 896 key_material->key_param_set.key_info |=
9c05fd72 897 cpu_to_le16(KEY_UNICAST);
b877f4cf
YL
898 else /* AES group key: multicast */
899 key_material->key_param_set.key_info |=
9c05fd72 900 cpu_to_le16(KEY_MCAST);
b877f4cf 901 }
5e6e3a92 902 } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
acebe8c1 903 mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_TKIP\n");
5e6e3a92 904 key_material->key_param_set.key_type_id =
9c05fd72 905 cpu_to_le16(KEY_TYPE_ID_TKIP);
5e6e3a92 906 key_material->key_param_set.key_info =
9c05fd72 907 cpu_to_le16(KEY_ENABLED);
5e6e3a92
BZ
908
909 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
910 /* TKIP pairwise key: unicast */
911 key_material->key_param_set.key_info |=
9c05fd72 912 cpu_to_le16(KEY_UNICAST);
5e6e3a92
BZ
913 else /* TKIP group key: multicast */
914 key_material->key_param_set.key_info |=
9c05fd72 915 cpu_to_le16(KEY_MCAST);
5e6e3a92
BZ
916 }
917
918 if (key_material->key_param_set.key_type_id) {
919 key_material->key_param_set.type =
9c05fd72 920 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
5e6e3a92 921 key_material->key_param_set.key_len =
9c05fd72 922 cpu_to_le16((u16) enc_key->key_len);
5e6e3a92
BZ
923 memcpy(key_material->key_param_set.key, enc_key->key_material,
924 enc_key->key_len);
925 key_material->key_param_set.length =
926 cpu_to_le16((u16) enc_key->key_len +
927 KEYPARAMSET_FIXED_LEN);
928
75edd2c6 929 key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
9c05fd72 930 + sizeof(struct mwifiex_ie_types_header);
5e6e3a92 931
b877f4cf
YL
932 if (le16_to_cpu(key_material->key_param_set.key_type_id) ==
933 KEY_TYPE_ID_AES_CMAC) {
934 struct mwifiex_cmac_param *param =
935 (void *)key_material->key_param_set.key;
936
937 memcpy(param->ipn, enc_key->pn, IGTK_PN_LEN);
938 memcpy(param->key, enc_key->key_material,
641c869d 939 WLAN_KEY_LEN_AES_CMAC);
b877f4cf
YL
940
941 key_param_len = sizeof(struct mwifiex_cmac_param);
942 key_material->key_param_set.key_len =
943 cpu_to_le16(key_param_len);
944 key_param_len += KEYPARAMSET_FIXED_LEN;
945 key_material->key_param_set.length =
946 cpu_to_le16(key_param_len);
947 key_param_len += sizeof(struct mwifiex_ie_types_header);
948 }
949
9c05fd72
YAP
950 cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
951 + key_param_len);
75edd2c6 952
8342bdac 953 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
75edd2c6
AP
954 tlv_mac = (void *)((u8 *)&key_material->key_param_set +
955 key_param_len);
6b21a69f
AK
956 tlv_mac->header.type =
957 cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
958 tlv_mac->header.len = cpu_to_le16(ETH_ALEN);
75edd2c6
AP
959 memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
960 cmd_size = key_param_len + S_DS_GEN +
961 sizeof(key_material->action) +
962 sizeof(struct host_cmd_tlv_mac_addr);
963 } else {
964 cmd_size = key_param_len + S_DS_GEN +
965 sizeof(key_material->action);
966 }
967 cmd->size = cpu_to_le16(cmd_size);
5e6e3a92
BZ
968 }
969
970 return ret;
971}
972
e57f1734
AP
973/* Wrapper function for setting network key depending upon FW KEY API version */
974static int
975mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
976 struct host_cmd_ds_command *cmd,
977 u16 cmd_action, u32 cmd_oid,
978 struct mwifiex_ds_encrypt_key *enc_key)
979{
4b9fede5 980 if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
e57f1734
AP
981 return mwifiex_cmd_802_11_key_material_v2(priv, cmd,
982 cmd_action, cmd_oid,
983 enc_key);
984
985 else
986 return mwifiex_cmd_802_11_key_material_v1(priv, cmd,
987 cmd_action, cmd_oid,
988 enc_key);
989}
990
5e6e3a92
BZ
991/*
992 * This function prepares command to set/get 11d domain information.
993 *
994 * Preparation includes -
995 * - Setting command ID, action and proper size
996 * - Setting domain information fields (for SET only)
997 * - Ensuring correct endian-ness
998 */
999static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
1000 struct host_cmd_ds_command *cmd,
1001 u16 cmd_action)
1002{
1003 struct mwifiex_adapter *adapter = priv->adapter;
1004 struct host_cmd_ds_802_11d_domain_info *domain_info =
1005 &cmd->params.domain_info;
1006 struct mwifiex_ietypes_domain_param_set *domain =
1007 &domain_info->domain;
1008 u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
1009
acebe8c1
ZL
1010 mwifiex_dbg(adapter, INFO,
1011 "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
5e6e3a92
BZ
1012
1013 cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
1014 domain_info->action = cpu_to_le16(cmd_action);
1015 if (cmd_action == HostCmd_ACT_GEN_GET) {
1016 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1017 return 0;
1018 }
1019
1020 /* Set domain info fields */
1021 domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
1022 memcpy(domain->country_code, adapter->domain_reg.country_code,
9c05fd72 1023 sizeof(domain->country_code));
5e6e3a92 1024
9c05fd72
YAP
1025 domain->header.len =
1026 cpu_to_le16((no_of_triplet *
1027 sizeof(struct ieee80211_country_ie_triplet))
1028 + sizeof(domain->country_code));
5e6e3a92
BZ
1029
1030 if (no_of_triplet) {
1031 memcpy(domain->triplet, adapter->domain_reg.triplet,
9c05fd72
YAP
1032 no_of_triplet * sizeof(struct
1033 ieee80211_country_ie_triplet));
5e6e3a92
BZ
1034
1035 cmd->size = cpu_to_le16(sizeof(domain_info->action) +
9c05fd72
YAP
1036 le16_to_cpu(domain->header.len) +
1037 sizeof(struct mwifiex_ie_types_header)
1038 + S_DS_GEN);
5e6e3a92
BZ
1039 } else {
1040 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1041 }
1042
1043 return 0;
1044}
1045
5e6e3a92
BZ
1046/*
1047 * This function prepares command to set/get IBSS coalescing status.
1048 *
1049 * Preparation includes -
1050 * - Setting command ID, action and proper size
1051 * - Setting status to enable or disable (for SET only)
1052 * - Ensuring correct endian-ness
1053 */
572e8f3e 1054static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
a5ffddb7 1055 u16 cmd_action, u16 *enable)
5e6e3a92
BZ
1056{
1057 struct host_cmd_ds_802_11_ibss_status *ibss_coal =
1058 &(cmd->params.ibss_coalescing);
5e6e3a92
BZ
1059
1060 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
1061 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
1062 S_DS_GEN);
1063 cmd->result = 0;
1064 ibss_coal->action = cpu_to_le16(cmd_action);
1065
1066 switch (cmd_action) {
1067 case HostCmd_ACT_GEN_SET:
a5ffddb7
AK
1068 if (enable)
1069 ibss_coal->enable = cpu_to_le16(*enable);
a5e5aa6c
DC
1070 else
1071 ibss_coal->enable = 0;
5e6e3a92
BZ
1072 break;
1073
1074 /* In other case.. Nothing to do */
1075 case HostCmd_ACT_GEN_GET:
1076 default:
1077 break;
1078 }
1079
1080 return 0;
1081}
1082
c2c6c85f
CL
1083/* This function prepares command buffer to get/set memory location value.
1084 */
1085static int
1086mwifiex_cmd_mem_access(struct host_cmd_ds_command *cmd, u16 cmd_action,
1087 void *pdata_buf)
1088{
1089 struct mwifiex_ds_mem_rw *mem_rw = (void *)pdata_buf;
1090 struct host_cmd_ds_mem_access *mem_access = (void *)&cmd->params.mem;
1091
1092 cmd->command = cpu_to_le16(HostCmd_CMD_MEM_ACCESS);
1093 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mem_access) +
1094 S_DS_GEN);
1095
1096 mem_access->action = cpu_to_le16(cmd_action);
1097 mem_access->addr = cpu_to_le32(mem_rw->addr);
1098 mem_access->value = cpu_to_le32(mem_rw->value);
1099
1100 return 0;
1101}
1102
5e6e3a92
BZ
1103/*
1104 * This function prepares command to set/get register value.
1105 *
1106 * Preparation includes -
1107 * - Setting command ID, action and proper size
1108 * - Setting register offset (for both GET and SET) and
1109 * register value (for SET only)
1110 * - Ensuring correct endian-ness
1111 *
1112 * The following type of registers can be accessed with this function -
1113 * - MAC register
1114 * - BBP register
1115 * - RF register
1116 * - PMIC register
1117 * - CAU register
1118 * - EEPROM
1119 */
1120static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
1121 u16 cmd_action, void *data_buf)
1122{
a5ffddb7 1123 struct mwifiex_ds_reg_rw *reg_rw = data_buf;
5e6e3a92 1124
5e6e3a92
BZ
1125 switch (le16_to_cpu(cmd->command)) {
1126 case HostCmd_CMD_MAC_REG_ACCESS:
1127 {
1128 struct host_cmd_ds_mac_reg_access *mac_reg;
1129
1130 cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
2c208890 1131 mac_reg = &cmd->params.mac_reg;
5e6e3a92
BZ
1132 mac_reg->action = cpu_to_le16(cmd_action);
1133 mac_reg->offset =
1134 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
1135 mac_reg->value = reg_rw->value;
1136 break;
1137 }
1138 case HostCmd_CMD_BBP_REG_ACCESS:
1139 {
1140 struct host_cmd_ds_bbp_reg_access *bbp_reg;
1141
1142 cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
2c208890 1143 bbp_reg = &cmd->params.bbp_reg;
5e6e3a92
BZ
1144 bbp_reg->action = cpu_to_le16(cmd_action);
1145 bbp_reg->offset =
1146 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
1147 bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
1148 break;
1149 }
1150 case HostCmd_CMD_RF_REG_ACCESS:
1151 {
1152 struct host_cmd_ds_rf_reg_access *rf_reg;
1153
1154 cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
2c208890 1155 rf_reg = &cmd->params.rf_reg;
5e6e3a92 1156 rf_reg->action = cpu_to_le16(cmd_action);
9c05fd72 1157 rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
5e6e3a92
BZ
1158 rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
1159 break;
1160 }
1161 case HostCmd_CMD_PMIC_REG_ACCESS:
1162 {
1163 struct host_cmd_ds_pmic_reg_access *pmic_reg;
1164
1165 cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
2c208890 1166 pmic_reg = &cmd->params.pmic_reg;
5e6e3a92
BZ
1167 pmic_reg->action = cpu_to_le16(cmd_action);
1168 pmic_reg->offset =
9c05fd72 1169 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
5e6e3a92
BZ
1170 pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
1171 break;
1172 }
1173 case HostCmd_CMD_CAU_REG_ACCESS:
1174 {
1175 struct host_cmd_ds_rf_reg_access *cau_reg;
1176
1177 cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
2c208890 1178 cau_reg = &cmd->params.rf_reg;
5e6e3a92
BZ
1179 cau_reg->action = cpu_to_le16(cmd_action);
1180 cau_reg->offset =
9c05fd72 1181 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
5e6e3a92
BZ
1182 cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
1183 break;
1184 }
1185 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1186 {
a5ffddb7 1187 struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
5e6e3a92 1188 struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
5e6e3a92
BZ
1189 &cmd->params.eeprom;
1190
1191 cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
1192 cmd_eeprom->action = cpu_to_le16(cmd_action);
1193 cmd_eeprom->offset = rd_eeprom->offset;
1194 cmd_eeprom->byte_count = rd_eeprom->byte_count;
1195 cmd_eeprom->value = 0;
1196 break;
1197 }
1198 default:
1199 return -1;
1200 }
1201
1202 return 0;
1203}
1204
d930faee
AK
1205/*
1206 * This function prepares command to set PCI-Express
1207 * host buffer configuration
1208 *
1209 * Preparation includes -
1210 * - Setting command ID, action and proper size
1211 * - Setting host buffer configuration
1212 * - Ensuring correct endian-ness
1213 */
1214static int
1215mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
9c05fd72 1216 struct host_cmd_ds_command *cmd, u16 action)
d930faee
AK
1217{
1218 struct host_cmd_ds_pcie_details *host_spec =
1219 &cmd->params.pcie_host_spec;
1220 struct pcie_service_card *card = priv->adapter->card;
d930faee
AK
1221
1222 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
1223 cmd->size = cpu_to_le16(sizeof(struct
1224 host_cmd_ds_pcie_details) + S_DS_GEN);
1225 cmd->result = 0;
1226
1227 memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
1228
9c05fd72
YAP
1229 if (action != HostCmd_ACT_GEN_SET)
1230 return 0;
1231
1232 /* Send the ring base addresses and count to firmware */
1233 host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
1234 host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
1235 host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
1236 host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
1237 host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
1238 host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
1239 host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
1240 host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
1241 host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
fc331460
AP
1242 if (card->sleep_cookie_vbase) {
1243 host_spec->sleep_cookie_addr_lo =
1244 (u32)(card->sleep_cookie_pbase);
1245 host_spec->sleep_cookie_addr_hi =
1246 (u32)(((u64)(card->sleep_cookie_pbase)) >> 32);
acebe8c1
ZL
1247 mwifiex_dbg(priv->adapter, INFO,
1248 "sleep_cook_lo phy addr: 0x%x\n",
1249 host_spec->sleep_cookie_addr_lo);
d930faee
AK
1250 }
1251
1252 return 0;
1253}
1254
fa444bf8
AK
1255/*
1256 * This function prepares command for event subscription, configuration
1257 * and query. Events can be subscribed or unsubscribed. Current subscribed
1258 * events can be queried. Also, current subscribed events are reported in
1259 * every FW response.
1260 */
1261static int
1262mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
1263 struct host_cmd_ds_command *cmd,
1264 struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
1265{
1266 struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
1267 struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
1268 u16 event_bitmap;
1269 u8 *pos;
1270
1271 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
1272 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
1273 S_DS_GEN);
1274
1275 subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
acebe8c1
ZL
1276 mwifiex_dbg(priv->adapter, CMD,
1277 "cmd: action: %d\n", subsc_evt_cfg->action);
fa444bf8
AK
1278
1279 /*For query requests, no configuration TLV structures are to be added.*/
1280 if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
1281 return 0;
1282
1283 subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
1284
1285 event_bitmap = subsc_evt_cfg->events;
acebe8c1
ZL
1286 mwifiex_dbg(priv->adapter, CMD, "cmd: event bitmap : %16x\n",
1287 event_bitmap);
fa444bf8
AK
1288
1289 if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
1290 (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
1291 (event_bitmap == 0)) {
acebe8c1
ZL
1292 mwifiex_dbg(priv->adapter, ERROR,
1293 "Error: No event specified\t"
1294 "for bitwise action type\n");
fa444bf8
AK
1295 return -EINVAL;
1296 }
1297
1298 /*
1299 * Append TLV structures for each of the specified events for
1300 * subscribing or re-configuring. This is not required for
1301 * bitwise unsubscribing request.
1302 */
1303 if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
1304 return 0;
1305
1306 pos = ((u8 *)subsc_evt) +
1307 sizeof(struct host_cmd_ds_802_11_subsc_evt);
1308
1309 if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
1310 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1311
1312 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
1313 rssi_tlv->header.len =
1314 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1315 sizeof(struct mwifiex_ie_types_header));
1316 rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
1317 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
1318
acebe8c1
ZL
1319 mwifiex_dbg(priv->adapter, EVENT,
1320 "Cfg Beacon Low Rssi event,\t"
1321 "RSSI:-%d dBm, Freq:%d\n",
1322 subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
1323 subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
fa444bf8
AK
1324
1325 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1326 le16_add_cpu(&cmd->size,
1327 sizeof(struct mwifiex_ie_types_rssi_threshold));
1328 }
1329
1330 if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
1331 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1332
1333 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1334 rssi_tlv->header.len =
1335 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1336 sizeof(struct mwifiex_ie_types_header));
1337 rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
1338 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
1339
acebe8c1
ZL
1340 mwifiex_dbg(priv->adapter, EVENT,
1341 "Cfg Beacon High Rssi event,\t"
1342 "RSSI:-%d dBm, Freq:%d\n",
1343 subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
1344 subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
fa444bf8
AK
1345
1346 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1347 le16_add_cpu(&cmd->size,
1348 sizeof(struct mwifiex_ie_types_rssi_threshold));
1349 }
1350
1351 return 0;
1352}
1353
7da060c1
AK
1354static int
1355mwifiex_cmd_append_rpn_expression(struct mwifiex_private *priv,
1356 struct mwifiex_mef_entry *mef_entry,
1357 u8 **buffer)
1358{
1359 struct mwifiex_mef_filter *filter = mef_entry->filter;
1360 int i, byte_len;
1361 u8 *stack_ptr = *buffer;
1362
3f4e854a 1363 for (i = 0; i < MWIFIEX_MEF_MAX_FILTERS; i++) {
7da060c1
AK
1364 filter = &mef_entry->filter[i];
1365 if (!filter->filt_type)
1366 break;
1367 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->repeat);
1368 stack_ptr += 4;
1369 *stack_ptr = TYPE_DNUM;
1370 stack_ptr += 1;
1371
3f4e854a 1372 byte_len = filter->byte_seq[MWIFIEX_MEF_MAX_BYTESEQ];
7da060c1
AK
1373 memcpy(stack_ptr, filter->byte_seq, byte_len);
1374 stack_ptr += byte_len;
1375 *stack_ptr = byte_len;
1376 stack_ptr += 1;
1377 *stack_ptr = TYPE_BYTESEQ;
1378 stack_ptr += 1;
1379
1380 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->offset);
1381 stack_ptr += 4;
1382 *stack_ptr = TYPE_DNUM;
1383 stack_ptr += 1;
1384
1385 *stack_ptr = filter->filt_type;
1386 stack_ptr += 1;
1387
1388 if (filter->filt_action) {
1389 *stack_ptr = filter->filt_action;
1390 stack_ptr += 1;
1391 }
1392
1393 if (stack_ptr - *buffer > STACK_NBYTES)
1394 return -1;
1395 }
1396
1397 *buffer = stack_ptr;
1398 return 0;
1399}
1400
1401static int
1402mwifiex_cmd_mef_cfg(struct mwifiex_private *priv,
1403 struct host_cmd_ds_command *cmd,
1404 struct mwifiex_ds_mef_cfg *mef)
1405{
1406 struct host_cmd_ds_mef_cfg *mef_cfg = &cmd->params.mef_cfg;
b533be18 1407 struct mwifiex_fw_mef_entry *mef_entry = NULL;
7da060c1 1408 u8 *pos = (u8 *)mef_cfg;
b533be18 1409 u16 i;
7da060c1
AK
1410
1411 cmd->command = cpu_to_le16(HostCmd_CMD_MEF_CFG);
1412
1413 mef_cfg->criteria = cpu_to_le32(mef->criteria);
1414 mef_cfg->num_entries = cpu_to_le16(mef->num_entries);
1415 pos += sizeof(*mef_cfg);
7da060c1 1416
b533be18
MH
1417 for (i = 0; i < mef->num_entries; i++) {
1418 mef_entry = (struct mwifiex_fw_mef_entry *)pos;
1419 mef_entry->mode = mef->mef_entry[i].mode;
1420 mef_entry->action = mef->mef_entry[i].action;
1421 pos += sizeof(*mef_cfg->mef_entry);
1422
1423 if (mwifiex_cmd_append_rpn_expression(priv,
1424 &mef->mef_entry[i], &pos))
1425 return -1;
7da060c1 1426
b533be18
MH
1427 mef_entry->exprsize =
1428 cpu_to_le16(pos - mef_entry->expr);
1429 }
7da060c1
AK
1430 cmd->size = cpu_to_le16((u16) (pos - (u8 *)mef_cfg) + S_DS_GEN);
1431
1432 return 0;
1433}
1434
388ec385
AK
1435/* This function parse cal data from ASCII to hex */
1436static u32 mwifiex_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
1437{
1438 u8 *s = src, *d = dst;
1439
1440 while (s - src < len) {
1441 if (*s && (isspace(*s) || *s == '\t')) {
1442 s++;
1443 continue;
1444 }
1445 if (isxdigit(*s)) {
1446 *d++ = simple_strtol(s, NULL, 16);
1447 s += 2;
1448 } else {
1449 s++;
1450 }
1451 }
1452
1453 return d - dst;
1454}
1455
82efa16a
BZ
1456int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv,
1457 struct device_node *node, const char *prefix)
699b027b
BZ
1458{
1459#ifdef CONFIG_OF
1460 struct property *prop;
1461 size_t len = strlen(prefix);
1462 int ret;
1463
1464 /* look for all matching property names */
1465 for_each_property_of_node(node, prop) {
1466 if (len > strlen(prop->name) ||
1467 strncmp(prop->name, prefix, len))
1468 continue;
1469
63791ccd
BZ
1470 /* property header is 6 bytes, data must fit in cmd buffer */
1471 if (prop && prop->value && prop->length > 6 &&
1472 prop->length <= MWIFIEX_SIZE_OF_CMD_BUFFER - S_DS_GEN) {
fa0ecbb9
BZ
1473 ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
1474 HostCmd_ACT_GEN_SET, 0,
1475 prop, true);
699b027b
BZ
1476 if (ret)
1477 return ret;
1478 }
1479 }
1480#endif
1481 return 0;
1482}
1483
388ec385
AK
1484/* This function prepares command of set_cfg_data. */
1485static int mwifiex_cmd_cfg_data(struct mwifiex_private *priv,
699b027b 1486 struct host_cmd_ds_command *cmd, void *data_buf)
388ec385 1487{
388ec385 1488 struct mwifiex_adapter *adapter = priv->adapter;
699b027b 1489 struct property *prop = data_buf;
d39fbc88
BZ
1490 u32 len;
1491 u8 *data = (u8 *)cmd + S_DS_GEN;
699b027b 1492 int ret;
388ec385 1493
699b027b
BZ
1494 if (prop) {
1495 len = prop->length;
1496 ret = of_property_read_u8_array(adapter->dt_node, prop->name,
1497 data, len);
1498 if (ret)
1499 return ret;
acebe8c1
ZL
1500 mwifiex_dbg(adapter, INFO,
1501 "download cfg_data from device tree: %s\n",
1502 prop->name);
699b027b 1503 } else if (adapter->cal_data->data && adapter->cal_data->size > 0) {
388ec385 1504 len = mwifiex_parse_cal_cfg((u8 *)adapter->cal_data->data,
d39fbc88 1505 adapter->cal_data->size, data);
acebe8c1
ZL
1506 mwifiex_dbg(adapter, INFO,
1507 "download cfg_data from config file\n");
699b027b 1508 } else {
388ec385 1509 return -1;
699b027b 1510 }
388ec385 1511
388ec385 1512 cmd->command = cpu_to_le16(HostCmd_CMD_CFG_DATA);
d39fbc88 1513 cmd->size = cpu_to_le16(S_DS_GEN + len);
388ec385
AK
1514
1515 return 0;
1516}
1517
d5b036c4
AP
1518static int
1519mwifiex_cmd_set_mc_policy(struct mwifiex_private *priv,
1520 struct host_cmd_ds_command *cmd,
1521 u16 cmd_action, void *data_buf)
1522{
1523 struct host_cmd_ds_multi_chan_policy *mc_pol = &cmd->params.mc_policy;
1524 const u16 *drcs_info = data_buf;
1525
1526 mc_pol->action = cpu_to_le16(cmd_action);
1527 mc_pol->policy = cpu_to_le16(*drcs_info);
1528 cmd->command = cpu_to_le16(HostCmd_CMD_MC_POLICY);
1529 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_multi_chan_policy) +
1530 S_DS_GEN);
1531 return 0;
1532}
1533
562fc5b3
AK
1534static int
1535mwifiex_cmd_coalesce_cfg(struct mwifiex_private *priv,
1536 struct host_cmd_ds_command *cmd,
1537 u16 cmd_action, void *data_buf)
1538{
1539 struct host_cmd_ds_coalesce_cfg *coalesce_cfg =
1540 &cmd->params.coalesce_cfg;
1541 struct mwifiex_ds_coalesce_cfg *cfg = data_buf;
1542 struct coalesce_filt_field_param *param;
1543 u16 cnt, idx, length;
1544 struct coalesce_receive_filt_rule *rule;
1545
1546 cmd->command = cpu_to_le16(HostCmd_CMD_COALESCE_CFG);
1547 cmd->size = cpu_to_le16(S_DS_GEN);
1548
1549 coalesce_cfg->action = cpu_to_le16(cmd_action);
1550 coalesce_cfg->num_of_rules = cpu_to_le16(cfg->num_of_rules);
1551 rule = coalesce_cfg->rule;
1552
1553 for (cnt = 0; cnt < cfg->num_of_rules; cnt++) {
1554 rule->header.type = cpu_to_le16(TLV_TYPE_COALESCE_RULE);
1555 rule->max_coalescing_delay =
1556 cpu_to_le16(cfg->rule[cnt].max_coalescing_delay);
1557 rule->pkt_type = cfg->rule[cnt].pkt_type;
1558 rule->num_of_fields = cfg->rule[cnt].num_of_fields;
1559
1560 length = 0;
1561
1562 param = rule->params;
1563 for (idx = 0; idx < cfg->rule[cnt].num_of_fields; idx++) {
1564 param->operation = cfg->rule[cnt].params[idx].operation;
1565 param->operand_len =
1566 cfg->rule[cnt].params[idx].operand_len;
1567 param->offset =
1568 cpu_to_le16(cfg->rule[cnt].params[idx].offset);
1569 memcpy(param->operand_byte_stream,
1570 cfg->rule[cnt].params[idx].operand_byte_stream,
1571 param->operand_len);
1572
1573 length += sizeof(struct coalesce_filt_field_param);
1574
1575 param++;
1576 }
1577
1578 /* Total rule length is sizeof max_coalescing_delay(u16),
1579 * num_of_fields(u8), pkt_type(u8) and total length of the all
1580 * params
1581 */
1582 rule->header.len = cpu_to_le16(length + sizeof(u16) +
1583 sizeof(u8) + sizeof(u8));
1584
1585 /* Add the rule length to the command size*/
1586 le16_add_cpu(&cmd->size, le16_to_cpu(rule->header.len) +
1587 sizeof(struct mwifiex_ie_types_header));
1588
1589 rule = (void *)((u8 *)rule->params + length);
1590 }
1591
1592 /* Add sizeof action, num_of_rules to total command length */
1593 le16_add_cpu(&cmd->size, sizeof(u16) + sizeof(u16));
1594
1595 return 0;
1596}
1597
449b8bbf
XH
1598static int
1599mwifiex_cmd_tdls_config(struct mwifiex_private *priv,
1600 struct host_cmd_ds_command *cmd,
1601 u16 cmd_action, void *data_buf)
1602{
1603 struct host_cmd_ds_tdls_config *tdls_config = &cmd->params.tdls_config;
1604 struct mwifiex_tdls_init_cs_params *config;
1605 struct mwifiex_tdls_config *init_config;
1606 u16 len;
1607
1608 cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_CONFIG);
1609 cmd->size = cpu_to_le16(S_DS_GEN);
1610 tdls_config->tdls_action = cpu_to_le16(cmd_action);
1611 le16_add_cpu(&cmd->size, sizeof(tdls_config->tdls_action));
1612
1613 switch (cmd_action) {
1614 case ACT_TDLS_CS_ENABLE_CONFIG:
1615 init_config = data_buf;
1616 len = sizeof(*init_config);
1617 memcpy(tdls_config->tdls_data, init_config, len);
1618 break;
1619 case ACT_TDLS_CS_INIT:
1620 config = data_buf;
1621 len = sizeof(*config);
1622 memcpy(tdls_config->tdls_data, config, len);
1623 break;
1624 case ACT_TDLS_CS_STOP:
1625 len = sizeof(struct mwifiex_tdls_stop_cs_params);
1626 memcpy(tdls_config->tdls_data, data_buf, len);
1627 break;
1628 case ACT_TDLS_CS_PARAMS:
1629 len = sizeof(struct mwifiex_tdls_config_cs_params);
1630 memcpy(tdls_config->tdls_data, data_buf, len);
1631 break;
1632 default:
1633 mwifiex_dbg(priv->adapter, ERROR,
1634 "Unknown TDLS configuration\n");
1635 return -ENOTSUPP;
1636 }
1637
1638 le16_add_cpu(&cmd->size, len);
1639 return 0;
1640}
1641
429d90d2
AP
1642static int
1643mwifiex_cmd_tdls_oper(struct mwifiex_private *priv,
1644 struct host_cmd_ds_command *cmd,
1645 void *data_buf)
1646{
1647 struct host_cmd_ds_tdls_oper *tdls_oper = &cmd->params.tdls_oper;
1648 struct mwifiex_ds_tdls_oper *oper = data_buf;
1649 struct mwifiex_sta_node *sta_ptr;
1f4dfd8a
AP
1650 struct host_cmd_tlv_rates *tlv_rates;
1651 struct mwifiex_ie_types_htcap *ht_capab;
1652 struct mwifiex_ie_types_qos_info *wmm_qos_info;
1653 struct mwifiex_ie_types_extcap *extcap;
5f6d5983
AP
1654 struct mwifiex_ie_types_vhtcap *vht_capab;
1655 struct mwifiex_ie_types_aid *aid;
d29caf25 1656 struct mwifiex_ie_types_tdls_idle_timeout *timeout;
1f4dfd8a
AP
1657 u8 *pos, qos_info;
1658 u16 config_len = 0;
1659 struct station_parameters *params = priv->sta_params;
429d90d2
AP
1660
1661 cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_OPER);
1662 cmd->size = cpu_to_le16(S_DS_GEN);
1f4dfd8a 1663 le16_add_cpu(&cmd->size, sizeof(struct host_cmd_ds_tdls_oper));
429d90d2
AP
1664
1665 tdls_oper->reason = 0;
1666 memcpy(tdls_oper->peer_mac, oper->peer_mac, ETH_ALEN);
1667 sta_ptr = mwifiex_get_sta_entry(priv, oper->peer_mac);
1668
1f4dfd8a
AP
1669 pos = (u8 *)tdls_oper + sizeof(struct host_cmd_ds_tdls_oper);
1670
429d90d2
AP
1671 switch (oper->tdls_action) {
1672 case MWIFIEX_TDLS_DISABLE_LINK:
1673 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_DELETE);
1674 break;
e48e0de0
AP
1675 case MWIFIEX_TDLS_CREATE_LINK:
1676 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CREATE);
1f4dfd8a
AP
1677 break;
1678 case MWIFIEX_TDLS_CONFIG_LINK:
1679 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CONFIG);
1680
1681 if (!params) {
acebe8c1
ZL
1682 mwifiex_dbg(priv->adapter, ERROR,
1683 "TDLS config params not available for %pM\n",
1684 oper->peer_mac);
1f4dfd8a
AP
1685 return -ENODATA;
1686 }
1687
1688 *(__le16 *)pos = cpu_to_le16(params->capability);
1689 config_len += sizeof(params->capability);
1690
1691 qos_info = params->uapsd_queues | (params->max_sp << 5);
1692 wmm_qos_info = (struct mwifiex_ie_types_qos_info *)(pos +
1693 config_len);
1694 wmm_qos_info->header.type = cpu_to_le16(WLAN_EID_QOS_CAPA);
1695 wmm_qos_info->header.len = cpu_to_le16(sizeof(qos_info));
1696 wmm_qos_info->qos_info = qos_info;
1697 config_len += sizeof(struct mwifiex_ie_types_qos_info);
1698
1699 if (params->ht_capa) {
1700 ht_capab = (struct mwifiex_ie_types_htcap *)(pos +
1701 config_len);
1702 ht_capab->header.type =
1703 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1704 ht_capab->header.len =
1705 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
1706 memcpy(&ht_capab->ht_cap, params->ht_capa,
1707 sizeof(struct ieee80211_ht_cap));
1708 config_len += sizeof(struct mwifiex_ie_types_htcap);
1709 }
1710
1711 if (params->supported_rates && params->supported_rates_len) {
1712 tlv_rates = (struct host_cmd_tlv_rates *)(pos +
1713 config_len);
1714 tlv_rates->header.type =
1715 cpu_to_le16(WLAN_EID_SUPP_RATES);
1716 tlv_rates->header.len =
1717 cpu_to_le16(params->supported_rates_len);
1718 memcpy(tlv_rates->rates, params->supported_rates,
1719 params->supported_rates_len);
1720 config_len += sizeof(struct host_cmd_tlv_rates) +
1721 params->supported_rates_len;
1722 }
1723
1724 if (params->ext_capab && params->ext_capab_len) {
1725 extcap = (struct mwifiex_ie_types_extcap *)(pos +
1726 config_len);
1727 extcap->header.type =
1728 cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
1729 extcap->header.len = cpu_to_le16(params->ext_capab_len);
1730 memcpy(extcap->ext_capab, params->ext_capab,
1731 params->ext_capab_len);
1732 config_len += sizeof(struct mwifiex_ie_types_extcap) +
1733 params->ext_capab_len;
1734 }
5f6d5983
AP
1735 if (params->vht_capa) {
1736 vht_capab = (struct mwifiex_ie_types_vhtcap *)(pos +
1737 config_len);
1738 vht_capab->header.type =
1739 cpu_to_le16(WLAN_EID_VHT_CAPABILITY);
1740 vht_capab->header.len =
1741 cpu_to_le16(sizeof(struct ieee80211_vht_cap));
1742 memcpy(&vht_capab->vht_cap, params->vht_capa,
1743 sizeof(struct ieee80211_vht_cap));
1744 config_len += sizeof(struct mwifiex_ie_types_vhtcap);
1745 }
1746 if (params->aid) {
1747 aid = (struct mwifiex_ie_types_aid *)(pos + config_len);
1748 aid->header.type = cpu_to_le16(WLAN_EID_AID);
1749 aid->header.len = cpu_to_le16(sizeof(params->aid));
1750 aid->aid = cpu_to_le16(params->aid);
1751 config_len += sizeof(struct mwifiex_ie_types_aid);
1752 }
1f4dfd8a 1753
d29caf25
AP
1754 timeout = (void *)(pos + config_len);
1755 timeout->header.type = cpu_to_le16(TLV_TYPE_TDLS_IDLE_TIMEOUT);
1756 timeout->header.len = cpu_to_le16(sizeof(timeout->value));
30fa51c8 1757 timeout->value = cpu_to_le16(MWIFIEX_TDLS_IDLE_TIMEOUT_IN_SEC);
d29caf25
AP
1758 config_len += sizeof(struct mwifiex_ie_types_tdls_idle_timeout);
1759
e48e0de0 1760 break;
429d90d2 1761 default:
acebe8c1 1762 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS operation\n");
429d90d2
AP
1763 return -ENOTSUPP;
1764 }
1765
1f4dfd8a 1766 le16_add_cpu(&cmd->size, config_len);
429d90d2
AP
1767
1768 return 0;
1769}
92263a84
ZL
1770
1771/* This function prepares command of sdio rx aggr info. */
1772static int mwifiex_cmd_sdio_rx_aggr_cfg(struct host_cmd_ds_command *cmd,
1773 u16 cmd_action, void *data_buf)
1774{
1775 struct host_cmd_sdio_sp_rx_aggr_cfg *cfg =
1776 &cmd->params.sdio_rx_aggr_cfg;
1777
1778 cmd->command = cpu_to_le16(HostCmd_CMD_SDIO_SP_RX_AGGR_CFG);
1779 cmd->size =
1780 cpu_to_le16(sizeof(struct host_cmd_sdio_sp_rx_aggr_cfg) +
1781 S_DS_GEN);
1782 cfg->action = cmd_action;
1783 if (cmd_action == HostCmd_ACT_GEN_SET)
1784 cfg->enable = *(u8 *)data_buf;
1785
1786 return 0;
1787}
1788
5e6e3a92
BZ
1789/*
1790 * This function prepares the commands before sending them to the firmware.
1791 *
1792 * This is a generic function which calls specific command preparation
1793 * routines based upon the command number.
1794 */
1795int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1796 u16 cmd_action, u32 cmd_oid,
1797 void *data_buf, void *cmd_buf)
1798{
a5ffddb7 1799 struct host_cmd_ds_command *cmd_ptr = cmd_buf;
5e6e3a92
BZ
1800 int ret = 0;
1801
1802 /* Prepare command */
1803 switch (cmd_no) {
1804 case HostCmd_CMD_GET_HW_SPEC:
1805 ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
1806 break;
388ec385 1807 case HostCmd_CMD_CFG_DATA:
699b027b 1808 ret = mwifiex_cmd_cfg_data(priv, cmd_ptr, data_buf);
388ec385 1809 break;
5e6e3a92
BZ
1810 case HostCmd_CMD_MAC_CONTROL:
1811 ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
1812 data_buf);
1813 break;
1814 case HostCmd_CMD_802_11_MAC_ADDRESS:
1815 ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
1816 cmd_action);
1817 break;
1818 case HostCmd_CMD_MAC_MULTICAST_ADR:
572e8f3e 1819 ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
5e6e3a92
BZ
1820 data_buf);
1821 break;
1822 case HostCmd_CMD_TX_RATE_CFG:
1823 ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
1824 data_buf);
1825 break;
1826 case HostCmd_CMD_TXPWR_CFG:
572e8f3e 1827 ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
5e6e3a92
BZ
1828 data_buf);
1829 break;
caa8984f
AK
1830 case HostCmd_CMD_RF_TX_PWR:
1831 ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
1832 data_buf);
1833 break;
8a279d5b
AK
1834 case HostCmd_CMD_RF_ANTENNA:
1835 ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
1836 data_buf);
1837 break;
5e6e3a92
BZ
1838 case HostCmd_CMD_802_11_PS_MODE_ENH:
1839 ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
1840 (uint16_t)cmd_oid, data_buf);
1841 break;
1842 case HostCmd_CMD_802_11_HS_CFG_ENH:
1843 ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
1844 (struct mwifiex_hs_config_param *) data_buf);
1845 break;
1846 case HostCmd_CMD_802_11_SCAN:
572e8f3e 1847 ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
5e6e3a92
BZ
1848 break;
1849 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
572e8f3e 1850 ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
5e6e3a92
BZ
1851 break;
1852 case HostCmd_CMD_802_11_ASSOCIATE:
1853 ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
1854 break;
1855 case HostCmd_CMD_802_11_DEAUTHENTICATE:
1856 ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
1857 data_buf);
1858 break;
1859 case HostCmd_CMD_802_11_AD_HOC_START:
1860 ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
1861 data_buf);
1862 break;
1863 case HostCmd_CMD_802_11_GET_LOG:
572e8f3e 1864 ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
5e6e3a92
BZ
1865 break;
1866 case HostCmd_CMD_802_11_AD_HOC_JOIN:
1867 ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
1868 data_buf);
1869 break;
1870 case HostCmd_CMD_802_11_AD_HOC_STOP:
572e8f3e 1871 ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
5e6e3a92
BZ
1872 break;
1873 case HostCmd_CMD_RSSI_INFO:
1874 ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
1875 break;
1876 case HostCmd_CMD_802_11_SNMP_MIB:
1877 ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
1878 cmd_oid, data_buf);
1879 break;
1880 case HostCmd_CMD_802_11_TX_RATE_QUERY:
1881 cmd_ptr->command =
1882 cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
1883 cmd_ptr->size =
1884 cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
1885 S_DS_GEN);
1886 priv->tx_rate = 0;
1887 ret = 0;
1888 break;
1889 case HostCmd_CMD_VERSION_EXT:
1890 cmd_ptr->command = cpu_to_le16(cmd_no);
1891 cmd_ptr->params.verext.version_str_sel =
1892 (u8) (*((u32 *) data_buf));
1893 memcpy(&cmd_ptr->params, data_buf,
1894 sizeof(struct host_cmd_ds_version_ext));
1895 cmd_ptr->size =
1896 cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
1897 S_DS_GEN);
1898 ret = 0;
1899 break;
3cec6870
SP
1900 case HostCmd_CMD_MGMT_FRAME_REG:
1901 cmd_ptr->command = cpu_to_le16(cmd_no);
1902 cmd_ptr->params.reg_mask.action = cpu_to_le16(cmd_action);
1903 cmd_ptr->params.reg_mask.mask = cpu_to_le32(*(u32 *)data_buf);
1904 cmd_ptr->size =
1905 cpu_to_le16(sizeof(struct host_cmd_ds_mgmt_frame_reg) +
1906 S_DS_GEN);
1907 ret = 0;
1908 break;
7feb4c48
SP
1909 case HostCmd_CMD_REMAIN_ON_CHAN:
1910 cmd_ptr->command = cpu_to_le16(cmd_no);
1911 memcpy(&cmd_ptr->params, data_buf,
1912 sizeof(struct host_cmd_ds_remain_on_chan));
1913 cmd_ptr->size =
1914 cpu_to_le16(sizeof(struct host_cmd_ds_remain_on_chan) +
1915 S_DS_GEN);
1916 break;
83c78da9
YAP
1917 case HostCmd_CMD_11AC_CFG:
1918 ret = mwifiex_cmd_11ac_cfg(priv, cmd_ptr, cmd_action, data_buf);
1919 break;
e1a2b7a3
SP
1920 case HostCmd_CMD_P2P_MODE_CFG:
1921 cmd_ptr->command = cpu_to_le16(cmd_no);
1922 cmd_ptr->params.mode_cfg.action = cpu_to_le16(cmd_action);
1923 cmd_ptr->params.mode_cfg.mode = cpu_to_le16(*(u16 *)data_buf);
1924 cmd_ptr->size =
1925 cpu_to_le16(sizeof(struct host_cmd_ds_p2p_mode_cfg) +
1926 S_DS_GEN);
1927 break;
5e6e3a92
BZ
1928 case HostCmd_CMD_FUNC_INIT:
1929 if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
1930 priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
1931 cmd_ptr->command = cpu_to_le16(cmd_no);
1932 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1933 break;
1934 case HostCmd_CMD_FUNC_SHUTDOWN:
1935 priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
1936 cmd_ptr->command = cpu_to_le16(cmd_no);
1937 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1938 break;
1939 case HostCmd_CMD_11N_ADDBA_REQ:
572e8f3e 1940 ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
5e6e3a92
BZ
1941 break;
1942 case HostCmd_CMD_11N_DELBA:
572e8f3e 1943 ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
5e6e3a92
BZ
1944 break;
1945 case HostCmd_CMD_11N_ADDBA_RSP:
1946 ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
1947 break;
1948 case HostCmd_CMD_802_11_KEY_MATERIAL:
1949 ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
9c05fd72
YAP
1950 cmd_action, cmd_oid,
1951 data_buf);
5e6e3a92
BZ
1952 break;
1953 case HostCmd_CMD_802_11D_DOMAIN_INFO:
1954 ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
9c05fd72 1955 cmd_action);
5e6e3a92
BZ
1956 break;
1957 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
1958 ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
1959 data_buf);
1960 break;
1961 case HostCmd_CMD_AMSDU_AGGR_CTRL:
572e8f3e 1962 ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
5e6e3a92
BZ
1963 data_buf);
1964 break;
1965 case HostCmd_CMD_11N_CFG:
a5f39056 1966 ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf);
5e6e3a92
BZ
1967 break;
1968 case HostCmd_CMD_WMM_GET_STATUS:
acebe8c1
ZL
1969 mwifiex_dbg(priv->adapter, CMD,
1970 "cmd: WMM: WMM_GET_STATUS cmd sent\n");
5e6e3a92
BZ
1971 cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
1972 cmd_ptr->size =
1973 cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
1974 S_DS_GEN);
1975 ret = 0;
1976 break;
1977 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
572e8f3e
AK
1978 ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
1979 data_buf);
5e6e3a92 1980 break;
21f58d20
AK
1981 case HostCmd_CMD_802_11_SCAN_EXT:
1982 ret = mwifiex_cmd_802_11_scan_ext(priv, cmd_ptr, data_buf);
1983 break;
c2c6c85f
CL
1984 case HostCmd_CMD_MEM_ACCESS:
1985 ret = mwifiex_cmd_mem_access(cmd_ptr, cmd_action, data_buf);
1986 break;
5e6e3a92
BZ
1987 case HostCmd_CMD_MAC_REG_ACCESS:
1988 case HostCmd_CMD_BBP_REG_ACCESS:
1989 case HostCmd_CMD_RF_REG_ACCESS:
1990 case HostCmd_CMD_PMIC_REG_ACCESS:
1991 case HostCmd_CMD_CAU_REG_ACCESS:
1992 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1993 ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
1994 break;
1995 case HostCmd_CMD_SET_BSS_MODE:
1996 cmd_ptr->command = cpu_to_le16(cmd_no);
eecd8250 1997 if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
5e6e3a92
BZ
1998 cmd_ptr->params.bss_mode.con_type =
1999 CONNECTION_TYPE_ADHOC;
ae86c587
AN
2000 else if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2001 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT)
5e6e3a92
BZ
2002 cmd_ptr->params.bss_mode.con_type =
2003 CONNECTION_TYPE_INFRA;
ae86c587
AN
2004 else if (priv->bss_mode == NL80211_IFTYPE_AP ||
2005 priv->bss_mode == NL80211_IFTYPE_P2P_GO)
9197ab9e 2006 cmd_ptr->params.bss_mode.con_type = CONNECTION_TYPE_AP;
5e6e3a92
BZ
2007 cmd_ptr->size = cpu_to_le16(sizeof(struct
2008 host_cmd_ds_set_bss_mode) + S_DS_GEN);
2009 ret = 0;
2010 break;
d930faee
AK
2011 case HostCmd_CMD_PCIE_DESC_DETAILS:
2012 ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
2013 break;
fa444bf8
AK
2014 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
2015 ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
2016 break;
7da060c1
AK
2017 case HostCmd_CMD_MEF_CFG:
2018 ret = mwifiex_cmd_mef_cfg(priv, cmd_ptr, data_buf);
2019 break;
562fc5b3
AK
2020 case HostCmd_CMD_COALESCE_CFG:
2021 ret = mwifiex_cmd_coalesce_cfg(priv, cmd_ptr, cmd_action,
2022 data_buf);
2023 break;
429d90d2
AP
2024 case HostCmd_CMD_TDLS_OPER:
2025 ret = mwifiex_cmd_tdls_oper(priv, cmd_ptr, data_buf);
2026 break;
449b8bbf
XH
2027 case HostCmd_CMD_TDLS_CONFIG:
2028 ret = mwifiex_cmd_tdls_config(priv, cmd_ptr, cmd_action,
2029 data_buf);
2030 break;
85afb186
AP
2031 case HostCmd_CMD_CHAN_REPORT_REQUEST:
2032 ret = mwifiex_cmd_issue_chan_report_request(priv, cmd_ptr,
2033 data_buf);
2034 break;
92263a84
ZL
2035 case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG:
2036 ret = mwifiex_cmd_sdio_rx_aggr_cfg(cmd_ptr, cmd_action,
2037 data_buf);
2038 break;
d5b036c4
AP
2039 case HostCmd_CMD_MC_POLICY:
2040 ret = mwifiex_cmd_set_mc_policy(priv, cmd_ptr, cmd_action,
2041 data_buf);
2042 break;
5e6e3a92 2043 default:
acebe8c1
ZL
2044 mwifiex_dbg(priv->adapter, ERROR,
2045 "PREP_CMD: unknown cmd- %#x\n", cmd_no);
5e6e3a92
BZ
2046 ret = -1;
2047 break;
2048 }
2049 return ret;
2050}
2051
2052/*
2053 * This function issues commands to initialize firmware.
2054 *
2055 * This is called after firmware download to bring the card to
2056 * working state.
1247cc1f
AP
2057 * Function is also called during reinitialization of virtual
2058 * interfaces.
5e6e3a92
BZ
2059 *
2060 * The following commands are issued sequentially -
d930faee 2061 * - Set PCI-Express host buffer configuration (PCIE only)
5e6e3a92
BZ
2062 * - Function init (for first interface only)
2063 * - Read MAC address (for first interface only)
2064 * - Reconfigure Tx buffer size (for first interface only)
2065 * - Enable auto deep sleep (for first interface only)
2066 * - Get Tx rate
2067 * - Get Tx power
2068 * - Set IBSS coalescing status
2069 * - Set AMSDU aggregation control
2070 * - Set 11d control
2071 * - Set MAC control (this must be the last command to initialize firmware)
2072 */
1247cc1f 2073int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta, bool init)
5e6e3a92 2074{
388ec385 2075 struct mwifiex_adapter *adapter = priv->adapter;
270e58e8 2076 int ret;
5e6e3a92
BZ
2077 u16 enable = true;
2078 struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
2079 struct mwifiex_ds_auto_ds auto_ds;
2080 enum state_11d_t state_11d;
cd27bc3c 2081 struct mwifiex_ds_11n_tx_cfg tx_cfg;
92263a84 2082 u8 sdio_sp_rx_aggr_enable;
5e6e3a92
BZ
2083
2084 if (first_sta) {
d930faee 2085 if (priv->adapter->iface_type == MWIFIEX_PCIE) {
fa0ecbb9
BZ
2086 ret = mwifiex_send_cmd(priv,
2087 HostCmd_CMD_PCIE_DESC_DETAILS,
2088 HostCmd_ACT_GEN_SET, 0, NULL,
2089 true);
d930faee
AK
2090 if (ret)
2091 return -1;
2092 }
5e6e3a92 2093
fa0ecbb9
BZ
2094 ret = mwifiex_send_cmd(priv, HostCmd_CMD_FUNC_INIT,
2095 HostCmd_ACT_GEN_SET, 0, NULL, true);
5e6e3a92
BZ
2096 if (ret)
2097 return -1;
388ec385 2098
699b027b
BZ
2099 /* Download calibration data to firmware.
2100 * The cal-data can be read from device tree and/or
2101 * a configuration file and downloaded to firmware.
2102 */
2103 adapter->dt_node =
2104 of_find_node_by_name(NULL, "marvell_cfgdata");
2105 if (adapter->dt_node) {
2106 ret = mwifiex_dnld_dt_cfgdata(priv, adapter->dt_node,
2107 "marvell,caldata");
2108 if (ret)
2109 return -1;
2110 }
2111
388ec385 2112 if (adapter->cal_data) {
fa0ecbb9
BZ
2113 ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
2114 HostCmd_ACT_GEN_SET, 0, NULL,
2115 true);
388ec385
AK
2116 if (ret)
2117 return -1;
2118 }
2119
5e6e3a92 2120 /* Read MAC address from HW */
fa0ecbb9
BZ
2121 ret = mwifiex_send_cmd(priv, HostCmd_CMD_GET_HW_SPEC,
2122 HostCmd_ACT_GEN_GET, 0, NULL, true);
5e6e3a92
BZ
2123 if (ret)
2124 return -1;
2125
92263a84
ZL
2126 /** Set SDIO Single Port RX Aggr Info */
2127 if (priv->adapter->iface_type == MWIFIEX_SDIO &&
2128 ISSUPP_SDIO_SPA_ENABLED(priv->adapter->fw_cap_info)) {
2129 sdio_sp_rx_aggr_enable = true;
2130 ret = mwifiex_send_cmd(priv,
2131 HostCmd_CMD_SDIO_SP_RX_AGGR_CFG,
2132 HostCmd_ACT_GEN_SET, 0,
2133 &sdio_sp_rx_aggr_enable,
2134 true);
2135 if (ret) {
acebe8c1
ZL
2136 mwifiex_dbg(priv->adapter, ERROR,
2137 "error while enabling SP aggregation..disable it");
92263a84
ZL
2138 adapter->sdio_rx_aggr_enable = false;
2139 }
2140 }
2141
5e6e3a92 2142 /* Reconfigure tx buf size */
fa0ecbb9
BZ
2143 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
2144 HostCmd_ACT_GEN_SET, 0,
2145 &priv->adapter->tx_buf_size, true);
5e6e3a92
BZ
2146 if (ret)
2147 return -1;
2148
03785387
AP
2149 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2150 /* Enable IEEE PS by default */
2151 priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
fa0ecbb9
BZ
2152 ret = mwifiex_send_cmd(priv,
2153 HostCmd_CMD_802_11_PS_MODE_ENH,
2154 EN_AUTO_PS, BITMAP_STA_PS, NULL,
2155 true);
03785387
AP
2156 if (ret)
2157 return -1;
2158 }
d5b036c4 2159
de9e9932
AP
2160 if (drcs) {
2161 adapter->drcs_enabled = true;
2162 if (ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
2163 ret = mwifiex_send_cmd(priv,
2164 HostCmd_CMD_MC_POLICY,
2165 HostCmd_ACT_GEN_SET, 0,
2166 &adapter->drcs_enabled,
2167 true);
d5b036c4
AP
2168 if (ret)
2169 return -1;
de9e9932 2170 }
5e6e3a92
BZ
2171 }
2172
2173 /* get tx rate */
fa0ecbb9
BZ
2174 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
2175 HostCmd_ACT_GEN_GET, 0, NULL, true);
5e6e3a92
BZ
2176 if (ret)
2177 return -1;
2178 priv->data_rate = 0;
2179
2180 /* get tx power */
fa0ecbb9
BZ
2181 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
2182 HostCmd_ACT_GEN_GET, 0, NULL, true);
5e6e3a92
BZ
2183 if (ret)
2184 return -1;
2185
03785387
AP
2186 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
2187 /* set ibss coalescing_status */
fa0ecbb9
BZ
2188 ret = mwifiex_send_cmd(
2189 priv,
2190 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
2191 HostCmd_ACT_GEN_SET, 0, &enable, true);
03785387
AP
2192 if (ret)
2193 return -1;
2194 }
5e6e3a92
BZ
2195
2196 memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
2197 amsdu_aggr_ctrl.enable = true;
2198 /* Send request to firmware */
fa0ecbb9
BZ
2199 ret = mwifiex_send_cmd(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
2200 HostCmd_ACT_GEN_SET, 0,
2201 &amsdu_aggr_ctrl, true);
5e6e3a92
BZ
2202 if (ret)
2203 return -1;
2204 /* MAC Control must be the last command in init_fw */
2205 /* set MAC Control */
fa0ecbb9
BZ
2206 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
2207 HostCmd_ACT_GEN_SET, 0,
2208 &priv->curr_pkt_filter, true);
5e6e3a92
BZ
2209 if (ret)
2210 return -1;
2211
0b4155d1
AP
2212 if (!disable_auto_ds &&
2213 first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
03785387 2214 priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
5e6e3a92
BZ
2215 /* Enable auto deep sleep */
2216 auto_ds.auto_ds = DEEP_SLEEP_ON;
2217 auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
fa0ecbb9
BZ
2218 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
2219 EN_AUTO_PS, BITMAP_AUTO_DS,
2220 &auto_ds, true);
5e6e3a92
BZ
2221 if (ret)
2222 return -1;
2223 }
2224
03785387
AP
2225 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2226 /* Send cmd to FW to enable/disable 11D function */
2227 state_11d = ENABLE_11D;
fa0ecbb9
BZ
2228 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
2229 HostCmd_ACT_GEN_SET, DOT11D_I,
2230 &state_11d, true);
03785387 2231 if (ret)
acebe8c1
ZL
2232 mwifiex_dbg(priv->adapter, ERROR,
2233 "11D: failed to enable 11D\n");
03785387 2234 }
5e6e3a92 2235
cd27bc3c
AK
2236 /* Send cmd to FW to configure 11n specific configuration
2237 * (Short GI, Channel BW, Green field support etc.) for transmit
2238 */
2239 tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
fa0ecbb9
BZ
2240 ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_CFG,
2241 HostCmd_ACT_GEN_SET, 0, &tx_cfg, true);
cd27bc3c 2242
1247cc1f
AP
2243 if (init) {
2244 /* set last_init_cmd before sending the command */
2245 priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
2246 ret = -EINPROGRESS;
2247 }
5e6e3a92
BZ
2248
2249 return ret;
2250}
This page took 0.495533 seconds and 5 git commands to generate.