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