sta_event.c 13 KB

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