2 * Marvell Wireless LAN device driver: station event handling
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
29 * This function resets the connection state.
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.
44 mwifiex_reset_connect_state(struct mwifiex_private *priv, u16 reason_code)
46 struct mwifiex_adapter *adapter = priv->adapter;
48 if (!priv->media_connected)
51 mwifiex_dbg(adapter, INFO,
52 "info: handles disconnect event\n");
54 priv->media_connected = false;
56 priv->scan_block = false;
58 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
59 ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info)) {
60 mwifiex_disable_all_tdls_links(priv);
62 if (priv->adapter->auto_tdls)
63 mwifiex_clean_auto_tdls(priv);
66 /* Free Tx and Rx packets, report disconnect to upper layer */
67 mwifiex_clean_txrx(priv);
69 /* Reset SNR/NF/RSSI values */
70 priv->data_rssi_last = 0;
71 priv->data_nf_last = 0;
72 priv->data_rssi_avg = 0;
73 priv->data_nf_avg = 0;
74 priv->bcn_rssi_last = 0;
75 priv->bcn_nf_last = 0;
76 priv->bcn_rssi_avg = 0;
79 priv->rxpd_htinfo = 0;
80 priv->sec_info.wpa_enabled = false;
81 priv->sec_info.wpa2_enabled = false;
84 priv->sec_info.wapi_enabled = false;
85 priv->wapi_ie_len = 0;
86 priv->sec_info.wapi_key_on = false;
88 priv->sec_info.encryption_mode = 0;
90 /* Enable auto data rate */
91 priv->is_data_rate_auto = true;
94 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
95 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) && priv->hist_data)
96 mwifiex_hist_data_reset(priv);
98 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
99 priv->adhoc_state = ADHOC_IDLE;
100 priv->adhoc_is_link_sensed = false;
104 * Memorize the previous SSID and BSSID so
105 * it could be used for re-assoc
108 mwifiex_dbg(adapter, INFO,
109 "info: previous SSID=%s, SSID len=%u\n",
110 priv->prev_ssid.ssid, priv->prev_ssid.ssid_len);
112 mwifiex_dbg(adapter, INFO,
113 "info: current SSID=%s, SSID len=%u\n",
114 priv->curr_bss_params.bss_descriptor.ssid.ssid,
115 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
117 memcpy(&priv->prev_ssid,
118 &priv->curr_bss_params.bss_descriptor.ssid,
119 sizeof(struct cfg80211_ssid));
121 memcpy(priv->prev_bssid,
122 priv->curr_bss_params.bss_descriptor.mac_address, ETH_ALEN);
124 /* Need to erase the current SSID and BSSID info */
125 memset(&priv->curr_bss_params, 0x00, sizeof(priv->curr_bss_params));
127 adapter->tx_lock_flag = false;
128 adapter->pps_uapsd_mode = false;
130 if (adapter->is_cmd_timedout && adapter->curr_cmd)
132 priv->media_connected = false;
133 mwifiex_dbg(adapter, MSG,
134 "info: successfully disconnected from %pM: reason code %d\n",
135 priv->cfg_bssid, reason_code);
136 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
137 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
138 cfg80211_disconnected(priv->netdev, reason_code, NULL, 0,
141 eth_zero_addr(priv->cfg_bssid);
143 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
144 if (netif_carrier_ok(priv->netdev))
145 netif_carrier_off(priv->netdev);
148 static int mwifiex_parse_tdls_event(struct mwifiex_private *priv,
149 struct sk_buff *event_skb)
152 struct mwifiex_adapter *adapter = priv->adapter;
153 struct mwifiex_sta_node *sta_ptr;
154 struct mwifiex_tdls_generic_event *tdls_evt =
155 (void *)event_skb->data + sizeof(adapter->event_cause);
157 /* reserved 2 bytes are not mandatory in tdls event */
158 if (event_skb->len < (sizeof(struct mwifiex_tdls_generic_event) -
159 sizeof(u16) - sizeof(adapter->event_cause))) {
160 mwifiex_dbg(adapter, ERROR, "Invalid event length!\n");
164 sta_ptr = mwifiex_get_sta_entry(priv, tdls_evt->peer_mac);
166 mwifiex_dbg(adapter, ERROR, "cannot get sta entry!\n");
170 switch (le16_to_cpu(tdls_evt->type)) {
171 case TDLS_EVENT_LINK_TEAR_DOWN:
172 cfg80211_tdls_oper_request(priv->netdev,
174 NL80211_TDLS_TEARDOWN,
175 le16_to_cpu(tdls_evt->u.reason_code),
186 * This function handles events generated by firmware.
188 * This is a generic function and handles all events.
190 * Event specific routines are called by this function based
191 * upon the generated event cause.
193 * For the following events, the function just forwards them to upper
194 * layers, optionally recording the change -
195 * - EVENT_LINK_SENSED
196 * - EVENT_MIC_ERR_UNICAST
197 * - EVENT_MIC_ERR_MULTICAST
198 * - EVENT_PORT_RELEASE
204 * - EVENT_DATA_RSSI_LOW
205 * - EVENT_DATA_SNR_LOW
206 * - EVENT_DATA_RSSI_HIGH
207 * - EVENT_DATA_SNR_HIGH
208 * - EVENT_LINK_QUALITY
209 * - EVENT_PRE_BEACON_LOST
210 * - EVENT_IBSS_COALESCED
211 * - EVENT_WEP_ICV_ERR
213 * - EVENT_HOSTWAKE_STAIE
215 * For the following events, no action is taken -
216 * - EVENT_MIB_CHANGED
218 * - EVENT_DUMMY_HOST_WAKEUP_SIGNAL
220 * Rest of the supported events requires driver handling -
221 * - EVENT_DEAUTHENTICATED
222 * - EVENT_DISASSOCIATED
226 * - EVENT_DEEP_SLEEP_AWAKE
228 * - EVENT_ADHOC_BCN_LOST
229 * - EVENT_BG_SCAN_REPORT
230 * - EVENT_WMM_STATUS_CHANGE
233 * - EVENT_BA_STREAM_TIEMOUT
234 * - EVENT_AMSDU_AGGR_CTRL
236 int mwifiex_process_sta_event(struct mwifiex_private *priv)
238 struct mwifiex_adapter *adapter = priv->adapter;
240 u32 eventcause = adapter->event_cause;
241 u16 ctrl, reason_code;
243 switch (eventcause) {
244 case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
245 mwifiex_dbg(adapter, ERROR,
246 "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
248 case EVENT_LINK_SENSED:
249 mwifiex_dbg(adapter, EVENT, "event: LINK_SENSED\n");
250 if (!netif_carrier_ok(priv->netdev))
251 netif_carrier_on(priv->netdev);
252 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
255 case EVENT_DEAUTHENTICATED:
256 mwifiex_dbg(adapter, EVENT, "event: Deauthenticated\n");
257 if (priv->wps.session_enable) {
258 mwifiex_dbg(adapter, INFO,
259 "info: receive deauth event in wps session\n");
262 adapter->dbg.num_event_deauth++;
263 if (priv->media_connected) {
265 le16_to_cpu(*(__le16 *)adapter->event_body);
266 mwifiex_reset_connect_state(priv, reason_code);
270 case EVENT_DISASSOCIATED:
271 mwifiex_dbg(adapter, EVENT, "event: Disassociated\n");
272 if (priv->wps.session_enable) {
273 mwifiex_dbg(adapter, INFO,
274 "info: receive disassoc event in wps session\n");
277 adapter->dbg.num_event_disassoc++;
278 if (priv->media_connected) {
280 le16_to_cpu(*(__le16 *)adapter->event_body);
281 mwifiex_reset_connect_state(priv, reason_code);
285 case EVENT_LINK_LOST:
286 mwifiex_dbg(adapter, EVENT, "event: Link lost\n");
287 adapter->dbg.num_event_link_lost++;
288 if (priv->media_connected) {
290 le16_to_cpu(*(__le16 *)adapter->event_body);
291 mwifiex_reset_connect_state(priv, reason_code);
296 mwifiex_dbg(adapter, EVENT, "info: EVENT: SLEEP\n");
298 adapter->ps_state = PS_STATE_PRE_SLEEP;
300 mwifiex_check_ps_cond(adapter);
304 mwifiex_dbg(adapter, EVENT, "info: EVENT: AWAKE\n");
305 if (!adapter->pps_uapsd_mode &&
306 priv->media_connected && adapter->sleep_period.period) {
307 adapter->pps_uapsd_mode = true;
308 mwifiex_dbg(adapter, EVENT,
309 "event: PPS/UAPSD mode activated\n");
311 adapter->tx_lock_flag = false;
312 if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
313 if (mwifiex_check_last_packet_indication(priv)) {
314 if (adapter->data_sent) {
315 adapter->ps_state = PS_STATE_AWAKE;
316 adapter->pm_wakeup_card_req = false;
317 adapter->pm_wakeup_fw_try = false;
318 del_timer(&adapter->wakeup_timer);
321 if (!mwifiex_send_null_packet
323 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
324 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
330 adapter->ps_state = PS_STATE_AWAKE;
331 adapter->pm_wakeup_card_req = false;
332 adapter->pm_wakeup_fw_try = false;
333 del_timer(&adapter->wakeup_timer);
337 case EVENT_DEEP_SLEEP_AWAKE:
338 adapter->if_ops.wakeup_complete(adapter);
339 mwifiex_dbg(adapter, EVENT, "event: DS_AWAKE\n");
340 if (adapter->is_deep_sleep)
341 adapter->is_deep_sleep = false;
344 case EVENT_HS_ACT_REQ:
345 mwifiex_dbg(adapter, EVENT, "event: HS_ACT_REQ\n");
346 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_HS_CFG_ENH,
350 case EVENT_MIC_ERR_UNICAST:
351 mwifiex_dbg(adapter, EVENT, "event: UNICAST MIC ERROR\n");
352 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
353 NL80211_KEYTYPE_PAIRWISE,
354 -1, NULL, GFP_KERNEL);
357 case EVENT_MIC_ERR_MULTICAST:
358 mwifiex_dbg(adapter, EVENT, "event: MULTICAST MIC ERROR\n");
359 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
360 NL80211_KEYTYPE_GROUP,
361 -1, NULL, GFP_KERNEL);
363 case EVENT_MIB_CHANGED:
364 case EVENT_INIT_DONE:
367 case EVENT_ADHOC_BCN_LOST:
368 mwifiex_dbg(adapter, EVENT, "event: ADHOC_BCN_LOST\n");
369 priv->adhoc_is_link_sensed = false;
370 mwifiex_clean_txrx(priv);
371 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
372 if (netif_carrier_ok(priv->netdev))
373 netif_carrier_off(priv->netdev);
376 case EVENT_BG_SCAN_REPORT:
377 mwifiex_dbg(adapter, EVENT, "event: BGS_REPORT\n");
378 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_QUERY,
379 HostCmd_ACT_GEN_GET, 0, NULL, false);
382 case EVENT_PORT_RELEASE:
383 mwifiex_dbg(adapter, EVENT, "event: PORT RELEASE\n");
386 case EVENT_EXT_SCAN_REPORT:
387 mwifiex_dbg(adapter, EVENT, "event: EXT_SCAN Report\n");
388 if (adapter->ext_scan)
389 ret = mwifiex_handle_event_ext_scan_report(priv,
390 adapter->event_skb->data);
394 case EVENT_WMM_STATUS_CHANGE:
395 mwifiex_dbg(adapter, EVENT, "event: WMM status changed\n");
396 ret = mwifiex_send_cmd(priv, HostCmd_CMD_WMM_GET_STATUS,
401 cfg80211_cqm_rssi_notify(priv->netdev,
402 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
404 mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
405 HostCmd_ACT_GEN_GET, 0, NULL, false);
406 priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
407 mwifiex_dbg(adapter, EVENT, "event: Beacon RSSI_LOW\n");
410 mwifiex_dbg(adapter, EVENT, "event: Beacon SNR_LOW\n");
413 mwifiex_dbg(adapter, EVENT, "event: MAX_FAIL\n");
415 case EVENT_RSSI_HIGH:
416 cfg80211_cqm_rssi_notify(priv->netdev,
417 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
419 mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
420 HostCmd_ACT_GEN_GET, 0, NULL, false);
421 priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
422 mwifiex_dbg(adapter, EVENT, "event: Beacon RSSI_HIGH\n");
425 mwifiex_dbg(adapter, EVENT, "event: Beacon SNR_HIGH\n");
427 case EVENT_DATA_RSSI_LOW:
428 mwifiex_dbg(adapter, EVENT, "event: Data RSSI_LOW\n");
430 case EVENT_DATA_SNR_LOW:
431 mwifiex_dbg(adapter, EVENT, "event: Data SNR_LOW\n");
433 case EVENT_DATA_RSSI_HIGH:
434 mwifiex_dbg(adapter, EVENT, "event: Data RSSI_HIGH\n");
436 case EVENT_DATA_SNR_HIGH:
437 mwifiex_dbg(adapter, EVENT, "event: Data SNR_HIGH\n");
439 case EVENT_LINK_QUALITY:
440 mwifiex_dbg(adapter, EVENT, "event: Link Quality\n");
442 case EVENT_PRE_BEACON_LOST:
443 mwifiex_dbg(adapter, EVENT, "event: Pre-Beacon Lost\n");
445 case EVENT_IBSS_COALESCED:
446 mwifiex_dbg(adapter, EVENT, "event: IBSS_COALESCED\n");
447 ret = mwifiex_send_cmd(priv,
448 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
449 HostCmd_ACT_GEN_GET, 0, NULL, false);
452 mwifiex_dbg(adapter, EVENT, "event: ADDBA Request\n");
453 mwifiex_send_cmd(priv, HostCmd_CMD_11N_ADDBA_RSP,
454 HostCmd_ACT_GEN_SET, 0,
455 adapter->event_body, false);
458 mwifiex_dbg(adapter, EVENT, "event: DELBA Request\n");
459 mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
461 case EVENT_BA_STREAM_TIEMOUT:
462 mwifiex_dbg(adapter, EVENT, "event: BA Stream timeout\n");
463 mwifiex_11n_ba_stream_timeout(priv,
464 (struct host_cmd_ds_11n_batimeout
466 adapter->event_body);
468 case EVENT_AMSDU_AGGR_CTRL:
469 ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
470 mwifiex_dbg(adapter, EVENT,
471 "event: AMSDU_AGGR_CTRL %d\n", ctrl);
473 adapter->tx_buf_size =
474 min_t(u16, adapter->curr_tx_buf_size, ctrl);
475 mwifiex_dbg(adapter, EVENT, "event: tx_buf_size %d\n",
476 adapter->tx_buf_size);
479 case EVENT_WEP_ICV_ERR:
480 mwifiex_dbg(adapter, EVENT, "event: WEP ICV error\n");
483 case EVENT_BW_CHANGE:
484 mwifiex_dbg(adapter, EVENT, "event: BW Change\n");
487 case EVENT_HOSTWAKE_STAIE:
488 mwifiex_dbg(adapter, EVENT,
489 "event: HOSTWAKE_STAIE %d\n", eventcause);
492 case EVENT_REMAIN_ON_CHAN_EXPIRED:
493 mwifiex_dbg(adapter, EVENT,
494 "event: Remain on channel expired\n");
495 cfg80211_remain_on_channel_expired(&priv->wdev,
496 priv->roc_cfg.cookie,
500 memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
504 case EVENT_CHANNEL_SWITCH_ANN:
505 mwifiex_dbg(adapter, EVENT, "event: Channel Switch Announcement\n");
506 priv->csa_expire_time =
507 jiffies + msecs_to_jiffies(DFS_CHAN_MOVE_TIME);
508 priv->csa_chan = priv->curr_bss_params.bss_descriptor.channel;
509 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
510 HostCmd_ACT_GEN_SET, 0,
511 priv->curr_bss_params.bss_descriptor.mac_address,
515 case EVENT_TDLS_GENERIC_EVENT:
516 ret = mwifiex_parse_tdls_event(priv, adapter->event_skb);
519 case EVENT_TX_STATUS_REPORT:
520 mwifiex_dbg(adapter, EVENT, "event: TX_STATUS Report\n");
521 mwifiex_parse_tx_status_event(priv, adapter->event_body);
524 case EVENT_CHANNEL_REPORT_RDY:
525 mwifiex_dbg(adapter, EVENT, "event: Channel Report\n");
526 ret = mwifiex_11h_handle_chanrpt_ready(priv,
529 case EVENT_RADAR_DETECTED:
530 mwifiex_dbg(adapter, EVENT, "event: Radar detected\n");
531 ret = mwifiex_11h_handle_radar_detected(priv,
535 mwifiex_dbg(adapter, ERROR, "event: unknown event id: %#x\n",