blob: dff51d55271c20267097245b079235f5882a1522 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: station event handling
3 *
4 * Copyright (C) 2011, 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 */
43void
44mwifiex_reset_connect_state(struct mwifiex_private *priv)
45{
46 struct mwifiex_adapter *adapter = priv->adapter;
47
48 if (!priv->media_connected)
49 return;
50
51 dev_dbg(adapter->dev, "info: handles disconnect event\n");
52
53 priv->media_connected = false;
54
55 priv->scan_block = false;
56
57 /* Free Tx and Rx packets, report disconnect to upper layer */
58 mwifiex_clean_txrx(priv);
59
60 /* Reset SNR/NF/RSSI values */
61 priv->data_rssi_last = 0;
62 priv->data_nf_last = 0;
63 priv->data_rssi_avg = 0;
64 priv->data_nf_avg = 0;
65 priv->bcn_rssi_last = 0;
66 priv->bcn_nf_last = 0;
67 priv->bcn_rssi_avg = 0;
68 priv->bcn_nf_avg = 0;
69 priv->rxpd_rate = 0;
70 priv->rxpd_htinfo = 0;
71 priv->sec_info.wpa_enabled = false;
72 priv->sec_info.wpa2_enabled = false;
73 priv->wpa_ie_len = 0;
74
75 priv->sec_info.wapi_enabled = false;
76 priv->wapi_ie_len = 0;
77 priv->sec_info.wapi_key_on = false;
78
Yogesh Ashok Powar2be50b82011-04-01 18:36:47 -070079 priv->sec_info.encryption_mode = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070080
81 /* Enable auto data rate */
82 priv->is_data_rate_auto = true;
83 priv->data_rate = 0;
84
Bing Zhaoeecd8252011-03-28 17:55:41 -070085 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -070086 priv->adhoc_state = ADHOC_IDLE;
87 priv->adhoc_is_link_sensed = false;
88 }
89
90 /*
91 * Memorize the previous SSID and BSSID so
92 * it could be used for re-assoc
93 */
94
95 dev_dbg(adapter->dev, "info: previous SSID=%s, SSID len=%u\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -070096 priv->prev_ssid.ssid, priv->prev_ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -070097
98 dev_dbg(adapter->dev, "info: current SSID=%s, SSID len=%u\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -070099 priv->curr_bss_params.bss_descriptor.ssid.ssid,
100 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700101
102 memcpy(&priv->prev_ssid,
103 &priv->curr_bss_params.bss_descriptor.ssid,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800104 sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700105
106 memcpy(priv->prev_bssid,
107 priv->curr_bss_params.bss_descriptor.mac_address, ETH_ALEN);
108
109 /* Need to erase the current SSID and BSSID info */
110 memset(&priv->curr_bss_params, 0x00, sizeof(priv->curr_bss_params));
111
112 adapter->tx_lock_flag = false;
113 adapter->pps_uapsd_mode = false;
114
115 if (adapter->num_cmd_timeout && adapter->curr_cmd)
116 return;
117 priv->media_connected = false;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700118 dev_dbg(adapter->dev,
119 "info: successfully disconnected from %pM: reason code %d\n",
120 priv->cfg_bssid, WLAN_REASON_DEAUTH_LEAVING);
Amitkumar Karwar38c9d662011-12-13 20:43:17 -0800121 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
122 cfg80211_disconnected(priv->netdev, WLAN_REASON_DEAUTH_LEAVING,
123 NULL, 0, GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700124 }
Amitkumar Karwar38c9d662011-12-13 20:43:17 -0800125 memset(priv->cfg_bssid, 0, ETH_ALEN);
126
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700127 if (!netif_queue_stopped(priv->netdev))
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800128 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700129 if (netif_carrier_ok(priv->netdev))
130 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700131}
132
133/*
134 * This function handles events generated by firmware.
135 *
136 * This is a generic function and handles all events.
137 *
138 * Event specific routines are called by this function based
139 * upon the generated event cause.
140 *
141 * For the following events, the function just forwards them to upper
142 * layers, optionally recording the change -
143 * - EVENT_LINK_SENSED
144 * - EVENT_MIC_ERR_UNICAST
145 * - EVENT_MIC_ERR_MULTICAST
146 * - EVENT_PORT_RELEASE
147 * - EVENT_RSSI_LOW
148 * - EVENT_SNR_LOW
149 * - EVENT_MAX_FAIL
150 * - EVENT_RSSI_HIGH
151 * - EVENT_SNR_HIGH
152 * - EVENT_DATA_RSSI_LOW
153 * - EVENT_DATA_SNR_LOW
154 * - EVENT_DATA_RSSI_HIGH
155 * - EVENT_DATA_SNR_HIGH
156 * - EVENT_LINK_QUALITY
157 * - EVENT_PRE_BEACON_LOST
158 * - EVENT_IBSS_COALESCED
159 * - EVENT_WEP_ICV_ERR
160 * - EVENT_BW_CHANGE
161 * - EVENT_HOSTWAKE_STAIE
162 *
163 * For the following events, no action is taken -
164 * - EVENT_MIB_CHANGED
165 * - EVENT_INIT_DONE
166 * - EVENT_DUMMY_HOST_WAKEUP_SIGNAL
167 *
168 * Rest of the supported events requires driver handling -
169 * - EVENT_DEAUTHENTICATED
170 * - EVENT_DISASSOCIATED
171 * - EVENT_LINK_LOST
172 * - EVENT_PS_SLEEP
173 * - EVENT_PS_AWAKE
174 * - EVENT_DEEP_SLEEP_AWAKE
175 * - EVENT_HS_ACT_REQ
176 * - EVENT_ADHOC_BCN_LOST
177 * - EVENT_BG_SCAN_REPORT
178 * - EVENT_WMM_STATUS_CHANGE
179 * - EVENT_ADDBA
180 * - EVENT_DELBA
181 * - EVENT_BA_STREAM_TIEMOUT
182 * - EVENT_AMSDU_AGGR_CTRL
183 */
184int mwifiex_process_sta_event(struct mwifiex_private *priv)
185{
186 struct mwifiex_adapter *adapter = priv->adapter;
Avinash Patil3d99d982012-08-03 18:06:06 -0700187 int ret = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700188 u32 eventcause = adapter->event_cause;
Bing Zhao8dd43722012-08-07 16:08:08 -0700189 u16 ctrl;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700190
191 switch (eventcause) {
192 case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700193 dev_err(adapter->dev,
194 "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700195 break;
196 case EVENT_LINK_SENSED:
197 dev_dbg(adapter->dev, "event: LINK_SENSED\n");
198 if (!netif_carrier_ok(priv->netdev))
199 netif_carrier_on(priv->netdev);
200 if (netif_queue_stopped(priv->netdev))
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800201 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700202 break;
203
204 case EVENT_DEAUTHENTICATED:
205 dev_dbg(adapter->dev, "event: Deauthenticated\n");
206 adapter->dbg.num_event_deauth++;
207 if (priv->media_connected)
208 mwifiex_reset_connect_state(priv);
209 break;
210
211 case EVENT_DISASSOCIATED:
212 dev_dbg(adapter->dev, "event: Disassociated\n");
213 adapter->dbg.num_event_disassoc++;
214 if (priv->media_connected)
215 mwifiex_reset_connect_state(priv);
216 break;
217
218 case EVENT_LINK_LOST:
219 dev_dbg(adapter->dev, "event: Link lost\n");
220 adapter->dbg.num_event_link_lost++;
221 if (priv->media_connected)
222 mwifiex_reset_connect_state(priv);
223 break;
224
225 case EVENT_PS_SLEEP:
226 dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
227
228 adapter->ps_state = PS_STATE_PRE_SLEEP;
229
230 mwifiex_check_ps_cond(adapter);
231 break;
232
233 case EVENT_PS_AWAKE:
234 dev_dbg(adapter->dev, "info: EVENT: AWAKE\n");
235 if (!adapter->pps_uapsd_mode &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700236 priv->media_connected && adapter->sleep_period.period) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700237 adapter->pps_uapsd_mode = true;
238 dev_dbg(adapter->dev,
239 "event: PPS/UAPSD mode activated\n");
240 }
241 adapter->tx_lock_flag = false;
242 if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
243 if (mwifiex_check_last_packet_indication(priv)) {
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700244 if (adapter->data_sent) {
245 adapter->ps_state = PS_STATE_AWAKE;
246 adapter->pm_wakeup_card_req = false;
247 adapter->pm_wakeup_fw_try = false;
248 break;
249 }
250 if (!mwifiex_send_null_packet
251 (priv,
252 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
253 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700254 adapter->ps_state =
255 PS_STATE_SLEEP;
256 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700257 }
258 }
259 adapter->ps_state = PS_STATE_AWAKE;
260 adapter->pm_wakeup_card_req = false;
261 adapter->pm_wakeup_fw_try = false;
262
263 break;
264
265 case EVENT_DEEP_SLEEP_AWAKE:
266 adapter->if_ops.wakeup_complete(adapter);
267 dev_dbg(adapter->dev, "event: DS_AWAKE\n");
268 if (adapter->is_deep_sleep)
269 adapter->is_deep_sleep = false;
270 break;
271
272 case EVENT_HS_ACT_REQ:
273 dev_dbg(adapter->dev, "event: HS_ACT_REQ\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700274 ret = mwifiex_send_cmd_async(priv,
275 HostCmd_CMD_802_11_HS_CFG_ENH,
276 0, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700277 break;
278
279 case EVENT_MIC_ERR_UNICAST:
280 dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n");
Amitkumar Karwar9c7ff732012-08-08 19:02:56 -0700281 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
282 NL80211_KEYTYPE_PAIRWISE,
283 -1, NULL, GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700284 break;
285
286 case EVENT_MIC_ERR_MULTICAST:
287 dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n");
Amitkumar Karwar9c7ff732012-08-08 19:02:56 -0700288 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
289 NL80211_KEYTYPE_GROUP,
290 -1, NULL, GFP_KERNEL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700291 break;
292 case EVENT_MIB_CHANGED:
293 case EVENT_INIT_DONE:
294 break;
295
296 case EVENT_ADHOC_BCN_LOST:
297 dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n");
298 priv->adhoc_is_link_sensed = false;
299 mwifiex_clean_txrx(priv);
300 if (!netif_queue_stopped(priv->netdev))
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800301 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700302 if (netif_carrier_ok(priv->netdev))
303 netif_carrier_off(priv->netdev);
304 break;
305
306 case EVENT_BG_SCAN_REPORT:
307 dev_dbg(adapter->dev, "event: BGS_REPORT\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700308 ret = mwifiex_send_cmd_async(priv,
309 HostCmd_CMD_802_11_BG_SCAN_QUERY,
310 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700311 break;
312
313 case EVENT_PORT_RELEASE:
314 dev_dbg(adapter->dev, "event: PORT RELEASE\n");
315 break;
316
317 case EVENT_WMM_STATUS_CHANGE:
318 dev_dbg(adapter->dev, "event: WMM status changed\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700319 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_WMM_GET_STATUS,
320 0, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700321 break;
322
323 case EVENT_RSSI_LOW:
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700324 cfg80211_cqm_rssi_notify(priv->netdev,
325 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
326 GFP_KERNEL);
327 mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
328 HostCmd_ACT_GEN_GET, 0, NULL);
329 priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700330 dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n");
331 break;
332 case EVENT_SNR_LOW:
333 dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
334 break;
335 case EVENT_MAX_FAIL:
336 dev_dbg(adapter->dev, "event: MAX_FAIL\n");
337 break;
338 case EVENT_RSSI_HIGH:
Amitkumar Karwarfa444bf2012-03-15 20:51:51 -0700339 cfg80211_cqm_rssi_notify(priv->netdev,
340 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
341 GFP_KERNEL);
342 mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
343 HostCmd_ACT_GEN_GET, 0, NULL);
344 priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700345 dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n");
346 break;
347 case EVENT_SNR_HIGH:
348 dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
349 break;
350 case EVENT_DATA_RSSI_LOW:
351 dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
352 break;
353 case EVENT_DATA_SNR_LOW:
354 dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
355 break;
356 case EVENT_DATA_RSSI_HIGH:
357 dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
358 break;
359 case EVENT_DATA_SNR_HIGH:
360 dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
361 break;
362 case EVENT_LINK_QUALITY:
363 dev_dbg(adapter->dev, "event: Link Quality\n");
364 break;
365 case EVENT_PRE_BEACON_LOST:
366 dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
367 break;
368 case EVENT_IBSS_COALESCED:
369 dev_dbg(adapter->dev, "event: IBSS_COALESCED\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700370 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700371 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700372 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700373 break;
374 case EVENT_ADDBA:
375 dev_dbg(adapter->dev, "event: ADDBA Request\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700376 mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP,
377 HostCmd_ACT_GEN_SET, 0,
378 adapter->event_body);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700379 break;
380 case EVENT_DELBA:
381 dev_dbg(adapter->dev, "event: DELBA Request\n");
382 mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
383 break;
384 case EVENT_BA_STREAM_TIEMOUT:
385 dev_dbg(adapter->dev, "event: BA Stream timeout\n");
386 mwifiex_11n_ba_stream_timeout(priv,
387 (struct host_cmd_ds_11n_batimeout
388 *)
389 adapter->event_body);
390 break;
391 case EVENT_AMSDU_AGGR_CTRL:
Bing Zhao8dd43722012-08-07 16:08:08 -0700392 ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
393 dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
394
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700395 adapter->tx_buf_size =
Bing Zhao8dd43722012-08-07 16:08:08 -0700396 min_t(u16, adapter->curr_tx_buf_size, ctrl);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700397 dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700398 adapter->tx_buf_size);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700399 break;
400
401 case EVENT_WEP_ICV_ERR:
402 dev_dbg(adapter->dev, "event: WEP ICV error\n");
403 break;
404
405 case EVENT_BW_CHANGE:
406 dev_dbg(adapter->dev, "event: BW Change\n");
407 break;
408
409 case EVENT_HOSTWAKE_STAIE:
410 dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
411 break;
Avinash Patile5686342012-05-08 18:30:25 -0700412
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700413 default:
414 dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700415 eventcause);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700416 break;
417 }
418
419 return ret;
420}