uap_event.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. /*
  22. * This function will return the pointer to station entry in station list
  23. * table which matches specified mac address.
  24. * This function should be called after acquiring RA list spinlock.
  25. * NULL is returned if station entry is not found in associated STA list.
  26. */
  27. struct mwifiex_sta_node *
  28. mwifiex_get_sta_entry(struct mwifiex_private *priv, u8 *mac)
  29. {
  30. struct mwifiex_sta_node *node;
  31. if (!mac)
  32. return NULL;
  33. list_for_each_entry(node, &priv->sta_list, list) {
  34. if (!memcmp(node->mac_addr, mac, ETH_ALEN))
  35. return node;
  36. }
  37. return NULL;
  38. }
  39. /*
  40. * This function will add a sta_node entry to associated station list
  41. * table with the given mac address.
  42. * If entry exist already, existing entry is returned.
  43. * If received mac address is NULL, NULL is returned.
  44. */
  45. static struct mwifiex_sta_node *
  46. mwifiex_add_sta_entry(struct mwifiex_private *priv, u8 *mac)
  47. {
  48. struct mwifiex_sta_node *node;
  49. unsigned long flags;
  50. if (!mac)
  51. return NULL;
  52. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  53. node = mwifiex_get_sta_entry(priv, mac);
  54. if (node)
  55. goto done;
  56. node = kzalloc(sizeof(struct mwifiex_sta_node), GFP_KERNEL);
  57. if (!node)
  58. goto done;
  59. memcpy(node->mac_addr, mac, ETH_ALEN);
  60. list_add_tail(&node->list, &priv->sta_list);
  61. done:
  62. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  63. return node;
  64. }
  65. /*
  66. * This function will search for HT IE in association request IEs
  67. * and set station HT parameters accordingly.
  68. */
  69. static void
  70. mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies,
  71. int ies_len, struct mwifiex_sta_node *node)
  72. {
  73. const struct ieee80211_ht_cap *ht_cap;
  74. if (!ies)
  75. return;
  76. ht_cap = (void *)cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
  77. if (ht_cap) {
  78. node->is_11n_enabled = 1;
  79. node->max_amsdu = le16_to_cpu(ht_cap->cap_info) &
  80. IEEE80211_HT_CAP_MAX_AMSDU ?
  81. MWIFIEX_TX_DATA_BUF_SIZE_8K :
  82. MWIFIEX_TX_DATA_BUF_SIZE_4K;
  83. } else {
  84. node->is_11n_enabled = 0;
  85. }
  86. return;
  87. }
  88. /*
  89. * This function will delete a station entry from station list
  90. */
  91. static void mwifiex_del_sta_entry(struct mwifiex_private *priv, u8 *mac)
  92. {
  93. struct mwifiex_sta_node *node, *tmp;
  94. unsigned long flags;
  95. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  96. node = mwifiex_get_sta_entry(priv, mac);
  97. if (node) {
  98. list_for_each_entry_safe(node, tmp, &priv->sta_list,
  99. list) {
  100. list_del(&node->list);
  101. kfree(node);
  102. }
  103. }
  104. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  105. return;
  106. }
  107. /*
  108. * This function will delete all stations from associated station list.
  109. */
  110. static void mwifiex_del_all_sta_list(struct mwifiex_private *priv)
  111. {
  112. struct mwifiex_sta_node *node, *tmp;
  113. unsigned long flags;
  114. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  115. list_for_each_entry_safe(node, tmp, &priv->sta_list, list) {
  116. list_del(&node->list);
  117. kfree(node);
  118. }
  119. INIT_LIST_HEAD(&priv->sta_list);
  120. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  121. return;
  122. }
  123. /*
  124. * This function handles AP interface specific events generated by firmware.
  125. *
  126. * Event specific routines are called by this function based
  127. * upon the generated event cause.
  128. *
  129. *
  130. * Events supported for AP -
  131. * - EVENT_UAP_STA_ASSOC
  132. * - EVENT_UAP_STA_DEAUTH
  133. * - EVENT_UAP_BSS_ACTIVE
  134. * - EVENT_UAP_BSS_START
  135. * - EVENT_UAP_BSS_IDLE
  136. * - EVENT_UAP_MIC_COUNTERMEASURES:
  137. */
  138. int mwifiex_process_uap_event(struct mwifiex_private *priv)
  139. {
  140. struct mwifiex_adapter *adapter = priv->adapter;
  141. int len, i;
  142. u32 eventcause = adapter->event_cause;
  143. struct station_info sinfo;
  144. struct mwifiex_assoc_event *event;
  145. struct mwifiex_sta_node *node;
  146. u8 *deauth_mac;
  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. mwifiex_del_sta_entry(priv, deauth_mac);
  196. break;
  197. case EVENT_UAP_BSS_IDLE:
  198. priv->media_connected = false;
  199. mwifiex_del_all_sta_list(priv);
  200. break;
  201. case EVENT_UAP_BSS_ACTIVE:
  202. priv->media_connected = true;
  203. break;
  204. case EVENT_UAP_BSS_START:
  205. dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
  206. memcpy(priv->netdev->dev_addr, adapter->event_body + 2,
  207. ETH_ALEN);
  208. break;
  209. case EVENT_UAP_MIC_COUNTERMEASURES:
  210. /* For future development */
  211. dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
  212. break;
  213. default:
  214. dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
  215. eventcause);
  216. break;
  217. }
  218. return 0;
  219. }