uap_event.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Marvell Wireless LAN device driver: AP event handling
  3. *
  4. * Copyright (C) 2012, 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. /*
  23. * This function will return the pointer to station entry in station list
  24. * table which matches specified mac address.
  25. * This function should be called after acquiring RA list spinlock.
  26. * NULL is returned if station entry is not found in associated STA list.
  27. */
  28. struct mwifiex_sta_node *
  29. mwifiex_get_sta_entry(struct mwifiex_private *priv, u8 *mac)
  30. {
  31. struct mwifiex_sta_node *node;
  32. if (!mac)
  33. return NULL;
  34. list_for_each_entry(node, &priv->sta_list, list) {
  35. if (!memcmp(node->mac_addr, mac, ETH_ALEN))
  36. return node;
  37. }
  38. return NULL;
  39. }
  40. /*
  41. * This function will add a sta_node entry to associated station list
  42. * table with the given mac address.
  43. * If entry exist already, existing entry is returned.
  44. * If received mac address is NULL, NULL is returned.
  45. */
  46. static struct mwifiex_sta_node *
  47. mwifiex_add_sta_entry(struct mwifiex_private *priv, u8 *mac)
  48. {
  49. struct mwifiex_sta_node *node;
  50. unsigned long flags;
  51. if (!mac)
  52. return NULL;
  53. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  54. node = mwifiex_get_sta_entry(priv, mac);
  55. if (node)
  56. goto done;
  57. node = kzalloc(sizeof(struct mwifiex_sta_node), GFP_ATOMIC);
  58. if (!node)
  59. goto done;
  60. memcpy(node->mac_addr, mac, ETH_ALEN);
  61. list_add_tail(&node->list, &priv->sta_list);
  62. done:
  63. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  64. return node;
  65. }
  66. /*
  67. * This function will search for HT IE in association request IEs
  68. * and set station HT parameters accordingly.
  69. */
  70. static void
  71. mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies,
  72. int ies_len, struct mwifiex_sta_node *node)
  73. {
  74. const struct ieee80211_ht_cap *ht_cap;
  75. if (!ies)
  76. return;
  77. ht_cap = (void *)cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
  78. if (ht_cap) {
  79. node->is_11n_enabled = 1;
  80. node->max_amsdu = le16_to_cpu(ht_cap->cap_info) &
  81. IEEE80211_HT_CAP_MAX_AMSDU ?
  82. MWIFIEX_TX_DATA_BUF_SIZE_8K :
  83. MWIFIEX_TX_DATA_BUF_SIZE_4K;
  84. } else {
  85. node->is_11n_enabled = 0;
  86. }
  87. return;
  88. }
  89. /*
  90. * This function will delete a station entry from station list
  91. */
  92. static void mwifiex_del_sta_entry(struct mwifiex_private *priv, u8 *mac)
  93. {
  94. struct mwifiex_sta_node *node;
  95. unsigned long flags;
  96. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  97. node = mwifiex_get_sta_entry(priv, mac);
  98. if (node) {
  99. list_del(&node->list);
  100. kfree(node);
  101. }
  102. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  103. return;
  104. }
  105. /*
  106. * This function will delete all stations from associated station list.
  107. */
  108. static void mwifiex_del_all_sta_list(struct mwifiex_private *priv)
  109. {
  110. struct mwifiex_sta_node *node, *tmp;
  111. unsigned long flags;
  112. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  113. list_for_each_entry_safe(node, tmp, &priv->sta_list, list) {
  114. list_del(&node->list);
  115. kfree(node);
  116. }
  117. INIT_LIST_HEAD(&priv->sta_list);
  118. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  119. return;
  120. }
  121. /*
  122. * This function handles AP interface specific events generated by firmware.
  123. *
  124. * Event specific routines are called by this function based
  125. * upon the generated event cause.
  126. *
  127. *
  128. * Events supported for AP -
  129. * - EVENT_UAP_STA_ASSOC
  130. * - EVENT_UAP_STA_DEAUTH
  131. * - EVENT_UAP_BSS_ACTIVE
  132. * - EVENT_UAP_BSS_START
  133. * - EVENT_UAP_BSS_IDLE
  134. * - EVENT_UAP_MIC_COUNTERMEASURES:
  135. */
  136. int mwifiex_process_uap_event(struct mwifiex_private *priv)
  137. {
  138. struct mwifiex_adapter *adapter = priv->adapter;
  139. int len, i;
  140. u32 eventcause = adapter->event_cause;
  141. struct station_info sinfo;
  142. struct mwifiex_assoc_event *event;
  143. struct mwifiex_sta_node *node;
  144. u8 *deauth_mac;
  145. struct host_cmd_ds_11n_batimeout *ba_timeout;
  146. u16 ctrl;
  147. switch (eventcause) {
  148. case EVENT_UAP_STA_ASSOC:
  149. memset(&sinfo, 0, sizeof(sinfo));
  150. event = (struct mwifiex_assoc_event *)
  151. (adapter->event_body + MWIFIEX_UAP_EVENT_EXTRA_HEADER);
  152. if (le16_to_cpu(event->type) == TLV_TYPE_UAP_MGMT_FRAME) {
  153. len = -1;
  154. if (ieee80211_is_assoc_req(event->frame_control))
  155. len = 0;
  156. else if (ieee80211_is_reassoc_req(event->frame_control))
  157. /* There will be ETH_ALEN bytes of
  158. * current_ap_addr before the re-assoc ies.
  159. */
  160. len = ETH_ALEN;
  161. if (len != -1) {
  162. sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
  163. sinfo.assoc_req_ies = &event->data[len];
  164. len = (u8 *)sinfo.assoc_req_ies -
  165. (u8 *)&event->frame_control;
  166. sinfo.assoc_req_ies_len =
  167. le16_to_cpu(event->len) - (u16)len;
  168. }
  169. }
  170. cfg80211_new_sta(priv->netdev, event->sta_addr, &sinfo,
  171. GFP_KERNEL);
  172. node = mwifiex_add_sta_entry(priv, event->sta_addr);
  173. if (!node) {
  174. dev_warn(adapter->dev,
  175. "could not create station entry!\n");
  176. return -1;
  177. }
  178. if (!priv->ap_11n_enabled)
  179. break;
  180. mwifiex_set_sta_ht_cap(priv, sinfo.assoc_req_ies,
  181. sinfo.assoc_req_ies_len, node);
  182. for (i = 0; i < MAX_NUM_TID; i++) {
  183. if (node->is_11n_enabled)
  184. node->ampdu_sta[i] =
  185. priv->aggr_prio_tbl[i].ampdu_user;
  186. else
  187. node->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
  188. }
  189. memset(node->rx_seq, 0xff, sizeof(node->rx_seq));
  190. break;
  191. case EVENT_UAP_STA_DEAUTH:
  192. deauth_mac = adapter->event_body +
  193. MWIFIEX_UAP_EVENT_EXTRA_HEADER;
  194. cfg80211_del_sta(priv->netdev, deauth_mac, GFP_KERNEL);
  195. if (priv->ap_11n_enabled) {
  196. mwifiex_11n_del_rx_reorder_tbl_by_ta(priv, deauth_mac);
  197. mwifiex_del_tx_ba_stream_tbl_by_ra(priv, deauth_mac);
  198. }
  199. mwifiex_del_sta_entry(priv, deauth_mac);
  200. break;
  201. case EVENT_UAP_BSS_IDLE:
  202. priv->media_connected = false;
  203. if (netif_carrier_ok(priv->netdev))
  204. netif_carrier_off(priv->netdev);
  205. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  206. mwifiex_clean_txrx(priv);
  207. mwifiex_del_all_sta_list(priv);
  208. break;
  209. case EVENT_UAP_BSS_ACTIVE:
  210. priv->media_connected = true;
  211. if (!netif_carrier_ok(priv->netdev))
  212. netif_carrier_on(priv->netdev);
  213. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  214. break;
  215. case EVENT_UAP_BSS_START:
  216. dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
  217. memcpy(priv->netdev->dev_addr, adapter->event_body + 2,
  218. ETH_ALEN);
  219. break;
  220. case EVENT_UAP_MIC_COUNTERMEASURES:
  221. /* For future development */
  222. dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
  223. break;
  224. case EVENT_AMSDU_AGGR_CTRL:
  225. ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
  226. dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
  227. if (priv->media_connected) {
  228. adapter->tx_buf_size =
  229. min_t(u16, adapter->curr_tx_buf_size, ctrl);
  230. dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
  231. adapter->tx_buf_size);
  232. }
  233. break;
  234. case EVENT_ADDBA:
  235. dev_dbg(adapter->dev, "event: ADDBA Request\n");
  236. if (priv->media_connected)
  237. mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP,
  238. HostCmd_ACT_GEN_SET, 0,
  239. adapter->event_body);
  240. break;
  241. case EVENT_DELBA:
  242. dev_dbg(adapter->dev, "event: DELBA Request\n");
  243. if (priv->media_connected)
  244. mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
  245. break;
  246. case EVENT_BA_STREAM_TIEMOUT:
  247. dev_dbg(adapter->dev, "event: BA Stream timeout\n");
  248. if (priv->media_connected) {
  249. ba_timeout = (void *)adapter->event_body;
  250. mwifiex_11n_ba_stream_timeout(priv, ba_timeout);
  251. }
  252. break;
  253. default:
  254. dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
  255. eventcause);
  256. break;
  257. }
  258. return 0;
  259. }
  260. /* This function deletes station entry from associated station list.
  261. * Also if both AP and STA are 11n enabled, RxReorder tables and TxBA stream
  262. * tables created for this station are deleted.
  263. */
  264. void mwifiex_uap_del_sta_data(struct mwifiex_private *priv,
  265. struct mwifiex_sta_node *node)
  266. {
  267. if (priv->ap_11n_enabled && node->is_11n_enabled) {
  268. mwifiex_11n_del_rx_reorder_tbl_by_ta(priv, node->mac_addr);
  269. mwifiex_del_tx_ba_stream_tbl_by_ra(priv, node->mac_addr);
  270. }
  271. mwifiex_del_sta_entry(priv, node->mac_addr);
  272. return;
  273. }