fd2a7165cfa5be83a2702a4c3899a013a99ec308
[deliverable/linux.git] / drivers / net / wireless / mwifiex / sta_event.c
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 */
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 dev_dbg(adapter->dev, "info: handles disconnect event\n");
52
53 priv->media_connected = false;
54
55 priv->scan_block = false;
56
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);
60
61 /* Free Tx and Rx packets, report disconnect to upper layer */
62 mwifiex_clean_txrx(priv);
63
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;
72 priv->bcn_nf_avg = 0;
73 priv->rxpd_rate = 0;
74 priv->rxpd_htinfo = 0;
75 priv->sec_info.wpa_enabled = false;
76 priv->sec_info.wpa2_enabled = false;
77 priv->wpa_ie_len = 0;
78
79 priv->sec_info.wapi_enabled = false;
80 priv->wapi_ie_len = 0;
81 priv->sec_info.wapi_key_on = false;
82
83 priv->sec_info.encryption_mode = 0;
84
85 /* Enable auto data rate */
86 priv->is_data_rate_auto = true;
87 priv->data_rate = 0;
88
89 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
90 priv->adhoc_state = ADHOC_IDLE;
91 priv->adhoc_is_link_sensed = false;
92 }
93
94 /*
95 * Memorize the previous SSID and BSSID so
96 * it could be used for re-assoc
97 */
98
99 dev_dbg(adapter->dev, "info: previous SSID=%s, SSID len=%u\n",
100 priv->prev_ssid.ssid, priv->prev_ssid.ssid_len);
101
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);
105
106 memcpy(&priv->prev_ssid,
107 &priv->curr_bss_params.bss_descriptor.ssid,
108 sizeof(struct cfg80211_ssid));
109
110 memcpy(priv->prev_bssid,
111 priv->curr_bss_params.bss_descriptor.mac_address, ETH_ALEN);
112
113 /* Need to erase the current SSID and BSSID info */
114 memset(&priv->curr_bss_params, 0x00, sizeof(priv->curr_bss_params));
115
116 adapter->tx_lock_flag = false;
117 adapter->pps_uapsd_mode = false;
118
119 if (adapter->num_cmd_timeout && adapter->curr_cmd)
120 return;
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,
128 GFP_KERNEL);
129 }
130 memset(priv->cfg_bssid, 0, ETH_ALEN);
131
132 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
133 if (netif_carrier_ok(priv->netdev))
134 netif_carrier_off(priv->netdev);
135 }
136
137 /*
138 * This function handles events generated by firmware.
139 *
140 * This is a generic function and handles all events.
141 *
142 * Event specific routines are called by this function based
143 * upon the generated event cause.
144 *
145 * For the following events, the function just forwards them to upper
146 * layers, optionally recording the change -
147 * - EVENT_LINK_SENSED
148 * - EVENT_MIC_ERR_UNICAST
149 * - EVENT_MIC_ERR_MULTICAST
150 * - EVENT_PORT_RELEASE
151 * - EVENT_RSSI_LOW
152 * - EVENT_SNR_LOW
153 * - EVENT_MAX_FAIL
154 * - EVENT_RSSI_HIGH
155 * - EVENT_SNR_HIGH
156 * - EVENT_DATA_RSSI_LOW
157 * - EVENT_DATA_SNR_LOW
158 * - EVENT_DATA_RSSI_HIGH
159 * - EVENT_DATA_SNR_HIGH
160 * - EVENT_LINK_QUALITY
161 * - EVENT_PRE_BEACON_LOST
162 * - EVENT_IBSS_COALESCED
163 * - EVENT_WEP_ICV_ERR
164 * - EVENT_BW_CHANGE
165 * - EVENT_HOSTWAKE_STAIE
166 *
167 * For the following events, no action is taken -
168 * - EVENT_MIB_CHANGED
169 * - EVENT_INIT_DONE
170 * - EVENT_DUMMY_HOST_WAKEUP_SIGNAL
171 *
172 * Rest of the supported events requires driver handling -
173 * - EVENT_DEAUTHENTICATED
174 * - EVENT_DISASSOCIATED
175 * - EVENT_LINK_LOST
176 * - EVENT_PS_SLEEP
177 * - EVENT_PS_AWAKE
178 * - EVENT_DEEP_SLEEP_AWAKE
179 * - EVENT_HS_ACT_REQ
180 * - EVENT_ADHOC_BCN_LOST
181 * - EVENT_BG_SCAN_REPORT
182 * - EVENT_WMM_STATUS_CHANGE
183 * - EVENT_ADDBA
184 * - EVENT_DELBA
185 * - EVENT_BA_STREAM_TIEMOUT
186 * - EVENT_AMSDU_AGGR_CTRL
187 */
188 int mwifiex_process_sta_event(struct mwifiex_private *priv)
189 {
190 struct mwifiex_adapter *adapter = priv->adapter;
191 int ret = 0;
192 u32 eventcause = adapter->event_cause;
193 u16 ctrl, reason_code;
194
195 switch (eventcause) {
196 case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
197 dev_err(adapter->dev,
198 "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
199 break;
200 case EVENT_LINK_SENSED:
201 dev_dbg(adapter->dev, "event: LINK_SENSED\n");
202 if (!netif_carrier_ok(priv->netdev))
203 netif_carrier_on(priv->netdev);
204 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
205 break;
206
207 case EVENT_DEAUTHENTICATED:
208 dev_dbg(adapter->dev, "event: Deauthenticated\n");
209 if (priv->wps.session_enable) {
210 dev_dbg(adapter->dev,
211 "info: receive deauth event in wps session\n");
212 break;
213 }
214 adapter->dbg.num_event_deauth++;
215 if (priv->media_connected) {
216 reason_code =
217 le16_to_cpu(*(__le16 *)adapter->event_body);
218 mwifiex_reset_connect_state(priv, reason_code);
219 }
220 break;
221
222 case EVENT_DISASSOCIATED:
223 dev_dbg(adapter->dev, "event: Disassociated\n");
224 if (priv->wps.session_enable) {
225 dev_dbg(adapter->dev,
226 "info: receive disassoc event in wps session\n");
227 break;
228 }
229 adapter->dbg.num_event_disassoc++;
230 if (priv->media_connected) {
231 reason_code =
232 le16_to_cpu(*(__le16 *)adapter->event_body);
233 mwifiex_reset_connect_state(priv, reason_code);
234 }
235 break;
236
237 case EVENT_LINK_LOST:
238 dev_dbg(adapter->dev, "event: Link lost\n");
239 adapter->dbg.num_event_link_lost++;
240 if (priv->media_connected) {
241 reason_code =
242 le16_to_cpu(*(__le16 *)adapter->event_body);
243 mwifiex_reset_connect_state(priv, reason_code);
244 }
245 break;
246
247 case EVENT_PS_SLEEP:
248 dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
249
250 adapter->ps_state = PS_STATE_PRE_SLEEP;
251
252 mwifiex_check_ps_cond(adapter);
253 break;
254
255 case EVENT_PS_AWAKE:
256 dev_dbg(adapter->dev, "info: EVENT: AWAKE\n");
257 if (!adapter->pps_uapsd_mode &&
258 priv->media_connected && adapter->sleep_period.period) {
259 adapter->pps_uapsd_mode = true;
260 dev_dbg(adapter->dev,
261 "event: PPS/UAPSD mode activated\n");
262 }
263 adapter->tx_lock_flag = false;
264 if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
265 if (mwifiex_check_last_packet_indication(priv)) {
266 if (adapter->data_sent) {
267 adapter->ps_state = PS_STATE_AWAKE;
268 adapter->pm_wakeup_card_req = false;
269 adapter->pm_wakeup_fw_try = false;
270 break;
271 }
272 if (!mwifiex_send_null_packet
273 (priv,
274 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
275 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
276 adapter->ps_state =
277 PS_STATE_SLEEP;
278 return 0;
279 }
280 }
281 adapter->ps_state = PS_STATE_AWAKE;
282 adapter->pm_wakeup_card_req = false;
283 adapter->pm_wakeup_fw_try = false;
284
285 break;
286
287 case EVENT_DEEP_SLEEP_AWAKE:
288 adapter->if_ops.wakeup_complete(adapter);
289 dev_dbg(adapter->dev, "event: DS_AWAKE\n");
290 if (adapter->is_deep_sleep)
291 adapter->is_deep_sleep = false;
292 break;
293
294 case EVENT_HS_ACT_REQ:
295 dev_dbg(adapter->dev, "event: HS_ACT_REQ\n");
296 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_HS_CFG_ENH,
297 0, 0, NULL, false);
298 break;
299
300 case EVENT_MIC_ERR_UNICAST:
301 dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n");
302 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
303 NL80211_KEYTYPE_PAIRWISE,
304 -1, NULL, GFP_KERNEL);
305 break;
306
307 case EVENT_MIC_ERR_MULTICAST:
308 dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n");
309 cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
310 NL80211_KEYTYPE_GROUP,
311 -1, NULL, GFP_KERNEL);
312 break;
313 case EVENT_MIB_CHANGED:
314 case EVENT_INIT_DONE:
315 break;
316
317 case EVENT_ADHOC_BCN_LOST:
318 dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n");
319 priv->adhoc_is_link_sensed = false;
320 mwifiex_clean_txrx(priv);
321 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
322 if (netif_carrier_ok(priv->netdev))
323 netif_carrier_off(priv->netdev);
324 break;
325
326 case EVENT_BG_SCAN_REPORT:
327 dev_dbg(adapter->dev, "event: BGS_REPORT\n");
328 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_QUERY,
329 HostCmd_ACT_GEN_GET, 0, NULL, false);
330 break;
331
332 case EVENT_PORT_RELEASE:
333 dev_dbg(adapter->dev, "event: PORT RELEASE\n");
334 break;
335
336 case EVENT_EXT_SCAN_REPORT:
337 dev_dbg(adapter->dev, "event: EXT_SCAN Report\n");
338 if (adapter->ext_scan)
339 ret = mwifiex_handle_event_ext_scan_report(priv,
340 adapter->event_skb->data);
341
342 break;
343
344 case EVENT_WMM_STATUS_CHANGE:
345 dev_dbg(adapter->dev, "event: WMM status changed\n");
346 ret = mwifiex_send_cmd(priv, HostCmd_CMD_WMM_GET_STATUS,
347 0, 0, NULL, false);
348 break;
349
350 case EVENT_RSSI_LOW:
351 cfg80211_cqm_rssi_notify(priv->netdev,
352 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
353 GFP_KERNEL);
354 mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
355 HostCmd_ACT_GEN_GET, 0, NULL, false);
356 priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
357 dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n");
358 break;
359 case EVENT_SNR_LOW:
360 dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
361 break;
362 case EVENT_MAX_FAIL:
363 dev_dbg(adapter->dev, "event: MAX_FAIL\n");
364 break;
365 case EVENT_RSSI_HIGH:
366 cfg80211_cqm_rssi_notify(priv->netdev,
367 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
368 GFP_KERNEL);
369 mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
370 HostCmd_ACT_GEN_GET, 0, NULL, false);
371 priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
372 dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n");
373 break;
374 case EVENT_SNR_HIGH:
375 dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
376 break;
377 case EVENT_DATA_RSSI_LOW:
378 dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
379 break;
380 case EVENT_DATA_SNR_LOW:
381 dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
382 break;
383 case EVENT_DATA_RSSI_HIGH:
384 dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
385 break;
386 case EVENT_DATA_SNR_HIGH:
387 dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
388 break;
389 case EVENT_LINK_QUALITY:
390 dev_dbg(adapter->dev, "event: Link Quality\n");
391 break;
392 case EVENT_PRE_BEACON_LOST:
393 dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
394 break;
395 case EVENT_IBSS_COALESCED:
396 dev_dbg(adapter->dev, "event: IBSS_COALESCED\n");
397 ret = mwifiex_send_cmd(priv,
398 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
399 HostCmd_ACT_GEN_GET, 0, NULL, false);
400 break;
401 case EVENT_ADDBA:
402 dev_dbg(adapter->dev, "event: ADDBA Request\n");
403 mwifiex_send_cmd(priv, HostCmd_CMD_11N_ADDBA_RSP,
404 HostCmd_ACT_GEN_SET, 0,
405 adapter->event_body, false);
406 break;
407 case EVENT_DELBA:
408 dev_dbg(adapter->dev, "event: DELBA Request\n");
409 mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
410 break;
411 case EVENT_BA_STREAM_TIEMOUT:
412 dev_dbg(adapter->dev, "event: BA Stream timeout\n");
413 mwifiex_11n_ba_stream_timeout(priv,
414 (struct host_cmd_ds_11n_batimeout
415 *)
416 adapter->event_body);
417 break;
418 case EVENT_AMSDU_AGGR_CTRL:
419 ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
420 dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
421
422 adapter->tx_buf_size =
423 min_t(u16, adapter->curr_tx_buf_size, ctrl);
424 dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
425 adapter->tx_buf_size);
426 break;
427
428 case EVENT_WEP_ICV_ERR:
429 dev_dbg(adapter->dev, "event: WEP ICV error\n");
430 break;
431
432 case EVENT_BW_CHANGE:
433 dev_dbg(adapter->dev, "event: BW Change\n");
434 break;
435
436 case EVENT_HOSTWAKE_STAIE:
437 dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
438 break;
439
440 case EVENT_REMAIN_ON_CHAN_EXPIRED:
441 dev_dbg(adapter->dev, "event: Remain on channel expired\n");
442 cfg80211_remain_on_channel_expired(priv->wdev,
443 priv->roc_cfg.cookie,
444 &priv->roc_cfg.chan,
445 GFP_ATOMIC);
446
447 memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
448
449 break;
450
451 case EVENT_CHANNEL_SWITCH_ANN:
452 dev_dbg(adapter->dev, "event: Channel Switch Announcement\n");
453 priv->csa_expire_time =
454 jiffies + msecs_to_jiffies(DFS_CHAN_MOVE_TIME);
455 priv->csa_chan = priv->curr_bss_params.bss_descriptor.channel;
456 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
457 HostCmd_ACT_GEN_SET, 0,
458 priv->curr_bss_params.bss_descriptor.mac_address,
459 false);
460 break;
461
462 default:
463 dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
464 eventcause);
465 break;
466 }
467
468 return ret;
469 }
This page took 0.039274 seconds and 4 git commands to generate.