blob: ad64c87b91d6a05261c3f62cf842be8761c24793 [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,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700186 u32 *ul_temp)
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);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700191
192 dev_dbg(priv->adapter->dev, "info: SNMP_RESP: oid value = %#x,"
193 " query_type = %#x, buf size = %#x\n",
194 oid, query_type, le16_to_cpu(smib->buf_size));
195 if (query_type == HostCmd_ACT_GEN_GET) {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700196 if (ul_temp)
197 *ul_temp = le16_to_cpu(*((__le16 *) (smib->value)));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700198 switch (oid) {
199 case FRAG_THRESH_I:
200 dev_dbg(priv->adapter->dev,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700201 "info: SNMP_RESP: FragThsd =%u\n", *ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700202 break;
203 case RTS_THRESH_I:
204 dev_dbg(priv->adapter->dev,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700205 "info: SNMP_RESP: RTSThsd =%u\n", *ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700206 break;
207 case SHORT_RETRY_LIM_I:
208 dev_dbg(priv->adapter->dev,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700209 "info: SNMP_RESP: TxRetryCount=%u\n", *ul_temp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700210 break;
211 default:
212 break;
213 }
214 }
215
216 return 0;
217}
218
219/*
220 * This function handles the command response of get log request
221 *
222 * Handling includes changing the header fields into CPU format
223 * and sending the received parameters to application.
224 */
225static int mwifiex_ret_get_log(struct mwifiex_private *priv,
226 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700227 struct mwifiex_ds_get_stats *stats)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700228{
229 struct host_cmd_ds_802_11_get_log *get_log =
230 (struct host_cmd_ds_802_11_get_log *) &resp->params.get_log;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700231
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700232 if (stats) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700233 stats->mcast_tx_frame = le32_to_cpu(get_log->mcast_tx_frame);
234 stats->failed = le32_to_cpu(get_log->failed);
235 stats->retry = le32_to_cpu(get_log->retry);
236 stats->multi_retry = le32_to_cpu(get_log->multi_retry);
237 stats->frame_dup = le32_to_cpu(get_log->frame_dup);
238 stats->rts_success = le32_to_cpu(get_log->rts_success);
239 stats->rts_failure = le32_to_cpu(get_log->rts_failure);
240 stats->ack_failure = le32_to_cpu(get_log->ack_failure);
241 stats->rx_frag = le32_to_cpu(get_log->rx_frag);
242 stats->mcast_rx_frame = le32_to_cpu(get_log->mcast_rx_frame);
243 stats->fcs_error = le32_to_cpu(get_log->fcs_error);
244 stats->tx_frame = le32_to_cpu(get_log->tx_frame);
245 stats->wep_icv_error[0] =
246 le32_to_cpu(get_log->wep_icv_err_cnt[0]);
247 stats->wep_icv_error[1] =
248 le32_to_cpu(get_log->wep_icv_err_cnt[1]);
249 stats->wep_icv_error[2] =
250 le32_to_cpu(get_log->wep_icv_err_cnt[2]);
251 stats->wep_icv_error[3] =
252 le32_to_cpu(get_log->wep_icv_err_cnt[3]);
253 }
254
255 return 0;
256}
257
258/*
259 * This function handles the command response of set/get Tx rate
260 * configurations.
261 *
262 * Handling includes changing the header fields into CPU format
263 * and saving the following parameters in driver -
264 * - DSSS rate bitmap
265 * - OFDM rate bitmap
266 * - HT MCS rate bitmaps
267 *
268 * Based on the new rate bitmaps, the function re-evaluates if
269 * auto data rate has been activated. If not, it sends another
270 * query to the firmware to get the current Tx data rate and updates
271 * the driver value.
272 */
273static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
274 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700275 struct mwifiex_rate_cfg *ds_rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700276{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700277 struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
278 struct mwifiex_rate_scope *rate_scope;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700279 struct mwifiex_ie_types_header *head;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700280 u16 tlv, tlv_buf_len;
281 u8 *tlv_buf;
282 u32 i;
283 int ret = 0;
284
285 tlv_buf = (u8 *) ((u8 *) rate_cfg) +
286 sizeof(struct host_cmd_ds_tx_rate_cfg);
287 tlv_buf_len = *(u16 *) (tlv_buf + sizeof(u16));
288
289 while (tlv_buf && tlv_buf_len > 0) {
290 tlv = (*tlv_buf);
291 tlv = tlv | (*(tlv_buf + 1) << 8);
292
293 switch (tlv) {
294 case TLV_TYPE_RATE_SCOPE:
295 rate_scope = (struct mwifiex_rate_scope *) tlv_buf;
296 priv->bitmap_rates[0] =
297 le16_to_cpu(rate_scope->hr_dsss_rate_bitmap);
298 priv->bitmap_rates[1] =
299 le16_to_cpu(rate_scope->ofdm_rate_bitmap);
300 for (i = 0;
301 i <
302 sizeof(rate_scope->ht_mcs_rate_bitmap) /
303 sizeof(u16); i++)
304 priv->bitmap_rates[2 + i] =
305 le16_to_cpu(rate_scope->
306 ht_mcs_rate_bitmap[i]);
307 break;
308 /* Add RATE_DROP tlv here */
309 }
310
311 head = (struct mwifiex_ie_types_header *) tlv_buf;
312 tlv_buf += le16_to_cpu(head->len) + sizeof(*head);
313 tlv_buf_len -= le16_to_cpu(head->len);
314 }
315
316 priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
317
318 if (priv->is_data_rate_auto)
319 priv->data_rate = 0;
320 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700321 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700322 HostCmd_CMD_802_11_TX_RATE_QUERY,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700323 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700324
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700325 if (ds_rate) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700326 if (le16_to_cpu(rate_cfg->action) == HostCmd_ACT_GEN_GET) {
327 if (priv->is_data_rate_auto) {
328 ds_rate->is_rate_auto = 1;
329 } else {
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700330 ds_rate->rate = mwifiex_get_rate_index(priv->
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331 bitmap_rates,
332 sizeof(priv->
333 bitmap_rates));
334 if (ds_rate->rate >=
335 MWIFIEX_RATE_BITMAP_OFDM0
336 && ds_rate->rate <=
337 MWIFIEX_RATE_BITMAP_OFDM7)
338 ds_rate->rate -=
339 (MWIFIEX_RATE_BITMAP_OFDM0 -
340 MWIFIEX_RATE_INDEX_OFDM0);
341 if (ds_rate->rate >=
342 MWIFIEX_RATE_BITMAP_MCS0
343 && ds_rate->rate <=
344 MWIFIEX_RATE_BITMAP_MCS127)
345 ds_rate->rate -=
346 (MWIFIEX_RATE_BITMAP_MCS0 -
347 MWIFIEX_RATE_INDEX_MCS0);
348 }
349 }
350 }
351
352 return ret;
353}
354
355/*
356 * This function handles the command response of get Tx power level.
357 *
358 * Handling includes saving the maximum and minimum Tx power levels
359 * in driver, as well as sending the values to user.
360 */
361static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
362{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700363 int length, max_power = -1, min_power = -1;
364 struct mwifiex_types_power_group *pg_tlv_hdr;
365 struct mwifiex_power_group *pg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700366
367 if (data_buf) {
368 pg_tlv_hdr =
369 (struct mwifiex_types_power_group *) ((u8 *) data_buf
370 + sizeof(struct host_cmd_ds_txpwr_cfg));
371 pg = (struct mwifiex_power_group *) ((u8 *) pg_tlv_hdr +
372 sizeof(struct mwifiex_types_power_group));
373 length = pg_tlv_hdr->length;
374 if (length > 0) {
375 max_power = pg->power_max;
376 min_power = pg->power_min;
377 length -= sizeof(struct mwifiex_power_group);
378 }
379 while (length) {
380 pg++;
381 if (max_power < pg->power_max)
382 max_power = pg->power_max;
383
384 if (min_power > pg->power_min)
385 min_power = pg->power_min;
386
387 length -= sizeof(struct mwifiex_power_group);
388 }
389 if (pg_tlv_hdr->length > 0) {
390 priv->min_tx_power_level = (u8) min_power;
391 priv->max_tx_power_level = (u8) max_power;
392 }
393 } else {
394 return -1;
395 }
396
397 return 0;
398}
399
400/*
401 * This function handles the command response of set/get Tx power
402 * configurations.
403 *
404 * Handling includes changing the header fields into CPU format
405 * and saving the current Tx power level in driver.
406 */
407static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700408 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700409{
410 struct mwifiex_adapter *adapter = priv->adapter;
411 struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700412 struct mwifiex_types_power_group *pg_tlv_hdr;
413 struct mwifiex_power_group *pg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700414 u16 action = le16_to_cpu(txp_cfg->action);
415
416 switch (action) {
417 case HostCmd_ACT_GEN_GET:
418 {
419 pg_tlv_hdr =
420 (struct mwifiex_types_power_group *) ((u8 *)
421 txp_cfg +
422 sizeof
423 (struct
424 host_cmd_ds_txpwr_cfg));
425 pg = (struct mwifiex_power_group *) ((u8 *)
426 pg_tlv_hdr +
427 sizeof(struct
428 mwifiex_types_power_group));
429 if (adapter->hw_status ==
430 MWIFIEX_HW_STATUS_INITIALIZING)
431 mwifiex_get_power_level(priv, txp_cfg);
432 priv->tx_power_level = (u16) pg->power_min;
433 break;
434 }
435 case HostCmd_ACT_GEN_SET:
436 if (le32_to_cpu(txp_cfg->mode)) {
437 pg_tlv_hdr =
438 (struct mwifiex_types_power_group *) ((u8 *)
439 txp_cfg +
440 sizeof
441 (struct
442 host_cmd_ds_txpwr_cfg));
443 pg = (struct mwifiex_power_group *) ((u8 *) pg_tlv_hdr
444 +
445 sizeof(struct
446 mwifiex_types_power_group));
447 if (pg->power_max == pg->power_min)
448 priv->tx_power_level = (u16) pg->power_min;
449 }
450 break;
451 default:
452 dev_err(adapter->dev, "CMD_RESP: unknown cmd action %d\n",
453 action);
454 return 0;
455 }
456 dev_dbg(adapter->dev,
457 "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
458 priv->tx_power_level, priv->max_tx_power_level,
459 priv->min_tx_power_level);
460
461 return 0;
462}
463
464/*
465 * This function handles the command response of set/get MAC address.
466 *
467 * Handling includes saving the MAC address in driver.
468 */
469static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
470 struct host_cmd_ds_command *resp)
471{
472 struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
473 &resp->params.mac_addr;
474
475 memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
476
477 dev_dbg(priv->adapter->dev,
478 "info: set mac address: %pM\n", priv->curr_addr);
479
480 return 0;
481}
482
483/*
484 * This function handles the command response of set/get MAC multicast
485 * address.
486 */
487static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
488 struct host_cmd_ds_command *resp)
489{
490 return 0;
491}
492
493/*
494 * This function handles the command response of get Tx rate query.
495 *
496 * Handling includes changing the header fields into CPU format
497 * and saving the Tx rate and HT information parameters in driver.
498 *
499 * Both rate configuration and current data rate can be retrieved
500 * with this request.
501 */
502static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
503 struct host_cmd_ds_command *resp)
504{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700505 priv->tx_rate = resp->params.tx_rate.tx_rate;
506 priv->tx_htinfo = resp->params.tx_rate.ht_info;
507 if (!priv->is_data_rate_auto)
508 priv->data_rate =
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700509 mwifiex_index_to_data_rate(priv->tx_rate,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510 priv->tx_htinfo);
511
512 return 0;
513}
514
515/*
516 * This function handles the command response of a deauthenticate
517 * command.
518 *
519 * If the deauthenticated MAC matches the current BSS MAC, the connection
520 * state is reset.
521 */
522static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
523 struct host_cmd_ds_command *resp)
524{
525 struct mwifiex_adapter *adapter = priv->adapter;
526
527 adapter->dbg.num_cmd_deauth++;
528 if (!memcmp(resp->params.deauth.mac_addr,
529 &priv->curr_bss_params.bss_descriptor.mac_address,
530 sizeof(resp->params.deauth.mac_addr)))
531 mwifiex_reset_connect_state(priv);
532
533 return 0;
534}
535
536/*
537 * This function handles the command response of ad-hoc stop.
538 *
539 * The function resets the connection state in driver.
540 */
541static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
542 struct host_cmd_ds_command *resp)
543{
544 mwifiex_reset_connect_state(priv);
545 return 0;
546}
547
548/*
549 * This function handles the command response of set/get key material.
550 *
551 * Handling includes updating the driver parameters to reflect the
552 * changes.
553 */
554static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
555 struct host_cmd_ds_command *resp)
556{
557 struct host_cmd_ds_802_11_key_material *key =
558 &resp->params.key_material;
559
560 if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700561 if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562 dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
563 priv->wpa_is_gtk_set = true;
564 priv->scan_block = false;
565 }
566 }
567
568 memset(priv->aes_key.key_param_set.key, 0,
569 sizeof(key->key_param_set.key));
570 priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
571 memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
572 le16_to_cpu(priv->aes_key.key_param_set.key_len));
573
574 return 0;
575}
576
577/*
578 * This function handles the command response of get 11d domain information.
579 */
580static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
581 struct host_cmd_ds_command *resp)
582{
583 struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
584 &resp->params.domain_info_resp;
585 struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
586 u16 action = le16_to_cpu(domain_info->action);
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700587 u8 no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700588
589 no_of_triplet = (u8) ((le16_to_cpu(domain->header.len) -
590 IEEE80211_COUNTRY_STRING_LEN) /
591 sizeof(struct ieee80211_country_ie_triplet));
592
593 dev_dbg(priv->adapter->dev, "info: 11D Domain Info Resp:"
594 " no_of_triplet=%d\n", no_of_triplet);
595
596 if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
597 dev_warn(priv->adapter->dev,
598 "11D: invalid number of triplets %d "
599 "returned!!\n", no_of_triplet);
600 return -1;
601 }
602
603 switch (action) {
604 case HostCmd_ACT_GEN_SET: /* Proc Set Action */
605 break;
606 case HostCmd_ACT_GEN_GET:
607 break;
608 default:
609 dev_err(priv->adapter->dev,
610 "11D: invalid action:%d\n", domain_info->action);
611 return -1;
612 }
613
614 return 0;
615}
616
617/*
618 * This function handles the command response of get RF channel.
619 *
620 * Handling includes changing the header fields into CPU format
621 * and saving the new channel in driver.
622 */
623static int mwifiex_ret_802_11_rf_channel(struct mwifiex_private *priv,
624 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700625 u16 *new_channel)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700626{
627 struct host_cmd_ds_802_11_rf_channel *rf_channel =
628 &resp->params.rf_channel;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700629
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700630 if (new_channel)
631 *new_channel = le16_to_cpu(rf_channel->current_channel);
632
633 if (priv->curr_bss_params.bss_descriptor.channel != *new_channel) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700634 dev_dbg(priv->adapter->dev, "cmd: Channel Switch: %d to %d\n",
635 priv->curr_bss_params.bss_descriptor.channel,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700636 *new_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700637 /* Update the channel again */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700638 priv->curr_bss_params.bss_descriptor.channel = *new_channel;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700639 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700640
641 return 0;
642}
643
644/*
645 * This function handles the command response of get extended version.
646 *
647 * Handling includes forming the extended version string and sending it
648 * to application.
649 */
650static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
651 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700652 struct host_cmd_ds_version_ext *version_ext)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700653{
654 struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700655
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700656 if (version_ext) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700657 version_ext->version_str_sel = ver_ext->version_str_sel;
658 memcpy(version_ext->version_str, ver_ext->version_str,
659 sizeof(char) * 128);
660 memcpy(priv->version_str, ver_ext->version_str, 128);
661 }
662 return 0;
663}
664
665/*
666 * This function handles the command response of register access.
667 *
668 * The register value and offset are returned to the user. For EEPROM
669 * access, the byte count is also returned.
670 */
671static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
672 void *data_buf)
673{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700674 struct mwifiex_ds_reg_rw *reg_rw;
675 struct mwifiex_ds_read_eeprom *eeprom;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700676
677 if (data_buf) {
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700678 reg_rw = data_buf;
679 eeprom = data_buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700680 switch (type) {
681 case HostCmd_CMD_MAC_REG_ACCESS:
682 {
683 struct host_cmd_ds_mac_reg_access *reg;
684 reg = (struct host_cmd_ds_mac_reg_access *)
685 &resp->params.mac_reg;
686 reg_rw->offset = cpu_to_le32(
687 (u32) le16_to_cpu(reg->offset));
688 reg_rw->value = reg->value;
689 break;
690 }
691 case HostCmd_CMD_BBP_REG_ACCESS:
692 {
693 struct host_cmd_ds_bbp_reg_access *reg;
694 reg = (struct host_cmd_ds_bbp_reg_access *)
695 &resp->params.bbp_reg;
696 reg_rw->offset = cpu_to_le32(
697 (u32) le16_to_cpu(reg->offset));
698 reg_rw->value = cpu_to_le32((u32) reg->value);
699 break;
700 }
701
702 case HostCmd_CMD_RF_REG_ACCESS:
703 {
704 struct host_cmd_ds_rf_reg_access *reg;
705 reg = (struct host_cmd_ds_rf_reg_access *)
706 &resp->params.rf_reg;
707 reg_rw->offset = cpu_to_le32(
708 (u32) le16_to_cpu(reg->offset));
709 reg_rw->value = cpu_to_le32((u32) reg->value);
710 break;
711 }
712 case HostCmd_CMD_PMIC_REG_ACCESS:
713 {
714 struct host_cmd_ds_pmic_reg_access *reg;
715 reg = (struct host_cmd_ds_pmic_reg_access *)
716 &resp->params.pmic_reg;
717 reg_rw->offset = cpu_to_le32(
718 (u32) le16_to_cpu(reg->offset));
719 reg_rw->value = cpu_to_le32((u32) reg->value);
720 break;
721 }
722 case HostCmd_CMD_CAU_REG_ACCESS:
723 {
724 struct host_cmd_ds_rf_reg_access *reg;
725 reg = (struct host_cmd_ds_rf_reg_access *)
726 &resp->params.rf_reg;
727 reg_rw->offset = cpu_to_le32(
728 (u32) le16_to_cpu(reg->offset));
729 reg_rw->value = cpu_to_le32((u32) reg->value);
730 break;
731 }
732 case HostCmd_CMD_802_11_EEPROM_ACCESS:
733 {
734 struct host_cmd_ds_802_11_eeprom_access
735 *cmd_eeprom =
736 (struct host_cmd_ds_802_11_eeprom_access
737 *) &resp->params.eeprom;
738 pr_debug("info: EEPROM read len=%x\n",
739 cmd_eeprom->byte_count);
740 if (le16_to_cpu(eeprom->byte_count) <
741 le16_to_cpu(
742 cmd_eeprom->byte_count)) {
743 eeprom->byte_count = cpu_to_le16(0);
744 pr_debug("info: EEPROM read "
745 "length is too big\n");
746 return -1;
747 }
748 eeprom->offset = cmd_eeprom->offset;
749 eeprom->byte_count = cmd_eeprom->byte_count;
750 if (le16_to_cpu(eeprom->byte_count) > 0)
751 memcpy(&eeprom->value,
752 &cmd_eeprom->value,
753 le16_to_cpu(eeprom->byte_count));
754
755 break;
756 }
757 default:
758 return -1;
759 }
760 }
761 return 0;
762}
763
764/*
765 * This function handles the command response of get IBSS coalescing status.
766 *
767 * If the received BSSID is different than the current one, the current BSSID,
768 * beacon interval, ATIM window and ERP information are updated, along with
769 * changing the ad-hoc state accordingly.
770 */
771static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
772 struct host_cmd_ds_command *resp)
773{
774 struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
775 &(resp->params.ibss_coalescing);
776 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
777
778 if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
779 return 0;
780
781 dev_dbg(priv->adapter->dev,
782 "info: new BSSID %pM\n", ibss_coal_resp->bssid);
783
784 /* If rsp has NULL BSSID, Just return..... No Action */
785 if (!memcmp(ibss_coal_resp->bssid, zero_mac, ETH_ALEN)) {
786 dev_warn(priv->adapter->dev, "new BSSID is NULL\n");
787 return 0;
788 }
789
790 /* If BSSID is diff, modify current BSS parameters */
791 if (memcmp(priv->curr_bss_params.bss_descriptor.mac_address,
792 ibss_coal_resp->bssid, ETH_ALEN)) {
793 /* BSSID */
794 memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
795 ibss_coal_resp->bssid, ETH_ALEN);
796
797 /* Beacon Interval */
798 priv->curr_bss_params.bss_descriptor.beacon_period
799 = le16_to_cpu(ibss_coal_resp->beacon_interval);
800
801 /* ERP Information */
802 priv->curr_bss_params.bss_descriptor.erp_flags =
803 (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
804
805 priv->adhoc_state = ADHOC_COALESCED;
806 }
807
808 return 0;
809}
810
811/*
812 * This function handles the command responses.
813 *
814 * This is a generic function, which calls command specific
815 * response handlers based on the command ID.
816 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700817int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
818 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700819{
820 int ret = 0;
821 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700822 void *data_buf = adapter->curr_cmd->data_buf;
823
824 /* If the command is not successful, cleanup and return failure */
825 if (resp->result != HostCmd_RESULT_OK) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700826 mwifiex_process_cmdresp_error(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700827 return -1;
828 }
829 /* Command successful, handle response */
830 switch (cmdresp_no) {
831 case HostCmd_CMD_GET_HW_SPEC:
832 ret = mwifiex_ret_get_hw_spec(priv, resp);
833 break;
834 case HostCmd_CMD_MAC_CONTROL:
835 break;
836 case HostCmd_CMD_802_11_MAC_ADDRESS:
837 ret = mwifiex_ret_802_11_mac_address(priv, resp);
838 break;
839 case HostCmd_CMD_MAC_MULTICAST_ADR:
840 ret = mwifiex_ret_mac_multicast_adr(priv, resp);
841 break;
842 case HostCmd_CMD_TX_RATE_CFG:
843 ret = mwifiex_ret_tx_rate_cfg(priv, resp, data_buf);
844 break;
845 case HostCmd_CMD_802_11_SCAN:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700846 ret = mwifiex_ret_802_11_scan(priv, resp);
847 adapter->curr_cmd->wait_q_enabled = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700848 break;
849 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700850 ret = mwifiex_ret_802_11_scan(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700851 dev_dbg(adapter->dev,
852 "info: CMD_RESP: BG_SCAN result is ready!\n");
853 break;
854 case HostCmd_CMD_TXPWR_CFG:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700855 ret = mwifiex_ret_tx_power_cfg(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700856 break;
857 case HostCmd_CMD_802_11_PS_MODE_ENH:
858 ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
859 break;
860 case HostCmd_CMD_802_11_HS_CFG_ENH:
861 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
862 break;
863 case HostCmd_CMD_802_11_ASSOCIATE:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700864 ret = mwifiex_ret_802_11_associate(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700865 break;
866 case HostCmd_CMD_802_11_DEAUTHENTICATE:
867 ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
868 break;
869 case HostCmd_CMD_802_11_AD_HOC_START:
870 case HostCmd_CMD_802_11_AD_HOC_JOIN:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700871 ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700872 break;
873 case HostCmd_CMD_802_11_AD_HOC_STOP:
874 ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
875 break;
876 case HostCmd_CMD_802_11_GET_LOG:
877 ret = mwifiex_ret_get_log(priv, resp, data_buf);
878 break;
879 case HostCmd_CMD_RSSI_INFO:
880 ret = mwifiex_ret_802_11_rssi_info(priv, resp, data_buf);
881 break;
882 case HostCmd_CMD_802_11_SNMP_MIB:
883 ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
884 break;
885 case HostCmd_CMD_802_11_TX_RATE_QUERY:
886 ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
887 break;
888 case HostCmd_CMD_802_11_RF_CHANNEL:
889 ret = mwifiex_ret_802_11_rf_channel(priv, resp, data_buf);
890 break;
891 case HostCmd_CMD_VERSION_EXT:
892 ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
893 break;
894 case HostCmd_CMD_FUNC_INIT:
895 case HostCmd_CMD_FUNC_SHUTDOWN:
896 break;
897 case HostCmd_CMD_802_11_KEY_MATERIAL:
898 ret = mwifiex_ret_802_11_key_material(priv, resp);
899 break;
900 case HostCmd_CMD_802_11D_DOMAIN_INFO:
901 ret = mwifiex_ret_802_11d_domain_info(priv, resp);
902 break;
903 case HostCmd_CMD_11N_ADDBA_REQ:
904 ret = mwifiex_ret_11n_addba_req(priv, resp);
905 break;
906 case HostCmd_CMD_11N_DELBA:
907 ret = mwifiex_ret_11n_delba(priv, resp);
908 break;
909 case HostCmd_CMD_11N_ADDBA_RSP:
910 ret = mwifiex_ret_11n_addba_resp(priv, resp);
911 break;
912 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
913 adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
914 tx_buf.buff_size);
915 adapter->tx_buf_size = (adapter->tx_buf_size /
916 MWIFIEX_SDIO_BLOCK_SIZE) *
917 MWIFIEX_SDIO_BLOCK_SIZE;
918 adapter->curr_tx_buf_size = adapter->tx_buf_size;
919 dev_dbg(adapter->dev,
920 "cmd: max_tx_buf_size=%d, tx_buf_size=%d\n",
921 adapter->max_tx_buf_size, adapter->tx_buf_size);
922
923 if (adapter->if_ops.update_mp_end_port)
924 adapter->if_ops.update_mp_end_port(adapter,
925 le16_to_cpu(resp->
926 params.
927 tx_buf.
928 mp_end_port));
929 break;
930 case HostCmd_CMD_AMSDU_AGGR_CTRL:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700931 ret = mwifiex_ret_amsdu_aggr_ctrl(resp, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700932 break;
933 case HostCmd_CMD_WMM_GET_STATUS:
934 ret = mwifiex_ret_wmm_get_status(priv, resp);
935 break;
936 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
937 ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
938 break;
939 case HostCmd_CMD_MAC_REG_ACCESS:
940 case HostCmd_CMD_BBP_REG_ACCESS:
941 case HostCmd_CMD_RF_REG_ACCESS:
942 case HostCmd_CMD_PMIC_REG_ACCESS:
943 case HostCmd_CMD_CAU_REG_ACCESS:
944 case HostCmd_CMD_802_11_EEPROM_ACCESS:
945 ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
946 break;
947 case HostCmd_CMD_SET_BSS_MODE:
948 break;
949 case HostCmd_CMD_11N_CFG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700950 ret = mwifiex_ret_11n_cfg(resp, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700951 break;
952 default:
953 dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
954 resp->command);
955 break;
956 }
957
958 return ret;
959}