sta_event.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /*
  2. * Marvell Wireless LAN device driver: station event handling
  3. *
  4. * Copyright (C) 2011-2014, 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. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  51. ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info)) {
  52. mwifiex_disable_all_tdls_links(priv);
  53. if (priv->adapter->auto_tdls)
  54. mwifiex_clean_auto_tdls(priv);
  55. }
  56. /* Free Tx and Rx packets, report disconnect to upper layer */
  57. mwifiex_clean_txrx(priv);
  58. /* Reset SNR/NF/RSSI values */
  59. priv->data_rssi_last = 0;
  60. priv->data_nf_last = 0;
  61. priv->data_rssi_avg = 0;
  62. priv->data_nf_avg = 0;
  63. priv->bcn_rssi_last = 0;
  64. priv->bcn_nf_last = 0;
  65. priv->bcn_rssi_avg = 0;
  66. priv->bcn_nf_avg = 0;
  67. priv->rxpd_rate = 0;
  68. priv->rxpd_htinfo = 0;
  69. priv->sec_info.wpa_enabled = false;
  70. priv->sec_info.wpa2_enabled = false;
  71. priv->wpa_ie_len = 0;
  72. priv->sec_info.wapi_enabled = false;
  73. priv->wapi_ie_len = 0;
  74. priv->sec_info.wapi_key_on = false;
  75. priv->sec_info.encryption_mode = 0;
  76. /* Enable auto data rate */
  77. priv->is_data_rate_auto = true;
  78. priv->data_rate = 0;
  79. if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
  80. priv->adhoc_state = ADHOC_IDLE;
  81. priv->adhoc_is_link_sensed = false;
  82. }
  83. /*
  84. * Memorize the previous SSID and BSSID so
  85. * it could be used for re-assoc
  86. */
  87. dev_dbg(adapter->dev, "info: previous SSID=%s, SSID len=%u\n",
  88. priv->prev_ssid.ssid, priv->prev_ssid.ssid_len);
  89. dev_dbg(adapter->dev, "info: current SSID=%s, SSID len=%u\n",
  90. priv->curr_bss_params.bss_descriptor.ssid.ssid,
  91. priv->curr_bss_params.bss_descriptor.ssid.ssid_len);
  92. memcpy(&priv->prev_ssid,
  93. &priv->curr_bss_params.bss_descriptor.ssid,
  94. sizeof(struct cfg80211_ssid));
  95. memcpy(priv->prev_bssid,
  96. priv->curr_bss_params.bss_descriptor.mac_address, ETH_ALEN);
  97. /* Need to erase the current SSID and BSSID info */
  98. memset(&priv->curr_bss_params, 0x00, sizeof(priv->curr_bss_params));
  99. adapter->tx_lock_flag = false;
  100. adapter->pps_uapsd_mode = false;
  101. if (adapter->is_cmd_timedout && adapter->curr_cmd)
  102. return;
  103. priv->media_connected = false;
  104. dev_dbg(adapter->dev,
  105. "info: successfully disconnected from %pM: reason code %d\n",
  106. priv->cfg_bssid, reason_code);
  107. if (priv->bss_mode == NL80211_IFTYPE_STATION ||
  108. priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
  109. cfg80211_disconnected(priv->netdev, reason_code, NULL, 0,
  110. GFP_KERNEL);
  111. }
  112. memset(priv->cfg_bssid, 0, ETH_ALEN);
  113. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  114. if (netif_carrier_ok(priv->netdev))
  115. netif_carrier_off(priv->netdev);
  116. }
  117. static int mwifiex_parse_tdls_event(struct mwifiex_private *priv,
  118. struct sk_buff *event_skb)
  119. {
  120. int ret = 0;
  121. struct mwifiex_adapter *adapter = priv->adapter;
  122. struct mwifiex_sta_node *sta_ptr;
  123. struct mwifiex_tdls_generic_event *tdls_evt =
  124. (void *)event_skb->data + sizeof(adapter->event_cause);
  125. /* reserved 2 bytes are not mandatory in tdls event */
  126. if (event_skb->len < (sizeof(struct mwifiex_tdls_generic_event) -
  127. sizeof(u16) - sizeof(adapter->event_cause))) {
  128. dev_err(adapter->dev, "Invalid event length!\n");
  129. return -1;
  130. }
  131. sta_ptr = mwifiex_get_sta_entry(priv, tdls_evt->peer_mac);
  132. if (!sta_ptr) {
  133. dev_err(adapter->dev, "cannot get sta entry!\n");
  134. return -1;
  135. }
  136. switch (le16_to_cpu(tdls_evt->type)) {
  137. case TDLS_EVENT_LINK_TEAR_DOWN:
  138. cfg80211_tdls_oper_request(priv->netdev,
  139. tdls_evt->peer_mac,
  140. NL80211_TDLS_TEARDOWN,
  141. le16_to_cpu(tdls_evt->u.reason_code),
  142. GFP_KERNEL);
  143. break;
  144. default:
  145. break;
  146. }
  147. return ret;
  148. }
  149. /*
  150. * This function handles events generated by firmware.
  151. *
  152. * This is a generic function and handles all events.
  153. *
  154. * Event specific routines are called by this function based
  155. * upon the generated event cause.
  156. *
  157. * For the following events, the function just forwards them to upper
  158. * layers, optionally recording the change -
  159. * - EVENT_LINK_SENSED
  160. * - EVENT_MIC_ERR_UNICAST
  161. * - EVENT_MIC_ERR_MULTICAST
  162. * - EVENT_PORT_RELEASE
  163. * - EVENT_RSSI_LOW
  164. * - EVENT_SNR_LOW
  165. * - EVENT_MAX_FAIL
  166. * - EVENT_RSSI_HIGH
  167. * - EVENT_SNR_HIGH
  168. * - EVENT_DATA_RSSI_LOW
  169. * - EVENT_DATA_SNR_LOW
  170. * - EVENT_DATA_RSSI_HIGH
  171. * - EVENT_DATA_SNR_HIGH
  172. * - EVENT_LINK_QUALITY
  173. * - EVENT_PRE_BEACON_LOST
  174. * - EVENT_IBSS_COALESCED
  175. * - EVENT_WEP_ICV_ERR
  176. * - EVENT_BW_CHANGE
  177. * - EVENT_HOSTWAKE_STAIE
  178. *
  179. * For the following events, no action is taken -
  180. * - EVENT_MIB_CHANGED
  181. * - EVENT_INIT_DONE
  182. * - EVENT_DUMMY_HOST_WAKEUP_SIGNAL
  183. *
  184. * Rest of the supported events requires driver handling -
  185. * - EVENT_DEAUTHENTICATED
  186. * - EVENT_DISASSOCIATED
  187. * - EVENT_LINK_LOST
  188. * - EVENT_PS_SLEEP
  189. * - EVENT_PS_AWAKE
  190. * - EVENT_DEEP_SLEEP_AWAKE
  191. * - EVENT_HS_ACT_REQ
  192. * - EVENT_ADHOC_BCN_LOST
  193. * - EVENT_BG_SCAN_REPORT
  194. * - EVENT_WMM_STATUS_CHANGE
  195. * - EVENT_ADDBA
  196. * - EVENT_DELBA
  197. * - EVENT_BA_STREAM_TIEMOUT
  198. * - EVENT_AMSDU_AGGR_CTRL
  199. */
  200. int mwifiex_process_sta_event(struct mwifiex_private *priv)
  201. {
  202. struct mwifiex_adapter *adapter = priv->adapter;
  203. int ret = 0;
  204. u32 eventcause = adapter->event_cause;
  205. u16 ctrl, reason_code;
  206. switch (eventcause) {
  207. case EVENT_DUMMY_HOST_WAKEUP_SIGNAL:
  208. dev_err(adapter->dev,
  209. "invalid EVENT: DUMMY_HOST_WAKEUP_SIGNAL, ignore it\n");
  210. break;
  211. case EVENT_LINK_SENSED:
  212. dev_dbg(adapter->dev, "event: LINK_SENSED\n");
  213. if (!netif_carrier_ok(priv->netdev))
  214. netif_carrier_on(priv->netdev);
  215. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  216. break;
  217. case EVENT_DEAUTHENTICATED:
  218. dev_dbg(adapter->dev, "event: Deauthenticated\n");
  219. if (priv->wps.session_enable) {
  220. dev_dbg(adapter->dev,
  221. "info: receive deauth event in wps session\n");
  222. break;
  223. }
  224. adapter->dbg.num_event_deauth++;
  225. if (priv->media_connected) {
  226. reason_code =
  227. le16_to_cpu(*(__le16 *)adapter->event_body);
  228. mwifiex_reset_connect_state(priv, reason_code);
  229. }
  230. break;
  231. case EVENT_DISASSOCIATED:
  232. dev_dbg(adapter->dev, "event: Disassociated\n");
  233. if (priv->wps.session_enable) {
  234. dev_dbg(adapter->dev,
  235. "info: receive disassoc event in wps session\n");
  236. break;
  237. }
  238. adapter->dbg.num_event_disassoc++;
  239. if (priv->media_connected) {
  240. reason_code =
  241. le16_to_cpu(*(__le16 *)adapter->event_body);
  242. mwifiex_reset_connect_state(priv, reason_code);
  243. }
  244. break;
  245. case EVENT_LINK_LOST:
  246. dev_dbg(adapter->dev, "event: Link lost\n");
  247. adapter->dbg.num_event_link_lost++;
  248. if (priv->media_connected) {
  249. reason_code =
  250. le16_to_cpu(*(__le16 *)adapter->event_body);
  251. mwifiex_reset_connect_state(priv, reason_code);
  252. }
  253. break;
  254. case EVENT_PS_SLEEP:
  255. dev_dbg(adapter->dev, "info: EVENT: SLEEP\n");
  256. adapter->ps_state = PS_STATE_PRE_SLEEP;
  257. mwifiex_check_ps_cond(adapter);
  258. break;
  259. case EVENT_PS_AWAKE:
  260. dev_dbg(adapter->dev, "info: EVENT: AWAKE\n");
  261. if (!adapter->pps_uapsd_mode &&
  262. priv->media_connected && adapter->sleep_period.period) {
  263. adapter->pps_uapsd_mode = true;
  264. dev_dbg(adapter->dev,
  265. "event: PPS/UAPSD mode activated\n");
  266. }
  267. adapter->tx_lock_flag = false;
  268. if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
  269. if (mwifiex_check_last_packet_indication(priv)) {
  270. if (adapter->data_sent) {
  271. adapter->ps_state = PS_STATE_AWAKE;
  272. adapter->pm_wakeup_card_req = false;
  273. adapter->pm_wakeup_fw_try = false;
  274. break;
  275. }
  276. if (!mwifiex_send_null_packet
  277. (priv,
  278. MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
  279. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
  280. adapter->ps_state =
  281. PS_STATE_SLEEP;
  282. return 0;
  283. }
  284. }
  285. adapter->ps_state = PS_STATE_AWAKE;
  286. adapter->pm_wakeup_card_req = false;
  287. adapter->pm_wakeup_fw_try = false;
  288. break;
  289. case EVENT_DEEP_SLEEP_AWAKE:
  290. adapter->if_ops.wakeup_complete(adapter);
  291. dev_dbg(adapter->dev, "event: DS_AWAKE\n");
  292. if (adapter->is_deep_sleep)
  293. adapter->is_deep_sleep = false;
  294. break;
  295. case EVENT_HS_ACT_REQ:
  296. dev_dbg(adapter->dev, "event: HS_ACT_REQ\n");
  297. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_HS_CFG_ENH,
  298. 0, 0, NULL, false);
  299. break;
  300. case EVENT_MIC_ERR_UNICAST:
  301. dev_dbg(adapter->dev, "event: UNICAST MIC ERROR\n");
  302. cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
  303. NL80211_KEYTYPE_PAIRWISE,
  304. -1, NULL, GFP_KERNEL);
  305. break;
  306. case EVENT_MIC_ERR_MULTICAST:
  307. dev_dbg(adapter->dev, "event: MULTICAST MIC ERROR\n");
  308. cfg80211_michael_mic_failure(priv->netdev, priv->cfg_bssid,
  309. NL80211_KEYTYPE_GROUP,
  310. -1, NULL, GFP_KERNEL);
  311. break;
  312. case EVENT_MIB_CHANGED:
  313. case EVENT_INIT_DONE:
  314. break;
  315. case EVENT_ADHOC_BCN_LOST:
  316. dev_dbg(adapter->dev, "event: ADHOC_BCN_LOST\n");
  317. priv->adhoc_is_link_sensed = false;
  318. mwifiex_clean_txrx(priv);
  319. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  320. if (netif_carrier_ok(priv->netdev))
  321. netif_carrier_off(priv->netdev);
  322. break;
  323. case EVENT_BG_SCAN_REPORT:
  324. dev_dbg(adapter->dev, "event: BGS_REPORT\n");
  325. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_QUERY,
  326. HostCmd_ACT_GEN_GET, 0, NULL, false);
  327. break;
  328. case EVENT_PORT_RELEASE:
  329. dev_dbg(adapter->dev, "event: PORT RELEASE\n");
  330. break;
  331. case EVENT_EXT_SCAN_REPORT:
  332. dev_dbg(adapter->dev, "event: EXT_SCAN Report\n");
  333. if (adapter->ext_scan)
  334. ret = mwifiex_handle_event_ext_scan_report(priv,
  335. adapter->event_skb->data);
  336. break;
  337. case EVENT_WMM_STATUS_CHANGE:
  338. dev_dbg(adapter->dev, "event: WMM status changed\n");
  339. ret = mwifiex_send_cmd(priv, HostCmd_CMD_WMM_GET_STATUS,
  340. 0, 0, NULL, false);
  341. break;
  342. case EVENT_RSSI_LOW:
  343. cfg80211_cqm_rssi_notify(priv->netdev,
  344. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  345. GFP_KERNEL);
  346. mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
  347. HostCmd_ACT_GEN_GET, 0, NULL, false);
  348. priv->subsc_evt_rssi_state = RSSI_LOW_RECVD;
  349. dev_dbg(adapter->dev, "event: Beacon RSSI_LOW\n");
  350. break;
  351. case EVENT_SNR_LOW:
  352. dev_dbg(adapter->dev, "event: Beacon SNR_LOW\n");
  353. break;
  354. case EVENT_MAX_FAIL:
  355. dev_dbg(adapter->dev, "event: MAX_FAIL\n");
  356. break;
  357. case EVENT_RSSI_HIGH:
  358. cfg80211_cqm_rssi_notify(priv->netdev,
  359. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  360. GFP_KERNEL);
  361. mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO,
  362. HostCmd_ACT_GEN_GET, 0, NULL, false);
  363. priv->subsc_evt_rssi_state = RSSI_HIGH_RECVD;
  364. dev_dbg(adapter->dev, "event: Beacon RSSI_HIGH\n");
  365. break;
  366. case EVENT_SNR_HIGH:
  367. dev_dbg(adapter->dev, "event: Beacon SNR_HIGH\n");
  368. break;
  369. case EVENT_DATA_RSSI_LOW:
  370. dev_dbg(adapter->dev, "event: Data RSSI_LOW\n");
  371. break;
  372. case EVENT_DATA_SNR_LOW:
  373. dev_dbg(adapter->dev, "event: Data SNR_LOW\n");
  374. break;
  375. case EVENT_DATA_RSSI_HIGH:
  376. dev_dbg(adapter->dev, "event: Data RSSI_HIGH\n");
  377. break;
  378. case EVENT_DATA_SNR_HIGH:
  379. dev_dbg(adapter->dev, "event: Data SNR_HIGH\n");
  380. break;
  381. case EVENT_LINK_QUALITY:
  382. dev_dbg(adapter->dev, "event: Link Quality\n");
  383. break;
  384. case EVENT_PRE_BEACON_LOST:
  385. dev_dbg(adapter->dev, "event: Pre-Beacon Lost\n");
  386. break;
  387. case EVENT_IBSS_COALESCED:
  388. dev_dbg(adapter->dev, "event: IBSS_COALESCED\n");
  389. ret = mwifiex_send_cmd(priv,
  390. HostCmd_CMD_802_11_IBSS_COALESCING_STATUS,
  391. HostCmd_ACT_GEN_GET, 0, NULL, false);
  392. break;
  393. case EVENT_ADDBA:
  394. dev_dbg(adapter->dev, "event: ADDBA Request\n");
  395. mwifiex_send_cmd(priv, HostCmd_CMD_11N_ADDBA_RSP,
  396. HostCmd_ACT_GEN_SET, 0,
  397. adapter->event_body, false);
  398. break;
  399. case EVENT_DELBA:
  400. dev_dbg(adapter->dev, "event: DELBA Request\n");
  401. mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
  402. break;
  403. case EVENT_BA_STREAM_TIEMOUT:
  404. dev_dbg(adapter->dev, "event: BA Stream timeout\n");
  405. mwifiex_11n_ba_stream_timeout(priv,
  406. (struct host_cmd_ds_11n_batimeout
  407. *)
  408. adapter->event_body);
  409. break;
  410. case EVENT_AMSDU_AGGR_CTRL:
  411. ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
  412. dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
  413. adapter->tx_buf_size =
  414. min_t(u16, adapter->curr_tx_buf_size, ctrl);
  415. dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
  416. adapter->tx_buf_size);
  417. break;
  418. case EVENT_WEP_ICV_ERR:
  419. dev_dbg(adapter->dev, "event: WEP ICV error\n");
  420. break;
  421. case EVENT_BW_CHANGE:
  422. dev_dbg(adapter->dev, "event: BW Change\n");
  423. break;
  424. case EVENT_HOSTWAKE_STAIE:
  425. dev_dbg(adapter->dev, "event: HOSTWAKE_STAIE %d\n", eventcause);
  426. break;
  427. case EVENT_REMAIN_ON_CHAN_EXPIRED:
  428. dev_dbg(adapter->dev, "event: Remain on channel expired\n");
  429. cfg80211_remain_on_channel_expired(priv->wdev,
  430. priv->roc_cfg.cookie,
  431. &priv->roc_cfg.chan,
  432. GFP_ATOMIC);
  433. memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
  434. break;
  435. case EVENT_CHANNEL_SWITCH_ANN:
  436. dev_dbg(adapter->dev, "event: Channel Switch Announcement\n");
  437. priv->csa_expire_time =
  438. jiffies + msecs_to_jiffies(DFS_CHAN_MOVE_TIME);
  439. priv->csa_chan = priv->curr_bss_params.bss_descriptor.channel;
  440. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_DEAUTHENTICATE,
  441. HostCmd_ACT_GEN_SET, 0,
  442. priv->curr_bss_params.bss_descriptor.mac_address,
  443. false);
  444. break;
  445. case EVENT_TDLS_GENERIC_EVENT:
  446. ret = mwifiex_parse_tdls_event(priv, adapter->event_skb);
  447. break;
  448. case EVENT_TX_STATUS_REPORT:
  449. dev_dbg(adapter->dev, "event: TX_STATUS Report\n");
  450. mwifiex_parse_tx_status_event(priv, adapter->event_body);
  451. break;
  452. default:
  453. dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
  454. eventcause);
  455. break;
  456. }
  457. return ret;
  458. }