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