powerpc/eeh: Fix PE#0 check in eeh_add_to_parent_pe()
[linux/fpc-iii.git] / drivers / net / wireless / mwifiex / sta_cmdresp.c
blob5f8da5924666275615482fd07de75fa46d4bfb4a
1 /*
2 * Marvell Wireless LAN device driver: station command response handling
4 * Copyright (C) 2011-2014, Marvell International Ltd.
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.
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.
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"
31 * This function handles the command response error case.
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.
37 * For Power Save command failure, we do not retry enter PS
38 * command in case of Ad-hoc mode.
40 * For all other response errors, the current command buffer is freed
41 * and returned to the free command queue.
43 static void
44 mwifiex_process_cmdresp_error(struct mwifiex_private *priv,
45 struct host_cmd_ds_command *resp)
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;
52 dev_err(adapter->dev, "CMD_RESP: cmd %#x error, result=%#x\n",
53 resp->command, resp->result);
55 if (adapter->curr_cmd->wait_q_enabled)
56 adapter->cmd_wait_q.status = -1;
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;
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);
83 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
85 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
86 adapter->scan_processing = false;
87 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
88 break;
90 case HostCmd_CMD_MAC_CONTROL:
91 break;
93 default:
94 break;
96 /* Handling errors here */
97 mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
99 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
100 adapter->curr_cmd = NULL;
101 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
105 * This function handles the command response of get RSSI info.
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
114 * The parameters are send to the application as well, along with
115 * calculated SNR values.
117 static int mwifiex_ret_802_11_rssi_info(struct mwifiex_private *priv,
118 struct host_cmd_ds_command *resp)
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;
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);
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);
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);
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);
137 if (priv->subsc_evt_rssi_state == EVENT_HANDLED)
138 return 0;
140 memset(subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
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);
154 subsc_evt->bcn_l_rssi_cfg.evt_freq = 1;
155 subsc_evt->bcn_h_rssi_cfg.evt_freq = 1;
157 priv->subsc_evt_rssi_state = EVENT_HANDLED;
159 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
160 0, 0, subsc_evt, false);
162 return 0;
166 * This function handles the command response of set/get SNMP
167 * MIB parameters.
169 * Handling includes changing the header fields into CPU format
170 * and saving the parameter in driver.
172 * The following parameters are supported -
173 * - Fragmentation threshold
174 * - RTS threshold
175 * - Short retry limit
177 static int mwifiex_ret_802_11_snmp_mib(struct mwifiex_private *priv,
178 struct host_cmd_ds_command *resp,
179 u32 *data_buf)
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;
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;
214 return 0;
218 * This function handles the command response of get log request
220 * Handling includes changing the header fields into CPU format
221 * and sending the received parameters to application.
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)
227 struct host_cmd_ds_802_11_get_log *get_log =
228 &resp->params.get_log;
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 stats->bcn_rcv_cnt = le32_to_cpu(get_log->bcn_rcv_cnt);
252 stats->bcn_miss_cnt = le32_to_cpu(get_log->bcn_miss_cnt);
255 return 0;
259 * This function handles the command response of set/get Tx rate
260 * configurations.
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
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.
272 static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
273 struct host_cmd_ds_command *resp)
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;
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);
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);
290 if (tlv_buf_left < (sizeof(*head) + tlv_buf_len))
291 break;
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;
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]);
308 if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
309 for (i = 0; i < ARRAY_SIZE(rate_scope->
310 vht_mcs_rate_bitmap);
311 i++)
312 priv->bitmap_rates[10 + i] =
313 le16_to_cpu(rate_scope->
314 vht_mcs_rate_bitmap[i]);
316 break;
317 /* Add RATE_DROP tlv here */
320 tlv_buf += (sizeof(*head) + tlv_buf_len);
321 tlv_buf_left -= (sizeof(*head) + tlv_buf_len);
324 priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
326 if (priv->is_data_rate_auto)
327 priv->data_rate = 0;
328 else
329 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
330 HostCmd_ACT_GEN_GET, 0, NULL, false);
332 return 0;
336 * This function handles the command response of get Tx power level.
338 * Handling includes saving the maximum and minimum Tx power levels
339 * in driver, as well as sending the values to user.
341 static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
343 int length, max_power = -1, min_power = -1;
344 struct mwifiex_types_power_group *pg_tlv_hdr;
345 struct mwifiex_power_group *pg;
347 if (!data_buf)
348 return -1;
350 pg_tlv_hdr = (struct mwifiex_types_power_group *)((u8 *)data_buf);
351 pg = (struct mwifiex_power_group *)
352 ((u8 *) pg_tlv_hdr + sizeof(struct mwifiex_types_power_group));
353 length = le16_to_cpu(pg_tlv_hdr->length);
355 /* At least one structure required to update power */
356 if (length < sizeof(struct mwifiex_power_group))
357 return 0;
359 max_power = pg->power_max;
360 min_power = pg->power_min;
361 length -= sizeof(struct mwifiex_power_group);
363 while (length >= sizeof(struct mwifiex_power_group)) {
364 pg++;
365 if (max_power < pg->power_max)
366 max_power = pg->power_max;
368 if (min_power > pg->power_min)
369 min_power = pg->power_min;
371 length -= sizeof(struct mwifiex_power_group);
373 priv->min_tx_power_level = (u8) min_power;
374 priv->max_tx_power_level = (u8) max_power;
376 return 0;
380 * This function handles the command response of set/get Tx power
381 * configurations.
383 * Handling includes changing the header fields into CPU format
384 * and saving the current Tx power level in driver.
386 static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
387 struct host_cmd_ds_command *resp)
389 struct mwifiex_adapter *adapter = priv->adapter;
390 struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
391 struct mwifiex_types_power_group *pg_tlv_hdr;
392 struct mwifiex_power_group *pg;
393 u16 action = le16_to_cpu(txp_cfg->action);
394 u16 tlv_buf_left;
396 pg_tlv_hdr = (struct mwifiex_types_power_group *)
397 ((u8 *)txp_cfg +
398 sizeof(struct host_cmd_ds_txpwr_cfg));
400 pg = (struct mwifiex_power_group *)
401 ((u8 *)pg_tlv_hdr +
402 sizeof(struct mwifiex_types_power_group));
404 tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*txp_cfg);
405 if (tlv_buf_left <
406 le16_to_cpu(pg_tlv_hdr->length) + sizeof(*pg_tlv_hdr))
407 return 0;
409 switch (action) {
410 case HostCmd_ACT_GEN_GET:
411 if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
412 mwifiex_get_power_level(priv, pg_tlv_hdr);
414 priv->tx_power_level = (u16) pg->power_min;
415 break;
417 case HostCmd_ACT_GEN_SET:
418 if (!le32_to_cpu(txp_cfg->mode))
419 break;
421 if (pg->power_max == pg->power_min)
422 priv->tx_power_level = (u16) pg->power_min;
423 break;
424 default:
425 dev_err(adapter->dev, "CMD_RESP: unknown cmd action %d\n",
426 action);
427 return 0;
429 dev_dbg(adapter->dev,
430 "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
431 priv->tx_power_level, priv->max_tx_power_level,
432 priv->min_tx_power_level);
434 return 0;
438 * This function handles the command response of get RF Tx power.
440 static int mwifiex_ret_rf_tx_power(struct mwifiex_private *priv,
441 struct host_cmd_ds_command *resp)
443 struct host_cmd_ds_rf_tx_pwr *txp = &resp->params.txp;
444 u16 action = le16_to_cpu(txp->action);
446 priv->tx_power_level = le16_to_cpu(txp->cur_level);
448 if (action == HostCmd_ACT_GEN_GET) {
449 priv->max_tx_power_level = txp->max_power;
450 priv->min_tx_power_level = txp->min_power;
453 dev_dbg(priv->adapter->dev,
454 "Current TxPower Level=%d, Max Power=%d, Min Power=%d\n",
455 priv->tx_power_level, priv->max_tx_power_level,
456 priv->min_tx_power_level);
458 return 0;
462 * This function handles the command response of set rf antenna
464 static int mwifiex_ret_rf_antenna(struct mwifiex_private *priv,
465 struct host_cmd_ds_command *resp)
467 struct host_cmd_ds_rf_ant_mimo *ant_mimo = &resp->params.ant_mimo;
468 struct host_cmd_ds_rf_ant_siso *ant_siso = &resp->params.ant_siso;
469 struct mwifiex_adapter *adapter = priv->adapter;
471 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2)
472 dev_dbg(adapter->dev,
473 "RF_ANT_RESP: Tx action = 0x%x, Tx Mode = 0x%04x"
474 " Rx action = 0x%x, Rx Mode = 0x%04x\n",
475 le16_to_cpu(ant_mimo->action_tx),
476 le16_to_cpu(ant_mimo->tx_ant_mode),
477 le16_to_cpu(ant_mimo->action_rx),
478 le16_to_cpu(ant_mimo->rx_ant_mode));
479 else
480 dev_dbg(adapter->dev,
481 "RF_ANT_RESP: action = 0x%x, Mode = 0x%04x\n",
482 le16_to_cpu(ant_siso->action),
483 le16_to_cpu(ant_siso->ant_mode));
485 return 0;
489 * This function handles the command response of set/get MAC address.
491 * Handling includes saving the MAC address in driver.
493 static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
494 struct host_cmd_ds_command *resp)
496 struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
497 &resp->params.mac_addr;
499 memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
501 dev_dbg(priv->adapter->dev,
502 "info: set mac address: %pM\n", priv->curr_addr);
504 return 0;
508 * This function handles the command response of set/get MAC multicast
509 * address.
511 static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
512 struct host_cmd_ds_command *resp)
514 return 0;
518 * This function handles the command response of get Tx rate query.
520 * Handling includes changing the header fields into CPU format
521 * and saving the Tx rate and HT information parameters in driver.
523 * Both rate configuration and current data rate can be retrieved
524 * with this request.
526 static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
527 struct host_cmd_ds_command *resp)
529 priv->tx_rate = resp->params.tx_rate.tx_rate;
530 priv->tx_htinfo = resp->params.tx_rate.ht_info;
531 if (!priv->is_data_rate_auto)
532 priv->data_rate =
533 mwifiex_index_to_data_rate(priv, priv->tx_rate,
534 priv->tx_htinfo);
536 return 0;
540 * This function handles the command response of a deauthenticate
541 * command.
543 * If the deauthenticated MAC matches the current BSS MAC, the connection
544 * state is reset.
546 static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
547 struct host_cmd_ds_command *resp)
549 struct mwifiex_adapter *adapter = priv->adapter;
551 adapter->dbg.num_cmd_deauth++;
552 if (!memcmp(resp->params.deauth.mac_addr,
553 &priv->curr_bss_params.bss_descriptor.mac_address,
554 sizeof(resp->params.deauth.mac_addr)))
555 mwifiex_reset_connect_state(priv, WLAN_REASON_DEAUTH_LEAVING);
557 return 0;
561 * This function handles the command response of ad-hoc stop.
563 * The function resets the connection state in driver.
565 static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
566 struct host_cmd_ds_command *resp)
568 mwifiex_reset_connect_state(priv, WLAN_REASON_DEAUTH_LEAVING);
569 return 0;
573 * This function handles the command response of set/get v1 key material.
575 * Handling includes updating the driver parameters to reflect the
576 * changes.
578 static int mwifiex_ret_802_11_key_material_v1(struct mwifiex_private *priv,
579 struct host_cmd_ds_command *resp)
581 struct host_cmd_ds_802_11_key_material *key =
582 &resp->params.key_material;
584 if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
585 if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
586 dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
587 priv->wpa_is_gtk_set = true;
588 priv->scan_block = false;
592 memset(priv->aes_key.key_param_set.key, 0,
593 sizeof(key->key_param_set.key));
594 priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
595 memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
596 le16_to_cpu(priv->aes_key.key_param_set.key_len));
598 return 0;
602 * This function handles the command response of set/get v2 key material.
604 * Handling includes updating the driver parameters to reflect the
605 * changes.
607 static int mwifiex_ret_802_11_key_material_v2(struct mwifiex_private *priv,
608 struct host_cmd_ds_command *resp)
610 struct host_cmd_ds_802_11_key_material_v2 *key_v2;
611 __le16 len;
613 key_v2 = &resp->params.key_material_v2;
614 if (le16_to_cpu(key_v2->action) == HostCmd_ACT_GEN_SET) {
615 if ((le16_to_cpu(key_v2->key_param_set.key_info) & KEY_MCAST)) {
616 dev_dbg(priv->adapter->dev, "info: key: GTK is set\n");
617 priv->wpa_is_gtk_set = true;
618 priv->scan_block = false;
622 if (key_v2->key_param_set.key_type != KEY_TYPE_ID_AES)
623 return 0;
625 memset(priv->aes_key_v2.key_param_set.key_params.aes.key, 0,
626 WLAN_KEY_LEN_CCMP);
627 priv->aes_key_v2.key_param_set.key_params.aes.key_len =
628 key_v2->key_param_set.key_params.aes.key_len;
629 len = priv->aes_key_v2.key_param_set.key_params.aes.key_len;
630 memcpy(priv->aes_key_v2.key_param_set.key_params.aes.key,
631 key_v2->key_param_set.key_params.aes.key, le16_to_cpu(len));
633 return 0;
636 /* Wrapper function for processing response of key material command */
637 static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
638 struct host_cmd_ds_command *resp)
640 if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
641 return mwifiex_ret_802_11_key_material_v2(priv, resp);
642 else
643 return mwifiex_ret_802_11_key_material_v1(priv, resp);
647 * This function handles the command response of get 11d domain information.
649 static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
650 struct host_cmd_ds_command *resp)
652 struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
653 &resp->params.domain_info_resp;
654 struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
655 u16 action = le16_to_cpu(domain_info->action);
656 u8 no_of_triplet;
658 no_of_triplet = (u8) ((le16_to_cpu(domain->header.len)
659 - IEEE80211_COUNTRY_STRING_LEN)
660 / sizeof(struct ieee80211_country_ie_triplet));
662 dev_dbg(priv->adapter->dev,
663 "info: 11D Domain Info Resp: no_of_triplet=%d\n",
664 no_of_triplet);
666 if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
667 dev_warn(priv->adapter->dev,
668 "11D: invalid number of triplets %d returned\n",
669 no_of_triplet);
670 return -1;
673 switch (action) {
674 case HostCmd_ACT_GEN_SET: /* Proc Set Action */
675 break;
676 case HostCmd_ACT_GEN_GET:
677 break;
678 default:
679 dev_err(priv->adapter->dev,
680 "11D: invalid action:%d\n", domain_info->action);
681 return -1;
684 return 0;
688 * This function handles the command response of get extended version.
690 * Handling includes forming the extended version string and sending it
691 * to application.
693 static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
694 struct host_cmd_ds_command *resp,
695 struct host_cmd_ds_version_ext *version_ext)
697 struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
699 if (version_ext) {
700 version_ext->version_str_sel = ver_ext->version_str_sel;
701 memcpy(version_ext->version_str, ver_ext->version_str,
702 sizeof(char) * 128);
703 memcpy(priv->version_str, ver_ext->version_str, 128);
705 return 0;
709 * This function handles the command response of remain on channel.
711 static int
712 mwifiex_ret_remain_on_chan(struct mwifiex_private *priv,
713 struct host_cmd_ds_command *resp,
714 struct host_cmd_ds_remain_on_chan *roc_cfg)
716 struct host_cmd_ds_remain_on_chan *resp_cfg = &resp->params.roc_cfg;
718 if (roc_cfg)
719 memcpy(roc_cfg, resp_cfg, sizeof(*roc_cfg));
721 return 0;
725 * This function handles the command response of P2P mode cfg.
727 static int
728 mwifiex_ret_p2p_mode_cfg(struct mwifiex_private *priv,
729 struct host_cmd_ds_command *resp,
730 void *data_buf)
732 struct host_cmd_ds_p2p_mode_cfg *mode_cfg = &resp->params.mode_cfg;
734 if (data_buf)
735 *((u16 *)data_buf) = le16_to_cpu(mode_cfg->mode);
737 return 0;
741 * This function handles the command response of register access.
743 * The register value and offset are returned to the user. For EEPROM
744 * access, the byte count is also returned.
746 static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
747 void *data_buf)
749 struct mwifiex_ds_reg_rw *reg_rw;
750 struct mwifiex_ds_read_eeprom *eeprom;
751 union reg {
752 struct host_cmd_ds_mac_reg_access *mac;
753 struct host_cmd_ds_bbp_reg_access *bbp;
754 struct host_cmd_ds_rf_reg_access *rf;
755 struct host_cmd_ds_pmic_reg_access *pmic;
756 struct host_cmd_ds_802_11_eeprom_access *eeprom;
757 } r;
759 if (!data_buf)
760 return 0;
762 reg_rw = data_buf;
763 eeprom = data_buf;
764 switch (type) {
765 case HostCmd_CMD_MAC_REG_ACCESS:
766 r.mac = &resp->params.mac_reg;
767 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.mac->offset));
768 reg_rw->value = r.mac->value;
769 break;
770 case HostCmd_CMD_BBP_REG_ACCESS:
771 r.bbp = &resp->params.bbp_reg;
772 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.bbp->offset));
773 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
774 break;
776 case HostCmd_CMD_RF_REG_ACCESS:
777 r.rf = &resp->params.rf_reg;
778 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
779 reg_rw->value = cpu_to_le32((u32) r.bbp->value);
780 break;
781 case HostCmd_CMD_PMIC_REG_ACCESS:
782 r.pmic = &resp->params.pmic_reg;
783 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.pmic->offset));
784 reg_rw->value = cpu_to_le32((u32) r.pmic->value);
785 break;
786 case HostCmd_CMD_CAU_REG_ACCESS:
787 r.rf = &resp->params.rf_reg;
788 reg_rw->offset = cpu_to_le32((u32) le16_to_cpu(r.rf->offset));
789 reg_rw->value = cpu_to_le32((u32) r.rf->value);
790 break;
791 case HostCmd_CMD_802_11_EEPROM_ACCESS:
792 r.eeprom = &resp->params.eeprom;
793 pr_debug("info: EEPROM read len=%x\n", r.eeprom->byte_count);
794 if (le16_to_cpu(eeprom->byte_count) <
795 le16_to_cpu(r.eeprom->byte_count)) {
796 eeprom->byte_count = cpu_to_le16(0);
797 pr_debug("info: EEPROM read length is too big\n");
798 return -1;
800 eeprom->offset = r.eeprom->offset;
801 eeprom->byte_count = r.eeprom->byte_count;
802 if (le16_to_cpu(eeprom->byte_count) > 0)
803 memcpy(&eeprom->value, &r.eeprom->value,
804 le16_to_cpu(r.eeprom->byte_count));
806 break;
807 default:
808 return -1;
810 return 0;
814 * This function handles the command response of get IBSS coalescing status.
816 * If the received BSSID is different than the current one, the current BSSID,
817 * beacon interval, ATIM window and ERP information are updated, along with
818 * changing the ad-hoc state accordingly.
820 static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
821 struct host_cmd_ds_command *resp)
823 struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
824 &(resp->params.ibss_coalescing);
826 if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
827 return 0;
829 dev_dbg(priv->adapter->dev,
830 "info: new BSSID %pM\n", ibss_coal_resp->bssid);
832 /* If rsp has NULL BSSID, Just return..... No Action */
833 if (is_zero_ether_addr(ibss_coal_resp->bssid)) {
834 dev_warn(priv->adapter->dev, "new BSSID is NULL\n");
835 return 0;
838 /* If BSSID is diff, modify current BSS parameters */
839 if (!ether_addr_equal(priv->curr_bss_params.bss_descriptor.mac_address, ibss_coal_resp->bssid)) {
840 /* BSSID */
841 memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
842 ibss_coal_resp->bssid, ETH_ALEN);
844 /* Beacon Interval */
845 priv->curr_bss_params.bss_descriptor.beacon_period
846 = le16_to_cpu(ibss_coal_resp->beacon_interval);
848 /* ERP Information */
849 priv->curr_bss_params.bss_descriptor.erp_flags =
850 (u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
852 priv->adhoc_state = ADHOC_COALESCED;
855 return 0;
857 static int mwifiex_ret_tdls_oper(struct mwifiex_private *priv,
858 struct host_cmd_ds_command *resp)
860 struct host_cmd_ds_tdls_oper *cmd_tdls_oper = &resp->params.tdls_oper;
861 u16 reason = le16_to_cpu(cmd_tdls_oper->reason);
862 u16 action = le16_to_cpu(cmd_tdls_oper->tdls_action);
863 struct mwifiex_sta_node *node =
864 mwifiex_get_sta_entry(priv, cmd_tdls_oper->peer_mac);
866 switch (action) {
867 case ACT_TDLS_DELETE:
868 if (reason) {
869 if (!node || reason == TDLS_ERR_LINK_NONEXISTENT)
870 dev_dbg(priv->adapter->dev,
871 "TDLS link delete for %pM failed: reason %d\n",
872 cmd_tdls_oper->peer_mac, reason);
873 else
874 dev_err(priv->adapter->dev,
875 "TDLS link delete for %pM failed: reason %d\n",
876 cmd_tdls_oper->peer_mac, reason);
877 } else {
878 dev_dbg(priv->adapter->dev,
879 "TDLS link delete for %pM successful\n",
880 cmd_tdls_oper->peer_mac);
882 break;
883 case ACT_TDLS_CREATE:
884 if (reason) {
885 dev_err(priv->adapter->dev,
886 "TDLS link creation for %pM failed: reason %d",
887 cmd_tdls_oper->peer_mac, reason);
888 if (node && reason != TDLS_ERR_LINK_EXISTS)
889 node->tdls_status = TDLS_SETUP_FAILURE;
890 } else {
891 dev_dbg(priv->adapter->dev,
892 "TDLS link creation for %pM successful",
893 cmd_tdls_oper->peer_mac);
895 break;
896 case ACT_TDLS_CONFIG:
897 if (reason) {
898 dev_err(priv->adapter->dev,
899 "TDLS link config for %pM failed, reason %d\n",
900 cmd_tdls_oper->peer_mac, reason);
901 if (node)
902 node->tdls_status = TDLS_SETUP_FAILURE;
903 } else {
904 dev_dbg(priv->adapter->dev,
905 "TDLS link config for %pM successful\n",
906 cmd_tdls_oper->peer_mac);
908 break;
909 default:
910 dev_err(priv->adapter->dev,
911 "Unknown TDLS command action response %d", action);
912 return -1;
915 return 0;
918 * This function handles the command response for subscribe event command.
920 static int mwifiex_ret_subsc_evt(struct mwifiex_private *priv,
921 struct host_cmd_ds_command *resp)
923 struct host_cmd_ds_802_11_subsc_evt *cmd_sub_event =
924 &resp->params.subsc_evt;
926 /* For every subscribe event command (Get/Set/Clear), FW reports the
927 * current set of subscribed events*/
928 dev_dbg(priv->adapter->dev, "Bitmap of currently subscribed events: %16x\n",
929 le16_to_cpu(cmd_sub_event->events));
931 return 0;
934 /* This function handles the command response of set_cfg_data */
935 static int mwifiex_ret_cfg_data(struct mwifiex_private *priv,
936 struct host_cmd_ds_command *resp)
938 if (resp->result != HostCmd_RESULT_OK) {
939 dev_err(priv->adapter->dev, "Cal data cmd resp failed\n");
940 return -1;
943 return 0;
947 * This function handles the command responses.
949 * This is a generic function, which calls command specific
950 * response handlers based on the command ID.
952 int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
953 struct host_cmd_ds_command *resp)
955 int ret = 0;
956 struct mwifiex_adapter *adapter = priv->adapter;
957 void *data_buf = adapter->curr_cmd->data_buf;
959 /* If the command is not successful, cleanup and return failure */
960 if (resp->result != HostCmd_RESULT_OK) {
961 mwifiex_process_cmdresp_error(priv, resp);
962 return -1;
964 /* Command successful, handle response */
965 switch (cmdresp_no) {
966 case HostCmd_CMD_GET_HW_SPEC:
967 ret = mwifiex_ret_get_hw_spec(priv, resp);
968 break;
969 case HostCmd_CMD_CFG_DATA:
970 ret = mwifiex_ret_cfg_data(priv, resp);
971 break;
972 case HostCmd_CMD_MAC_CONTROL:
973 break;
974 case HostCmd_CMD_802_11_MAC_ADDRESS:
975 ret = mwifiex_ret_802_11_mac_address(priv, resp);
976 break;
977 case HostCmd_CMD_MAC_MULTICAST_ADR:
978 ret = mwifiex_ret_mac_multicast_adr(priv, resp);
979 break;
980 case HostCmd_CMD_TX_RATE_CFG:
981 ret = mwifiex_ret_tx_rate_cfg(priv, resp);
982 break;
983 case HostCmd_CMD_802_11_SCAN:
984 ret = mwifiex_ret_802_11_scan(priv, resp);
985 adapter->curr_cmd->wait_q_enabled = false;
986 break;
987 case HostCmd_CMD_802_11_SCAN_EXT:
988 ret = mwifiex_ret_802_11_scan_ext(priv, resp);
989 adapter->curr_cmd->wait_q_enabled = false;
990 break;
991 case HostCmd_CMD_802_11_BG_SCAN_QUERY:
992 ret = mwifiex_ret_802_11_scan(priv, resp);
993 dev_dbg(adapter->dev,
994 "info: CMD_RESP: BG_SCAN result is ready!\n");
995 break;
996 case HostCmd_CMD_TXPWR_CFG:
997 ret = mwifiex_ret_tx_power_cfg(priv, resp);
998 break;
999 case HostCmd_CMD_RF_TX_PWR:
1000 ret = mwifiex_ret_rf_tx_power(priv, resp);
1001 break;
1002 case HostCmd_CMD_RF_ANTENNA:
1003 ret = mwifiex_ret_rf_antenna(priv, resp);
1004 break;
1005 case HostCmd_CMD_802_11_PS_MODE_ENH:
1006 ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
1007 break;
1008 case HostCmd_CMD_802_11_HS_CFG_ENH:
1009 ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
1010 break;
1011 case HostCmd_CMD_802_11_ASSOCIATE:
1012 ret = mwifiex_ret_802_11_associate(priv, resp);
1013 break;
1014 case HostCmd_CMD_802_11_DEAUTHENTICATE:
1015 ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
1016 break;
1017 case HostCmd_CMD_802_11_AD_HOC_START:
1018 case HostCmd_CMD_802_11_AD_HOC_JOIN:
1019 ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
1020 break;
1021 case HostCmd_CMD_802_11_AD_HOC_STOP:
1022 ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
1023 break;
1024 case HostCmd_CMD_802_11_GET_LOG:
1025 ret = mwifiex_ret_get_log(priv, resp, data_buf);
1026 break;
1027 case HostCmd_CMD_RSSI_INFO:
1028 ret = mwifiex_ret_802_11_rssi_info(priv, resp);
1029 break;
1030 case HostCmd_CMD_802_11_SNMP_MIB:
1031 ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
1032 break;
1033 case HostCmd_CMD_802_11_TX_RATE_QUERY:
1034 ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
1035 break;
1036 case HostCmd_CMD_VERSION_EXT:
1037 ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
1038 break;
1039 case HostCmd_CMD_REMAIN_ON_CHAN:
1040 ret = mwifiex_ret_remain_on_chan(priv, resp, data_buf);
1041 break;
1042 case HostCmd_CMD_11AC_CFG:
1043 break;
1044 case HostCmd_CMD_P2P_MODE_CFG:
1045 ret = mwifiex_ret_p2p_mode_cfg(priv, resp, data_buf);
1046 break;
1047 case HostCmd_CMD_MGMT_FRAME_REG:
1048 case HostCmd_CMD_FUNC_INIT:
1049 case HostCmd_CMD_FUNC_SHUTDOWN:
1050 break;
1051 case HostCmd_CMD_802_11_KEY_MATERIAL:
1052 ret = mwifiex_ret_802_11_key_material(priv, resp);
1053 break;
1054 case HostCmd_CMD_802_11D_DOMAIN_INFO:
1055 ret = mwifiex_ret_802_11d_domain_info(priv, resp);
1056 break;
1057 case HostCmd_CMD_11N_ADDBA_REQ:
1058 ret = mwifiex_ret_11n_addba_req(priv, resp);
1059 break;
1060 case HostCmd_CMD_11N_DELBA:
1061 ret = mwifiex_ret_11n_delba(priv, resp);
1062 break;
1063 case HostCmd_CMD_11N_ADDBA_RSP:
1064 ret = mwifiex_ret_11n_addba_resp(priv, resp);
1065 break;
1066 case HostCmd_CMD_RECONFIGURE_TX_BUFF:
1067 adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
1068 tx_buf.buff_size);
1069 adapter->tx_buf_size = (adapter->tx_buf_size
1070 / MWIFIEX_SDIO_BLOCK_SIZE)
1071 * MWIFIEX_SDIO_BLOCK_SIZE;
1072 adapter->curr_tx_buf_size = adapter->tx_buf_size;
1073 dev_dbg(adapter->dev, "cmd: curr_tx_buf_size=%d\n",
1074 adapter->curr_tx_buf_size);
1076 if (adapter->if_ops.update_mp_end_port)
1077 adapter->if_ops.update_mp_end_port(adapter,
1078 le16_to_cpu(resp->params.tx_buf.mp_end_port));
1079 break;
1080 case HostCmd_CMD_AMSDU_AGGR_CTRL:
1081 break;
1082 case HostCmd_CMD_WMM_GET_STATUS:
1083 ret = mwifiex_ret_wmm_get_status(priv, resp);
1084 break;
1085 case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
1086 ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
1087 break;
1088 case HostCmd_CMD_MAC_REG_ACCESS:
1089 case HostCmd_CMD_BBP_REG_ACCESS:
1090 case HostCmd_CMD_RF_REG_ACCESS:
1091 case HostCmd_CMD_PMIC_REG_ACCESS:
1092 case HostCmd_CMD_CAU_REG_ACCESS:
1093 case HostCmd_CMD_802_11_EEPROM_ACCESS:
1094 ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
1095 break;
1096 case HostCmd_CMD_SET_BSS_MODE:
1097 break;
1098 case HostCmd_CMD_11N_CFG:
1099 break;
1100 case HostCmd_CMD_PCIE_DESC_DETAILS:
1101 break;
1102 case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
1103 ret = mwifiex_ret_subsc_evt(priv, resp);
1104 break;
1105 case HostCmd_CMD_UAP_SYS_CONFIG:
1106 break;
1107 case HostCmd_CMD_UAP_BSS_START:
1108 adapter->tx_lock_flag = false;
1109 adapter->pps_uapsd_mode = false;
1110 adapter->delay_null_pkt = false;
1111 priv->bss_started = 1;
1112 break;
1113 case HostCmd_CMD_UAP_BSS_STOP:
1114 priv->bss_started = 0;
1115 break;
1116 case HostCmd_CMD_UAP_STA_DEAUTH:
1117 break;
1118 case HostCmd_CMD_MEF_CFG:
1119 break;
1120 case HostCmd_CMD_COALESCE_CFG:
1121 break;
1122 case HostCmd_CMD_TDLS_OPER:
1123 ret = mwifiex_ret_tdls_oper(priv, resp);
1124 break;
1125 case HostCmd_CMD_CHAN_REPORT_REQUEST:
1126 break;
1127 default:
1128 dev_err(adapter->dev, "CMD_RESP: unknown cmd response %#x\n",
1129 resp->command);
1130 break;
1133 return ret;