Merge remote-tracking branches 'asoc/topic/intel', 'asoc/topic/kirkwood', 'asoc/topic...
[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->is_cmd_timedout && 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 static int mwifiex_parse_tdls_event(struct mwifiex_private *priv,
138 struct sk_buff *event_skb)
139 {
140 int ret = 0;
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);
145
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");
150 return -1;
151 }
152
153 sta_ptr = mwifiex_get_sta_entry(priv, tdls_evt->peer_mac);
154 if (!sta_ptr) {
155 dev_err(adapter->dev, "cannot get sta entry!\n");
156 return -1;
157 }
158
159 switch (le16_to_cpu(tdls_evt->type)) {
160 case TDLS_EVENT_LINK_TEAR_DOWN:
161 cfg80211_tdls_oper_request(priv->netdev,
162 tdls_evt->peer_mac,
163 NL80211_TDLS_TEARDOWN,
164 le16_to_cpu(tdls_evt->u.reason_code),
165 GFP_KERNEL);
166 ret = mwifiex_tdls_oper(priv, tdls_evt->peer_mac,
167 MWIFIEX_TDLS_DISABLE_LINK);
168 queue_work(adapter->workqueue, &adapter->main_work);
169 break;
170 default:
171 break;
172 }
173
174 return ret;
175 }
176
177 /*
178 * This function handles events generated by firmware.
179 *
180 * This is a generic function and handles all events.
181 *
182 * Event specific routines are called by this function based
183 * upon the generated event cause.
184 *
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
191 * - EVENT_RSSI_LOW
192 * - EVENT_SNR_LOW
193 * - EVENT_MAX_FAIL
194 * - EVENT_RSSI_HIGH
195 * - EVENT_SNR_HIGH
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
204 * - EVENT_BW_CHANGE
205 * - EVENT_HOSTWAKE_STAIE
206 *
207 * For the following events, no action is taken -
208 * - EVENT_MIB_CHANGED
209 * - EVENT_INIT_DONE
210 * - EVENT_DUMMY_HOST_WAKEUP_SIGNAL
211 *
212 * Rest of the supported events requires driver handling -
213 * - EVENT_DEAUTHENTICATED
214 * - EVENT_DISASSOCIATED
215 * - EVENT_LINK_LOST
216 * - EVENT_PS_SLEEP
217 * - EVENT_PS_AWAKE
218 * - EVENT_DEEP_SLEEP_AWAKE
219 * - EVENT_HS_ACT_REQ
220 * - EVENT_ADHOC_BCN_LOST
221 * - EVENT_BG_SCAN_REPORT
222 * - EVENT_WMM_STATUS_CHANGE
223 * - EVENT_ADDBA
224 * - EVENT_DELBA
225 * - EVENT_BA_STREAM_TIEMOUT
226 * - EVENT_AMSDU_AGGR_CTRL
227 */
228 int mwifiex_process_sta_event(struct mwifiex_private *priv)
229 {
230 struct mwifiex_adapter *adapter = priv->adapter;
231 int ret = 0;
232 u32 eventcause = adapter->event_cause;
233 u16 ctrl, reason_code;
234
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");
239 break;
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);
245 break;
246
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");
252 break;
253 }
254 adapter->dbg.num_event_deauth++;
255 if (priv->media_connected) {
256 reason_code =
257 le16_to_cpu(*(__le16 *)adapter->event_body);
258 mwifiex_reset_connect_state(priv, reason_code);
259 }
260 break;
261
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");
267 break;
268 }
269 adapter->dbg.num_event_disassoc++;
270 if (priv->media_connected) {
271 reason_code =
272 le16_to_cpu(*(__le16 *)adapter->event_body);
273 mwifiex_reset_connect_state(priv, reason_code);
274 }
275 break;
276
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) {
281 reason_code =
282 le16_to_cpu(*(__le16 *)adapter->event_body);
283 mwifiex_reset_connect_state(priv, reason_code);
284 }
285 break;
286
287 case EVENT_PS_SLEEP:
288 dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
289
290 adapter->ps_state = PS_STATE_PRE_SLEEP;
291
292 mwifiex_check_ps_cond(adapter);
293 break;
294
295 case EVENT_PS_AWAKE:
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");
302 }
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;
310 break;
311 }
312 if (!mwifiex_send_null_packet
313 (priv,
314 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
315 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
316 adapter->ps_state =
317 PS_STATE_SLEEP;
318 return 0;
319 }
320 }
321 adapter->ps_state = PS_STATE_AWAKE;
322 adapter->pm_wakeup_card_req = false;
323 adapter->pm_wakeup_fw_try = false;
324
325 break;
326
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;
332 break;
333
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,
337 0, 0, NULL, false);
338 break;
339
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);
345 break;
346
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);
352 break;
353 case EVENT_MIB_CHANGED:
354 case EVENT_INIT_DONE:
355 break;
356
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);
364 break;
365
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);
370 break;
371
372 case EVENT_PORT_RELEASE:
373 dev_dbg(adapter->dev, "event: PORT RELEASE\n");
374 break;
375
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);
381
382 break;
383
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,
387 0, 0, NULL, false);
388 break;
389
390 case EVENT_RSSI_LOW:
391 cfg80211_cqm_rssi_notify(priv->netdev,
392 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
393 GFP_KERNEL);
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");
398 break;
399 case EVENT_SNR_LOW:
400 dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
401 break;
402 case EVENT_MAX_FAIL:
403 dev_dbg(adapter->dev, "event: MAX_FAIL\n");
404 break;
405 case EVENT_RSSI_HIGH:
406 cfg80211_cqm_rssi_notify(priv->netdev,
407 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
408 GFP_KERNEL);
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");
413 break;
414 case EVENT_SNR_HIGH:
415 dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
416 break;
417 case EVENT_DATA_RSSI_LOW:
418 dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
419 break;
420 case EVENT_DATA_SNR_LOW:
421 dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
422 break;
423 case EVENT_DATA_RSSI_HIGH:
424 dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
425 break;
426 case EVENT_DATA_SNR_HIGH:
427 dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
428 break;
429 case EVENT_LINK_QUALITY:
430 dev_dbg(adapter->dev, "event: Link Quality\n");
431 break;
432 case EVENT_PRE_BEACON_LOST:
433 dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
434 break;
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);
440 break;
441 case EVENT_ADDBA:
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);
446 break;
447 case EVENT_DELBA:
448 dev_dbg(adapter->dev, "event: DELBA Request\n");
449 mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
450 break;
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
455 *)
456 adapter->event_body);
457 break;
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);
461
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);
466 break;
467
468 case EVENT_WEP_ICV_ERR:
469 dev_dbg(adapter->dev, "event: WEP ICV error\n");
470 break;
471
472 case EVENT_BW_CHANGE:
473 dev_dbg(adapter->dev, "event: BW Change\n");
474 break;
475
476 case EVENT_HOSTWAKE_STAIE:
477 dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
478 break;
479
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,
484 &priv->roc_cfg.chan,
485 GFP_ATOMIC);
486
487 memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
488
489 break;
490
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,
499 false);
500 break;
501
502 case EVENT_TDLS_GENERIC_EVENT:
503 ret = mwifiex_parse_tdls_event(priv, adapter->event_skb);
504 break;
505
506 default:
507 dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
508 eventcause);
509 break;
510 }
511
512 return ret;
513 }
This page took 0.042639 seconds and 5 git commands to generate.