mwifiex: correction in mwifiex_check_fw_status() return status
[deliverable/linux.git] / drivers / net / wireless / mwifiex / sta_cmd.c
CommitLineData
5e6e3a92
BZ
1/*
2 * Marvell Wireless LAN device driver: station command handling
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
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
BZ
28
29/*
30 * This function prepares command to set/get RSSI information.
31 *
32 * Preparation includes -
33 * - Setting command ID, action and proper size
34 * - Setting data/beacon average factors
35 * - Resetting SNR/NF/RSSI values in private structure
36 * - Ensuring correct endian-ness
37 */
38static int
39mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
40 struct host_cmd_ds_command *cmd, u16 cmd_action)
41{
42 cmd->command = cpu_to_le16(HostCmd_CMD_RSSI_INFO);
43 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rssi_info) +
44 S_DS_GEN);
45 cmd->params.rssi_info.action = cpu_to_le16(cmd_action);
46 cmd->params.rssi_info.ndata = cpu_to_le16(priv->data_avg_factor);
47 cmd->params.rssi_info.nbcn = cpu_to_le16(priv->bcn_avg_factor);
48
49 /* Reset SNR/NF/RSSI values in private structure */
50 priv->data_rssi_last = 0;
51 priv->data_nf_last = 0;
52 priv->data_rssi_avg = 0;
53 priv->data_nf_avg = 0;
54 priv->bcn_rssi_last = 0;
55 priv->bcn_nf_last = 0;
56 priv->bcn_rssi_avg = 0;
57 priv->bcn_nf_avg = 0;
58
59 return 0;
60}
61
62/*
63 * This function prepares command to set MAC control.
64 *
65 * Preparation includes -
66 * - Setting command ID, action and proper size
67 * - Ensuring correct endian-ness
68 */
69static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
70 struct host_cmd_ds_command *cmd,
a5ffddb7 71 u16 cmd_action, u16 *action)
5e6e3a92
BZ
72{
73 struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
5e6e3a92
BZ
74
75 if (cmd_action != HostCmd_ACT_GEN_SET) {
76 dev_err(priv->adapter->dev,
77 "mac_control: only support set cmd\n");
78 return -1;
79 }
80
81 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
82 cmd->size =
83 cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
a5ffddb7 84 mac_ctrl->action = cpu_to_le16(*action);
5e6e3a92
BZ
85
86 return 0;
87}
88
89/*
90 * This function prepares command to set/get SNMP MIB.
91 *
92 * Preparation includes -
93 * - Setting command ID, action and proper size
94 * - Setting SNMP MIB OID number and value
95 * (as required)
96 * - Ensuring correct endian-ness
97 *
98 * The following SNMP MIB OIDs are supported -
99 * - FRAG_THRESH_I : Fragmentation threshold
100 * - RTS_THRESH_I : RTS threshold
101 * - SHORT_RETRY_LIM_I : Short retry limit
102 * - DOT11D_I : 11d support
103 */
104static int mwifiex_cmd_802_11_snmp_mib(struct mwifiex_private *priv,
105 struct host_cmd_ds_command *cmd,
106 u16 cmd_action, u32 cmd_oid,
f3c8d259 107 u16 *ul_temp)
5e6e3a92
BZ
108{
109 struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
5e6e3a92
BZ
110
111 dev_dbg(priv->adapter->dev, "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
112 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SNMP_MIB);
113 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_snmp_mib)
9c05fd72 114 - 1 + S_DS_GEN);
5e6e3a92 115
f3c8d259 116 snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
5e6e3a92
BZ
117 if (cmd_action == HostCmd_ACT_GEN_GET) {
118 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_GET);
119 snmp_mib->buf_size = cpu_to_le16(MAX_SNMP_BUF_SIZE);
f3c8d259
AK
120 le16_add_cpu(&cmd->size, MAX_SNMP_BUF_SIZE);
121 } else if (cmd_action == HostCmd_ACT_GEN_SET) {
122 snmp_mib->query_type = cpu_to_le16(HostCmd_ACT_GEN_SET);
123 snmp_mib->buf_size = cpu_to_le16(sizeof(u16));
124 *((__le16 *) (snmp_mib->value)) = cpu_to_le16(*ul_temp);
125 le16_add_cpu(&cmd->size, sizeof(u16));
5e6e3a92
BZ
126 }
127
5e6e3a92
BZ
128 dev_dbg(priv->adapter->dev,
129 "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
130 " Value=0x%x\n",
9c05fd72
YAP
131 cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
132 le16_to_cpu(*(__le16 *) snmp_mib->value));
5e6e3a92
BZ
133 return 0;
134}
135
136/*
137 * This function prepares command to get log.
138 *
139 * Preparation includes -
140 * - Setting command ID and proper size
141 * - Ensuring correct endian-ness
142 */
143static int
572e8f3e 144mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
5e6e3a92
BZ
145{
146 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_GET_LOG);
147 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_get_log) +
148 S_DS_GEN);
149 return 0;
150}
151
152/*
153 * This function prepares command to set/get Tx data rate configuration.
154 *
155 * Preparation includes -
156 * - Setting command ID, action and proper size
157 * - Setting configuration index, rate scope and rate drop pattern
158 * parameters (as required)
159 * - Ensuring correct endian-ness
160 */
161static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
162 struct host_cmd_ds_command *cmd,
a5ffddb7 163 u16 cmd_action, u16 *pbitmap_rates)
5e6e3a92
BZ
164{
165 struct host_cmd_ds_tx_rate_cfg *rate_cfg = &cmd->params.tx_rate_cfg;
166 struct mwifiex_rate_scope *rate_scope;
167 struct mwifiex_rate_drop_pattern *rate_drop;
5e6e3a92
BZ
168 u32 i;
169
170 cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
171
172 rate_cfg->action = cpu_to_le16(cmd_action);
173 rate_cfg->cfg_index = 0;
174
175 rate_scope = (struct mwifiex_rate_scope *) ((u8 *) rate_cfg +
176 sizeof(struct host_cmd_ds_tx_rate_cfg));
177 rate_scope->type = cpu_to_le16(TLV_TYPE_RATE_SCOPE);
9c05fd72
YAP
178 rate_scope->length = cpu_to_le16
179 (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
5e6e3a92
BZ
180 if (pbitmap_rates != NULL) {
181 rate_scope->hr_dsss_rate_bitmap = cpu_to_le16(pbitmap_rates[0]);
182 rate_scope->ofdm_rate_bitmap = cpu_to_le16(pbitmap_rates[1]);
183 for (i = 0;
184 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
185 i++)
186 rate_scope->ht_mcs_rate_bitmap[i] =
187 cpu_to_le16(pbitmap_rates[2 + i]);
188 } else {
189 rate_scope->hr_dsss_rate_bitmap =
190 cpu_to_le16(priv->bitmap_rates[0]);
191 rate_scope->ofdm_rate_bitmap =
192 cpu_to_le16(priv->bitmap_rates[1]);
193 for (i = 0;
194 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
195 i++)
196 rate_scope->ht_mcs_rate_bitmap[i] =
197 cpu_to_le16(priv->bitmap_rates[2 + i]);
198 }
199
200 rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
9c05fd72 201 sizeof(struct mwifiex_rate_scope));
5e6e3a92
BZ
202 rate_drop->type = cpu_to_le16(TLV_TYPE_RATE_DROP_CONTROL);
203 rate_drop->length = cpu_to_le16(sizeof(rate_drop->rate_drop_mode));
204 rate_drop->rate_drop_mode = 0;
205
206 cmd->size =
207 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_tx_rate_cfg) +
208 sizeof(struct mwifiex_rate_scope) +
209 sizeof(struct mwifiex_rate_drop_pattern));
210
211 return 0;
212}
213
214/*
215 * This function prepares command to set/get Tx power configuration.
216 *
217 * Preparation includes -
218 * - Setting command ID, action and proper size
219 * - Setting Tx power mode, power group TLV
220 * (as required)
221 * - Ensuring correct endian-ness
222 */
572e8f3e 223static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
a5ffddb7
AK
224 u16 cmd_action,
225 struct host_cmd_ds_txpwr_cfg *txp)
5e6e3a92 226{
270e58e8 227 struct mwifiex_types_power_group *pg_tlv;
5e6e3a92
BZ
228 struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
229
230 cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
231 cmd->size =
232 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
233 switch (cmd_action) {
234 case HostCmd_ACT_GEN_SET:
5e6e3a92
BZ
235 if (txp->mode) {
236 pg_tlv = (struct mwifiex_types_power_group
a5ffddb7 237 *) ((unsigned long) txp +
5e6e3a92 238 sizeof(struct host_cmd_ds_txpwr_cfg));
a5ffddb7 239 memmove(cmd_txp_cfg, txp,
5e6e3a92
BZ
240 sizeof(struct host_cmd_ds_txpwr_cfg) +
241 sizeof(struct mwifiex_types_power_group) +
242 pg_tlv->length);
243
244 pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
245 cmd_txp_cfg +
246 sizeof(struct host_cmd_ds_txpwr_cfg));
247 cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
248 sizeof(struct mwifiex_types_power_group) +
249 pg_tlv->length);
250 } else {
a5ffddb7 251 memmove(cmd_txp_cfg, txp, sizeof(*txp));
5e6e3a92
BZ
252 }
253 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
254 break;
255 case HostCmd_ACT_GEN_GET:
256 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
257 break;
258 }
259
260 return 0;
261}
262
caa8984f
AK
263/*
264 * This function prepares command to get RF Tx power.
265 */
266static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv,
267 struct host_cmd_ds_command *cmd,
268 u16 cmd_action, void *data_buf)
269{
270 struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp;
271
272 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr)
273 + S_DS_GEN);
274 cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR);
275 txp->action = cpu_to_le16(cmd_action);
276
277 return 0;
278}
279
8a279d5b
AK
280/*
281 * This function prepares command to set rf antenna.
282 */
283static int mwifiex_cmd_rf_antenna(struct mwifiex_private *priv,
284 struct host_cmd_ds_command *cmd,
285 u16 cmd_action,
286 struct mwifiex_ds_ant_cfg *ant_cfg)
287{
288 struct host_cmd_ds_rf_ant_mimo *ant_mimo = &cmd->params.ant_mimo;
289 struct host_cmd_ds_rf_ant_siso *ant_siso = &cmd->params.ant_siso;
290
291 cmd->command = cpu_to_le16(HostCmd_CMD_RF_ANTENNA);
292
293 if (cmd_action != HostCmd_ACT_GEN_SET)
294 return 0;
295
296 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
297 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_mimo) +
298 S_DS_GEN);
299 ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_SET_TX);
300 ant_mimo->tx_ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
301 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX);
302 ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg->rx_ant);
303 } else {
304 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_ant_siso) +
305 S_DS_GEN);
306 ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH);
307 ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
308 }
309
310 return 0;
311}
312
5e6e3a92
BZ
313/*
314 * This function prepares command to set Host Sleep configuration.
315 *
316 * Preparation includes -
317 * - Setting command ID and proper size
318 * - Setting Host Sleep action, conditions, ARP filters
319 * (as required)
320 * - Ensuring correct endian-ness
321 */
a5ffddb7
AK
322static int
323mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
324 struct host_cmd_ds_command *cmd,
325 u16 cmd_action,
326 struct mwifiex_hs_config_param *hscfg_param)
5e6e3a92
BZ
327{
328 struct mwifiex_adapter *adapter = priv->adapter;
329 struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
330 u16 hs_activate = false;
331
a5ffddb7 332 if (!hscfg_param)
5e6e3a92
BZ
333 /* New Activate command */
334 hs_activate = true;
335 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
336
337 if (!hs_activate &&
cc0b5a64 338 (hscfg_param->conditions != cpu_to_le32(HS_CFG_CANCEL)) &&
9c05fd72
YAP
339 ((adapter->arp_filter_size > 0) &&
340 (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
5e6e3a92
BZ
341 dev_dbg(adapter->dev,
342 "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
9c05fd72 343 adapter->arp_filter_size);
5e6e3a92
BZ
344 memcpy(((u8 *) hs_cfg) +
345 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
346 adapter->arp_filter, adapter->arp_filter_size);
9c05fd72
YAP
347 cmd->size = cpu_to_le16
348 (adapter->arp_filter_size +
349 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
350 + S_DS_GEN);
5e6e3a92
BZ
351 } else {
352 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
9c05fd72 353 host_cmd_ds_802_11_hs_cfg_enh));
5e6e3a92
BZ
354 }
355 if (hs_activate) {
356 hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
357 hs_cfg->params.hs_activate.resp_ctrl = RESP_NEEDED;
358 } else {
359 hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
a5ffddb7
AK
360 hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
361 hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
362 hs_cfg->params.hs_config.gap = hscfg_param->gap;
5e6e3a92
BZ
363 dev_dbg(adapter->dev,
364 "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
365 hs_cfg->params.hs_config.conditions,
366 hs_cfg->params.hs_config.gpio,
367 hs_cfg->params.hs_config.gap);
368 }
369
370 return 0;
371}
372
373/*
374 * This function prepares command to set/get MAC address.
375 *
376 * Preparation includes -
377 * - Setting command ID, action and proper size
378 * - Setting MAC address (for SET only)
379 * - Ensuring correct endian-ness
380 */
381static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
382 struct host_cmd_ds_command *cmd,
383 u16 cmd_action)
384{
385 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
386 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
387 S_DS_GEN);
388 cmd->result = 0;
389
390 cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
391
392 if (cmd_action == HostCmd_ACT_GEN_SET)
393 memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
394 ETH_ALEN);
395 return 0;
396}
397
398/*
399 * This function prepares command to set MAC multicast address.
400 *
401 * Preparation includes -
402 * - Setting command ID, action and proper size
403 * - Setting MAC multicast address
404 * - Ensuring correct endian-ness
405 */
a5ffddb7
AK
406static int
407mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
408 u16 cmd_action,
409 struct mwifiex_multicast_list *mcast_list)
5e6e3a92 410{
5e6e3a92
BZ
411 struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
412
413 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
414 S_DS_GEN);
415 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
416
417 mcast_addr->action = cpu_to_le16(cmd_action);
418 mcast_addr->num_of_adrs =
419 cpu_to_le16((u16) mcast_list->num_multicast_addr);
420 memcpy(mcast_addr->mac_list, mcast_list->mac_list,
421 mcast_list->num_multicast_addr * ETH_ALEN);
422
423 return 0;
424}
425
426/*
427 * This function prepares command to deauthenticate.
428 *
429 * Preparation includes -
430 * - Setting command ID and proper size
431 * - Setting AP MAC address and reason code
432 * - Ensuring correct endian-ness
433 */
434static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
435 struct host_cmd_ds_command *cmd,
a5ffddb7 436 u8 *mac)
5e6e3a92
BZ
437{
438 struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
439
440 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
441 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
442 + S_DS_GEN);
443
444 /* Set AP MAC address */
a5ffddb7 445 memcpy(deauth->mac_addr, mac, ETH_ALEN);
5e6e3a92
BZ
446
447 dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
448
449 deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
450
451 return 0;
452}
453
454/*
455 * This function prepares command to stop Ad-Hoc network.
456 *
457 * Preparation includes -
458 * - Setting command ID and proper size
459 * - Ensuring correct endian-ness
460 */
572e8f3e 461static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
5e6e3a92
BZ
462{
463 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
464 cmd->size = cpu_to_le16(S_DS_GEN);
465 return 0;
466}
467
468/*
469 * This function sets WEP key(s) to key parameter TLV(s).
470 *
471 * Multi-key parameter TLVs are supported, so we can send multiple
472 * WEP keys in a single buffer.
473 */
474static int
475mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
476 struct mwifiex_ie_type_key_param_set *key_param_set,
477 u16 *key_param_len)
478{
270e58e8 479 int cur_key_param_len;
5e6e3a92
BZ
480 u8 i;
481
482 /* Multi-key_param_set TLV is supported */
483 for (i = 0; i < NUM_WEP_KEYS; i++) {
484 if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
485 (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
486 key_param_set->type =
487 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
488/* Key_param_set WEP fixed length */
489#define KEYPARAMSET_WEP_FIXED_LEN 8
490 key_param_set->length = cpu_to_le16((u16)
491 (priv->wep_key[i].
492 key_length +
493 KEYPARAMSET_WEP_FIXED_LEN));
494 key_param_set->key_type_id =
495 cpu_to_le16(KEY_TYPE_ID_WEP);
496 key_param_set->key_info =
6a35a0ac
YAP
497 cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
498 KEY_MCAST);
5e6e3a92
BZ
499 key_param_set->key_len =
500 cpu_to_le16(priv->wep_key[i].key_length);
501 /* Set WEP key index */
502 key_param_set->key[0] = i;
503 /* Set default Tx key flag */
504 if (i ==
505 (priv->
506 wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
507 key_param_set->key[1] = 1;
508 else
509 key_param_set->key[1] = 0;
510 memmove(&key_param_set->key[2],
511 priv->wep_key[i].key_material,
512 priv->wep_key[i].key_length);
513
514 cur_key_param_len = priv->wep_key[i].key_length +
515 KEYPARAMSET_WEP_FIXED_LEN +
516 sizeof(struct mwifiex_ie_types_header);
517 *key_param_len += (u16) cur_key_param_len;
518 key_param_set =
519 (struct mwifiex_ie_type_key_param_set *)
520 ((u8 *)key_param_set +
9c05fd72 521 cur_key_param_len);
5e6e3a92
BZ
522 } else if (!priv->wep_key[i].key_length) {
523 continue;
524 } else {
525 dev_err(priv->adapter->dev,
526 "key%d Length = %d is incorrect\n",
527 (i + 1), priv->wep_key[i].key_length);
528 return -1;
529 }
530 }
531
532 return 0;
533}
534
535/*
536 * This function prepares command to set/get/reset network key(s).
537 *
538 * Preparation includes -
539 * - Setting command ID, action and proper size
540 * - Setting WEP keys, WAPI keys or WPA keys along with required
541 * encryption (TKIP, AES) (as required)
542 * - Ensuring correct endian-ness
543 */
a5ffddb7
AK
544static int
545mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
546 struct host_cmd_ds_command *cmd,
547 u16 cmd_action, u32 cmd_oid,
548 struct mwifiex_ds_encrypt_key *enc_key)
5e6e3a92
BZ
549{
550 struct host_cmd_ds_802_11_key_material *key_material =
551 &cmd->params.key_material;
75edd2c6
AP
552 struct host_cmd_tlv_mac_addr *tlv_mac;
553 u16 key_param_len = 0, cmd_size;
5e6e3a92 554 int ret = 0;
5e6e3a92
BZ
555
556 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
557 key_material->action = cpu_to_le16(cmd_action);
558
559 if (cmd_action == HostCmd_ACT_GEN_GET) {
560 cmd->size =
561 cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
562 return ret;
563 }
564
565 if (!enc_key) {
566 memset(&key_material->key_param_set, 0,
567 (NUM_WEP_KEYS *
568 sizeof(struct mwifiex_ie_type_key_param_set)));
569 ret = mwifiex_set_keyparamset_wep(priv,
570 &key_material->key_param_set,
571 &key_param_len);
572 cmd->size = cpu_to_le16(key_param_len +
573 sizeof(key_material->action) + S_DS_GEN);
574 return ret;
575 } else
576 memset(&key_material->key_param_set, 0,
577 sizeof(struct mwifiex_ie_type_key_param_set));
578 if (enc_key->is_wapi_key) {
579 dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
580 key_material->key_param_set.key_type_id =
9c05fd72 581 cpu_to_le16(KEY_TYPE_ID_WAPI);
5e6e3a92
BZ
582 if (cmd_oid == KEY_INFO_ENABLED)
583 key_material->key_param_set.key_info =
9c05fd72 584 cpu_to_le16(KEY_ENABLED);
5e6e3a92
BZ
585 else
586 key_material->key_param_set.key_info =
9c05fd72 587 cpu_to_le16(!KEY_ENABLED);
5e6e3a92
BZ
588
589 key_material->key_param_set.key[0] = enc_key->key_index;
590 if (!priv->sec_info.wapi_key_on)
591 key_material->key_param_set.key[1] = 1;
592 else
593 /* set 0 when re-key */
594 key_material->key_param_set.key[1] = 0;
595
a71bf90f 596 if (!is_broadcast_ether_addr(enc_key->mac_addr)) {
5e6e3a92
BZ
597 /* WAPI pairwise key: unicast */
598 key_material->key_param_set.key_info |=
6a35a0ac 599 cpu_to_le16(KEY_UNICAST);
5e6e3a92
BZ
600 } else { /* WAPI group key: multicast */
601 key_material->key_param_set.key_info |=
6a35a0ac 602 cpu_to_le16(KEY_MCAST);
5e6e3a92
BZ
603 priv->sec_info.wapi_key_on = true;
604 }
605
606 key_material->key_param_set.type =
9c05fd72 607 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
5e6e3a92 608 key_material->key_param_set.key_len =
9c05fd72 609 cpu_to_le16(WAPI_KEY_LEN);
5e6e3a92
BZ
610 memcpy(&key_material->key_param_set.key[2],
611 enc_key->key_material, enc_key->key_len);
612 memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
9d7aba63 613 enc_key->pn, PN_LEN);
5e6e3a92
BZ
614 key_material->key_param_set.length =
615 cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
616
617 key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
618 sizeof(struct mwifiex_ie_types_header);
9c05fd72
YAP
619 cmd->size = cpu_to_le16(sizeof(key_material->action)
620 + S_DS_GEN + key_param_len);
5e6e3a92
BZ
621 return ret;
622 }
623 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
b877f4cf
YL
624 if (enc_key->is_igtk_key) {
625 dev_dbg(priv->adapter->dev, "cmd: CMAC_AES\n");
626 key_material->key_param_set.key_type_id =
627 cpu_to_le16(KEY_TYPE_ID_AES_CMAC);
628 if (cmd_oid == KEY_INFO_ENABLED)
629 key_material->key_param_set.key_info =
630 cpu_to_le16(KEY_ENABLED);
631 else
632 key_material->key_param_set.key_info =
633 cpu_to_le16(!KEY_ENABLED);
634
635 key_material->key_param_set.key_info |=
636 cpu_to_le16(KEY_IGTK);
637 } else {
638 dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
639 key_material->key_param_set.key_type_id =
9c05fd72 640 cpu_to_le16(KEY_TYPE_ID_AES);
b877f4cf
YL
641 if (cmd_oid == KEY_INFO_ENABLED)
642 key_material->key_param_set.key_info =
9c05fd72 643 cpu_to_le16(KEY_ENABLED);
b877f4cf
YL
644 else
645 key_material->key_param_set.key_info =
9c05fd72 646 cpu_to_le16(!KEY_ENABLED);
5e6e3a92 647
b877f4cf 648 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
5e6e3a92 649 /* AES pairwise key: unicast */
b877f4cf 650 key_material->key_param_set.key_info |=
9c05fd72 651 cpu_to_le16(KEY_UNICAST);
b877f4cf
YL
652 else /* AES group key: multicast */
653 key_material->key_param_set.key_info |=
9c05fd72 654 cpu_to_le16(KEY_MCAST);
b877f4cf 655 }
5e6e3a92
BZ
656 } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
657 dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
658 key_material->key_param_set.key_type_id =
9c05fd72 659 cpu_to_le16(KEY_TYPE_ID_TKIP);
5e6e3a92 660 key_material->key_param_set.key_info =
9c05fd72 661 cpu_to_le16(KEY_ENABLED);
5e6e3a92
BZ
662
663 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
664 /* TKIP pairwise key: unicast */
665 key_material->key_param_set.key_info |=
9c05fd72 666 cpu_to_le16(KEY_UNICAST);
5e6e3a92
BZ
667 else /* TKIP group key: multicast */
668 key_material->key_param_set.key_info |=
9c05fd72 669 cpu_to_le16(KEY_MCAST);
5e6e3a92
BZ
670 }
671
672 if (key_material->key_param_set.key_type_id) {
673 key_material->key_param_set.type =
9c05fd72 674 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
5e6e3a92 675 key_material->key_param_set.key_len =
9c05fd72 676 cpu_to_le16((u16) enc_key->key_len);
5e6e3a92
BZ
677 memcpy(key_material->key_param_set.key, enc_key->key_material,
678 enc_key->key_len);
679 key_material->key_param_set.length =
680 cpu_to_le16((u16) enc_key->key_len +
681 KEYPARAMSET_FIXED_LEN);
682
75edd2c6 683 key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
9c05fd72 684 + sizeof(struct mwifiex_ie_types_header);
5e6e3a92 685
b877f4cf
YL
686 if (le16_to_cpu(key_material->key_param_set.key_type_id) ==
687 KEY_TYPE_ID_AES_CMAC) {
688 struct mwifiex_cmac_param *param =
689 (void *)key_material->key_param_set.key;
690
691 memcpy(param->ipn, enc_key->pn, IGTK_PN_LEN);
692 memcpy(param->key, enc_key->key_material,
641c869d 693 WLAN_KEY_LEN_AES_CMAC);
b877f4cf
YL
694
695 key_param_len = sizeof(struct mwifiex_cmac_param);
696 key_material->key_param_set.key_len =
697 cpu_to_le16(key_param_len);
698 key_param_len += KEYPARAMSET_FIXED_LEN;
699 key_material->key_param_set.length =
700 cpu_to_le16(key_param_len);
701 key_param_len += sizeof(struct mwifiex_ie_types_header);
702 }
703
9c05fd72
YAP
704 cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
705 + key_param_len);
75edd2c6
AP
706
707 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
708 tlv_mac = (void *)((u8 *)&key_material->key_param_set +
709 key_param_len);
710 tlv_mac->tlv.type = cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
711 tlv_mac->tlv.len = cpu_to_le16(ETH_ALEN);
712 memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
713 cmd_size = key_param_len + S_DS_GEN +
714 sizeof(key_material->action) +
715 sizeof(struct host_cmd_tlv_mac_addr);
716 } else {
717 cmd_size = key_param_len + S_DS_GEN +
718 sizeof(key_material->action);
719 }
720 cmd->size = cpu_to_le16(cmd_size);
5e6e3a92
BZ
721 }
722
723 return ret;
724}
725
726/*
727 * This function prepares command to set/get 11d domain information.
728 *
729 * Preparation includes -
730 * - Setting command ID, action and proper size
731 * - Setting domain information fields (for SET only)
732 * - Ensuring correct endian-ness
733 */
734static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
735 struct host_cmd_ds_command *cmd,
736 u16 cmd_action)
737{
738 struct mwifiex_adapter *adapter = priv->adapter;
739 struct host_cmd_ds_802_11d_domain_info *domain_info =
740 &cmd->params.domain_info;
741 struct mwifiex_ietypes_domain_param_set *domain =
742 &domain_info->domain;
743 u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
744
745 dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
746
747 cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
748 domain_info->action = cpu_to_le16(cmd_action);
749 if (cmd_action == HostCmd_ACT_GEN_GET) {
750 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
751 return 0;
752 }
753
754 /* Set domain info fields */
755 domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
756 memcpy(domain->country_code, adapter->domain_reg.country_code,
9c05fd72 757 sizeof(domain->country_code));
5e6e3a92 758
9c05fd72
YAP
759 domain->header.len =
760 cpu_to_le16((no_of_triplet *
761 sizeof(struct ieee80211_country_ie_triplet))
762 + sizeof(domain->country_code));
5e6e3a92
BZ
763
764 if (no_of_triplet) {
765 memcpy(domain->triplet, adapter->domain_reg.triplet,
9c05fd72
YAP
766 no_of_triplet * sizeof(struct
767 ieee80211_country_ie_triplet));
5e6e3a92
BZ
768
769 cmd->size = cpu_to_le16(sizeof(domain_info->action) +
9c05fd72
YAP
770 le16_to_cpu(domain->header.len) +
771 sizeof(struct mwifiex_ie_types_header)
772 + S_DS_GEN);
5e6e3a92
BZ
773 } else {
774 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
775 }
776
777 return 0;
778}
779
5e6e3a92
BZ
780/*
781 * This function prepares command to set/get IBSS coalescing status.
782 *
783 * Preparation includes -
784 * - Setting command ID, action and proper size
785 * - Setting status to enable or disable (for SET only)
786 * - Ensuring correct endian-ness
787 */
572e8f3e 788static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
a5ffddb7 789 u16 cmd_action, u16 *enable)
5e6e3a92
BZ
790{
791 struct host_cmd_ds_802_11_ibss_status *ibss_coal =
792 &(cmd->params.ibss_coalescing);
5e6e3a92
BZ
793
794 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
795 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
796 S_DS_GEN);
797 cmd->result = 0;
798 ibss_coal->action = cpu_to_le16(cmd_action);
799
800 switch (cmd_action) {
801 case HostCmd_ACT_GEN_SET:
a5ffddb7
AK
802 if (enable)
803 ibss_coal->enable = cpu_to_le16(*enable);
a5e5aa6c
DC
804 else
805 ibss_coal->enable = 0;
5e6e3a92
BZ
806 break;
807
808 /* In other case.. Nothing to do */
809 case HostCmd_ACT_GEN_GET:
810 default:
811 break;
812 }
813
814 return 0;
815}
816
817/*
818 * This function prepares command to set/get register value.
819 *
820 * Preparation includes -
821 * - Setting command ID, action and proper size
822 * - Setting register offset (for both GET and SET) and
823 * register value (for SET only)
824 * - Ensuring correct endian-ness
825 *
826 * The following type of registers can be accessed with this function -
827 * - MAC register
828 * - BBP register
829 * - RF register
830 * - PMIC register
831 * - CAU register
832 * - EEPROM
833 */
834static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
835 u16 cmd_action, void *data_buf)
836{
a5ffddb7 837 struct mwifiex_ds_reg_rw *reg_rw = data_buf;
5e6e3a92 838
5e6e3a92
BZ
839 switch (le16_to_cpu(cmd->command)) {
840 case HostCmd_CMD_MAC_REG_ACCESS:
841 {
842 struct host_cmd_ds_mac_reg_access *mac_reg;
843
844 cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
2c208890 845 mac_reg = &cmd->params.mac_reg;
5e6e3a92
BZ
846 mac_reg->action = cpu_to_le16(cmd_action);
847 mac_reg->offset =
848 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
849 mac_reg->value = reg_rw->value;
850 break;
851 }
852 case HostCmd_CMD_BBP_REG_ACCESS:
853 {
854 struct host_cmd_ds_bbp_reg_access *bbp_reg;
855
856 cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
2c208890 857 bbp_reg = &cmd->params.bbp_reg;
5e6e3a92
BZ
858 bbp_reg->action = cpu_to_le16(cmd_action);
859 bbp_reg->offset =
860 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
861 bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
862 break;
863 }
864 case HostCmd_CMD_RF_REG_ACCESS:
865 {
866 struct host_cmd_ds_rf_reg_access *rf_reg;
867
868 cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
2c208890 869 rf_reg = &cmd->params.rf_reg;
5e6e3a92 870 rf_reg->action = cpu_to_le16(cmd_action);
9c05fd72 871 rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
5e6e3a92
BZ
872 rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
873 break;
874 }
875 case HostCmd_CMD_PMIC_REG_ACCESS:
876 {
877 struct host_cmd_ds_pmic_reg_access *pmic_reg;
878
879 cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
2c208890 880 pmic_reg = &cmd->params.pmic_reg;
5e6e3a92
BZ
881 pmic_reg->action = cpu_to_le16(cmd_action);
882 pmic_reg->offset =
9c05fd72 883 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
5e6e3a92
BZ
884 pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
885 break;
886 }
887 case HostCmd_CMD_CAU_REG_ACCESS:
888 {
889 struct host_cmd_ds_rf_reg_access *cau_reg;
890
891 cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
2c208890 892 cau_reg = &cmd->params.rf_reg;
5e6e3a92
BZ
893 cau_reg->action = cpu_to_le16(cmd_action);
894 cau_reg->offset =
9c05fd72 895 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
5e6e3a92
BZ
896 cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
897 break;
898 }
899 case HostCmd_CMD_802_11_EEPROM_ACCESS:
900 {
a5ffddb7 901 struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
5e6e3a92 902 struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
5e6e3a92
BZ
903 &cmd->params.eeprom;
904
905 cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
906 cmd_eeprom->action = cpu_to_le16(cmd_action);
907 cmd_eeprom->offset = rd_eeprom->offset;
908 cmd_eeprom->byte_count = rd_eeprom->byte_count;
909 cmd_eeprom->value = 0;
910 break;
911 }
912 default:
913 return -1;
914 }
915
916 return 0;
917}
918
d930faee
AK
919/*
920 * This function prepares command to set PCI-Express
921 * host buffer configuration
922 *
923 * Preparation includes -
924 * - Setting command ID, action and proper size
925 * - Setting host buffer configuration
926 * - Ensuring correct endian-ness
927 */
928static int
929mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
9c05fd72 930 struct host_cmd_ds_command *cmd, u16 action)
d930faee
AK
931{
932 struct host_cmd_ds_pcie_details *host_spec =
933 &cmd->params.pcie_host_spec;
934 struct pcie_service_card *card = priv->adapter->card;
d930faee
AK
935
936 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
937 cmd->size = cpu_to_le16(sizeof(struct
938 host_cmd_ds_pcie_details) + S_DS_GEN);
939 cmd->result = 0;
940
941 memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
942
9c05fd72
YAP
943 if (action != HostCmd_ACT_GEN_SET)
944 return 0;
945
946 /* Send the ring base addresses and count to firmware */
947 host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
948 host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
949 host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
950 host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
951 host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
952 host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
953 host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
954 host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
955 host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
fc331460
AP
956 if (card->sleep_cookie_vbase) {
957 host_spec->sleep_cookie_addr_lo =
958 (u32)(card->sleep_cookie_pbase);
959 host_spec->sleep_cookie_addr_hi =
960 (u32)(((u64)(card->sleep_cookie_pbase)) >> 32);
9c05fd72
YAP
961 dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
962 host_spec->sleep_cookie_addr_lo);
d930faee
AK
963 }
964
965 return 0;
966}
967
fa444bf8
AK
968/*
969 * This function prepares command for event subscription, configuration
970 * and query. Events can be subscribed or unsubscribed. Current subscribed
971 * events can be queried. Also, current subscribed events are reported in
972 * every FW response.
973 */
974static int
975mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
976 struct host_cmd_ds_command *cmd,
977 struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
978{
979 struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
980 struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
981 u16 event_bitmap;
982 u8 *pos;
983
984 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
985 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
986 S_DS_GEN);
987
988 subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
989 dev_dbg(priv->adapter->dev, "cmd: action: %d\n", subsc_evt_cfg->action);
990
991 /*For query requests, no configuration TLV structures are to be added.*/
992 if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
993 return 0;
994
995 subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
996
997 event_bitmap = subsc_evt_cfg->events;
998 dev_dbg(priv->adapter->dev, "cmd: event bitmap : %16x\n",
999 event_bitmap);
1000
1001 if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
1002 (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
1003 (event_bitmap == 0)) {
1004 dev_dbg(priv->adapter->dev, "Error: No event specified "
1005 "for bitwise action type\n");
1006 return -EINVAL;
1007 }
1008
1009 /*
1010 * Append TLV structures for each of the specified events for
1011 * subscribing or re-configuring. This is not required for
1012 * bitwise unsubscribing request.
1013 */
1014 if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
1015 return 0;
1016
1017 pos = ((u8 *)subsc_evt) +
1018 sizeof(struct host_cmd_ds_802_11_subsc_evt);
1019
1020 if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
1021 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1022
1023 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
1024 rssi_tlv->header.len =
1025 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1026 sizeof(struct mwifiex_ie_types_header));
1027 rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
1028 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
1029
1030 dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
1031 "RSSI:-%d dBm, Freq:%d\n",
1032 subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
1033 subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
1034
1035 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1036 le16_add_cpu(&cmd->size,
1037 sizeof(struct mwifiex_ie_types_rssi_threshold));
1038 }
1039
1040 if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
1041 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1042
1043 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1044 rssi_tlv->header.len =
1045 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1046 sizeof(struct mwifiex_ie_types_header));
1047 rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
1048 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
1049
d35ccaa4 1050 dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
fa444bf8
AK
1051 "RSSI:-%d dBm, Freq:%d\n",
1052 subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
1053 subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
1054
1055 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1056 le16_add_cpu(&cmd->size,
1057 sizeof(struct mwifiex_ie_types_rssi_threshold));
1058 }
1059
1060 return 0;
1061}
1062
7da060c1
AK
1063static int
1064mwifiex_cmd_append_rpn_expression(struct mwifiex_private *priv,
1065 struct mwifiex_mef_entry *mef_entry,
1066 u8 **buffer)
1067{
1068 struct mwifiex_mef_filter *filter = mef_entry->filter;
1069 int i, byte_len;
1070 u8 *stack_ptr = *buffer;
1071
1072 for (i = 0; i < MWIFIEX_MAX_FILTERS; i++) {
1073 filter = &mef_entry->filter[i];
1074 if (!filter->filt_type)
1075 break;
1076 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->repeat);
1077 stack_ptr += 4;
1078 *stack_ptr = TYPE_DNUM;
1079 stack_ptr += 1;
1080
1081 byte_len = filter->byte_seq[MAX_BYTESEQ];
1082 memcpy(stack_ptr, filter->byte_seq, byte_len);
1083 stack_ptr += byte_len;
1084 *stack_ptr = byte_len;
1085 stack_ptr += 1;
1086 *stack_ptr = TYPE_BYTESEQ;
1087 stack_ptr += 1;
1088
1089 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->offset);
1090 stack_ptr += 4;
1091 *stack_ptr = TYPE_DNUM;
1092 stack_ptr += 1;
1093
1094 *stack_ptr = filter->filt_type;
1095 stack_ptr += 1;
1096
1097 if (filter->filt_action) {
1098 *stack_ptr = filter->filt_action;
1099 stack_ptr += 1;
1100 }
1101
1102 if (stack_ptr - *buffer > STACK_NBYTES)
1103 return -1;
1104 }
1105
1106 *buffer = stack_ptr;
1107 return 0;
1108}
1109
1110static int
1111mwifiex_cmd_mef_cfg(struct mwifiex_private *priv,
1112 struct host_cmd_ds_command *cmd,
1113 struct mwifiex_ds_mef_cfg *mef)
1114{
1115 struct host_cmd_ds_mef_cfg *mef_cfg = &cmd->params.mef_cfg;
1116 u8 *pos = (u8 *)mef_cfg;
1117
1118 cmd->command = cpu_to_le16(HostCmd_CMD_MEF_CFG);
1119
1120 mef_cfg->criteria = cpu_to_le32(mef->criteria);
1121 mef_cfg->num_entries = cpu_to_le16(mef->num_entries);
1122 pos += sizeof(*mef_cfg);
1123 mef_cfg->mef_entry->mode = mef->mef_entry->mode;
1124 mef_cfg->mef_entry->action = mef->mef_entry->action;
1125 pos += sizeof(*(mef_cfg->mef_entry));
1126
1127 if (mwifiex_cmd_append_rpn_expression(priv, mef->mef_entry, &pos))
1128 return -1;
1129
1130 mef_cfg->mef_entry->exprsize =
1131 cpu_to_le16(pos - mef_cfg->mef_entry->expr);
1132 cmd->size = cpu_to_le16((u16) (pos - (u8 *)mef_cfg) + S_DS_GEN);
1133
1134 return 0;
1135}
1136
388ec385
AK
1137/* This function parse cal data from ASCII to hex */
1138static u32 mwifiex_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
1139{
1140 u8 *s = src, *d = dst;
1141
1142 while (s - src < len) {
1143 if (*s && (isspace(*s) || *s == '\t')) {
1144 s++;
1145 continue;
1146 }
1147 if (isxdigit(*s)) {
1148 *d++ = simple_strtol(s, NULL, 16);
1149 s += 2;
1150 } else {
1151 s++;
1152 }
1153 }
1154
1155 return d - dst;
1156}
1157
1158/* This function prepares command of set_cfg_data. */
1159static int mwifiex_cmd_cfg_data(struct mwifiex_private *priv,
1160 struct host_cmd_ds_command *cmd,
1161 u16 cmd_action)
1162{
1163 struct host_cmd_ds_802_11_cfg_data *cfg_data = &cmd->params.cfg_data;
1164 struct mwifiex_adapter *adapter = priv->adapter;
1165 u32 len, cal_data_offset;
1166 u8 *tmp_cmd = (u8 *)cmd;
1167
1168 cal_data_offset = S_DS_GEN + sizeof(*cfg_data);
1169 if ((adapter->cal_data->data) && (adapter->cal_data->size > 0))
1170 len = mwifiex_parse_cal_cfg((u8 *)adapter->cal_data->data,
1171 adapter->cal_data->size,
1172 (u8 *)(tmp_cmd + cal_data_offset));
1173 else
1174 return -1;
1175
1176 cfg_data->action = cpu_to_le16(cmd_action);
1177 cfg_data->type = cpu_to_le16(CFG_DATA_TYPE_CAL);
1178 cfg_data->data_len = cpu_to_le16(len);
1179
1180 cmd->command = cpu_to_le16(HostCmd_CMD_CFG_DATA);
1181 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(*cfg_data) + len);
1182
1183 return 0;
1184}
1185
5e6e3a92
BZ
1186/*
1187 * This function prepares the commands before sending them to the firmware.
1188 *
1189 * This is a generic function which calls specific command preparation
1190 * routines based upon the command number.
1191 */
1192int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1193 u16 cmd_action, u32 cmd_oid,
1194 void *data_buf, void *cmd_buf)
1195{
a5ffddb7 1196 struct host_cmd_ds_command *cmd_ptr = cmd_buf;
5e6e3a92
BZ
1197 int ret = 0;
1198
1199 /* Prepare command */
1200 switch (cmd_no) {
1201 case HostCmd_CMD_GET_HW_SPEC:
1202 ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
1203 break;
388ec385
AK
1204 case HostCmd_CMD_CFG_DATA:
1205 ret = mwifiex_cmd_cfg_data(priv, cmd_ptr, cmd_action);
1206 break;
5e6e3a92
BZ
1207 case HostCmd_CMD_MAC_CONTROL:
1208 ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
1209 data_buf);
1210 break;
1211 case HostCmd_CMD_802_11_MAC_ADDRESS:
1212 ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
1213 cmd_action);
1214 break;
1215 case HostCmd_CMD_MAC_MULTICAST_ADR:
572e8f3e 1216 ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
5e6e3a92
BZ
1217 data_buf);
1218 break;
1219 case HostCmd_CMD_TX_RATE_CFG:
1220 ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
1221 data_buf);
1222 break;
1223 case HostCmd_CMD_TXPWR_CFG:
572e8f3e 1224 ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
5e6e3a92
BZ
1225 data_buf);
1226 break;
caa8984f
AK
1227 case HostCmd_CMD_RF_TX_PWR:
1228 ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
1229 data_buf);
1230 break;
8a279d5b
AK
1231 case HostCmd_CMD_RF_ANTENNA:
1232 ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
1233 data_buf);
1234 break;
5e6e3a92
BZ
1235 case HostCmd_CMD_802_11_PS_MODE_ENH:
1236 ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
1237 (uint16_t)cmd_oid, data_buf);
1238 break;
1239 case HostCmd_CMD_802_11_HS_CFG_ENH:
1240 ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
1241 (struct mwifiex_hs_config_param *) data_buf);
1242 break;
1243 case HostCmd_CMD_802_11_SCAN:
572e8f3e 1244 ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
5e6e3a92
BZ
1245 break;
1246 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
572e8f3e 1247 ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
5e6e3a92
BZ
1248 break;
1249 case HostCmd_CMD_802_11_ASSOCIATE:
1250 ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
1251 break;
1252 case HostCmd_CMD_802_11_DEAUTHENTICATE:
1253 ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
1254 data_buf);
1255 break;
1256 case HostCmd_CMD_802_11_AD_HOC_START:
1257 ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
1258 data_buf);
1259 break;
1260 case HostCmd_CMD_802_11_GET_LOG:
572e8f3e 1261 ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
5e6e3a92
BZ
1262 break;
1263 case HostCmd_CMD_802_11_AD_HOC_JOIN:
1264 ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
1265 data_buf);
1266 break;
1267 case HostCmd_CMD_802_11_AD_HOC_STOP:
572e8f3e 1268 ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
5e6e3a92
BZ
1269 break;
1270 case HostCmd_CMD_RSSI_INFO:
1271 ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
1272 break;
1273 case HostCmd_CMD_802_11_SNMP_MIB:
1274 ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
1275 cmd_oid, data_buf);
1276 break;
1277 case HostCmd_CMD_802_11_TX_RATE_QUERY:
1278 cmd_ptr->command =
1279 cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
1280 cmd_ptr->size =
1281 cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
1282 S_DS_GEN);
1283 priv->tx_rate = 0;
1284 ret = 0;
1285 break;
1286 case HostCmd_CMD_VERSION_EXT:
1287 cmd_ptr->command = cpu_to_le16(cmd_no);
1288 cmd_ptr->params.verext.version_str_sel =
1289 (u8) (*((u32 *) data_buf));
1290 memcpy(&cmd_ptr->params, data_buf,
1291 sizeof(struct host_cmd_ds_version_ext));
1292 cmd_ptr->size =
1293 cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
1294 S_DS_GEN);
1295 ret = 0;
1296 break;
3cec6870
SP
1297 case HostCmd_CMD_MGMT_FRAME_REG:
1298 cmd_ptr->command = cpu_to_le16(cmd_no);
1299 cmd_ptr->params.reg_mask.action = cpu_to_le16(cmd_action);
1300 cmd_ptr->params.reg_mask.mask = cpu_to_le32(*(u32 *)data_buf);
1301 cmd_ptr->size =
1302 cpu_to_le16(sizeof(struct host_cmd_ds_mgmt_frame_reg) +
1303 S_DS_GEN);
1304 ret = 0;
1305 break;
7feb4c48
SP
1306 case HostCmd_CMD_REMAIN_ON_CHAN:
1307 cmd_ptr->command = cpu_to_le16(cmd_no);
1308 memcpy(&cmd_ptr->params, data_buf,
1309 sizeof(struct host_cmd_ds_remain_on_chan));
1310 cmd_ptr->size =
1311 cpu_to_le16(sizeof(struct host_cmd_ds_remain_on_chan) +
1312 S_DS_GEN);
1313 break;
83c78da9
YAP
1314 case HostCmd_CMD_11AC_CFG:
1315 ret = mwifiex_cmd_11ac_cfg(priv, cmd_ptr, cmd_action, data_buf);
1316 break;
e1a2b7a3
SP
1317 case HostCmd_CMD_P2P_MODE_CFG:
1318 cmd_ptr->command = cpu_to_le16(cmd_no);
1319 cmd_ptr->params.mode_cfg.action = cpu_to_le16(cmd_action);
1320 cmd_ptr->params.mode_cfg.mode = cpu_to_le16(*(u16 *)data_buf);
1321 cmd_ptr->size =
1322 cpu_to_le16(sizeof(struct host_cmd_ds_p2p_mode_cfg) +
1323 S_DS_GEN);
1324 break;
5e6e3a92
BZ
1325 case HostCmd_CMD_FUNC_INIT:
1326 if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
1327 priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
1328 cmd_ptr->command = cpu_to_le16(cmd_no);
1329 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1330 break;
1331 case HostCmd_CMD_FUNC_SHUTDOWN:
1332 priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
1333 cmd_ptr->command = cpu_to_le16(cmd_no);
1334 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1335 break;
1336 case HostCmd_CMD_11N_ADDBA_REQ:
572e8f3e 1337 ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
5e6e3a92
BZ
1338 break;
1339 case HostCmd_CMD_11N_DELBA:
572e8f3e 1340 ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
5e6e3a92
BZ
1341 break;
1342 case HostCmd_CMD_11N_ADDBA_RSP:
1343 ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
1344 break;
1345 case HostCmd_CMD_802_11_KEY_MATERIAL:
1346 ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
9c05fd72
YAP
1347 cmd_action, cmd_oid,
1348 data_buf);
5e6e3a92
BZ
1349 break;
1350 case HostCmd_CMD_802_11D_DOMAIN_INFO:
1351 ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
9c05fd72 1352 cmd_action);
5e6e3a92
BZ
1353 break;
1354 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
1355 ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
1356 data_buf);
1357 break;
1358 case HostCmd_CMD_AMSDU_AGGR_CTRL:
572e8f3e 1359 ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
5e6e3a92
BZ
1360 data_buf);
1361 break;
1362 case HostCmd_CMD_11N_CFG:
a5f39056 1363 ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf);
5e6e3a92
BZ
1364 break;
1365 case HostCmd_CMD_WMM_GET_STATUS:
1366 dev_dbg(priv->adapter->dev,
1367 "cmd: WMM: WMM_GET_STATUS cmd sent\n");
1368 cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
1369 cmd_ptr->size =
1370 cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
1371 S_DS_GEN);
1372 ret = 0;
1373 break;
1374 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
572e8f3e
AK
1375 ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
1376 data_buf);
5e6e3a92
BZ
1377 break;
1378 case HostCmd_CMD_MAC_REG_ACCESS:
1379 case HostCmd_CMD_BBP_REG_ACCESS:
1380 case HostCmd_CMD_RF_REG_ACCESS:
1381 case HostCmd_CMD_PMIC_REG_ACCESS:
1382 case HostCmd_CMD_CAU_REG_ACCESS:
1383 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1384 ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
1385 break;
1386 case HostCmd_CMD_SET_BSS_MODE:
1387 cmd_ptr->command = cpu_to_le16(cmd_no);
eecd8250 1388 if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
5e6e3a92
BZ
1389 cmd_ptr->params.bss_mode.con_type =
1390 CONNECTION_TYPE_ADHOC;
eecd8250 1391 else if (priv->bss_mode == NL80211_IFTYPE_STATION)
5e6e3a92
BZ
1392 cmd_ptr->params.bss_mode.con_type =
1393 CONNECTION_TYPE_INFRA;
9197ab9e
SP
1394 else if (priv->bss_mode == NL80211_IFTYPE_AP)
1395 cmd_ptr->params.bss_mode.con_type = CONNECTION_TYPE_AP;
5e6e3a92
BZ
1396 cmd_ptr->size = cpu_to_le16(sizeof(struct
1397 host_cmd_ds_set_bss_mode) + S_DS_GEN);
1398 ret = 0;
1399 break;
d930faee
AK
1400 case HostCmd_CMD_PCIE_DESC_DETAILS:
1401 ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
1402 break;
fa444bf8
AK
1403 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
1404 ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
1405 break;
7da060c1
AK
1406 case HostCmd_CMD_MEF_CFG:
1407 ret = mwifiex_cmd_mef_cfg(priv, cmd_ptr, data_buf);
1408 break;
5e6e3a92
BZ
1409 default:
1410 dev_err(priv->adapter->dev,
1411 "PREP_CMD: unknown cmd- %#x\n", cmd_no);
1412 ret = -1;
1413 break;
1414 }
1415 return ret;
1416}
1417
1418/*
1419 * This function issues commands to initialize firmware.
1420 *
1421 * This is called after firmware download to bring the card to
1422 * working state.
1423 *
1424 * The following commands are issued sequentially -
d930faee 1425 * - Set PCI-Express host buffer configuration (PCIE only)
5e6e3a92
BZ
1426 * - Function init (for first interface only)
1427 * - Read MAC address (for first interface only)
1428 * - Reconfigure Tx buffer size (for first interface only)
1429 * - Enable auto deep sleep (for first interface only)
1430 * - Get Tx rate
1431 * - Get Tx power
1432 * - Set IBSS coalescing status
1433 * - Set AMSDU aggregation control
1434 * - Set 11d control
1435 * - Set MAC control (this must be the last command to initialize firmware)
1436 */
1437int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
1438{
388ec385 1439 struct mwifiex_adapter *adapter = priv->adapter;
270e58e8 1440 int ret;
5e6e3a92
BZ
1441 u16 enable = true;
1442 struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
1443 struct mwifiex_ds_auto_ds auto_ds;
1444 enum state_11d_t state_11d;
cd27bc3c 1445 struct mwifiex_ds_11n_tx_cfg tx_cfg;
5e6e3a92
BZ
1446
1447 if (first_sta) {
d930faee 1448 if (priv->adapter->iface_type == MWIFIEX_PCIE) {
7bff9c97 1449 ret = mwifiex_send_cmd_sync(priv,
9c05fd72
YAP
1450 HostCmd_CMD_PCIE_DESC_DETAILS,
1451 HostCmd_ACT_GEN_SET, 0, NULL);
d930faee
AK
1452 if (ret)
1453 return -1;
1454 }
5e6e3a92 1455
7bff9c97
SP
1456 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_FUNC_INIT,
1457 HostCmd_ACT_GEN_SET, 0, NULL);
5e6e3a92
BZ
1458 if (ret)
1459 return -1;
388ec385
AK
1460
1461 /* Download calibration data to firmware */
1462 if (adapter->cal_data) {
1463 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_CFG_DATA,
1464 HostCmd_ACT_GEN_SET, 0, NULL);
1465 if (ret)
1466 return -1;
1467 }
1468
5e6e3a92 1469 /* Read MAC address from HW */
7bff9c97
SP
1470 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_GET_HW_SPEC,
1471 HostCmd_ACT_GEN_GET, 0, NULL);
5e6e3a92
BZ
1472 if (ret)
1473 return -1;
1474
1475 /* Reconfigure tx buf size */
7bff9c97
SP
1476 ret = mwifiex_send_cmd_sync(priv,
1477 HostCmd_CMD_RECONFIGURE_TX_BUFF,
1478 HostCmd_ACT_GEN_SET, 0,
1479 &priv->adapter->tx_buf_size);
5e6e3a92
BZ
1480 if (ret)
1481 return -1;
1482
03785387
AP
1483 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
1484 /* Enable IEEE PS by default */
1485 priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
7bff9c97 1486 ret = mwifiex_send_cmd_sync(
03785387
AP
1487 priv, HostCmd_CMD_802_11_PS_MODE_ENH,
1488 EN_AUTO_PS, BITMAP_STA_PS, NULL);
1489 if (ret)
1490 return -1;
1491 }
5e6e3a92
BZ
1492 }
1493
1494 /* get tx rate */
7bff9c97
SP
1495 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
1496 HostCmd_ACT_GEN_GET, 0, NULL);
5e6e3a92
BZ
1497 if (ret)
1498 return -1;
1499 priv->data_rate = 0;
1500
1501 /* get tx power */
7bff9c97
SP
1502 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_TX_PWR,
1503 HostCmd_ACT_GEN_GET, 0, NULL);
5e6e3a92
BZ
1504 if (ret)
1505 return -1;
1506
03785387
AP
1507 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
1508 /* set ibss coalescing_status */
7bff9c97 1509 ret = mwifiex_send_cmd_sync(
03785387
AP
1510 priv, HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
1511 HostCmd_ACT_GEN_SET, 0, &enable);
1512 if (ret)
1513 return -1;
1514 }
5e6e3a92
BZ
1515
1516 memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
1517 amsdu_aggr_ctrl.enable = true;
1518 /* Send request to firmware */
7bff9c97
SP
1519 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
1520 HostCmd_ACT_GEN_SET, 0,
1521 &amsdu_aggr_ctrl);
5e6e3a92
BZ
1522 if (ret)
1523 return -1;
1524 /* MAC Control must be the last command in init_fw */
1525 /* set MAC Control */
7bff9c97
SP
1526 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1527 HostCmd_ACT_GEN_SET, 0,
1528 &priv->curr_pkt_filter);
5e6e3a92
BZ
1529 if (ret)
1530 return -1;
1531
03785387
AP
1532 if (first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
1533 priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
5e6e3a92
BZ
1534 /* Enable auto deep sleep */
1535 auto_ds.auto_ds = DEEP_SLEEP_ON;
1536 auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
7bff9c97
SP
1537 ret = mwifiex_send_cmd_sync(priv,
1538 HostCmd_CMD_802_11_PS_MODE_ENH,
1539 EN_AUTO_PS, BITMAP_AUTO_DS,
1540 &auto_ds);
5e6e3a92
BZ
1541 if (ret)
1542 return -1;
1543 }
1544
03785387
AP
1545 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
1546 /* Send cmd to FW to enable/disable 11D function */
1547 state_11d = ENABLE_11D;
7bff9c97
SP
1548 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_SNMP_MIB,
1549 HostCmd_ACT_GEN_SET, DOT11D_I,
1550 &state_11d);
03785387
AP
1551 if (ret)
1552 dev_err(priv->adapter->dev,
1553 "11D: failed to enable 11D\n");
1554 }
5e6e3a92 1555
7bff9c97
SP
1556 /* set last_init_cmd before sending the command */
1557 priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
1558
cd27bc3c
AK
1559 /* Send cmd to FW to configure 11n specific configuration
1560 * (Short GI, Channel BW, Green field support etc.) for transmit
1561 */
1562 tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
7bff9c97
SP
1563 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_11N_CFG,
1564 HostCmd_ACT_GEN_SET, 0, &tx_cfg);
cd27bc3c 1565
5e6e3a92
BZ
1566 ret = -EINPROGRESS;
1567
1568 return ret;
1569}
This page took 0.313243 seconds and 5 git commands to generate.