blob: 3f13ff0cd262353340056faa79ecf8a5655e674a [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:
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700423 pg_tlv_hdr = (struct mwifiex_types_power_group *)
424 ((u8 *) txp_cfg +
425 sizeof(struct host_cmd_ds_txpwr_cfg));
426
427 pg = (struct mwifiex_power_group *)
428 ((u8 *) pg_tlv_hdr +
429 sizeof(struct mwifiex_types_power_group));
430
431 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
432 mwifiex_get_power_level(priv, txp_cfg);
433
434 priv->tx_power_level = (u16) pg->power_min;
435 break;
436
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700437 case HostCmd_ACT_GEN_SET:
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700438 if (!le32_to_cpu(txp_cfg->mode))
439 break;
440
441 pg_tlv_hdr = (struct mwifiex_types_power_group *)
442 ((u8 *) txp_cfg +
443 sizeof(struct host_cmd_ds_txpwr_cfg));
444
445 pg = (struct mwifiex_power_group *)
446 ((u8 *) pg_tlv_hdr +
447 sizeof(struct mwifiex_types_power_group));
448
449 if (pg->power_max == pg->power_min)
450 priv->tx_power_level = (u16) pg->power_min;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700451 break;
452 default:
453 dev_err(adapter->dev, "CMD_RESP: unknown cmd action %d\n",
454 action);
455 return 0;
456 }
457 dev_dbg(adapter->dev,
458 "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
459 priv->tx_power_level, priv->max_tx_power_level,
460 priv->min_tx_power_level);
461
462 return 0;
463}
464
465/*
466 * This function handles the command response of set/get MAC address.
467 *
468 * Handling includes saving the MAC address in driver.
469 */
470static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
471 struct host_cmd_ds_command *resp)
472{
473 struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
474 &resp->params.mac_addr;
475
476 memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
477
478 dev_dbg(priv->adapter->dev,
479 "info: set mac address: %pM\n", priv->curr_addr);
480
481 return 0;
482}
483
484/*
485 * This function handles the command response of set/get MAC multicast
486 * address.
487 */
488static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
489 struct host_cmd_ds_command *resp)
490{
491 return 0;
492}
493
494/*
495 * This function handles the command response of get Tx rate query.
496 *
497 * Handling includes changing the header fields into CPU format
498 * and saving the Tx rate and HT information parameters in driver.
499 *
500 * Both rate configuration and current data rate can be retrieved
501 * with this request.
502 */
503static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
504 struct host_cmd_ds_command *resp)
505{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700506 priv->tx_rate = resp->params.tx_rate.tx_rate;
507 priv->tx_htinfo = resp->params.tx_rate.ht_info;
508 if (!priv->is_data_rate_auto)
509 priv->data_rate =
Bing Zhaoe3bea1c2011-11-16 20:40:35 -0800510 mwifiex_index_to_data_rate(priv, priv->tx_rate,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700511 priv->tx_htinfo);
512
513 return 0;
514}
515
516/*
517 * This function handles the command response of a deauthenticate
518 * command.
519 *
520 * If the deauthenticated MAC matches the current BSS MAC, the connection
521 * state is reset.
522 */
523static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
524 struct host_cmd_ds_command *resp)
525{
526 struct mwifiex_adapter *adapter = priv->adapter;
527
528 adapter->dbg.num_cmd_deauth++;
529 if (!memcmp(resp->params.deauth.mac_addr,
530 &priv->curr_bss_params.bss_descriptor.mac_address,
531 sizeof(resp->params.deauth.mac_addr)))
532 mwifiex_reset_connect_state(priv);
533
534 return 0;
535}
536
537/*
538 * This function handles the command response of ad-hoc stop.
539 *
540 * The function resets the connection state in driver.
541 */
542static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
543 struct host_cmd_ds_command *resp)
544{
545 mwifiex_reset_connect_state(priv);
546 return 0;
547}
548
549/*
550 * This function handles the command response of set/get key material.
551 *
552 * Handling includes updating the driver parameters to reflect the
553 * changes.
554 */
555static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
556 struct host_cmd_ds_command *resp)
557{
558 struct host_cmd_ds_802_11_key_material *key =
559 &resp->params.key_material;
560
561 if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700562 if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700563 dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
564 priv->wpa_is_gtk_set = true;
565 priv->scan_block = false;
566 }
567 }
568
569 memset(priv->aes_key.key_param_set.key, 0,
570 sizeof(key->key_param_set.key));
571 priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
572 memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
573 le16_to_cpu(priv->aes_key.key_param_set.key_len));
574
575 return 0;
576}
577
578/*
579 * This function handles the command response of get 11d domain information.
580 */
581static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
582 struct host_cmd_ds_command *resp)
583{
584 struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
585 &resp->params.domain_info_resp;
586 struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
587 u16 action = le16_to_cpu(domain_info->action);
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700588 u8 no_of_triplet;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700589
590 no_of_triplet = (u8) ((le16_to_cpu(domain->header.len) -
591 IEEE80211_COUNTRY_STRING_LEN) /
592 sizeof(struct ieee80211_country_ie_triplet));
593
594 dev_dbg(priv->adapter->dev, "info: 11D Domain Info Resp:"
595 " no_of_triplet=%d\n", no_of_triplet);
596
597 if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
598 dev_warn(priv->adapter->dev,
599 "11D: invalid number of triplets %d "
600 "returned!!\n", no_of_triplet);
601 return -1;
602 }
603
604 switch (action) {
605 case HostCmd_ACT_GEN_SET: /* Proc Set Action */
606 break;
607 case HostCmd_ACT_GEN_GET:
608 break;
609 default:
610 dev_err(priv->adapter->dev,
611 "11D: invalid action:%d\n", domain_info->action);
612 return -1;
613 }
614
615 return 0;
616}
617
618/*
619 * This function handles the command response of get RF channel.
620 *
621 * Handling includes changing the header fields into CPU format
622 * and saving the new channel in driver.
623 */
624static int mwifiex_ret_802_11_rf_channel(struct mwifiex_private *priv,
625 struct host_cmd_ds_command *resp,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300626 u16 *data_buf)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700627{
628 struct host_cmd_ds_802_11_rf_channel *rf_channel =
629 &resp->params.rf_channel;
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300630 u16 new_channel = le16_to_cpu(rf_channel->current_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700631
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300632 if (priv->curr_bss_params.bss_descriptor.channel != new_channel) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633 dev_dbg(priv->adapter->dev, "cmd: Channel Switch: %d to %d\n",
634 priv->curr_bss_params.bss_descriptor.channel,
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300635 new_channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700636 /* Update the channel again */
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300637 priv->curr_bss_params.bss_descriptor.channel = new_channel;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700638 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700639
Dan Carpentera5e5aa62011-06-24 16:33:35 +0300640 if (data_buf)
641 *data_buf = new_channel;
642
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700643 return 0;
644}
645
646/*
647 * This function handles the command response of get extended version.
648 *
649 * Handling includes forming the extended version string and sending it
650 * to application.
651 */
652static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
653 struct host_cmd_ds_command *resp,
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700654 struct host_cmd_ds_version_ext *version_ext)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700655{
656 struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700657
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700658 if (version_ext) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700659 version_ext->version_str_sel = ver_ext->version_str_sel;
660 memcpy(version_ext->version_str, ver_ext->version_str,
661 sizeof(char) * 128);
662 memcpy(priv->version_str, ver_ext->version_str, 128);
663 }
664 return 0;
665}
666
667/*
668 * This function handles the command response of register access.
669 *
670 * The register value and offset are returned to the user. For EEPROM
671 * access, the byte count is also returned.
672 */
673static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
674 void *data_buf)
675{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700676 struct mwifiex_ds_reg_rw *reg_rw;
677 struct mwifiex_ds_read_eeprom *eeprom;
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700678 union reg {
679 struct host_cmd_ds_mac_reg_access *mac;
680 struct host_cmd_ds_bbp_reg_access *bbp;
681 struct host_cmd_ds_rf_reg_access *rf;
682 struct host_cmd_ds_pmic_reg_access *pmic;
683 struct host_cmd_ds_802_11_eeprom_access *eeprom;
684 } r;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700685
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700686 if (!data_buf)
687 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700688
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700689 reg_rw = data_buf;
690 eeprom = data_buf;
691 switch (type) {
692 case HostCmd_CMD_MAC_REG_ACCESS:
693 r.mac = (struct host_cmd_ds_mac_reg_access *)
694 &resp->params.mac_reg;
695 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac->offset));
696 reg_rw->value = r.mac->value;
697 break;
698 case HostCmd_CMD_BBP_REG_ACCESS:
699 r.bbp = (struct host_cmd_ds_bbp_reg_access *)
700 &resp->params.bbp_reg;
701 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp->offset));
702 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
703 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700704
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700705 case HostCmd_CMD_RF_REG_ACCESS:
706 r.rf = (struct host_cmd_ds_rf_reg_access *)
707 &resp->params.rf_reg;
708 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
709 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
710 break;
711 case HostCmd_CMD_PMIC_REG_ACCESS:
712 r.pmic = (struct host_cmd_ds_pmic_reg_access *)
713 &resp->params.pmic_reg;
714 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic->offset));
715 reg_rw->value = cpu_to_le32((u32) r.pmic->value);
716 break;
717 case HostCmd_CMD_CAU_REG_ACCESS:
718 r.rf = (struct host_cmd_ds_rf_reg_access *)
719 &resp->params.rf_reg;
720 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
721 reg_rw->value = cpu_to_le32((u32) r.rf->value);
722 break;
723 case HostCmd_CMD_802_11_EEPROM_ACCESS:
724 r.eeprom = (struct host_cmd_ds_802_11_eeprom_access *)
725 &resp->params.eeprom;
726 pr_debug("info: EEPROM read len=%x\n", r.eeprom->byte_count);
727 if (le16_to_cpu(eeprom->byte_count) <
728 le16_to_cpu(r.eeprom->byte_count)) {
729 eeprom->byte_count = cpu_to_le16(0);
730 pr_debug("info: EEPROM read length is too big\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700731 return -1;
732 }
Yogesh Ashok Powar985d68a2012-03-12 19:35:09 -0700733 eeprom->offset = r.eeprom->offset;
734 eeprom->byte_count = r.eeprom->byte_count;
735 if (le16_to_cpu(eeprom->byte_count) > 0)
736 memcpy(&eeprom->value, &r.eeprom->value,
737 le16_to_cpu(r.eeprom->byte_count));
738
739 break;
740 default:
741 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700742 }
743 return 0;
744}
745
746/*
747 * This function handles the command response of get IBSS coalescing status.
748 *
749 * If the received BSSID is different than the current one, the current BSSID,
750 * beacon interval, ATIM window and ERP information are updated, along with
751 * changing the ad-hoc state accordingly.
752 */
753static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
754 struct host_cmd_ds_command *resp)
755{
756 struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
757 &(resp->params.ibss_coalescing);
758 u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
759
760 if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
761 return 0;
762
763 dev_dbg(priv->adapter->dev,
764 "info: new BSSID %pM\n", ibss_coal_resp->bssid);
765
766 /* If rsp has NULL BSSID, Just return..... No Action */
767 if (!memcmp(ibss_coal_resp->bssid, zero_mac, ETH_ALEN)) {
768 dev_warn(priv->adapter->dev, "new BSSID is NULL\n");
769 return 0;
770 }
771
772 /* If BSSID is diff, modify current BSS parameters */
773 if (memcmp(priv->curr_bss_params.bss_descriptor.mac_address,
774 ibss_coal_resp->bssid, ETH_ALEN)) {
775 /* BSSID */
776 memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
777 ibss_coal_resp->bssid, ETH_ALEN);
778
779 /* Beacon Interval */
780 priv->curr_bss_params.bss_descriptor.beacon_period
781 = le16_to_cpu(ibss_coal_resp->beacon_interval);
782
783 /* ERP Information */
784 priv->curr_bss_params.bss_descriptor.erp_flags =
785 (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
786
787 priv->adhoc_state = ADHOC_COALESCED;
788 }
789
790 return 0;
791}
792
793/*
794 * This function handles the command responses.
795 *
796 * This is a generic function, which calls command specific
797 * response handlers based on the command ID.
798 */
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700799int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
800 struct host_cmd_ds_command *resp)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700801{
802 int ret = 0;
803 struct mwifiex_adapter *adapter = priv->adapter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700804 void *data_buf = adapter->curr_cmd->data_buf;
805
806 /* If the command is not successful, cleanup and return failure */
807 if (resp->result != HostCmd_RESULT_OK) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700808 mwifiex_process_cmdresp_error(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700809 return -1;
810 }
811 /* Command successful, handle response */
812 switch (cmdresp_no) {
813 case HostCmd_CMD_GET_HW_SPEC:
814 ret = mwifiex_ret_get_hw_spec(priv, resp);
815 break;
816 case HostCmd_CMD_MAC_CONTROL:
817 break;
818 case HostCmd_CMD_802_11_MAC_ADDRESS:
819 ret = mwifiex_ret_802_11_mac_address(priv, resp);
820 break;
821 case HostCmd_CMD_MAC_MULTICAST_ADR:
822 ret = mwifiex_ret_mac_multicast_adr(priv, resp);
823 break;
824 case HostCmd_CMD_TX_RATE_CFG:
825 ret = mwifiex_ret_tx_rate_cfg(priv, resp, data_buf);
826 break;
827 case HostCmd_CMD_802_11_SCAN:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700828 ret = mwifiex_ret_802_11_scan(priv, resp);
829 adapter->curr_cmd->wait_q_enabled = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700830 break;
831 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700832 ret = mwifiex_ret_802_11_scan(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700833 dev_dbg(adapter->dev,
834 "info: CMD_RESP: BG_SCAN result is ready!\n");
835 break;
836 case HostCmd_CMD_TXPWR_CFG:
Amitkumar Karwara5ffddb2011-06-20 15:21:48 -0700837 ret = mwifiex_ret_tx_power_cfg(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700838 break;
839 case HostCmd_CMD_802_11_PS_MODE_ENH:
840 ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
841 break;
842 case HostCmd_CMD_802_11_HS_CFG_ENH:
843 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
844 break;
845 case HostCmd_CMD_802_11_ASSOCIATE:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700846 ret = mwifiex_ret_802_11_associate(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700847 break;
848 case HostCmd_CMD_802_11_DEAUTHENTICATE:
849 ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
850 break;
851 case HostCmd_CMD_802_11_AD_HOC_START:
852 case HostCmd_CMD_802_11_AD_HOC_JOIN:
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700853 ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700854 break;
855 case HostCmd_CMD_802_11_AD_HOC_STOP:
856 ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
857 break;
858 case HostCmd_CMD_802_11_GET_LOG:
859 ret = mwifiex_ret_get_log(priv, resp, data_buf);
860 break;
861 case HostCmd_CMD_RSSI_INFO:
862 ret = mwifiex_ret_802_11_rssi_info(priv, resp, data_buf);
863 break;
864 case HostCmd_CMD_802_11_SNMP_MIB:
865 ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
866 break;
867 case HostCmd_CMD_802_11_TX_RATE_QUERY:
868 ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
869 break;
870 case HostCmd_CMD_802_11_RF_CHANNEL:
871 ret = mwifiex_ret_802_11_rf_channel(priv, resp, data_buf);
872 break;
873 case HostCmd_CMD_VERSION_EXT:
874 ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
875 break;
876 case HostCmd_CMD_FUNC_INIT:
877 case HostCmd_CMD_FUNC_SHUTDOWN:
878 break;
879 case HostCmd_CMD_802_11_KEY_MATERIAL:
880 ret = mwifiex_ret_802_11_key_material(priv, resp);
881 break;
882 case HostCmd_CMD_802_11D_DOMAIN_INFO:
883 ret = mwifiex_ret_802_11d_domain_info(priv, resp);
884 break;
885 case HostCmd_CMD_11N_ADDBA_REQ:
886 ret = mwifiex_ret_11n_addba_req(priv, resp);
887 break;
888 case HostCmd_CMD_11N_DELBA:
889 ret = mwifiex_ret_11n_delba(priv, resp);
890 break;
891 case HostCmd_CMD_11N_ADDBA_RSP:
892 ret = mwifiex_ret_11n_addba_resp(priv, resp);
893 break;
894 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
895 adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
896 tx_buf.buff_size);
897 adapter->tx_buf_size = (adapter->tx_buf_size /
898 MWIFIEX_SDIO_BLOCK_SIZE) *
899 MWIFIEX_SDIO_BLOCK_SIZE;
900 adapter->curr_tx_buf_size = adapter->tx_buf_size;
901 dev_dbg(adapter->dev,
902 "cmd: max_tx_buf_size=%d, tx_buf_size=%d\n",
903 adapter->max_tx_buf_size, adapter->tx_buf_size);
904
905 if (adapter->if_ops.update_mp_end_port)
906 adapter->if_ops.update_mp_end_port(adapter,
907 le16_to_cpu(resp->
908 params.
909 tx_buf.
910 mp_end_port));
911 break;
912 case HostCmd_CMD_AMSDU_AGGR_CTRL:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700913 ret = mwifiex_ret_amsdu_aggr_ctrl(resp, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700914 break;
915 case HostCmd_CMD_WMM_GET_STATUS:
916 ret = mwifiex_ret_wmm_get_status(priv, resp);
917 break;
918 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
919 ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
920 break;
921 case HostCmd_CMD_MAC_REG_ACCESS:
922 case HostCmd_CMD_BBP_REG_ACCESS:
923 case HostCmd_CMD_RF_REG_ACCESS:
924 case HostCmd_CMD_PMIC_REG_ACCESS:
925 case HostCmd_CMD_CAU_REG_ACCESS:
926 case HostCmd_CMD_802_11_EEPROM_ACCESS:
927 ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
928 break;
929 case HostCmd_CMD_SET_BSS_MODE:
930 break;
931 case HostCmd_CMD_11N_CFG:
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700932 ret = mwifiex_ret_11n_cfg(resp, data_buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700933 break;
Amitkumar Karward930fae2011-10-11 17:41:21 -0700934 case HostCmd_CMD_PCIE_DESC_DETAILS:
935 break;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700936 default:
937 dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
938 resp->command);
939 break;
940 }
941
942 return ret;
943}