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