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