1 /*
2  * Marvell Wireless LAN device driver: station command response handling
3  *
4  * Copyright (C) 2011-2014, 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 mwifiex_adapter *adapter = priv->adapter;
48 	struct host_cmd_ds_802_11_ps_mode_enh *pm;
49 	unsigned long flags;
50 
51 	mwifiex_dbg(adapter, ERROR,
52 		    "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 		mwifiex_dbg(adapter, ERROR,
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 		mwifiex_cancel_scan(adapter);
74 		break;
75 
76 	case HostCmd_CMD_MAC_CONTROL:
77 		break;
78 
79 	case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG:
80 		mwifiex_dbg(adapter, MSG,
81 			    "SDIO RX single-port aggregation Not support\n");
82 		break;
83 
84 	default:
85 		break;
86 	}
87 	/* Handling errors here */
88 	mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
89 
90 	spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
91 	adapter->curr_cmd = NULL;
92 	spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
93 }
94 
95 /*
96  * This function handles the command response of get RSSI info.
97  *
98  * Handling includes changing the header fields into CPU format
99  * and saving the following parameters in driver -
100  *      - Last data and beacon RSSI value
101  *      - Average data and beacon RSSI value
102  *      - Last data and beacon NF value
103  *      - Average data and beacon NF value
104  *
105  * The parameters are send to the application as well, along with
106  * calculated SNR values.
107  */
108 static int mwifiex_ret_802_11_rssi_info(struct mwifiex_private *priv,
109 					struct host_cmd_ds_command *resp)
110 {
111 	struct host_cmd_ds_802_11_rssi_info_rsp *rssi_info_rsp =
112 						&resp->params.rssi_info_rsp;
113 	struct mwifiex_ds_misc_subsc_evt *subsc_evt =
114 						&priv->async_subsc_evt_storage;
115 
116 	priv->data_rssi_last = le16_to_cpu(rssi_info_rsp->data_rssi_last);
117 	priv->data_nf_last = le16_to_cpu(rssi_info_rsp->data_nf_last);
118 
119 	priv->data_rssi_avg = le16_to_cpu(rssi_info_rsp->data_rssi_avg);
120 	priv->data_nf_avg = le16_to_cpu(rssi_info_rsp->data_nf_avg);
121 
122 	priv->bcn_rssi_last = le16_to_cpu(rssi_info_rsp->bcn_rssi_last);
123 	priv->bcn_nf_last = le16_to_cpu(rssi_info_rsp->bcn_nf_last);
124 
125 	priv->bcn_rssi_avg = le16_to_cpu(rssi_info_rsp->bcn_rssi_avg);
126 	priv->bcn_nf_avg = le16_to_cpu(rssi_info_rsp->bcn_nf_avg);
127 
128 	if (priv->subsc_evt_rssi_state == EVENT_HANDLED)
129 		return 0;
130 
131 	memset(subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
132 
133 	/* Resubscribe low and high rssi events with new thresholds */
134 	subsc_evt->events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
135 	subsc_evt->action = HostCmd_ACT_BITWISE_SET;
136 	if (priv->subsc_evt_rssi_state == RSSI_LOW_RECVD) {
137 		subsc_evt->bcn_l_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg -
138 				priv->cqm_rssi_hyst);
139 		subsc_evt->bcn_h_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
140 	} else if (priv->subsc_evt_rssi_state == RSSI_HIGH_RECVD) {
141 		subsc_evt->bcn_l_rssi_cfg.abs_value = abs(priv->cqm_rssi_thold);
142 		subsc_evt->bcn_h_rssi_cfg.abs_value = abs(priv->bcn_rssi_avg +
143 				priv->cqm_rssi_hyst);
144 	}
145 	subsc_evt->bcn_l_rssi_cfg.evt_freq = 1;
146 	subsc_evt->bcn_h_rssi_cfg.evt_freq = 1;
147 
148 	priv->subsc_evt_rssi_state = EVENT_HANDLED;
149 
150 	mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
151 			 0, 0, subsc_evt, false);
152 
153 	return 0;
154 }
155 
156 /*
157  * This function handles the command response of set/get SNMP
158  * MIB parameters.
159  *
160  * Handling includes changing the header fields into CPU format
161  * and saving the parameter in driver.
162  *
163  * The following parameters are supported -
164  *      - Fragmentation threshold
165  *      - RTS threshold
166  *      - Short retry limit
167  */
168 static int mwifiex_ret_802_11_snmp_mib(struct mwifiex_private *priv,
169 				       struct host_cmd_ds_command *resp,
170 				       u32 *data_buf)
171 {
172 	struct host_cmd_ds_802_11_snmp_mib *smib = &resp->params.smib;
173 	u16 oid = le16_to_cpu(smib->oid);
174 	u16 query_type = le16_to_cpu(smib->query_type);
175 	u32 ul_temp;
176 
177 	mwifiex_dbg(priv->adapter, INFO,
178 		    "info: SNMP_RESP: oid value = %#x,\t"
179 		    "query_type = %#x, buf size = %#x\n",
180 		    oid, query_type, le16_to_cpu(smib->buf_size));
181 	if (query_type == HostCmd_ACT_GEN_GET) {
182 		ul_temp = get_unaligned_le16(smib->value);
183 		if (data_buf)
184 			*data_buf = ul_temp;
185 		switch (oid) {
186 		case FRAG_THRESH_I:
187 			mwifiex_dbg(priv->adapter, INFO,
188 				    "info: SNMP_RESP: FragThsd =%u\n",
189 				    ul_temp);
190 			break;
191 		case RTS_THRESH_I:
192 			mwifiex_dbg(priv->adapter, INFO,
193 				    "info: SNMP_RESP: RTSThsd =%u\n",
194 				    ul_temp);
195 			break;
196 		case SHORT_RETRY_LIM_I:
197 			mwifiex_dbg(priv->adapter, INFO,
198 				    "info: SNMP_RESP: TxRetryCount=%u\n",
199 				    ul_temp);
200 			break;
201 		case DTIM_PERIOD_I:
202 			mwifiex_dbg(priv->adapter, INFO,
203 				    "info: SNMP_RESP: DTIM period=%u\n",
204 				    ul_temp);
205 		default:
206 			break;
207 		}
208 	}
209 
210 	return 0;
211 }
212 
213 /*
214  * This function handles the command response of get log request
215  *
216  * Handling includes changing the header fields into CPU format
217  * and sending the received parameters to application.
218  */
219 static int mwifiex_ret_get_log(struct mwifiex_private *priv,
220 			       struct host_cmd_ds_command *resp,
221 			       struct mwifiex_ds_get_stats *stats)
222 {
223 	struct host_cmd_ds_802_11_get_log *get_log =
224 		&resp->params.get_log;
225 
226 	if (stats) {
227 		stats->mcast_tx_frame = le32_to_cpu(get_log->mcast_tx_frame);
228 		stats->failed = le32_to_cpu(get_log->failed);
229 		stats->retry = le32_to_cpu(get_log->retry);
230 		stats->multi_retry = le32_to_cpu(get_log->multi_retry);
231 		stats->frame_dup = le32_to_cpu(get_log->frame_dup);
232 		stats->rts_success = le32_to_cpu(get_log->rts_success);
233 		stats->rts_failure = le32_to_cpu(get_log->rts_failure);
234 		stats->ack_failure = le32_to_cpu(get_log->ack_failure);
235 		stats->rx_frag = le32_to_cpu(get_log->rx_frag);
236 		stats->mcast_rx_frame = le32_to_cpu(get_log->mcast_rx_frame);
237 		stats->fcs_error = le32_to_cpu(get_log->fcs_error);
238 		stats->tx_frame = le32_to_cpu(get_log->tx_frame);
239 		stats->wep_icv_error[0] =
240 			le32_to_cpu(get_log->wep_icv_err_cnt[0]);
241 		stats->wep_icv_error[1] =
242 			le32_to_cpu(get_log->wep_icv_err_cnt[1]);
243 		stats->wep_icv_error[2] =
244 			le32_to_cpu(get_log->wep_icv_err_cnt[2]);
245 		stats->wep_icv_error[3] =
246 			le32_to_cpu(get_log->wep_icv_err_cnt[3]);
247 		stats->bcn_rcv_cnt = le32_to_cpu(get_log->bcn_rcv_cnt);
248 		stats->bcn_miss_cnt = le32_to_cpu(get_log->bcn_miss_cnt);
249 	}
250 
251 	return 0;
252 }
253 
254 /*
255  * This function handles the command response of set/get Tx rate
256  * configurations.
257  *
258  * Handling includes changing the header fields into CPU format
259  * and saving the following parameters in driver -
260  *      - DSSS rate bitmap
261  *      - OFDM rate bitmap
262  *      - HT MCS rate bitmaps
263  *
264  * Based on the new rate bitmaps, the function re-evaluates if
265  * auto data rate has been activated. If not, it sends another
266  * query to the firmware to get the current Tx data rate.
267  */
268 static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
269 				   struct host_cmd_ds_command *resp)
270 {
271 	struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
272 	struct mwifiex_rate_scope *rate_scope;
273 	struct mwifiex_ie_types_header *head;
274 	u16 tlv, tlv_buf_len, tlv_buf_left;
275 	u8 *tlv_buf;
276 	u32 i;
277 
278 	tlv_buf = ((u8 *)rate_cfg) + sizeof(struct host_cmd_ds_tx_rate_cfg);
279 	tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*rate_cfg);
280 
281 	while (tlv_buf_left >= sizeof(*head)) {
282 		head = (struct mwifiex_ie_types_header *)tlv_buf;
283 		tlv = le16_to_cpu(head->type);
284 		tlv_buf_len = le16_to_cpu(head->len);
285 
286 		if (tlv_buf_left < (sizeof(*head) + tlv_buf_len))
287 			break;
288 
289 		switch (tlv) {
290 		case TLV_TYPE_RATE_SCOPE:
291 			rate_scope = (struct mwifiex_rate_scope *) tlv_buf;
292 			priv->bitmap_rates[0] =
293 				le16_to_cpu(rate_scope->hr_dsss_rate_bitmap);
294 			priv->bitmap_rates[1] =
295 				le16_to_cpu(rate_scope->ofdm_rate_bitmap);
296 			for (i = 0;
297 			     i < ARRAY_SIZE(rate_scope->ht_mcs_rate_bitmap);
298 			     i++)
299 				priv->bitmap_rates[2 + i] =
300 					le16_to_cpu(rate_scope->
301 						    ht_mcs_rate_bitmap[i]);
302 
303 			if (priv->adapter->fw_api_ver == MWIFIEX_FW_V15) {
304 				for (i = 0; i < ARRAY_SIZE(rate_scope->
305 							   vht_mcs_rate_bitmap);
306 				     i++)
307 					priv->bitmap_rates[10 + i] =
308 					    le16_to_cpu(rate_scope->
309 							vht_mcs_rate_bitmap[i]);
310 			}
311 			break;
312 			/* Add RATE_DROP tlv here */
313 		}
314 
315 		tlv_buf += (sizeof(*head) + tlv_buf_len);
316 		tlv_buf_left -= (sizeof(*head) + tlv_buf_len);
317 	}
318 
319 	priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
320 
321 	if (priv->is_data_rate_auto)
322 		priv->data_rate = 0;
323 	else
324 		return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
325 					HostCmd_ACT_GEN_GET, 0, NULL, false);
326 
327 	return 0;
328 }
329 
330 /*
331  * This function handles the command response of get Tx power level.
332  *
333  * Handling includes saving the maximum and minimum Tx power levels
334  * in driver, as well as sending the values to user.
335  */
336 static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
337 {
338 	int length, max_power = -1, min_power = -1;
339 	struct mwifiex_types_power_group *pg_tlv_hdr;
340 	struct mwifiex_power_group *pg;
341 
342 	if (!data_buf)
343 		return -1;
344 
345 	pg_tlv_hdr = (struct mwifiex_types_power_group *)((u8 *)data_buf);
346 	pg = (struct mwifiex_power_group *)
347 		((u8 *) pg_tlv_hdr + sizeof(struct mwifiex_types_power_group));
348 	length = le16_to_cpu(pg_tlv_hdr->length);
349 
350 	/* At least one structure required to update power */
351 	if (length < sizeof(struct mwifiex_power_group))
352 		return 0;
353 
354 	max_power = pg->power_max;
355 	min_power = pg->power_min;
356 	length -= sizeof(struct mwifiex_power_group);
357 
358 	while (length >= sizeof(struct mwifiex_power_group)) {
359 		pg++;
360 		if (max_power < pg->power_max)
361 			max_power = pg->power_max;
362 
363 		if (min_power > pg->power_min)
364 			min_power = pg->power_min;
365 
366 		length -= sizeof(struct mwifiex_power_group);
367 	}
368 	priv->min_tx_power_level = (u8) min_power;
369 	priv->max_tx_power_level = (u8) max_power;
370 
371 	return 0;
372 }
373 
374 /*
375  * This function handles the command response of set/get Tx power
376  * configurations.
377  *
378  * Handling includes changing the header fields into CPU format
379  * and saving the current Tx power level in driver.
380  */
381 static int mwifiex_ret_tx_power_cfg(struct mwifiex_private *priv,
382 				    struct host_cmd_ds_command *resp)
383 {
384 	struct mwifiex_adapter *adapter = priv->adapter;
385 	struct host_cmd_ds_txpwr_cfg *txp_cfg = &resp->params.txp_cfg;
386 	struct mwifiex_types_power_group *pg_tlv_hdr;
387 	struct mwifiex_power_group *pg;
388 	u16 action = le16_to_cpu(txp_cfg->action);
389 	u16 tlv_buf_left;
390 
391 	pg_tlv_hdr = (struct mwifiex_types_power_group *)
392 		((u8 *)txp_cfg +
393 		 sizeof(struct host_cmd_ds_txpwr_cfg));
394 
395 	pg = (struct mwifiex_power_group *)
396 		((u8 *)pg_tlv_hdr +
397 		 sizeof(struct mwifiex_types_power_group));
398 
399 	tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*txp_cfg);
400 	if (tlv_buf_left <
401 			le16_to_cpu(pg_tlv_hdr->length) + sizeof(*pg_tlv_hdr))
402 		return 0;
403 
404 	switch (action) {
405 	case HostCmd_ACT_GEN_GET:
406 		if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
407 			mwifiex_get_power_level(priv, pg_tlv_hdr);
408 
409 		priv->tx_power_level = (u16) pg->power_min;
410 		break;
411 
412 	case HostCmd_ACT_GEN_SET:
413 		if (!le32_to_cpu(txp_cfg->mode))
414 			break;
415 
416 		if (pg->power_max == pg->power_min)
417 			priv->tx_power_level = (u16) pg->power_min;
418 		break;
419 	default:
420 		mwifiex_dbg(adapter, ERROR,
421 			    "CMD_RESP: unknown cmd action %d\n",
422 			    action);
423 		return 0;
424 	}
425 	mwifiex_dbg(adapter, INFO,
426 		    "info: Current TxPower Level = %d, Max Power=%d, Min Power=%d\n",
427 		    priv->tx_power_level, priv->max_tx_power_level,
428 		    priv->min_tx_power_level);
429 
430 	return 0;
431 }
432 
433 /*
434  * This function handles the command response of get RF Tx power.
435  */
436 static int mwifiex_ret_rf_tx_power(struct mwifiex_private *priv,
437 				   struct host_cmd_ds_command *resp)
438 {
439 	struct host_cmd_ds_rf_tx_pwr *txp = &resp->params.txp;
440 	u16 action = le16_to_cpu(txp->action);
441 
442 	priv->tx_power_level = le16_to_cpu(txp->cur_level);
443 
444 	if (action == HostCmd_ACT_GEN_GET) {
445 		priv->max_tx_power_level = txp->max_power;
446 		priv->min_tx_power_level = txp->min_power;
447 	}
448 
449 	mwifiex_dbg(priv->adapter, INFO,
450 		    "Current TxPower Level=%d, Max Power=%d, Min Power=%d\n",
451 		    priv->tx_power_level, priv->max_tx_power_level,
452 		    priv->min_tx_power_level);
453 
454 	return 0;
455 }
456 
457 /*
458  * This function handles the command response of set rf antenna
459  */
460 static int mwifiex_ret_rf_antenna(struct mwifiex_private *priv,
461 				  struct host_cmd_ds_command *resp)
462 {
463 	struct host_cmd_ds_rf_ant_mimo *ant_mimo = &resp->params.ant_mimo;
464 	struct host_cmd_ds_rf_ant_siso *ant_siso = &resp->params.ant_siso;
465 	struct mwifiex_adapter *adapter = priv->adapter;
466 
467 	if (adapter->hw_dev_mcs_support == HT_STREAM_2X2) {
468 		priv->tx_ant = le16_to_cpu(ant_mimo->tx_ant_mode);
469 		priv->rx_ant = le16_to_cpu(ant_mimo->rx_ant_mode);
470 		mwifiex_dbg(adapter, INFO,
471 			    "RF_ANT_RESP: Tx action = 0x%x, Tx Mode = 0x%04x\t"
472 			    "Rx action = 0x%x, Rx Mode = 0x%04x\n",
473 			    le16_to_cpu(ant_mimo->action_tx),
474 			    le16_to_cpu(ant_mimo->tx_ant_mode),
475 			    le16_to_cpu(ant_mimo->action_rx),
476 			    le16_to_cpu(ant_mimo->rx_ant_mode));
477 	} else {
478 		priv->tx_ant = le16_to_cpu(ant_siso->ant_mode);
479 		priv->rx_ant = le16_to_cpu(ant_siso->ant_mode);
480 		mwifiex_dbg(adapter, INFO,
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));
484 	}
485 	return 0;
486 }
487 
488 /*
489  * This function handles the command response of set/get MAC address.
490  *
491  * Handling includes saving the MAC address in driver.
492  */
493 static int mwifiex_ret_802_11_mac_address(struct mwifiex_private *priv,
494 					  struct host_cmd_ds_command *resp)
495 {
496 	struct host_cmd_ds_802_11_mac_address *cmd_mac_addr =
497 							&resp->params.mac_addr;
498 
499 	memcpy(priv->curr_addr, cmd_mac_addr->mac_addr, ETH_ALEN);
500 
501 	mwifiex_dbg(priv->adapter, INFO,
502 		    "info: set mac address: %pM\n", priv->curr_addr);
503 
504 	return 0;
505 }
506 
507 /*
508  * This function handles the command response of set/get MAC multicast
509  * address.
510  */
511 static int mwifiex_ret_mac_multicast_adr(struct mwifiex_private *priv,
512 					 struct host_cmd_ds_command *resp)
513 {
514 	return 0;
515 }
516 
517 /*
518  * This function handles the command response of get Tx rate query.
519  *
520  * Handling includes changing the header fields into CPU format
521  * and saving the Tx rate and HT information parameters in driver.
522  *
523  * Both rate configuration and current data rate can be retrieved
524  * with this request.
525  */
526 static int mwifiex_ret_802_11_tx_rate_query(struct mwifiex_private *priv,
527 					    struct host_cmd_ds_command *resp)
528 {
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);
535 
536 	return 0;
537 }
538 
539 /*
540  * This function handles the command response of a deauthenticate
541  * command.
542  *
543  * If the deauthenticated MAC matches the current BSS MAC, the connection
544  * state is reset.
545  */
546 static int mwifiex_ret_802_11_deauthenticate(struct mwifiex_private *priv,
547 					     struct host_cmd_ds_command *resp)
548 {
549 	struct mwifiex_adapter *adapter = priv->adapter;
550 
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,
556 					    false);
557 
558 	return 0;
559 }
560 
561 /*
562  * This function handles the command response of ad-hoc stop.
563  *
564  * The function resets the connection state in driver.
565  */
566 static int mwifiex_ret_802_11_ad_hoc_stop(struct mwifiex_private *priv,
567 					  struct host_cmd_ds_command *resp)
568 {
569 	mwifiex_reset_connect_state(priv, WLAN_REASON_DEAUTH_LEAVING, false);
570 	return 0;
571 }
572 
573 /*
574  * This function handles the command response of set/get v1 key material.
575  *
576  * Handling includes updating the driver parameters to reflect the
577  * changes.
578  */
579 static int mwifiex_ret_802_11_key_material_v1(struct mwifiex_private *priv,
580 					      struct host_cmd_ds_command *resp)
581 {
582 	struct host_cmd_ds_802_11_key_material *key =
583 						&resp->params.key_material;
584 
585 	if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
586 		if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
587 			mwifiex_dbg(priv->adapter, INFO,
588 				    "info: key: GTK is set\n");
589 			priv->wpa_is_gtk_set = true;
590 			priv->scan_block = false;
591 			priv->port_open = true;
592 		}
593 	}
594 
595 	memset(priv->aes_key.key_param_set.key, 0,
596 	       sizeof(key->key_param_set.key));
597 	priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
598 	memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
599 	       le16_to_cpu(priv->aes_key.key_param_set.key_len));
600 
601 	return 0;
602 }
603 
604 /*
605  * This function handles the command response of set/get v2 key material.
606  *
607  * Handling includes updating the driver parameters to reflect the
608  * changes.
609  */
610 static int mwifiex_ret_802_11_key_material_v2(struct mwifiex_private *priv,
611 					      struct host_cmd_ds_command *resp)
612 {
613 	struct host_cmd_ds_802_11_key_material_v2 *key_v2;
614 	__le16 len;
615 
616 	key_v2 = &resp->params.key_material_v2;
617 	if (le16_to_cpu(key_v2->action) == HostCmd_ACT_GEN_SET) {
618 		if ((le16_to_cpu(key_v2->key_param_set.key_info) & KEY_MCAST)) {
619 			mwifiex_dbg(priv->adapter, INFO, "info: key: GTK is set\n");
620 			priv->wpa_is_gtk_set = true;
621 			priv->scan_block = false;
622 			priv->port_open = true;
623 		}
624 	}
625 
626 	if (key_v2->key_param_set.key_type != KEY_TYPE_ID_AES)
627 		return 0;
628 
629 	memset(priv->aes_key_v2.key_param_set.key_params.aes.key, 0,
630 	       WLAN_KEY_LEN_CCMP);
631 	priv->aes_key_v2.key_param_set.key_params.aes.key_len =
632 				key_v2->key_param_set.key_params.aes.key_len;
633 	len = priv->aes_key_v2.key_param_set.key_params.aes.key_len;
634 	memcpy(priv->aes_key_v2.key_param_set.key_params.aes.key,
635 	       key_v2->key_param_set.key_params.aes.key, le16_to_cpu(len));
636 
637 	return 0;
638 }
639 
640 /* Wrapper function for processing response of key material command */
641 static int mwifiex_ret_802_11_key_material(struct mwifiex_private *priv,
642 					   struct host_cmd_ds_command *resp)
643 {
644 	if (priv->adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
645 		return mwifiex_ret_802_11_key_material_v2(priv, resp);
646 	else
647 		return mwifiex_ret_802_11_key_material_v1(priv, resp);
648 }
649 
650 /*
651  * This function handles the command response of get 11d domain information.
652  */
653 static int mwifiex_ret_802_11d_domain_info(struct mwifiex_private *priv,
654 					   struct host_cmd_ds_command *resp)
655 {
656 	struct host_cmd_ds_802_11d_domain_info_rsp *domain_info =
657 		&resp->params.domain_info_resp;
658 	struct mwifiex_ietypes_domain_param_set *domain = &domain_info->domain;
659 	u16 action = le16_to_cpu(domain_info->action);
660 	u8 no_of_triplet;
661 
662 	no_of_triplet = (u8) ((le16_to_cpu(domain->header.len)
663 				- IEEE80211_COUNTRY_STRING_LEN)
664 			      / sizeof(struct ieee80211_country_ie_triplet));
665 
666 	mwifiex_dbg(priv->adapter, INFO,
667 		    "info: 11D Domain Info Resp: no_of_triplet=%d\n",
668 		    no_of_triplet);
669 
670 	if (no_of_triplet > MWIFIEX_MAX_TRIPLET_802_11D) {
671 		mwifiex_dbg(priv->adapter, FATAL,
672 			    "11D: invalid number of triplets %d returned\n",
673 			    no_of_triplet);
674 		return -1;
675 	}
676 
677 	switch (action) {
678 	case HostCmd_ACT_GEN_SET:  /* Proc Set Action */
679 		break;
680 	case HostCmd_ACT_GEN_GET:
681 		break;
682 	default:
683 		mwifiex_dbg(priv->adapter, ERROR,
684 			    "11D: invalid action:%d\n", domain_info->action);
685 		return -1;
686 	}
687 
688 	return 0;
689 }
690 
691 /*
692  * This function handles the command response of get extended version.
693  *
694  * Handling includes forming the extended version string and sending it
695  * to application.
696  */
697 static int mwifiex_ret_ver_ext(struct mwifiex_private *priv,
698 			       struct host_cmd_ds_command *resp,
699 			       struct host_cmd_ds_version_ext *version_ext)
700 {
701 	struct host_cmd_ds_version_ext *ver_ext = &resp->params.verext;
702 
703 	if (version_ext) {
704 		version_ext->version_str_sel = ver_ext->version_str_sel;
705 		memcpy(version_ext->version_str, ver_ext->version_str,
706 		       sizeof(char) * 128);
707 		memcpy(priv->version_str, ver_ext->version_str, 128);
708 	}
709 	return 0;
710 }
711 
712 /*
713  * This function handles the command response of remain on channel.
714  */
715 static int
716 mwifiex_ret_remain_on_chan(struct mwifiex_private *priv,
717 			   struct host_cmd_ds_command *resp,
718 			   struct host_cmd_ds_remain_on_chan *roc_cfg)
719 {
720 	struct host_cmd_ds_remain_on_chan *resp_cfg = &resp->params.roc_cfg;
721 
722 	if (roc_cfg)
723 		memcpy(roc_cfg, resp_cfg, sizeof(*roc_cfg));
724 
725 	return 0;
726 }
727 
728 /*
729  * This function handles the command response of P2P mode cfg.
730  */
731 static int
732 mwifiex_ret_p2p_mode_cfg(struct mwifiex_private *priv,
733 			 struct host_cmd_ds_command *resp,
734 			 void *data_buf)
735 {
736 	struct host_cmd_ds_p2p_mode_cfg *mode_cfg = &resp->params.mode_cfg;
737 
738 	if (data_buf)
739 		put_unaligned_le16(le16_to_cpu(mode_cfg->mode), data_buf);
740 
741 	return 0;
742 }
743 
744 /* This function handles the command response of mem_access command
745  */
746 static int
747 mwifiex_ret_mem_access(struct mwifiex_private *priv,
748 		       struct host_cmd_ds_command *resp, void *pioctl_buf)
749 {
750 	struct host_cmd_ds_mem_access *mem = (void *)&resp->params.mem;
751 
752 	priv->mem_rw.addr = le32_to_cpu(mem->addr);
753 	priv->mem_rw.value = le32_to_cpu(mem->value);
754 
755 	return 0;
756 }
757 /*
758  * This function handles the command response of register access.
759  *
760  * The register value and offset are returned to the user. For EEPROM
761  * access, the byte count is also returned.
762  */
763 static int mwifiex_ret_reg_access(u16 type, struct host_cmd_ds_command *resp,
764 				  void *data_buf)
765 {
766 	struct mwifiex_ds_reg_rw *reg_rw;
767 	struct mwifiex_ds_read_eeprom *eeprom;
768 	union reg {
769 		struct host_cmd_ds_mac_reg_access *mac;
770 		struct host_cmd_ds_bbp_reg_access *bbp;
771 		struct host_cmd_ds_rf_reg_access *rf;
772 		struct host_cmd_ds_pmic_reg_access *pmic;
773 		struct host_cmd_ds_802_11_eeprom_access *eeprom;
774 	} r;
775 
776 	if (!data_buf)
777 		return 0;
778 
779 	reg_rw = data_buf;
780 	eeprom = data_buf;
781 	switch (type) {
782 	case HostCmd_CMD_MAC_REG_ACCESS:
783 		r.mac = &resp->params.mac_reg;
784 		reg_rw->offset = (u32) le16_to_cpu(r.mac->offset);
785 		reg_rw->value = le32_to_cpu(r.mac->value);
786 		break;
787 	case HostCmd_CMD_BBP_REG_ACCESS:
788 		r.bbp = &resp->params.bbp_reg;
789 		reg_rw->offset = (u32) le16_to_cpu(r.bbp->offset);
790 		reg_rw->value = (u32) r.bbp->value;
791 		break;
792 
793 	case HostCmd_CMD_RF_REG_ACCESS:
794 		r.rf = &resp->params.rf_reg;
795 		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
796 		reg_rw->value = (u32) r.bbp->value;
797 		break;
798 	case HostCmd_CMD_PMIC_REG_ACCESS:
799 		r.pmic = &resp->params.pmic_reg;
800 		reg_rw->offset = (u32) le16_to_cpu(r.pmic->offset);
801 		reg_rw->value = (u32) r.pmic->value;
802 		break;
803 	case HostCmd_CMD_CAU_REG_ACCESS:
804 		r.rf = &resp->params.rf_reg;
805 		reg_rw->offset = (u32) le16_to_cpu(r.rf->offset);
806 		reg_rw->value = (u32) r.rf->value;
807 		break;
808 	case HostCmd_CMD_802_11_EEPROM_ACCESS:
809 		r.eeprom = &resp->params.eeprom;
810 		pr_debug("info: EEPROM read len=%x\n",
811 				le16_to_cpu(r.eeprom->byte_count));
812 		if (eeprom->byte_count < le16_to_cpu(r.eeprom->byte_count)) {
813 			eeprom->byte_count = 0;
814 			pr_debug("info: EEPROM read length is too big\n");
815 			return -1;
816 		}
817 		eeprom->offset = le16_to_cpu(r.eeprom->offset);
818 		eeprom->byte_count = le16_to_cpu(r.eeprom->byte_count);
819 		if (eeprom->byte_count > 0)
820 			memcpy(&eeprom->value, &r.eeprom->value,
821 			       min((u16)MAX_EEPROM_DATA, eeprom->byte_count));
822 		break;
823 	default:
824 		return -1;
825 	}
826 	return 0;
827 }
828 
829 /*
830  * This function handles the command response of get IBSS coalescing status.
831  *
832  * If the received BSSID is different than the current one, the current BSSID,
833  * beacon interval, ATIM window and ERP information are updated, along with
834  * changing the ad-hoc state accordingly.
835  */
836 static int mwifiex_ret_ibss_coalescing_status(struct mwifiex_private *priv,
837 					      struct host_cmd_ds_command *resp)
838 {
839 	struct host_cmd_ds_802_11_ibss_status *ibss_coal_resp =
840 					&(resp->params.ibss_coalescing);
841 
842 	if (le16_to_cpu(ibss_coal_resp->action) == HostCmd_ACT_GEN_SET)
843 		return 0;
844 
845 	mwifiex_dbg(priv->adapter, INFO,
846 		    "info: new BSSID %pM\n", ibss_coal_resp->bssid);
847 
848 	/* If rsp has NULL BSSID, Just return..... No Action */
849 	if (is_zero_ether_addr(ibss_coal_resp->bssid)) {
850 		mwifiex_dbg(priv->adapter, FATAL, "new BSSID is NULL\n");
851 		return 0;
852 	}
853 
854 	/* If BSSID is diff, modify current BSS parameters */
855 	if (!ether_addr_equal(priv->curr_bss_params.bss_descriptor.mac_address, ibss_coal_resp->bssid)) {
856 		/* BSSID */
857 		memcpy(priv->curr_bss_params.bss_descriptor.mac_address,
858 		       ibss_coal_resp->bssid, ETH_ALEN);
859 
860 		/* Beacon Interval */
861 		priv->curr_bss_params.bss_descriptor.beacon_period
862 			= le16_to_cpu(ibss_coal_resp->beacon_interval);
863 
864 		/* ERP Information */
865 		priv->curr_bss_params.bss_descriptor.erp_flags =
866 			(u8) le16_to_cpu(ibss_coal_resp->use_g_rate_protect);
867 
868 		priv->adhoc_state = ADHOC_COALESCED;
869 	}
870 
871 	return 0;
872 }
873 static int mwifiex_ret_tdls_oper(struct mwifiex_private *priv,
874 				 struct host_cmd_ds_command *resp)
875 {
876 	struct host_cmd_ds_tdls_oper *cmd_tdls_oper = &resp->params.tdls_oper;
877 	u16 reason = le16_to_cpu(cmd_tdls_oper->reason);
878 	u16 action = le16_to_cpu(cmd_tdls_oper->tdls_action);
879 	struct mwifiex_sta_node *node =
880 			   mwifiex_get_sta_entry(priv, cmd_tdls_oper->peer_mac);
881 
882 	switch (action) {
883 	case ACT_TDLS_DELETE:
884 		if (reason) {
885 			if (!node || reason == TDLS_ERR_LINK_NONEXISTENT)
886 				mwifiex_dbg(priv->adapter, MSG,
887 					    "TDLS link delete for %pM failed: reason %d\n",
888 					    cmd_tdls_oper->peer_mac, reason);
889 			else
890 				mwifiex_dbg(priv->adapter, ERROR,
891 					    "TDLS link delete for %pM failed: reason %d\n",
892 					    cmd_tdls_oper->peer_mac, reason);
893 		} else {
894 			mwifiex_dbg(priv->adapter, MSG,
895 				    "TDLS link delete for %pM successful\n",
896 				    cmd_tdls_oper->peer_mac);
897 		}
898 		break;
899 	case ACT_TDLS_CREATE:
900 		if (reason) {
901 			mwifiex_dbg(priv->adapter, ERROR,
902 				    "TDLS link creation for %pM failed: reason %d",
903 				    cmd_tdls_oper->peer_mac, reason);
904 			if (node && reason != TDLS_ERR_LINK_EXISTS)
905 				node->tdls_status = TDLS_SETUP_FAILURE;
906 		} else {
907 			mwifiex_dbg(priv->adapter, MSG,
908 				    "TDLS link creation for %pM successful",
909 				    cmd_tdls_oper->peer_mac);
910 		}
911 		break;
912 	case ACT_TDLS_CONFIG:
913 		if (reason) {
914 			mwifiex_dbg(priv->adapter, ERROR,
915 				    "TDLS link config for %pM failed, reason %d\n",
916 				    cmd_tdls_oper->peer_mac, reason);
917 			if (node)
918 				node->tdls_status = TDLS_SETUP_FAILURE;
919 		} else {
920 			mwifiex_dbg(priv->adapter, MSG,
921 				    "TDLS link config for %pM successful\n",
922 				    cmd_tdls_oper->peer_mac);
923 		}
924 		break;
925 	default:
926 		mwifiex_dbg(priv->adapter, ERROR,
927 			    "Unknown TDLS command action response %d", action);
928 		return -1;
929 	}
930 
931 	return 0;
932 }
933 /*
934  * This function handles the command response for subscribe event command.
935  */
936 static int mwifiex_ret_subsc_evt(struct mwifiex_private *priv,
937 				 struct host_cmd_ds_command *resp)
938 {
939 	struct host_cmd_ds_802_11_subsc_evt *cmd_sub_event =
940 		&resp->params.subsc_evt;
941 
942 	/* For every subscribe event command (Get/Set/Clear), FW reports the
943 	 * current set of subscribed events*/
944 	mwifiex_dbg(priv->adapter, EVENT,
945 		    "Bitmap of currently subscribed events: %16x\n",
946 		    le16_to_cpu(cmd_sub_event->events));
947 
948 	return 0;
949 }
950 
951 static int mwifiex_ret_uap_sta_list(struct mwifiex_private *priv,
952 				    struct host_cmd_ds_command *resp)
953 {
954 	struct host_cmd_ds_sta_list *sta_list =
955 		&resp->params.sta_list;
956 	struct mwifiex_ie_types_sta_info *sta_info = (void *)&sta_list->tlv;
957 	int i;
958 	struct mwifiex_sta_node *sta_node;
959 
960 	for (i = 0; i < (le16_to_cpu(sta_list->sta_count)); i++) {
961 		sta_node = mwifiex_get_sta_entry(priv, sta_info->mac);
962 		if (unlikely(!sta_node))
963 			continue;
964 
965 		sta_node->stats.rssi = sta_info->rssi;
966 		sta_info++;
967 	}
968 
969 	return 0;
970 }
971 
972 /* This function handles the command response of set_cfg_data */
973 static int mwifiex_ret_cfg_data(struct mwifiex_private *priv,
974 				struct host_cmd_ds_command *resp)
975 {
976 	if (resp->result != HostCmd_RESULT_OK) {
977 		mwifiex_dbg(priv->adapter, ERROR, "Cal data cmd resp failed\n");
978 		return -1;
979 	}
980 
981 	return 0;
982 }
983 
984 /** This Function handles the command response of sdio rx aggr */
985 static int mwifiex_ret_sdio_rx_aggr_cfg(struct mwifiex_private *priv,
986 					struct host_cmd_ds_command *resp)
987 {
988 	struct mwifiex_adapter *adapter = priv->adapter;
989 	struct host_cmd_sdio_sp_rx_aggr_cfg *cfg =
990 				&resp->params.sdio_rx_aggr_cfg;
991 
992 	adapter->sdio_rx_aggr_enable = cfg->enable;
993 	adapter->sdio_rx_block_size = le16_to_cpu(cfg->block_size);
994 
995 	return 0;
996 }
997 
998 static int mwifiex_ret_robust_coex(struct mwifiex_private *priv,
999 				   struct host_cmd_ds_command *resp,
1000 				   bool *is_timeshare)
1001 {
1002 	struct host_cmd_ds_robust_coex *coex = &resp->params.coex;
1003 	struct mwifiex_ie_types_robust_coex *coex_tlv;
1004 	u16 action = le16_to_cpu(coex->action);
1005 	u32 mode;
1006 
1007 	coex_tlv = (struct mwifiex_ie_types_robust_coex
1008 		    *)((u8 *)coex + sizeof(struct host_cmd_ds_robust_coex));
1009 	if (action == HostCmd_ACT_GEN_GET) {
1010 		mode = le32_to_cpu(coex_tlv->mode);
1011 		if (mode == MWIFIEX_COEX_MODE_TIMESHARE)
1012 			*is_timeshare = true;
1013 		else
1014 			*is_timeshare = false;
1015 	}
1016 
1017 	return 0;
1018 }
1019 
1020 static struct ieee80211_regdomain *
1021 mwifiex_create_custom_regdomain(struct mwifiex_private *priv,
1022 				u8 *buf, u16 buf_len)
1023 {
1024 	u16 num_chan = buf_len / 2;
1025 	struct ieee80211_regdomain *regd;
1026 	struct ieee80211_reg_rule *rule;
1027 	bool new_rule;
1028 	int idx, freq, prev_freq = 0;
1029 	u32 bw, prev_bw = 0;
1030 	u8 chflags, prev_chflags = 0, valid_rules = 0;
1031 
1032 	if (WARN_ON_ONCE(num_chan > NL80211_MAX_SUPP_REG_RULES))
1033 		return ERR_PTR(-EINVAL);
1034 
1035 	regd = kzalloc(struct_size(regd, reg_rules, num_chan), GFP_KERNEL);
1036 	if (!regd)
1037 		return ERR_PTR(-ENOMEM);
1038 
1039 	for (idx = 0; idx < num_chan; idx++) {
1040 		u8 chan;
1041 		enum nl80211_band band;
1042 
1043 		chan = *buf++;
1044 		if (!chan) {
1045 			kfree(regd);
1046 			return NULL;
1047 		}
1048 		chflags = *buf++;
1049 		band = (chan <= 14) ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
1050 		freq = ieee80211_channel_to_frequency(chan, band);
1051 		new_rule = false;
1052 
1053 		if (chflags & MWIFIEX_CHANNEL_DISABLED)
1054 			continue;
1055 
1056 		if (band == NL80211_BAND_5GHZ) {
1057 			if (!(chflags & MWIFIEX_CHANNEL_NOHT80))
1058 				bw = MHZ_TO_KHZ(80);
1059 			else if (!(chflags & MWIFIEX_CHANNEL_NOHT40))
1060 				bw = MHZ_TO_KHZ(40);
1061 			else
1062 				bw = MHZ_TO_KHZ(20);
1063 		} else {
1064 			if (!(chflags & MWIFIEX_CHANNEL_NOHT40))
1065 				bw = MHZ_TO_KHZ(40);
1066 			else
1067 				bw = MHZ_TO_KHZ(20);
1068 		}
1069 
1070 		if (idx == 0 || prev_chflags != chflags || prev_bw != bw ||
1071 		    freq - prev_freq > 20) {
1072 			valid_rules++;
1073 			new_rule = true;
1074 		}
1075 
1076 		rule = &regd->reg_rules[valid_rules - 1];
1077 
1078 		rule->freq_range.end_freq_khz = MHZ_TO_KHZ(freq + 10);
1079 
1080 		prev_chflags = chflags;
1081 		prev_freq = freq;
1082 		prev_bw = bw;
1083 
1084 		if (!new_rule)
1085 			continue;
1086 
1087 		rule->freq_range.start_freq_khz = MHZ_TO_KHZ(freq - 10);
1088 		rule->power_rule.max_eirp = DBM_TO_MBM(19);
1089 
1090 		if (chflags & MWIFIEX_CHANNEL_PASSIVE)
1091 			rule->flags = NL80211_RRF_NO_IR;
1092 
1093 		if (chflags & MWIFIEX_CHANNEL_DFS)
1094 			rule->flags = NL80211_RRF_DFS;
1095 
1096 		rule->freq_range.max_bandwidth_khz = bw;
1097 	}
1098 
1099 	regd->n_reg_rules = valid_rules;
1100 	regd->alpha2[0] = '9';
1101 	regd->alpha2[1] = '9';
1102 
1103 	return regd;
1104 }
1105 
1106 static int mwifiex_ret_chan_region_cfg(struct mwifiex_private *priv,
1107 				       struct host_cmd_ds_command *resp)
1108 {
1109 	struct host_cmd_ds_chan_region_cfg *reg = &resp->params.reg_cfg;
1110 	u16 action = le16_to_cpu(reg->action);
1111 	u16 tlv, tlv_buf_len, tlv_buf_left;
1112 	struct mwifiex_ie_types_header *head;
1113 	struct ieee80211_regdomain *regd;
1114 	u8 *tlv_buf;
1115 
1116 	if (action != HostCmd_ACT_GEN_GET)
1117 		return 0;
1118 
1119 	tlv_buf = (u8 *)reg + sizeof(*reg);
1120 	tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*reg);
1121 
1122 	while (tlv_buf_left >= sizeof(*head)) {
1123 		head = (struct mwifiex_ie_types_header *)tlv_buf;
1124 		tlv = le16_to_cpu(head->type);
1125 		tlv_buf_len = le16_to_cpu(head->len);
1126 
1127 		if (tlv_buf_left < (sizeof(*head) + tlv_buf_len))
1128 			break;
1129 
1130 		switch (tlv) {
1131 		case TLV_TYPE_CHAN_ATTR_CFG:
1132 			mwifiex_dbg_dump(priv->adapter, CMD_D, "CHAN:",
1133 					 (u8 *)head + sizeof(*head),
1134 					 tlv_buf_len);
1135 			regd = mwifiex_create_custom_regdomain(priv,
1136 				(u8 *)head + sizeof(*head), tlv_buf_len);
1137 			if (!IS_ERR(regd))
1138 				priv->adapter->regd = regd;
1139 			break;
1140 		}
1141 
1142 		tlv_buf += (sizeof(*head) + tlv_buf_len);
1143 		tlv_buf_left -= (sizeof(*head) + tlv_buf_len);
1144 	}
1145 
1146 	return 0;
1147 }
1148 
1149 static int mwifiex_ret_pkt_aggr_ctrl(struct mwifiex_private *priv,
1150 				     struct host_cmd_ds_command *resp)
1151 {
1152 	struct host_cmd_ds_pkt_aggr_ctrl *pkt_aggr_ctrl =
1153 					&resp->params.pkt_aggr_ctrl;
1154 	struct mwifiex_adapter *adapter = priv->adapter;
1155 
1156 	adapter->bus_aggr.enable = le16_to_cpu(pkt_aggr_ctrl->enable);
1157 	if (adapter->bus_aggr.enable)
1158 		adapter->intf_hdr_len = INTF_HEADER_LEN;
1159 	adapter->bus_aggr.mode = MWIFIEX_BUS_AGGR_MODE_LEN_V2;
1160 	adapter->bus_aggr.tx_aggr_max_size =
1161 				le16_to_cpu(pkt_aggr_ctrl->tx_aggr_max_size);
1162 	adapter->bus_aggr.tx_aggr_max_num =
1163 				le16_to_cpu(pkt_aggr_ctrl->tx_aggr_max_num);
1164 	adapter->bus_aggr.tx_aggr_align =
1165 				le16_to_cpu(pkt_aggr_ctrl->tx_aggr_align);
1166 
1167 	return 0;
1168 }
1169 
1170 static int mwifiex_ret_get_chan_info(struct mwifiex_private *priv,
1171 				     struct host_cmd_ds_command *resp,
1172 				     struct mwifiex_channel_band *channel_band)
1173 {
1174 	struct host_cmd_ds_sta_configure *sta_cfg_cmd = &resp->params.sta_cfg;
1175 	struct host_cmd_tlv_channel_band *tlv_band_channel;
1176 
1177 	tlv_band_channel =
1178 	(struct host_cmd_tlv_channel_band *)sta_cfg_cmd->tlv_buffer;
1179 	memcpy(&channel_band->band_config, &tlv_band_channel->band_config,
1180 	       sizeof(struct mwifiex_band_config));
1181 	channel_band->channel = tlv_band_channel->channel;
1182 
1183 	return 0;
1184 }
1185 
1186 /*
1187  * This function handles the command responses.
1188  *
1189  * This is a generic function, which calls command specific
1190  * response handlers based on the command ID.
1191  */
1192 int mwifiex_process_sta_cmdresp(struct mwifiex_private *priv, u16 cmdresp_no,
1193 				struct host_cmd_ds_command *resp)
1194 {
1195 	int ret = 0;
1196 	struct mwifiex_adapter *adapter = priv->adapter;
1197 	void *data_buf = adapter->curr_cmd->data_buf;
1198 
1199 	/* If the command is not successful, cleanup and return failure */
1200 	if (resp->result != HostCmd_RESULT_OK) {
1201 		mwifiex_process_cmdresp_error(priv, resp);
1202 		return -1;
1203 	}
1204 	/* Command successful, handle response */
1205 	switch (cmdresp_no) {
1206 	case HostCmd_CMD_GET_HW_SPEC:
1207 		ret = mwifiex_ret_get_hw_spec(priv, resp);
1208 		break;
1209 	case HostCmd_CMD_CFG_DATA:
1210 		ret = mwifiex_ret_cfg_data(priv, resp);
1211 		break;
1212 	case HostCmd_CMD_MAC_CONTROL:
1213 		break;
1214 	case HostCmd_CMD_802_11_MAC_ADDRESS:
1215 		ret = mwifiex_ret_802_11_mac_address(priv, resp);
1216 		break;
1217 	case HostCmd_CMD_MAC_MULTICAST_ADR:
1218 		ret = mwifiex_ret_mac_multicast_adr(priv, resp);
1219 		break;
1220 	case HostCmd_CMD_TX_RATE_CFG:
1221 		ret = mwifiex_ret_tx_rate_cfg(priv, resp);
1222 		break;
1223 	case HostCmd_CMD_802_11_SCAN:
1224 		ret = mwifiex_ret_802_11_scan(priv, resp);
1225 		adapter->curr_cmd->wait_q_enabled = false;
1226 		break;
1227 	case HostCmd_CMD_802_11_SCAN_EXT:
1228 		ret = mwifiex_ret_802_11_scan_ext(priv, resp);
1229 		adapter->curr_cmd->wait_q_enabled = false;
1230 		break;
1231 	case HostCmd_CMD_802_11_BG_SCAN_QUERY:
1232 		ret = mwifiex_ret_802_11_scan(priv, resp);
1233 		cfg80211_sched_scan_results(priv->wdev.wiphy, 0);
1234 		mwifiex_dbg(adapter, CMD,
1235 			    "info: CMD_RESP: BG_SCAN result is ready!\n");
1236 		break;
1237 	case HostCmd_CMD_802_11_BG_SCAN_CONFIG:
1238 		break;
1239 	case HostCmd_CMD_TXPWR_CFG:
1240 		ret = mwifiex_ret_tx_power_cfg(priv, resp);
1241 		break;
1242 	case HostCmd_CMD_RF_TX_PWR:
1243 		ret = mwifiex_ret_rf_tx_power(priv, resp);
1244 		break;
1245 	case HostCmd_CMD_RF_ANTENNA:
1246 		ret = mwifiex_ret_rf_antenna(priv, resp);
1247 		break;
1248 	case HostCmd_CMD_802_11_PS_MODE_ENH:
1249 		ret = mwifiex_ret_enh_power_mode(priv, resp, data_buf);
1250 		break;
1251 	case HostCmd_CMD_802_11_HS_CFG_ENH:
1252 		ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
1253 		break;
1254 	case HostCmd_CMD_802_11_ASSOCIATE:
1255 		ret = mwifiex_ret_802_11_associate(priv, resp);
1256 		break;
1257 	case HostCmd_CMD_802_11_DEAUTHENTICATE:
1258 		ret = mwifiex_ret_802_11_deauthenticate(priv, resp);
1259 		break;
1260 	case HostCmd_CMD_802_11_AD_HOC_START:
1261 	case HostCmd_CMD_802_11_AD_HOC_JOIN:
1262 		ret = mwifiex_ret_802_11_ad_hoc(priv, resp);
1263 		break;
1264 	case HostCmd_CMD_802_11_AD_HOC_STOP:
1265 		ret = mwifiex_ret_802_11_ad_hoc_stop(priv, resp);
1266 		break;
1267 	case HostCmd_CMD_802_11_GET_LOG:
1268 		ret = mwifiex_ret_get_log(priv, resp, data_buf);
1269 		break;
1270 	case HostCmd_CMD_RSSI_INFO:
1271 		ret = mwifiex_ret_802_11_rssi_info(priv, resp);
1272 		break;
1273 	case HostCmd_CMD_802_11_SNMP_MIB:
1274 		ret = mwifiex_ret_802_11_snmp_mib(priv, resp, data_buf);
1275 		break;
1276 	case HostCmd_CMD_802_11_TX_RATE_QUERY:
1277 		ret = mwifiex_ret_802_11_tx_rate_query(priv, resp);
1278 		break;
1279 	case HostCmd_CMD_VERSION_EXT:
1280 		ret = mwifiex_ret_ver_ext(priv, resp, data_buf);
1281 		break;
1282 	case HostCmd_CMD_REMAIN_ON_CHAN:
1283 		ret = mwifiex_ret_remain_on_chan(priv, resp, data_buf);
1284 		break;
1285 	case HostCmd_CMD_11AC_CFG:
1286 		break;
1287 	case HostCmd_CMD_PACKET_AGGR_CTRL:
1288 		ret = mwifiex_ret_pkt_aggr_ctrl(priv, resp);
1289 		break;
1290 	case HostCmd_CMD_P2P_MODE_CFG:
1291 		ret = mwifiex_ret_p2p_mode_cfg(priv, resp, data_buf);
1292 		break;
1293 	case HostCmd_CMD_MGMT_FRAME_REG:
1294 	case HostCmd_CMD_FUNC_INIT:
1295 	case HostCmd_CMD_FUNC_SHUTDOWN:
1296 		break;
1297 	case HostCmd_CMD_802_11_KEY_MATERIAL:
1298 		ret = mwifiex_ret_802_11_key_material(priv, resp);
1299 		break;
1300 	case HostCmd_CMD_802_11D_DOMAIN_INFO:
1301 		ret = mwifiex_ret_802_11d_domain_info(priv, resp);
1302 		break;
1303 	case HostCmd_CMD_11N_ADDBA_REQ:
1304 		ret = mwifiex_ret_11n_addba_req(priv, resp);
1305 		break;
1306 	case HostCmd_CMD_11N_DELBA:
1307 		ret = mwifiex_ret_11n_delba(priv, resp);
1308 		break;
1309 	case HostCmd_CMD_11N_ADDBA_RSP:
1310 		ret = mwifiex_ret_11n_addba_resp(priv, resp);
1311 		break;
1312 	case HostCmd_CMD_RECONFIGURE_TX_BUFF:
1313 		if (0xffff == (u16)le16_to_cpu(resp->params.tx_buf.buff_size)) {
1314 			if (adapter->iface_type == MWIFIEX_USB &&
1315 			    adapter->usb_mc_setup) {
1316 				if (adapter->if_ops.multi_port_resync)
1317 					adapter->if_ops.
1318 						multi_port_resync(adapter);
1319 				adapter->usb_mc_setup = false;
1320 				adapter->tx_lock_flag = false;
1321 			}
1322 			break;
1323 		}
1324 		adapter->tx_buf_size = (u16) le16_to_cpu(resp->params.
1325 							     tx_buf.buff_size);
1326 		adapter->tx_buf_size = (adapter->tx_buf_size
1327 					/ MWIFIEX_SDIO_BLOCK_SIZE)
1328 				       * MWIFIEX_SDIO_BLOCK_SIZE;
1329 		adapter->curr_tx_buf_size = adapter->tx_buf_size;
1330 		mwifiex_dbg(adapter, CMD, "cmd: curr_tx_buf_size=%d\n",
1331 			    adapter->curr_tx_buf_size);
1332 
1333 		if (adapter->if_ops.update_mp_end_port)
1334 			adapter->if_ops.update_mp_end_port(adapter,
1335 				le16_to_cpu(resp->params.tx_buf.mp_end_port));
1336 		break;
1337 	case HostCmd_CMD_AMSDU_AGGR_CTRL:
1338 		break;
1339 	case HostCmd_CMD_WMM_GET_STATUS:
1340 		ret = mwifiex_ret_wmm_get_status(priv, resp);
1341 		break;
1342 	case HostCmd_CMD_802_11_IBSS_COALESCING_STATUS:
1343 		ret = mwifiex_ret_ibss_coalescing_status(priv, resp);
1344 		break;
1345 	case HostCmd_CMD_MEM_ACCESS:
1346 		ret = mwifiex_ret_mem_access(priv, resp, data_buf);
1347 		break;
1348 	case HostCmd_CMD_MAC_REG_ACCESS:
1349 	case HostCmd_CMD_BBP_REG_ACCESS:
1350 	case HostCmd_CMD_RF_REG_ACCESS:
1351 	case HostCmd_CMD_PMIC_REG_ACCESS:
1352 	case HostCmd_CMD_CAU_REG_ACCESS:
1353 	case HostCmd_CMD_802_11_EEPROM_ACCESS:
1354 		ret = mwifiex_ret_reg_access(cmdresp_no, resp, data_buf);
1355 		break;
1356 	case HostCmd_CMD_SET_BSS_MODE:
1357 		break;
1358 	case HostCmd_CMD_11N_CFG:
1359 		break;
1360 	case HostCmd_CMD_PCIE_DESC_DETAILS:
1361 		break;
1362 	case HostCmd_CMD_802_11_SUBSCRIBE_EVENT:
1363 		ret = mwifiex_ret_subsc_evt(priv, resp);
1364 		break;
1365 	case HostCmd_CMD_UAP_SYS_CONFIG:
1366 		break;
1367 	case HOST_CMD_APCMD_STA_LIST:
1368 		ret = mwifiex_ret_uap_sta_list(priv, resp);
1369 		break;
1370 	case HostCmd_CMD_UAP_BSS_START:
1371 		adapter->tx_lock_flag = false;
1372 		adapter->pps_uapsd_mode = false;
1373 		adapter->delay_null_pkt = false;
1374 		priv->bss_started = 1;
1375 		break;
1376 	case HostCmd_CMD_UAP_BSS_STOP:
1377 		priv->bss_started = 0;
1378 		break;
1379 	case HostCmd_CMD_UAP_STA_DEAUTH:
1380 		break;
1381 	case HOST_CMD_APCMD_SYS_RESET:
1382 		break;
1383 	case HostCmd_CMD_MEF_CFG:
1384 		break;
1385 	case HostCmd_CMD_COALESCE_CFG:
1386 		break;
1387 	case HostCmd_CMD_TDLS_OPER:
1388 		ret = mwifiex_ret_tdls_oper(priv, resp);
1389 	case HostCmd_CMD_MC_POLICY:
1390 		break;
1391 	case HostCmd_CMD_CHAN_REPORT_REQUEST:
1392 		break;
1393 	case HostCmd_CMD_SDIO_SP_RX_AGGR_CFG:
1394 		ret = mwifiex_ret_sdio_rx_aggr_cfg(priv, resp);
1395 		break;
1396 	case HostCmd_CMD_HS_WAKEUP_REASON:
1397 		ret = mwifiex_ret_wakeup_reason(priv, resp, data_buf);
1398 		break;
1399 	case HostCmd_CMD_TDLS_CONFIG:
1400 		break;
1401 	case HostCmd_CMD_ROBUST_COEX:
1402 		ret = mwifiex_ret_robust_coex(priv, resp, data_buf);
1403 		break;
1404 	case HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG:
1405 		break;
1406 	case HostCmd_CMD_CHAN_REGION_CFG:
1407 		ret = mwifiex_ret_chan_region_cfg(priv, resp);
1408 		break;
1409 	case HostCmd_CMD_STA_CONFIGURE:
1410 		ret = mwifiex_ret_get_chan_info(priv, resp, data_buf);
1411 		break;
1412 	default:
1413 		mwifiex_dbg(adapter, ERROR,
1414 			    "CMD_RESP: unknown cmd response %#x\n",
1415 			    resp->command);
1416 		break;
1417 	}
1418 
1419 	return ret;
1420 }
1421