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 dev_dbg(adapter->dev, "info: handles disconnect event\n");
53 priv->media_connected = false;
55 priv->scan_block = false;
57 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
58 ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
59 mwifiex_disable_all_tdls_links(priv);
61 /* Free Tx and Rx packets, report disconnect to upper layer */
62 mwifiex_clean_txrx(priv);
64 /* Reset SNR/NF/RSSI values */
65 priv->data_rssi_last = 0;
66 priv->data_nf_last = 0;
67 priv->data_rssi_avg = 0;
68 priv->data_nf_avg = 0;
69 priv->bcn_rssi_last = 0;
70 priv->bcn_nf_last = 0;
71 priv->bcn_rssi_avg = 0;
74 priv->rxpd_htinfo = 0;
75 priv->sec_info.wpa_enabled = false;
76 priv->sec_info.wpa2_enabled = false;
79 priv->sec_info.wapi_enabled = false;
80 priv->wapi_ie_len = 0;
81 priv->sec_info.wapi_key_on = false;
83 priv->sec_info.encryption_mode = 0;
85 /* Enable auto data rate */
86 priv->is_data_rate_auto = true;
89 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
90 priv->adhoc_state = ADHOC_IDLE;
91 priv->adhoc_is_link_sensed = false;
95 * Memorize the previous SSID and BSSID so
96 * it could be used for re-assoc
99 dev_dbg(adapter->dev, "info: previous SSID=%s, SSID len=%u\n",
100 priv->prev_ssid.ssid, priv->prev_ssid.ssid_len);
102 dev_dbg(adapter->dev, "info: current SSID=%s, SSID len=%u\n",
103 priv->curr_bss_params.bss_descriptor.ssid.ssid,
104 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
106 memcpy(&priv->prev_ssid,
107 &priv->curr_bss_params.bss_descriptor.ssid,
108 sizeof(struct cfg80211_ssid));
110 memcpy(priv->prev_bssid,
111 priv->curr_bss_params.bss_descriptor.mac_address, ETH_ALEN);
113 /* Need to erase the current SSID and BSSID info */
114 memset(&priv->curr_bss_params, 0x00, sizeof(priv->curr_bss_params));
116 adapter->tx_lock_flag = false;
117 adapter->pps_uapsd_mode = false;
119 if (adapter->is_cmd_timedout && adapter->curr_cmd)
121 priv->media_connected = false;
122 dev_dbg(adapter->dev,
123 "info: successfully disconnected from %pM: reason code %d\n",
124 priv->cfg_bssid, reason_code);
125 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
126 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
127 cfg80211_disconnected(priv->netdev, reason_code, NULL, 0,
130 memset(priv->cfg_bssid, 0, ETH_ALEN);
132 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
133 if (netif_carrier_ok(priv->netdev))
134 netif_carrier_off(priv->netdev);
137 static int mwifiex_parse_tdls_event(struct mwifiex_private *priv,
138 struct sk_buff *event_skb)
141 struct mwifiex_adapter *adapter = priv->adapter;
142 struct mwifiex_sta_node *sta_ptr;
143 struct mwifiex_tdls_generic_event *tdls_evt =
144 (void *)event_skb->data + sizeof(adapter->event_cause);
146 /* reserved 2 bytes are not mandatory in tdls event */
147 if (event_skb->len < (sizeof(struct mwifiex_tdls_generic_event) -
148 sizeof(u16) - sizeof(adapter->event_cause))) {
149 dev_err(adapter->dev, "Invalid event length!\n");
153 sta_ptr = mwifiex_get_sta_entry(priv, tdls_evt->peer_mac);
155 dev_err(adapter->dev, "cannot get sta entry!\n");
159 switch (le16_to_cpu(tdls_evt->type)) {
160 case TDLS_EVENT_LINK_TEAR_DOWN:
161 cfg80211_tdls_oper_request(priv->netdev,
163 NL80211_TDLS_TEARDOWN,
164 le16_to_cpu(tdls_evt->u.reason_code),
166 ret = mwifiex_tdls_oper(priv, tdls_evt->peer_mac,
167 MWIFIEX_TDLS_DISABLE_LINK);
168 queue_work(adapter->workqueue, &adapter->main_work);
178 * This function handles events generated by firmware.
180 * This is a generic function and handles all events.
182 * Event specific routines are called by this function based
183 * upon the generated event cause.
185 * For the following events, the function just forwards them to upper
186 * layers, optionally recording the change -
187 * - EVENT_LINK_SENSED
188 * - EVENT_MIC_ERR_UNICAST
189 * - EVENT_MIC_ERR_MULTICAST
190 * - EVENT_PORT_RELEASE
196 * - EVENT_DATA_RSSI_LOW
197 * - EVENT_DATA_SNR_LOW
198 * - EVENT_DATA_RSSI_HIGH
199 * - EVENT_DATA_SNR_HIGH
200 * - EVENT_LINK_QUALITY
201 * - EVENT_PRE_BEACON_LOST
202 * - EVENT_IBSS_COALESCED
203 * - EVENT_WEP_ICV_ERR
205 * - EVENT_HOSTWAKE_STAIE
207 * For the following events, no action is taken -
208 * - EVENT_MIB_CHANGED
210 * - EVENT_DUMMY_HOST_WAKEUP_SIGNAL
212 * Rest of the supported events requires driver handling -
213 * - EVENT_DEAUTHENTICATED
214 * - EVENT_DISASSOCIATED
218 * - EVENT_DEEP_SLEEP_AWAKE
220 * - EVENT_ADHOC_BCN_LOST
221 * - EVENT_BG_SCAN_REPORT
222 * - EVENT_WMM_STATUS_CHANGE
225 * - EVENT_BA_STREAM_TIEMOUT
226 * - EVENT_AMSDU_AGGR_CTRL
228 int mwifiex_process_sta_event(struct mwifiex_private *priv)
230 struct mwifiex_adapter *adapter = priv->adapter;
232 u32 eventcause = adapter->event_cause;
233 u16 ctrl, reason_code;
235 switch (eventcause) {
236 case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
237 dev_err(adapter->dev,
238 "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
240 case EVENT_LINK_SENSED:
241 dev_dbg(adapter->dev, "event: LINK_SENSED\n");
242 if (!netif_carrier_ok(priv->netdev))
243 netif_carrier_on(priv->netdev);
244 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
247 case EVENT_DEAUTHENTICATED:
248 dev_dbg(adapter->dev, "event: Deauthenticated\n");
249 if (priv->wps.session_enable) {
250 dev_dbg(adapter->dev,
251 "info: receive deauth event in wps session\n");
254 adapter->dbg.num_event_deauth++;
255 if (priv->media_connected) {
257 le16_to_cpu(*(__le16 *)adapter->event_body);
258 mwifiex_reset_connect_state(priv, reason_code);
262 case EVENT_DISASSOCIATED:
263 dev_dbg(adapter->dev, "event: Disassociated\n");
264 if (priv->wps.session_enable) {
265 dev_dbg(adapter->dev,
266 "info: receive disassoc event in wps session\n");
269 adapter->dbg.num_event_disassoc++;
270 if (priv->media_connected) {
272 le16_to_cpu(*(__le16 *)adapter->event_body);
273 mwifiex_reset_connect_state(priv, reason_code);
277 case EVENT_LINK_LOST:
278 dev_dbg(adapter->dev, "event: Link lost\n");
279 adapter->dbg.num_event_link_lost++;
280 if (priv->media_connected) {
282 le16_to_cpu(*(__le16 *)adapter->event_body);
283 mwifiex_reset_connect_state(priv, reason_code);
288 dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
290 adapter->ps_state = PS_STATE_PRE_SLEEP;
292 mwifiex_check_ps_cond(adapter);
296 dev_dbg(adapter->dev, "info: EVENT: AWAKE\n");
297 if (!adapter->pps_uapsd_mode &&
298 priv->media_connected && adapter->sleep_period.period) {
299 adapter->pps_uapsd_mode = true;
300 dev_dbg(adapter->dev,
301 "event: PPS/UAPSD mode activated\n");
303 adapter->tx_lock_flag = false;
304 if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
305 if (mwifiex_check_last_packet_indication(priv)) {
306 if (adapter->data_sent) {
307 adapter->ps_state = PS_STATE_AWAKE;
308 adapter->pm_wakeup_card_req = false;
309 adapter->pm_wakeup_fw_try = false;
312 if (!mwifiex_send_null_packet
314 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
315 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
321 adapter->ps_state = PS_STATE_AWAKE;
322 adapter->pm_wakeup_card_req = false;
323 adapter->pm_wakeup_fw_try = false;
327 case EVENT_DEEP_SLEEP_AWAKE:
328 adapter->if_ops.wakeup_complete(adapter);
329 dev_dbg(adapter->dev, "event: DS_AWAKE\n");
330 if (adapter->is_deep_sleep)
331 adapter->is_deep_sleep = false;
334 case EVENT_HS_ACT_REQ:
335 dev_dbg(adapter->dev, "event: HS_ACT_REQ\n");
336 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_HS_CFG_ENH,
340 case EVENT_MIC_ERR_UNICAST:
341 dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n");
342 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
343 NL80211_KEYTYPE_PAIRWISE,
344 -1, NULL, GFP_KERNEL);
347 case EVENT_MIC_ERR_MULTICAST:
348 dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n");
349 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
350 NL80211_KEYTYPE_GROUP,
351 -1, NULL, GFP_KERNEL);
353 case EVENT_MIB_CHANGED:
354 case EVENT_INIT_DONE:
357 case EVENT_ADHOC_BCN_LOST:
358 dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n");
359 priv->adhoc_is_link_sensed = false;
360 mwifiex_clean_txrx(priv);
361 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
362 if (netif_carrier_ok(priv->netdev))
363 netif_carrier_off(priv->netdev);
366 case EVENT_BG_SCAN_REPORT:
367 dev_dbg(adapter->dev, "event: BGS_REPORT\n");
368 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_QUERY,
369 HostCmd_ACT_GEN_GET, 0, NULL, false);
372 case EVENT_PORT_RELEASE:
373 dev_dbg(adapter->dev, "event: PORT RELEASE\n");
376 case EVENT_EXT_SCAN_REPORT:
377 dev_dbg(adapter->dev, "event: EXT_SCAN Report\n");
378 if (adapter->ext_scan)
379 ret = mwifiex_handle_event_ext_scan_report(priv,
380 adapter->event_skb->data);
384 case EVENT_WMM_STATUS_CHANGE:
385 dev_dbg(adapter->dev, "event: WMM status changed\n");
386 ret = mwifiex_send_cmd(priv, HostCmd_CMD_WMM_GET_STATUS,
391 cfg80211_cqm_rssi_notify(priv->netdev,
392 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
394 mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
395 HostCmd_ACT_GEN_GET, 0, NULL, false);
396 priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
397 dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n");
400 dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
403 dev_dbg(adapter->dev, "event: MAX_FAIL\n");
405 case EVENT_RSSI_HIGH:
406 cfg80211_cqm_rssi_notify(priv->netdev,
407 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
409 mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
410 HostCmd_ACT_GEN_GET, 0, NULL, false);
411 priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
412 dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n");
415 dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
417 case EVENT_DATA_RSSI_LOW:
418 dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
420 case EVENT_DATA_SNR_LOW:
421 dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
423 case EVENT_DATA_RSSI_HIGH:
424 dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
426 case EVENT_DATA_SNR_HIGH:
427 dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
429 case EVENT_LINK_QUALITY:
430 dev_dbg(adapter->dev, "event: Link Quality\n");
432 case EVENT_PRE_BEACON_LOST:
433 dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
435 case EVENT_IBSS_COALESCED:
436 dev_dbg(adapter->dev, "event: IBSS_COALESCED\n");
437 ret = mwifiex_send_cmd(priv,
438 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
439 HostCmd_ACT_GEN_GET, 0, NULL, false);
442 dev_dbg(adapter->dev, "event: ADDBA Request\n");
443 mwifiex_send_cmd(priv, HostCmd_CMD_11N_ADDBA_RSP,
444 HostCmd_ACT_GEN_SET, 0,
445 adapter->event_body, false);
448 dev_dbg(adapter->dev, "event: DELBA Request\n");
449 mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
451 case EVENT_BA_STREAM_TIEMOUT:
452 dev_dbg(adapter->dev, "event: BA Stream timeout\n");
453 mwifiex_11n_ba_stream_timeout(priv,
454 (struct host_cmd_ds_11n_batimeout
456 adapter->event_body);
458 case EVENT_AMSDU_AGGR_CTRL:
459 ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
460 dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
462 adapter->tx_buf_size =
463 min_t(u16, adapter->curr_tx_buf_size, ctrl);
464 dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
465 adapter->tx_buf_size);
468 case EVENT_WEP_ICV_ERR:
469 dev_dbg(adapter->dev, "event: WEP ICV error\n");
472 case EVENT_BW_CHANGE:
473 dev_dbg(adapter->dev, "event: BW Change\n");
476 case EVENT_HOSTWAKE_STAIE:
477 dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
480 case EVENT_REMAIN_ON_CHAN_EXPIRED:
481 dev_dbg(adapter->dev, "event: Remain on channel expired\n");
482 cfg80211_remain_on_channel_expired(priv->wdev,
483 priv->roc_cfg.cookie,
487 memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
491 case EVENT_CHANNEL_SWITCH_ANN:
492 dev_dbg(adapter->dev, "event: Channel Switch Announcement\n");
493 priv->csa_expire_time =
494 jiffies + msecs_to_jiffies(DFS_CHAN_MOVE_TIME);
495 priv->csa_chan = priv->curr_bss_params.bss_descriptor.channel;
496 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
497 HostCmd_ACT_GEN_SET, 0,
498 priv->curr_bss_params.bss_descriptor.mac_address,
502 case EVENT_TDLS_GENERIC_EVENT:
503 ret = mwifiex_parse_tdls_event(priv, adapter->event_skb);
507 dev_dbg(adapter->dev, "event: unknown event id: %#x\n",