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