]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/net/wireless/mwifiex/sta_event.c
wireless: Remove casts to same type
[mirror_ubuntu-artful-kernel.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)
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, WLAN_REASON_DEAUTH_LEAVING);
121 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
122 cfg80211_disconnected(priv->netdev, WLAN_REASON_DEAUTH_LEAVING,
123 NULL, 0, GFP_KERNEL);
124 }
125 memset(priv->cfg_bssid, 0, ETH_ALEN);
126
127 if (!netif_queue_stopped(priv->netdev))
128 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
129 if (netif_carrier_ok(priv->netdev))
130 netif_carrier_off(priv->netdev);
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 */
184 int mwifiex_process_sta_event(struct mwifiex_private *priv)
185 {
186 struct mwifiex_adapter *adapter = priv->adapter;
187 int len, ret = 0;
188 u32 eventcause = adapter->event_cause;
189 struct station_info sinfo;
190 struct mwifiex_assoc_event *event;
191
192 switch (eventcause) {
193 case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
194 dev_err(adapter->dev,
195 "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
196 break;
197 case EVENT_LINK_SENSED:
198 dev_dbg(adapter->dev, "event: LINK_SENSED\n");
199 if (!netif_carrier_ok(priv->netdev))
200 netif_carrier_on(priv->netdev);
201 if (netif_queue_stopped(priv->netdev))
202 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
203 break;
204
205 case EVENT_DEAUTHENTICATED:
206 dev_dbg(adapter->dev, "event: Deauthenticated\n");
207 adapter->dbg.num_event_deauth++;
208 if (priv->media_connected)
209 mwifiex_reset_connect_state(priv);
210 break;
211
212 case EVENT_DISASSOCIATED:
213 dev_dbg(adapter->dev, "event: Disassociated\n");
214 adapter->dbg.num_event_disassoc++;
215 if (priv->media_connected)
216 mwifiex_reset_connect_state(priv);
217 break;
218
219 case EVENT_LINK_LOST:
220 dev_dbg(adapter->dev, "event: Link lost\n");
221 adapter->dbg.num_event_link_lost++;
222 if (priv->media_connected)
223 mwifiex_reset_connect_state(priv);
224 break;
225
226 case EVENT_PS_SLEEP:
227 dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
228
229 adapter->ps_state = PS_STATE_PRE_SLEEP;
230
231 mwifiex_check_ps_cond(adapter);
232 break;
233
234 case EVENT_PS_AWAKE:
235 dev_dbg(adapter->dev, "info: EVENT: AWAKE\n");
236 if (!adapter->pps_uapsd_mode &&
237 priv->media_connected && adapter->sleep_period.period) {
238 adapter->pps_uapsd_mode = true;
239 dev_dbg(adapter->dev,
240 "event: PPS/UAPSD mode activated\n");
241 }
242 adapter->tx_lock_flag = false;
243 if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
244 if (mwifiex_check_last_packet_indication(priv)) {
245 if (adapter->data_sent) {
246 adapter->ps_state = PS_STATE_AWAKE;
247 adapter->pm_wakeup_card_req = false;
248 adapter->pm_wakeup_fw_try = false;
249 break;
250 }
251 if (!mwifiex_send_null_packet
252 (priv,
253 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
254 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
255 adapter->ps_state =
256 PS_STATE_SLEEP;
257 return 0;
258 }
259 }
260 adapter->ps_state = PS_STATE_AWAKE;
261 adapter->pm_wakeup_card_req = false;
262 adapter->pm_wakeup_fw_try = false;
263
264 break;
265
266 case EVENT_DEEP_SLEEP_AWAKE:
267 adapter->if_ops.wakeup_complete(adapter);
268 dev_dbg(adapter->dev, "event: DS_AWAKE\n");
269 if (adapter->is_deep_sleep)
270 adapter->is_deep_sleep = false;
271 break;
272
273 case EVENT_HS_ACT_REQ:
274 dev_dbg(adapter->dev, "event: HS_ACT_REQ\n");
275 ret = mwifiex_send_cmd_async(priv,
276 HostCmd_CMD_802_11_HS_CFG_ENH,
277 0, 0, NULL);
278 break;
279
280 case EVENT_MIC_ERR_UNICAST:
281 dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n");
282 break;
283
284 case EVENT_MIC_ERR_MULTICAST:
285 dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n");
286 break;
287 case EVENT_MIB_CHANGED:
288 case EVENT_INIT_DONE:
289 break;
290
291 case EVENT_ADHOC_BCN_LOST:
292 dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n");
293 priv->adhoc_is_link_sensed = false;
294 mwifiex_clean_txrx(priv);
295 if (!netif_queue_stopped(priv->netdev))
296 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
297 if (netif_carrier_ok(priv->netdev))
298 netif_carrier_off(priv->netdev);
299 break;
300
301 case EVENT_BG_SCAN_REPORT:
302 dev_dbg(adapter->dev, "event: BGS_REPORT\n");
303 ret = mwifiex_send_cmd_async(priv,
304 HostCmd_CMD_802_11_BG_SCAN_QUERY,
305 HostCmd_ACT_GEN_GET, 0, NULL);
306 break;
307
308 case EVENT_PORT_RELEASE:
309 dev_dbg(adapter->dev, "event: PORT RELEASE\n");
310 break;
311
312 case EVENT_WMM_STATUS_CHANGE:
313 dev_dbg(adapter->dev, "event: WMM status changed\n");
314 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_WMM_GET_STATUS,
315 0, 0, NULL);
316 break;
317
318 case EVENT_RSSI_LOW:
319 cfg80211_cqm_rssi_notify(priv->netdev,
320 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
321 GFP_KERNEL);
322 mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
323 HostCmd_ACT_GEN_GET, 0, NULL);
324 priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
325 dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n");
326 break;
327 case EVENT_SNR_LOW:
328 dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
329 break;
330 case EVENT_MAX_FAIL:
331 dev_dbg(adapter->dev, "event: MAX_FAIL\n");
332 break;
333 case EVENT_RSSI_HIGH:
334 cfg80211_cqm_rssi_notify(priv->netdev,
335 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
336 GFP_KERNEL);
337 mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
338 HostCmd_ACT_GEN_GET, 0, NULL);
339 priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
340 dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n");
341 break;
342 case EVENT_SNR_HIGH:
343 dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
344 break;
345 case EVENT_DATA_RSSI_LOW:
346 dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
347 break;
348 case EVENT_DATA_SNR_LOW:
349 dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
350 break;
351 case EVENT_DATA_RSSI_HIGH:
352 dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
353 break;
354 case EVENT_DATA_SNR_HIGH:
355 dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
356 break;
357 case EVENT_LINK_QUALITY:
358 dev_dbg(adapter->dev, "event: Link Quality\n");
359 break;
360 case EVENT_PRE_BEACON_LOST:
361 dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
362 break;
363 case EVENT_IBSS_COALESCED:
364 dev_dbg(adapter->dev, "event: IBSS_COALESCED\n");
365 ret = mwifiex_send_cmd_async(priv,
366 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
367 HostCmd_ACT_GEN_GET, 0, NULL);
368 break;
369 case EVENT_ADDBA:
370 dev_dbg(adapter->dev, "event: ADDBA Request\n");
371 mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP,
372 HostCmd_ACT_GEN_SET, 0,
373 adapter->event_body);
374 break;
375 case EVENT_DELBA:
376 dev_dbg(adapter->dev, "event: DELBA Request\n");
377 mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
378 break;
379 case EVENT_BA_STREAM_TIEMOUT:
380 dev_dbg(adapter->dev, "event: BA Stream timeout\n");
381 mwifiex_11n_ba_stream_timeout(priv,
382 (struct host_cmd_ds_11n_batimeout
383 *)
384 adapter->event_body);
385 break;
386 case EVENT_AMSDU_AGGR_CTRL:
387 dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n",
388 *(u16 *) adapter->event_body);
389 adapter->tx_buf_size =
390 min(adapter->curr_tx_buf_size,
391 le16_to_cpu(*(__le16 *) adapter->event_body));
392 dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
393 adapter->tx_buf_size);
394 break;
395
396 case EVENT_WEP_ICV_ERR:
397 dev_dbg(adapter->dev, "event: WEP ICV error\n");
398 break;
399
400 case EVENT_BW_CHANGE:
401 dev_dbg(adapter->dev, "event: BW Change\n");
402 break;
403
404 case EVENT_HOSTWAKE_STAIE:
405 dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
406 break;
407
408 case EVENT_UAP_STA_ASSOC:
409 skb_pull(adapter->event_skb, MWIFIEX_UAP_EVENT_EXTRA_HEADER);
410 memset(&sinfo, 0, sizeof(sinfo));
411 event = (struct mwifiex_assoc_event *)adapter->event_skb->data;
412 if (le16_to_cpu(event->type) == TLV_TYPE_UAP_MGMT_FRAME) {
413 len = -1;
414
415 if (ieee80211_is_assoc_req(event->frame_control))
416 len = 0;
417 else if (ieee80211_is_reassoc_req(event->frame_control))
418 /* There will be ETH_ALEN bytes of
419 * current_ap_addr before the re-assoc ies.
420 */
421 len = ETH_ALEN;
422
423 if (len != -1) {
424 sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
425 sinfo.assoc_req_ies = &event->data[len];
426 len = (u8 *)sinfo.assoc_req_ies -
427 (u8 *)&event->frame_control;
428 sinfo.assoc_req_ies_len =
429 le16_to_cpu(event->len) - (u16)len;
430 }
431 }
432 cfg80211_new_sta(priv->netdev, event->sta_addr, &sinfo,
433 GFP_KERNEL);
434 break;
435 case EVENT_UAP_STA_DEAUTH:
436 skb_pull(adapter->event_skb, MWIFIEX_UAP_EVENT_EXTRA_HEADER);
437 cfg80211_del_sta(priv->netdev, adapter->event_skb->data,
438 GFP_KERNEL);
439 break;
440 case EVENT_UAP_BSS_IDLE:
441 priv->media_connected = false;
442 break;
443 case EVENT_UAP_BSS_ACTIVE:
444 priv->media_connected = true;
445 break;
446 case EVENT_UAP_BSS_START:
447 dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
448 memcpy(priv->netdev->dev_addr, adapter->event_body+2, ETH_ALEN);
449 break;
450 case EVENT_UAP_MIC_COUNTERMEASURES:
451 /* For future development */
452 dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
453 break;
454 default:
455 dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
456 eventcause);
457 break;
458 }
459
460 return ret;
461 }