uap_event.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. * Marvell Wireless LAN device driver: AP event handling
  3. *
  4. * Copyright (C) 2012-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 "main.h"
  21. #include "11n.h"
  22. #define MWIFIEX_BSS_START_EVT_FIX_SIZE 12
  23. static int mwifiex_check_uap_capabilties(struct mwifiex_private *priv,
  24. struct sk_buff *event)
  25. {
  26. int evt_len;
  27. u8 *curr;
  28. u16 tlv_len;
  29. struct mwifiex_ie_types_data *tlv_hdr;
  30. struct ieee_types_wmm_parameter *wmm_param_ie = NULL;
  31. int mask = IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK;
  32. priv->wmm_enabled = false;
  33. skb_pull(event, MWIFIEX_BSS_START_EVT_FIX_SIZE);
  34. evt_len = event->len;
  35. curr = event->data;
  36. mwifiex_dbg_dump(priv->adapter, EVT_D, "uap capabilties:",
  37. event->data, event->len);
  38. skb_push(event, MWIFIEX_BSS_START_EVT_FIX_SIZE);
  39. while ((evt_len >= sizeof(tlv_hdr->header))) {
  40. tlv_hdr = (struct mwifiex_ie_types_data *)curr;
  41. tlv_len = le16_to_cpu(tlv_hdr->header.len);
  42. if (evt_len < tlv_len + sizeof(tlv_hdr->header))
  43. break;
  44. switch (le16_to_cpu(tlv_hdr->header.type)) {
  45. case WLAN_EID_HT_CAPABILITY:
  46. priv->ap_11n_enabled = true;
  47. break;
  48. case WLAN_EID_VHT_CAPABILITY:
  49. priv->ap_11ac_enabled = true;
  50. break;
  51. case WLAN_EID_VENDOR_SPECIFIC:
  52. /* Point the regular IEEE IE 2 bytes into the Marvell IE
  53. * and setup the IEEE IE type and length byte fields
  54. */
  55. wmm_param_ie = (void *)(curr + 2);
  56. wmm_param_ie->vend_hdr.len = (u8)tlv_len;
  57. wmm_param_ie->vend_hdr.element_id =
  58. WLAN_EID_VENDOR_SPECIFIC;
  59. mwifiex_dbg(priv->adapter, EVENT,
  60. "info: check uap capabilities:\t"
  61. "wmm parameter set count: %d\n",
  62. wmm_param_ie->qos_info_bitmap & mask);
  63. mwifiex_wmm_setup_ac_downgrade(priv);
  64. priv->wmm_enabled = true;
  65. mwifiex_wmm_setup_queue_priorities(priv, wmm_param_ie);
  66. break;
  67. default:
  68. break;
  69. }
  70. curr += (tlv_len + sizeof(tlv_hdr->header));
  71. evt_len -= (tlv_len + sizeof(tlv_hdr->header));
  72. }
  73. return 0;
  74. }
  75. /*
  76. * This function handles AP interface specific events generated by firmware.
  77. *
  78. * Event specific routines are called by this function based
  79. * upon the generated event cause.
  80. *
  81. *
  82. * Events supported for AP -
  83. * - EVENT_UAP_STA_ASSOC
  84. * - EVENT_UAP_STA_DEAUTH
  85. * - EVENT_UAP_BSS_ACTIVE
  86. * - EVENT_UAP_BSS_START
  87. * - EVENT_UAP_BSS_IDLE
  88. * - EVENT_UAP_MIC_COUNTERMEASURES:
  89. */
  90. int mwifiex_process_uap_event(struct mwifiex_private *priv)
  91. {
  92. struct mwifiex_adapter *adapter = priv->adapter;
  93. int len, i;
  94. u32 eventcause = adapter->event_cause;
  95. struct station_info sinfo;
  96. struct mwifiex_assoc_event *event;
  97. struct mwifiex_sta_node *node;
  98. u8 *deauth_mac;
  99. struct host_cmd_ds_11n_batimeout *ba_timeout;
  100. u16 ctrl;
  101. switch (eventcause) {
  102. case EVENT_UAP_STA_ASSOC:
  103. memset(&sinfo, 0, sizeof(sinfo));
  104. event = (struct mwifiex_assoc_event *)
  105. (adapter->event_body + MWIFIEX_UAP_EVENT_EXTRA_HEADER);
  106. if (le16_to_cpu(event->type) == TLV_TYPE_UAP_MGMT_FRAME) {
  107. len = -1;
  108. if (ieee80211_is_assoc_req(event->frame_control))
  109. len = 0;
  110. else if (ieee80211_is_reassoc_req(event->frame_control))
  111. /* There will be ETH_ALEN bytes of
  112. * current_ap_addr before the re-assoc ies.
  113. */
  114. len = ETH_ALEN;
  115. if (len != -1) {
  116. sinfo.assoc_req_ies = &event->data[len];
  117. len = (u8 *)sinfo.assoc_req_ies -
  118. (u8 *)&event->frame_control;
  119. sinfo.assoc_req_ies_len =
  120. le16_to_cpu(event->len) - (u16)len;
  121. }
  122. }
  123. cfg80211_new_sta(priv->netdev, event->sta_addr, &sinfo,
  124. GFP_KERNEL);
  125. node = mwifiex_add_sta_entry(priv, event->sta_addr);
  126. if (!node) {
  127. mwifiex_dbg(adapter, ERROR,
  128. "could not create station entry!\n");
  129. return -1;
  130. }
  131. if (!priv->ap_11n_enabled)
  132. break;
  133. mwifiex_set_sta_ht_cap(priv, sinfo.assoc_req_ies,
  134. sinfo.assoc_req_ies_len, node);
  135. for (i = 0; i < MAX_NUM_TID; i++) {
  136. if (node->is_11n_enabled)
  137. node->ampdu_sta[i] =
  138. priv->aggr_prio_tbl[i].ampdu_user;
  139. else
  140. node->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
  141. }
  142. memset(node->rx_seq, 0xff, sizeof(node->rx_seq));
  143. break;
  144. case EVENT_UAP_STA_DEAUTH:
  145. deauth_mac = adapter->event_body +
  146. MWIFIEX_UAP_EVENT_EXTRA_HEADER;
  147. cfg80211_del_sta(priv->netdev, deauth_mac, GFP_KERNEL);
  148. if (priv->ap_11n_enabled) {
  149. mwifiex_11n_del_rx_reorder_tbl_by_ta(priv, deauth_mac);
  150. mwifiex_del_tx_ba_stream_tbl_by_ra(priv, deauth_mac);
  151. }
  152. mwifiex_wmm_del_peer_ra_list(priv, deauth_mac);
  153. mwifiex_del_sta_entry(priv, deauth_mac);
  154. break;
  155. case EVENT_UAP_BSS_IDLE:
  156. priv->media_connected = false;
  157. priv->port_open = false;
  158. mwifiex_clean_txrx(priv);
  159. mwifiex_del_all_sta_list(priv);
  160. break;
  161. case EVENT_UAP_BSS_ACTIVE:
  162. priv->media_connected = true;
  163. priv->port_open = true;
  164. break;
  165. case EVENT_UAP_BSS_START:
  166. mwifiex_dbg(adapter, EVENT,
  167. "AP EVENT: event id: %#x\n", eventcause);
  168. priv->port_open = false;
  169. memcpy(priv->netdev->dev_addr, adapter->event_body + 2,
  170. ETH_ALEN);
  171. if (priv->hist_data)
  172. mwifiex_hist_data_reset(priv);
  173. mwifiex_check_uap_capabilties(priv, adapter->event_skb);
  174. break;
  175. case EVENT_UAP_MIC_COUNTERMEASURES:
  176. /* For future development */
  177. mwifiex_dbg(adapter, EVENT,
  178. "AP EVENT: event id: %#x\n", eventcause);
  179. break;
  180. case EVENT_AMSDU_AGGR_CTRL:
  181. ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
  182. mwifiex_dbg(adapter, EVENT,
  183. "event: AMSDU_AGGR_CTRL %d\n", ctrl);
  184. if (priv->media_connected) {
  185. adapter->tx_buf_size =
  186. min_t(u16, adapter->curr_tx_buf_size, ctrl);
  187. mwifiex_dbg(adapter, EVENT,
  188. "event: tx_buf_size %d\n",
  189. adapter->tx_buf_size);
  190. }
  191. break;
  192. case EVENT_ADDBA:
  193. mwifiex_dbg(adapter, EVENT, "event: ADDBA Request\n");
  194. if (priv->media_connected)
  195. mwifiex_send_cmd(priv, HostCmd_CMD_11N_ADDBA_RSP,
  196. HostCmd_ACT_GEN_SET, 0,
  197. adapter->event_body, false);
  198. break;
  199. case EVENT_DELBA:
  200. mwifiex_dbg(adapter, EVENT, "event: DELBA Request\n");
  201. if (priv->media_connected)
  202. mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
  203. break;
  204. case EVENT_BA_STREAM_TIEMOUT:
  205. mwifiex_dbg(adapter, EVENT, "event: BA Stream timeout\n");
  206. if (priv->media_connected) {
  207. ba_timeout = (void *)adapter->event_body;
  208. mwifiex_11n_ba_stream_timeout(priv, ba_timeout);
  209. }
  210. break;
  211. case EVENT_EXT_SCAN_REPORT:
  212. mwifiex_dbg(adapter, EVENT, "event: EXT_SCAN Report\n");
  213. if (adapter->ext_scan)
  214. return mwifiex_handle_event_ext_scan_report(priv,
  215. adapter->event_skb->data);
  216. break;
  217. case EVENT_TX_STATUS_REPORT:
  218. mwifiex_dbg(adapter, EVENT, "event: TX_STATUS Report\n");
  219. mwifiex_parse_tx_status_event(priv, adapter->event_body);
  220. break;
  221. case EVENT_PS_SLEEP:
  222. mwifiex_dbg(adapter, EVENT, "info: EVENT: SLEEP\n");
  223. adapter->ps_state = PS_STATE_PRE_SLEEP;
  224. mwifiex_check_ps_cond(adapter);
  225. break;
  226. case EVENT_PS_AWAKE:
  227. mwifiex_dbg(adapter, EVENT, "info: EVENT: AWAKE\n");
  228. if (!adapter->pps_uapsd_mode &&
  229. priv->media_connected && adapter->sleep_period.period) {
  230. adapter->pps_uapsd_mode = true;
  231. mwifiex_dbg(adapter, EVENT,
  232. "event: PPS/UAPSD mode activated\n");
  233. }
  234. adapter->tx_lock_flag = false;
  235. if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
  236. if (mwifiex_check_last_packet_indication(priv)) {
  237. if (adapter->data_sent ||
  238. (adapter->if_ops.is_port_ready &&
  239. !adapter->if_ops.is_port_ready(priv))) {
  240. adapter->ps_state = PS_STATE_AWAKE;
  241. adapter->pm_wakeup_card_req = false;
  242. adapter->pm_wakeup_fw_try = false;
  243. break;
  244. }
  245. if (!mwifiex_send_null_packet
  246. (priv,
  247. MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
  248. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
  249. adapter->ps_state =
  250. PS_STATE_SLEEP;
  251. return 0;
  252. }
  253. }
  254. adapter->ps_state = PS_STATE_AWAKE;
  255. adapter->pm_wakeup_card_req = false;
  256. adapter->pm_wakeup_fw_try = false;
  257. break;
  258. case EVENT_CHANNEL_REPORT_RDY:
  259. mwifiex_dbg(adapter, EVENT, "event: Channel Report\n");
  260. mwifiex_11h_handle_chanrpt_ready(priv, adapter->event_skb);
  261. break;
  262. case EVENT_RADAR_DETECTED:
  263. mwifiex_dbg(adapter, EVENT, "event: Radar detected\n");
  264. mwifiex_11h_handle_radar_detected(priv, adapter->event_skb);
  265. break;
  266. case EVENT_BT_COEX_WLAN_PARA_CHANGE:
  267. dev_err(adapter->dev, "EVENT: BT coex wlan param update\n");
  268. mwifiex_bt_coex_wlan_param_update_event(priv,
  269. adapter->event_skb);
  270. break;
  271. case EVENT_TX_DATA_PAUSE:
  272. mwifiex_dbg(adapter, EVENT, "event: TX DATA PAUSE\n");
  273. mwifiex_process_tx_pause_event(priv, adapter->event_skb);
  274. break;
  275. case EVENT_MULTI_CHAN_INFO:
  276. mwifiex_dbg(adapter, EVENT, "event: multi-chan info\n");
  277. mwifiex_process_multi_chan_event(priv, adapter->event_skb);
  278. break;
  279. default:
  280. mwifiex_dbg(adapter, EVENT,
  281. "event: unknown event id: %#x\n", eventcause);
  282. break;
  283. }
  284. return 0;
  285. }
  286. /* This function deletes station entry from associated station list.
  287. * Also if both AP and STA are 11n enabled, RxReorder tables and TxBA stream
  288. * tables created for this station are deleted.
  289. */
  290. void mwifiex_uap_del_sta_data(struct mwifiex_private *priv,
  291. struct mwifiex_sta_node *node)
  292. {
  293. if (priv->ap_11n_enabled && node->is_11n_enabled) {
  294. mwifiex_11n_del_rx_reorder_tbl_by_ta(priv, node->mac_addr);
  295. mwifiex_del_tx_ba_stream_tbl_by_ra(priv, node->mac_addr);
  296. }
  297. mwifiex_del_sta_entry(priv, node->mac_addr);
  298. return;
  299. }