sta_event.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. #include "11n.h"
  26. /*
  27. * This function resets the connection state.
  28. *
  29. * The function is invoked after receiving a disconnect event from firmware,
  30. * and performs the following actions -
  31. * - Set media status to disconnected
  32. * - Clean up Tx and Rx packets
  33. * - Resets SNR/NF/RSSI value in driver
  34. * - Resets security configurations in driver
  35. * - Enables auto data rate
  36. * - Saves the previous SSID and BSSID so that they can
  37. * be used for re-association, if required
  38. * - Erases current SSID and BSSID information
  39. * - Sends a disconnect event to upper layers/applications.
  40. */
  41. void
  42. mwifiex_reset_connect_state(struct mwifiex_private *priv)
  43. {
  44. struct mwifiex_adapter *adapter = priv->adapter;
  45. if (!priv->media_connected)
  46. return;
  47. dev_dbg(adapter->dev, "info: handles disconnect event\n");
  48. priv->media_connected = false;
  49. priv->scan_block = false;
  50. /* Free Tx and Rx packets, report disconnect to upper layer */
  51. mwifiex_clean_txrx(priv);
  52. /* Reset SNR/NF/RSSI values */
  53. priv->data_rssi_last = 0;
  54. priv->data_nf_last = 0;
  55. priv->data_rssi_avg = 0;
  56. priv->data_nf_avg = 0;
  57. priv->bcn_rssi_last = 0;
  58. priv->bcn_nf_last = 0;
  59. priv->bcn_rssi_avg = 0;
  60. priv->bcn_nf_avg = 0;
  61. priv->rxpd_rate = 0;
  62. priv->rxpd_htinfo = 0;
  63. priv->sec_info.wpa_enabled = false;
  64. priv->sec_info.wpa2_enabled = false;
  65. priv->wpa_ie_len = 0;
  66. priv->sec_info.wapi_enabled = false;
  67. priv->wapi_ie_len = 0;
  68. priv->sec_info.wapi_key_on = false;
  69. priv->sec_info.encryption_mode = 0;
  70. /* Enable auto data rate */
  71. priv->is_data_rate_auto = true;
  72. priv->data_rate = 0;
  73. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  74. priv->adhoc_state = ADHOC_IDLE;
  75. priv->adhoc_is_link_sensed = false;
  76. }
  77. /*
  78. * Memorize the previous SSID and BSSID so
  79. * it could be used for re-assoc
  80. */
  81. dev_dbg(adapter->dev, "info: previous SSID=%s, SSID len=%u\n",
  82. priv->prev_ssid.ssid, priv->prev_ssid.ssid_len);
  83. dev_dbg(adapter->dev, "info: current SSID=%s, SSID len=%u\n",
  84. priv->curr_bss_params.bss_descriptor.ssid.ssid,
  85. priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
  86. memcpy(&priv->prev_ssid,
  87. &priv->curr_bss_params.bss_descriptor.ssid,
  88. sizeof(struct cfg80211_ssid));
  89. memcpy(priv->prev_bssid,
  90. priv->curr_bss_params.bss_descriptor.mac_address, ETH_ALEN);
  91. /* Need to erase the current SSID and BSSID info */
  92. memset(&priv->curr_bss_params, 0x00, sizeof(priv->curr_bss_params));
  93. adapter->tx_lock_flag = false;
  94. adapter->pps_uapsd_mode = false;
  95. if (adapter->num_cmd_timeout && adapter->curr_cmd)
  96. return;
  97. priv->media_connected = false;
  98. dev_dbg(adapter->dev,
  99. "info: successfully disconnected from %pM: reason code %d\n",
  100. priv->cfg_bssid, WLAN_REASON_DEAUTH_LEAVING);
  101. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  102. cfg80211_disconnected(priv->netdev, WLAN_REASON_DEAUTH_LEAVING,
  103. NULL, 0, GFP_KERNEL);
  104. }
  105. memset(priv->cfg_bssid, 0, ETH_ALEN);
  106. if (!netif_queue_stopped(priv->netdev))
  107. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  108. if (netif_carrier_ok(priv->netdev))
  109. netif_carrier_off(priv->netdev);
  110. /* Reset wireless stats signal info */
  111. priv->qual_level = 0;
  112. priv->qual_noise = 0;
  113. }
  114. /*
  115. * This function handles events generated by firmware.
  116. *
  117. * This is a generic function and handles all events.
  118. *
  119. * Event specific routines are called by this function based
  120. * upon the generated event cause.
  121. *
  122. * For the following events, the function just forwards them to upper
  123. * layers, optionally recording the change -
  124. * - EVENT_LINK_SENSED
  125. * - EVENT_MIC_ERR_UNICAST
  126. * - EVENT_MIC_ERR_MULTICAST
  127. * - EVENT_PORT_RELEASE
  128. * - EVENT_RSSI_LOW
  129. * - EVENT_SNR_LOW
  130. * - EVENT_MAX_FAIL
  131. * - EVENT_RSSI_HIGH
  132. * - EVENT_SNR_HIGH
  133. * - EVENT_DATA_RSSI_LOW
  134. * - EVENT_DATA_SNR_LOW
  135. * - EVENT_DATA_RSSI_HIGH
  136. * - EVENT_DATA_SNR_HIGH
  137. * - EVENT_LINK_QUALITY
  138. * - EVENT_PRE_BEACON_LOST
  139. * - EVENT_IBSS_COALESCED
  140. * - EVENT_WEP_ICV_ERR
  141. * - EVENT_BW_CHANGE
  142. * - EVENT_HOSTWAKE_STAIE
  143. *
  144. * For the following events, no action is taken -
  145. * - EVENT_MIB_CHANGED
  146. * - EVENT_INIT_DONE
  147. * - EVENT_DUMMY_HOST_WAKEUP_SIGNAL
  148. *
  149. * Rest of the supported events requires driver handling -
  150. * - EVENT_DEAUTHENTICATED
  151. * - EVENT_DISASSOCIATED
  152. * - EVENT_LINK_LOST
  153. * - EVENT_PS_SLEEP
  154. * - EVENT_PS_AWAKE
  155. * - EVENT_DEEP_SLEEP_AWAKE
  156. * - EVENT_HS_ACT_REQ
  157. * - EVENT_ADHOC_BCN_LOST
  158. * - EVENT_BG_SCAN_REPORT
  159. * - EVENT_WMM_STATUS_CHANGE
  160. * - EVENT_ADDBA
  161. * - EVENT_DELBA
  162. * - EVENT_BA_STREAM_TIEMOUT
  163. * - EVENT_AMSDU_AGGR_CTRL
  164. */
  165. int mwifiex_process_sta_event(struct mwifiex_private *priv)
  166. {
  167. struct mwifiex_adapter *adapter = priv->adapter;
  168. int ret = 0;
  169. u32 eventcause = adapter->event_cause;
  170. switch (eventcause) {
  171. case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
  172. dev_err(adapter->dev,
  173. "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
  174. break;
  175. case EVENT_LINK_SENSED:
  176. dev_dbg(adapter->dev, "event: LINK_SENSED\n");
  177. if (!netif_carrier_ok(priv->netdev))
  178. netif_carrier_on(priv->netdev);
  179. if (netif_queue_stopped(priv->netdev))
  180. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  181. break;
  182. case EVENT_DEAUTHENTICATED:
  183. dev_dbg(adapter->dev, "event: Deauthenticated\n");
  184. adapter->dbg.num_event_deauth++;
  185. if (priv->media_connected)
  186. mwifiex_reset_connect_state(priv);
  187. break;
  188. case EVENT_DISASSOCIATED:
  189. dev_dbg(adapter->dev, "event: Disassociated\n");
  190. adapter->dbg.num_event_disassoc++;
  191. if (priv->media_connected)
  192. mwifiex_reset_connect_state(priv);
  193. break;
  194. case EVENT_LINK_LOST:
  195. dev_dbg(adapter->dev, "event: Link lost\n");
  196. adapter->dbg.num_event_link_lost++;
  197. if (priv->media_connected)
  198. mwifiex_reset_connect_state(priv);
  199. break;
  200. case EVENT_PS_SLEEP:
  201. dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
  202. adapter->ps_state = PS_STATE_PRE_SLEEP;
  203. mwifiex_check_ps_cond(adapter);
  204. break;
  205. case EVENT_PS_AWAKE:
  206. dev_dbg(adapter->dev, "info: EVENT: AWAKE\n");
  207. if (!adapter->pps_uapsd_mode &&
  208. priv->media_connected && adapter->sleep_period.period) {
  209. adapter->pps_uapsd_mode = true;
  210. dev_dbg(adapter->dev,
  211. "event: PPS/UAPSD mode activated\n");
  212. }
  213. adapter->tx_lock_flag = false;
  214. if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
  215. if (mwifiex_check_last_packet_indication(priv)) {
  216. if (adapter->data_sent) {
  217. adapter->ps_state = PS_STATE_AWAKE;
  218. adapter->pm_wakeup_card_req = false;
  219. adapter->pm_wakeup_fw_try = false;
  220. break;
  221. }
  222. if (!mwifiex_send_null_packet
  223. (priv,
  224. MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
  225. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
  226. adapter->ps_state =
  227. PS_STATE_SLEEP;
  228. return 0;
  229. }
  230. }
  231. adapter->ps_state = PS_STATE_AWAKE;
  232. adapter->pm_wakeup_card_req = false;
  233. adapter->pm_wakeup_fw_try = false;
  234. break;
  235. case EVENT_DEEP_SLEEP_AWAKE:
  236. adapter->if_ops.wakeup_complete(adapter);
  237. dev_dbg(adapter->dev, "event: DS_AWAKE\n");
  238. if (adapter->is_deep_sleep)
  239. adapter->is_deep_sleep = false;
  240. break;
  241. case EVENT_HS_ACT_REQ:
  242. dev_dbg(adapter->dev, "event: HS_ACT_REQ\n");
  243. ret = mwifiex_send_cmd_async(priv,
  244. HostCmd_CMD_802_11_HS_CFG_ENH,
  245. 0, 0, NULL);
  246. break;
  247. case EVENT_MIC_ERR_UNICAST:
  248. dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n");
  249. break;
  250. case EVENT_MIC_ERR_MULTICAST:
  251. dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n");
  252. break;
  253. case EVENT_MIB_CHANGED:
  254. case EVENT_INIT_DONE:
  255. break;
  256. case EVENT_ADHOC_BCN_LOST:
  257. dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n");
  258. priv->adhoc_is_link_sensed = false;
  259. mwifiex_clean_txrx(priv);
  260. if (!netif_queue_stopped(priv->netdev))
  261. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  262. if (netif_carrier_ok(priv->netdev))
  263. netif_carrier_off(priv->netdev);
  264. break;
  265. case EVENT_BG_SCAN_REPORT:
  266. dev_dbg(adapter->dev, "event: BGS_REPORT\n");
  267. ret = mwifiex_send_cmd_async(priv,
  268. HostCmd_CMD_802_11_BG_SCAN_QUERY,
  269. HostCmd_ACT_GEN_GET, 0, NULL);
  270. break;
  271. case EVENT_PORT_RELEASE:
  272. dev_dbg(adapter->dev, "event: PORT RELEASE\n");
  273. break;
  274. case EVENT_WMM_STATUS_CHANGE:
  275. dev_dbg(adapter->dev, "event: WMM status changed\n");
  276. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_WMM_GET_STATUS,
  277. 0, 0, NULL);
  278. break;
  279. case EVENT_RSSI_LOW:
  280. dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n");
  281. break;
  282. case EVENT_SNR_LOW:
  283. dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
  284. break;
  285. case EVENT_MAX_FAIL:
  286. dev_dbg(adapter->dev, "event: MAX_FAIL\n");
  287. break;
  288. case EVENT_RSSI_HIGH:
  289. dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n");
  290. break;
  291. case EVENT_SNR_HIGH:
  292. dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
  293. break;
  294. case EVENT_DATA_RSSI_LOW:
  295. dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
  296. break;
  297. case EVENT_DATA_SNR_LOW:
  298. dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
  299. break;
  300. case EVENT_DATA_RSSI_HIGH:
  301. dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
  302. break;
  303. case EVENT_DATA_SNR_HIGH:
  304. dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
  305. break;
  306. case EVENT_LINK_QUALITY:
  307. dev_dbg(adapter->dev, "event: Link Quality\n");
  308. break;
  309. case EVENT_PRE_BEACON_LOST:
  310. dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
  311. break;
  312. case EVENT_IBSS_COALESCED:
  313. dev_dbg(adapter->dev, "event: IBSS_COALESCED\n");
  314. ret = mwifiex_send_cmd_async(priv,
  315. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  316. HostCmd_ACT_GEN_GET, 0, NULL);
  317. break;
  318. case EVENT_ADDBA:
  319. dev_dbg(adapter->dev, "event: ADDBA Request\n");
  320. mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP,
  321. HostCmd_ACT_GEN_SET, 0,
  322. adapter->event_body);
  323. break;
  324. case EVENT_DELBA:
  325. dev_dbg(adapter->dev, "event: DELBA Request\n");
  326. mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
  327. break;
  328. case EVENT_BA_STREAM_TIEMOUT:
  329. dev_dbg(adapter->dev, "event: BA Stream timeout\n");
  330. mwifiex_11n_ba_stream_timeout(priv,
  331. (struct host_cmd_ds_11n_batimeout
  332. *)
  333. adapter->event_body);
  334. break;
  335. case EVENT_AMSDU_AGGR_CTRL:
  336. dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n",
  337. *(u16 *) adapter->event_body);
  338. adapter->tx_buf_size =
  339. min(adapter->curr_tx_buf_size,
  340. le16_to_cpu(*(__le16 *) adapter->event_body));
  341. dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
  342. adapter->tx_buf_size);
  343. break;
  344. case EVENT_WEP_ICV_ERR:
  345. dev_dbg(adapter->dev, "event: WEP ICV error\n");
  346. break;
  347. case EVENT_BW_CHANGE:
  348. dev_dbg(adapter->dev, "event: BW Change\n");
  349. break;
  350. case EVENT_HOSTWAKE_STAIE:
  351. dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
  352. break;
  353. default:
  354. dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
  355. eventcause);
  356. break;
  357. }
  358. return ret;
  359. }