uap_event.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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_capabilities(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 capabilities:",
  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. sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
  104. if (!sinfo)
  105. return -ENOMEM;
  106. event = (struct mwifiex_assoc_event *)
  107. (adapter->event_body + MWIFIEX_UAP_EVENT_EXTRA_HEADER);
  108. if (le16_to_cpu(event->type) == TLV_TYPE_UAP_MGMT_FRAME) {
  109. len = -1;
  110. if (ieee80211_is_assoc_req(event->frame_control))
  111. len = 0;
  112. else if (ieee80211_is_reassoc_req(event->frame_control))
  113. /* There will be ETH_ALEN bytes of
  114. * current_ap_addr before the re-assoc ies.
  115. */
  116. len = ETH_ALEN;
  117. if (len != -1) {
  118. sinfo->assoc_req_ies = &event->data[len];
  119. len = (u8 *)sinfo->assoc_req_ies -
  120. (u8 *)&event->frame_control;
  121. sinfo->assoc_req_ies_len =
  122. le16_to_cpu(event->len) - (u16)len;
  123. }
  124. }
  125. cfg80211_new_sta(priv->netdev, event->sta_addr, sinfo,
  126. GFP_KERNEL);
  127. node = mwifiex_add_sta_entry(priv, event->sta_addr);
  128. if (!node) {
  129. mwifiex_dbg(adapter, ERROR,
  130. "could not create station entry!\n");
  131. kfree(sinfo);
  132. return -1;
  133. }
  134. if (!priv->ap_11n_enabled) {
  135. kfree(sinfo);
  136. break;
  137. }
  138. mwifiex_set_sta_ht_cap(priv, sinfo->assoc_req_ies,
  139. sinfo->assoc_req_ies_len, node);
  140. for (i = 0; i < MAX_NUM_TID; i++) {
  141. if (node->is_11n_enabled)
  142. node->ampdu_sta[i] =
  143. priv->aggr_prio_tbl[i].ampdu_user;
  144. else
  145. node->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
  146. }
  147. memset(node->rx_seq, 0xff, sizeof(node->rx_seq));
  148. kfree(sinfo);
  149. break;
  150. case EVENT_UAP_STA_DEAUTH:
  151. deauth_mac = adapter->event_body +
  152. MWIFIEX_UAP_EVENT_EXTRA_HEADER;
  153. cfg80211_del_sta(priv->netdev, deauth_mac, GFP_KERNEL);
  154. if (priv->ap_11n_enabled) {
  155. mwifiex_11n_del_rx_reorder_tbl_by_ta(priv, deauth_mac);
  156. mwifiex_del_tx_ba_stream_tbl_by_ra(priv, deauth_mac);
  157. }
  158. mwifiex_wmm_del_peer_ra_list(priv, deauth_mac);
  159. mwifiex_del_sta_entry(priv, deauth_mac);
  160. break;
  161. case EVENT_UAP_BSS_IDLE:
  162. priv->media_connected = false;
  163. priv->port_open = false;
  164. mwifiex_clean_txrx(priv);
  165. mwifiex_del_all_sta_list(priv);
  166. break;
  167. case EVENT_UAP_BSS_ACTIVE:
  168. priv->media_connected = true;
  169. priv->port_open = true;
  170. break;
  171. case EVENT_UAP_BSS_START:
  172. mwifiex_dbg(adapter, EVENT,
  173. "AP EVENT: event id: %#x\n", eventcause);
  174. priv->port_open = false;
  175. memcpy(priv->netdev->dev_addr, adapter->event_body + 2,
  176. ETH_ALEN);
  177. if (priv->hist_data)
  178. mwifiex_hist_data_reset(priv);
  179. mwifiex_check_uap_capabilities(priv, adapter->event_skb);
  180. break;
  181. case EVENT_UAP_MIC_COUNTERMEASURES:
  182. /* For future development */
  183. mwifiex_dbg(adapter, EVENT,
  184. "AP EVENT: event id: %#x\n", eventcause);
  185. break;
  186. case EVENT_AMSDU_AGGR_CTRL:
  187. ctrl = get_unaligned_le16(adapter->event_body);
  188. mwifiex_dbg(adapter, EVENT,
  189. "event: AMSDU_AGGR_CTRL %d\n", ctrl);
  190. if (priv->media_connected) {
  191. adapter->tx_buf_size =
  192. min_t(u16, adapter->curr_tx_buf_size, ctrl);
  193. mwifiex_dbg(adapter, EVENT,
  194. "event: tx_buf_size %d\n",
  195. adapter->tx_buf_size);
  196. }
  197. break;
  198. case EVENT_ADDBA:
  199. mwifiex_dbg(adapter, EVENT, "event: ADDBA Request\n");
  200. if (priv->media_connected)
  201. mwifiex_send_cmd(priv, HostCmd_CMD_11N_ADDBA_RSP,
  202. HostCmd_ACT_GEN_SET, 0,
  203. adapter->event_body, false);
  204. break;
  205. case EVENT_DELBA:
  206. mwifiex_dbg(adapter, EVENT, "event: DELBA Request\n");
  207. if (priv->media_connected)
  208. mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
  209. break;
  210. case EVENT_BA_STREAM_TIEMOUT:
  211. mwifiex_dbg(adapter, EVENT, "event: BA Stream timeout\n");
  212. if (priv->media_connected) {
  213. ba_timeout = (void *)adapter->event_body;
  214. mwifiex_11n_ba_stream_timeout(priv, ba_timeout);
  215. }
  216. break;
  217. case EVENT_EXT_SCAN_REPORT:
  218. mwifiex_dbg(adapter, EVENT, "event: EXT_SCAN Report\n");
  219. if (adapter->ext_scan)
  220. return mwifiex_handle_event_ext_scan_report(priv,
  221. adapter->event_skb->data);
  222. break;
  223. case EVENT_TX_STATUS_REPORT:
  224. mwifiex_dbg(adapter, EVENT, "event: TX_STATUS Report\n");
  225. mwifiex_parse_tx_status_event(priv, adapter->event_body);
  226. break;
  227. case EVENT_PS_SLEEP:
  228. mwifiex_dbg(adapter, EVENT, "info: EVENT: SLEEP\n");
  229. adapter->ps_state = PS_STATE_PRE_SLEEP;
  230. mwifiex_check_ps_cond(adapter);
  231. break;
  232. case EVENT_PS_AWAKE:
  233. mwifiex_dbg(adapter, EVENT, "info: EVENT: AWAKE\n");
  234. if (!adapter->pps_uapsd_mode &&
  235. priv->media_connected && adapter->sleep_period.period) {
  236. adapter->pps_uapsd_mode = true;
  237. mwifiex_dbg(adapter, EVENT,
  238. "event: PPS/UAPSD mode activated\n");
  239. }
  240. adapter->tx_lock_flag = false;
  241. if (adapter->pps_uapsd_mode && adapter->gen_null_pkt) {
  242. if (mwifiex_check_last_packet_indication(priv)) {
  243. if (adapter->data_sent ||
  244. (adapter->if_ops.is_port_ready &&
  245. !adapter->if_ops.is_port_ready(priv))) {
  246. adapter->ps_state = PS_STATE_AWAKE;
  247. adapter->pm_wakeup_card_req = false;
  248. adapter->pm_wakeup_fw_try = false;
  249. break;
  250. }
  251. if (!mwifiex_send_null_packet
  252. (priv,
  253. MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
  254. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET))
  255. adapter->ps_state =
  256. PS_STATE_SLEEP;
  257. return 0;
  258. }
  259. }
  260. adapter->ps_state = PS_STATE_AWAKE;
  261. adapter->pm_wakeup_card_req = false;
  262. adapter->pm_wakeup_fw_try = false;
  263. break;
  264. case EVENT_CHANNEL_REPORT_RDY:
  265. mwifiex_dbg(adapter, EVENT, "event: Channel Report\n");
  266. mwifiex_11h_handle_chanrpt_ready(priv, adapter->event_skb);
  267. break;
  268. case EVENT_RADAR_DETECTED:
  269. mwifiex_dbg(adapter, EVENT, "event: Radar detected\n");
  270. mwifiex_11h_handle_radar_detected(priv, adapter->event_skb);
  271. break;
  272. case EVENT_BT_COEX_WLAN_PARA_CHANGE:
  273. mwifiex_dbg(adapter, EVENT, "event: BT coex wlan param update\n");
  274. mwifiex_bt_coex_wlan_param_update_event(priv,
  275. adapter->event_skb);
  276. break;
  277. case EVENT_TX_DATA_PAUSE:
  278. mwifiex_dbg(adapter, EVENT, "event: TX DATA PAUSE\n");
  279. mwifiex_process_tx_pause_event(priv, adapter->event_skb);
  280. break;
  281. case EVENT_MULTI_CHAN_INFO:
  282. mwifiex_dbg(adapter, EVENT, "event: multi-chan info\n");
  283. mwifiex_process_multi_chan_event(priv, adapter->event_skb);
  284. break;
  285. case EVENT_RXBA_SYNC:
  286. dev_dbg(adapter->dev, "EVENT: RXBA_SYNC\n");
  287. mwifiex_11n_rxba_sync_event(priv, adapter->event_body,
  288. adapter->event_skb->len -
  289. sizeof(eventcause));
  290. break;
  291. case EVENT_REMAIN_ON_CHAN_EXPIRED:
  292. mwifiex_dbg(adapter, EVENT,
  293. "event: uap: Remain on channel expired\n");
  294. cfg80211_remain_on_channel_expired(&priv->wdev,
  295. priv->roc_cfg.cookie,
  296. &priv->roc_cfg.chan,
  297. GFP_ATOMIC);
  298. memset(&priv->roc_cfg, 0x00, sizeof(struct mwifiex_roc_cfg));
  299. break;
  300. default:
  301. mwifiex_dbg(adapter, EVENT,
  302. "event: unknown event id: %#x\n", eventcause);
  303. break;
  304. }
  305. return 0;
  306. }
  307. /* This function deletes station entry from associated station list.
  308. * Also if both AP and STA are 11n enabled, RxReorder tables and TxBA stream
  309. * tables created for this station are deleted.
  310. */
  311. void mwifiex_uap_del_sta_data(struct mwifiex_private *priv,
  312. struct mwifiex_sta_node *node)
  313. {
  314. if (priv->ap_11n_enabled && node->is_11n_enabled) {
  315. mwifiex_11n_del_rx_reorder_tbl_by_ta(priv, node->mac_addr);
  316. mwifiex_del_tx_ba_stream_tbl_by_ra(priv, node->mac_addr);
  317. }
  318. mwifiex_del_sta_entry(priv, node->mac_addr);
  319. return;
  320. }