]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/net/wireless/mwifiex/sta_event.c
mwifiex: separate out next scan command queueing logic
[mirror_ubuntu-zesty-kernel.git] / drivers / net / wireless / mwifiex / sta_event.c
CommitLineData
5e6e3a92
BZ
1/*
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
8cc1d523 44mwifiex_reset_connect_state(struct mwifiex_private *priv, u16 reason_code)
5e6e3a92
BZ
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
2be50b8d 79 priv->sec_info.encryption_mode = 0;
5e6e3a92
BZ
80
81 /* Enable auto data rate */
82 priv->is_data_rate_auto = true;
83 priv->data_rate = 0;
84
eecd8250 85 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
5e6e3a92
BZ
86 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",
500f747c 96 priv->prev_ssid.ssid, priv->prev_ssid.ssid_len);
5e6e3a92
BZ
97
98 dev_dbg(adapter->dev, "info: current SSID=%s, SSID len=%u\n",
500f747c
YAP
99 priv->curr_bss_params.bss_descriptor.ssid.ssid,
100 priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
5e6e3a92
BZ
101
102 memcpy(&priv->prev_ssid,
103 &priv->curr_bss_params.bss_descriptor.ssid,
b9be5f39 104 sizeof(struct cfg80211_ssid));
5e6e3a92
BZ
105
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;
500f747c
YAP
118 dev_dbg(adapter->dev,
119 "info: successfully disconnected from %pM: reason code %d\n",
8cc1d523 120 priv->cfg_bssid, reason_code);
9612bd1e
AP
121 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
122 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
8cc1d523
AK
123 cfg80211_disconnected(priv->netdev, reason_code, NULL, 0,
124 GFP_KERNEL);
5e6e3a92 125 }
38c9d664
AK
126 memset(priv->cfg_bssid, 0, ETH_ALEN);
127
47411a06 128 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
5e6e3a92
BZ
129 if (netif_carrier_ok(priv->netdev))
130 netif_carrier_off(priv->netdev);
5e6e3a92
BZ
131}
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;
3d99d987 187 int ret = 0;
5e6e3a92 188 u32 eventcause = adapter->event_cause;
8cc1d523 189 u16 ctrl, reason_code;
5e6e3a92
BZ
190
191 switch (eventcause) {
192 case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
500f747c
YAP
193 dev_err(adapter->dev,
194 "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
5e6e3a92
BZ
195 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);
47411a06 200 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
5e6e3a92
BZ
201 break;
202
203 case EVENT_DEAUTHENTICATED:
204 dev_dbg(adapter->dev, "event: Deauthenticated\n");
eaf49dbc
SP
205 if (priv->wps.session_enable) {
206 dev_dbg(adapter->dev,
207 "info: receive deauth event in wps session\n");
208 break;
209 }
5e6e3a92 210 adapter->dbg.num_event_deauth++;
8cc1d523
AK
211 if (priv->media_connected) {
212 reason_code =
213 le16_to_cpu(*(__le16 *)adapter->event_body);
214 mwifiex_reset_connect_state(priv, reason_code);
215 }
5e6e3a92
BZ
216 break;
217
218 case EVENT_DISASSOCIATED:
219 dev_dbg(adapter->dev, "event: Disassociated\n");
eaf49dbc
SP
220 if (priv->wps.session_enable) {
221 dev_dbg(adapter->dev,
222 "info: receive disassoc event in wps session\n");
223 break;
224 }
5e6e3a92 225 adapter->dbg.num_event_disassoc++;
8cc1d523
AK
226 if (priv->media_connected) {
227 reason_code =
228 le16_to_cpu(*(__le16 *)adapter->event_body);
229 mwifiex_reset_connect_state(priv, reason_code);
230 }
5e6e3a92
BZ
231 break;
232
233 case EVENT_LINK_LOST:
234 dev_dbg(adapter->dev, "event: Link lost\n");
235 adapter->dbg.num_event_link_lost++;
8cc1d523
AK
236 if (priv->media_connected) {
237 reason_code =
238 le16_to_cpu(*(__le16 *)adapter->event_body);
239 mwifiex_reset_connect_state(priv, reason_code);
240 }
5e6e3a92
BZ
241 break;
242
243 case EVENT_PS_SLEEP:
244 dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
245
246 adapter->ps_state = PS_STATE_PRE_SLEEP;
247
248 mwifiex_check_ps_cond(adapter);
249 break;
250
251 case EVENT_PS_AWAKE:
252 dev_dbg(adapter->dev, "info: EVENT: AWAKE\n");
253 if (!adapter->pps_uapsd_mode &&
500f747c 254 priv->media_connected && adapter->sleep_period.period) {
5e6e3a92
BZ
255 adapter->pps_uapsd_mode = true;
256 dev_dbg(adapter->dev,
257 "event: PPS/UAPSD mode activated\n");
258 }
259 adapter->tx_lock_flag = false;
260 if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
261 if (mwifiex_check_last_packet_indication(priv)) {
500f747c
YAP
262 if (adapter->data_sent) {
263 adapter->ps_state = PS_STATE_AWAKE;
264 adapter->pm_wakeup_card_req = false;
265 adapter->pm_wakeup_fw_try = false;
266 break;
267 }
268 if (!mwifiex_send_null_packet
269 (priv,
270 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
271 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
5e6e3a92
BZ
272 adapter->ps_state =
273 PS_STATE_SLEEP;
274 return 0;
5e6e3a92
BZ
275 }
276 }
277 adapter->ps_state = PS_STATE_AWAKE;
278 adapter->pm_wakeup_card_req = false;
279 adapter->pm_wakeup_fw_try = false;
280
281 break;
282
283 case EVENT_DEEP_SLEEP_AWAKE:
284 adapter->if_ops.wakeup_complete(adapter);
285 dev_dbg(adapter->dev, "event: DS_AWAKE\n");
286 if (adapter->is_deep_sleep)
287 adapter->is_deep_sleep = false;
288 break;
289
290 case EVENT_HS_ACT_REQ:
291 dev_dbg(adapter->dev, "event: HS_ACT_REQ\n");
600f5d90
AK
292 ret = mwifiex_send_cmd_async(priv,
293 HostCmd_CMD_802_11_HS_CFG_ENH,
294 0, 0, NULL);
5e6e3a92
BZ
295 break;
296
297 case EVENT_MIC_ERR_UNICAST:
298 dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n");
9c7ff737
AK
299 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
300 NL80211_KEYTYPE_PAIRWISE,
301 -1, NULL, GFP_KERNEL);
5e6e3a92
BZ
302 break;
303
304 case EVENT_MIC_ERR_MULTICAST:
305 dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n");
9c7ff737
AK
306 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
307 NL80211_KEYTYPE_GROUP,
308 -1, NULL, GFP_KERNEL);
5e6e3a92
BZ
309 break;
310 case EVENT_MIB_CHANGED:
311 case EVENT_INIT_DONE:
312 break;
313
314 case EVENT_ADHOC_BCN_LOST:
315 dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n");
316 priv->adhoc_is_link_sensed = false;
317 mwifiex_clean_txrx(priv);
47411a06 318 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
5e6e3a92
BZ
319 if (netif_carrier_ok(priv->netdev))
320 netif_carrier_off(priv->netdev);
321 break;
322
323 case EVENT_BG_SCAN_REPORT:
324 dev_dbg(adapter->dev, "event: BGS_REPORT\n");
600f5d90
AK
325 ret = mwifiex_send_cmd_async(priv,
326 HostCmd_CMD_802_11_BG_SCAN_QUERY,
327 HostCmd_ACT_GEN_GET, 0, NULL);
5e6e3a92
BZ
328 break;
329
330 case EVENT_PORT_RELEASE:
331 dev_dbg(adapter->dev, "event: PORT RELEASE\n");
332 break;
333
334 case EVENT_WMM_STATUS_CHANGE:
335 dev_dbg(adapter->dev, "event: WMM status changed\n");
600f5d90
AK
336 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_WMM_GET_STATUS,
337 0, 0, NULL);
5e6e3a92
BZ
338 break;
339
340 case EVENT_RSSI_LOW:
fa444bf8
AK
341 cfg80211_cqm_rssi_notify(priv->netdev,
342 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
343 GFP_KERNEL);
344 mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
345 HostCmd_ACT_GEN_GET, 0, NULL);
346 priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
5e6e3a92
BZ
347 dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n");
348 break;
349 case EVENT_SNR_LOW:
350 dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
351 break;
352 case EVENT_MAX_FAIL:
353 dev_dbg(adapter->dev, "event: MAX_FAIL\n");
354 break;
355 case EVENT_RSSI_HIGH:
fa444bf8
AK
356 cfg80211_cqm_rssi_notify(priv->netdev,
357 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
358 GFP_KERNEL);
359 mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
360 HostCmd_ACT_GEN_GET, 0, NULL);
361 priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
5e6e3a92
BZ
362 dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n");
363 break;
364 case EVENT_SNR_HIGH:
365 dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
366 break;
367 case EVENT_DATA_RSSI_LOW:
368 dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
369 break;
370 case EVENT_DATA_SNR_LOW:
371 dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
372 break;
373 case EVENT_DATA_RSSI_HIGH:
374 dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
375 break;
376 case EVENT_DATA_SNR_HIGH:
377 dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
378 break;
379 case EVENT_LINK_QUALITY:
380 dev_dbg(adapter->dev, "event: Link Quality\n");
381 break;
382 case EVENT_PRE_BEACON_LOST:
383 dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
384 break;
385 case EVENT_IBSS_COALESCED:
386 dev_dbg(adapter->dev, "event: IBSS_COALESCED\n");
600f5d90 387 ret = mwifiex_send_cmd_async(priv,
5e6e3a92 388 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
600f5d90 389 HostCmd_ACT_GEN_GET, 0, NULL);
5e6e3a92
BZ
390 break;
391 case EVENT_ADDBA:
392 dev_dbg(adapter->dev, "event: ADDBA Request\n");
600f5d90
AK
393 mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP,
394 HostCmd_ACT_GEN_SET, 0,
395 adapter->event_body);
5e6e3a92
BZ
396 break;
397 case EVENT_DELBA:
398 dev_dbg(adapter->dev, "event: DELBA Request\n");
399 mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
400 break;
401 case EVENT_BA_STREAM_TIEMOUT:
402 dev_dbg(adapter->dev, "event: BA Stream timeout\n");
403 mwifiex_11n_ba_stream_timeout(priv,
404 (struct host_cmd_ds_11n_batimeout
405 *)
406 adapter->event_body);
407 break;
408 case EVENT_AMSDU_AGGR_CTRL:
8dd4372e
BZ
409 ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
410 dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
411
5e6e3a92 412 adapter->tx_buf_size =
8dd4372e 413 min_t(u16, adapter->curr_tx_buf_size, ctrl);
5e6e3a92 414 dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
500f747c 415 adapter->tx_buf_size);
5e6e3a92
BZ
416 break;
417
418 case EVENT_WEP_ICV_ERR:
419 dev_dbg(adapter->dev, "event: WEP ICV error\n");
420 break;
421
422 case EVENT_BW_CHANGE:
423 dev_dbg(adapter->dev, "event: BW Change\n");
424 break;
425
426 case EVENT_HOSTWAKE_STAIE:
427 dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
428 break;
e568634a 429
eab1c76b
SP
430 case EVENT_REMAIN_ON_CHAN_EXPIRED:
431 dev_dbg(adapter->dev, "event: Remain on channel expired\n");
432 cfg80211_remain_on_channel_expired(priv->wdev,
433 priv->roc_cfg.cookie,
434 &priv->roc_cfg.chan,
eab1c76b
SP
435 GFP_ATOMIC);
436
437 memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
438
439 break;
440
2a7305c8
AK
441 case EVENT_CHANNEL_SWITCH_ANN:
442 dev_dbg(adapter->dev, "event: Channel Switch Announcement\n");
b887664d
AK
443 priv->csa_expire_time =
444 jiffies + msecs_to_jiffies(DFS_CHAN_MOVE_TIME);
445 priv->csa_chan = priv->curr_bss_params.bss_descriptor.channel;
2a7305c8
AK
446 ret = mwifiex_send_cmd_async(priv,
447 HostCmd_CMD_802_11_DEAUTHENTICATE,
448 HostCmd_ACT_GEN_SET, 0,
449 priv->curr_bss_params.bss_descriptor.mac_address);
450 break;
451
5e6e3a92
BZ
452 default:
453 dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
500f747c 454 eventcause);
5e6e3a92
BZ
455 break;
456 }
457
458 return ret;
459}