sta_event.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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, u16 reason_code)
  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, reason_code);
  101. if (priv->bss_mode == NL80211_IFTYPE_STATION) {
  102. cfg80211_disconnected(priv->netdev, reason_code, NULL, 0,
  103. GFP_KERNEL);
  104. }
  105. memset(priv->cfg_bssid, 0, ETH_ALEN);
  106. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  107. if (netif_carrier_ok(priv->netdev))
  108. netif_carrier_off(priv->netdev);
  109. }
  110. /*
  111. * This function handles events generated by firmware.
  112. *
  113. * This is a generic function and handles all events.
  114. *
  115. * Event specific routines are called by this function based
  116. * upon the generated event cause.
  117. *
  118. * For the following events, the function just forwards them to upper
  119. * layers, optionally recording the change -
  120. * - EVENT_LINK_SENSED
  121. * - EVENT_MIC_ERR_UNICAST
  122. * - EVENT_MIC_ERR_MULTICAST
  123. * - EVENT_PORT_RELEASE
  124. * - EVENT_RSSI_LOW
  125. * - EVENT_SNR_LOW
  126. * - EVENT_MAX_FAIL
  127. * - EVENT_RSSI_HIGH
  128. * - EVENT_SNR_HIGH
  129. * - EVENT_DATA_RSSI_LOW
  130. * - EVENT_DATA_SNR_LOW
  131. * - EVENT_DATA_RSSI_HIGH
  132. * - EVENT_DATA_SNR_HIGH
  133. * - EVENT_LINK_QUALITY
  134. * - EVENT_PRE_BEACON_LOST
  135. * - EVENT_IBSS_COALESCED
  136. * - EVENT_WEP_ICV_ERR
  137. * - EVENT_BW_CHANGE
  138. * - EVENT_HOSTWAKE_STAIE
  139. *
  140. * For the following events, no action is taken -
  141. * - EVENT_MIB_CHANGED
  142. * - EVENT_INIT_DONE
  143. * - EVENT_DUMMY_HOST_WAKEUP_SIGNAL
  144. *
  145. * Rest of the supported events requires driver handling -
  146. * - EVENT_DEAUTHENTICATED
  147. * - EVENT_DISASSOCIATED
  148. * - EVENT_LINK_LOST
  149. * - EVENT_PS_SLEEP
  150. * - EVENT_PS_AWAKE
  151. * - EVENT_DEEP_SLEEP_AWAKE
  152. * - EVENT_HS_ACT_REQ
  153. * - EVENT_ADHOC_BCN_LOST
  154. * - EVENT_BG_SCAN_REPORT
  155. * - EVENT_WMM_STATUS_CHANGE
  156. * - EVENT_ADDBA
  157. * - EVENT_DELBA
  158. * - EVENT_BA_STREAM_TIEMOUT
  159. * - EVENT_AMSDU_AGGR_CTRL
  160. */
  161. int mwifiex_process_sta_event(struct mwifiex_private *priv)
  162. {
  163. struct mwifiex_adapter *adapter = priv->adapter;
  164. int ret = 0;
  165. u32 eventcause = adapter->event_cause;
  166. u16 ctrl, reason_code;
  167. switch (eventcause) {
  168. case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
  169. dev_err(adapter->dev,
  170. "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
  171. break;
  172. case EVENT_LINK_SENSED:
  173. dev_dbg(adapter->dev, "event: LINK_SENSED\n");
  174. if (!netif_carrier_ok(priv->netdev))
  175. netif_carrier_on(priv->netdev);
  176. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  177. break;
  178. case EVENT_DEAUTHENTICATED:
  179. dev_dbg(adapter->dev, "event: Deauthenticated\n");
  180. adapter->dbg.num_event_deauth++;
  181. if (priv->media_connected) {
  182. reason_code =
  183. le16_to_cpu(*(__le16 *)adapter->event_body);
  184. mwifiex_reset_connect_state(priv, reason_code);
  185. }
  186. break;
  187. case EVENT_DISASSOCIATED:
  188. dev_dbg(adapter->dev, "event: Disassociated\n");
  189. adapter->dbg.num_event_disassoc++;
  190. if (priv->media_connected) {
  191. reason_code =
  192. le16_to_cpu(*(__le16 *)adapter->event_body);
  193. mwifiex_reset_connect_state(priv, reason_code);
  194. }
  195. break;
  196. case EVENT_LINK_LOST:
  197. dev_dbg(adapter->dev, "event: Link lost\n");
  198. adapter->dbg.num_event_link_lost++;
  199. if (priv->media_connected) {
  200. reason_code =
  201. le16_to_cpu(*(__le16 *)adapter->event_body);
  202. mwifiex_reset_connect_state(priv, reason_code);
  203. }
  204. break;
  205. case EVENT_PS_SLEEP:
  206. dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
  207. adapter->ps_state = PS_STATE_PRE_SLEEP;
  208. mwifiex_check_ps_cond(adapter);
  209. break;
  210. case EVENT_PS_AWAKE:
  211. dev_dbg(adapter->dev, "info: EVENT: AWAKE\n");
  212. if (!adapter->pps_uapsd_mode &&
  213. priv->media_connected && adapter->sleep_period.period) {
  214. adapter->pps_uapsd_mode = true;
  215. dev_dbg(adapter->dev,
  216. "event: PPS/UAPSD mode activated\n");
  217. }
  218. adapter->tx_lock_flag = false;
  219. if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
  220. if (mwifiex_check_last_packet_indication(priv)) {
  221. if (adapter->data_sent) {
  222. adapter->ps_state = PS_STATE_AWAKE;
  223. adapter->pm_wakeup_card_req = false;
  224. adapter->pm_wakeup_fw_try = false;
  225. break;
  226. }
  227. if (!mwifiex_send_null_packet
  228. (priv,
  229. MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
  230. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
  231. adapter->ps_state =
  232. PS_STATE_SLEEP;
  233. return 0;
  234. }
  235. }
  236. adapter->ps_state = PS_STATE_AWAKE;
  237. adapter->pm_wakeup_card_req = false;
  238. adapter->pm_wakeup_fw_try = false;
  239. break;
  240. case EVENT_DEEP_SLEEP_AWAKE:
  241. adapter->if_ops.wakeup_complete(adapter);
  242. dev_dbg(adapter->dev, "event: DS_AWAKE\n");
  243. if (adapter->is_deep_sleep)
  244. adapter->is_deep_sleep = false;
  245. break;
  246. case EVENT_HS_ACT_REQ:
  247. dev_dbg(adapter->dev, "event: HS_ACT_REQ\n");
  248. ret = mwifiex_send_cmd_async(priv,
  249. HostCmd_CMD_802_11_HS_CFG_ENH,
  250. 0, 0, NULL);
  251. break;
  252. case EVENT_MIC_ERR_UNICAST:
  253. dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n");
  254. cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
  255. NL80211_KEYTYPE_PAIRWISE,
  256. -1, NULL, GFP_KERNEL);
  257. break;
  258. case EVENT_MIC_ERR_MULTICAST:
  259. dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n");
  260. cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
  261. NL80211_KEYTYPE_GROUP,
  262. -1, NULL, GFP_KERNEL);
  263. break;
  264. case EVENT_MIB_CHANGED:
  265. case EVENT_INIT_DONE:
  266. break;
  267. case EVENT_ADHOC_BCN_LOST:
  268. dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n");
  269. priv->adhoc_is_link_sensed = false;
  270. mwifiex_clean_txrx(priv);
  271. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  272. if (netif_carrier_ok(priv->netdev))
  273. netif_carrier_off(priv->netdev);
  274. break;
  275. case EVENT_BG_SCAN_REPORT:
  276. dev_dbg(adapter->dev, "event: BGS_REPORT\n");
  277. ret = mwifiex_send_cmd_async(priv,
  278. HostCmd_CMD_802_11_BG_SCAN_QUERY,
  279. HostCmd_ACT_GEN_GET, 0, NULL);
  280. break;
  281. case EVENT_PORT_RELEASE:
  282. dev_dbg(adapter->dev, "event: PORT RELEASE\n");
  283. break;
  284. case EVENT_WMM_STATUS_CHANGE:
  285. dev_dbg(adapter->dev, "event: WMM status changed\n");
  286. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_WMM_GET_STATUS,
  287. 0, 0, NULL);
  288. break;
  289. case EVENT_RSSI_LOW:
  290. cfg80211_cqm_rssi_notify(priv->netdev,
  291. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  292. GFP_KERNEL);
  293. mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
  294. HostCmd_ACT_GEN_GET, 0, NULL);
  295. priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
  296. dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n");
  297. break;
  298. case EVENT_SNR_LOW:
  299. dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
  300. break;
  301. case EVENT_MAX_FAIL:
  302. dev_dbg(adapter->dev, "event: MAX_FAIL\n");
  303. break;
  304. case EVENT_RSSI_HIGH:
  305. cfg80211_cqm_rssi_notify(priv->netdev,
  306. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  307. GFP_KERNEL);
  308. mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
  309. HostCmd_ACT_GEN_GET, 0, NULL);
  310. priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
  311. dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n");
  312. break;
  313. case EVENT_SNR_HIGH:
  314. dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
  315. break;
  316. case EVENT_DATA_RSSI_LOW:
  317. dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
  318. break;
  319. case EVENT_DATA_SNR_LOW:
  320. dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
  321. break;
  322. case EVENT_DATA_RSSI_HIGH:
  323. dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
  324. break;
  325. case EVENT_DATA_SNR_HIGH:
  326. dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
  327. break;
  328. case EVENT_LINK_QUALITY:
  329. dev_dbg(adapter->dev, "event: Link Quality\n");
  330. break;
  331. case EVENT_PRE_BEACON_LOST:
  332. dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
  333. break;
  334. case EVENT_IBSS_COALESCED:
  335. dev_dbg(adapter->dev, "event: IBSS_COALESCED\n");
  336. ret = mwifiex_send_cmd_async(priv,
  337. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  338. HostCmd_ACT_GEN_GET, 0, NULL);
  339. break;
  340. case EVENT_ADDBA:
  341. dev_dbg(adapter->dev, "event: ADDBA Request\n");
  342. mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP,
  343. HostCmd_ACT_GEN_SET, 0,
  344. adapter->event_body);
  345. break;
  346. case EVENT_DELBA:
  347. dev_dbg(adapter->dev, "event: DELBA Request\n");
  348. mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
  349. break;
  350. case EVENT_BA_STREAM_TIEMOUT:
  351. dev_dbg(adapter->dev, "event: BA Stream timeout\n");
  352. mwifiex_11n_ba_stream_timeout(priv,
  353. (struct host_cmd_ds_11n_batimeout
  354. *)
  355. adapter->event_body);
  356. break;
  357. case EVENT_AMSDU_AGGR_CTRL:
  358. ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
  359. dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
  360. adapter->tx_buf_size =
  361. min_t(u16, adapter->curr_tx_buf_size, ctrl);
  362. dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
  363. adapter->tx_buf_size);
  364. break;
  365. case EVENT_WEP_ICV_ERR:
  366. dev_dbg(adapter->dev, "event: WEP ICV error\n");
  367. break;
  368. case EVENT_BW_CHANGE:
  369. dev_dbg(adapter->dev, "event: BW Change\n");
  370. break;
  371. case EVENT_HOSTWAKE_STAIE:
  372. dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
  373. break;
  374. case EVENT_REMAIN_ON_CHAN_EXPIRED:
  375. dev_dbg(adapter->dev, "event: Remain on channel expired\n");
  376. cfg80211_remain_on_channel_expired(priv->wdev,
  377. priv->roc_cfg.cookie,
  378. &priv->roc_cfg.chan,
  379. GFP_ATOMIC);
  380. memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
  381. break;
  382. default:
  383. dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
  384. eventcause);
  385. break;
  386. }
  387. return ret;
  388. }