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