]> Pileus Git - ~andy/linux/blob - drivers/net/wireless/mwifiex/sta_cmdresp.c
Merge tag 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik...
[~andy/linux] / 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,
61                         "PS_MODE_ENH cmd failed: 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                                         struct mwifiex_ds_get_signal *signal)
124 {
125         struct host_cmd_ds_802_11_rssi_info_rsp *rssi_info_rsp =
126                                                 &resp->params.rssi_info_rsp;
127
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 */
141         if (signal) {
142                 memset(signal, 0, sizeof(*signal));
143
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  */
184 static int mwifiex_ret_802_11_snmp_mib(struct mwifiex_private *priv,
185                                        struct host_cmd_ds_command *resp,
186                                        u32 *data_buf)
187 {
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);
191         u32 ul_temp;
192
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) {
197                 ul_temp = le16_to_cpu(*((__le16 *) (smib->value)));
198                 if (data_buf)
199                         *data_buf = ul_temp;
200                 switch (oid) {
201                 case FRAG_THRESH_I:
202                         dev_dbg(priv->adapter->dev,
203                                 "info: SNMP_RESP: FragThsd =%u\n", ul_temp);
204                         break;
205                 case RTS_THRESH_I:
206                         dev_dbg(priv->adapter->dev,
207                                 "info: SNMP_RESP: RTSThsd =%u\n", ul_temp);
208                         break;
209                 case SHORT_RETRY_LIM_I:
210                         dev_dbg(priv->adapter->dev,
211                                 "info: SNMP_RESP: TxRetryCount=%u\n", ul_temp);
212                         break;
213                 case DTIM_PERIOD_I:
214                         dev_dbg(priv->adapter->dev,
215                                 "info: SNMP_RESP: DTIM period=%u\n", ul_temp);
216                 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  */
230 static int mwifiex_ret_get_log(struct mwifiex_private *priv,
231                                struct host_cmd_ds_command *resp,
232                                struct mwifiex_ds_get_stats *stats)
233 {
234         struct host_cmd_ds_802_11_get_log *get_log =
235                 (struct host_cmd_ds_802_11_get_log *) &resp->params.get_log;
236
237         if (stats) {
238                 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  */
278 static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
279                                    struct host_cmd_ds_command *resp,
280                                    struct mwifiex_rate_cfg *ds_rate)
281 {
282         struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
283         struct mwifiex_rate_scope *rate_scope;
284         struct mwifiex_ie_types_header *head;
285         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
326                 ret = mwifiex_send_cmd_async(priv,
327                                           HostCmd_CMD_802_11_TX_RATE_QUERY,
328                                           HostCmd_ACT_GEN_GET, 0, NULL);
329
330         if (!ds_rate)
331                 return ret;
332
333         if (le16_to_cpu(rate_cfg->action) == HostCmd_ACT_GEN_GET) {
334                 if (priv->is_data_rate_auto) {
335                         ds_rate->is_rate_auto = 1;
336                 return ret;
337         }
338         ds_rate->rate = mwifiex_get_rate_index(priv->bitmap_rates,
339                                                sizeof(priv->bitmap_rates));
340
341         if (ds_rate->rate >= MWIFIEX_RATE_BITMAP_OFDM0 &&
342             ds_rate->rate <= MWIFIEX_RATE_BITMAP_OFDM7)
343                 ds_rate->rate -= (MWIFIEX_RATE_BITMAP_OFDM0 -
344                                   MWIFIEX_RATE_INDEX_OFDM0);
345
346         if (ds_rate->rate >= MWIFIEX_RATE_BITMAP_MCS0 &&
347             ds_rate->rate <= MWIFIEX_RATE_BITMAP_MCS127)
348                 ds_rate->rate -= (MWIFIEX_RATE_BITMAP_MCS0 -
349                                   MWIFIEX_RATE_INDEX_MCS0);
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  */
361 static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
362 {
363         int length, max_power = -1, min_power = -1;
364         struct mwifiex_types_power_group *pg_tlv_hdr;
365         struct mwifiex_power_group *pg;
366
367         if (!data_buf)
368                 return -1;
369
370         pg_tlv_hdr = (struct mwifiex_types_power_group *)
371                 ((u8 *) data_buf + sizeof(struct host_cmd_ds_txpwr_cfg));
372         pg = (struct mwifiex_power_group *)
373                 ((u8 *) pg_tlv_hdr + sizeof(struct mwifiex_types_power_group));
374         length = pg_tlv_hdr->length;
375         if (length > 0) {
376                 max_power = pg->power_max;
377                 min_power = pg->power_min;
378                 length -= sizeof(struct mwifiex_power_group);
379         }
380         while (length) {
381                 pg++;
382                 if (max_power < pg->power_max)
383                         max_power = pg->power_max;
384
385                 if (min_power > pg->power_min)
386                         min_power = pg->power_min;
387
388                 length -= sizeof(struct mwifiex_power_group);
389         }
390         if (pg_tlv_hdr->length > 0) {
391                 priv->min_tx_power_level = (u8) min_power;
392                 priv->max_tx_power_level = (u8) max_power;
393         }
394
395         return 0;
396 }
397
398 /*
399  * This function handles the command response of set/get Tx power
400  * configurations.
401  *
402  * Handling includes changing the header fields into CPU format
403  * and saving the current Tx power level in driver.
404  */
405 static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
406                                     struct host_cmd_ds_command *resp)
407 {
408         struct mwifiex_adapter *adapter = priv->adapter;
409         struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
410         struct mwifiex_types_power_group *pg_tlv_hdr;
411         struct mwifiex_power_group *pg;
412         u16 action = le16_to_cpu(txp_cfg->action);
413
414         switch (action) {
415         case HostCmd_ACT_GEN_GET:
416                 pg_tlv_hdr = (struct mwifiex_types_power_group *)
417                         ((u8 *) txp_cfg +
418                          sizeof(struct host_cmd_ds_txpwr_cfg));
419
420                 pg = (struct mwifiex_power_group *)
421                         ((u8 *) pg_tlv_hdr +
422                          sizeof(struct mwifiex_types_power_group));
423
424                 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
425                         mwifiex_get_power_level(priv, txp_cfg);
426
427                 priv->tx_power_level = (u16) pg->power_min;
428                 break;
429
430         case HostCmd_ACT_GEN_SET:
431                 if (!le32_to_cpu(txp_cfg->mode))
432                         break;
433
434                 pg_tlv_hdr = (struct mwifiex_types_power_group *)
435                         ((u8 *) txp_cfg +
436                          sizeof(struct host_cmd_ds_txpwr_cfg));
437
438                 pg = (struct mwifiex_power_group *)
439                         ((u8 *) pg_tlv_hdr +
440                          sizeof(struct mwifiex_types_power_group));
441
442                 if (pg->power_max == pg->power_min)
443                         priv->tx_power_level = (u16) pg->power_min;
444                 break;
445         default:
446                 dev_err(adapter->dev, "CMD_RESP: unknown cmd action %d\n",
447                         action);
448                 return 0;
449         }
450         dev_dbg(adapter->dev,
451                 "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
452                priv->tx_power_level, priv->max_tx_power_level,
453                priv->min_tx_power_level);
454
455         return 0;
456 }
457
458 /*
459  * This function handles the command response of set/get MAC address.
460  *
461  * Handling includes saving the MAC address in driver.
462  */
463 static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
464                                           struct host_cmd_ds_command *resp)
465 {
466         struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
467                                                         &resp->params.mac_addr;
468
469         memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
470
471         dev_dbg(priv->adapter->dev,
472                 "info: set mac address: %pM\n", priv->curr_addr);
473
474         return 0;
475 }
476
477 /*
478  * This function handles the command response of set/get MAC multicast
479  * address.
480  */
481 static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
482                                          struct host_cmd_ds_command *resp)
483 {
484         return 0;
485 }
486
487 /*
488  * This function handles the command response of get Tx rate query.
489  *
490  * Handling includes changing the header fields into CPU format
491  * and saving the Tx rate and HT information parameters in driver.
492  *
493  * Both rate configuration and current data rate can be retrieved
494  * with this request.
495  */
496 static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
497                                             struct host_cmd_ds_command *resp)
498 {
499         priv->tx_rate = resp->params.tx_rate.tx_rate;
500         priv->tx_htinfo = resp->params.tx_rate.ht_info;
501         if (!priv->is_data_rate_auto)
502                 priv->data_rate =
503                         mwifiex_index_to_data_rate(priv, priv->tx_rate,
504                                                    priv->tx_htinfo);
505
506         return 0;
507 }
508
509 /*
510  * This function handles the command response of a deauthenticate
511  * command.
512  *
513  * If the deauthenticated MAC matches the current BSS MAC, the connection
514  * state is reset.
515  */
516 static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
517                                              struct host_cmd_ds_command *resp)
518 {
519         struct mwifiex_adapter *adapter = priv->adapter;
520
521         adapter->dbg.num_cmd_deauth++;
522         if (!memcmp(resp->params.deauth.mac_addr,
523                     &priv->curr_bss_params.bss_descriptor.mac_address,
524                     sizeof(resp->params.deauth.mac_addr)))
525                 mwifiex_reset_connect_state(priv);
526
527         return 0;
528 }
529
530 /*
531  * This function handles the command response of ad-hoc stop.
532  *
533  * The function resets the connection state in driver.
534  */
535 static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
536                                           struct host_cmd_ds_command *resp)
537 {
538         mwifiex_reset_connect_state(priv);
539         return 0;
540 }
541
542 /*
543  * This function handles the command response of set/get key material.
544  *
545  * Handling includes updating the driver parameters to reflect the
546  * changes.
547  */
548 static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
549                                            struct host_cmd_ds_command *resp)
550 {
551         struct host_cmd_ds_802_11_key_material *key =
552                                                 &resp->params.key_material;
553
554         if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
555                 if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
556                         dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
557                         priv->wpa_is_gtk_set = true;
558                         priv->scan_block = false;
559                 }
560         }
561
562         memset(priv->aes_key.key_param_set.key, 0,
563                sizeof(key->key_param_set.key));
564         priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
565         memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
566                le16_to_cpu(priv->aes_key.key_param_set.key_len));
567
568         return 0;
569 }
570
571 /*
572  * This function handles the command response of get 11d domain information.
573  */
574 static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
575                                            struct host_cmd_ds_command *resp)
576 {
577         struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
578                 &resp->params.domain_info_resp;
579         struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
580         u16 action = le16_to_cpu(domain_info->action);
581         u8 no_of_triplet;
582
583         no_of_triplet = (u8) ((le16_to_cpu(domain->header.len)
584                                 - IEEE80211_COUNTRY_STRING_LEN)
585                               / sizeof(struct ieee80211_country_ie_triplet));
586
587         dev_dbg(priv->adapter->dev,
588                 "info: 11D Domain Info Resp: no_of_triplet=%d\n",
589                 no_of_triplet);
590
591         if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
592                 dev_warn(priv->adapter->dev,
593                          "11D: invalid number of triplets %d returned\n",
594                          no_of_triplet);
595                 return -1;
596         }
597
598         switch (action) {
599         case HostCmd_ACT_GEN_SET:  /* Proc Set Action */
600                 break;
601         case HostCmd_ACT_GEN_GET:
602                 break;
603         default:
604                 dev_err(priv->adapter->dev,
605                         "11D: invalid action:%d\n", domain_info->action);
606                 return -1;
607         }
608
609         return 0;
610 }
611
612 /*
613  * This function handles the command response of get RF channel.
614  *
615  * Handling includes changing the header fields into CPU format
616  * and saving the new channel in driver.
617  */
618 static int mwifiex_ret_802_11_rf_channel(struct mwifiex_private *priv,
619                                          struct host_cmd_ds_command *resp,
620                                          u16 *data_buf)
621 {
622         struct host_cmd_ds_802_11_rf_channel *rf_channel =
623                 &resp->params.rf_channel;
624         u16 new_channel = le16_to_cpu(rf_channel->current_channel);
625
626         if (priv->curr_bss_params.bss_descriptor.channel != new_channel) {
627                 dev_dbg(priv->adapter->dev, "cmd: Channel Switch: %d to %d\n",
628                         priv->curr_bss_params.bss_descriptor.channel,
629                         new_channel);
630                 /* Update the channel again */
631                 priv->curr_bss_params.bss_descriptor.channel = new_channel;
632         }
633
634         if (data_buf)
635                 *data_buf = new_channel;
636
637         return 0;
638 }
639
640 /*
641  * This function handles the command response of get extended version.
642  *
643  * Handling includes forming the extended version string and sending it
644  * to application.
645  */
646 static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
647                                struct host_cmd_ds_command *resp,
648                                struct host_cmd_ds_version_ext *version_ext)
649 {
650         struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
651
652         if (version_ext) {
653                 version_ext->version_str_sel = ver_ext->version_str_sel;
654                 memcpy(version_ext->version_str, ver_ext->version_str,
655                        sizeof(char) * 128);
656                 memcpy(priv->version_str, ver_ext->version_str, 128);
657         }
658         return 0;
659 }
660
661 /*
662  * This function handles the command response of register access.
663  *
664  * The register value and offset are returned to the user. For EEPROM
665  * access, the byte count is also returned.
666  */
667 static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
668                                   void *data_buf)
669 {
670         struct mwifiex_ds_reg_rw *reg_rw;
671         struct mwifiex_ds_read_eeprom *eeprom;
672         union reg {
673                 struct host_cmd_ds_mac_reg_access *mac;
674                 struct host_cmd_ds_bbp_reg_access *bbp;
675                 struct host_cmd_ds_rf_reg_access *rf;
676                 struct host_cmd_ds_pmic_reg_access *pmic;
677                 struct host_cmd_ds_802_11_eeprom_access *eeprom;
678         } r;
679
680         if (!data_buf)
681                 return 0;
682
683         reg_rw = data_buf;
684         eeprom = data_buf;
685         switch (type) {
686         case HostCmd_CMD_MAC_REG_ACCESS:
687                 r.mac = (struct host_cmd_ds_mac_reg_access *)
688                         &resp->params.mac_reg;
689                 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac->offset));
690                 reg_rw->value = r.mac->value;
691                 break;
692         case HostCmd_CMD_BBP_REG_ACCESS:
693                 r.bbp = (struct host_cmd_ds_bbp_reg_access *)
694                         &resp->params.bbp_reg;
695                 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp->offset));
696                 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
697                 break;
698
699         case HostCmd_CMD_RF_REG_ACCESS:
700                 r.rf = (struct host_cmd_ds_rf_reg_access *)
701                        &resp->params.rf_reg;
702                 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
703                 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
704                 break;
705         case HostCmd_CMD_PMIC_REG_ACCESS:
706                 r.pmic = (struct host_cmd_ds_pmic_reg_access *)
707                          &resp->params.pmic_reg;
708                 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic->offset));
709                 reg_rw->value = cpu_to_le32((u32) r.pmic->value);
710                 break;
711         case HostCmd_CMD_CAU_REG_ACCESS:
712                 r.rf = (struct host_cmd_ds_rf_reg_access *)
713                        &resp->params.rf_reg;
714                 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
715                 reg_rw->value = cpu_to_le32((u32) r.rf->value);
716                 break;
717         case HostCmd_CMD_802_11_EEPROM_ACCESS:
718                 r.eeprom = (struct host_cmd_ds_802_11_eeprom_access *)
719                            &resp->params.eeprom;
720                 pr_debug("info: EEPROM read len=%x\n", r.eeprom->byte_count);
721                 if (le16_to_cpu(eeprom->byte_count) <
722                     le16_to_cpu(r.eeprom->byte_count)) {
723                         eeprom->byte_count = cpu_to_le16(0);
724                         pr_debug("info: EEPROM read length is too big\n");
725                         return -1;
726                 }
727                 eeprom->offset = r.eeprom->offset;
728                 eeprom->byte_count = r.eeprom->byte_count;
729                 if (le16_to_cpu(eeprom->byte_count) > 0)
730                         memcpy(&eeprom->value, &r.eeprom->value,
731                                le16_to_cpu(r.eeprom->byte_count));
732
733                 break;
734         default:
735                 return -1;
736         }
737         return 0;
738 }
739
740 /*
741  * This function handles the command response of get IBSS coalescing status.
742  *
743  * If the received BSSID is different than the current one, the current BSSID,
744  * beacon interval, ATIM window and ERP information are updated, along with
745  * changing the ad-hoc state accordingly.
746  */
747 static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
748                                               struct host_cmd_ds_command *resp)
749 {
750         struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
751                                         &(resp->params.ibss_coalescing);
752         u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
753
754         if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
755                 return 0;
756
757         dev_dbg(priv->adapter->dev,
758                 "info: new BSSID %pM\n", ibss_coal_resp->bssid);
759
760         /* If rsp has NULL BSSID, Just return..... No Action */
761         if (!memcmp(ibss_coal_resp->bssid, zero_mac, ETH_ALEN)) {
762                 dev_warn(priv->adapter->dev, "new BSSID is NULL\n");
763                 return 0;
764         }
765
766         /* If BSSID is diff, modify current BSS parameters */
767         if (memcmp(priv->curr_bss_params.bss_descriptor.mac_address,
768                    ibss_coal_resp->bssid, ETH_ALEN)) {
769                 /* BSSID */
770                 memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
771                        ibss_coal_resp->bssid, ETH_ALEN);
772
773                 /* Beacon Interval */
774                 priv->curr_bss_params.bss_descriptor.beacon_period
775                         = le16_to_cpu(ibss_coal_resp->beacon_interval);
776
777                 /* ERP Information */
778                 priv->curr_bss_params.bss_descriptor.erp_flags =
779                         (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
780
781                 priv->adhoc_state = ADHOC_COALESCED;
782         }
783
784         return 0;
785 }
786
787 /*
788  * This function handles the command responses.
789  *
790  * This is a generic function, which calls command specific
791  * response handlers based on the command ID.
792  */
793 int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
794                                 struct host_cmd_ds_command *resp)
795 {
796         int ret = 0;
797         struct mwifiex_adapter *adapter = priv->adapter;
798         void *data_buf = adapter->curr_cmd->data_buf;
799
800         /* If the command is not successful, cleanup and return failure */
801         if (resp->result != HostCmd_RESULT_OK) {
802                 mwifiex_process_cmdresp_error(priv, resp);
803                 return -1;
804         }
805         /* Command successful, handle response */
806         switch (cmdresp_no) {
807         case HostCmd_CMD_GET_HW_SPEC:
808                 ret = mwifiex_ret_get_hw_spec(priv, resp);
809                 break;
810         case HostCmd_CMD_MAC_CONTROL:
811                 break;
812         case HostCmd_CMD_802_11_MAC_ADDRESS:
813                 ret = mwifiex_ret_802_11_mac_address(priv, resp);
814                 break;
815         case HostCmd_CMD_MAC_MULTICAST_ADR:
816                 ret = mwifiex_ret_mac_multicast_adr(priv, resp);
817                 break;
818         case HostCmd_CMD_TX_RATE_CFG:
819                 ret = mwifiex_ret_tx_rate_cfg(priv, resp, data_buf);
820                 break;
821         case HostCmd_CMD_802_11_SCAN:
822                 ret = mwifiex_ret_802_11_scan(priv, resp);
823                 adapter->curr_cmd->wait_q_enabled = false;
824                 break;
825         case HostCmd_CMD_802_11_BG_SCAN_QUERY:
826                 ret = mwifiex_ret_802_11_scan(priv, resp);
827                 dev_dbg(adapter->dev,
828                         "info: CMD_RESP: BG_SCAN result is ready!\n");
829                 break;
830         case HostCmd_CMD_TXPWR_CFG:
831                 ret = mwifiex_ret_tx_power_cfg(priv, resp);
832                 break;
833         case HostCmd_CMD_802_11_PS_MODE_ENH:
834                 ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
835                 break;
836         case HostCmd_CMD_802_11_HS_CFG_ENH:
837                 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
838                 break;
839         case HostCmd_CMD_802_11_ASSOCIATE:
840                 ret = mwifiex_ret_802_11_associate(priv, resp);
841                 break;
842         case HostCmd_CMD_802_11_DEAUTHENTICATE:
843                 ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
844                 break;
845         case HostCmd_CMD_802_11_AD_HOC_START:
846         case HostCmd_CMD_802_11_AD_HOC_JOIN:
847                 ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
848                 break;
849         case HostCmd_CMD_802_11_AD_HOC_STOP:
850                 ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
851                 break;
852         case HostCmd_CMD_802_11_GET_LOG:
853                 ret = mwifiex_ret_get_log(priv, resp, data_buf);
854                 break;
855         case HostCmd_CMD_RSSI_INFO:
856                 ret = mwifiex_ret_802_11_rssi_info(priv, resp, data_buf);
857                 break;
858         case HostCmd_CMD_802_11_SNMP_MIB:
859                 ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
860                 break;
861         case HostCmd_CMD_802_11_TX_RATE_QUERY:
862                 ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
863                 break;
864         case HostCmd_CMD_802_11_RF_CHANNEL:
865                 ret = mwifiex_ret_802_11_rf_channel(priv, resp, data_buf);
866                 break;
867         case HostCmd_CMD_VERSION_EXT:
868                 ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
869                 break;
870         case HostCmd_CMD_FUNC_INIT:
871         case HostCmd_CMD_FUNC_SHUTDOWN:
872                 break;
873         case HostCmd_CMD_802_11_KEY_MATERIAL:
874                 ret = mwifiex_ret_802_11_key_material(priv, resp);
875                 break;
876         case HostCmd_CMD_802_11D_DOMAIN_INFO:
877                 ret = mwifiex_ret_802_11d_domain_info(priv, resp);
878                 break;
879         case HostCmd_CMD_11N_ADDBA_REQ:
880                 ret = mwifiex_ret_11n_addba_req(priv, resp);
881                 break;
882         case HostCmd_CMD_11N_DELBA:
883                 ret = mwifiex_ret_11n_delba(priv, resp);
884                 break;
885         case HostCmd_CMD_11N_ADDBA_RSP:
886                 ret = mwifiex_ret_11n_addba_resp(priv, resp);
887                 break;
888         case HostCmd_CMD_RECONFIGURE_TX_BUFF:
889                 adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
890                                                              tx_buf.buff_size);
891                 adapter->tx_buf_size = (adapter->tx_buf_size
892                                         / MWIFIEX_SDIO_BLOCK_SIZE)
893                                        * MWIFIEX_SDIO_BLOCK_SIZE;
894                 adapter->curr_tx_buf_size = adapter->tx_buf_size;
895                 dev_dbg(adapter->dev,
896                         "cmd: max_tx_buf_size=%d, tx_buf_size=%d\n",
897                         adapter->max_tx_buf_size, adapter->tx_buf_size);
898
899                 if (adapter->if_ops.update_mp_end_port)
900                         adapter->if_ops.update_mp_end_port(adapter,
901                                 le16_to_cpu(resp->params.tx_buf.mp_end_port));
902                 break;
903         case HostCmd_CMD_AMSDU_AGGR_CTRL:
904                 ret = mwifiex_ret_amsdu_aggr_ctrl(resp, data_buf);
905                 break;
906         case HostCmd_CMD_WMM_GET_STATUS:
907                 ret = mwifiex_ret_wmm_get_status(priv, resp);
908                 break;
909         case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
910                 ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
911                 break;
912         case HostCmd_CMD_MAC_REG_ACCESS:
913         case HostCmd_CMD_BBP_REG_ACCESS:
914         case HostCmd_CMD_RF_REG_ACCESS:
915         case HostCmd_CMD_PMIC_REG_ACCESS:
916         case HostCmd_CMD_CAU_REG_ACCESS:
917         case HostCmd_CMD_802_11_EEPROM_ACCESS:
918                 ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
919                 break;
920         case HostCmd_CMD_SET_BSS_MODE:
921                 break;
922         case HostCmd_CMD_11N_CFG:
923                 ret = mwifiex_ret_11n_cfg(resp, data_buf);
924                 break;
925         case HostCmd_CMD_PCIE_DESC_DETAILS:
926                 break;
927         default:
928                 dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
929                         resp->command);
930                 break;
931         }
932
933         return ret;
934 }