Merge branch 'akpm' (Andrew's patch-bomb)
[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(HOST_SLEEP_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 const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
555
556 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
557 key_material->action = cpu_to_le16(cmd_action);
558
559 if (cmd_action == HostCmd_ACT_GEN_GET) {
560 cmd->size =
561 cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
562 return ret;
563 }
564
565 if (!enc_key) {
566 memset(&key_material->key_param_set, 0,
567 (NUM_WEP_KEYS *
568 sizeof(struct mwifiex_ie_type_key_param_set)));
569 ret = mwifiex_set_keyparamset_wep(priv,
570 &key_material->key_param_set,
571 &key_param_len);
572 cmd->size = cpu_to_le16(key_param_len +
573 sizeof(key_material->action) + S_DS_GEN);
574 return ret;
575 } else
576 memset(&key_material->key_param_set, 0,
577 sizeof(struct mwifiex_ie_type_key_param_set));
578 if (enc_key->is_wapi_key) {
579 dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
580 key_material->key_param_set.key_type_id =
581 cpu_to_le16(KEY_TYPE_ID_WAPI);
582 if (cmd_oid == KEY_INFO_ENABLED)
583 key_material->key_param_set.key_info =
584 cpu_to_le16(KEY_ENABLED);
585 else
586 key_material->key_param_set.key_info =
587 cpu_to_le16(!KEY_ENABLED);
588
589 key_material->key_param_set.key[0] = enc_key->key_index;
590 if (!priv->sec_info.wapi_key_on)
591 key_material->key_param_set.key[1] = 1;
592 else
593 /* set 0 when re-key */
594 key_material->key_param_set.key[1] = 0;
595
596 if (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) {
597 /* WAPI pairwise key: unicast */
598 key_material->key_param_set.key_info |=
599 cpu_to_le16(KEY_UNICAST);
600 } else { /* WAPI group key: multicast */
601 key_material->key_param_set.key_info |=
602 cpu_to_le16(KEY_MCAST);
603 priv->sec_info.wapi_key_on = true;
604 }
605
606 key_material->key_param_set.type =
607 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
608 key_material->key_param_set.key_len =
609 cpu_to_le16(WAPI_KEY_LEN);
610 memcpy(&key_material->key_param_set.key[2],
611 enc_key->key_material, enc_key->key_len);
612 memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
613 enc_key->wapi_rxpn, WAPI_RXPN_LEN);
614 key_material->key_param_set.length =
615 cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
616
617 key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
618 sizeof(struct mwifiex_ie_types_header);
619 cmd->size = cpu_to_le16(sizeof(key_material->action)
620 + S_DS_GEN + key_param_len);
621 return ret;
622 }
623 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
624 dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
625 key_material->key_param_set.key_type_id =
626 cpu_to_le16(KEY_TYPE_ID_AES);
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 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
635 /* AES pairwise key: unicast */
636 key_material->key_param_set.key_info |=
637 cpu_to_le16(KEY_UNICAST);
638 else /* AES group key: multicast */
639 key_material->key_param_set.key_info |=
640 cpu_to_le16(KEY_MCAST);
641 } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
642 dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
643 key_material->key_param_set.key_type_id =
644 cpu_to_le16(KEY_TYPE_ID_TKIP);
645 key_material->key_param_set.key_info =
646 cpu_to_le16(KEY_ENABLED);
647
648 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
649 /* TKIP pairwise key: unicast */
650 key_material->key_param_set.key_info |=
651 cpu_to_le16(KEY_UNICAST);
652 else /* TKIP group key: multicast */
653 key_material->key_param_set.key_info |=
654 cpu_to_le16(KEY_MCAST);
655 }
656
657 if (key_material->key_param_set.key_type_id) {
658 key_material->key_param_set.type =
659 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
660 key_material->key_param_set.key_len =
661 cpu_to_le16((u16) enc_key->key_len);
662 memcpy(key_material->key_param_set.key, enc_key->key_material,
663 enc_key->key_len);
664 key_material->key_param_set.length =
665 cpu_to_le16((u16) enc_key->key_len +
666 KEYPARAMSET_FIXED_LEN);
667
668 key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
669 + sizeof(struct mwifiex_ie_types_header);
670
671 cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
672 + key_param_len);
673
674 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
675 tlv_mac = (void *)((u8 *)&key_material->key_param_set +
676 key_param_len);
677 tlv_mac->tlv.type = cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
678 tlv_mac->tlv.len = cpu_to_le16(ETH_ALEN);
679 memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
680 cmd_size = key_param_len + S_DS_GEN +
681 sizeof(key_material->action) +
682 sizeof(struct host_cmd_tlv_mac_addr);
683 } else {
684 cmd_size = key_param_len + S_DS_GEN +
685 sizeof(key_material->action);
686 }
687 cmd->size = cpu_to_le16(cmd_size);
688 }
689
690 return ret;
691 }
692
693 /*
694 * This function prepares command to set/get 11d domain information.
695 *
696 * Preparation includes -
697 * - Setting command ID, action and proper size
698 * - Setting domain information fields (for SET only)
699 * - Ensuring correct endian-ness
700 */
701 static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
702 struct host_cmd_ds_command *cmd,
703 u16 cmd_action)
704 {
705 struct mwifiex_adapter *adapter = priv->adapter;
706 struct host_cmd_ds_802_11d_domain_info *domain_info =
707 &cmd->params.domain_info;
708 struct mwifiex_ietypes_domain_param_set *domain =
709 &domain_info->domain;
710 u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
711
712 dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
713
714 cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
715 domain_info->action = cpu_to_le16(cmd_action);
716 if (cmd_action == HostCmd_ACT_GEN_GET) {
717 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
718 return 0;
719 }
720
721 /* Set domain info fields */
722 domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
723 memcpy(domain->country_code, adapter->domain_reg.country_code,
724 sizeof(domain->country_code));
725
726 domain->header.len =
727 cpu_to_le16((no_of_triplet *
728 sizeof(struct ieee80211_country_ie_triplet))
729 + sizeof(domain->country_code));
730
731 if (no_of_triplet) {
732 memcpy(domain->triplet, adapter->domain_reg.triplet,
733 no_of_triplet * sizeof(struct
734 ieee80211_country_ie_triplet));
735
736 cmd->size = cpu_to_le16(sizeof(domain_info->action) +
737 le16_to_cpu(domain->header.len) +
738 sizeof(struct mwifiex_ie_types_header)
739 + S_DS_GEN);
740 } else {
741 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
742 }
743
744 return 0;
745 }
746
747 /*
748 * This function prepares command to set/get IBSS coalescing status.
749 *
750 * Preparation includes -
751 * - Setting command ID, action and proper size
752 * - Setting status to enable or disable (for SET only)
753 * - Ensuring correct endian-ness
754 */
755 static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
756 u16 cmd_action, u16 *enable)
757 {
758 struct host_cmd_ds_802_11_ibss_status *ibss_coal =
759 &(cmd->params.ibss_coalescing);
760
761 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
762 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
763 S_DS_GEN);
764 cmd->result = 0;
765 ibss_coal->action = cpu_to_le16(cmd_action);
766
767 switch (cmd_action) {
768 case HostCmd_ACT_GEN_SET:
769 if (enable)
770 ibss_coal->enable = cpu_to_le16(*enable);
771 else
772 ibss_coal->enable = 0;
773 break;
774
775 /* In other case.. Nothing to do */
776 case HostCmd_ACT_GEN_GET:
777 default:
778 break;
779 }
780
781 return 0;
782 }
783
784 /*
785 * This function prepares command to set/get register value.
786 *
787 * Preparation includes -
788 * - Setting command ID, action and proper size
789 * - Setting register offset (for both GET and SET) and
790 * register value (for SET only)
791 * - Ensuring correct endian-ness
792 *
793 * The following type of registers can be accessed with this function -
794 * - MAC register
795 * - BBP register
796 * - RF register
797 * - PMIC register
798 * - CAU register
799 * - EEPROM
800 */
801 static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
802 u16 cmd_action, void *data_buf)
803 {
804 struct mwifiex_ds_reg_rw *reg_rw = data_buf;
805
806 switch (le16_to_cpu(cmd->command)) {
807 case HostCmd_CMD_MAC_REG_ACCESS:
808 {
809 struct host_cmd_ds_mac_reg_access *mac_reg;
810
811 cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
812 mac_reg = &cmd->params.mac_reg;
813 mac_reg->action = cpu_to_le16(cmd_action);
814 mac_reg->offset =
815 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
816 mac_reg->value = reg_rw->value;
817 break;
818 }
819 case HostCmd_CMD_BBP_REG_ACCESS:
820 {
821 struct host_cmd_ds_bbp_reg_access *bbp_reg;
822
823 cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
824 bbp_reg = &cmd->params.bbp_reg;
825 bbp_reg->action = cpu_to_le16(cmd_action);
826 bbp_reg->offset =
827 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
828 bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
829 break;
830 }
831 case HostCmd_CMD_RF_REG_ACCESS:
832 {
833 struct host_cmd_ds_rf_reg_access *rf_reg;
834
835 cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
836 rf_reg = &cmd->params.rf_reg;
837 rf_reg->action = cpu_to_le16(cmd_action);
838 rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
839 rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
840 break;
841 }
842 case HostCmd_CMD_PMIC_REG_ACCESS:
843 {
844 struct host_cmd_ds_pmic_reg_access *pmic_reg;
845
846 cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
847 pmic_reg = &cmd->params.pmic_reg;
848 pmic_reg->action = cpu_to_le16(cmd_action);
849 pmic_reg->offset =
850 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
851 pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
852 break;
853 }
854 case HostCmd_CMD_CAU_REG_ACCESS:
855 {
856 struct host_cmd_ds_rf_reg_access *cau_reg;
857
858 cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
859 cau_reg = &cmd->params.rf_reg;
860 cau_reg->action = cpu_to_le16(cmd_action);
861 cau_reg->offset =
862 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
863 cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
864 break;
865 }
866 case HostCmd_CMD_802_11_EEPROM_ACCESS:
867 {
868 struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
869 struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
870 &cmd->params.eeprom;
871
872 cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
873 cmd_eeprom->action = cpu_to_le16(cmd_action);
874 cmd_eeprom->offset = rd_eeprom->offset;
875 cmd_eeprom->byte_count = rd_eeprom->byte_count;
876 cmd_eeprom->value = 0;
877 break;
878 }
879 default:
880 return -1;
881 }
882
883 return 0;
884 }
885
886 /*
887 * This function prepares command to set PCI-Express
888 * host buffer configuration
889 *
890 * Preparation includes -
891 * - Setting command ID, action and proper size
892 * - Setting host buffer configuration
893 * - Ensuring correct endian-ness
894 */
895 static int
896 mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
897 struct host_cmd_ds_command *cmd, u16 action)
898 {
899 struct host_cmd_ds_pcie_details *host_spec =
900 &cmd->params.pcie_host_spec;
901 struct pcie_service_card *card = priv->adapter->card;
902 phys_addr_t *buf_pa;
903
904 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
905 cmd->size = cpu_to_le16(sizeof(struct
906 host_cmd_ds_pcie_details) + S_DS_GEN);
907 cmd->result = 0;
908
909 memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
910
911 if (action != HostCmd_ACT_GEN_SET)
912 return 0;
913
914 /* Send the ring base addresses and count to firmware */
915 host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
916 host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
917 host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
918 host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
919 host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
920 host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
921 host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
922 host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
923 host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
924 if (card->sleep_cookie) {
925 buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie);
926 host_spec->sleep_cookie_addr_lo = (u32) *buf_pa;
927 host_spec->sleep_cookie_addr_hi = (u32) (((u64)*buf_pa) >> 32);
928 dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
929 host_spec->sleep_cookie_addr_lo);
930 }
931
932 return 0;
933 }
934
935 /*
936 * This function prepares command for event subscription, configuration
937 * and query. Events can be subscribed or unsubscribed. Current subscribed
938 * events can be queried. Also, current subscribed events are reported in
939 * every FW response.
940 */
941 static int
942 mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
943 struct host_cmd_ds_command *cmd,
944 struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
945 {
946 struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
947 struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
948 u16 event_bitmap;
949 u8 *pos;
950
951 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
952 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
953 S_DS_GEN);
954
955 subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
956 dev_dbg(priv->adapter->dev, "cmd: action: %d\n", subsc_evt_cfg->action);
957
958 /*For query requests, no configuration TLV structures are to be added.*/
959 if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
960 return 0;
961
962 subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
963
964 event_bitmap = subsc_evt_cfg->events;
965 dev_dbg(priv->adapter->dev, "cmd: event bitmap : %16x\n",
966 event_bitmap);
967
968 if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
969 (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
970 (event_bitmap == 0)) {
971 dev_dbg(priv->adapter->dev, "Error: No event specified "
972 "for bitwise action type\n");
973 return -EINVAL;
974 }
975
976 /*
977 * Append TLV structures for each of the specified events for
978 * subscribing or re-configuring. This is not required for
979 * bitwise unsubscribing request.
980 */
981 if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
982 return 0;
983
984 pos = ((u8 *)subsc_evt) +
985 sizeof(struct host_cmd_ds_802_11_subsc_evt);
986
987 if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
988 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
989
990 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
991 rssi_tlv->header.len =
992 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
993 sizeof(struct mwifiex_ie_types_header));
994 rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
995 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
996
997 dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
998 "RSSI:-%d dBm, Freq:%d\n",
999 subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
1000 subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
1001
1002 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1003 le16_add_cpu(&cmd->size,
1004 sizeof(struct mwifiex_ie_types_rssi_threshold));
1005 }
1006
1007 if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
1008 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1009
1010 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1011 rssi_tlv->header.len =
1012 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1013 sizeof(struct mwifiex_ie_types_header));
1014 rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
1015 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
1016
1017 dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
1018 "RSSI:-%d dBm, Freq:%d\n",
1019 subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
1020 subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
1021
1022 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1023 le16_add_cpu(&cmd->size,
1024 sizeof(struct mwifiex_ie_types_rssi_threshold));
1025 }
1026
1027 return 0;
1028 }
1029
1030 /*
1031 * This function prepares the commands before sending them to the firmware.
1032 *
1033 * This is a generic function which calls specific command preparation
1034 * routines based upon the command number.
1035 */
1036 int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1037 u16 cmd_action, u32 cmd_oid,
1038 void *data_buf, void *cmd_buf)
1039 {
1040 struct host_cmd_ds_command *cmd_ptr = cmd_buf;
1041 int ret = 0;
1042
1043 /* Prepare command */
1044 switch (cmd_no) {
1045 case HostCmd_CMD_GET_HW_SPEC:
1046 ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
1047 break;
1048 case HostCmd_CMD_MAC_CONTROL:
1049 ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
1050 data_buf);
1051 break;
1052 case HostCmd_CMD_802_11_MAC_ADDRESS:
1053 ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
1054 cmd_action);
1055 break;
1056 case HostCmd_CMD_MAC_MULTICAST_ADR:
1057 ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
1058 data_buf);
1059 break;
1060 case HostCmd_CMD_TX_RATE_CFG:
1061 ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
1062 data_buf);
1063 break;
1064 case HostCmd_CMD_TXPWR_CFG:
1065 ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
1066 data_buf);
1067 break;
1068 case HostCmd_CMD_RF_TX_PWR:
1069 ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
1070 data_buf);
1071 break;
1072 case HostCmd_CMD_RF_ANTENNA:
1073 ret = mwifiex_cmd_rf_antenna(priv, cmd_ptr, cmd_action,
1074 data_buf);
1075 break;
1076 case HostCmd_CMD_802_11_PS_MODE_ENH:
1077 ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
1078 (uint16_t)cmd_oid, data_buf);
1079 break;
1080 case HostCmd_CMD_802_11_HS_CFG_ENH:
1081 ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
1082 (struct mwifiex_hs_config_param *) data_buf);
1083 break;
1084 case HostCmd_CMD_802_11_SCAN:
1085 ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
1086 break;
1087 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
1088 ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
1089 break;
1090 case HostCmd_CMD_802_11_ASSOCIATE:
1091 ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
1092 break;
1093 case HostCmd_CMD_802_11_DEAUTHENTICATE:
1094 ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
1095 data_buf);
1096 break;
1097 case HostCmd_CMD_802_11_AD_HOC_START:
1098 ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
1099 data_buf);
1100 break;
1101 case HostCmd_CMD_802_11_GET_LOG:
1102 ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
1103 break;
1104 case HostCmd_CMD_802_11_AD_HOC_JOIN:
1105 ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
1106 data_buf);
1107 break;
1108 case HostCmd_CMD_802_11_AD_HOC_STOP:
1109 ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
1110 break;
1111 case HostCmd_CMD_RSSI_INFO:
1112 ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
1113 break;
1114 case HostCmd_CMD_802_11_SNMP_MIB:
1115 ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
1116 cmd_oid, data_buf);
1117 break;
1118 case HostCmd_CMD_802_11_TX_RATE_QUERY:
1119 cmd_ptr->command =
1120 cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
1121 cmd_ptr->size =
1122 cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
1123 S_DS_GEN);
1124 priv->tx_rate = 0;
1125 ret = 0;
1126 break;
1127 case HostCmd_CMD_VERSION_EXT:
1128 cmd_ptr->command = cpu_to_le16(cmd_no);
1129 cmd_ptr->params.verext.version_str_sel =
1130 (u8) (*((u32 *) data_buf));
1131 memcpy(&cmd_ptr->params, data_buf,
1132 sizeof(struct host_cmd_ds_version_ext));
1133 cmd_ptr->size =
1134 cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
1135 S_DS_GEN);
1136 ret = 0;
1137 break;
1138 case HostCmd_CMD_FUNC_INIT:
1139 if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
1140 priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
1141 cmd_ptr->command = cpu_to_le16(cmd_no);
1142 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1143 break;
1144 case HostCmd_CMD_FUNC_SHUTDOWN:
1145 priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
1146 cmd_ptr->command = cpu_to_le16(cmd_no);
1147 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1148 break;
1149 case HostCmd_CMD_11N_ADDBA_REQ:
1150 ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
1151 break;
1152 case HostCmd_CMD_11N_DELBA:
1153 ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
1154 break;
1155 case HostCmd_CMD_11N_ADDBA_RSP:
1156 ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
1157 break;
1158 case HostCmd_CMD_802_11_KEY_MATERIAL:
1159 ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
1160 cmd_action, cmd_oid,
1161 data_buf);
1162 break;
1163 case HostCmd_CMD_802_11D_DOMAIN_INFO:
1164 ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
1165 cmd_action);
1166 break;
1167 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
1168 ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
1169 data_buf);
1170 break;
1171 case HostCmd_CMD_AMSDU_AGGR_CTRL:
1172 ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
1173 data_buf);
1174 break;
1175 case HostCmd_CMD_11N_CFG:
1176 ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action, data_buf);
1177 break;
1178 case HostCmd_CMD_WMM_GET_STATUS:
1179 dev_dbg(priv->adapter->dev,
1180 "cmd: WMM: WMM_GET_STATUS cmd sent\n");
1181 cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
1182 cmd_ptr->size =
1183 cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
1184 S_DS_GEN);
1185 ret = 0;
1186 break;
1187 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
1188 ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
1189 data_buf);
1190 break;
1191 case HostCmd_CMD_MAC_REG_ACCESS:
1192 case HostCmd_CMD_BBP_REG_ACCESS:
1193 case HostCmd_CMD_RF_REG_ACCESS:
1194 case HostCmd_CMD_PMIC_REG_ACCESS:
1195 case HostCmd_CMD_CAU_REG_ACCESS:
1196 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1197 ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
1198 break;
1199 case HostCmd_CMD_SET_BSS_MODE:
1200 cmd_ptr->command = cpu_to_le16(cmd_no);
1201 if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
1202 cmd_ptr->params.bss_mode.con_type =
1203 CONNECTION_TYPE_ADHOC;
1204 else if (priv->bss_mode == NL80211_IFTYPE_STATION)
1205 cmd_ptr->params.bss_mode.con_type =
1206 CONNECTION_TYPE_INFRA;
1207 cmd_ptr->size = cpu_to_le16(sizeof(struct
1208 host_cmd_ds_set_bss_mode) + S_DS_GEN);
1209 ret = 0;
1210 break;
1211 case HostCmd_CMD_PCIE_DESC_DETAILS:
1212 ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
1213 break;
1214 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
1215 ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
1216 break;
1217 default:
1218 dev_err(priv->adapter->dev,
1219 "PREP_CMD: unknown cmd- %#x\n", cmd_no);
1220 ret = -1;
1221 break;
1222 }
1223 return ret;
1224 }
1225
1226 /*
1227 * This function issues commands to initialize firmware.
1228 *
1229 * This is called after firmware download to bring the card to
1230 * working state.
1231 *
1232 * The following commands are issued sequentially -
1233 * - Set PCI-Express host buffer configuration (PCIE only)
1234 * - Function init (for first interface only)
1235 * - Read MAC address (for first interface only)
1236 * - Reconfigure Tx buffer size (for first interface only)
1237 * - Enable auto deep sleep (for first interface only)
1238 * - Get Tx rate
1239 * - Get Tx power
1240 * - Set IBSS coalescing status
1241 * - Set AMSDU aggregation control
1242 * - Set 11d control
1243 * - Set MAC control (this must be the last command to initialize firmware)
1244 */
1245 int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
1246 {
1247 int ret;
1248 u16 enable = true;
1249 struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
1250 struct mwifiex_ds_auto_ds auto_ds;
1251 enum state_11d_t state_11d;
1252 struct mwifiex_ds_11n_tx_cfg tx_cfg;
1253
1254 if (first_sta) {
1255 if (priv->adapter->iface_type == MWIFIEX_PCIE) {
1256 ret = mwifiex_send_cmd_async(priv,
1257 HostCmd_CMD_PCIE_DESC_DETAILS,
1258 HostCmd_ACT_GEN_SET, 0, NULL);
1259 if (ret)
1260 return -1;
1261 }
1262
1263 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
1264 HostCmd_ACT_GEN_SET, 0, NULL);
1265 if (ret)
1266 return -1;
1267 /* Read MAC address from HW */
1268 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
1269 HostCmd_ACT_GEN_GET, 0, NULL);
1270 if (ret)
1271 return -1;
1272
1273 /* Reconfigure tx buf size */
1274 ret = mwifiex_send_cmd_async(priv,
1275 HostCmd_CMD_RECONFIGURE_TX_BUFF,
1276 HostCmd_ACT_GEN_SET, 0,
1277 &priv->adapter->tx_buf_size);
1278 if (ret)
1279 return -1;
1280
1281 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
1282 /* Enable IEEE PS by default */
1283 priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
1284 ret = mwifiex_send_cmd_async(
1285 priv, HostCmd_CMD_802_11_PS_MODE_ENH,
1286 EN_AUTO_PS, BITMAP_STA_PS, NULL);
1287 if (ret)
1288 return -1;
1289 }
1290 }
1291
1292 /* get tx rate */
1293 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
1294 HostCmd_ACT_GEN_GET, 0, NULL);
1295 if (ret)
1296 return -1;
1297 priv->data_rate = 0;
1298
1299 /* get tx power */
1300 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_RF_TX_PWR,
1301 HostCmd_ACT_GEN_GET, 0, NULL);
1302 if (ret)
1303 return -1;
1304
1305 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
1306 /* set ibss coalescing_status */
1307 ret = mwifiex_send_cmd_async(
1308 priv, HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
1309 HostCmd_ACT_GEN_SET, 0, &enable);
1310 if (ret)
1311 return -1;
1312 }
1313
1314 memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
1315 amsdu_aggr_ctrl.enable = true;
1316 /* Send request to firmware */
1317 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
1318 HostCmd_ACT_GEN_SET, 0,
1319 &amsdu_aggr_ctrl);
1320 if (ret)
1321 return -1;
1322 /* MAC Control must be the last command in init_fw */
1323 /* set MAC Control */
1324 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
1325 HostCmd_ACT_GEN_SET, 0,
1326 &priv->curr_pkt_filter);
1327 if (ret)
1328 return -1;
1329
1330 if (first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
1331 priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
1332 /* Enable auto deep sleep */
1333 auto_ds.auto_ds = DEEP_SLEEP_ON;
1334 auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
1335 ret = mwifiex_send_cmd_async(priv,
1336 HostCmd_CMD_802_11_PS_MODE_ENH,
1337 EN_AUTO_PS, BITMAP_AUTO_DS,
1338 &auto_ds);
1339 if (ret)
1340 return -1;
1341 }
1342
1343 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
1344 /* Send cmd to FW to enable/disable 11D function */
1345 state_11d = ENABLE_11D;
1346 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
1347 HostCmd_ACT_GEN_SET, DOT11D_I,
1348 &state_11d);
1349 if (ret)
1350 dev_err(priv->adapter->dev,
1351 "11D: failed to enable 11D\n");
1352 }
1353
1354 /* Send cmd to FW to configure 11n specific configuration
1355 * (Short GI, Channel BW, Green field support etc.) for transmit
1356 */
1357 tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
1358 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG,
1359 HostCmd_ACT_GEN_SET, 0, &tx_cfg);
1360
1361 /* set last_init_cmd */
1362 priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
1363 ret = -EINPROGRESS;
1364
1365 return ret;
1366 }
This page took 0.065548 seconds and 5 git commands to generate.