uap_event.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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, *tmp;
  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_for_each_entry_safe(node, tmp, &priv->sta_list,
  100. list) {
  101. list_del(&node->list);
  102. kfree(node);
  103. }
  104. }
  105. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  106. return;
  107. }
  108. /*
  109. * This function will delete all stations from associated station list.
  110. */
  111. static void mwifiex_del_all_sta_list(struct mwifiex_private *priv)
  112. {
  113. struct mwifiex_sta_node *node, *tmp;
  114. unsigned long flags;
  115. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  116. list_for_each_entry_safe(node, tmp, &priv->sta_list, list) {
  117. list_del(&node->list);
  118. kfree(node);
  119. }
  120. INIT_LIST_HEAD(&priv->sta_list);
  121. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  122. return;
  123. }
  124. /*
  125. * This function handles AP interface specific events generated by firmware.
  126. *
  127. * Event specific routines are called by this function based
  128. * upon the generated event cause.
  129. *
  130. *
  131. * Events supported for AP -
  132. * - EVENT_UAP_STA_ASSOC
  133. * - EVENT_UAP_STA_DEAUTH
  134. * - EVENT_UAP_BSS_ACTIVE
  135. * - EVENT_UAP_BSS_START
  136. * - EVENT_UAP_BSS_IDLE
  137. * - EVENT_UAP_MIC_COUNTERMEASURES:
  138. */
  139. int mwifiex_process_uap_event(struct mwifiex_private *priv)
  140. {
  141. struct mwifiex_adapter *adapter = priv->adapter;
  142. int len, i;
  143. u32 eventcause = adapter->event_cause;
  144. struct station_info sinfo;
  145. struct mwifiex_assoc_event *event;
  146. struct mwifiex_sta_node *node;
  147. u8 *deauth_mac;
  148. struct host_cmd_ds_11n_batimeout *ba_timeout;
  149. u16 ctrl;
  150. switch (eventcause) {
  151. case EVENT_UAP_STA_ASSOC:
  152. memset(&sinfo, 0, sizeof(sinfo));
  153. event = (struct mwifiex_assoc_event *)
  154. (adapter->event_body + MWIFIEX_UAP_EVENT_EXTRA_HEADER);
  155. if (le16_to_cpu(event->type) == TLV_TYPE_UAP_MGMT_FRAME) {
  156. len = -1;
  157. if (ieee80211_is_assoc_req(event->frame_control))
  158. len = 0;
  159. else if (ieee80211_is_reassoc_req(event->frame_control))
  160. /* There will be ETH_ALEN bytes of
  161. * current_ap_addr before the re-assoc ies.
  162. */
  163. len = ETH_ALEN;
  164. if (len != -1) {
  165. sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
  166. sinfo.assoc_req_ies = &event->data[len];
  167. len = (u8 *)sinfo.assoc_req_ies -
  168. (u8 *)&event->frame_control;
  169. sinfo.assoc_req_ies_len =
  170. le16_to_cpu(event->len) - (u16)len;
  171. }
  172. }
  173. cfg80211_new_sta(priv->netdev, event->sta_addr, &sinfo,
  174. GFP_KERNEL);
  175. node = mwifiex_add_sta_entry(priv, event->sta_addr);
  176. if (!node) {
  177. dev_warn(adapter->dev,
  178. "could not create station entry!\n");
  179. return -1;
  180. }
  181. if (!priv->ap_11n_enabled)
  182. break;
  183. mwifiex_set_sta_ht_cap(priv, sinfo.assoc_req_ies,
  184. sinfo.assoc_req_ies_len, node);
  185. for (i = 0; i < MAX_NUM_TID; i++) {
  186. if (node->is_11n_enabled)
  187. node->ampdu_sta[i] =
  188. priv->aggr_prio_tbl[i].ampdu_user;
  189. else
  190. node->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
  191. }
  192. memset(node->rx_seq, 0xff, sizeof(node->rx_seq));
  193. break;
  194. case EVENT_UAP_STA_DEAUTH:
  195. deauth_mac = adapter->event_body +
  196. MWIFIEX_UAP_EVENT_EXTRA_HEADER;
  197. cfg80211_del_sta(priv->netdev, deauth_mac, GFP_KERNEL);
  198. if (priv->ap_11n_enabled) {
  199. mwifiex_11n_del_rx_reorder_tbl_by_ta(priv, deauth_mac);
  200. mwifiex_del_tx_ba_stream_tbl_by_ra(priv, deauth_mac);
  201. }
  202. mwifiex_del_sta_entry(priv, deauth_mac);
  203. break;
  204. case EVENT_UAP_BSS_IDLE:
  205. priv->media_connected = false;
  206. if (netif_carrier_ok(priv->netdev))
  207. netif_carrier_off(priv->netdev);
  208. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  209. mwifiex_clean_txrx(priv);
  210. mwifiex_del_all_sta_list(priv);
  211. break;
  212. case EVENT_UAP_BSS_ACTIVE:
  213. priv->media_connected = true;
  214. if (!netif_carrier_ok(priv->netdev))
  215. netif_carrier_on(priv->netdev);
  216. mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
  217. break;
  218. case EVENT_UAP_BSS_START:
  219. dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
  220. memcpy(priv->netdev->dev_addr, adapter->event_body + 2,
  221. ETH_ALEN);
  222. break;
  223. case EVENT_UAP_MIC_COUNTERMEASURES:
  224. /* For future development */
  225. dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
  226. break;
  227. case EVENT_AMSDU_AGGR_CTRL:
  228. ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
  229. dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
  230. if (priv->media_connected) {
  231. adapter->tx_buf_size =
  232. min_t(u16, adapter->curr_tx_buf_size, ctrl);
  233. dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
  234. adapter->tx_buf_size);
  235. }
  236. break;
  237. case EVENT_ADDBA:
  238. dev_dbg(adapter->dev, "event: ADDBA Request\n");
  239. if (priv->media_connected)
  240. mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP,
  241. HostCmd_ACT_GEN_SET, 0,
  242. adapter->event_body);
  243. break;
  244. case EVENT_DELBA:
  245. dev_dbg(adapter->dev, "event: DELBA Request\n");
  246. if (priv->media_connected)
  247. mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
  248. break;
  249. case EVENT_BA_STREAM_TIEMOUT:
  250. dev_dbg(adapter->dev, "event: BA Stream timeout\n");
  251. if (priv->media_connected) {
  252. ba_timeout = (void *)adapter->event_body;
  253. mwifiex_11n_ba_stream_timeout(priv, ba_timeout);
  254. }
  255. break;
  256. default:
  257. dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
  258. eventcause);
  259. break;
  260. }
  261. return 0;
  262. }