blob: cd90b6f0969f2925430385f350c3d5648de10ed4 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: station command response 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/*
30 * This function handles the command response error case.
31 *
32 * For scan response error, the function cancels all the pending
33 * scan commands and generates an event to inform the applications
34 * of the scan completion.
35 *
36 * For Power Save command failure, we do not retry enter PS
37 * command in case of Ad-hoc mode.
38 *
39 * For all other response errors, the current command buffer is freed
40 * and returned to the free command queue.
41 */
42static void
43mwifiex_process_cmdresp_error(struct mwifiex_private *priv,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070044 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070045{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -070046 struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070047 struct mwifiex_adapter *adapter = priv->adapter;
Marc Yang2b06bdb2011-03-30 18:12:44 -070048 struct host_cmd_ds_802_11_ps_mode_enh *pm;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070049 unsigned long flags;
50
51 dev_err(adapter->dev, "CMD_RESP: cmd %#x error, result=%#x\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -070052 resp->command, resp->result);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070053
54 if (adapter->curr_cmd->wait_q_enabled)
55 adapter->cmd_wait_q.status = -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070056
57 switch (le16_to_cpu(resp->command)) {
58 case HostCmd_CMD_802_11_PS_MODE_ENH:
Marc Yang2b06bdb2011-03-30 18:12:44 -070059 pm = &resp->params.psmode_enh;
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -070060 dev_err(adapter->dev,
61 "PS_MODE_ENH cmd failed: result=0x%x action=0x%X\n",
62 resp->result, le16_to_cpu(pm->action));
Marc Yang2b06bdb2011-03-30 18:12:44 -070063 /* We do not re-try enter-ps command in ad-hoc mode. */
64 if (le16_to_cpu(pm->action) == EN_AUTO_PS &&
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -070065 (le16_to_cpu(pm->params.ps_bitmap) & BITMAP_STA_PS) &&
66 priv->bss_mode == NL80211_IFTYPE_ADHOC)
Marc Yang2b06bdb2011-03-30 18:12:44 -070067 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
68
Bing Zhao5e6e3a92011-03-21 18:00:50 -070069 break;
70 case HostCmd_CMD_802_11_SCAN:
71 /* Cancel all pending scan command */
72 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
73 list_for_each_entry_safe(cmd_node, tmp_node,
74 &adapter->scan_pending_q, list) {
75 list_del(&cmd_node->list);
76 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
77 flags);
78 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
79 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
80 }
81 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
82
83 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
84 adapter->scan_processing = false;
85 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
86 if (priv->report_scan_result)
87 priv->report_scan_result = false;
88 if (priv->scan_pending_on_block) {
89 priv->scan_pending_on_block = false;
90 up(&priv->async_sem);
91 }
92 break;
93
94 case HostCmd_CMD_MAC_CONTROL:
95 break;
96
97 default:
98 break;
99 }
100 /* Handling errors here */
101 mwifiex_insert_cmd_to_free_q(adapter, adapter->curr_cmd);
102
103 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
104 adapter->curr_cmd = NULL;
105 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700106}
107
108/*
109 * This function handles the command response of get RSSI info.
110 *
111 * Handling includes changing the header fields into CPU format
112 * and saving the following parameters in driver -
113 * - Last data and beacon RSSI value
114 * - Average data and beacon RSSI value
115 * - Last data and beacon NF value
116 * - Average data and beacon NF value
117 *
118 * The parameters are send to the application as well, along with
119 * calculated SNR values.
120 */
121static int mwifiex_ret_802_11_rssi_info(struct mwifiex_private *priv,
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700122 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700123{
124 struct host_cmd_ds_802_11_rssi_info_rsp *rssi_info_rsp =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700125 &resp->params.rssi_info_rsp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700126
127 priv->data_rssi_last = le16_to_cpu(rssi_info_rsp->data_rssi_last);
128 priv->data_nf_last = le16_to_cpu(rssi_info_rsp->data_nf_last);
129
130 priv->data_rssi_avg = le16_to_cpu(rssi_info_rsp->data_rssi_avg);
131 priv->data_nf_avg = le16_to_cpu(rssi_info_rsp->data_nf_avg);
132
133 priv->bcn_rssi_last = le16_to_cpu(rssi_info_rsp->bcn_rssi_last);
134 priv->bcn_nf_last = le16_to_cpu(rssi_info_rsp->bcn_nf_last);
135
136 priv->bcn_rssi_avg = le16_to_cpu(rssi_info_rsp->bcn_rssi_avg);
137 priv->bcn_nf_avg = le16_to_cpu(rssi_info_rsp->bcn_nf_avg);
138
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700139 return 0;
140}
141
142/*
143 * This function handles the command response of set/get SNMP
144 * MIB parameters.
145 *
146 * Handling includes changing the header fields into CPU format
147 * and saving the parameter in driver.
148 *
149 * The following parameters are supported -
150 * - Fragmentation threshold
151 * - RTS threshold
152 * - Short retry limit
153 */
154static int mwifiex_ret_802_11_snmp_mib(struct mwifiex_private *priv,
155 struct host_cmd_ds_command *resp,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300156 u32 *data_buf)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700157{
158 struct host_cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
159 u16 oid = le16_to_cpu(smib->oid);
160 u16 query_type = le16_to_cpu(smib->query_type);
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300161 u32 ul_temp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700162
163 dev_dbg(priv->adapter->dev, "info: SNMP_RESP: oid value = %#x,"
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700164 " query_type = %#x, buf size = %#x\n",
165 oid, query_type, le16_to_cpu(smib->buf_size));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700166 if (query_type == HostCmd_ACT_GEN_GET) {
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300167 ul_temp = le16_to_cpu(*((__le16 *) (smib->value)));
168 if (data_buf)
169 *data_buf = ul_temp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700170 switch (oid) {
171 case FRAG_THRESH_I:
172 dev_dbg(priv->adapter->dev,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300173 "info: SNMP_RESP: FragThsd =%u\n", ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700174 break;
175 case RTS_THRESH_I:
176 dev_dbg(priv->adapter->dev,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300177 "info: SNMP_RESP: RTSThsd =%u\n", ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700178 break;
179 case SHORT_RETRY_LIM_I:
180 dev_dbg(priv->adapter->dev,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300181 "info: SNMP_RESP: TxRetryCount=%u\n", ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700182 break;
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800183 case DTIM_PERIOD_I:
184 dev_dbg(priv->adapter->dev,
185 "info: SNMP_RESP: DTIM period=%u\n", ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700186 default:
187 break;
188 }
189 }
190
191 return 0;
192}
193
194/*
195 * This function handles the command response of get log request
196 *
197 * Handling includes changing the header fields into CPU format
198 * and sending the received parameters to application.
199 */
200static int mwifiex_ret_get_log(struct mwifiex_private *priv,
201 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700202 struct mwifiex_ds_get_stats *stats)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700203{
204 struct host_cmd_ds_802_11_get_log *get_log =
205 (struct host_cmd_ds_802_11_get_log *) &resp->params.get_log;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700206
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700207 if (stats) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700208 stats->mcast_tx_frame = le32_to_cpu(get_log->mcast_tx_frame);
209 stats->failed = le32_to_cpu(get_log->failed);
210 stats->retry = le32_to_cpu(get_log->retry);
211 stats->multi_retry = le32_to_cpu(get_log->multi_retry);
212 stats->frame_dup = le32_to_cpu(get_log->frame_dup);
213 stats->rts_success = le32_to_cpu(get_log->rts_success);
214 stats->rts_failure = le32_to_cpu(get_log->rts_failure);
215 stats->ack_failure = le32_to_cpu(get_log->ack_failure);
216 stats->rx_frag = le32_to_cpu(get_log->rx_frag);
217 stats->mcast_rx_frame = le32_to_cpu(get_log->mcast_rx_frame);
218 stats->fcs_error = le32_to_cpu(get_log->fcs_error);
219 stats->tx_frame = le32_to_cpu(get_log->tx_frame);
220 stats->wep_icv_error[0] =
221 le32_to_cpu(get_log->wep_icv_err_cnt[0]);
222 stats->wep_icv_error[1] =
223 le32_to_cpu(get_log->wep_icv_err_cnt[1]);
224 stats->wep_icv_error[2] =
225 le32_to_cpu(get_log->wep_icv_err_cnt[2]);
226 stats->wep_icv_error[3] =
227 le32_to_cpu(get_log->wep_icv_err_cnt[3]);
228 }
229
230 return 0;
231}
232
233/*
234 * This function handles the command response of set/get Tx rate
235 * configurations.
236 *
237 * Handling includes changing the header fields into CPU format
238 * and saving the following parameters in driver -
239 * - DSSS rate bitmap
240 * - OFDM rate bitmap
241 * - HT MCS rate bitmaps
242 *
243 * Based on the new rate bitmaps, the function re-evaluates if
244 * auto data rate has been activated. If not, it sends another
245 * query to the firmware to get the current Tx data rate and updates
246 * the driver value.
247 */
248static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
249 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700250 struct mwifiex_rate_cfg *ds_rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700251{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700252 struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
253 struct mwifiex_rate_scope *rate_scope;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700254 struct mwifiex_ie_types_header *head;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700255 u16 tlv, tlv_buf_len;
256 u8 *tlv_buf;
257 u32 i;
258 int ret = 0;
259
260 tlv_buf = (u8 *) ((u8 *) rate_cfg) +
261 sizeof(struct host_cmd_ds_tx_rate_cfg);
262 tlv_buf_len = *(u16 *) (tlv_buf + sizeof(u16));
263
264 while (tlv_buf && tlv_buf_len > 0) {
265 tlv = (*tlv_buf);
266 tlv = tlv | (*(tlv_buf + 1) << 8);
267
268 switch (tlv) {
269 case TLV_TYPE_RATE_SCOPE:
270 rate_scope = (struct mwifiex_rate_scope *) tlv_buf;
271 priv->bitmap_rates[0] =
272 le16_to_cpu(rate_scope->hr_dsss_rate_bitmap);
273 priv->bitmap_rates[1] =
274 le16_to_cpu(rate_scope->ofdm_rate_bitmap);
275 for (i = 0;
276 i <
277 sizeof(rate_scope->ht_mcs_rate_bitmap) /
278 sizeof(u16); i++)
279 priv->bitmap_rates[2 + i] =
280 le16_to_cpu(rate_scope->
281 ht_mcs_rate_bitmap[i]);
282 break;
283 /* Add RATE_DROP tlv here */
284 }
285
286 head = (struct mwifiex_ie_types_header *) tlv_buf;
287 tlv_buf += le16_to_cpu(head->len) + sizeof(*head);
288 tlv_buf_len -= le16_to_cpu(head->len);
289 }
290
291 priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
292
293 if (priv->is_data_rate_auto)
294 priv->data_rate = 0;
295 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700296 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700297 HostCmd_CMD_802_11_TX_RATE_QUERY,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700298 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700299
Yogesh Ashok Powarbb7de2b2012-03-12 19:35:12 -0700300 if (!ds_rate)
301 return ret;
302
303 if (le16_to_cpu(rate_cfg->action) == HostCmd_ACT_GEN_GET) {
304 if (priv->is_data_rate_auto) {
305 ds_rate->is_rate_auto = 1;
306 return ret;
307 }
308 ds_rate->rate = mwifiex_get_rate_index(priv->bitmap_rates,
309 sizeof(priv->bitmap_rates));
310
311 if (ds_rate->rate >= MWIFIEX_RATE_BITMAP_OFDM0 &&
312 ds_rate->rate <= MWIFIEX_RATE_BITMAP_OFDM7)
313 ds_rate->rate -= (MWIFIEX_RATE_BITMAP_OFDM0 -
314 MWIFIEX_RATE_INDEX_OFDM0);
315
316 if (ds_rate->rate >= MWIFIEX_RATE_BITMAP_MCS0 &&
317 ds_rate->rate <= MWIFIEX_RATE_BITMAP_MCS127)
318 ds_rate->rate -= (MWIFIEX_RATE_BITMAP_MCS0 -
319 MWIFIEX_RATE_INDEX_MCS0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700320 }
321
322 return ret;
323}
324
325/*
326 * This function handles the command response of get Tx power level.
327 *
328 * Handling includes saving the maximum and minimum Tx power levels
329 * in driver, as well as sending the values to user.
330 */
331static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
332{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700333 int length, max_power = -1, min_power = -1;
334 struct mwifiex_types_power_group *pg_tlv_hdr;
335 struct mwifiex_power_group *pg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700336
Yogesh Ashok Powarbb7de2b2012-03-12 19:35:12 -0700337 if (!data_buf)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700338 return -1;
Yogesh Ashok Powarbb7de2b2012-03-12 19:35:12 -0700339
340 pg_tlv_hdr = (struct mwifiex_types_power_group *)
341 ((u8 *) data_buf + sizeof(struct host_cmd_ds_txpwr_cfg));
342 pg = (struct mwifiex_power_group *)
343 ((u8 *) pg_tlv_hdr + sizeof(struct mwifiex_types_power_group));
344 length = pg_tlv_hdr->length;
345 if (length > 0) {
346 max_power = pg->power_max;
347 min_power = pg->power_min;
348 length -= sizeof(struct mwifiex_power_group);
349 }
350 while (length) {
351 pg++;
352 if (max_power < pg->power_max)
353 max_power = pg->power_max;
354
355 if (min_power > pg->power_min)
356 min_power = pg->power_min;
357
358 length -= sizeof(struct mwifiex_power_group);
359 }
360 if (pg_tlv_hdr->length > 0) {
361 priv->min_tx_power_level = (u8) min_power;
362 priv->max_tx_power_level = (u8) max_power;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700363 }
364
365 return 0;
366}
367
368/*
369 * This function handles the command response of set/get Tx power
370 * configurations.
371 *
372 * Handling includes changing the header fields into CPU format
373 * and saving the current Tx power level in driver.
374 */
375static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700376 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700377{
378 struct mwifiex_adapter *adapter = priv->adapter;
379 struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700380 struct mwifiex_types_power_group *pg_tlv_hdr;
381 struct mwifiex_power_group *pg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700382 u16 action = le16_to_cpu(txp_cfg->action);
383
384 switch (action) {
385 case HostCmd_ACT_GEN_GET:
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700386 pg_tlv_hdr = (struct mwifiex_types_power_group *)
387 ((u8 *) txp_cfg +
388 sizeof(struct host_cmd_ds_txpwr_cfg));
389
390 pg = (struct mwifiex_power_group *)
391 ((u8 *) pg_tlv_hdr +
392 sizeof(struct mwifiex_types_power_group));
393
394 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
395 mwifiex_get_power_level(priv, txp_cfg);
396
397 priv->tx_power_level = (u16) pg->power_min;
398 break;
399
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700400 case HostCmd_ACT_GEN_SET:
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700401 if (!le32_to_cpu(txp_cfg->mode))
402 break;
403
404 pg_tlv_hdr = (struct mwifiex_types_power_group *)
405 ((u8 *) txp_cfg +
406 sizeof(struct host_cmd_ds_txpwr_cfg));
407
408 pg = (struct mwifiex_power_group *)
409 ((u8 *) pg_tlv_hdr +
410 sizeof(struct mwifiex_types_power_group));
411
412 if (pg->power_max == pg->power_min)
413 priv->tx_power_level = (u16) pg->power_min;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700414 break;
415 default:
416 dev_err(adapter->dev, "CMD_RESP: unknown cmd action %d\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700417 action);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700418 return 0;
419 }
420 dev_dbg(adapter->dev,
421 "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
422 priv->tx_power_level, priv->max_tx_power_level,
423 priv->min_tx_power_level);
424
425 return 0;
426}
427
428/*
429 * This function handles the command response of set/get MAC address.
430 *
431 * Handling includes saving the MAC address in driver.
432 */
433static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
434 struct host_cmd_ds_command *resp)
435{
436 struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700437 &resp->params.mac_addr;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700438
439 memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
440
441 dev_dbg(priv->adapter->dev,
442 "info: set mac address: %pM\n", priv->curr_addr);
443
444 return 0;
445}
446
447/*
448 * This function handles the command response of set/get MAC multicast
449 * address.
450 */
451static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
452 struct host_cmd_ds_command *resp)
453{
454 return 0;
455}
456
457/*
458 * This function handles the command response of get Tx rate query.
459 *
460 * Handling includes changing the header fields into CPU format
461 * and saving the Tx rate and HT information parameters in driver.
462 *
463 * Both rate configuration and current data rate can be retrieved
464 * with this request.
465 */
466static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
467 struct host_cmd_ds_command *resp)
468{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700469 priv->tx_rate = resp->params.tx_rate.tx_rate;
470 priv->tx_htinfo = resp->params.tx_rate.ht_info;
471 if (!priv->is_data_rate_auto)
472 priv->data_rate =
Bing Zhaoe3bea1c2011-11-16 20:40:35 -0800473 mwifiex_index_to_data_rate(priv, priv->tx_rate,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700474 priv->tx_htinfo);
475
476 return 0;
477}
478
479/*
480 * This function handles the command response of a deauthenticate
481 * command.
482 *
483 * If the deauthenticated MAC matches the current BSS MAC, the connection
484 * state is reset.
485 */
486static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
487 struct host_cmd_ds_command *resp)
488{
489 struct mwifiex_adapter *adapter = priv->adapter;
490
491 adapter->dbg.num_cmd_deauth++;
492 if (!memcmp(resp->params.deauth.mac_addr,
493 &priv->curr_bss_params.bss_descriptor.mac_address,
494 sizeof(resp->params.deauth.mac_addr)))
495 mwifiex_reset_connect_state(priv);
496
497 return 0;
498}
499
500/*
501 * This function handles the command response of ad-hoc stop.
502 *
503 * The function resets the connection state in driver.
504 */
505static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
506 struct host_cmd_ds_command *resp)
507{
508 mwifiex_reset_connect_state(priv);
509 return 0;
510}
511
512/*
513 * This function handles the command response of set/get key material.
514 *
515 * Handling includes updating the driver parameters to reflect the
516 * changes.
517 */
518static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
519 struct host_cmd_ds_command *resp)
520{
521 struct host_cmd_ds_802_11_key_material *key =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700522 &resp->params.key_material;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700523
524 if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700525 if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700526 dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
527 priv->wpa_is_gtk_set = true;
528 priv->scan_block = false;
529 }
530 }
531
532 memset(priv->aes_key.key_param_set.key, 0,
533 sizeof(key->key_param_set.key));
534 priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
535 memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
536 le16_to_cpu(priv->aes_key.key_param_set.key_len));
537
538 return 0;
539}
540
541/*
542 * This function handles the command response of get 11d domain information.
543 */
544static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
545 struct host_cmd_ds_command *resp)
546{
547 struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
548 &resp->params.domain_info_resp;
549 struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
550 u16 action = le16_to_cpu(domain_info->action);
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700551 u8 no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700552
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700553 no_of_triplet = (u8) ((le16_to_cpu(domain->header.len)
554 - IEEE80211_COUNTRY_STRING_LEN)
555 / sizeof(struct ieee80211_country_ie_triplet));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700556
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700557 dev_dbg(priv->adapter->dev,
558 "info: 11D Domain Info Resp: no_of_triplet=%d\n",
559 no_of_triplet);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700560
561 if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
562 dev_warn(priv->adapter->dev,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700563 "11D: invalid number of triplets %d returned\n",
564 no_of_triplet);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700565 return -1;
566 }
567
568 switch (action) {
569 case HostCmd_ACT_GEN_SET: /* Proc Set Action */
570 break;
571 case HostCmd_ACT_GEN_GET:
572 break;
573 default:
574 dev_err(priv->adapter->dev,
575 "11D: invalid action:%d\n", domain_info->action);
576 return -1;
577 }
578
579 return 0;
580}
581
582/*
583 * This function handles the command response of get RF channel.
584 *
585 * Handling includes changing the header fields into CPU format
586 * and saving the new channel in driver.
587 */
588static int mwifiex_ret_802_11_rf_channel(struct mwifiex_private *priv,
589 struct host_cmd_ds_command *resp,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300590 u16 *data_buf)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700591{
592 struct host_cmd_ds_802_11_rf_channel *rf_channel =
593 &resp->params.rf_channel;
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300594 u16 new_channel = le16_to_cpu(rf_channel->current_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700595
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300596 if (priv->curr_bss_params.bss_descriptor.channel != new_channel) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700597 dev_dbg(priv->adapter->dev, "cmd: Channel Switch: %d to %d\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700598 priv->curr_bss_params.bss_descriptor.channel,
599 new_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700600 /* Update the channel again */
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300601 priv->curr_bss_params.bss_descriptor.channel = new_channel;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700602 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700603
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300604 if (data_buf)
605 *data_buf = new_channel;
606
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700607 return 0;
608}
609
610/*
611 * This function handles the command response of get extended version.
612 *
613 * Handling includes forming the extended version string and sending it
614 * to application.
615 */
616static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
617 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700618 struct host_cmd_ds_version_ext *version_ext)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700619{
620 struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700622 if (version_ext) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700623 version_ext->version_str_sel = ver_ext->version_str_sel;
624 memcpy(version_ext->version_str, ver_ext->version_str,
625 sizeof(char) * 128);
626 memcpy(priv->version_str, ver_ext->version_str, 128);
627 }
628 return 0;
629}
630
631/*
632 * This function handles the command response of register access.
633 *
634 * The register value and offset are returned to the user. For EEPROM
635 * access, the byte count is also returned.
636 */
637static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
638 void *data_buf)
639{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700640 struct mwifiex_ds_reg_rw *reg_rw;
641 struct mwifiex_ds_read_eeprom *eeprom;
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700642 union reg {
643 struct host_cmd_ds_mac_reg_access *mac;
644 struct host_cmd_ds_bbp_reg_access *bbp;
645 struct host_cmd_ds_rf_reg_access *rf;
646 struct host_cmd_ds_pmic_reg_access *pmic;
647 struct host_cmd_ds_802_11_eeprom_access *eeprom;
648 } r;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700649
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700650 if (!data_buf)
651 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700652
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700653 reg_rw = data_buf;
654 eeprom = data_buf;
655 switch (type) {
656 case HostCmd_CMD_MAC_REG_ACCESS:
657 r.mac = (struct host_cmd_ds_mac_reg_access *)
658 &resp->params.mac_reg;
659 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac->offset));
660 reg_rw->value = r.mac->value;
661 break;
662 case HostCmd_CMD_BBP_REG_ACCESS:
663 r.bbp = (struct host_cmd_ds_bbp_reg_access *)
664 &resp->params.bbp_reg;
665 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp->offset));
666 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
667 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700668
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700669 case HostCmd_CMD_RF_REG_ACCESS:
670 r.rf = (struct host_cmd_ds_rf_reg_access *)
671 &resp->params.rf_reg;
672 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
673 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
674 break;
675 case HostCmd_CMD_PMIC_REG_ACCESS:
676 r.pmic = (struct host_cmd_ds_pmic_reg_access *)
677 &resp->params.pmic_reg;
678 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic->offset));
679 reg_rw->value = cpu_to_le32((u32) r.pmic->value);
680 break;
681 case HostCmd_CMD_CAU_REG_ACCESS:
682 r.rf = (struct host_cmd_ds_rf_reg_access *)
683 &resp->params.rf_reg;
684 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
685 reg_rw->value = cpu_to_le32((u32) r.rf->value);
686 break;
687 case HostCmd_CMD_802_11_EEPROM_ACCESS:
688 r.eeprom = (struct host_cmd_ds_802_11_eeprom_access *)
689 &resp->params.eeprom;
690 pr_debug("info: EEPROM read len=%x\n", r.eeprom->byte_count);
691 if (le16_to_cpu(eeprom->byte_count) <
692 le16_to_cpu(r.eeprom->byte_count)) {
693 eeprom->byte_count = cpu_to_le16(0);
694 pr_debug("info: EEPROM read length is too big\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700695 return -1;
696 }
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700697 eeprom->offset = r.eeprom->offset;
698 eeprom->byte_count = r.eeprom->byte_count;
699 if (le16_to_cpu(eeprom->byte_count) > 0)
700 memcpy(&eeprom->value, &r.eeprom->value,
701 le16_to_cpu(r.eeprom->byte_count));
702
703 break;
704 default:
705 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700706 }
707 return 0;
708}
709
710/*
711 * This function handles the command response of get IBSS coalescing status.
712 *
713 * If the received BSSID is different than the current one, the current BSSID,
714 * beacon interval, ATIM window and ERP information are updated, along with
715 * changing the ad-hoc state accordingly.
716 */
717static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
718 struct host_cmd_ds_command *resp)
719{
720 struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700721 &(resp->params.ibss_coalescing);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700722 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
723
724 if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
725 return 0;
726
727 dev_dbg(priv->adapter->dev,
728 "info: new BSSID %pM\n", ibss_coal_resp->bssid);
729
730 /* If rsp has NULL BSSID, Just return..... No Action */
731 if (!memcmp(ibss_coal_resp->bssid, zero_mac, ETH_ALEN)) {
732 dev_warn(priv->adapter->dev, "new BSSID is NULL\n");
733 return 0;
734 }
735
736 /* If BSSID is diff, modify current BSS parameters */
737 if (memcmp(priv->curr_bss_params.bss_descriptor.mac_address,
738 ibss_coal_resp->bssid, ETH_ALEN)) {
739 /* BSSID */
740 memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
741 ibss_coal_resp->bssid, ETH_ALEN);
742
743 /* Beacon Interval */
744 priv->curr_bss_params.bss_descriptor.beacon_period
745 = le16_to_cpu(ibss_coal_resp->beacon_interval);
746
747 /* ERP Information */
748 priv->curr_bss_params.bss_descriptor.erp_flags =
749 (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
750
751 priv->adhoc_state = ADHOC_COALESCED;
752 }
753
754 return 0;
755}
756
757/*
758 * This function handles the command responses.
759 *
760 * This is a generic function, which calls command specific
761 * response handlers based on the command ID.
762 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700763int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
764 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700765{
766 int ret = 0;
767 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700768 void *data_buf = adapter->curr_cmd->data_buf;
769
770 /* If the command is not successful, cleanup and return failure */
771 if (resp->result != HostCmd_RESULT_OK) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700772 mwifiex_process_cmdresp_error(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700773 return -1;
774 }
775 /* Command successful, handle response */
776 switch (cmdresp_no) {
777 case HostCmd_CMD_GET_HW_SPEC:
778 ret = mwifiex_ret_get_hw_spec(priv, resp);
779 break;
780 case HostCmd_CMD_MAC_CONTROL:
781 break;
782 case HostCmd_CMD_802_11_MAC_ADDRESS:
783 ret = mwifiex_ret_802_11_mac_address(priv, resp);
784 break;
785 case HostCmd_CMD_MAC_MULTICAST_ADR:
786 ret = mwifiex_ret_mac_multicast_adr(priv, resp);
787 break;
788 case HostCmd_CMD_TX_RATE_CFG:
789 ret = mwifiex_ret_tx_rate_cfg(priv, resp, data_buf);
790 break;
791 case HostCmd_CMD_802_11_SCAN:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700792 ret = mwifiex_ret_802_11_scan(priv, resp);
793 adapter->curr_cmd->wait_q_enabled = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700794 break;
795 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700796 ret = mwifiex_ret_802_11_scan(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700797 dev_dbg(adapter->dev,
798 "info: CMD_RESP: BG_SCAN result is ready!\n");
799 break;
800 case HostCmd_CMD_TXPWR_CFG:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700801 ret = mwifiex_ret_tx_power_cfg(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700802 break;
803 case HostCmd_CMD_802_11_PS_MODE_ENH:
804 ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
805 break;
806 case HostCmd_CMD_802_11_HS_CFG_ENH:
807 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
808 break;
809 case HostCmd_CMD_802_11_ASSOCIATE:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700810 ret = mwifiex_ret_802_11_associate(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700811 break;
812 case HostCmd_CMD_802_11_DEAUTHENTICATE:
813 ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
814 break;
815 case HostCmd_CMD_802_11_AD_HOC_START:
816 case HostCmd_CMD_802_11_AD_HOC_JOIN:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700817 ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700818 break;
819 case HostCmd_CMD_802_11_AD_HOC_STOP:
820 ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
821 break;
822 case HostCmd_CMD_802_11_GET_LOG:
823 ret = mwifiex_ret_get_log(priv, resp, data_buf);
824 break;
825 case HostCmd_CMD_RSSI_INFO:
Amitkumar Karwar958a4a82012-03-15 20:51:49 -0700826 ret = mwifiex_ret_802_11_rssi_info(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700827 break;
828 case HostCmd_CMD_802_11_SNMP_MIB:
829 ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
830 break;
831 case HostCmd_CMD_802_11_TX_RATE_QUERY:
832 ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
833 break;
834 case HostCmd_CMD_802_11_RF_CHANNEL:
835 ret = mwifiex_ret_802_11_rf_channel(priv, resp, data_buf);
836 break;
837 case HostCmd_CMD_VERSION_EXT:
838 ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
839 break;
840 case HostCmd_CMD_FUNC_INIT:
841 case HostCmd_CMD_FUNC_SHUTDOWN:
842 break;
843 case HostCmd_CMD_802_11_KEY_MATERIAL:
844 ret = mwifiex_ret_802_11_key_material(priv, resp);
845 break;
846 case HostCmd_CMD_802_11D_DOMAIN_INFO:
847 ret = mwifiex_ret_802_11d_domain_info(priv, resp);
848 break;
849 case HostCmd_CMD_11N_ADDBA_REQ:
850 ret = mwifiex_ret_11n_addba_req(priv, resp);
851 break;
852 case HostCmd_CMD_11N_DELBA:
853 ret = mwifiex_ret_11n_delba(priv, resp);
854 break;
855 case HostCmd_CMD_11N_ADDBA_RSP:
856 ret = mwifiex_ret_11n_addba_resp(priv, resp);
857 break;
858 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
859 adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
860 tx_buf.buff_size);
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700861 adapter->tx_buf_size = (adapter->tx_buf_size
862 / MWIFIEX_SDIO_BLOCK_SIZE)
863 * MWIFIEX_SDIO_BLOCK_SIZE;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700864 adapter->curr_tx_buf_size = adapter->tx_buf_size;
865 dev_dbg(adapter->dev,
866 "cmd: max_tx_buf_size=%d, tx_buf_size=%d\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700867 adapter->max_tx_buf_size, adapter->tx_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700868
869 if (adapter->if_ops.update_mp_end_port)
870 adapter->if_ops.update_mp_end_port(adapter,
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700871 le16_to_cpu(resp->params.tx_buf.mp_end_port));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700872 break;
873 case HostCmd_CMD_AMSDU_AGGR_CTRL:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700874 ret = mwifiex_ret_amsdu_aggr_ctrl(resp, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700875 break;
876 case HostCmd_CMD_WMM_GET_STATUS:
877 ret = mwifiex_ret_wmm_get_status(priv, resp);
878 break;
879 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
880 ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
881 break;
882 case HostCmd_CMD_MAC_REG_ACCESS:
883 case HostCmd_CMD_BBP_REG_ACCESS:
884 case HostCmd_CMD_RF_REG_ACCESS:
885 case HostCmd_CMD_PMIC_REG_ACCESS:
886 case HostCmd_CMD_CAU_REG_ACCESS:
887 case HostCmd_CMD_802_11_EEPROM_ACCESS:
888 ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
889 break;
890 case HostCmd_CMD_SET_BSS_MODE:
891 break;
892 case HostCmd_CMD_11N_CFG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700893 ret = mwifiex_ret_11n_cfg(resp, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700894 break;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700895 case HostCmd_CMD_PCIE_DESC_DETAILS:
896 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700897 default:
898 dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
Yogesh Ashok Powar9c05fd72012-03-13 19:22:40 -0700899 resp->command);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700900 break;
901 }
902
903 return ret;
904}