blob: 0d8618a8443fb8bf007b8db85be3367ffde57aa6 [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",
52 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;
60 dev_err(adapter->dev, "PS_MODE_ENH cmd failed: "
61 "result=0x%x action=0x%X\n",
Bing Zhao5e6e3a92011-03-21 18:00:50 -070062 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 &&
65 (le16_to_cpu(pm->params.ps_bitmap) & BITMAP_STA_PS) &&
66 priv->bss_mode == NL80211_IFTYPE_ADHOC)
67 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,
122 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700123 struct mwifiex_ds_get_signal *signal)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700124{
125 struct host_cmd_ds_802_11_rssi_info_rsp *rssi_info_rsp =
126 &resp->params.rssi_info_rsp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700127
128 priv->data_rssi_last = le16_to_cpu(rssi_info_rsp->data_rssi_last);
129 priv->data_nf_last = le16_to_cpu(rssi_info_rsp->data_nf_last);
130
131 priv->data_rssi_avg = le16_to_cpu(rssi_info_rsp->data_rssi_avg);
132 priv->data_nf_avg = le16_to_cpu(rssi_info_rsp->data_nf_avg);
133
134 priv->bcn_rssi_last = le16_to_cpu(rssi_info_rsp->bcn_rssi_last);
135 priv->bcn_nf_last = le16_to_cpu(rssi_info_rsp->bcn_nf_last);
136
137 priv->bcn_rssi_avg = le16_to_cpu(rssi_info_rsp->bcn_rssi_avg);
138 priv->bcn_nf_avg = le16_to_cpu(rssi_info_rsp->bcn_nf_avg);
139
140 /* Need to indicate IOCTL complete */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700141 if (signal) {
142 memset(signal, 0, sizeof(*signal));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700143
144 signal->selector = ALL_RSSI_INFO_MASK;
145
146 /* RSSI */
147 signal->bcn_rssi_last = priv->bcn_rssi_last;
148 signal->bcn_rssi_avg = priv->bcn_rssi_avg;
149 signal->data_rssi_last = priv->data_rssi_last;
150 signal->data_rssi_avg = priv->data_rssi_avg;
151
152 /* SNR */
153 signal->bcn_snr_last =
154 CAL_SNR(priv->bcn_rssi_last, priv->bcn_nf_last);
155 signal->bcn_snr_avg =
156 CAL_SNR(priv->bcn_rssi_avg, priv->bcn_nf_avg);
157 signal->data_snr_last =
158 CAL_SNR(priv->data_rssi_last, priv->data_nf_last);
159 signal->data_snr_avg =
160 CAL_SNR(priv->data_rssi_avg, priv->data_nf_avg);
161
162 /* NF */
163 signal->bcn_nf_last = priv->bcn_nf_last;
164 signal->bcn_nf_avg = priv->bcn_nf_avg;
165 signal->data_nf_last = priv->data_nf_last;
166 signal->data_nf_avg = priv->data_nf_avg;
167 }
168
169 return 0;
170}
171
172/*
173 * This function handles the command response of set/get SNMP
174 * MIB parameters.
175 *
176 * Handling includes changing the header fields into CPU format
177 * and saving the parameter in driver.
178 *
179 * The following parameters are supported -
180 * - Fragmentation threshold
181 * - RTS threshold
182 * - Short retry limit
183 */
184static int mwifiex_ret_802_11_snmp_mib(struct mwifiex_private *priv,
185 struct host_cmd_ds_command *resp,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300186 u32 *data_buf)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700187{
188 struct host_cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
189 u16 oid = le16_to_cpu(smib->oid);
190 u16 query_type = le16_to_cpu(smib->query_type);
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300191 u32 ul_temp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700192
193 dev_dbg(priv->adapter->dev, "info: SNMP_RESP: oid value = %#x,"
194 " query_type = %#x, buf size = %#x\n",
195 oid, query_type, le16_to_cpu(smib->buf_size));
196 if (query_type == HostCmd_ACT_GEN_GET) {
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300197 ul_temp = le16_to_cpu(*((__le16 *) (smib->value)));
198 if (data_buf)
199 *data_buf = ul_temp;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700200 switch (oid) {
201 case FRAG_THRESH_I:
202 dev_dbg(priv->adapter->dev,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300203 "info: SNMP_RESP: FragThsd =%u\n", ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700204 break;
205 case RTS_THRESH_I:
206 dev_dbg(priv->adapter->dev,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300207 "info: SNMP_RESP: RTSThsd =%u\n", ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700208 break;
209 case SHORT_RETRY_LIM_I:
210 dev_dbg(priv->adapter->dev,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300211 "info: SNMP_RESP: TxRetryCount=%u\n", ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700212 break;
Amitkumar Karwarcaf60a62012-02-02 20:48:58 -0800213 case DTIM_PERIOD_I:
214 dev_dbg(priv->adapter->dev,
215 "info: SNMP_RESP: DTIM period=%u\n", ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700216 default:
217 break;
218 }
219 }
220
221 return 0;
222}
223
224/*
225 * This function handles the command response of get log request
226 *
227 * Handling includes changing the header fields into CPU format
228 * and sending the received parameters to application.
229 */
230static int mwifiex_ret_get_log(struct mwifiex_private *priv,
231 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700232 struct mwifiex_ds_get_stats *stats)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700233{
234 struct host_cmd_ds_802_11_get_log *get_log =
235 (struct host_cmd_ds_802_11_get_log *) &resp->params.get_log;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700236
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700237 if (stats) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700238 stats->mcast_tx_frame = le32_to_cpu(get_log->mcast_tx_frame);
239 stats->failed = le32_to_cpu(get_log->failed);
240 stats->retry = le32_to_cpu(get_log->retry);
241 stats->multi_retry = le32_to_cpu(get_log->multi_retry);
242 stats->frame_dup = le32_to_cpu(get_log->frame_dup);
243 stats->rts_success = le32_to_cpu(get_log->rts_success);
244 stats->rts_failure = le32_to_cpu(get_log->rts_failure);
245 stats->ack_failure = le32_to_cpu(get_log->ack_failure);
246 stats->rx_frag = le32_to_cpu(get_log->rx_frag);
247 stats->mcast_rx_frame = le32_to_cpu(get_log->mcast_rx_frame);
248 stats->fcs_error = le32_to_cpu(get_log->fcs_error);
249 stats->tx_frame = le32_to_cpu(get_log->tx_frame);
250 stats->wep_icv_error[0] =
251 le32_to_cpu(get_log->wep_icv_err_cnt[0]);
252 stats->wep_icv_error[1] =
253 le32_to_cpu(get_log->wep_icv_err_cnt[1]);
254 stats->wep_icv_error[2] =
255 le32_to_cpu(get_log->wep_icv_err_cnt[2]);
256 stats->wep_icv_error[3] =
257 le32_to_cpu(get_log->wep_icv_err_cnt[3]);
258 }
259
260 return 0;
261}
262
263/*
264 * This function handles the command response of set/get Tx rate
265 * configurations.
266 *
267 * Handling includes changing the header fields into CPU format
268 * and saving the following parameters in driver -
269 * - DSSS rate bitmap
270 * - OFDM rate bitmap
271 * - HT MCS rate bitmaps
272 *
273 * Based on the new rate bitmaps, the function re-evaluates if
274 * auto data rate has been activated. If not, it sends another
275 * query to the firmware to get the current Tx data rate and updates
276 * the driver value.
277 */
278static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
279 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700280 struct mwifiex_rate_cfg *ds_rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700281{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700282 struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
283 struct mwifiex_rate_scope *rate_scope;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700284 struct mwifiex_ie_types_header *head;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700285 u16 tlv, tlv_buf_len;
286 u8 *tlv_buf;
287 u32 i;
288 int ret = 0;
289
290 tlv_buf = (u8 *) ((u8 *) rate_cfg) +
291 sizeof(struct host_cmd_ds_tx_rate_cfg);
292 tlv_buf_len = *(u16 *) (tlv_buf + sizeof(u16));
293
294 while (tlv_buf && tlv_buf_len > 0) {
295 tlv = (*tlv_buf);
296 tlv = tlv | (*(tlv_buf + 1) << 8);
297
298 switch (tlv) {
299 case TLV_TYPE_RATE_SCOPE:
300 rate_scope = (struct mwifiex_rate_scope *) tlv_buf;
301 priv->bitmap_rates[0] =
302 le16_to_cpu(rate_scope->hr_dsss_rate_bitmap);
303 priv->bitmap_rates[1] =
304 le16_to_cpu(rate_scope->ofdm_rate_bitmap);
305 for (i = 0;
306 i <
307 sizeof(rate_scope->ht_mcs_rate_bitmap) /
308 sizeof(u16); i++)
309 priv->bitmap_rates[2 + i] =
310 le16_to_cpu(rate_scope->
311 ht_mcs_rate_bitmap[i]);
312 break;
313 /* Add RATE_DROP tlv here */
314 }
315
316 head = (struct mwifiex_ie_types_header *) tlv_buf;
317 tlv_buf += le16_to_cpu(head->len) + sizeof(*head);
318 tlv_buf_len -= le16_to_cpu(head->len);
319 }
320
321 priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
322
323 if (priv->is_data_rate_auto)
324 priv->data_rate = 0;
325 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700326 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700327 HostCmd_CMD_802_11_TX_RATE_QUERY,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700328 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700329
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700330 if (ds_rate) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331 if (le16_to_cpu(rate_cfg->action) == HostCmd_ACT_GEN_GET) {
332 if (priv->is_data_rate_auto) {
333 ds_rate->is_rate_auto = 1;
334 } else {
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700335 ds_rate->rate = mwifiex_get_rate_index(priv->
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700336 bitmap_rates,
337 sizeof(priv->
338 bitmap_rates));
339 if (ds_rate->rate >=
340 MWIFIEX_RATE_BITMAP_OFDM0
341 && ds_rate->rate <=
342 MWIFIEX_RATE_BITMAP_OFDM7)
343 ds_rate->rate -=
344 (MWIFIEX_RATE_BITMAP_OFDM0 -
345 MWIFIEX_RATE_INDEX_OFDM0);
346 if (ds_rate->rate >=
347 MWIFIEX_RATE_BITMAP_MCS0
348 && ds_rate->rate <=
349 MWIFIEX_RATE_BITMAP_MCS127)
350 ds_rate->rate -=
351 (MWIFIEX_RATE_BITMAP_MCS0 -
352 MWIFIEX_RATE_INDEX_MCS0);
353 }
354 }
355 }
356
357 return ret;
358}
359
360/*
361 * This function handles the command response of get Tx power level.
362 *
363 * Handling includes saving the maximum and minimum Tx power levels
364 * in driver, as well as sending the values to user.
365 */
366static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
367{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700368 int length, max_power = -1, min_power = -1;
369 struct mwifiex_types_power_group *pg_tlv_hdr;
370 struct mwifiex_power_group *pg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700371
372 if (data_buf) {
373 pg_tlv_hdr =
374 (struct mwifiex_types_power_group *) ((u8 *) data_buf
375 + sizeof(struct host_cmd_ds_txpwr_cfg));
376 pg = (struct mwifiex_power_group *) ((u8 *) pg_tlv_hdr +
377 sizeof(struct mwifiex_types_power_group));
378 length = pg_tlv_hdr->length;
379 if (length > 0) {
380 max_power = pg->power_max;
381 min_power = pg->power_min;
382 length -= sizeof(struct mwifiex_power_group);
383 }
384 while (length) {
385 pg++;
386 if (max_power < pg->power_max)
387 max_power = pg->power_max;
388
389 if (min_power > pg->power_min)
390 min_power = pg->power_min;
391
392 length -= sizeof(struct mwifiex_power_group);
393 }
394 if (pg_tlv_hdr->length > 0) {
395 priv->min_tx_power_level = (u8) min_power;
396 priv->max_tx_power_level = (u8) max_power;
397 }
398 } else {
399 return -1;
400 }
401
402 return 0;
403}
404
405/*
406 * This function handles the command response of set/get Tx power
407 * configurations.
408 *
409 * Handling includes changing the header fields into CPU format
410 * and saving the current Tx power level in driver.
411 */
412static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700413 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700414{
415 struct mwifiex_adapter *adapter = priv->adapter;
416 struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700417 struct mwifiex_types_power_group *pg_tlv_hdr;
418 struct mwifiex_power_group *pg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700419 u16 action = le16_to_cpu(txp_cfg->action);
420
421 switch (action) {
422 case HostCmd_ACT_GEN_GET:
423 {
424 pg_tlv_hdr =
425 (struct mwifiex_types_power_group *) ((u8 *)
426 txp_cfg +
427 sizeof
428 (struct
429 host_cmd_ds_txpwr_cfg));
430 pg = (struct mwifiex_power_group *) ((u8 *)
431 pg_tlv_hdr +
432 sizeof(struct
433 mwifiex_types_power_group));
434 if (adapter->hw_status ==
435 MWIFIEX_HW_STATUS_INITIALIZING)
436 mwifiex_get_power_level(priv, txp_cfg);
437 priv->tx_power_level = (u16) pg->power_min;
438 break;
439 }
440 case HostCmd_ACT_GEN_SET:
441 if (le32_to_cpu(txp_cfg->mode)) {
442 pg_tlv_hdr =
443 (struct mwifiex_types_power_group *) ((u8 *)
444 txp_cfg +
445 sizeof
446 (struct
447 host_cmd_ds_txpwr_cfg));
448 pg = (struct mwifiex_power_group *) ((u8 *) pg_tlv_hdr
449 +
450 sizeof(struct
451 mwifiex_types_power_group));
452 if (pg->power_max == pg->power_min)
453 priv->tx_power_level = (u16) pg->power_min;
454 }
455 break;
456 default:
457 dev_err(adapter->dev, "CMD_RESP: unknown cmd action %d\n",
458 action);
459 return 0;
460 }
461 dev_dbg(adapter->dev,
462 "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
463 priv->tx_power_level, priv->max_tx_power_level,
464 priv->min_tx_power_level);
465
466 return 0;
467}
468
469/*
470 * This function handles the command response of set/get MAC address.
471 *
472 * Handling includes saving the MAC address in driver.
473 */
474static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
475 struct host_cmd_ds_command *resp)
476{
477 struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
478 &resp->params.mac_addr;
479
480 memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
481
482 dev_dbg(priv->adapter->dev,
483 "info: set mac address: %pM\n", priv->curr_addr);
484
485 return 0;
486}
487
488/*
489 * This function handles the command response of set/get MAC multicast
490 * address.
491 */
492static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
493 struct host_cmd_ds_command *resp)
494{
495 return 0;
496}
497
498/*
499 * This function handles the command response of get Tx rate query.
500 *
501 * Handling includes changing the header fields into CPU format
502 * and saving the Tx rate and HT information parameters in driver.
503 *
504 * Both rate configuration and current data rate can be retrieved
505 * with this request.
506 */
507static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
508 struct host_cmd_ds_command *resp)
509{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510 priv->tx_rate = resp->params.tx_rate.tx_rate;
511 priv->tx_htinfo = resp->params.tx_rate.ht_info;
512 if (!priv->is_data_rate_auto)
513 priv->data_rate =
Bing Zhaoe3bea1c2011-11-16 20:40:35 -0800514 mwifiex_index_to_data_rate(priv, priv->tx_rate,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700515 priv->tx_htinfo);
516
517 return 0;
518}
519
520/*
521 * This function handles the command response of a deauthenticate
522 * command.
523 *
524 * If the deauthenticated MAC matches the current BSS MAC, the connection
525 * state is reset.
526 */
527static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
528 struct host_cmd_ds_command *resp)
529{
530 struct mwifiex_adapter *adapter = priv->adapter;
531
532 adapter->dbg.num_cmd_deauth++;
533 if (!memcmp(resp->params.deauth.mac_addr,
534 &priv->curr_bss_params.bss_descriptor.mac_address,
535 sizeof(resp->params.deauth.mac_addr)))
536 mwifiex_reset_connect_state(priv);
537
538 return 0;
539}
540
541/*
542 * This function handles the command response of ad-hoc stop.
543 *
544 * The function resets the connection state in driver.
545 */
546static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
547 struct host_cmd_ds_command *resp)
548{
549 mwifiex_reset_connect_state(priv);
550 return 0;
551}
552
553/*
554 * This function handles the command response of set/get key material.
555 *
556 * Handling includes updating the driver parameters to reflect the
557 * changes.
558 */
559static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
560 struct host_cmd_ds_command *resp)
561{
562 struct host_cmd_ds_802_11_key_material *key =
563 &resp->params.key_material;
564
565 if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700566 if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700567 dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
568 priv->wpa_is_gtk_set = true;
569 priv->scan_block = false;
570 }
571 }
572
573 memset(priv->aes_key.key_param_set.key, 0,
574 sizeof(key->key_param_set.key));
575 priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
576 memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
577 le16_to_cpu(priv->aes_key.key_param_set.key_len));
578
579 return 0;
580}
581
582/*
583 * This function handles the command response of get 11d domain information.
584 */
585static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
586 struct host_cmd_ds_command *resp)
587{
588 struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
589 &resp->params.domain_info_resp;
590 struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
591 u16 action = le16_to_cpu(domain_info->action);
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700592 u8 no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700593
594 no_of_triplet = (u8) ((le16_to_cpu(domain->header.len) -
595 IEEE80211_COUNTRY_STRING_LEN) /
596 sizeof(struct ieee80211_country_ie_triplet));
597
598 dev_dbg(priv->adapter->dev, "info: 11D Domain Info Resp:"
599 " no_of_triplet=%d\n", no_of_triplet);
600
601 if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
602 dev_warn(priv->adapter->dev,
603 "11D: invalid number of triplets %d "
604 "returned!!\n", no_of_triplet);
605 return -1;
606 }
607
608 switch (action) {
609 case HostCmd_ACT_GEN_SET: /* Proc Set Action */
610 break;
611 case HostCmd_ACT_GEN_GET:
612 break;
613 default:
614 dev_err(priv->adapter->dev,
615 "11D: invalid action:%d\n", domain_info->action);
616 return -1;
617 }
618
619 return 0;
620}
621
622/*
623 * This function handles the command response of get RF channel.
624 *
625 * Handling includes changing the header fields into CPU format
626 * and saving the new channel in driver.
627 */
628static int mwifiex_ret_802_11_rf_channel(struct mwifiex_private *priv,
629 struct host_cmd_ds_command *resp,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300630 u16 *data_buf)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700631{
632 struct host_cmd_ds_802_11_rf_channel *rf_channel =
633 &resp->params.rf_channel;
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300634 u16 new_channel = le16_to_cpu(rf_channel->current_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700635
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300636 if (priv->curr_bss_params.bss_descriptor.channel != new_channel) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700637 dev_dbg(priv->adapter->dev, "cmd: Channel Switch: %d to %d\n",
638 priv->curr_bss_params.bss_descriptor.channel,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300639 new_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700640 /* Update the channel again */
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300641 priv->curr_bss_params.bss_descriptor.channel = new_channel;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700642 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700643
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300644 if (data_buf)
645 *data_buf = new_channel;
646
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700647 return 0;
648}
649
650/*
651 * This function handles the command response of get extended version.
652 *
653 * Handling includes forming the extended version string and sending it
654 * to application.
655 */
656static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
657 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700658 struct host_cmd_ds_version_ext *version_ext)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700659{
660 struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700661
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700662 if (version_ext) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700663 version_ext->version_str_sel = ver_ext->version_str_sel;
664 memcpy(version_ext->version_str, ver_ext->version_str,
665 sizeof(char) * 128);
666 memcpy(priv->version_str, ver_ext->version_str, 128);
667 }
668 return 0;
669}
670
671/*
672 * This function handles the command response of register access.
673 *
674 * The register value and offset are returned to the user. For EEPROM
675 * access, the byte count is also returned.
676 */
677static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
678 void *data_buf)
679{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700680 struct mwifiex_ds_reg_rw *reg_rw;
681 struct mwifiex_ds_read_eeprom *eeprom;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700682
683 if (data_buf) {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700684 reg_rw = data_buf;
685 eeprom = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700686 switch (type) {
687 case HostCmd_CMD_MAC_REG_ACCESS:
688 {
689 struct host_cmd_ds_mac_reg_access *reg;
690 reg = (struct host_cmd_ds_mac_reg_access *)
691 &resp->params.mac_reg;
692 reg_rw->offset = cpu_to_le32(
693 (u32) le16_to_cpu(reg->offset));
694 reg_rw->value = reg->value;
695 break;
696 }
697 case HostCmd_CMD_BBP_REG_ACCESS:
698 {
699 struct host_cmd_ds_bbp_reg_access *reg;
700 reg = (struct host_cmd_ds_bbp_reg_access *)
701 &resp->params.bbp_reg;
702 reg_rw->offset = cpu_to_le32(
703 (u32) le16_to_cpu(reg->offset));
704 reg_rw->value = cpu_to_le32((u32) reg->value);
705 break;
706 }
707
708 case HostCmd_CMD_RF_REG_ACCESS:
709 {
710 struct host_cmd_ds_rf_reg_access *reg;
711 reg = (struct host_cmd_ds_rf_reg_access *)
712 &resp->params.rf_reg;
713 reg_rw->offset = cpu_to_le32(
714 (u32) le16_to_cpu(reg->offset));
715 reg_rw->value = cpu_to_le32((u32) reg->value);
716 break;
717 }
718 case HostCmd_CMD_PMIC_REG_ACCESS:
719 {
720 struct host_cmd_ds_pmic_reg_access *reg;
721 reg = (struct host_cmd_ds_pmic_reg_access *)
722 &resp->params.pmic_reg;
723 reg_rw->offset = cpu_to_le32(
724 (u32) le16_to_cpu(reg->offset));
725 reg_rw->value = cpu_to_le32((u32) reg->value);
726 break;
727 }
728 case HostCmd_CMD_CAU_REG_ACCESS:
729 {
730 struct host_cmd_ds_rf_reg_access *reg;
731 reg = (struct host_cmd_ds_rf_reg_access *)
732 &resp->params.rf_reg;
733 reg_rw->offset = cpu_to_le32(
734 (u32) le16_to_cpu(reg->offset));
735 reg_rw->value = cpu_to_le32((u32) reg->value);
736 break;
737 }
738 case HostCmd_CMD_802_11_EEPROM_ACCESS:
739 {
740 struct host_cmd_ds_802_11_eeprom_access
741 *cmd_eeprom =
742 (struct host_cmd_ds_802_11_eeprom_access
743 *) &resp->params.eeprom;
744 pr_debug("info: EEPROM read len=%x\n",
745 cmd_eeprom->byte_count);
746 if (le16_to_cpu(eeprom->byte_count) <
747 le16_to_cpu(
748 cmd_eeprom->byte_count)) {
749 eeprom->byte_count = cpu_to_le16(0);
750 pr_debug("info: EEPROM read "
751 "length is too big\n");
752 return -1;
753 }
754 eeprom->offset = cmd_eeprom->offset;
755 eeprom->byte_count = cmd_eeprom->byte_count;
756 if (le16_to_cpu(eeprom->byte_count) > 0)
757 memcpy(&eeprom->value,
758 &cmd_eeprom->value,
759 le16_to_cpu(eeprom->byte_count));
760
761 break;
762 }
763 default:
764 return -1;
765 }
766 }
767 return 0;
768}
769
770/*
771 * This function handles the command response of get IBSS coalescing status.
772 *
773 * If the received BSSID is different than the current one, the current BSSID,
774 * beacon interval, ATIM window and ERP information are updated, along with
775 * changing the ad-hoc state accordingly.
776 */
777static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
778 struct host_cmd_ds_command *resp)
779{
780 struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
781 &(resp->params.ibss_coalescing);
782 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
783
784 if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
785 return 0;
786
787 dev_dbg(priv->adapter->dev,
788 "info: new BSSID %pM\n", ibss_coal_resp->bssid);
789
790 /* If rsp has NULL BSSID, Just return..... No Action */
791 if (!memcmp(ibss_coal_resp->bssid, zero_mac, ETH_ALEN)) {
792 dev_warn(priv->adapter->dev, "new BSSID is NULL\n");
793 return 0;
794 }
795
796 /* If BSSID is diff, modify current BSS parameters */
797 if (memcmp(priv->curr_bss_params.bss_descriptor.mac_address,
798 ibss_coal_resp->bssid, ETH_ALEN)) {
799 /* BSSID */
800 memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
801 ibss_coal_resp->bssid, ETH_ALEN);
802
803 /* Beacon Interval */
804 priv->curr_bss_params.bss_descriptor.beacon_period
805 = le16_to_cpu(ibss_coal_resp->beacon_interval);
806
807 /* ERP Information */
808 priv->curr_bss_params.bss_descriptor.erp_flags =
809 (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
810
811 priv->adhoc_state = ADHOC_COALESCED;
812 }
813
814 return 0;
815}
816
817/*
818 * This function handles the command responses.
819 *
820 * This is a generic function, which calls command specific
821 * response handlers based on the command ID.
822 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700823int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
824 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700825{
826 int ret = 0;
827 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700828 void *data_buf = adapter->curr_cmd->data_buf;
829
830 /* If the command is not successful, cleanup and return failure */
831 if (resp->result != HostCmd_RESULT_OK) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700832 mwifiex_process_cmdresp_error(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700833 return -1;
834 }
835 /* Command successful, handle response */
836 switch (cmdresp_no) {
837 case HostCmd_CMD_GET_HW_SPEC:
838 ret = mwifiex_ret_get_hw_spec(priv, resp);
839 break;
840 case HostCmd_CMD_MAC_CONTROL:
841 break;
842 case HostCmd_CMD_802_11_MAC_ADDRESS:
843 ret = mwifiex_ret_802_11_mac_address(priv, resp);
844 break;
845 case HostCmd_CMD_MAC_MULTICAST_ADR:
846 ret = mwifiex_ret_mac_multicast_adr(priv, resp);
847 break;
848 case HostCmd_CMD_TX_RATE_CFG:
849 ret = mwifiex_ret_tx_rate_cfg(priv, resp, data_buf);
850 break;
851 case HostCmd_CMD_802_11_SCAN:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700852 ret = mwifiex_ret_802_11_scan(priv, resp);
853 adapter->curr_cmd->wait_q_enabled = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700854 break;
855 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700856 ret = mwifiex_ret_802_11_scan(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700857 dev_dbg(adapter->dev,
858 "info: CMD_RESP: BG_SCAN result is ready!\n");
859 break;
860 case HostCmd_CMD_TXPWR_CFG:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700861 ret = mwifiex_ret_tx_power_cfg(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700862 break;
863 case HostCmd_CMD_802_11_PS_MODE_ENH:
864 ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
865 break;
866 case HostCmd_CMD_802_11_HS_CFG_ENH:
867 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
868 break;
869 case HostCmd_CMD_802_11_ASSOCIATE:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700870 ret = mwifiex_ret_802_11_associate(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700871 break;
872 case HostCmd_CMD_802_11_DEAUTHENTICATE:
873 ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
874 break;
875 case HostCmd_CMD_802_11_AD_HOC_START:
876 case HostCmd_CMD_802_11_AD_HOC_JOIN:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700877 ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700878 break;
879 case HostCmd_CMD_802_11_AD_HOC_STOP:
880 ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
881 break;
882 case HostCmd_CMD_802_11_GET_LOG:
883 ret = mwifiex_ret_get_log(priv, resp, data_buf);
884 break;
885 case HostCmd_CMD_RSSI_INFO:
886 ret = mwifiex_ret_802_11_rssi_info(priv, resp, data_buf);
887 break;
888 case HostCmd_CMD_802_11_SNMP_MIB:
889 ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
890 break;
891 case HostCmd_CMD_802_11_TX_RATE_QUERY:
892 ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
893 break;
894 case HostCmd_CMD_802_11_RF_CHANNEL:
895 ret = mwifiex_ret_802_11_rf_channel(priv, resp, data_buf);
896 break;
897 case HostCmd_CMD_VERSION_EXT:
898 ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
899 break;
900 case HostCmd_CMD_FUNC_INIT:
901 case HostCmd_CMD_FUNC_SHUTDOWN:
902 break;
903 case HostCmd_CMD_802_11_KEY_MATERIAL:
904 ret = mwifiex_ret_802_11_key_material(priv, resp);
905 break;
906 case HostCmd_CMD_802_11D_DOMAIN_INFO:
907 ret = mwifiex_ret_802_11d_domain_info(priv, resp);
908 break;
909 case HostCmd_CMD_11N_ADDBA_REQ:
910 ret = mwifiex_ret_11n_addba_req(priv, resp);
911 break;
912 case HostCmd_CMD_11N_DELBA:
913 ret = mwifiex_ret_11n_delba(priv, resp);
914 break;
915 case HostCmd_CMD_11N_ADDBA_RSP:
916 ret = mwifiex_ret_11n_addba_resp(priv, resp);
917 break;
918 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
919 adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
920 tx_buf.buff_size);
921 adapter->tx_buf_size = (adapter->tx_buf_size /
922 MWIFIEX_SDIO_BLOCK_SIZE) *
923 MWIFIEX_SDIO_BLOCK_SIZE;
924 adapter->curr_tx_buf_size = adapter->tx_buf_size;
925 dev_dbg(adapter->dev,
926 "cmd: max_tx_buf_size=%d, tx_buf_size=%d\n",
927 adapter->max_tx_buf_size, adapter->tx_buf_size);
928
929 if (adapter->if_ops.update_mp_end_port)
930 adapter->if_ops.update_mp_end_port(adapter,
931 le16_to_cpu(resp->
932 params.
933 tx_buf.
934 mp_end_port));
935 break;
936 case HostCmd_CMD_AMSDU_AGGR_CTRL:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700937 ret = mwifiex_ret_amsdu_aggr_ctrl(resp, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700938 break;
939 case HostCmd_CMD_WMM_GET_STATUS:
940 ret = mwifiex_ret_wmm_get_status(priv, resp);
941 break;
942 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
943 ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
944 break;
945 case HostCmd_CMD_MAC_REG_ACCESS:
946 case HostCmd_CMD_BBP_REG_ACCESS:
947 case HostCmd_CMD_RF_REG_ACCESS:
948 case HostCmd_CMD_PMIC_REG_ACCESS:
949 case HostCmd_CMD_CAU_REG_ACCESS:
950 case HostCmd_CMD_802_11_EEPROM_ACCESS:
951 ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
952 break;
953 case HostCmd_CMD_SET_BSS_MODE:
954 break;
955 case HostCmd_CMD_11N_CFG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700956 ret = mwifiex_ret_11n_cfg(resp, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700957 break;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700958 case HostCmd_CMD_PCIE_DESC_DETAILS:
959 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700960 default:
961 dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
962 resp->command);
963 break;
964 }
965
966 return ret;
967}