Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 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 | |
Yogesh Ashok Powar | 2be50b8 | 2011-04-01 18:36:47 -0700 | [diff] [blame] | 79 | priv->sec_info.encryption_mode = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 80 | |
| 81 | /* Enable auto data rate */ |
| 82 | priv->is_data_rate_auto = true; |
| 83 | priv->data_rate = 0; |
| 84 | |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 85 | if (priv->bss_mode == NL80211_IFTYPE_ADHOC) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 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 mwifiex_802_11_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 | if (!priv->disconnect) { |
| 119 | priv->disconnect = 1; |
| 120 | dev_dbg(adapter->dev, "info: successfully disconnected from" |
| 121 | " %pM: reason code %d\n", priv->cfg_bssid, |
| 122 | WLAN_REASON_DEAUTH_LEAVING); |
| 123 | cfg80211_disconnected(priv->netdev, |
| 124 | WLAN_REASON_DEAUTH_LEAVING, NULL, 0, |
| 125 | GFP_KERNEL); |
| 126 | queue_work(priv->workqueue, &priv->cfg_workqueue); |
| 127 | } |
| 128 | if (!netif_queue_stopped(priv->netdev)) |
| 129 | netif_stop_queue(priv->netdev); |
| 130 | if (netif_carrier_ok(priv->netdev)) |
| 131 | netif_carrier_off(priv->netdev); |
| 132 | /* Reset wireless stats signal info */ |
Bing Zhao | 67a5003 | 2011-07-13 18:38:34 -0700 | [diff] [blame^] | 133 | priv->qual_level = 0; |
| 134 | priv->qual_noise = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 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 | |
| 194 | switch (eventcause) { |
| 195 | case EVENT_DUMMY_HOST_WAKEUP_SIGNAL: |
| 196 | dev_err(adapter->dev, "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL," |
| 197 | " ignoring it\n"); |
| 198 | break; |
| 199 | case EVENT_LINK_SENSED: |
| 200 | dev_dbg(adapter->dev, "event: LINK_SENSED\n"); |
| 201 | if (!netif_carrier_ok(priv->netdev)) |
| 202 | netif_carrier_on(priv->netdev); |
| 203 | if (netif_queue_stopped(priv->netdev)) |
| 204 | netif_wake_queue(priv->netdev); |
| 205 | break; |
| 206 | |
| 207 | case EVENT_DEAUTHENTICATED: |
| 208 | dev_dbg(adapter->dev, "event: Deauthenticated\n"); |
| 209 | adapter->dbg.num_event_deauth++; |
| 210 | if (priv->media_connected) |
| 211 | mwifiex_reset_connect_state(priv); |
| 212 | break; |
| 213 | |
| 214 | case EVENT_DISASSOCIATED: |
| 215 | dev_dbg(adapter->dev, "event: Disassociated\n"); |
| 216 | adapter->dbg.num_event_disassoc++; |
| 217 | if (priv->media_connected) |
| 218 | mwifiex_reset_connect_state(priv); |
| 219 | break; |
| 220 | |
| 221 | case EVENT_LINK_LOST: |
| 222 | dev_dbg(adapter->dev, "event: Link lost\n"); |
| 223 | adapter->dbg.num_event_link_lost++; |
| 224 | if (priv->media_connected) |
| 225 | mwifiex_reset_connect_state(priv); |
| 226 | break; |
| 227 | |
| 228 | case EVENT_PS_SLEEP: |
| 229 | dev_dbg(adapter->dev, "info: EVENT: SLEEP\n"); |
| 230 | |
| 231 | adapter->ps_state = PS_STATE_PRE_SLEEP; |
| 232 | |
| 233 | mwifiex_check_ps_cond(adapter); |
| 234 | break; |
| 235 | |
| 236 | case EVENT_PS_AWAKE: |
| 237 | dev_dbg(adapter->dev, "info: EVENT: AWAKE\n"); |
| 238 | if (!adapter->pps_uapsd_mode && |
| 239 | priv->media_connected && |
| 240 | adapter->sleep_period.period) { |
| 241 | adapter->pps_uapsd_mode = true; |
| 242 | dev_dbg(adapter->dev, |
| 243 | "event: PPS/UAPSD mode activated\n"); |
| 244 | } |
| 245 | adapter->tx_lock_flag = false; |
| 246 | if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) { |
| 247 | if (mwifiex_check_last_packet_indication(priv)) { |
| 248 | if (!adapter->data_sent) { |
| 249 | if (!mwifiex_send_null_packet(priv, |
| 250 | MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
| 251 | | |
| 252 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) |
| 253 | adapter->ps_state = |
| 254 | PS_STATE_SLEEP; |
| 255 | return 0; |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | adapter->ps_state = PS_STATE_AWAKE; |
| 260 | adapter->pm_wakeup_card_req = false; |
| 261 | adapter->pm_wakeup_fw_try = false; |
| 262 | |
| 263 | break; |
| 264 | |
| 265 | case EVENT_DEEP_SLEEP_AWAKE: |
| 266 | adapter->if_ops.wakeup_complete(adapter); |
| 267 | dev_dbg(adapter->dev, "event: DS_AWAKE\n"); |
| 268 | if (adapter->is_deep_sleep) |
| 269 | adapter->is_deep_sleep = false; |
| 270 | break; |
| 271 | |
| 272 | case EVENT_HS_ACT_REQ: |
| 273 | dev_dbg(adapter->dev, "event: HS_ACT_REQ\n"); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 274 | ret = mwifiex_send_cmd_async(priv, |
| 275 | HostCmd_CMD_802_11_HS_CFG_ENH, |
| 276 | 0, 0, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 277 | break; |
| 278 | |
| 279 | case EVENT_MIC_ERR_UNICAST: |
| 280 | dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n"); |
| 281 | break; |
| 282 | |
| 283 | case EVENT_MIC_ERR_MULTICAST: |
| 284 | dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n"); |
| 285 | break; |
| 286 | case EVENT_MIB_CHANGED: |
| 287 | case EVENT_INIT_DONE: |
| 288 | break; |
| 289 | |
| 290 | case EVENT_ADHOC_BCN_LOST: |
| 291 | dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n"); |
| 292 | priv->adhoc_is_link_sensed = false; |
| 293 | mwifiex_clean_txrx(priv); |
| 294 | if (!netif_queue_stopped(priv->netdev)) |
| 295 | netif_stop_queue(priv->netdev); |
| 296 | if (netif_carrier_ok(priv->netdev)) |
| 297 | netif_carrier_off(priv->netdev); |
| 298 | break; |
| 299 | |
| 300 | case EVENT_BG_SCAN_REPORT: |
| 301 | dev_dbg(adapter->dev, "event: BGS_REPORT\n"); |
| 302 | /* Clear the previous scan result */ |
| 303 | memset(adapter->scan_table, 0x00, |
Bing Zhao | 67a5003 | 2011-07-13 18:38:34 -0700 | [diff] [blame^] | 304 | sizeof(struct mwifiex_bssdescriptor) * MWIFIEX_MAX_AP); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 305 | adapter->num_in_scan_table = 0; |
| 306 | adapter->bcn_buf_end = adapter->bcn_buf; |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 307 | ret = mwifiex_send_cmd_async(priv, |
| 308 | HostCmd_CMD_802_11_BG_SCAN_QUERY, |
| 309 | HostCmd_ACT_GEN_GET, 0, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 310 | break; |
| 311 | |
| 312 | case EVENT_PORT_RELEASE: |
| 313 | dev_dbg(adapter->dev, "event: PORT RELEASE\n"); |
| 314 | break; |
| 315 | |
| 316 | case EVENT_WMM_STATUS_CHANGE: |
| 317 | dev_dbg(adapter->dev, "event: WMM status changed\n"); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 318 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_WMM_GET_STATUS, |
| 319 | 0, 0, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 320 | break; |
| 321 | |
| 322 | case EVENT_RSSI_LOW: |
| 323 | dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n"); |
| 324 | break; |
| 325 | case EVENT_SNR_LOW: |
| 326 | dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n"); |
| 327 | break; |
| 328 | case EVENT_MAX_FAIL: |
| 329 | dev_dbg(adapter->dev, "event: MAX_FAIL\n"); |
| 330 | break; |
| 331 | case EVENT_RSSI_HIGH: |
| 332 | dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n"); |
| 333 | break; |
| 334 | case EVENT_SNR_HIGH: |
| 335 | dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n"); |
| 336 | break; |
| 337 | case EVENT_DATA_RSSI_LOW: |
| 338 | dev_dbg(adapter->dev, "event: Data RSSI_LOW\n"); |
| 339 | break; |
| 340 | case EVENT_DATA_SNR_LOW: |
| 341 | dev_dbg(adapter->dev, "event: Data SNR_LOW\n"); |
| 342 | break; |
| 343 | case EVENT_DATA_RSSI_HIGH: |
| 344 | dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n"); |
| 345 | break; |
| 346 | case EVENT_DATA_SNR_HIGH: |
| 347 | dev_dbg(adapter->dev, "event: Data SNR_HIGH\n"); |
| 348 | break; |
| 349 | case EVENT_LINK_QUALITY: |
| 350 | dev_dbg(adapter->dev, "event: Link Quality\n"); |
| 351 | break; |
| 352 | case EVENT_PRE_BEACON_LOST: |
| 353 | dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n"); |
| 354 | break; |
| 355 | case EVENT_IBSS_COALESCED: |
| 356 | dev_dbg(adapter->dev, "event: IBSS_COALESCED\n"); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 357 | ret = mwifiex_send_cmd_async(priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 358 | HostCmd_CMD_802_11_IBSS_COALESCING_STATUS, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 359 | HostCmd_ACT_GEN_GET, 0, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 360 | break; |
| 361 | case EVENT_ADDBA: |
| 362 | dev_dbg(adapter->dev, "event: ADDBA Request\n"); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 363 | mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP, |
| 364 | HostCmd_ACT_GEN_SET, 0, |
| 365 | adapter->event_body); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 366 | break; |
| 367 | case EVENT_DELBA: |
| 368 | dev_dbg(adapter->dev, "event: DELBA Request\n"); |
| 369 | mwifiex_11n_delete_ba_stream(priv, adapter->event_body); |
| 370 | break; |
| 371 | case EVENT_BA_STREAM_TIEMOUT: |
| 372 | dev_dbg(adapter->dev, "event: BA Stream timeout\n"); |
| 373 | mwifiex_11n_ba_stream_timeout(priv, |
| 374 | (struct host_cmd_ds_11n_batimeout |
| 375 | *) |
| 376 | adapter->event_body); |
| 377 | break; |
| 378 | case EVENT_AMSDU_AGGR_CTRL: |
| 379 | dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", |
| 380 | *(u16 *) adapter->event_body); |
| 381 | adapter->tx_buf_size = |
| 382 | min(adapter->curr_tx_buf_size, |
| 383 | le16_to_cpu(*(__le16 *) adapter->event_body)); |
| 384 | dev_dbg(adapter->dev, "event: tx_buf_size %d\n", |
| 385 | adapter->tx_buf_size); |
| 386 | break; |
| 387 | |
| 388 | case EVENT_WEP_ICV_ERR: |
| 389 | dev_dbg(adapter->dev, "event: WEP ICV error\n"); |
| 390 | break; |
| 391 | |
| 392 | case EVENT_BW_CHANGE: |
| 393 | dev_dbg(adapter->dev, "event: BW Change\n"); |
| 394 | break; |
| 395 | |
| 396 | case EVENT_HOSTWAKE_STAIE: |
| 397 | dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause); |
| 398 | break; |
| 399 | default: |
| 400 | dev_dbg(adapter->dev, "event: unknown event id: %#x\n", |
| 401 | eventcause); |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | return ret; |
| 406 | } |