2 * Marvell Wireless LAN device driver: station command handling
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
30 module_param(drcs, bool, 0644);
31 MODULE_PARM_DESC(drcs, "multi-channel operation:1, single-channel operation:0");
33 static bool disable_auto_ds;
34 module_param(disable_auto_ds, bool, 0);
35 MODULE_PARM_DESC(disable_auto_ds,
36 "deepsleep enabled=0(default), deepsleep disabled=1");
38 * This function prepares command to set/get RSSI information.
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
47 mwifiex_cmd_802_11_rssi_info(struct mwifiex_private *priv,
48 struct host_cmd_ds_command *cmd, u16 cmd_action)
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) +
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);
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;
71 * This function prepares command to set MAC control.
73 * Preparation includes -
74 * - Setting command ID, action and proper size
75 * - Ensuring correct endian-ness
77 static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
78 struct host_cmd_ds_command *cmd,
79 u16 cmd_action, u16 *action)
81 struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
83 if (cmd_action != HostCmd_ACT_GEN_SET) {
84 mwifiex_dbg(priv->adapter, ERROR,
85 "mac_control: only support set cmd\n");
89 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_CONTROL);
91 cpu_to_le16(sizeof(struct host_cmd_ds_mac_control) + S_DS_GEN);
92 mac_ctrl->action = cpu_to_le16(*action);
98 * This function prepares command to set/get SNMP MIB.
100 * Preparation includes -
101 * - Setting command ID, action and proper size
102 * - Setting SNMP MIB OID number and value
104 * - Ensuring correct endian-ness
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
112 static 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,
117 struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
119 mwifiex_dbg(priv->adapter, CMD,
120 "cmd: SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
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)
125 snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
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);
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));
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));
146 * This function prepares command to get log.
148 * Preparation includes -
149 * - Setting command ID and proper size
150 * - Ensuring correct endian-ness
153 mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
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) +
162 * This function prepares command to set/get Tx data rate configuration.
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
170 static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
171 struct host_cmd_ds_command *cmd,
172 u16 cmd_action, u16 *pbitmap_rates)
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;
179 cmd->command = cpu_to_le16(HostCmd_CMD_TX_RATE_CFG);
181 rate_cfg->action = cpu_to_le16(cmd_action);
182 rate_cfg->cfg_index = 0;
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);
187 rate_scope->length = cpu_to_le16
188 (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
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]);
193 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
195 rate_scope->ht_mcs_rate_bitmap[i] =
196 cpu_to_le16(pbitmap_rates[2 + i]);
197 if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
199 i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap);
201 rate_scope->vht_mcs_rate_bitmap[i] =
202 cpu_to_le16(pbitmap_rates[10 + i]);
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]);
210 i < sizeof(rate_scope->ht_mcs_rate_bitmap) / sizeof(u16);
212 rate_scope->ht_mcs_rate_bitmap[i] =
213 cpu_to_le16(priv->bitmap_rates[2 + i]);
214 if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
216 i < ARRAY_SIZE(rate_scope->vht_mcs_rate_bitmap);
218 rate_scope->vht_mcs_rate_bitmap[i] =
219 cpu_to_le16(priv->bitmap_rates[10 + i]);
223 rate_drop = (struct mwifiex_rate_drop_pattern *) ((u8 *) rate_scope +
224 sizeof(struct mwifiex_rate_scope));
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;
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));
238 * This function prepares command to set/get Tx power configuration.
240 * Preparation includes -
241 * - Setting command ID, action and proper size
242 * - Setting Tx power mode, power group TLV
244 * - Ensuring correct endian-ness
246 static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
248 struct host_cmd_ds_txpwr_cfg *txp)
250 struct mwifiex_types_power_group *pg_tlv;
251 struct host_cmd_ds_txpwr_cfg *cmd_txp_cfg = &cmd->params.txp_cfg;
253 cmd->command = cpu_to_le16(HostCmd_CMD_TXPWR_CFG);
255 cpu_to_le16(S_DS_GEN + sizeof(struct host_cmd_ds_txpwr_cfg));
256 switch (cmd_action) {
257 case HostCmd_ACT_GEN_SET:
259 pg_tlv = (struct mwifiex_types_power_group
260 *) ((unsigned long) txp +
261 sizeof(struct host_cmd_ds_txpwr_cfg));
262 memmove(cmd_txp_cfg, txp,
263 sizeof(struct host_cmd_ds_txpwr_cfg) +
264 sizeof(struct mwifiex_types_power_group) +
265 le16_to_cpu(pg_tlv->length));
267 pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
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) +
272 le16_to_cpu(pg_tlv->length));
274 memmove(cmd_txp_cfg, txp, sizeof(*txp));
276 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
278 case HostCmd_ACT_GEN_GET:
279 cmd_txp_cfg->action = cpu_to_le16(cmd_action);
287 * This function prepares command to get RF Tx power.
289 static int mwifiex_cmd_rf_tx_power(struct mwifiex_private *priv,
290 struct host_cmd_ds_command *cmd,
291 u16 cmd_action, void *data_buf)
293 struct host_cmd_ds_rf_tx_pwr *txp = &cmd->params.txp;
295 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_rf_tx_pwr)
297 cmd->command = cpu_to_le16(HostCmd_CMD_RF_TX_PWR);
298 txp->action = cpu_to_le16(cmd_action);
304 * This function prepares command to set rf antenna.
306 static int mwifiex_cmd_rf_antenna(struct mwifiex_private *priv,
307 struct host_cmd_ds_command *cmd,
309 struct mwifiex_ds_ant_cfg *ant_cfg)
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;
314 cmd->command = cpu_to_le16(HostCmd_CMD_RF_ANTENNA);
316 switch (cmd_action) {
317 case HostCmd_ACT_GEN_SET:
318 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
319 cmd->size = cpu_to_le16(sizeof(struct
320 host_cmd_ds_rf_ant_mimo)
322 ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_SET_TX);
323 ant_mimo->tx_ant_mode = cpu_to_le16((u16)ant_cfg->
325 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_SET_RX);
326 ant_mimo->rx_ant_mode = cpu_to_le16((u16)ant_cfg->
329 cmd->size = cpu_to_le16(sizeof(struct
330 host_cmd_ds_rf_ant_siso) +
332 ant_siso->action = cpu_to_le16(HostCmd_ACT_SET_BOTH);
333 ant_siso->ant_mode = cpu_to_le16((u16)ant_cfg->tx_ant);
336 case HostCmd_ACT_GEN_GET:
337 if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
338 cmd->size = cpu_to_le16(sizeof(struct
339 host_cmd_ds_rf_ant_mimo) +
341 ant_mimo->action_tx = cpu_to_le16(HostCmd_ACT_GET_TX);
342 ant_mimo->action_rx = cpu_to_le16(HostCmd_ACT_GET_RX);
344 cmd->size = cpu_to_le16(sizeof(struct
345 host_cmd_ds_rf_ant_siso) +
347 ant_siso->action = cpu_to_le16(HostCmd_ACT_GET_BOTH);
355 * This function prepares command to set Host Sleep configuration.
357 * Preparation includes -
358 * - Setting command ID and proper size
359 * - Setting Host Sleep action, conditions, ARP filters
361 * - Ensuring correct endian-ness
364 mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
365 struct host_cmd_ds_command *cmd,
367 struct mwifiex_hs_config_param *hscfg_param)
369 struct mwifiex_adapter *adapter = priv->adapter;
370 struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
371 bool hs_activate = false;
374 /* New Activate command */
376 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
379 (hscfg_param->conditions != cpu_to_le32(HS_CFG_CANCEL)) &&
380 ((adapter->arp_filter_size > 0) &&
381 (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
382 mwifiex_dbg(adapter, CMD,
383 "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
384 adapter->arp_filter_size);
385 memcpy(((u8 *) hs_cfg) +
386 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
387 adapter->arp_filter, adapter->arp_filter_size);
388 cmd->size = cpu_to_le16
389 (adapter->arp_filter_size +
390 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
393 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
394 host_cmd_ds_802_11_hs_cfg_enh));
397 hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
398 hs_cfg->params.hs_activate.resp_ctrl = cpu_to_le16(RESP_NEEDED);
400 hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
401 hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
402 hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
403 hs_cfg->params.hs_config.gap = hscfg_param->gap;
404 mwifiex_dbg(adapter, CMD,
405 "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
406 hs_cfg->params.hs_config.conditions,
407 hs_cfg->params.hs_config.gpio,
408 hs_cfg->params.hs_config.gap);
415 * This function prepares command to set/get MAC address.
417 * Preparation includes -
418 * - Setting command ID, action and proper size
419 * - Setting MAC address (for SET only)
420 * - Ensuring correct endian-ness
422 static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
423 struct host_cmd_ds_command *cmd,
426 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
427 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
431 cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
433 if (cmd_action == HostCmd_ACT_GEN_SET)
434 memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
440 * This function prepares command to set MAC multicast address.
442 * Preparation includes -
443 * - Setting command ID, action and proper size
444 * - Setting MAC multicast address
445 * - Ensuring correct endian-ness
448 mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
450 struct mwifiex_multicast_list *mcast_list)
452 struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
454 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
456 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
458 mcast_addr->action = cpu_to_le16(cmd_action);
459 mcast_addr->num_of_adrs =
460 cpu_to_le16((u16) mcast_list->num_multicast_addr);
461 memcpy(mcast_addr->mac_list, mcast_list->mac_list,
462 mcast_list->num_multicast_addr * ETH_ALEN);
468 * This function prepares command to deauthenticate.
470 * Preparation includes -
471 * - Setting command ID and proper size
472 * - Setting AP MAC address and reason code
473 * - Ensuring correct endian-ness
475 static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
476 struct host_cmd_ds_command *cmd,
479 struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
481 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
482 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
485 /* Set AP MAC address */
486 memcpy(deauth->mac_addr, mac, ETH_ALEN);
488 mwifiex_dbg(priv->adapter, CMD, "cmd: Deauth: %pM\n", deauth->mac_addr);
490 deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
496 * This function prepares command to stop Ad-Hoc network.
498 * Preparation includes -
499 * - Setting command ID and proper size
500 * - Ensuring correct endian-ness
502 static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
504 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
505 cmd->size = cpu_to_le16(S_DS_GEN);
510 * This function sets WEP key(s) to key parameter TLV(s).
512 * Multi-key parameter TLVs are supported, so we can send multiple
513 * WEP keys in a single buffer.
516 mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
517 struct mwifiex_ie_type_key_param_set *key_param_set,
520 int cur_key_param_len;
523 /* Multi-key_param_set TLV is supported */
524 for (i = 0; i < NUM_WEP_KEYS; i++) {
525 if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
526 (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
527 key_param_set->type =
528 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
529 /* Key_param_set WEP fixed length */
530 #define KEYPARAMSET_WEP_FIXED_LEN 8
531 key_param_set->length = cpu_to_le16((u16)
534 KEYPARAMSET_WEP_FIXED_LEN));
535 key_param_set->key_type_id =
536 cpu_to_le16(KEY_TYPE_ID_WEP);
537 key_param_set->key_info =
538 cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
540 key_param_set->key_len =
541 cpu_to_le16(priv->wep_key[i].key_length);
542 /* Set WEP key index */
543 key_param_set->key[0] = i;
544 /* Set default Tx key flag */
547 wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
548 key_param_set->key[1] = 1;
550 key_param_set->key[1] = 0;
551 memmove(&key_param_set->key[2],
552 priv->wep_key[i].key_material,
553 priv->wep_key[i].key_length);
555 cur_key_param_len = priv->wep_key[i].key_length +
556 KEYPARAMSET_WEP_FIXED_LEN +
557 sizeof(struct mwifiex_ie_types_header);
558 *key_param_len += (u16) cur_key_param_len;
560 (struct mwifiex_ie_type_key_param_set *)
561 ((u8 *)key_param_set +
563 } else if (!priv->wep_key[i].key_length) {
566 mwifiex_dbg(priv->adapter, ERROR,
567 "key%d Length = %d is incorrect\n",
568 (i + 1), priv->wep_key[i].key_length);
576 /* This function populates key material v2 command
577 * to set network key for AES & CMAC AES.
579 static int mwifiex_set_aes_key_v2(struct mwifiex_private *priv,
580 struct host_cmd_ds_command *cmd,
581 struct mwifiex_ds_encrypt_key *enc_key,
582 struct host_cmd_ds_802_11_key_material_v2 *km)
584 struct mwifiex_adapter *adapter = priv->adapter;
585 u16 size, len = KEY_PARAMS_FIXED_LEN;
587 if (enc_key->is_igtk_key) {
588 mwifiex_dbg(adapter, INFO,
589 "%s: Set CMAC AES Key\n", __func__);
590 if (enc_key->is_rx_seq_valid)
591 memcpy(km->key_param_set.key_params.cmac_aes.ipn,
592 enc_key->pn, enc_key->pn_len);
593 km->key_param_set.key_info &= cpu_to_le16(~KEY_MCAST);
594 km->key_param_set.key_info |= cpu_to_le16(KEY_IGTK);
595 km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC;
596 km->key_param_set.key_params.cmac_aes.key_len =
597 cpu_to_le16(enc_key->key_len);
598 memcpy(km->key_param_set.key_params.cmac_aes.key,
599 enc_key->key_material, enc_key->key_len);
600 len += sizeof(struct mwifiex_cmac_aes_param);
601 } else if (enc_key->is_igtk_def_key) {
602 mwifiex_dbg(adapter, INFO,
603 "%s: Set CMAC default Key index\n", __func__);
604 km->key_param_set.key_type = KEY_TYPE_ID_AES_CMAC_DEF;
605 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
607 mwifiex_dbg(adapter, INFO,
608 "%s: Set AES Key\n", __func__);
609 if (enc_key->is_rx_seq_valid)
610 memcpy(km->key_param_set.key_params.aes.pn,
611 enc_key->pn, enc_key->pn_len);
612 km->key_param_set.key_type = KEY_TYPE_ID_AES;
613 km->key_param_set.key_params.aes.key_len =
614 cpu_to_le16(enc_key->key_len);
615 memcpy(km->key_param_set.key_params.aes.key,
616 enc_key->key_material, enc_key->key_len);
617 len += sizeof(struct mwifiex_aes_param);
620 km->key_param_set.len = cpu_to_le16(len);
621 size = len + sizeof(struct mwifiex_ie_types_header) +
622 sizeof(km->action) + S_DS_GEN;
623 cmd->size = cpu_to_le16(size);
628 /* This function prepares command to set/get/reset network key(s).
629 * This function prepares key material command for V2 format.
630 * Preparation includes -
631 * - Setting command ID, action and proper size
632 * - Setting WEP keys, WAPI keys or WPA keys along with required
633 * encryption (TKIP, AES) (as required)
634 * - Ensuring correct endian-ness
637 mwifiex_cmd_802_11_key_material_v2(struct mwifiex_private *priv,
638 struct host_cmd_ds_command *cmd,
639 u16 cmd_action, u32 cmd_oid,
640 struct mwifiex_ds_encrypt_key *enc_key)
642 struct mwifiex_adapter *adapter = priv->adapter;
643 u8 *mac = enc_key->mac_addr;
644 u16 key_info, len = KEY_PARAMS_FIXED_LEN;
645 struct host_cmd_ds_802_11_key_material_v2 *km =
646 &cmd->params.key_material_v2;
648 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
649 km->action = cpu_to_le16(cmd_action);
651 if (cmd_action == HostCmd_ACT_GEN_GET) {
652 mwifiex_dbg(adapter, INFO, "%s: Get key\n", __func__);
653 km->key_param_set.key_idx =
654 enc_key->key_index & KEY_INDEX_MASK;
655 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
656 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
657 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
659 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
660 key_info = KEY_UNICAST;
662 key_info = KEY_MCAST;
664 if (enc_key->is_igtk_key)
665 key_info |= KEY_IGTK;
667 km->key_param_set.key_info = cpu_to_le16(key_info);
669 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
670 S_DS_GEN + KEY_PARAMS_FIXED_LEN +
675 memset(&km->key_param_set, 0,
676 sizeof(struct mwifiex_ie_type_key_param_set_v2));
678 if (enc_key->key_disable) {
679 mwifiex_dbg(adapter, INFO, "%s: Remove key\n", __func__);
680 km->action = cpu_to_le16(HostCmd_ACT_GEN_REMOVE);
681 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
682 km->key_param_set.len = cpu_to_le16(KEY_PARAMS_FIXED_LEN);
683 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
684 key_info = KEY_MCAST | KEY_UNICAST;
685 km->key_param_set.key_info = cpu_to_le16(key_info);
686 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
687 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
688 S_DS_GEN + KEY_PARAMS_FIXED_LEN +
693 km->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
694 km->key_param_set.key_idx = enc_key->key_index & KEY_INDEX_MASK;
695 km->key_param_set.type = cpu_to_le16(TLV_TYPE_KEY_PARAM_V2);
696 key_info = KEY_ENABLED;
697 memcpy(km->key_param_set.mac_addr, mac, ETH_ALEN);
699 if (enc_key->key_len <= WLAN_KEY_LEN_WEP104) {
700 mwifiex_dbg(adapter, INFO, "%s: Set WEP Key\n", __func__);
701 len += sizeof(struct mwifiex_wep_param);
702 km->key_param_set.len = cpu_to_le16(len);
703 km->key_param_set.key_type = KEY_TYPE_ID_WEP;
705 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
706 key_info |= KEY_MCAST | KEY_UNICAST;
708 if (enc_key->is_current_wep_key) {
709 key_info |= KEY_MCAST | KEY_UNICAST;
710 if (km->key_param_set.key_idx ==
711 (priv->wep_key_curr_index & KEY_INDEX_MASK))
712 key_info |= KEY_DEFAULT;
714 if (is_broadcast_ether_addr(mac))
715 key_info |= KEY_MCAST;
717 key_info |= KEY_UNICAST | KEY_DEFAULT;
720 km->key_param_set.key_info = cpu_to_le16(key_info);
722 km->key_param_set.key_params.wep.key_len =
723 cpu_to_le16(enc_key->key_len);
724 memcpy(km->key_param_set.key_params.wep.key,
725 enc_key->key_material, enc_key->key_len);
727 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
728 len + sizeof(km->action) + S_DS_GEN);
732 if (is_broadcast_ether_addr(mac))
733 key_info |= KEY_MCAST | KEY_RX_KEY;
735 key_info |= KEY_UNICAST | KEY_TX_KEY | KEY_RX_KEY;
737 if (enc_key->is_wapi_key) {
738 mwifiex_dbg(adapter, INFO, "%s: Set WAPI Key\n", __func__);
739 km->key_param_set.key_type = KEY_TYPE_ID_WAPI;
740 memcpy(km->key_param_set.key_params.wapi.pn, enc_key->pn,
742 km->key_param_set.key_params.wapi.key_len =
743 cpu_to_le16(enc_key->key_len);
744 memcpy(km->key_param_set.key_params.wapi.key,
745 enc_key->key_material, enc_key->key_len);
746 if (is_broadcast_ether_addr(mac))
747 priv->sec_info.wapi_key_on = true;
749 if (!priv->sec_info.wapi_key_on)
750 key_info |= KEY_DEFAULT;
751 km->key_param_set.key_info = cpu_to_le16(key_info);
753 len += sizeof(struct mwifiex_wapi_param);
754 km->key_param_set.len = cpu_to_le16(len);
755 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
756 len + sizeof(km->action) + S_DS_GEN);
760 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
761 key_info |= KEY_DEFAULT;
762 /* Enable unicast bit for WPA-NONE/ADHOC_AES */
763 if (!priv->sec_info.wpa2_enabled &&
764 !is_broadcast_ether_addr(mac))
765 key_info |= KEY_UNICAST;
767 /* Enable default key for WPA/WPA2 */
768 if (!priv->wpa_is_gtk_set)
769 key_info |= KEY_DEFAULT;
772 km->key_param_set.key_info = cpu_to_le16(key_info);
774 if (enc_key->key_len == WLAN_KEY_LEN_CCMP)
775 return mwifiex_set_aes_key_v2(priv, cmd, enc_key, km);
777 if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
778 mwifiex_dbg(adapter, INFO,
779 "%s: Set TKIP Key\n", __func__);
780 if (enc_key->is_rx_seq_valid)
781 memcpy(km->key_param_set.key_params.tkip.pn,
782 enc_key->pn, enc_key->pn_len);
783 km->key_param_set.key_type = KEY_TYPE_ID_TKIP;
784 km->key_param_set.key_params.tkip.key_len =
785 cpu_to_le16(enc_key->key_len);
786 memcpy(km->key_param_set.key_params.tkip.key,
787 enc_key->key_material, enc_key->key_len);
789 len += sizeof(struct mwifiex_tkip_param);
790 km->key_param_set.len = cpu_to_le16(len);
791 cmd->size = cpu_to_le16(sizeof(struct mwifiex_ie_types_header) +
792 len + sizeof(km->action) + S_DS_GEN);
799 * This function prepares command to set/get/reset network key(s).
800 * This function prepares key material command for V1 format.
802 * Preparation includes -
803 * - Setting command ID, action and proper size
804 * - Setting WEP keys, WAPI keys or WPA keys along with required
805 * encryption (TKIP, AES) (as required)
806 * - Ensuring correct endian-ness
809 mwifiex_cmd_802_11_key_material_v1(struct mwifiex_private *priv,
810 struct host_cmd_ds_command *cmd,
811 u16 cmd_action, u32 cmd_oid,
812 struct mwifiex_ds_encrypt_key *enc_key)
814 struct host_cmd_ds_802_11_key_material *key_material =
815 &cmd->params.key_material;
816 struct host_cmd_tlv_mac_addr *tlv_mac;
817 u16 key_param_len = 0, cmd_size;
820 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
821 key_material->action = cpu_to_le16(cmd_action);
823 if (cmd_action == HostCmd_ACT_GEN_GET) {
825 cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
830 memset(&key_material->key_param_set, 0,
832 sizeof(struct mwifiex_ie_type_key_param_set)));
833 ret = mwifiex_set_keyparamset_wep(priv,
834 &key_material->key_param_set,
836 cmd->size = cpu_to_le16(key_param_len +
837 sizeof(key_material->action) + S_DS_GEN);
840 memset(&key_material->key_param_set, 0,
841 sizeof(struct mwifiex_ie_type_key_param_set));
842 if (enc_key->is_wapi_key) {
843 mwifiex_dbg(priv->adapter, INFO, "info: Set WAPI Key\n");
844 key_material->key_param_set.key_type_id =
845 cpu_to_le16(KEY_TYPE_ID_WAPI);
846 if (cmd_oid == KEY_INFO_ENABLED)
847 key_material->key_param_set.key_info =
848 cpu_to_le16(KEY_ENABLED);
850 key_material->key_param_set.key_info =
851 cpu_to_le16(!KEY_ENABLED);
853 key_material->key_param_set.key[0] = enc_key->key_index;
854 if (!priv->sec_info.wapi_key_on)
855 key_material->key_param_set.key[1] = 1;
857 /* set 0 when re-key */
858 key_material->key_param_set.key[1] = 0;
860 if (!is_broadcast_ether_addr(enc_key->mac_addr)) {
861 /* WAPI pairwise key: unicast */
862 key_material->key_param_set.key_info |=
863 cpu_to_le16(KEY_UNICAST);
864 } else { /* WAPI group key: multicast */
865 key_material->key_param_set.key_info |=
866 cpu_to_le16(KEY_MCAST);
867 priv->sec_info.wapi_key_on = true;
870 key_material->key_param_set.type =
871 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
872 key_material->key_param_set.key_len =
873 cpu_to_le16(WAPI_KEY_LEN);
874 memcpy(&key_material->key_param_set.key[2],
875 enc_key->key_material, enc_key->key_len);
876 memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
877 enc_key->pn, PN_LEN);
878 key_material->key_param_set.length =
879 cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
881 key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
882 sizeof(struct mwifiex_ie_types_header);
883 cmd->size = cpu_to_le16(sizeof(key_material->action)
884 + S_DS_GEN + key_param_len);
887 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
888 if (enc_key->is_igtk_key) {
889 mwifiex_dbg(priv->adapter, CMD, "cmd: CMAC_AES\n");
890 key_material->key_param_set.key_type_id =
891 cpu_to_le16(KEY_TYPE_ID_AES_CMAC);
892 if (cmd_oid == KEY_INFO_ENABLED)
893 key_material->key_param_set.key_info =
894 cpu_to_le16(KEY_ENABLED);
896 key_material->key_param_set.key_info =
897 cpu_to_le16(!KEY_ENABLED);
899 key_material->key_param_set.key_info |=
900 cpu_to_le16(KEY_IGTK);
902 mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_AES\n");
903 key_material->key_param_set.key_type_id =
904 cpu_to_le16(KEY_TYPE_ID_AES);
905 if (cmd_oid == KEY_INFO_ENABLED)
906 key_material->key_param_set.key_info =
907 cpu_to_le16(KEY_ENABLED);
909 key_material->key_param_set.key_info =
910 cpu_to_le16(!KEY_ENABLED);
912 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
913 /* AES pairwise key: unicast */
914 key_material->key_param_set.key_info |=
915 cpu_to_le16(KEY_UNICAST);
916 else /* AES group key: multicast */
917 key_material->key_param_set.key_info |=
918 cpu_to_le16(KEY_MCAST);
920 } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
921 mwifiex_dbg(priv->adapter, CMD, "cmd: WPA_TKIP\n");
922 key_material->key_param_set.key_type_id =
923 cpu_to_le16(KEY_TYPE_ID_TKIP);
924 key_material->key_param_set.key_info =
925 cpu_to_le16(KEY_ENABLED);
927 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
928 /* TKIP pairwise key: unicast */
929 key_material->key_param_set.key_info |=
930 cpu_to_le16(KEY_UNICAST);
931 else /* TKIP group key: multicast */
932 key_material->key_param_set.key_info |=
933 cpu_to_le16(KEY_MCAST);
936 if (key_material->key_param_set.key_type_id) {
937 key_material->key_param_set.type =
938 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
939 key_material->key_param_set.key_len =
940 cpu_to_le16((u16) enc_key->key_len);
941 memcpy(key_material->key_param_set.key, enc_key->key_material,
943 key_material->key_param_set.length =
944 cpu_to_le16((u16) enc_key->key_len +
945 KEYPARAMSET_FIXED_LEN);
947 key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
948 + sizeof(struct mwifiex_ie_types_header);
950 if (le16_to_cpu(key_material->key_param_set.key_type_id) ==
951 KEY_TYPE_ID_AES_CMAC) {
952 struct mwifiex_cmac_param *param =
953 (void *)key_material->key_param_set.key;
955 memcpy(param->ipn, enc_key->pn, IGTK_PN_LEN);
956 memcpy(param->key, enc_key->key_material,
957 WLAN_KEY_LEN_AES_CMAC);
959 key_param_len = sizeof(struct mwifiex_cmac_param);
960 key_material->key_param_set.key_len =
961 cpu_to_le16(key_param_len);
962 key_param_len += KEYPARAMSET_FIXED_LEN;
963 key_material->key_param_set.length =
964 cpu_to_le16(key_param_len);
965 key_param_len += sizeof(struct mwifiex_ie_types_header);
968 cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
971 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
972 tlv_mac = (void *)((u8 *)&key_material->key_param_set +
974 tlv_mac->header.type =
975 cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
976 tlv_mac->header.len = cpu_to_le16(ETH_ALEN);
977 memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
978 cmd_size = key_param_len + S_DS_GEN +
979 sizeof(key_material->action) +
980 sizeof(struct host_cmd_tlv_mac_addr);
982 cmd_size = key_param_len + S_DS_GEN +
983 sizeof(key_material->action);
985 cmd->size = cpu_to_le16(cmd_size);
991 /* Wrapper function for setting network key depending upon FW KEY API version */
993 mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
994 struct host_cmd_ds_command *cmd,
995 u16 cmd_action, u32 cmd_oid,
996 struct mwifiex_ds_encrypt_key *enc_key)
998 if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
999 return mwifiex_cmd_802_11_key_material_v2(priv, cmd,
1000 cmd_action, cmd_oid,
1004 return mwifiex_cmd_802_11_key_material_v1(priv, cmd,
1005 cmd_action, cmd_oid,
1010 * This function prepares command to set/get 11d domain information.
1012 * Preparation includes -
1013 * - Setting command ID, action and proper size
1014 * - Setting domain information fields (for SET only)
1015 * - Ensuring correct endian-ness
1017 static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
1018 struct host_cmd_ds_command *cmd,
1021 struct mwifiex_adapter *adapter = priv->adapter;
1022 struct host_cmd_ds_802_11d_domain_info *domain_info =
1023 &cmd->params.domain_info;
1024 struct mwifiex_ietypes_domain_param_set *domain =
1025 &domain_info->domain;
1026 u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
1028 mwifiex_dbg(adapter, INFO,
1029 "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
1031 cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
1032 domain_info->action = cpu_to_le16(cmd_action);
1033 if (cmd_action == HostCmd_ACT_GEN_GET) {
1034 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1038 /* Set domain info fields */
1039 domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
1040 memcpy(domain->country_code, adapter->domain_reg.country_code,
1041 sizeof(domain->country_code));
1043 domain->header.len =
1044 cpu_to_le16((no_of_triplet *
1045 sizeof(struct ieee80211_country_ie_triplet))
1046 + sizeof(domain->country_code));
1048 if (no_of_triplet) {
1049 memcpy(domain->triplet, adapter->domain_reg.triplet,
1050 no_of_triplet * sizeof(struct
1051 ieee80211_country_ie_triplet));
1053 cmd->size = cpu_to_le16(sizeof(domain_info->action) +
1054 le16_to_cpu(domain->header.len) +
1055 sizeof(struct mwifiex_ie_types_header)
1058 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
1065 * This function prepares command to set/get IBSS coalescing status.
1067 * Preparation includes -
1068 * - Setting command ID, action and proper size
1069 * - Setting status to enable or disable (for SET only)
1070 * - Ensuring correct endian-ness
1072 static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
1073 u16 cmd_action, u16 *enable)
1075 struct host_cmd_ds_802_11_ibss_status *ibss_coal =
1076 &(cmd->params.ibss_coalescing);
1078 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
1079 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
1082 ibss_coal->action = cpu_to_le16(cmd_action);
1084 switch (cmd_action) {
1085 case HostCmd_ACT_GEN_SET:
1087 ibss_coal->enable = cpu_to_le16(*enable);
1089 ibss_coal->enable = 0;
1092 /* In other case.. Nothing to do */
1093 case HostCmd_ACT_GEN_GET:
1101 /* This function prepares command buffer to get/set memory location value.
1104 mwifiex_cmd_mem_access(struct host_cmd_ds_command *cmd, u16 cmd_action,
1107 struct mwifiex_ds_mem_rw *mem_rw = (void *)pdata_buf;
1108 struct host_cmd_ds_mem_access *mem_access = (void *)&cmd->params.mem;
1110 cmd->command = cpu_to_le16(HostCmd_CMD_MEM_ACCESS);
1111 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mem_access) +
1114 mem_access->action = cpu_to_le16(cmd_action);
1115 mem_access->addr = cpu_to_le32(mem_rw->addr);
1116 mem_access->value = cpu_to_le32(mem_rw->value);
1122 * This function prepares command to set/get register value.
1124 * Preparation includes -
1125 * - Setting command ID, action and proper size
1126 * - Setting register offset (for both GET and SET) and
1127 * register value (for SET only)
1128 * - Ensuring correct endian-ness
1130 * The following type of registers can be accessed with this function -
1138 static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
1139 u16 cmd_action, void *data_buf)
1141 struct mwifiex_ds_reg_rw *reg_rw = data_buf;
1143 switch (le16_to_cpu(cmd->command)) {
1144 case HostCmd_CMD_MAC_REG_ACCESS:
1146 struct host_cmd_ds_mac_reg_access *mac_reg;
1148 cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
1149 mac_reg = &cmd->params.mac_reg;
1150 mac_reg->action = cpu_to_le16(cmd_action);
1151 mac_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1152 mac_reg->value = cpu_to_le32(reg_rw->value);
1155 case HostCmd_CMD_BBP_REG_ACCESS:
1157 struct host_cmd_ds_bbp_reg_access *bbp_reg;
1159 cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
1160 bbp_reg = &cmd->params.bbp_reg;
1161 bbp_reg->action = cpu_to_le16(cmd_action);
1162 bbp_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1163 bbp_reg->value = (u8) reg_rw->value;
1166 case HostCmd_CMD_RF_REG_ACCESS:
1168 struct host_cmd_ds_rf_reg_access *rf_reg;
1170 cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
1171 rf_reg = &cmd->params.rf_reg;
1172 rf_reg->action = cpu_to_le16(cmd_action);
1173 rf_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1174 rf_reg->value = (u8) reg_rw->value;
1177 case HostCmd_CMD_PMIC_REG_ACCESS:
1179 struct host_cmd_ds_pmic_reg_access *pmic_reg;
1181 cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
1182 pmic_reg = &cmd->params.pmic_reg;
1183 pmic_reg->action = cpu_to_le16(cmd_action);
1184 pmic_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1185 pmic_reg->value = (u8) reg_rw->value;
1188 case HostCmd_CMD_CAU_REG_ACCESS:
1190 struct host_cmd_ds_rf_reg_access *cau_reg;
1192 cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
1193 cau_reg = &cmd->params.rf_reg;
1194 cau_reg->action = cpu_to_le16(cmd_action);
1195 cau_reg->offset = cpu_to_le16((u16) reg_rw->offset);
1196 cau_reg->value = (u8) reg_rw->value;
1199 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1201 struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
1202 struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
1203 &cmd->params.eeprom;
1205 cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
1206 cmd_eeprom->action = cpu_to_le16(cmd_action);
1207 cmd_eeprom->offset = cpu_to_le16(rd_eeprom->offset);
1208 cmd_eeprom->byte_count = cpu_to_le16(rd_eeprom->byte_count);
1209 cmd_eeprom->value = 0;
1220 * This function prepares command to set PCI-Express
1221 * host buffer configuration
1223 * Preparation includes -
1224 * - Setting command ID, action and proper size
1225 * - Setting host buffer configuration
1226 * - Ensuring correct endian-ness
1229 mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
1230 struct host_cmd_ds_command *cmd, u16 action)
1232 struct host_cmd_ds_pcie_details *host_spec =
1233 &cmd->params.pcie_host_spec;
1234 struct pcie_service_card *card = priv->adapter->card;
1236 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
1237 cmd->size = cpu_to_le16(sizeof(struct
1238 host_cmd_ds_pcie_details) + S_DS_GEN);
1241 memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
1243 if (action != HostCmd_ACT_GEN_SET)
1246 /* Send the ring base addresses and count to firmware */
1247 host_spec->txbd_addr_lo = cpu_to_le32((u32)(card->txbd_ring_pbase));
1248 host_spec->txbd_addr_hi =
1249 cpu_to_le32((u32)(((u64)card->txbd_ring_pbase) >> 32));
1250 host_spec->txbd_count = cpu_to_le32(MWIFIEX_MAX_TXRX_BD);
1251 host_spec->rxbd_addr_lo = cpu_to_le32((u32)(card->rxbd_ring_pbase));
1252 host_spec->rxbd_addr_hi =
1253 cpu_to_le32((u32)(((u64)card->rxbd_ring_pbase) >> 32));
1254 host_spec->rxbd_count = cpu_to_le32(MWIFIEX_MAX_TXRX_BD);
1255 host_spec->evtbd_addr_lo = cpu_to_le32((u32)(card->evtbd_ring_pbase));
1256 host_spec->evtbd_addr_hi =
1257 cpu_to_le32((u32)(((u64)card->evtbd_ring_pbase) >> 32));
1258 host_spec->evtbd_count = cpu_to_le32(MWIFIEX_MAX_EVT_BD);
1259 if (card->sleep_cookie_vbase) {
1260 host_spec->sleep_cookie_addr_lo =
1261 cpu_to_le32((u32)(card->sleep_cookie_pbase));
1262 host_spec->sleep_cookie_addr_hi = cpu_to_le32((u32)(((u64)
1263 (card->sleep_cookie_pbase)) >> 32));
1264 mwifiex_dbg(priv->adapter, INFO,
1265 "sleep_cook_lo phy addr: 0x%x\n",
1266 host_spec->sleep_cookie_addr_lo);
1273 * This function prepares command for event subscription, configuration
1274 * and query. Events can be subscribed or unsubscribed. Current subscribed
1275 * events can be queried. Also, current subscribed events are reported in
1276 * every FW response.
1279 mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
1280 struct host_cmd_ds_command *cmd,
1281 struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
1283 struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
1284 struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
1288 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
1289 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
1292 subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
1293 mwifiex_dbg(priv->adapter, CMD,
1294 "cmd: action: %d\n", subsc_evt_cfg->action);
1296 /*For query requests, no configuration TLV structures are to be added.*/
1297 if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
1300 subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
1302 event_bitmap = subsc_evt_cfg->events;
1303 mwifiex_dbg(priv->adapter, CMD, "cmd: event bitmap : %16x\n",
1306 if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
1307 (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
1308 (event_bitmap == 0)) {
1309 mwifiex_dbg(priv->adapter, ERROR,
1310 "Error: No event specified\t"
1311 "for bitwise action type\n");
1316 * Append TLV structures for each of the specified events for
1317 * subscribing or re-configuring. This is not required for
1318 * bitwise unsubscribing request.
1320 if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
1323 pos = ((u8 *)subsc_evt) +
1324 sizeof(struct host_cmd_ds_802_11_subsc_evt);
1326 if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
1327 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1329 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
1330 rssi_tlv->header.len =
1331 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1332 sizeof(struct mwifiex_ie_types_header));
1333 rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
1334 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
1336 mwifiex_dbg(priv->adapter, EVENT,
1337 "Cfg Beacon Low Rssi event,\t"
1338 "RSSI:-%d dBm, Freq:%d\n",
1339 subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
1340 subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
1342 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1343 le16_add_cpu(&cmd->size,
1344 sizeof(struct mwifiex_ie_types_rssi_threshold));
1347 if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
1348 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1350 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1351 rssi_tlv->header.len =
1352 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1353 sizeof(struct mwifiex_ie_types_header));
1354 rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
1355 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
1357 mwifiex_dbg(priv->adapter, EVENT,
1358 "Cfg Beacon High Rssi event,\t"
1359 "RSSI:-%d dBm, Freq:%d\n",
1360 subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
1361 subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
1363 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1364 le16_add_cpu(&cmd->size,
1365 sizeof(struct mwifiex_ie_types_rssi_threshold));
1372 mwifiex_cmd_append_rpn_expression(struct mwifiex_private *priv,
1373 struct mwifiex_mef_entry *mef_entry,
1376 struct mwifiex_mef_filter *filter = mef_entry->filter;
1378 u8 *stack_ptr = *buffer;
1380 for (i = 0; i < MWIFIEX_MEF_MAX_FILTERS; i++) {
1381 filter = &mef_entry->filter[i];
1382 if (!filter->filt_type)
1384 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->repeat);
1386 *stack_ptr = TYPE_DNUM;
1389 byte_len = filter->byte_seq[MWIFIEX_MEF_MAX_BYTESEQ];
1390 memcpy(stack_ptr, filter->byte_seq, byte_len);
1391 stack_ptr += byte_len;
1392 *stack_ptr = byte_len;
1394 *stack_ptr = TYPE_BYTESEQ;
1397 *(__le32 *)stack_ptr = cpu_to_le32((u32)filter->offset);
1399 *stack_ptr = TYPE_DNUM;
1402 *stack_ptr = filter->filt_type;
1405 if (filter->filt_action) {
1406 *stack_ptr = filter->filt_action;
1410 if (stack_ptr - *buffer > STACK_NBYTES)
1414 *buffer = stack_ptr;
1419 mwifiex_cmd_mef_cfg(struct mwifiex_private *priv,
1420 struct host_cmd_ds_command *cmd,
1421 struct mwifiex_ds_mef_cfg *mef)
1423 struct host_cmd_ds_mef_cfg *mef_cfg = &cmd->params.mef_cfg;
1424 struct mwifiex_fw_mef_entry *mef_entry = NULL;
1425 u8 *pos = (u8 *)mef_cfg;
1428 cmd->command = cpu_to_le16(HostCmd_CMD_MEF_CFG);
1430 mef_cfg->criteria = cpu_to_le32(mef->criteria);
1431 mef_cfg->num_entries = cpu_to_le16(mef->num_entries);
1432 pos += sizeof(*mef_cfg);
1434 for (i = 0; i < mef->num_entries; i++) {
1435 mef_entry = (struct mwifiex_fw_mef_entry *)pos;
1436 mef_entry->mode = mef->mef_entry[i].mode;
1437 mef_entry->action = mef->mef_entry[i].action;
1438 pos += sizeof(*mef_cfg->mef_entry);
1440 if (mwifiex_cmd_append_rpn_expression(priv,
1441 &mef->mef_entry[i], &pos))
1444 mef_entry->exprsize =
1445 cpu_to_le16(pos - mef_entry->expr);
1447 cmd->size = cpu_to_le16((u16) (pos - (u8 *)mef_cfg) + S_DS_GEN);
1452 /* This function parse cal data from ASCII to hex */
1453 static u32 mwifiex_parse_cal_cfg(u8 *src, size_t len, u8 *dst)
1455 u8 *s = src, *d = dst;
1457 while (s - src < len) {
1458 if (*s && (isspace(*s) || *s == '\t')) {
1463 *d++ = simple_strtol(s, NULL, 16);
1473 int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv,
1474 struct device_node *node, const char *prefix)
1477 struct property *prop;
1478 size_t len = strlen(prefix);
1481 /* look for all matching property names */
1482 for_each_property_of_node(node, prop) {
1483 if (len > strlen(prop->name) ||
1484 strncmp(prop->name, prefix, len))
1487 /* property header is 6 bytes, data must fit in cmd buffer */
1488 if (prop->value && prop->length > 6 &&
1489 prop->length <= MWIFIEX_SIZE_OF_CMD_BUFFER - S_DS_GEN) {
1490 ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
1491 HostCmd_ACT_GEN_SET, 0,
1501 /* This function prepares command of set_cfg_data. */
1502 static int mwifiex_cmd_cfg_data(struct mwifiex_private *priv,
1503 struct host_cmd_ds_command *cmd, void *data_buf)
1505 struct mwifiex_adapter *adapter = priv->adapter;
1506 struct property *prop = data_buf;
1508 u8 *data = (u8 *)cmd + S_DS_GEN;
1513 ret = of_property_read_u8_array(adapter->dt_node, prop->name,
1517 mwifiex_dbg(adapter, INFO,
1518 "download cfg_data from device tree: %s\n",
1520 } else if (adapter->cal_data->data && adapter->cal_data->size > 0) {
1521 len = mwifiex_parse_cal_cfg((u8 *)adapter->cal_data->data,
1522 adapter->cal_data->size, data);
1523 mwifiex_dbg(adapter, INFO,
1524 "download cfg_data from config file\n");
1529 cmd->command = cpu_to_le16(HostCmd_CMD_CFG_DATA);
1530 cmd->size = cpu_to_le16(S_DS_GEN + len);
1536 mwifiex_cmd_set_mc_policy(struct mwifiex_private *priv,
1537 struct host_cmd_ds_command *cmd,
1538 u16 cmd_action, void *data_buf)
1540 struct host_cmd_ds_multi_chan_policy *mc_pol = &cmd->params.mc_policy;
1541 const u16 *drcs_info = data_buf;
1543 mc_pol->action = cpu_to_le16(cmd_action);
1544 mc_pol->policy = cpu_to_le16(*drcs_info);
1545 cmd->command = cpu_to_le16(HostCmd_CMD_MC_POLICY);
1546 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_multi_chan_policy) +
1551 static int mwifiex_cmd_robust_coex(struct mwifiex_private *priv,
1552 struct host_cmd_ds_command *cmd,
1553 u16 cmd_action, bool *is_timeshare)
1555 struct host_cmd_ds_robust_coex *coex = &cmd->params.coex;
1556 struct mwifiex_ie_types_robust_coex *coex_tlv;
1558 cmd->command = cpu_to_le16(HostCmd_CMD_ROBUST_COEX);
1559 cmd->size = cpu_to_le16(sizeof(*coex) + sizeof(*coex_tlv) + S_DS_GEN);
1561 coex->action = cpu_to_le16(cmd_action);
1562 coex_tlv = (struct mwifiex_ie_types_robust_coex *)
1563 ((u8 *)coex + sizeof(*coex));
1564 coex_tlv->header.type = cpu_to_le16(TLV_TYPE_ROBUST_COEX);
1565 coex_tlv->header.len = cpu_to_le16(sizeof(coex_tlv->mode));
1567 if (coex->action == HostCmd_ACT_GEN_GET)
1571 coex_tlv->mode = cpu_to_le32(MWIFIEX_COEX_MODE_TIMESHARE);
1573 coex_tlv->mode = cpu_to_le32(MWIFIEX_COEX_MODE_SPATIAL);
1578 static int mwifiex_cmd_gtk_rekey_offload(struct mwifiex_private *priv,
1579 struct host_cmd_ds_command *cmd,
1581 struct cfg80211_gtk_rekey_data *data)
1583 struct host_cmd_ds_gtk_rekey_params *rekey = &cmd->params.rekey;
1586 cmd->command = cpu_to_le16(HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG);
1587 cmd->size = cpu_to_le16(sizeof(*rekey) + S_DS_GEN);
1589 rekey->action = cpu_to_le16(cmd_action);
1590 if (cmd_action == HostCmd_ACT_GEN_SET) {
1591 memcpy(rekey->kek, data->kek, NL80211_KEK_LEN);
1592 memcpy(rekey->kck, data->kck, NL80211_KCK_LEN);
1593 rekey_ctr = be64_to_cpup((__be64 *)data->replay_ctr);
1594 rekey->replay_ctr_low = cpu_to_le32((u32)rekey_ctr);
1595 rekey->replay_ctr_high =
1596 cpu_to_le32((u32)((u64)rekey_ctr >> 32));
1602 static int mwifiex_cmd_chan_region_cfg(struct mwifiex_private *priv,
1603 struct host_cmd_ds_command *cmd,
1606 struct host_cmd_ds_chan_region_cfg *reg = &cmd->params.reg_cfg;
1608 cmd->command = cpu_to_le16(HostCmd_CMD_CHAN_REGION_CFG);
1609 cmd->size = cpu_to_le16(sizeof(*reg) + S_DS_GEN);
1611 if (cmd_action == HostCmd_ACT_GEN_GET)
1612 reg->action = cpu_to_le16(cmd_action);
1618 mwifiex_cmd_coalesce_cfg(struct mwifiex_private *priv,
1619 struct host_cmd_ds_command *cmd,
1620 u16 cmd_action, void *data_buf)
1622 struct host_cmd_ds_coalesce_cfg *coalesce_cfg =
1623 &cmd->params.coalesce_cfg;
1624 struct mwifiex_ds_coalesce_cfg *cfg = data_buf;
1625 struct coalesce_filt_field_param *param;
1626 u16 cnt, idx, length;
1627 struct coalesce_receive_filt_rule *rule;
1629 cmd->command = cpu_to_le16(HostCmd_CMD_COALESCE_CFG);
1630 cmd->size = cpu_to_le16(S_DS_GEN);
1632 coalesce_cfg->action = cpu_to_le16(cmd_action);
1633 coalesce_cfg->num_of_rules = cpu_to_le16(cfg->num_of_rules);
1634 rule = coalesce_cfg->rule;
1636 for (cnt = 0; cnt < cfg->num_of_rules; cnt++) {
1637 rule->header.type = cpu_to_le16(TLV_TYPE_COALESCE_RULE);
1638 rule->max_coalescing_delay =
1639 cpu_to_le16(cfg->rule[cnt].max_coalescing_delay);
1640 rule->pkt_type = cfg->rule[cnt].pkt_type;
1641 rule->num_of_fields = cfg->rule[cnt].num_of_fields;
1645 param = rule->params;
1646 for (idx = 0; idx < cfg->rule[cnt].num_of_fields; idx++) {
1647 param->operation = cfg->rule[cnt].params[idx].operation;
1648 param->operand_len =
1649 cfg->rule[cnt].params[idx].operand_len;
1651 cpu_to_le16(cfg->rule[cnt].params[idx].offset);
1652 memcpy(param->operand_byte_stream,
1653 cfg->rule[cnt].params[idx].operand_byte_stream,
1654 param->operand_len);
1656 length += sizeof(struct coalesce_filt_field_param);
1661 /* Total rule length is sizeof max_coalescing_delay(u16),
1662 * num_of_fields(u8), pkt_type(u8) and total length of the all
1665 rule->header.len = cpu_to_le16(length + sizeof(u16) +
1666 sizeof(u8) + sizeof(u8));
1668 /* Add the rule length to the command size*/
1669 le16_add_cpu(&cmd->size, le16_to_cpu(rule->header.len) +
1670 sizeof(struct mwifiex_ie_types_header));
1672 rule = (void *)((u8 *)rule->params + length);
1675 /* Add sizeof action, num_of_rules to total command length */
1676 le16_add_cpu(&cmd->size, sizeof(u16) + sizeof(u16));
1682 mwifiex_cmd_tdls_config(struct mwifiex_private *priv,
1683 struct host_cmd_ds_command *cmd,
1684 u16 cmd_action, void *data_buf)
1686 struct host_cmd_ds_tdls_config *tdls_config = &cmd->params.tdls_config;
1687 struct mwifiex_tdls_init_cs_params *config;
1688 struct mwifiex_tdls_config *init_config;
1691 cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_CONFIG);
1692 cmd->size = cpu_to_le16(S_DS_GEN);
1693 tdls_config->tdls_action = cpu_to_le16(cmd_action);
1694 le16_add_cpu(&cmd->size, sizeof(tdls_config->tdls_action));
1696 switch (cmd_action) {
1697 case ACT_TDLS_CS_ENABLE_CONFIG:
1698 init_config = data_buf;
1699 len = sizeof(*init_config);
1700 memcpy(tdls_config->tdls_data, init_config, len);
1702 case ACT_TDLS_CS_INIT:
1704 len = sizeof(*config);
1705 memcpy(tdls_config->tdls_data, config, len);
1707 case ACT_TDLS_CS_STOP:
1708 len = sizeof(struct mwifiex_tdls_stop_cs_params);
1709 memcpy(tdls_config->tdls_data, data_buf, len);
1711 case ACT_TDLS_CS_PARAMS:
1712 len = sizeof(struct mwifiex_tdls_config_cs_params);
1713 memcpy(tdls_config->tdls_data, data_buf, len);
1716 mwifiex_dbg(priv->adapter, ERROR,
1717 "Unknown TDLS configuration\n");
1721 le16_add_cpu(&cmd->size, len);
1726 mwifiex_cmd_tdls_oper(struct mwifiex_private *priv,
1727 struct host_cmd_ds_command *cmd,
1730 struct host_cmd_ds_tdls_oper *tdls_oper = &cmd->params.tdls_oper;
1731 struct mwifiex_ds_tdls_oper *oper = data_buf;
1732 struct mwifiex_sta_node *sta_ptr;
1733 struct host_cmd_tlv_rates *tlv_rates;
1734 struct mwifiex_ie_types_htcap *ht_capab;
1735 struct mwifiex_ie_types_qos_info *wmm_qos_info;
1736 struct mwifiex_ie_types_extcap *extcap;
1737 struct mwifiex_ie_types_vhtcap *vht_capab;
1738 struct mwifiex_ie_types_aid *aid;
1739 struct mwifiex_ie_types_tdls_idle_timeout *timeout;
1742 struct station_parameters *params = priv->sta_params;
1744 cmd->command = cpu_to_le16(HostCmd_CMD_TDLS_OPER);
1745 cmd->size = cpu_to_le16(S_DS_GEN);
1746 le16_add_cpu(&cmd->size, sizeof(struct host_cmd_ds_tdls_oper));
1748 tdls_oper->reason = 0;
1749 memcpy(tdls_oper->peer_mac, oper->peer_mac, ETH_ALEN);
1750 sta_ptr = mwifiex_get_sta_entry(priv, oper->peer_mac);
1752 pos = (u8 *)tdls_oper + sizeof(struct host_cmd_ds_tdls_oper);
1754 switch (oper->tdls_action) {
1755 case MWIFIEX_TDLS_DISABLE_LINK:
1756 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_DELETE);
1758 case MWIFIEX_TDLS_CREATE_LINK:
1759 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CREATE);
1761 case MWIFIEX_TDLS_CONFIG_LINK:
1762 tdls_oper->tdls_action = cpu_to_le16(ACT_TDLS_CONFIG);
1765 mwifiex_dbg(priv->adapter, ERROR,
1766 "TDLS config params not available for %pM\n",
1771 *(__le16 *)pos = cpu_to_le16(params->capability);
1772 config_len += sizeof(params->capability);
1774 qos_info = params->uapsd_queues | (params->max_sp << 5);
1775 wmm_qos_info = (struct mwifiex_ie_types_qos_info *)(pos +
1777 wmm_qos_info->header.type = cpu_to_le16(WLAN_EID_QOS_CAPA);
1778 wmm_qos_info->header.len = cpu_to_le16(sizeof(qos_info));
1779 wmm_qos_info->qos_info = qos_info;
1780 config_len += sizeof(struct mwifiex_ie_types_qos_info);
1782 if (params->ht_capa) {
1783 ht_capab = (struct mwifiex_ie_types_htcap *)(pos +
1785 ht_capab->header.type =
1786 cpu_to_le16(WLAN_EID_HT_CAPABILITY);
1787 ht_capab->header.len =
1788 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
1789 memcpy(&ht_capab->ht_cap, params->ht_capa,
1790 sizeof(struct ieee80211_ht_cap));
1791 config_len += sizeof(struct mwifiex_ie_types_htcap);
1794 if (params->supported_rates && params->supported_rates_len) {
1795 tlv_rates = (struct host_cmd_tlv_rates *)(pos +
1797 tlv_rates->header.type =
1798 cpu_to_le16(WLAN_EID_SUPP_RATES);
1799 tlv_rates->header.len =
1800 cpu_to_le16(params->supported_rates_len);
1801 memcpy(tlv_rates->rates, params->supported_rates,
1802 params->supported_rates_len);
1803 config_len += sizeof(struct host_cmd_tlv_rates) +
1804 params->supported_rates_len;
1807 if (params->ext_capab && params->ext_capab_len) {
1808 extcap = (struct mwifiex_ie_types_extcap *)(pos +
1810 extcap->header.type =
1811 cpu_to_le16(WLAN_EID_EXT_CAPABILITY);
1812 extcap->header.len = cpu_to_le16(params->ext_capab_len);
1813 memcpy(extcap->ext_capab, params->ext_capab,
1814 params->ext_capab_len);
1815 config_len += sizeof(struct mwifiex_ie_types_extcap) +
1816 params->ext_capab_len;
1818 if (params->vht_capa) {
1819 vht_capab = (struct mwifiex_ie_types_vhtcap *)(pos +
1821 vht_capab->header.type =
1822 cpu_to_le16(WLAN_EID_VHT_CAPABILITY);
1823 vht_capab->header.len =
1824 cpu_to_le16(sizeof(struct ieee80211_vht_cap));
1825 memcpy(&vht_capab->vht_cap, params->vht_capa,
1826 sizeof(struct ieee80211_vht_cap));
1827 config_len += sizeof(struct mwifiex_ie_types_vhtcap);
1830 aid = (struct mwifiex_ie_types_aid *)(pos + config_len);
1831 aid->header.type = cpu_to_le16(WLAN_EID_AID);
1832 aid->header.len = cpu_to_le16(sizeof(params->aid));
1833 aid->aid = cpu_to_le16(params->aid);
1834 config_len += sizeof(struct mwifiex_ie_types_aid);
1837 timeout = (void *)(pos + config_len);
1838 timeout->header.type = cpu_to_le16(TLV_TYPE_TDLS_IDLE_TIMEOUT);
1839 timeout->header.len = cpu_to_le16(sizeof(timeout->value));
1840 timeout->value = cpu_to_le16(MWIFIEX_TDLS_IDLE_TIMEOUT_IN_SEC);
1841 config_len += sizeof(struct mwifiex_ie_types_tdls_idle_timeout);
1845 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS operation\n");
1849 le16_add_cpu(&cmd->size, config_len);
1854 /* This function prepares command of sdio rx aggr info. */
1855 static int mwifiex_cmd_sdio_rx_aggr_cfg(struct host_cmd_ds_command *cmd,
1856 u16 cmd_action, void *data_buf)
1858 struct host_cmd_sdio_sp_rx_aggr_cfg *cfg =
1859 &cmd->params.sdio_rx_aggr_cfg;
1861 cmd->command = cpu_to_le16(HostCmd_CMD_SDIO_SP_RX_AGGR_CFG);
1863 cpu_to_le16(sizeof(struct host_cmd_sdio_sp_rx_aggr_cfg) +
1865 cfg->action = cmd_action;
1866 if (cmd_action == HostCmd_ACT_GEN_SET)
1867 cfg->enable = *(u8 *)data_buf;
1872 /* This function prepares command to get HS wakeup reason.
1874 * Preparation includes -
1875 * - Setting command ID, action and proper size
1876 * - Ensuring correct endian-ness
1878 static int mwifiex_cmd_get_wakeup_reason(struct mwifiex_private *priv,
1879 struct host_cmd_ds_command *cmd)
1881 cmd->command = cpu_to_le16(HostCmd_CMD_HS_WAKEUP_REASON);
1882 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_wakeup_reason) +
1889 * This function prepares the commands before sending them to the firmware.
1891 * This is a generic function which calls specific command preparation
1892 * routines based upon the command number.
1894 int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1895 u16 cmd_action, u32 cmd_oid,
1896 void *data_buf, void *cmd_buf)
1898 struct host_cmd_ds_command *cmd_ptr = cmd_buf;
1901 /* Prepare command */
1903 case HostCmd_CMD_GET_HW_SPEC:
1904 ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
1906 case HostCmd_CMD_CFG_DATA:
1907 ret = mwifiex_cmd_cfg_data(priv, cmd_ptr, data_buf);
1909 case HostCmd_CMD_MAC_CONTROL:
1910 ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
1913 case HostCmd_CMD_802_11_MAC_ADDRESS:
1914 ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
1917 case HostCmd_CMD_MAC_MULTICAST_ADR:
1918 ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
1921 case HostCmd_CMD_TX_RATE_CFG:
1922 ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
1925 case HostCmd_CMD_TXPWR_CFG:
1926 ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
1929 case HostCmd_CMD_RF_TX_PWR:
1930 ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
1933 case HostCmd_CMD_RF_ANTENNA:
1934 ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
1937 case HostCmd_CMD_802_11_PS_MODE_ENH:
1938 ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
1939 (uint16_t)cmd_oid, data_buf);
1941 case HostCmd_CMD_802_11_HS_CFG_ENH:
1942 ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
1943 (struct mwifiex_hs_config_param *) data_buf);
1945 case HostCmd_CMD_802_11_SCAN:
1946 ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
1948 case HostCmd_CMD_802_11_BG_SCAN_CONFIG:
1949 ret = mwifiex_cmd_802_11_bg_scan_config(priv, cmd_ptr,
1952 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
1953 ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
1955 case HostCmd_CMD_802_11_ASSOCIATE:
1956 ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
1958 case HostCmd_CMD_802_11_DEAUTHENTICATE:
1959 ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
1962 case HostCmd_CMD_802_11_AD_HOC_START:
1963 ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
1966 case HostCmd_CMD_802_11_GET_LOG:
1967 ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
1969 case HostCmd_CMD_802_11_AD_HOC_JOIN:
1970 ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
1973 case HostCmd_CMD_802_11_AD_HOC_STOP:
1974 ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
1976 case HostCmd_CMD_RSSI_INFO:
1977 ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
1979 case HostCmd_CMD_802_11_SNMP_MIB:
1980 ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
1983 case HostCmd_CMD_802_11_TX_RATE_QUERY:
1985 cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
1987 cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
1992 case HostCmd_CMD_VERSION_EXT:
1993 cmd_ptr->command = cpu_to_le16(cmd_no);
1994 cmd_ptr->params.verext.version_str_sel =
1995 (u8) (*((u32 *) data_buf));
1996 memcpy(&cmd_ptr->params, data_buf,
1997 sizeof(struct host_cmd_ds_version_ext));
1999 cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
2003 case HostCmd_CMD_MGMT_FRAME_REG:
2004 cmd_ptr->command = cpu_to_le16(cmd_no);
2005 cmd_ptr->params.reg_mask.action = cpu_to_le16(cmd_action);
2006 cmd_ptr->params.reg_mask.mask = cpu_to_le32(*(u32 *)data_buf);
2008 cpu_to_le16(sizeof(struct host_cmd_ds_mgmt_frame_reg) +
2012 case HostCmd_CMD_REMAIN_ON_CHAN:
2013 cmd_ptr->command = cpu_to_le16(cmd_no);
2014 memcpy(&cmd_ptr->params, data_buf,
2015 sizeof(struct host_cmd_ds_remain_on_chan));
2017 cpu_to_le16(sizeof(struct host_cmd_ds_remain_on_chan) +
2020 case HostCmd_CMD_11AC_CFG:
2021 ret = mwifiex_cmd_11ac_cfg(priv, cmd_ptr, cmd_action, data_buf);
2023 case HostCmd_CMD_P2P_MODE_CFG:
2024 cmd_ptr->command = cpu_to_le16(cmd_no);
2025 cmd_ptr->params.mode_cfg.action = cpu_to_le16(cmd_action);
2026 cmd_ptr->params.mode_cfg.mode = cpu_to_le16(*(u16 *)data_buf);
2028 cpu_to_le16(sizeof(struct host_cmd_ds_p2p_mode_cfg) +
2031 case HostCmd_CMD_FUNC_INIT:
2032 if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
2033 priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
2034 cmd_ptr->command = cpu_to_le16(cmd_no);
2035 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
2037 case HostCmd_CMD_FUNC_SHUTDOWN:
2038 priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
2039 cmd_ptr->command = cpu_to_le16(cmd_no);
2040 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
2042 case HostCmd_CMD_11N_ADDBA_REQ:
2043 ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
2045 case HostCmd_CMD_11N_DELBA:
2046 ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
2048 case HostCmd_CMD_11N_ADDBA_RSP:
2049 ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
2051 case HostCmd_CMD_802_11_KEY_MATERIAL:
2052 ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
2053 cmd_action, cmd_oid,
2056 case HostCmd_CMD_802_11D_DOMAIN_INFO:
2057 ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
2060 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
2061 ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
2064 case HostCmd_CMD_AMSDU_AGGR_CTRL:
2065 ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
2068 case HostCmd_CMD_11N_CFG:
2069 ret = mwifiex_cmd_11n_cfg(priv, cmd_ptr, cmd_action, data_buf);
2071 case HostCmd_CMD_WMM_GET_STATUS:
2072 mwifiex_dbg(priv->adapter, CMD,
2073 "cmd: WMM: WMM_GET_STATUS cmd sent\n");
2074 cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
2076 cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
2080 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
2081 ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
2084 case HostCmd_CMD_802_11_SCAN_EXT:
2085 ret = mwifiex_cmd_802_11_scan_ext(priv, cmd_ptr, data_buf);
2087 case HostCmd_CMD_MEM_ACCESS:
2088 ret = mwifiex_cmd_mem_access(cmd_ptr, cmd_action, data_buf);
2090 case HostCmd_CMD_MAC_REG_ACCESS:
2091 case HostCmd_CMD_BBP_REG_ACCESS:
2092 case HostCmd_CMD_RF_REG_ACCESS:
2093 case HostCmd_CMD_PMIC_REG_ACCESS:
2094 case HostCmd_CMD_CAU_REG_ACCESS:
2095 case HostCmd_CMD_802_11_EEPROM_ACCESS:
2096 ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
2098 case HostCmd_CMD_SET_BSS_MODE:
2099 cmd_ptr->command = cpu_to_le16(cmd_no);
2100 if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
2101 cmd_ptr->params.bss_mode.con_type =
2102 CONNECTION_TYPE_ADHOC;
2103 else if (priv->bss_mode == NL80211_IFTYPE_STATION ||
2104 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT)
2105 cmd_ptr->params.bss_mode.con_type =
2106 CONNECTION_TYPE_INFRA;
2107 else if (priv->bss_mode == NL80211_IFTYPE_AP ||
2108 priv->bss_mode == NL80211_IFTYPE_P2P_GO)
2109 cmd_ptr->params.bss_mode.con_type = CONNECTION_TYPE_AP;
2110 cmd_ptr->size = cpu_to_le16(sizeof(struct
2111 host_cmd_ds_set_bss_mode) + S_DS_GEN);
2114 case HostCmd_CMD_PCIE_DESC_DETAILS:
2115 ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
2117 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
2118 ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
2120 case HostCmd_CMD_MEF_CFG:
2121 ret = mwifiex_cmd_mef_cfg(priv, cmd_ptr, data_buf);
2123 case HostCmd_CMD_COALESCE_CFG:
2124 ret = mwifiex_cmd_coalesce_cfg(priv, cmd_ptr, cmd_action,
2127 case HostCmd_CMD_TDLS_OPER:
2128 ret = mwifiex_cmd_tdls_oper(priv, cmd_ptr, data_buf);
2130 case HostCmd_CMD_TDLS_CONFIG:
2131 ret = mwifiex_cmd_tdls_config(priv, cmd_ptr, cmd_action,
2134 case HostCmd_CMD_CHAN_REPORT_REQUEST:
2135 ret = mwifiex_cmd_issue_chan_report_request(priv, cmd_ptr,
2138 case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG:
2139 ret = mwifiex_cmd_sdio_rx_aggr_cfg(cmd_ptr, cmd_action,
2142 case HostCmd_CMD_HS_WAKEUP_REASON:
2143 ret = mwifiex_cmd_get_wakeup_reason(priv, cmd_ptr);
2145 case HostCmd_CMD_MC_POLICY:
2146 ret = mwifiex_cmd_set_mc_policy(priv, cmd_ptr, cmd_action,
2149 case HostCmd_CMD_ROBUST_COEX:
2150 ret = mwifiex_cmd_robust_coex(priv, cmd_ptr, cmd_action,
2153 case HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG:
2154 ret = mwifiex_cmd_gtk_rekey_offload(priv, cmd_ptr, cmd_action,
2157 case HostCmd_CMD_CHAN_REGION_CFG:
2158 ret = mwifiex_cmd_chan_region_cfg(priv, cmd_ptr, cmd_action);
2161 mwifiex_dbg(priv->adapter, ERROR,
2162 "PREP_CMD: unknown cmd- %#x\n", cmd_no);
2170 * This function issues commands to initialize firmware.
2172 * This is called after firmware download to bring the card to
2174 * Function is also called during reinitialization of virtual
2177 * The following commands are issued sequentially -
2178 * - Set PCI-Express host buffer configuration (PCIE only)
2179 * - Function init (for first interface only)
2180 * - Read MAC address (for first interface only)
2181 * - Reconfigure Tx buffer size (for first interface only)
2182 * - Enable auto deep sleep (for first interface only)
2185 * - Set IBSS coalescing status
2186 * - Set AMSDU aggregation control
2188 * - Set MAC control (this must be the last command to initialize firmware)
2190 int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta, bool init)
2192 struct mwifiex_adapter *adapter = priv->adapter;
2195 struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
2196 struct mwifiex_ds_auto_ds auto_ds;
2197 enum state_11d_t state_11d;
2198 struct mwifiex_ds_11n_tx_cfg tx_cfg;
2199 u8 sdio_sp_rx_aggr_enable;
2203 if (priv->adapter->iface_type == MWIFIEX_PCIE) {
2204 ret = mwifiex_send_cmd(priv,
2205 HostCmd_CMD_PCIE_DESC_DETAILS,
2206 HostCmd_ACT_GEN_SET, 0, NULL,
2212 ret = mwifiex_send_cmd(priv, HostCmd_CMD_FUNC_INIT,
2213 HostCmd_ACT_GEN_SET, 0, NULL, true);
2217 /* Download calibration data to firmware.
2218 * The cal-data can be read from device tree and/or
2219 * a configuration file and downloaded to firmware.
2221 if (priv->adapter->iface_type == MWIFIEX_SDIO &&
2222 adapter->dev->of_node) {
2223 adapter->dt_node = adapter->dev->of_node;
2224 if (of_property_read_u32(adapter->dt_node,
2225 "marvell,wakeup-pin",
2227 pr_debug("Wakeup pin = 0x%x\n", data);
2228 adapter->hs_cfg.gpio = data;
2231 ret = mwifiex_dnld_dt_cfgdata(priv, adapter->dt_node,
2237 if (adapter->cal_data) {
2238 ret = mwifiex_send_cmd(priv, HostCmd_CMD_CFG_DATA,
2239 HostCmd_ACT_GEN_SET, 0, NULL,
2245 /* Read MAC address from HW */
2246 ret = mwifiex_send_cmd(priv, HostCmd_CMD_GET_HW_SPEC,
2247 HostCmd_ACT_GEN_GET, 0, NULL, true);
2251 /** Set SDIO Single Port RX Aggr Info */
2252 if (priv->adapter->iface_type == MWIFIEX_SDIO &&
2253 ISSUPP_SDIO_SPA_ENABLED(priv->adapter->fw_cap_info) &&
2254 !priv->adapter->host_disable_sdio_rx_aggr) {
2255 sdio_sp_rx_aggr_enable = true;
2256 ret = mwifiex_send_cmd(priv,
2257 HostCmd_CMD_SDIO_SP_RX_AGGR_CFG,
2258 HostCmd_ACT_GEN_SET, 0,
2259 &sdio_sp_rx_aggr_enable,
2262 mwifiex_dbg(priv->adapter, ERROR,
2263 "error while enabling SP aggregation..disable it");
2264 adapter->sdio_rx_aggr_enable = false;
2268 /* Reconfigure tx buf size */
2269 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
2270 HostCmd_ACT_GEN_SET, 0,
2271 &priv->adapter->tx_buf_size, true);
2275 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2276 /* Enable IEEE PS by default */
2277 priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
2278 ret = mwifiex_send_cmd(priv,
2279 HostCmd_CMD_802_11_PS_MODE_ENH,
2280 EN_AUTO_PS, BITMAP_STA_PS, NULL,
2287 adapter->drcs_enabled = true;
2288 if (ISSUPP_DRCS_ENABLED(adapter->fw_cap_info))
2289 ret = mwifiex_send_cmd(priv,
2290 HostCmd_CMD_MC_POLICY,
2291 HostCmd_ACT_GEN_SET, 0,
2292 &adapter->drcs_enabled,
2298 mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REGION_CFG,
2299 HostCmd_ACT_GEN_GET, 0, NULL, true);
2303 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG,
2304 HostCmd_ACT_GEN_GET, 0, NULL, true);
2307 priv->data_rate = 0;
2310 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR,
2311 HostCmd_ACT_GEN_GET, 0, NULL, true);
2315 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
2316 /* set ibss coalescing_status */
2317 ret = mwifiex_send_cmd(
2319 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
2320 HostCmd_ACT_GEN_SET, 0, &enable, true);
2325 memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
2326 amsdu_aggr_ctrl.enable = true;
2327 /* Send request to firmware */
2328 ret = mwifiex_send_cmd(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
2329 HostCmd_ACT_GEN_SET, 0,
2330 &amsdu_aggr_ctrl, true);
2333 /* MAC Control must be the last command in init_fw */
2334 /* set MAC Control */
2335 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
2336 HostCmd_ACT_GEN_SET, 0,
2337 &priv->curr_pkt_filter, true);
2341 if (!disable_auto_ds &&
2342 first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
2343 priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2344 /* Enable auto deep sleep */
2345 auto_ds.auto_ds = DEEP_SLEEP_ON;
2346 auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
2347 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
2348 EN_AUTO_PS, BITMAP_AUTO_DS,
2354 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
2355 /* Send cmd to FW to enable/disable 11D function */
2356 state_11d = ENABLE_11D;
2357 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
2358 HostCmd_ACT_GEN_SET, DOT11D_I,
2361 mwifiex_dbg(priv->adapter, ERROR,
2362 "11D: failed to enable 11D\n");
2365 /* Send cmd to FW to configure 11n specific configuration
2366 * (Short GI, Channel BW, Green field support etc.) for transmit
2368 tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
2369 ret = mwifiex_send_cmd(priv, HostCmd_CMD_11N_CFG,
2370 HostCmd_ACT_GEN_SET, 0, &tx_cfg, true);
2373 /* set last_init_cmd before sending the command */
2374 priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;