blob: 2d4319a8941f66a8d37d0594dd8f8f3225f70b38 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
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 */
37static int
38mwifiex_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 */
68static int mwifiex_cmd_mac_control(struct mwifiex_private *priv,
69 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -070070 u16 cmd_action, u16 *action)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070071{
72 struct host_cmd_ds_mac_control *mac_ctrl = &cmd->params.mac_ctrl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070073
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);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -070083 mac_ctrl->action = cpu_to_le16(*action);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070084
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 */
103static 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,
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800106 u16 *ul_temp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700107{
108 struct host_cmd_ds_802_11_snmp_mib *snmp_mib = &cmd->params.smib;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700109
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)
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700113 - 1 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700114
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800115 snmp_mib->oid = cpu_to_le16((u16)cmd_oid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700116 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);
Amitkumar Karwarf3c8d252012-02-02 20:48:57 -0800119 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));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700125 }
126
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700127 dev_dbg(priv->adapter->dev,
128 "cmd: SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x,"
129 " Value=0x%x\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700130 cmd_action, cmd_oid, le16_to_cpu(snmp_mib->buf_size),
131 le16_to_cpu(*(__le16 *) snmp_mib->value));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700132 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 */
142static int
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700143mwifiex_cmd_802_11_get_log(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700144{
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 */
160static int mwifiex_cmd_tx_rate_cfg(struct mwifiex_private *priv,
161 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700162 u16 cmd_action, u16 *pbitmap_rates)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700163{
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;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700167 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);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700177 rate_scope->length = cpu_to_le16
178 (sizeof(*rate_scope) - sizeof(struct mwifiex_ie_types_header));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700179 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 +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700200 sizeof(struct mwifiex_rate_scope));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700201 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 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700222static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700223 u16 cmd_action,
224 struct host_cmd_ds_txpwr_cfg *txp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700225{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700226 struct mwifiex_types_power_group *pg_tlv;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700227 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:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700234 if (txp->mode) {
235 pg_tlv = (struct mwifiex_types_power_group
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700236 *) ((unsigned long) txp +
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700237 sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700238 memmove(cmd_txp_cfg, txp,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700239 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 {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700250 memmove(cmd_txp_cfg, txp, sizeof(*txp));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700251 }
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/*
Amitkumar Karwarcaa89842012-06-27 19:57:57 -0700263 * This function prepares command to get RF Tx power.
264 */
265static 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/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700280 * This function prepares command to set Host Sleep configuration.
281 *
282 * Preparation includes -
283 * - Setting command ID and proper size
284 * - Setting Host Sleep action, conditions, ARP filters
285 * (as required)
286 * - Ensuring correct endian-ness
287 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700288static int
289mwifiex_cmd_802_11_hs_cfg(struct mwifiex_private *priv,
290 struct host_cmd_ds_command *cmd,
291 u16 cmd_action,
292 struct mwifiex_hs_config_param *hscfg_param)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700293{
294 struct mwifiex_adapter *adapter = priv->adapter;
295 struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg = &cmd->params.opt_hs_cfg;
296 u16 hs_activate = false;
297
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700298 if (!hscfg_param)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700299 /* New Activate command */
300 hs_activate = true;
301 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH);
302
303 if (!hs_activate &&
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700304 (hscfg_param->conditions != cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) &&
305 ((adapter->arp_filter_size > 0) &&
306 (adapter->arp_filter_size <= ARP_FILTER_MAX_BUF_SIZE))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700307 dev_dbg(adapter->dev,
308 "cmd: Attach %d bytes ArpFilter to HSCfg cmd\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700309 adapter->arp_filter_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700310 memcpy(((u8 *) hs_cfg) +
311 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh),
312 adapter->arp_filter, adapter->arp_filter_size);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700313 cmd->size = cpu_to_le16
314 (adapter->arp_filter_size +
315 sizeof(struct host_cmd_ds_802_11_hs_cfg_enh)
316 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700317 } else {
318 cmd->size = cpu_to_le16(S_DS_GEN + sizeof(struct
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700319 host_cmd_ds_802_11_hs_cfg_enh));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700320 }
321 if (hs_activate) {
322 hs_cfg->action = cpu_to_le16(HS_ACTIVATE);
323 hs_cfg->params.hs_activate.resp_ctrl = RESP_NEEDED;
324 } else {
325 hs_cfg->action = cpu_to_le16(HS_CONFIGURE);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700326 hs_cfg->params.hs_config.conditions = hscfg_param->conditions;
327 hs_cfg->params.hs_config.gpio = hscfg_param->gpio;
328 hs_cfg->params.hs_config.gap = hscfg_param->gap;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700329 dev_dbg(adapter->dev,
330 "cmd: HS_CFG_CMD: condition:0x%x gpio:0x%x gap:0x%x\n",
331 hs_cfg->params.hs_config.conditions,
332 hs_cfg->params.hs_config.gpio,
333 hs_cfg->params.hs_config.gap);
334 }
335
336 return 0;
337}
338
339/*
340 * This function prepares command to set/get MAC address.
341 *
342 * Preparation includes -
343 * - Setting command ID, action and proper size
344 * - Setting MAC address (for SET only)
345 * - Ensuring correct endian-ness
346 */
347static int mwifiex_cmd_802_11_mac_address(struct mwifiex_private *priv,
348 struct host_cmd_ds_command *cmd,
349 u16 cmd_action)
350{
351 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_MAC_ADDRESS);
352 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_mac_address) +
353 S_DS_GEN);
354 cmd->result = 0;
355
356 cmd->params.mac_addr.action = cpu_to_le16(cmd_action);
357
358 if (cmd_action == HostCmd_ACT_GEN_SET)
359 memcpy(cmd->params.mac_addr.mac_addr, priv->curr_addr,
360 ETH_ALEN);
361 return 0;
362}
363
364/*
365 * This function prepares command to set MAC multicast address.
366 *
367 * Preparation includes -
368 * - Setting command ID, action and proper size
369 * - Setting MAC multicast address
370 * - Ensuring correct endian-ness
371 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700372static int
373mwifiex_cmd_mac_multicast_adr(struct host_cmd_ds_command *cmd,
374 u16 cmd_action,
375 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700377 struct host_cmd_ds_mac_multicast_adr *mcast_addr = &cmd->params.mc_addr;
378
379 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_mac_multicast_adr) +
380 S_DS_GEN);
381 cmd->command = cpu_to_le16(HostCmd_CMD_MAC_MULTICAST_ADR);
382
383 mcast_addr->action = cpu_to_le16(cmd_action);
384 mcast_addr->num_of_adrs =
385 cpu_to_le16((u16) mcast_list->num_multicast_addr);
386 memcpy(mcast_addr->mac_list, mcast_list->mac_list,
387 mcast_list->num_multicast_addr * ETH_ALEN);
388
389 return 0;
390}
391
392/*
393 * This function prepares command to deauthenticate.
394 *
395 * Preparation includes -
396 * - Setting command ID and proper size
397 * - Setting AP MAC address and reason code
398 * - Ensuring correct endian-ness
399 */
400static int mwifiex_cmd_802_11_deauthenticate(struct mwifiex_private *priv,
401 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700402 u8 *mac)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700403{
404 struct host_cmd_ds_802_11_deauthenticate *deauth = &cmd->params.deauth;
405
406 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_DEAUTHENTICATE);
407 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_deauthenticate)
408 + S_DS_GEN);
409
410 /* Set AP MAC address */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700411 memcpy(deauth->mac_addr, mac, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700412
413 dev_dbg(priv->adapter->dev, "cmd: Deauth: %pM\n", deauth->mac_addr);
414
415 deauth->reason_code = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
416
417 return 0;
418}
419
420/*
421 * This function prepares command to stop Ad-Hoc network.
422 *
423 * Preparation includes -
424 * - Setting command ID and proper size
425 * - Ensuring correct endian-ness
426 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700427static int mwifiex_cmd_802_11_ad_hoc_stop(struct host_cmd_ds_command *cmd)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700428{
429 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_STOP);
430 cmd->size = cpu_to_le16(S_DS_GEN);
431 return 0;
432}
433
434/*
435 * This function sets WEP key(s) to key parameter TLV(s).
436 *
437 * Multi-key parameter TLVs are supported, so we can send multiple
438 * WEP keys in a single buffer.
439 */
440static int
441mwifiex_set_keyparamset_wep(struct mwifiex_private *priv,
442 struct mwifiex_ie_type_key_param_set *key_param_set,
443 u16 *key_param_len)
444{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700445 int cur_key_param_len;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700446 u8 i;
447
448 /* Multi-key_param_set TLV is supported */
449 for (i = 0; i < NUM_WEP_KEYS; i++) {
450 if ((priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP40) ||
451 (priv->wep_key[i].key_length == WLAN_KEY_LEN_WEP104)) {
452 key_param_set->type =
453 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
454/* Key_param_set WEP fixed length */
455#define KEYPARAMSET_WEP_FIXED_LEN 8
456 key_param_set->length = cpu_to_le16((u16)
457 (priv->wep_key[i].
458 key_length +
459 KEYPARAMSET_WEP_FIXED_LEN));
460 key_param_set->key_type_id =
461 cpu_to_le16(KEY_TYPE_ID_WEP);
462 key_param_set->key_info =
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700463 cpu_to_le16(KEY_ENABLED | KEY_UNICAST |
464 KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700465 key_param_set->key_len =
466 cpu_to_le16(priv->wep_key[i].key_length);
467 /* Set WEP key index */
468 key_param_set->key[0] = i;
469 /* Set default Tx key flag */
470 if (i ==
471 (priv->
472 wep_key_curr_index & HostCmd_WEP_KEY_INDEX_MASK))
473 key_param_set->key[1] = 1;
474 else
475 key_param_set->key[1] = 0;
476 memmove(&key_param_set->key[2],
477 priv->wep_key[i].key_material,
478 priv->wep_key[i].key_length);
479
480 cur_key_param_len = priv->wep_key[i].key_length +
481 KEYPARAMSET_WEP_FIXED_LEN +
482 sizeof(struct mwifiex_ie_types_header);
483 *key_param_len += (u16) cur_key_param_len;
484 key_param_set =
485 (struct mwifiex_ie_type_key_param_set *)
486 ((u8 *)key_param_set +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700487 cur_key_param_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700488 } else if (!priv->wep_key[i].key_length) {
489 continue;
490 } else {
491 dev_err(priv->adapter->dev,
492 "key%d Length = %d is incorrect\n",
493 (i + 1), priv->wep_key[i].key_length);
494 return -1;
495 }
496 }
497
498 return 0;
499}
500
501/*
502 * This function prepares command to set/get/reset network key(s).
503 *
504 * Preparation includes -
505 * - Setting command ID, action and proper size
506 * - Setting WEP keys, WAPI keys or WPA keys along with required
507 * encryption (TKIP, AES) (as required)
508 * - Ensuring correct endian-ness
509 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700510static int
511mwifiex_cmd_802_11_key_material(struct mwifiex_private *priv,
512 struct host_cmd_ds_command *cmd,
513 u16 cmd_action, u32 cmd_oid,
514 struct mwifiex_ds_encrypt_key *enc_key)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700515{
516 struct host_cmd_ds_802_11_key_material *key_material =
517 &cmd->params.key_material;
Avinash Patil75edd2c2012-05-08 18:30:18 -0700518 struct host_cmd_tlv_mac_addr *tlv_mac;
519 u16 key_param_len = 0, cmd_size;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700520 int ret = 0;
521 const u8 bc_mac[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
522
523 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_KEY_MATERIAL);
524 key_material->action = cpu_to_le16(cmd_action);
525
526 if (cmd_action == HostCmd_ACT_GEN_GET) {
527 cmd->size =
528 cpu_to_le16(sizeof(key_material->action) + S_DS_GEN);
529 return ret;
530 }
531
532 if (!enc_key) {
533 memset(&key_material->key_param_set, 0,
534 (NUM_WEP_KEYS *
535 sizeof(struct mwifiex_ie_type_key_param_set)));
536 ret = mwifiex_set_keyparamset_wep(priv,
537 &key_material->key_param_set,
538 &key_param_len);
539 cmd->size = cpu_to_le16(key_param_len +
540 sizeof(key_material->action) + S_DS_GEN);
541 return ret;
542 } else
543 memset(&key_material->key_param_set, 0,
544 sizeof(struct mwifiex_ie_type_key_param_set));
545 if (enc_key->is_wapi_key) {
546 dev_dbg(priv->adapter->dev, "info: Set WAPI Key\n");
547 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700548 cpu_to_le16(KEY_TYPE_ID_WAPI);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700549 if (cmd_oid == KEY_INFO_ENABLED)
550 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700551 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700552 else
553 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700554 cpu_to_le16(!KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700555
556 key_material->key_param_set.key[0] = enc_key->key_index;
557 if (!priv->sec_info.wapi_key_on)
558 key_material->key_param_set.key[1] = 1;
559 else
560 /* set 0 when re-key */
561 key_material->key_param_set.key[1] = 0;
562
563 if (0 != memcmp(enc_key->mac_addr, bc_mac, sizeof(bc_mac))) {
564 /* WAPI pairwise key: unicast */
565 key_material->key_param_set.key_info |=
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700566 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700567 } else { /* WAPI group key: multicast */
568 key_material->key_param_set.key_info |=
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700569 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700570 priv->sec_info.wapi_key_on = true;
571 }
572
573 key_material->key_param_set.type =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700574 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700575 key_material->key_param_set.key_len =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700576 cpu_to_le16(WAPI_KEY_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700577 memcpy(&key_material->key_param_set.key[2],
578 enc_key->key_material, enc_key->key_len);
579 memcpy(&key_material->key_param_set.key[2 + enc_key->key_len],
580 enc_key->wapi_rxpn, WAPI_RXPN_LEN);
581 key_material->key_param_set.length =
582 cpu_to_le16(WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN);
583
584 key_param_len = (WAPI_KEY_LEN + KEYPARAMSET_FIXED_LEN) +
585 sizeof(struct mwifiex_ie_types_header);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700586 cmd->size = cpu_to_le16(sizeof(key_material->action)
587 + S_DS_GEN + key_param_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700588 return ret;
589 }
590 if (enc_key->key_len == WLAN_KEY_LEN_CCMP) {
591 dev_dbg(priv->adapter->dev, "cmd: WPA_AES\n");
592 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700593 cpu_to_le16(KEY_TYPE_ID_AES);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700594 if (cmd_oid == KEY_INFO_ENABLED)
595 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700596 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700597 else
598 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700599 cpu_to_le16(!KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700600
601 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
602 /* AES pairwise key: unicast */
603 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700604 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700605 else /* AES group key: multicast */
606 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700607 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700608 } else if (enc_key->key_len == WLAN_KEY_LEN_TKIP) {
609 dev_dbg(priv->adapter->dev, "cmd: WPA_TKIP\n");
610 key_material->key_param_set.key_type_id =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700611 cpu_to_le16(KEY_TYPE_ID_TKIP);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700612 key_material->key_param_set.key_info =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700613 cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700614
615 if (enc_key->key_index & MWIFIEX_KEY_INDEX_UNICAST)
616 /* TKIP pairwise key: unicast */
617 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700618 cpu_to_le16(KEY_UNICAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700619 else /* TKIP group key: multicast */
620 key_material->key_param_set.key_info |=
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700621 cpu_to_le16(KEY_MCAST);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700622 }
623
624 if (key_material->key_param_set.key_type_id) {
625 key_material->key_param_set.type =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700626 cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700627 key_material->key_param_set.key_len =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700628 cpu_to_le16((u16) enc_key->key_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700629 memcpy(key_material->key_param_set.key, enc_key->key_material,
630 enc_key->key_len);
631 key_material->key_param_set.length =
632 cpu_to_le16((u16) enc_key->key_len +
633 KEYPARAMSET_FIXED_LEN);
634
Avinash Patil75edd2c2012-05-08 18:30:18 -0700635 key_param_len = (u16)(enc_key->key_len + KEYPARAMSET_FIXED_LEN)
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700636 + sizeof(struct mwifiex_ie_types_header);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700637
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700638 cmd->size = cpu_to_le16(sizeof(key_material->action) + S_DS_GEN
639 + key_param_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -0700640
641 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) {
642 tlv_mac = (void *)((u8 *)&key_material->key_param_set +
643 key_param_len);
644 tlv_mac->tlv.type = cpu_to_le16(TLV_TYPE_STA_MAC_ADDR);
645 tlv_mac->tlv.len = cpu_to_le16(ETH_ALEN);
646 memcpy(tlv_mac->mac_addr, enc_key->mac_addr, ETH_ALEN);
647 cmd_size = key_param_len + S_DS_GEN +
648 sizeof(key_material->action) +
649 sizeof(struct host_cmd_tlv_mac_addr);
650 } else {
651 cmd_size = key_param_len + S_DS_GEN +
652 sizeof(key_material->action);
653 }
654 cmd->size = cpu_to_le16(cmd_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700655 }
656
657 return ret;
658}
659
660/*
661 * This function prepares command to set/get 11d domain information.
662 *
663 * Preparation includes -
664 * - Setting command ID, action and proper size
665 * - Setting domain information fields (for SET only)
666 * - Ensuring correct endian-ness
667 */
668static int mwifiex_cmd_802_11d_domain_info(struct mwifiex_private *priv,
669 struct host_cmd_ds_command *cmd,
670 u16 cmd_action)
671{
672 struct mwifiex_adapter *adapter = priv->adapter;
673 struct host_cmd_ds_802_11d_domain_info *domain_info =
674 &cmd->params.domain_info;
675 struct mwifiex_ietypes_domain_param_set *domain =
676 &domain_info->domain;
677 u8 no_of_triplet = adapter->domain_reg.no_of_triplet;
678
679 dev_dbg(adapter->dev, "info: 11D: no_of_triplet=0x%x\n", no_of_triplet);
680
681 cmd->command = cpu_to_le16(HostCmd_CMD_802_11D_DOMAIN_INFO);
682 domain_info->action = cpu_to_le16(cmd_action);
683 if (cmd_action == HostCmd_ACT_GEN_GET) {
684 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
685 return 0;
686 }
687
688 /* Set domain info fields */
689 domain->header.type = cpu_to_le16(WLAN_EID_COUNTRY);
690 memcpy(domain->country_code, adapter->domain_reg.country_code,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700691 sizeof(domain->country_code));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700692
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700693 domain->header.len =
694 cpu_to_le16((no_of_triplet *
695 sizeof(struct ieee80211_country_ie_triplet))
696 + sizeof(domain->country_code));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700697
698 if (no_of_triplet) {
699 memcpy(domain->triplet, adapter->domain_reg.triplet,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700700 no_of_triplet * sizeof(struct
701 ieee80211_country_ie_triplet));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700702
703 cmd->size = cpu_to_le16(sizeof(domain_info->action) +
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700704 le16_to_cpu(domain->header.len) +
705 sizeof(struct mwifiex_ie_types_header)
706 + S_DS_GEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700707 } else {
708 cmd->size = cpu_to_le16(sizeof(domain_info->action) + S_DS_GEN);
709 }
710
711 return 0;
712}
713
714/*
715 * This function prepares command to set/get RF channel.
716 *
717 * Preparation includes -
718 * - Setting command ID, action and proper size
719 * - Setting RF type and current RF channel (for SET only)
720 * - Ensuring correct endian-ness
721 */
722static int mwifiex_cmd_802_11_rf_channel(struct mwifiex_private *priv,
723 struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700724 u16 cmd_action, u16 *channel)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700725{
726 struct host_cmd_ds_802_11_rf_channel *rf_chan =
727 &cmd->params.rf_channel;
728 uint16_t rf_type = le16_to_cpu(rf_chan->rf_type);
729
730 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_RF_CHANNEL);
731 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_rf_channel)
732 + S_DS_GEN);
733
734 if (cmd_action == HostCmd_ACT_GEN_SET) {
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700735 if ((priv->adapter->adhoc_start_band & BAND_A) ||
736 (priv->adapter->adhoc_start_band & BAND_AN))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700737 rf_chan->rf_type =
738 cpu_to_le16(HostCmd_SCAN_RADIO_TYPE_A);
739
740 rf_type = le16_to_cpu(rf_chan->rf_type);
Amitkumar Karwar21c3ba32011-12-20 23:47:21 -0800741 SET_SECONDARYCHAN(rf_type, priv->adapter->sec_chan_offset);
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700742 rf_chan->current_channel = cpu_to_le16(*channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700743 }
744 rf_chan->action = cpu_to_le16(cmd_action);
745 return 0;
746}
747
748/*
749 * This function prepares command to set/get IBSS coalescing status.
750 *
751 * Preparation includes -
752 * - Setting command ID, action and proper size
753 * - Setting status to enable or disable (for SET only)
754 * - Ensuring correct endian-ness
755 */
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700756static int mwifiex_cmd_ibss_coalescing_status(struct host_cmd_ds_command *cmd,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700757 u16 cmd_action, u16 *enable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700758{
759 struct host_cmd_ds_802_11_ibss_status *ibss_coal =
760 &(cmd->params.ibss_coalescing);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700761
762 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_IBSS_COALESCING_STATUS);
763 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_ibss_status) +
764 S_DS_GEN);
765 cmd->result = 0;
766 ibss_coal->action = cpu_to_le16(cmd_action);
767
768 switch (cmd_action) {
769 case HostCmd_ACT_GEN_SET:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700770 if (enable)
771 ibss_coal->enable = cpu_to_le16(*enable);
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300772 else
773 ibss_coal->enable = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700774 break;
775
776 /* In other case.. Nothing to do */
777 case HostCmd_ACT_GEN_GET:
778 default:
779 break;
780 }
781
782 return 0;
783}
784
785/*
786 * This function prepares command to set/get register value.
787 *
788 * Preparation includes -
789 * - Setting command ID, action and proper size
790 * - Setting register offset (for both GET and SET) and
791 * register value (for SET only)
792 * - Ensuring correct endian-ness
793 *
794 * The following type of registers can be accessed with this function -
795 * - MAC register
796 * - BBP register
797 * - RF register
798 * - PMIC register
799 * - CAU register
800 * - EEPROM
801 */
802static int mwifiex_cmd_reg_access(struct host_cmd_ds_command *cmd,
803 u16 cmd_action, void *data_buf)
804{
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700805 struct mwifiex_ds_reg_rw *reg_rw = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700806
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700807 switch (le16_to_cpu(cmd->command)) {
808 case HostCmd_CMD_MAC_REG_ACCESS:
809 {
810 struct host_cmd_ds_mac_reg_access *mac_reg;
811
812 cmd->size = cpu_to_le16(sizeof(*mac_reg) + S_DS_GEN);
813 mac_reg = (struct host_cmd_ds_mac_reg_access *) &cmd->
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700814 params.mac_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700815 mac_reg->action = cpu_to_le16(cmd_action);
816 mac_reg->offset =
817 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
818 mac_reg->value = reg_rw->value;
819 break;
820 }
821 case HostCmd_CMD_BBP_REG_ACCESS:
822 {
823 struct host_cmd_ds_bbp_reg_access *bbp_reg;
824
825 cmd->size = cpu_to_le16(sizeof(*bbp_reg) + S_DS_GEN);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700826 bbp_reg = (struct host_cmd_ds_bbp_reg_access *)
827 &cmd->params.bbp_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700828 bbp_reg->action = cpu_to_le16(cmd_action);
829 bbp_reg->offset =
830 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
831 bbp_reg->value = (u8) le32_to_cpu(reg_rw->value);
832 break;
833 }
834 case HostCmd_CMD_RF_REG_ACCESS:
835 {
836 struct host_cmd_ds_rf_reg_access *rf_reg;
837
838 cmd->size = cpu_to_le16(sizeof(*rf_reg) + S_DS_GEN);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700839 rf_reg = (struct host_cmd_ds_rf_reg_access *)
840 &cmd->params.rf_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700841 rf_reg->action = cpu_to_le16(cmd_action);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700842 rf_reg->offset = cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700843 rf_reg->value = (u8) le32_to_cpu(reg_rw->value);
844 break;
845 }
846 case HostCmd_CMD_PMIC_REG_ACCESS:
847 {
848 struct host_cmd_ds_pmic_reg_access *pmic_reg;
849
850 cmd->size = cpu_to_le16(sizeof(*pmic_reg) + S_DS_GEN);
851 pmic_reg = (struct host_cmd_ds_pmic_reg_access *) &cmd->
852 params.pmic_reg;
853 pmic_reg->action = cpu_to_le16(cmd_action);
854 pmic_reg->offset =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700855 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700856 pmic_reg->value = (u8) le32_to_cpu(reg_rw->value);
857 break;
858 }
859 case HostCmd_CMD_CAU_REG_ACCESS:
860 {
861 struct host_cmd_ds_rf_reg_access *cau_reg;
862
863 cmd->size = cpu_to_le16(sizeof(*cau_reg) + S_DS_GEN);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700864 cau_reg = (struct host_cmd_ds_rf_reg_access *)
865 &cmd->params.rf_reg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700866 cau_reg->action = cpu_to_le16(cmd_action);
867 cau_reg->offset =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700868 cpu_to_le16((u16) le32_to_cpu(reg_rw->offset));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700869 cau_reg->value = (u8) le32_to_cpu(reg_rw->value);
870 break;
871 }
872 case HostCmd_CMD_802_11_EEPROM_ACCESS:
873 {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700874 struct mwifiex_ds_read_eeprom *rd_eeprom = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700875 struct host_cmd_ds_802_11_eeprom_access *cmd_eeprom =
876 (struct host_cmd_ds_802_11_eeprom_access *)
877 &cmd->params.eeprom;
878
879 cmd->size = cpu_to_le16(sizeof(*cmd_eeprom) + S_DS_GEN);
880 cmd_eeprom->action = cpu_to_le16(cmd_action);
881 cmd_eeprom->offset = rd_eeprom->offset;
882 cmd_eeprom->byte_count = rd_eeprom->byte_count;
883 cmd_eeprom->value = 0;
884 break;
885 }
886 default:
887 return -1;
888 }
889
890 return 0;
891}
892
893/*
Amitkumar Karward930fae2011-10-11 17:41:21 -0700894 * This function prepares command to set PCI-Express
895 * host buffer configuration
896 *
897 * Preparation includes -
898 * - Setting command ID, action and proper size
899 * - Setting host buffer configuration
900 * - Ensuring correct endian-ness
901 */
902static int
903mwifiex_cmd_pcie_host_spec(struct mwifiex_private *priv,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700904 struct host_cmd_ds_command *cmd, u16 action)
Amitkumar Karward930fae2011-10-11 17:41:21 -0700905{
906 struct host_cmd_ds_pcie_details *host_spec =
907 &cmd->params.pcie_host_spec;
908 struct pcie_service_card *card = priv->adapter->card;
909 phys_addr_t *buf_pa;
910
911 cmd->command = cpu_to_le16(HostCmd_CMD_PCIE_DESC_DETAILS);
912 cmd->size = cpu_to_le16(sizeof(struct
913 host_cmd_ds_pcie_details) + S_DS_GEN);
914 cmd->result = 0;
915
916 memset(host_spec, 0, sizeof(struct host_cmd_ds_pcie_details));
917
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700918 if (action != HostCmd_ACT_GEN_SET)
919 return 0;
920
921 /* Send the ring base addresses and count to firmware */
922 host_spec->txbd_addr_lo = (u32)(card->txbd_ring_pbase);
923 host_spec->txbd_addr_hi = (u32)(((u64)card->txbd_ring_pbase)>>32);
924 host_spec->txbd_count = MWIFIEX_MAX_TXRX_BD;
925 host_spec->rxbd_addr_lo = (u32)(card->rxbd_ring_pbase);
926 host_spec->rxbd_addr_hi = (u32)(((u64)card->rxbd_ring_pbase)>>32);
927 host_spec->rxbd_count = MWIFIEX_MAX_TXRX_BD;
928 host_spec->evtbd_addr_lo = (u32)(card->evtbd_ring_pbase);
929 host_spec->evtbd_addr_hi = (u32)(((u64)card->evtbd_ring_pbase)>>32);
930 host_spec->evtbd_count = MWIFIEX_MAX_EVT_BD;
931 if (card->sleep_cookie) {
932 buf_pa = MWIFIEX_SKB_PACB(card->sleep_cookie);
933 host_spec->sleep_cookie_addr_lo = (u32) *buf_pa;
934 host_spec->sleep_cookie_addr_hi = (u32) (((u64)*buf_pa) >> 32);
935 dev_dbg(priv->adapter->dev, "sleep_cook_lo phy addr: 0x%x\n",
936 host_spec->sleep_cookie_addr_lo);
Amitkumar Karward930fae2011-10-11 17:41:21 -0700937 }
938
939 return 0;
940}
941
942/*
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700943 * This function prepares command for event subscription, configuration
944 * and query. Events can be subscribed or unsubscribed. Current subscribed
945 * events can be queried. Also, current subscribed events are reported in
946 * every FW response.
947 */
948static int
949mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
950 struct host_cmd_ds_command *cmd,
951 struct mwifiex_ds_misc_subsc_evt *subsc_evt_cfg)
952{
953 struct host_cmd_ds_802_11_subsc_evt *subsc_evt = &cmd->params.subsc_evt;
954 struct mwifiex_ie_types_rssi_threshold *rssi_tlv;
955 u16 event_bitmap;
956 u8 *pos;
957
958 cmd->command = cpu_to_le16(HostCmd_CMD_802_11_SUBSCRIBE_EVENT);
959 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_802_11_subsc_evt) +
960 S_DS_GEN);
961
962 subsc_evt->action = cpu_to_le16(subsc_evt_cfg->action);
963 dev_dbg(priv->adapter->dev, "cmd: action: %d\n", subsc_evt_cfg->action);
964
965 /*For query requests, no configuration TLV structures are to be added.*/
966 if (subsc_evt_cfg->action == HostCmd_ACT_GEN_GET)
967 return 0;
968
969 subsc_evt->events = cpu_to_le16(subsc_evt_cfg->events);
970
971 event_bitmap = subsc_evt_cfg->events;
972 dev_dbg(priv->adapter->dev, "cmd: event bitmap : %16x\n",
973 event_bitmap);
974
975 if (((subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR) ||
976 (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_SET)) &&
977 (event_bitmap == 0)) {
978 dev_dbg(priv->adapter->dev, "Error: No event specified "
979 "for bitwise action type\n");
980 return -EINVAL;
981 }
982
983 /*
984 * Append TLV structures for each of the specified events for
985 * subscribing or re-configuring. This is not required for
986 * bitwise unsubscribing request.
987 */
988 if (subsc_evt_cfg->action == HostCmd_ACT_BITWISE_CLR)
989 return 0;
990
991 pos = ((u8 *)subsc_evt) +
992 sizeof(struct host_cmd_ds_802_11_subsc_evt);
993
994 if (event_bitmap & BITMASK_BCN_RSSI_LOW) {
995 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
996
997 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_LOW);
998 rssi_tlv->header.len =
999 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1000 sizeof(struct mwifiex_ie_types_header));
1001 rssi_tlv->abs_value = subsc_evt_cfg->bcn_l_rssi_cfg.abs_value;
1002 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq;
1003
1004 dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
1005 "RSSI:-%d dBm, Freq:%d\n",
1006 subsc_evt_cfg->bcn_l_rssi_cfg.abs_value,
1007 subsc_evt_cfg->bcn_l_rssi_cfg.evt_freq);
1008
1009 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1010 le16_add_cpu(&cmd->size,
1011 sizeof(struct mwifiex_ie_types_rssi_threshold));
1012 }
1013
1014 if (event_bitmap & BITMASK_BCN_RSSI_HIGH) {
1015 rssi_tlv = (struct mwifiex_ie_types_rssi_threshold *) pos;
1016
1017 rssi_tlv->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1018 rssi_tlv->header.len =
1019 cpu_to_le16(sizeof(struct mwifiex_ie_types_rssi_threshold) -
1020 sizeof(struct mwifiex_ie_types_header));
1021 rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
1022 rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
1023
Bing Zhaod35ccaa2012-04-09 20:06:53 -07001024 dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001025 "RSSI:-%d dBm, Freq:%d\n",
1026 subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
1027 subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
1028
1029 pos += sizeof(struct mwifiex_ie_types_rssi_threshold);
1030 le16_add_cpu(&cmd->size,
1031 sizeof(struct mwifiex_ie_types_rssi_threshold));
1032 }
1033
1034 return 0;
1035}
1036
1037/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001038 * This function prepares the commands before sending them to the firmware.
1039 *
1040 * This is a generic function which calls specific command preparation
1041 * routines based upon the command number.
1042 */
1043int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
1044 u16 cmd_action, u32 cmd_oid,
1045 void *data_buf, void *cmd_buf)
1046{
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001047 struct host_cmd_ds_command *cmd_ptr = cmd_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001048 int ret = 0;
1049
1050 /* Prepare command */
1051 switch (cmd_no) {
1052 case HostCmd_CMD_GET_HW_SPEC:
1053 ret = mwifiex_cmd_get_hw_spec(priv, cmd_ptr);
1054 break;
1055 case HostCmd_CMD_MAC_CONTROL:
1056 ret = mwifiex_cmd_mac_control(priv, cmd_ptr, cmd_action,
1057 data_buf);
1058 break;
1059 case HostCmd_CMD_802_11_MAC_ADDRESS:
1060 ret = mwifiex_cmd_802_11_mac_address(priv, cmd_ptr,
1061 cmd_action);
1062 break;
1063 case HostCmd_CMD_MAC_MULTICAST_ADR:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001064 ret = mwifiex_cmd_mac_multicast_adr(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001065 data_buf);
1066 break;
1067 case HostCmd_CMD_TX_RATE_CFG:
1068 ret = mwifiex_cmd_tx_rate_cfg(priv, cmd_ptr, cmd_action,
1069 data_buf);
1070 break;
1071 case HostCmd_CMD_TXPWR_CFG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001072 ret = mwifiex_cmd_tx_power_cfg(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001073 data_buf);
1074 break;
Amitkumar Karwarcaa89842012-06-27 19:57:57 -07001075 case HostCmd_CMD_RF_TX_PWR:
1076 ret = mwifiex_cmd_rf_tx_power(priv, cmd_ptr, cmd_action,
1077 data_buf);
1078 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001079 case HostCmd_CMD_802_11_PS_MODE_ENH:
1080 ret = mwifiex_cmd_enh_power_mode(priv, cmd_ptr, cmd_action,
1081 (uint16_t)cmd_oid, data_buf);
1082 break;
1083 case HostCmd_CMD_802_11_HS_CFG_ENH:
1084 ret = mwifiex_cmd_802_11_hs_cfg(priv, cmd_ptr, cmd_action,
1085 (struct mwifiex_hs_config_param *) data_buf);
1086 break;
1087 case HostCmd_CMD_802_11_SCAN:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001088 ret = mwifiex_cmd_802_11_scan(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001089 break;
1090 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001091 ret = mwifiex_cmd_802_11_bg_scan_query(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001092 break;
1093 case HostCmd_CMD_802_11_ASSOCIATE:
1094 ret = mwifiex_cmd_802_11_associate(priv, cmd_ptr, data_buf);
1095 break;
1096 case HostCmd_CMD_802_11_DEAUTHENTICATE:
1097 ret = mwifiex_cmd_802_11_deauthenticate(priv, cmd_ptr,
1098 data_buf);
1099 break;
1100 case HostCmd_CMD_802_11_AD_HOC_START:
1101 ret = mwifiex_cmd_802_11_ad_hoc_start(priv, cmd_ptr,
1102 data_buf);
1103 break;
1104 case HostCmd_CMD_802_11_GET_LOG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001105 ret = mwifiex_cmd_802_11_get_log(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001106 break;
1107 case HostCmd_CMD_802_11_AD_HOC_JOIN:
1108 ret = mwifiex_cmd_802_11_ad_hoc_join(priv, cmd_ptr,
1109 data_buf);
1110 break;
1111 case HostCmd_CMD_802_11_AD_HOC_STOP:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001112 ret = mwifiex_cmd_802_11_ad_hoc_stop(cmd_ptr);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001113 break;
1114 case HostCmd_CMD_RSSI_INFO:
1115 ret = mwifiex_cmd_802_11_rssi_info(priv, cmd_ptr, cmd_action);
1116 break;
1117 case HostCmd_CMD_802_11_SNMP_MIB:
1118 ret = mwifiex_cmd_802_11_snmp_mib(priv, cmd_ptr, cmd_action,
1119 cmd_oid, data_buf);
1120 break;
1121 case HostCmd_CMD_802_11_TX_RATE_QUERY:
1122 cmd_ptr->command =
1123 cpu_to_le16(HostCmd_CMD_802_11_TX_RATE_QUERY);
1124 cmd_ptr->size =
1125 cpu_to_le16(sizeof(struct host_cmd_ds_tx_rate_query) +
1126 S_DS_GEN);
1127 priv->tx_rate = 0;
1128 ret = 0;
1129 break;
1130 case HostCmd_CMD_VERSION_EXT:
1131 cmd_ptr->command = cpu_to_le16(cmd_no);
1132 cmd_ptr->params.verext.version_str_sel =
1133 (u8) (*((u32 *) data_buf));
1134 memcpy(&cmd_ptr->params, data_buf,
1135 sizeof(struct host_cmd_ds_version_ext));
1136 cmd_ptr->size =
1137 cpu_to_le16(sizeof(struct host_cmd_ds_version_ext) +
1138 S_DS_GEN);
1139 ret = 0;
1140 break;
1141 case HostCmd_CMD_802_11_RF_CHANNEL:
1142 ret = mwifiex_cmd_802_11_rf_channel(priv, cmd_ptr, cmd_action,
1143 data_buf);
1144 break;
1145 case HostCmd_CMD_FUNC_INIT:
1146 if (priv->adapter->hw_status == MWIFIEX_HW_STATUS_RESET)
1147 priv->adapter->hw_status = MWIFIEX_HW_STATUS_READY;
1148 cmd_ptr->command = cpu_to_le16(cmd_no);
1149 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1150 break;
1151 case HostCmd_CMD_FUNC_SHUTDOWN:
1152 priv->adapter->hw_status = MWIFIEX_HW_STATUS_RESET;
1153 cmd_ptr->command = cpu_to_le16(cmd_no);
1154 cmd_ptr->size = cpu_to_le16(S_DS_GEN);
1155 break;
1156 case HostCmd_CMD_11N_ADDBA_REQ:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001157 ret = mwifiex_cmd_11n_addba_req(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001158 break;
1159 case HostCmd_CMD_11N_DELBA:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001160 ret = mwifiex_cmd_11n_delba(cmd_ptr, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161 break;
1162 case HostCmd_CMD_11N_ADDBA_RSP:
1163 ret = mwifiex_cmd_11n_addba_rsp_gen(priv, cmd_ptr, data_buf);
1164 break;
1165 case HostCmd_CMD_802_11_KEY_MATERIAL:
1166 ret = mwifiex_cmd_802_11_key_material(priv, cmd_ptr,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001167 cmd_action, cmd_oid,
1168 data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001169 break;
1170 case HostCmd_CMD_802_11D_DOMAIN_INFO:
1171 ret = mwifiex_cmd_802_11d_domain_info(priv, cmd_ptr,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001172 cmd_action);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001173 break;
1174 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
1175 ret = mwifiex_cmd_recfg_tx_buf(priv, cmd_ptr, cmd_action,
1176 data_buf);
1177 break;
1178 case HostCmd_CMD_AMSDU_AGGR_CTRL:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001179 ret = mwifiex_cmd_amsdu_aggr_ctrl(cmd_ptr, cmd_action,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001180 data_buf);
1181 break;
1182 case HostCmd_CMD_11N_CFG:
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001183 ret = mwifiex_cmd_11n_cfg(cmd_ptr, cmd_action, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001184 break;
1185 case HostCmd_CMD_WMM_GET_STATUS:
1186 dev_dbg(priv->adapter->dev,
1187 "cmd: WMM: WMM_GET_STATUS cmd sent\n");
1188 cmd_ptr->command = cpu_to_le16(HostCmd_CMD_WMM_GET_STATUS);
1189 cmd_ptr->size =
1190 cpu_to_le16(sizeof(struct host_cmd_ds_wmm_get_status) +
1191 S_DS_GEN);
1192 ret = 0;
1193 break;
1194 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -07001195 ret = mwifiex_cmd_ibss_coalescing_status(cmd_ptr, cmd_action,
1196 data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001197 break;
1198 case HostCmd_CMD_MAC_REG_ACCESS:
1199 case HostCmd_CMD_BBP_REG_ACCESS:
1200 case HostCmd_CMD_RF_REG_ACCESS:
1201 case HostCmd_CMD_PMIC_REG_ACCESS:
1202 case HostCmd_CMD_CAU_REG_ACCESS:
1203 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1204 ret = mwifiex_cmd_reg_access(cmd_ptr, cmd_action, data_buf);
1205 break;
1206 case HostCmd_CMD_SET_BSS_MODE:
1207 cmd_ptr->command = cpu_to_le16(cmd_no);
Bing Zhaoeecd8252011-03-28 17:55:41 -07001208 if (priv->bss_mode == NL80211_IFTYPE_ADHOC)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001209 cmd_ptr->params.bss_mode.con_type =
1210 CONNECTION_TYPE_ADHOC;
Bing Zhaoeecd8252011-03-28 17:55:41 -07001211 else if (priv->bss_mode == NL80211_IFTYPE_STATION)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001212 cmd_ptr->params.bss_mode.con_type =
1213 CONNECTION_TYPE_INFRA;
1214 cmd_ptr->size = cpu_to_le16(sizeof(struct
1215 host_cmd_ds_set_bss_mode) + S_DS_GEN);
1216 ret = 0;
1217 break;
Amitkumar Karward930fae2011-10-11 17:41:21 -07001218 case HostCmd_CMD_PCIE_DESC_DETAILS:
1219 ret = mwifiex_cmd_pcie_host_spec(priv, cmd_ptr, cmd_action);
1220 break;
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -07001221 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
1222 ret = mwifiex_cmd_802_11_subsc_evt(priv, cmd_ptr, data_buf);
1223 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001224 default:
1225 dev_err(priv->adapter->dev,
1226 "PREP_CMD: unknown cmd- %#x\n", cmd_no);
1227 ret = -1;
1228 break;
1229 }
1230 return ret;
1231}
1232
1233/*
1234 * This function issues commands to initialize firmware.
1235 *
1236 * This is called after firmware download to bring the card to
1237 * working state.
1238 *
1239 * The following commands are issued sequentially -
Amitkumar Karward930fae2011-10-11 17:41:21 -07001240 * - Set PCI-Express host buffer configuration (PCIE only)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001241 * - Function init (for first interface only)
1242 * - Read MAC address (for first interface only)
1243 * - Reconfigure Tx buffer size (for first interface only)
1244 * - Enable auto deep sleep (for first interface only)
1245 * - Get Tx rate
1246 * - Get Tx power
1247 * - Set IBSS coalescing status
1248 * - Set AMSDU aggregation control
1249 * - Set 11d control
1250 * - Set MAC control (this must be the last command to initialize firmware)
1251 */
1252int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta)
1253{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001254 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001255 u16 enable = true;
1256 struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
1257 struct mwifiex_ds_auto_ds auto_ds;
1258 enum state_11d_t state_11d;
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07001259 struct mwifiex_ds_11n_tx_cfg tx_cfg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001260
1261 if (first_sta) {
Amitkumar Karward930fae2011-10-11 17:41:21 -07001262 if (priv->adapter->iface_type == MWIFIEX_PCIE) {
1263 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -07001264 HostCmd_CMD_PCIE_DESC_DETAILS,
1265 HostCmd_ACT_GEN_SET, 0, NULL);
Amitkumar Karward930fae2011-10-11 17:41:21 -07001266 if (ret)
1267 return -1;
1268 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001269
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001270 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_FUNC_INIT,
1271 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001272 if (ret)
1273 return -1;
1274 /* Read MAC address from HW */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001275 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_GET_HW_SPEC,
1276 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001277 if (ret)
1278 return -1;
1279
1280 /* Reconfigure tx buf size */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001281 ret = mwifiex_send_cmd_async(priv,
1282 HostCmd_CMD_RECONFIGURE_TX_BUFF,
1283 HostCmd_ACT_GEN_SET, 0,
1284 &priv->adapter->tx_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001285 if (ret)
1286 return -1;
1287
Avinash Patil03785382012-05-08 18:30:14 -07001288 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
1289 /* Enable IEEE PS by default */
1290 priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
1291 ret = mwifiex_send_cmd_async(
1292 priv, HostCmd_CMD_802_11_PS_MODE_ENH,
1293 EN_AUTO_PS, BITMAP_STA_PS, NULL);
1294 if (ret)
1295 return -1;
1296 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001297 }
1298
1299 /* get tx rate */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001300 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_TX_RATE_CFG,
1301 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001302 if (ret)
1303 return -1;
1304 priv->data_rate = 0;
1305
1306 /* get tx power */
Amitkumar Karwarcaa89842012-06-27 19:57:57 -07001307 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_RF_TX_PWR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001308 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001309 if (ret)
1310 return -1;
1311
Avinash Patil03785382012-05-08 18:30:14 -07001312 if (priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
1313 /* set ibss coalescing_status */
1314 ret = mwifiex_send_cmd_async(
1315 priv, HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
1316 HostCmd_ACT_GEN_SET, 0, &enable);
1317 if (ret)
1318 return -1;
1319 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001320
1321 memset(&amsdu_aggr_ctrl, 0, sizeof(amsdu_aggr_ctrl));
1322 amsdu_aggr_ctrl.enable = true;
1323 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001324 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_AMSDU_AGGR_CTRL,
1325 HostCmd_ACT_GEN_SET, 0,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -07001326 &amsdu_aggr_ctrl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001327 if (ret)
1328 return -1;
1329 /* MAC Control must be the last command in init_fw */
1330 /* set MAC Control */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001331 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
1332 HostCmd_ACT_GEN_SET, 0,
1333 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001334 if (ret)
1335 return -1;
1336
Avinash Patil03785382012-05-08 18:30:14 -07001337 if (first_sta && priv->adapter->iface_type != MWIFIEX_USB &&
1338 priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001339 /* Enable auto deep sleep */
1340 auto_ds.auto_ds = DEEP_SLEEP_ON;
1341 auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001342 ret = mwifiex_send_cmd_async(priv,
1343 HostCmd_CMD_802_11_PS_MODE_ENH,
1344 EN_AUTO_PS, BITMAP_AUTO_DS,
1345 &auto_ds);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001346 if (ret)
1347 return -1;
1348 }
1349
Avinash Patil03785382012-05-08 18:30:14 -07001350 if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
1351 /* Send cmd to FW to enable/disable 11D function */
1352 state_11d = ENABLE_11D;
1353 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11_SNMP_MIB,
1354 HostCmd_ACT_GEN_SET, DOT11D_I,
1355 &state_11d);
1356 if (ret)
1357 dev_err(priv->adapter->dev,
1358 "11D: failed to enable 11D\n");
1359 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001360
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07001361 /* Send cmd to FW to configure 11n specific configuration
1362 * (Short GI, Channel BW, Green field support etc.) for transmit
1363 */
1364 tx_cfg.tx_htcap = MWIFIEX_FW_DEF_HTTXCFG;
1365 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_CFG,
1366 HostCmd_ACT_GEN_SET, 0, &tx_cfg);
1367
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001368 /* set last_init_cmd */
Amitkumar Karwarcd27bc32011-07-08 20:40:30 -07001369 priv->adapter->last_init_cmd = HostCmd_CMD_11N_CFG;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001370 ret = -EINPROGRESS;
1371
1372 return ret;
1373}