xref: /linux/drivers/net/wireless/marvell/mwifiex/sta_event.c (revision 0883c2c06fb5bcf5b9e008270827e63c09a88c1e)
1 /*
2  * Marvell Wireless LAN device driver: station event 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 
28 /*
29  * This function resets the connection state.
30  *
31  * The function is invoked after receiving a disconnect event from firmware,
32  * and performs the following actions -
33  *      - Set media status to disconnected
34  *      - Clean up Tx and Rx packets
35  *      - Resets SNR/NF/RSSI value in driver
36  *      - Resets security configurations in driver
37  *      - Enables auto data rate
38  *      - Saves the previous SSID and BSSID so that they can
39  *        be used for re-association, if required
40  *      - Erases current SSID and BSSID information
41  *      - Sends a disconnect event to upper layers/applications.
42  */
43 void
44 mwifiex_reset_connect_state(struct mwifiex_private *priv, u16 reason_code)
45 {
46 	struct mwifiex_adapter *adapter = priv->adapter;
47 
48 	if (!priv->media_connected)
49 		return;
50 
51 	mwifiex_dbg(adapter, INFO,
52 		    "info: handles disconnect event\n");
53 
54 	priv->media_connected = false;
55 
56 	priv->scan_block = false;
57 	priv->port_open = false;
58 
59 	if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
60 	    ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info)) {
61 		mwifiex_disable_all_tdls_links(priv);
62 
63 		if (priv->adapter->auto_tdls)
64 			mwifiex_clean_auto_tdls(priv);
65 	}
66 
67 	/* Free Tx and Rx packets, report disconnect to upper layer */
68 	mwifiex_clean_txrx(priv);
69 
70 	/* Reset SNR/NF/RSSI values */
71 	priv->data_rssi_last = 0;
72 	priv->data_nf_last = 0;
73 	priv->data_rssi_avg = 0;
74 	priv->data_nf_avg = 0;
75 	priv->bcn_rssi_last = 0;
76 	priv->bcn_nf_last = 0;
77 	priv->bcn_rssi_avg = 0;
78 	priv->bcn_nf_avg = 0;
79 	priv->rxpd_rate = 0;
80 	priv->rxpd_htinfo = 0;
81 	priv->sec_info.wpa_enabled = false;
82 	priv->sec_info.wpa2_enabled = false;
83 	priv->wpa_ie_len = 0;
84 
85 	priv->sec_info.wapi_enabled = false;
86 	priv->wapi_ie_len = 0;
87 	priv->sec_info.wapi_key_on = false;
88 
89 	priv->sec_info.encryption_mode = 0;
90 
91 	/* Enable auto data rate */
92 	priv->is_data_rate_auto = true;
93 	priv->data_rate = 0;
94 
95 	priv->assoc_resp_ht_param = 0;
96 	priv->ht_param_present = false;
97 
98 	if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
99 	     GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) && priv->hist_data)
100 		mwifiex_hist_data_reset(priv);
101 
102 	if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
103 		priv->adhoc_state = ADHOC_IDLE;
104 		priv->adhoc_is_link_sensed = false;
105 	}
106 
107 	/*
108 	 * Memorize the previous SSID and BSSID so
109 	 * it could be used for re-assoc
110 	 */
111 
112 	mwifiex_dbg(adapter, INFO,
113 		    "info: previous SSID=%s, SSID len=%u\n",
114 		    priv->prev_ssid.ssid, priv->prev_ssid.ssid_len);
115 
116 	mwifiex_dbg(adapter, INFO,
117 		    "info: current SSID=%s, SSID len=%u\n",
118 		    priv->curr_bss_params.bss_descriptor.ssid.ssid,
119 		    priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
120 
121 	memcpy(&priv->prev_ssid,
122 	       &priv->curr_bss_params.bss_descriptor.ssid,
123 	       sizeof(struct cfg80211_ssid));
124 
125 	memcpy(priv->prev_bssid,
126 	       priv->curr_bss_params.bss_descriptor.mac_address, ETH_ALEN);
127 
128 	/* Need to erase the current SSID and BSSID info */
129 	memset(&priv->curr_bss_params, 0x00, sizeof(priv->curr_bss_params));
130 
131 	adapter->tx_lock_flag = false;
132 	adapter->pps_uapsd_mode = false;
133 
134 	if (adapter->is_cmd_timedout && adapter->curr_cmd)
135 		return;
136 	priv->media_connected = false;
137 	mwifiex_dbg(adapter, MSG,
138 		    "info: successfully disconnected from %pM: reason code %d\n",
139 		    priv->cfg_bssid, reason_code);
140 	if (priv->bss_mode == NL80211_IFTYPE_STATION ||
141 	    priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
142 		cfg80211_disconnected(priv->netdev, reason_code, NULL, 0,
143 				      false, GFP_KERNEL);
144 	}
145 	eth_zero_addr(priv->cfg_bssid);
146 
147 	mwifiex_stop_net_dev_queue(priv->netdev, adapter);
148 	if (netif_carrier_ok(priv->netdev))
149 		netif_carrier_off(priv->netdev);
150 
151 	mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG,
152 			 HostCmd_ACT_GEN_REMOVE, 0, NULL, false);
153 }
154 
155 static int mwifiex_parse_tdls_event(struct mwifiex_private *priv,
156 				    struct sk_buff *event_skb)
157 {
158 	int ret = 0;
159 	struct mwifiex_adapter *adapter = priv->adapter;
160 	struct mwifiex_sta_node *sta_ptr;
161 	struct mwifiex_tdls_generic_event *tdls_evt =
162 			(void *)event_skb->data + sizeof(adapter->event_cause);
163 	u8 *mac = tdls_evt->peer_mac;
164 
165 	/* reserved 2 bytes are not mandatory in tdls event */
166 	if (event_skb->len < (sizeof(struct mwifiex_tdls_generic_event) -
167 			      sizeof(u16) - sizeof(adapter->event_cause))) {
168 		mwifiex_dbg(adapter, ERROR, "Invalid event length!\n");
169 		return -1;
170 	}
171 
172 	sta_ptr = mwifiex_get_sta_entry(priv, tdls_evt->peer_mac);
173 	if (!sta_ptr) {
174 		mwifiex_dbg(adapter, ERROR, "cannot get sta entry!\n");
175 		return -1;
176 	}
177 
178 	switch (le16_to_cpu(tdls_evt->type)) {
179 	case TDLS_EVENT_LINK_TEAR_DOWN:
180 		cfg80211_tdls_oper_request(priv->netdev,
181 					   tdls_evt->peer_mac,
182 					   NL80211_TDLS_TEARDOWN,
183 					   le16_to_cpu(tdls_evt->u.reason_code),
184 					   GFP_KERNEL);
185 		break;
186 	case TDLS_EVENT_CHAN_SWITCH_RESULT:
187 		mwifiex_dbg(adapter, EVENT, "tdls channel switch result :\n");
188 		mwifiex_dbg(adapter, EVENT,
189 			    "status=0x%x, reason=0x%x cur_chan=%d\n",
190 			    tdls_evt->u.switch_result.status,
191 			    tdls_evt->u.switch_result.reason,
192 			    tdls_evt->u.switch_result.cur_chan);
193 
194 		/* tdls channel switch failed */
195 		if (tdls_evt->u.switch_result.status != 0) {
196 			switch (tdls_evt->u.switch_result.cur_chan) {
197 			case TDLS_BASE_CHANNEL:
198 				sta_ptr->tdls_status = TDLS_IN_BASE_CHAN;
199 				break;
200 			case TDLS_OFF_CHANNEL:
201 				sta_ptr->tdls_status = TDLS_IN_OFF_CHAN;
202 				break;
203 			default:
204 				break;
205 			}
206 			return ret;
207 		}
208 
209 		/* tdls channel switch success */
210 		switch (tdls_evt->u.switch_result.cur_chan) {
211 		case TDLS_BASE_CHANNEL:
212 			if (sta_ptr->tdls_status == TDLS_IN_BASE_CHAN)
213 				break;
214 			mwifiex_update_ralist_tx_pause_in_tdls_cs(priv, mac,
215 								  false);
216 			sta_ptr->tdls_status = TDLS_IN_BASE_CHAN;
217 			break;
218 		case TDLS_OFF_CHANNEL:
219 			if (sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)
220 				break;
221 			mwifiex_update_ralist_tx_pause_in_tdls_cs(priv, mac,
222 								  true);
223 			sta_ptr->tdls_status = TDLS_IN_OFF_CHAN;
224 			break;
225 		default:
226 			break;
227 		}
228 
229 		break;
230 	case TDLS_EVENT_START_CHAN_SWITCH:
231 		mwifiex_dbg(adapter, EVENT, "tdls start channel switch...\n");
232 		sta_ptr->tdls_status = TDLS_CHAN_SWITCHING;
233 		break;
234 	case TDLS_EVENT_CHAN_SWITCH_STOPPED:
235 		mwifiex_dbg(adapter, EVENT,
236 			    "tdls chan switch stopped, reason=%d\n",
237 			    tdls_evt->u.cs_stop_reason);
238 		break;
239 	default:
240 		break;
241 	}
242 
243 	return ret;
244 }
245 
246 static void mwifiex_process_uap_tx_pause(struct mwifiex_private *priv,
247 					 struct mwifiex_ie_types_header *tlv)
248 {
249 	struct mwifiex_tx_pause_tlv *tp;
250 	struct mwifiex_sta_node *sta_ptr;
251 	unsigned long flags;
252 
253 	tp = (void *)tlv;
254 	mwifiex_dbg(priv->adapter, EVENT,
255 		    "uap tx_pause: %pM pause=%d, pkts=%d\n",
256 		    tp->peermac, tp->tx_pause,
257 		    tp->pkt_cnt);
258 
259 	if (ether_addr_equal(tp->peermac, priv->netdev->dev_addr)) {
260 		if (tp->tx_pause)
261 			priv->port_open = false;
262 		else
263 			priv->port_open = true;
264 	} else if (is_multicast_ether_addr(tp->peermac)) {
265 		mwifiex_update_ralist_tx_pause(priv, tp->peermac, tp->tx_pause);
266 	} else {
267 		spin_lock_irqsave(&priv->sta_list_spinlock, flags);
268 		sta_ptr = mwifiex_get_sta_entry(priv, tp->peermac);
269 		spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
270 
271 		if (sta_ptr && sta_ptr->tx_pause != tp->tx_pause) {
272 			sta_ptr->tx_pause = tp->tx_pause;
273 			mwifiex_update_ralist_tx_pause(priv, tp->peermac,
274 						       tp->tx_pause);
275 		}
276 	}
277 }
278 
279 static void mwifiex_process_sta_tx_pause(struct mwifiex_private *priv,
280 					 struct mwifiex_ie_types_header *tlv)
281 {
282 	struct mwifiex_tx_pause_tlv *tp;
283 	struct mwifiex_sta_node *sta_ptr;
284 	int status;
285 	unsigned long flags;
286 
287 	tp = (void *)tlv;
288 	mwifiex_dbg(priv->adapter, EVENT,
289 		    "sta tx_pause: %pM pause=%d, pkts=%d\n",
290 		    tp->peermac, tp->tx_pause,
291 		    tp->pkt_cnt);
292 
293 	if (ether_addr_equal(tp->peermac, priv->cfg_bssid)) {
294 		if (tp->tx_pause)
295 			priv->port_open = false;
296 		else
297 			priv->port_open = true;
298 	} else {
299 		if (!ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
300 			return;
301 
302 		status = mwifiex_get_tdls_link_status(priv, tp->peermac);
303 		if (mwifiex_is_tdls_link_setup(status)) {
304 			spin_lock_irqsave(&priv->sta_list_spinlock, flags);
305 			sta_ptr = mwifiex_get_sta_entry(priv, tp->peermac);
306 			spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
307 
308 			if (sta_ptr && sta_ptr->tx_pause != tp->tx_pause) {
309 				sta_ptr->tx_pause = tp->tx_pause;
310 				mwifiex_update_ralist_tx_pause(priv,
311 							       tp->peermac,
312 							       tp->tx_pause);
313 			}
314 		}
315 	}
316 }
317 
318 void mwifiex_process_multi_chan_event(struct mwifiex_private *priv,
319 				      struct sk_buff *event_skb)
320 {
321 	struct mwifiex_ie_types_multi_chan_info *chan_info;
322 	struct mwifiex_ie_types_mc_group_info *grp_info;
323 	struct mwifiex_adapter *adapter = priv->adapter;
324 	struct mwifiex_ie_types_header *tlv;
325 	u16 tlv_buf_left, tlv_type, tlv_len;
326 	int intf_num, bss_type, bss_num, i;
327 	struct mwifiex_private *intf_priv;
328 
329 	tlv_buf_left = event_skb->len - sizeof(u32);
330 	chan_info = (void *)event_skb->data + sizeof(u32);
331 
332 	if (le16_to_cpu(chan_info->header.type) != TLV_TYPE_MULTI_CHAN_INFO ||
333 	    tlv_buf_left < sizeof(struct mwifiex_ie_types_multi_chan_info)) {
334 		mwifiex_dbg(adapter, ERROR,
335 			    "unknown TLV in chan_info event\n");
336 		return;
337 	}
338 
339 	adapter->usb_mc_status = le16_to_cpu(chan_info->status);
340 	mwifiex_dbg(adapter, EVENT, "multi chan operation %s\n",
341 		    adapter->usb_mc_status ? "started" : "over");
342 
343 	tlv_buf_left -= sizeof(struct mwifiex_ie_types_multi_chan_info);
344 	tlv = (struct mwifiex_ie_types_header *)chan_info->tlv_buffer;
345 
346 	while (tlv_buf_left >= (int)sizeof(struct mwifiex_ie_types_header)) {
347 		tlv_type = le16_to_cpu(tlv->type);
348 		tlv_len  = le16_to_cpu(tlv->len);
349 		if ((sizeof(struct mwifiex_ie_types_header) + tlv_len) >
350 		    tlv_buf_left) {
351 			mwifiex_dbg(adapter, ERROR, "wrong tlv: tlvLen=%d,\t"
352 				    "tlvBufLeft=%d\n", tlv_len, tlv_buf_left);
353 			break;
354 		}
355 		if (tlv_type != TLV_TYPE_MC_GROUP_INFO) {
356 			mwifiex_dbg(adapter, ERROR, "wrong tlv type: 0x%x\n",
357 				    tlv_type);
358 			break;
359 		}
360 
361 		grp_info = (struct mwifiex_ie_types_mc_group_info *)tlv;
362 		intf_num = grp_info->intf_num;
363 		for (i = 0; i < intf_num; i++) {
364 			bss_type = grp_info->bss_type_numlist[i] >> 4;
365 			bss_num = grp_info->bss_type_numlist[i] & BSS_NUM_MASK;
366 			intf_priv = mwifiex_get_priv_by_id(adapter, bss_num,
367 							   bss_type);
368 			if (!intf_priv) {
369 				mwifiex_dbg(adapter, ERROR,
370 					    "Invalid bss_type bss_num\t"
371 					    "in multi channel event\n");
372 				continue;
373 			}
374 			if (adapter->iface_type == MWIFIEX_USB) {
375 				u8 ep;
376 
377 				ep = grp_info->hid_num.usb_ep_num;
378 				if (ep == MWIFIEX_USB_EP_DATA ||
379 				    ep == MWIFIEX_USB_EP_DATA_CH2)
380 					intf_priv->usb_port = ep;
381 			}
382 		}
383 
384 		tlv_buf_left -= sizeof(struct mwifiex_ie_types_header) +
385 				tlv_len;
386 		tlv = (void *)((u8 *)tlv + tlv_len +
387 			       sizeof(struct mwifiex_ie_types_header));
388 	}
389 
390 	if (adapter->iface_type == MWIFIEX_USB) {
391 		adapter->tx_lock_flag = true;
392 		adapter->usb_mc_setup = true;
393 		mwifiex_multi_chan_resync(adapter);
394 	}
395 }
396 
397 void mwifiex_process_tx_pause_event(struct mwifiex_private *priv,
398 				    struct sk_buff *event_skb)
399 {
400 	struct mwifiex_ie_types_header *tlv;
401 	u16 tlv_type, tlv_len;
402 	int tlv_buf_left;
403 
404 	if (!priv->media_connected) {
405 		mwifiex_dbg(priv->adapter, ERROR,
406 			    "tx_pause event while disconnected; bss_role=%d\n",
407 			    priv->bss_role);
408 		return;
409 	}
410 
411 	tlv_buf_left = event_skb->len - sizeof(u32);
412 	tlv = (void *)event_skb->data + sizeof(u32);
413 
414 	while (tlv_buf_left >= (int)sizeof(struct mwifiex_ie_types_header)) {
415 		tlv_type = le16_to_cpu(tlv->type);
416 		tlv_len  = le16_to_cpu(tlv->len);
417 		if ((sizeof(struct mwifiex_ie_types_header) + tlv_len) >
418 		    tlv_buf_left) {
419 			mwifiex_dbg(priv->adapter, ERROR,
420 				    "wrong tlv: tlvLen=%d, tlvBufLeft=%d\n",
421 				    tlv_len, tlv_buf_left);
422 			break;
423 		}
424 		if (tlv_type == TLV_TYPE_TX_PAUSE) {
425 			if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
426 				mwifiex_process_sta_tx_pause(priv, tlv);
427 			else
428 				mwifiex_process_uap_tx_pause(priv, tlv);
429 		}
430 
431 		tlv_buf_left -= sizeof(struct mwifiex_ie_types_header) +
432 				tlv_len;
433 		tlv = (void *)((u8 *)tlv + tlv_len +
434 			       sizeof(struct mwifiex_ie_types_header));
435 	}
436 
437 }
438 
439 /*
440 * This function handles coex events generated by firmware
441 */
442 void mwifiex_bt_coex_wlan_param_update_event(struct mwifiex_private *priv,
443 					     struct sk_buff *event_skb)
444 {
445 	struct mwifiex_adapter *adapter = priv->adapter;
446 	struct mwifiex_ie_types_header *tlv;
447 	struct mwifiex_ie_types_btcoex_aggr_win_size *winsizetlv;
448 	struct mwifiex_ie_types_btcoex_scan_time *scantlv;
449 	s32 len = event_skb->len - sizeof(u32);
450 	u8 *cur_ptr = event_skb->data + sizeof(u32);
451 	u16 tlv_type, tlv_len;
452 
453 	while (len >= sizeof(struct mwifiex_ie_types_header)) {
454 		tlv = (struct mwifiex_ie_types_header *)cur_ptr;
455 		tlv_len = le16_to_cpu(tlv->len);
456 		tlv_type = le16_to_cpu(tlv->type);
457 
458 		if ((tlv_len + sizeof(struct mwifiex_ie_types_header)) > len)
459 			break;
460 		switch (tlv_type) {
461 		case TLV_BTCOEX_WL_AGGR_WINSIZE:
462 			winsizetlv =
463 			    (struct mwifiex_ie_types_btcoex_aggr_win_size *)tlv;
464 			adapter->coex_win_size = winsizetlv->coex_win_size;
465 			adapter->coex_tx_win_size =
466 				winsizetlv->tx_win_size;
467 			adapter->coex_rx_win_size =
468 				winsizetlv->rx_win_size;
469 			mwifiex_coex_ampdu_rxwinsize(adapter);
470 			mwifiex_update_ampdu_txwinsize(adapter);
471 			break;
472 
473 		case TLV_BTCOEX_WL_SCANTIME:
474 			scantlv =
475 			    (struct mwifiex_ie_types_btcoex_scan_time *)tlv;
476 			adapter->coex_scan = scantlv->coex_scan;
477 			adapter->coex_min_scan_time = scantlv->min_scan_time;
478 			adapter->coex_max_scan_time = scantlv->max_scan_time;
479 			break;
480 
481 		default:
482 			break;
483 		}
484 
485 		len -= tlv_len + sizeof(struct mwifiex_ie_types_header);
486 		cur_ptr += tlv_len +
487 			sizeof(struct mwifiex_ie_types_header);
488 	}
489 
490 	dev_dbg(adapter->dev, "coex_scan=%d min_scan=%d coex_win=%d, tx_win=%d rx_win=%d\n",
491 		adapter->coex_scan, adapter->coex_min_scan_time,
492 		adapter->coex_win_size, adapter->coex_tx_win_size,
493 		adapter->coex_rx_win_size);
494 }
495 
496 /*
497  * This function handles events generated by firmware.
498  *
499  * This is a generic function and handles all events.
500  *
501  * Event specific routines are called by this function based
502  * upon the generated event cause.
503  *
504  * For the following events, the function just forwards them to upper
505  * layers, optionally recording the change -
506  *      - EVENT_LINK_SENSED
507  *      - EVENT_MIC_ERR_UNICAST
508  *      - EVENT_MIC_ERR_MULTICAST
509  *      - EVENT_PORT_RELEASE
510  *      - EVENT_RSSI_LOW
511  *      - EVENT_SNR_LOW
512  *      - EVENT_MAX_FAIL
513  *      - EVENT_RSSI_HIGH
514  *      - EVENT_SNR_HIGH
515  *      - EVENT_DATA_RSSI_LOW
516  *      - EVENT_DATA_SNR_LOW
517  *      - EVENT_DATA_RSSI_HIGH
518  *      - EVENT_DATA_SNR_HIGH
519  *      - EVENT_LINK_QUALITY
520  *      - EVENT_PRE_BEACON_LOST
521  *      - EVENT_IBSS_COALESCED
522  *      - EVENT_WEP_ICV_ERR
523  *      - EVENT_BW_CHANGE
524  *      - EVENT_HOSTWAKE_STAIE
525   *
526  * For the following events, no action is taken -
527  *      - EVENT_MIB_CHANGED
528  *      - EVENT_INIT_DONE
529  *      - EVENT_DUMMY_HOST_WAKEUP_SIGNAL
530  *
531  * Rest of the supported events requires driver handling -
532  *      - EVENT_DEAUTHENTICATED
533  *      - EVENT_DISASSOCIATED
534  *      - EVENT_LINK_LOST
535  *      - EVENT_PS_SLEEP
536  *      - EVENT_PS_AWAKE
537  *      - EVENT_DEEP_SLEEP_AWAKE
538  *      - EVENT_HS_ACT_REQ
539  *      - EVENT_ADHOC_BCN_LOST
540  *      - EVENT_BG_SCAN_REPORT
541  *      - EVENT_WMM_STATUS_CHANGE
542  *      - EVENT_ADDBA
543  *      - EVENT_DELBA
544  *      - EVENT_BA_STREAM_TIEMOUT
545  *      - EVENT_AMSDU_AGGR_CTRL
546  */
547 int mwifiex_process_sta_event(struct mwifiex_private *priv)
548 {
549 	struct mwifiex_adapter *adapter = priv->adapter;
550 	int ret = 0;
551 	u32 eventcause = adapter->event_cause;
552 	u16 ctrl, reason_code;
553 
554 	switch (eventcause) {
555 	case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
556 		mwifiex_dbg(adapter, ERROR,
557 			    "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
558 		break;
559 	case EVENT_LINK_SENSED:
560 		mwifiex_dbg(adapter, EVENT, "event: LINK_SENSED\n");
561 		if (!netif_carrier_ok(priv->netdev))
562 			netif_carrier_on(priv->netdev);
563 		mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
564 		break;
565 
566 	case EVENT_DEAUTHENTICATED:
567 		mwifiex_dbg(adapter, EVENT, "event: Deauthenticated\n");
568 		if (priv->wps.session_enable) {
569 			mwifiex_dbg(adapter, INFO,
570 				    "info: receive deauth event in wps session\n");
571 			break;
572 		}
573 		adapter->dbg.num_event_deauth++;
574 		if (priv->media_connected) {
575 			reason_code =
576 				le16_to_cpu(*(__le16 *)adapter->event_body);
577 			mwifiex_reset_connect_state(priv, reason_code);
578 		}
579 		break;
580 
581 	case EVENT_DISASSOCIATED:
582 		mwifiex_dbg(adapter, EVENT, "event: Disassociated\n");
583 		if (priv->wps.session_enable) {
584 			mwifiex_dbg(adapter, INFO,
585 				    "info: receive disassoc event in wps session\n");
586 			break;
587 		}
588 		adapter->dbg.num_event_disassoc++;
589 		if (priv->media_connected) {
590 			reason_code =
591 				le16_to_cpu(*(__le16 *)adapter->event_body);
592 			mwifiex_reset_connect_state(priv, reason_code);
593 		}
594 		break;
595 
596 	case EVENT_LINK_LOST:
597 		mwifiex_dbg(adapter, EVENT, "event: Link lost\n");
598 		adapter->dbg.num_event_link_lost++;
599 		if (priv->media_connected) {
600 			reason_code =
601 				le16_to_cpu(*(__le16 *)adapter->event_body);
602 			mwifiex_reset_connect_state(priv, reason_code);
603 		}
604 		break;
605 
606 	case EVENT_PS_SLEEP:
607 		mwifiex_dbg(adapter, EVENT, "info: EVENT: SLEEP\n");
608 
609 		adapter->ps_state = PS_STATE_PRE_SLEEP;
610 
611 		mwifiex_check_ps_cond(adapter);
612 		break;
613 
614 	case EVENT_PS_AWAKE:
615 		mwifiex_dbg(adapter, EVENT, "info: EVENT: AWAKE\n");
616 		if (!adapter->pps_uapsd_mode &&
617 		    (priv->port_open ||
618 		     (priv->bss_mode == NL80211_IFTYPE_ADHOC)) &&
619 		    priv->media_connected && adapter->sleep_period.period) {
620 			adapter->pps_uapsd_mode = true;
621 			mwifiex_dbg(adapter, EVENT,
622 				    "event: PPS/UAPSD mode activated\n");
623 		}
624 		adapter->tx_lock_flag = false;
625 		if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
626 			if (mwifiex_check_last_packet_indication(priv)) {
627 				if (adapter->data_sent ||
628 				    (adapter->if_ops.is_port_ready &&
629 				     !adapter->if_ops.is_port_ready(priv))) {
630 					adapter->ps_state = PS_STATE_AWAKE;
631 					adapter->pm_wakeup_card_req = false;
632 					adapter->pm_wakeup_fw_try = false;
633 					del_timer(&adapter->wakeup_timer);
634 					break;
635 				}
636 				if (!mwifiex_send_null_packet
637 					(priv,
638 					 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
639 					 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
640 						adapter->ps_state =
641 							PS_STATE_SLEEP;
642 					return 0;
643 			}
644 		}
645 		adapter->ps_state = PS_STATE_AWAKE;
646 		adapter->pm_wakeup_card_req = false;
647 		adapter->pm_wakeup_fw_try = false;
648 		del_timer(&adapter->wakeup_timer);
649 
650 		break;
651 
652 	case EVENT_DEEP_SLEEP_AWAKE:
653 		adapter->if_ops.wakeup_complete(adapter);
654 		mwifiex_dbg(adapter, EVENT, "event: DS_AWAKE\n");
655 		if (adapter->is_deep_sleep)
656 			adapter->is_deep_sleep = false;
657 		break;
658 
659 	case EVENT_HS_ACT_REQ:
660 		mwifiex_dbg(adapter, EVENT, "event: HS_ACT_REQ\n");
661 		ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_HS_CFG_ENH,
662 				       0, 0, NULL, false);
663 		break;
664 
665 	case EVENT_MIC_ERR_UNICAST:
666 		mwifiex_dbg(adapter, EVENT, "event: UNICAST MIC ERROR\n");
667 		cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
668 					     NL80211_KEYTYPE_PAIRWISE,
669 					     -1, NULL, GFP_KERNEL);
670 		break;
671 
672 	case EVENT_MIC_ERR_MULTICAST:
673 		mwifiex_dbg(adapter, EVENT, "event: MULTICAST MIC ERROR\n");
674 		cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
675 					     NL80211_KEYTYPE_GROUP,
676 					     -1, NULL, GFP_KERNEL);
677 		break;
678 	case EVENT_MIB_CHANGED:
679 	case EVENT_INIT_DONE:
680 		break;
681 
682 	case EVENT_ADHOC_BCN_LOST:
683 		mwifiex_dbg(adapter, EVENT, "event: ADHOC_BCN_LOST\n");
684 		priv->adhoc_is_link_sensed = false;
685 		mwifiex_clean_txrx(priv);
686 		mwifiex_stop_net_dev_queue(priv->netdev, adapter);
687 		if (netif_carrier_ok(priv->netdev))
688 			netif_carrier_off(priv->netdev);
689 		break;
690 
691 	case EVENT_BG_SCAN_REPORT:
692 		mwifiex_dbg(adapter, EVENT, "event: BGS_REPORT\n");
693 		ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_QUERY,
694 				       HostCmd_ACT_GEN_GET, 0, NULL, false);
695 		break;
696 
697 	case EVENT_BG_SCAN_STOPPED:
698 		dev_dbg(adapter->dev, "event: BGS_STOPPED\n");
699 		cfg80211_sched_scan_stopped(priv->wdev.wiphy);
700 		if (priv->sched_scanning)
701 			priv->sched_scanning = false;
702 		break;
703 
704 	case EVENT_PORT_RELEASE:
705 		mwifiex_dbg(adapter, EVENT, "event: PORT RELEASE\n");
706 		priv->port_open = true;
707 		break;
708 
709 	case EVENT_EXT_SCAN_REPORT:
710 		mwifiex_dbg(adapter, EVENT, "event: EXT_SCAN Report\n");
711 		if (adapter->ext_scan)
712 			ret = mwifiex_handle_event_ext_scan_report(priv,
713 						adapter->event_skb->data);
714 
715 		break;
716 
717 	case EVENT_WMM_STATUS_CHANGE:
718 		mwifiex_dbg(adapter, EVENT, "event: WMM status changed\n");
719 		ret = mwifiex_send_cmd(priv, HostCmd_CMD_WMM_GET_STATUS,
720 				       0, 0, NULL, false);
721 		break;
722 
723 	case EVENT_RSSI_LOW:
724 		cfg80211_cqm_rssi_notify(priv->netdev,
725 					 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
726 					 GFP_KERNEL);
727 		mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
728 				 HostCmd_ACT_GEN_GET, 0, NULL, false);
729 		priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
730 		mwifiex_dbg(adapter, EVENT, "event: Beacon RSSI_LOW\n");
731 		break;
732 	case EVENT_SNR_LOW:
733 		mwifiex_dbg(adapter, EVENT, "event: Beacon SNR_LOW\n");
734 		break;
735 	case EVENT_MAX_FAIL:
736 		mwifiex_dbg(adapter, EVENT, "event: MAX_FAIL\n");
737 		break;
738 	case EVENT_RSSI_HIGH:
739 		cfg80211_cqm_rssi_notify(priv->netdev,
740 					 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
741 					 GFP_KERNEL);
742 		mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
743 				 HostCmd_ACT_GEN_GET, 0, NULL, false);
744 		priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
745 		mwifiex_dbg(adapter, EVENT, "event: Beacon RSSI_HIGH\n");
746 		break;
747 	case EVENT_SNR_HIGH:
748 		mwifiex_dbg(adapter, EVENT, "event: Beacon SNR_HIGH\n");
749 		break;
750 	case EVENT_DATA_RSSI_LOW:
751 		mwifiex_dbg(adapter, EVENT, "event: Data RSSI_LOW\n");
752 		break;
753 	case EVENT_DATA_SNR_LOW:
754 		mwifiex_dbg(adapter, EVENT, "event: Data SNR_LOW\n");
755 		break;
756 	case EVENT_DATA_RSSI_HIGH:
757 		mwifiex_dbg(adapter, EVENT, "event: Data RSSI_HIGH\n");
758 		break;
759 	case EVENT_DATA_SNR_HIGH:
760 		mwifiex_dbg(adapter, EVENT, "event: Data SNR_HIGH\n");
761 		break;
762 	case EVENT_LINK_QUALITY:
763 		mwifiex_dbg(adapter, EVENT, "event: Link Quality\n");
764 		break;
765 	case EVENT_PRE_BEACON_LOST:
766 		mwifiex_dbg(adapter, EVENT, "event: Pre-Beacon Lost\n");
767 		break;
768 	case EVENT_IBSS_COALESCED:
769 		mwifiex_dbg(adapter, EVENT, "event: IBSS_COALESCED\n");
770 		ret = mwifiex_send_cmd(priv,
771 				HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
772 				HostCmd_ACT_GEN_GET, 0, NULL, false);
773 		break;
774 	case EVENT_ADDBA:
775 		mwifiex_dbg(adapter, EVENT, "event: ADDBA Request\n");
776 		mwifiex_send_cmd(priv, HostCmd_CMD_11N_ADDBA_RSP,
777 				 HostCmd_ACT_GEN_SET, 0,
778 				 adapter->event_body, false);
779 		break;
780 	case EVENT_DELBA:
781 		mwifiex_dbg(adapter, EVENT, "event: DELBA Request\n");
782 		mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
783 		break;
784 	case EVENT_BA_STREAM_TIEMOUT:
785 		mwifiex_dbg(adapter, EVENT, "event:  BA Stream timeout\n");
786 		mwifiex_11n_ba_stream_timeout(priv,
787 					      (struct host_cmd_ds_11n_batimeout
788 					       *)
789 					      adapter->event_body);
790 		break;
791 	case EVENT_AMSDU_AGGR_CTRL:
792 		ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
793 		mwifiex_dbg(adapter, EVENT,
794 			    "event: AMSDU_AGGR_CTRL %d\n", ctrl);
795 
796 		adapter->tx_buf_size =
797 				min_t(u16, adapter->curr_tx_buf_size, ctrl);
798 		mwifiex_dbg(adapter, EVENT, "event: tx_buf_size %d\n",
799 			    adapter->tx_buf_size);
800 		break;
801 
802 	case EVENT_WEP_ICV_ERR:
803 		mwifiex_dbg(adapter, EVENT, "event: WEP ICV error\n");
804 		break;
805 
806 	case EVENT_BW_CHANGE:
807 		mwifiex_dbg(adapter, EVENT, "event: BW Change\n");
808 		break;
809 
810 	case EVENT_HOSTWAKE_STAIE:
811 		mwifiex_dbg(adapter, EVENT,
812 			    "event: HOSTWAKE_STAIE %d\n", eventcause);
813 		break;
814 
815 	case EVENT_REMAIN_ON_CHAN_EXPIRED:
816 		mwifiex_dbg(adapter, EVENT,
817 			    "event: Remain on channel expired\n");
818 		cfg80211_remain_on_channel_expired(&priv->wdev,
819 						   priv->roc_cfg.cookie,
820 						   &priv->roc_cfg.chan,
821 						   GFP_ATOMIC);
822 
823 		memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
824 
825 		break;
826 
827 	case EVENT_CHANNEL_SWITCH_ANN:
828 		mwifiex_dbg(adapter, EVENT, "event: Channel Switch Announcement\n");
829 		priv->csa_expire_time =
830 				jiffies + msecs_to_jiffies(DFS_CHAN_MOVE_TIME);
831 		priv->csa_chan = priv->curr_bss_params.bss_descriptor.channel;
832 		ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
833 			HostCmd_ACT_GEN_SET, 0,
834 			priv->curr_bss_params.bss_descriptor.mac_address,
835 			false);
836 		break;
837 
838 	case EVENT_TDLS_GENERIC_EVENT:
839 		ret = mwifiex_parse_tdls_event(priv, adapter->event_skb);
840 		break;
841 
842 	case EVENT_TX_DATA_PAUSE:
843 		mwifiex_dbg(adapter, EVENT, "event: TX DATA PAUSE\n");
844 		mwifiex_process_tx_pause_event(priv, adapter->event_skb);
845 		break;
846 
847 	case EVENT_MULTI_CHAN_INFO:
848 		mwifiex_dbg(adapter, EVENT, "event: multi-chan info\n");
849 		mwifiex_process_multi_chan_event(priv, adapter->event_skb);
850 		break;
851 
852 	case EVENT_TX_STATUS_REPORT:
853 		mwifiex_dbg(adapter, EVENT, "event: TX_STATUS Report\n");
854 		mwifiex_parse_tx_status_event(priv, adapter->event_body);
855 		break;
856 
857 	case EVENT_CHANNEL_REPORT_RDY:
858 		mwifiex_dbg(adapter, EVENT, "event: Channel Report\n");
859 		ret = mwifiex_11h_handle_chanrpt_ready(priv,
860 						       adapter->event_skb);
861 		break;
862 	case EVENT_RADAR_DETECTED:
863 		mwifiex_dbg(adapter, EVENT, "event: Radar detected\n");
864 		ret = mwifiex_11h_handle_radar_detected(priv,
865 							adapter->event_skb);
866 		break;
867 	case EVENT_BT_COEX_WLAN_PARA_CHANGE:
868 		dev_dbg(adapter->dev, "EVENT: BT coex wlan param update\n");
869 		mwifiex_bt_coex_wlan_param_update_event(priv,
870 							adapter->event_skb);
871 		break;
872 	default:
873 		mwifiex_dbg(adapter, ERROR, "event: unknown event id: %#x\n",
874 			    eventcause);
875 		break;
876 	}
877 
878 	return ret;
879 }
880