sta_event.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. if (priv->wps.session_enable) {
  181. dev_dbg(adapter->dev,
  182. "info: receive deauth event in wps session\n");
  183. break;
  184. }
  185. adapter->dbg.num_event_deauth++;
  186. if (priv->media_connected) {
  187. reason_code =
  188. le16_to_cpu(*(__le16 *)adapter->event_body);
  189. mwifiex_reset_connect_state(priv, reason_code);
  190. }
  191. break;
  192. case EVENT_DISASSOCIATED:
  193. dev_dbg(adapter->dev, "event: Disassociated\n");
  194. if (priv->wps.session_enable) {
  195. dev_dbg(adapter->dev,
  196. "info: receive disassoc event in wps session\n");
  197. break;
  198. }
  199. adapter->dbg.num_event_disassoc++;
  200. if (priv->media_connected) {
  201. reason_code =
  202. le16_to_cpu(*(__le16 *)adapter->event_body);
  203. mwifiex_reset_connect_state(priv, reason_code);
  204. }
  205. break;
  206. case EVENT_LINK_LOST:
  207. dev_dbg(adapter->dev, "event: Link lost\n");
  208. adapter->dbg.num_event_link_lost++;
  209. if (priv->media_connected) {
  210. reason_code =
  211. le16_to_cpu(*(__le16 *)adapter->event_body);
  212. mwifiex_reset_connect_state(priv, reason_code);
  213. }
  214. break;
  215. case EVENT_PS_SLEEP:
  216. dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
  217. adapter->ps_state = PS_STATE_PRE_SLEEP;
  218. mwifiex_check_ps_cond(adapter);
  219. break;
  220. case EVENT_PS_AWAKE:
  221. dev_dbg(adapter->dev, "info: EVENT: AWAKE\n");
  222. if (!adapter->pps_uapsd_mode &&
  223. priv->media_connected && adapter->sleep_period.period) {
  224. adapter->pps_uapsd_mode = true;
  225. dev_dbg(adapter->dev,
  226. "event: PPS/UAPSD mode activated\n");
  227. }
  228. adapter->tx_lock_flag = false;
  229. if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
  230. if (mwifiex_check_last_packet_indication(priv)) {
  231. if (adapter->data_sent) {
  232. adapter->ps_state = PS_STATE_AWAKE;
  233. adapter->pm_wakeup_card_req = false;
  234. adapter->pm_wakeup_fw_try = false;
  235. break;
  236. }
  237. if (!mwifiex_send_null_packet
  238. (priv,
  239. MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
  240. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
  241. adapter->ps_state =
  242. PS_STATE_SLEEP;
  243. return 0;
  244. }
  245. }
  246. adapter->ps_state = PS_STATE_AWAKE;
  247. adapter->pm_wakeup_card_req = false;
  248. adapter->pm_wakeup_fw_try = false;
  249. break;
  250. case EVENT_DEEP_SLEEP_AWAKE:
  251. adapter->if_ops.wakeup_complete(adapter);
  252. dev_dbg(adapter->dev, "event: DS_AWAKE\n");
  253. if (adapter->is_deep_sleep)
  254. adapter->is_deep_sleep = false;
  255. break;
  256. case EVENT_HS_ACT_REQ:
  257. dev_dbg(adapter->dev, "event: HS_ACT_REQ\n");
  258. ret = mwifiex_send_cmd_async(priv,
  259. HostCmd_CMD_802_11_HS_CFG_ENH,
  260. 0, 0, NULL);
  261. break;
  262. case EVENT_MIC_ERR_UNICAST:
  263. dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n");
  264. cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
  265. NL80211_KEYTYPE_PAIRWISE,
  266. -1, NULL, GFP_KERNEL);
  267. break;
  268. case EVENT_MIC_ERR_MULTICAST:
  269. dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n");
  270. cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
  271. NL80211_KEYTYPE_GROUP,
  272. -1, NULL, GFP_KERNEL);
  273. break;
  274. case EVENT_MIB_CHANGED:
  275. case EVENT_INIT_DONE:
  276. break;
  277. case EVENT_ADHOC_BCN_LOST:
  278. dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n");
  279. priv->adhoc_is_link_sensed = false;
  280. mwifiex_clean_txrx(priv);
  281. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  282. if (netif_carrier_ok(priv->netdev))
  283. netif_carrier_off(priv->netdev);
  284. break;
  285. case EVENT_BG_SCAN_REPORT:
  286. dev_dbg(adapter->dev, "event: BGS_REPORT\n");
  287. ret = mwifiex_send_cmd_async(priv,
  288. HostCmd_CMD_802_11_BG_SCAN_QUERY,
  289. HostCmd_ACT_GEN_GET, 0, NULL);
  290. break;
  291. case EVENT_PORT_RELEASE:
  292. dev_dbg(adapter->dev, "event: PORT RELEASE\n");
  293. break;
  294. case EVENT_WMM_STATUS_CHANGE:
  295. dev_dbg(adapter->dev, "event: WMM status changed\n");
  296. ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_WMM_GET_STATUS,
  297. 0, 0, NULL);
  298. break;
  299. case EVENT_RSSI_LOW:
  300. cfg80211_cqm_rssi_notify(priv->netdev,
  301. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  302. GFP_KERNEL);
  303. mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
  304. HostCmd_ACT_GEN_GET, 0, NULL);
  305. priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
  306. dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n");
  307. break;
  308. case EVENT_SNR_LOW:
  309. dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
  310. break;
  311. case EVENT_MAX_FAIL:
  312. dev_dbg(adapter->dev, "event: MAX_FAIL\n");
  313. break;
  314. case EVENT_RSSI_HIGH:
  315. cfg80211_cqm_rssi_notify(priv->netdev,
  316. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  317. GFP_KERNEL);
  318. mwifiex_send_cmd_async(priv, HostCmd_CMD_RSSI_INFO,
  319. HostCmd_ACT_GEN_GET, 0, NULL);
  320. priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
  321. dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n");
  322. break;
  323. case EVENT_SNR_HIGH:
  324. dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
  325. break;
  326. case EVENT_DATA_RSSI_LOW:
  327. dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
  328. break;
  329. case EVENT_DATA_SNR_LOW:
  330. dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
  331. break;
  332. case EVENT_DATA_RSSI_HIGH:
  333. dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
  334. break;
  335. case EVENT_DATA_SNR_HIGH:
  336. dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
  337. break;
  338. case EVENT_LINK_QUALITY:
  339. dev_dbg(adapter->dev, "event: Link Quality\n");
  340. break;
  341. case EVENT_PRE_BEACON_LOST:
  342. dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
  343. break;
  344. case EVENT_IBSS_COALESCED:
  345. dev_dbg(adapter->dev, "event: IBSS_COALESCED\n");
  346. ret = mwifiex_send_cmd_async(priv,
  347. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  348. HostCmd_ACT_GEN_GET, 0, NULL);
  349. break;
  350. case EVENT_ADDBA:
  351. dev_dbg(adapter->dev, "event: ADDBA Request\n");
  352. mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP,
  353. HostCmd_ACT_GEN_SET, 0,
  354. adapter->event_body);
  355. break;
  356. case EVENT_DELBA:
  357. dev_dbg(adapter->dev, "event: DELBA Request\n");
  358. mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
  359. break;
  360. case EVENT_BA_STREAM_TIEMOUT:
  361. dev_dbg(adapter->dev, "event: BA Stream timeout\n");
  362. mwifiex_11n_ba_stream_timeout(priv,
  363. (struct host_cmd_ds_11n_batimeout
  364. *)
  365. adapter->event_body);
  366. break;
  367. case EVENT_AMSDU_AGGR_CTRL:
  368. ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
  369. dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
  370. adapter->tx_buf_size =
  371. min_t(u16, adapter->curr_tx_buf_size, ctrl);
  372. dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
  373. adapter->tx_buf_size);
  374. break;
  375. case EVENT_WEP_ICV_ERR:
  376. dev_dbg(adapter->dev, "event: WEP ICV error\n");
  377. break;
  378. case EVENT_BW_CHANGE:
  379. dev_dbg(adapter->dev, "event: BW Change\n");
  380. break;
  381. case EVENT_HOSTWAKE_STAIE:
  382. dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
  383. break;
  384. case EVENT_REMAIN_ON_CHAN_EXPIRED:
  385. dev_dbg(adapter->dev, "event: Remain on channel expired\n");
  386. cfg80211_remain_on_channel_expired(priv->wdev,
  387. priv->roc_cfg.cookie,
  388. &priv->roc_cfg.chan,
  389. GFP_ATOMIC);
  390. memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
  391. break;
  392. case EVENT_CHANNEL_SWITCH_ANN:
  393. dev_dbg(adapter->dev, "event: Channel Switch Announcement\n");
  394. priv->csa_expire_time =
  395. jiffies + msecs_to_jiffies(DFS_CHAN_MOVE_TIME);
  396. priv->csa_chan = priv->curr_bss_params.bss_descriptor.channel;
  397. ret = mwifiex_send_cmd_async(priv,
  398. HostCmd_CMD_802_11_DEAUTHENTICATE,
  399. HostCmd_ACT_GEN_SET, 0,
  400. priv->curr_bss_params.bss_descriptor.mac_address);
  401. break;
  402. default:
  403. dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
  404. eventcause);
  405. break;
  406. }
  407. return ret;
  408. }