]>
Commit | Line | Data |
---|---|---|
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_async(priv, | |
297 | HostCmd_CMD_802_11_HS_CFG_ENH, | |
298 | 0, 0, NULL); | |
299 | break; | |
300 | ||
301 | case EVENT_MIC_ERR_UNICAST: | |
302 | dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n"); | |
303 | cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid, | |
304 | NL80211_KEYTYPE_PAIRWISE, | |
305 | -1, NULL, GFP_KERNEL); | |
306 | break; | |
307 | ||
308 | case EVENT_MIC_ERR_MULTICAST: | |
309 | dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n"); | |
310 | cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid, | |
311 | NL80211_KEYTYPE_GROUP, | |
312 | -1, NULL, GFP_KERNEL); | |
313 | break; | |
314 | case EVENT_MIB_CHANGED: | |
315 | case EVENT_INIT_DONE: | |
316 | break; | |
317 | ||
318 | case EVENT_ADHOC_BCN_LOST: | |
319 | dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n"); | |
320 | priv->adhoc_is_link_sensed = false; | |
321 | mwifiex_clean_txrx(priv); | |
322 | mwifiex_stop_net_dev_queue(priv->netdev, adapter); | |
323 | if (netif_carrier_ok(priv->netdev)) | |
324 | netif_carrier_off(priv->netdev); | |
325 | break; | |
326 | ||
327 | case EVENT_BG_SCAN_REPORT: | |
328 | dev_dbg(adapter->dev, "event: BGS_REPORT\n"); | |
329 | ret = mwifiex_send_cmd_async(priv, | |
330 | HostCmd_CMD_802_11_BG_SCAN_QUERY, | |
331 | HostCmd_ACT_GEN_GET, 0, NULL); | |
332 | break; | |
333 | ||
334 | case EVENT_PORT_RELEASE: | |
335 | dev_dbg(adapter->dev, "event: PORT RELEASE\n"); | |
336 | break; | |
337 | ||
338 | case EVENT_EXT_SCAN_REPORT: | |
339 | dev_dbg(adapter->dev, "event: EXT_SCAN Report\n"); | |
340 | if (adapter->ext_scan) | |
341 | ret = mwifiex_handle_event_ext_scan_report(priv, | |
342 | adapter->event_skb->data); | |
343 | ||
344 | break; | |
345 | ||
346 | case EVENT_WMM_STATUS_CHANGE: | |
347 | dev_dbg(adapter->dev, "event: WMM status changed\n"); | |
348 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_WMM_GET_STATUS, | |
349 | 0, 0, NULL); | |
350 | break; | |
351 | ||
352 | case EVENT_RSSI_LOW: | |
353 | cfg80211_cqm_rssi_notify(priv->netdev, | |
354 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, | |
355 | GFP_KERNEL); | |
356 | mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO, | |
357 | HostCmd_ACT_GEN_GET, 0, NULL); | |
358 | priv->subsc_evt_rssi_state = RSSI_LOW_RECVD; | |
359 | dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n"); | |
360 | break; | |
361 | case EVENT_SNR_LOW: | |
362 | dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n"); | |
363 | break; | |
364 | case EVENT_MAX_FAIL: | |
365 | dev_dbg(adapter->dev, "event: MAX_FAIL\n"); | |
366 | break; | |
367 | case EVENT_RSSI_HIGH: | |
368 | cfg80211_cqm_rssi_notify(priv->netdev, | |
369 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, | |
370 | GFP_KERNEL); | |
371 | mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO, | |
372 | HostCmd_ACT_GEN_GET, 0, NULL); | |
373 | priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD; | |
374 | dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n"); | |
375 | break; | |
376 | case EVENT_SNR_HIGH: | |
377 | dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n"); | |
378 | break; | |
379 | case EVENT_DATA_RSSI_LOW: | |
380 | dev_dbg(adapter->dev, "event: Data RSSI_LOW\n"); | |
381 | break; | |
382 | case EVENT_DATA_SNR_LOW: | |
383 | dev_dbg(adapter->dev, "event: Data SNR_LOW\n"); | |
384 | break; | |
385 | case EVENT_DATA_RSSI_HIGH: | |
386 | dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n"); | |
387 | break; | |
388 | case EVENT_DATA_SNR_HIGH: | |
389 | dev_dbg(adapter->dev, "event: Data SNR_HIGH\n"); | |
390 | break; | |
391 | case EVENT_LINK_QUALITY: | |
392 | dev_dbg(adapter->dev, "event: Link Quality\n"); | |
393 | break; | |
394 | case EVENT_PRE_BEACON_LOST: | |
395 | dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n"); | |
396 | break; | |
397 | case EVENT_IBSS_COALESCED: | |
398 | dev_dbg(adapter->dev, "event: IBSS_COALESCED\n"); | |
399 | ret = mwifiex_send_cmd_async(priv, | |
400 | HostCmd_CMD_802_11_IBSS_COALESCING_STATUS, | |
401 | HostCmd_ACT_GEN_GET, 0, NULL); | |
402 | break; | |
403 | case EVENT_ADDBA: | |
404 | dev_dbg(adapter->dev, "event: ADDBA Request\n"); | |
405 | mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP, | |
406 | HostCmd_ACT_GEN_SET, 0, | |
407 | adapter->event_body); | |
408 | break; | |
409 | case EVENT_DELBA: | |
410 | dev_dbg(adapter->dev, "event: DELBA Request\n"); | |
411 | mwifiex_11n_delete_ba_stream(priv, adapter->event_body); | |
412 | break; | |
413 | case EVENT_BA_STREAM_TIEMOUT: | |
414 | dev_dbg(adapter->dev, "event: BA Stream timeout\n"); | |
415 | mwifiex_11n_ba_stream_timeout(priv, | |
416 | (struct host_cmd_ds_11n_batimeout | |
417 | *) | |
418 | adapter->event_body); | |
419 | break; | |
420 | case EVENT_AMSDU_AGGR_CTRL: | |
421 | ctrl = le16_to_cpu(*(__le16 *)adapter->event_body); | |
422 | dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl); | |
423 | ||
424 | adapter->tx_buf_size = | |
425 | min_t(u16, adapter->curr_tx_buf_size, ctrl); | |
426 | dev_dbg(adapter->dev, "event: tx_buf_size %d\n", | |
427 | adapter->tx_buf_size); | |
428 | break; | |
429 | ||
430 | case EVENT_WEP_ICV_ERR: | |
431 | dev_dbg(adapter->dev, "event: WEP ICV error\n"); | |
432 | break; | |
433 | ||
434 | case EVENT_BW_CHANGE: | |
435 | dev_dbg(adapter->dev, "event: BW Change\n"); | |
436 | break; | |
437 | ||
438 | case EVENT_HOSTWAKE_STAIE: | |
439 | dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause); | |
440 | break; | |
441 | ||
442 | case EVENT_REMAIN_ON_CHAN_EXPIRED: | |
443 | dev_dbg(adapter->dev, "event: Remain on channel expired\n"); | |
444 | cfg80211_remain_on_channel_expired(priv->wdev, | |
445 | priv->roc_cfg.cookie, | |
446 | &priv->roc_cfg.chan, | |
447 | GFP_ATOMIC); | |
448 | ||
449 | memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg)); | |
450 | ||
451 | break; | |
452 | ||
453 | case EVENT_CHANNEL_SWITCH_ANN: | |
454 | dev_dbg(adapter->dev, "event: Channel Switch Announcement\n"); | |
455 | priv->csa_expire_time = | |
456 | jiffies + msecs_to_jiffies(DFS_CHAN_MOVE_TIME); | |
457 | priv->csa_chan = priv->curr_bss_params.bss_descriptor.channel; | |
458 | ret = mwifiex_send_cmd_async(priv, | |
459 | HostCmd_CMD_802_11_DEAUTHENTICATE, | |
460 | HostCmd_ACT_GEN_SET, 0, | |
461 | priv->curr_bss_params.bss_descriptor.mac_address); | |
462 | break; | |
463 | ||
464 | default: | |
465 | dev_dbg(adapter->dev, "event: unknown event id: %#x\n", | |
466 | eventcause); | |
467 | break; | |
468 | } | |
469 | ||
470 | return ret; | |
471 | } |