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