rtl871x_sta_mgt.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /******************************************************************************
  2. * rtl871x_sta_mgt.c
  3. *
  4. * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
  5. * Linux device driver for RTL8192SU
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  19. *
  20. * Modifications for inclusion into the Linux staging tree are
  21. * Copyright(c) 2010 Larry Finger. All rights reserved.
  22. *
  23. * Contact information:
  24. * WLAN FAE <wlanfae@realtek.com>
  25. * Larry Finger <Larry.Finger@lwfinger.net>
  26. *
  27. ******************************************************************************/
  28. #define _RTL871X_STA_MGT_C_
  29. #include "osdep_service.h"
  30. #include "drv_types.h"
  31. #include "recv_osdep.h"
  32. #include "xmit_osdep.h"
  33. #include "sta_info.h"
  34. static void _init_stainfo(struct sta_info *psta)
  35. {
  36. memset((u8 *)psta, 0, sizeof(struct sta_info));
  37. spin_lock_init(&psta->lock);
  38. INIT_LIST_HEAD(&psta->list);
  39. INIT_LIST_HEAD(&psta->hash_list);
  40. _r8712_init_sta_xmit_priv(&psta->sta_xmitpriv);
  41. _r8712_init_sta_recv_priv(&psta->sta_recvpriv);
  42. INIT_LIST_HEAD(&psta->asoc_list);
  43. INIT_LIST_HEAD(&psta->auth_list);
  44. }
  45. u32 _r8712_init_sta_priv(struct sta_priv *pstapriv)
  46. {
  47. struct sta_info *psta;
  48. s32 i;
  49. pstapriv->pallocated_stainfo_buf = kmalloc(sizeof(struct sta_info) *
  50. NUM_STA + 4, GFP_ATOMIC);
  51. if (pstapriv->pallocated_stainfo_buf == NULL)
  52. return _FAIL;
  53. pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 -
  54. ((addr_t)(pstapriv->pallocated_stainfo_buf) & 3);
  55. _init_queue(&pstapriv->free_sta_queue);
  56. spin_lock_init(&pstapriv->sta_hash_lock);
  57. pstapriv->asoc_sta_count = 0;
  58. _init_queue(&pstapriv->sleep_q);
  59. _init_queue(&pstapriv->wakeup_q);
  60. psta = (struct sta_info *)(pstapriv->pstainfo_buf);
  61. for (i = 0; i < NUM_STA; i++) {
  62. _init_stainfo(psta);
  63. INIT_LIST_HEAD(&(pstapriv->sta_hash[i]));
  64. list_add_tail(&psta->list, &pstapriv->free_sta_queue.queue);
  65. psta++;
  66. }
  67. INIT_LIST_HEAD(&pstapriv->asoc_list);
  68. INIT_LIST_HEAD(&pstapriv->auth_list);
  69. return _SUCCESS;
  70. }
  71. /* this function is used to free the memory of lock || sema for all stainfos */
  72. static void mfree_all_stainfo(struct sta_priv *pstapriv)
  73. {
  74. unsigned long irqL;
  75. struct list_head *plist, *phead;
  76. spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
  77. phead = &pstapriv->free_sta_queue.queue;
  78. plist = phead->next;
  79. while (!end_of_queue_search(phead, plist))
  80. plist = plist->next;
  81. spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
  82. }
  83. static void mfree_sta_priv_lock(struct sta_priv *pstapriv)
  84. {
  85. mfree_all_stainfo(pstapriv); /* be done before free sta_hash_lock */
  86. }
  87. u32 _r8712_free_sta_priv(struct sta_priv *pstapriv)
  88. {
  89. if (pstapriv) {
  90. mfree_sta_priv_lock(pstapriv);
  91. kfree(pstapriv->pallocated_stainfo_buf);
  92. }
  93. return _SUCCESS;
  94. }
  95. struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
  96. {
  97. s32 index;
  98. struct list_head *phash_list;
  99. struct sta_info *psta;
  100. struct __queue *pfree_sta_queue;
  101. struct recv_reorder_ctrl *preorder_ctrl;
  102. int i = 0;
  103. u16 wRxSeqInitialValue = 0xffff;
  104. unsigned long flags;
  105. pfree_sta_queue = &pstapriv->free_sta_queue;
  106. spin_lock_irqsave(&(pfree_sta_queue->lock), flags);
  107. if (list_empty(&pfree_sta_queue->queue)) {
  108. psta = NULL;
  109. } else {
  110. psta = LIST_CONTAINOR(pfree_sta_queue->queue.next,
  111. struct sta_info, list);
  112. list_del_init(&(psta->list));
  113. _init_stainfo(psta);
  114. memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
  115. index = wifi_mac_hash(hwaddr);
  116. if (index >= NUM_STA) {
  117. psta = NULL;
  118. goto exit;
  119. }
  120. phash_list = &(pstapriv->sta_hash[index]);
  121. list_add_tail(&psta->hash_list, phash_list);
  122. pstapriv->asoc_sta_count++;
  123. /* For the SMC router, the sequence number of first packet of WPS handshake
  124. * will be 0. In this case, this packet will be dropped by recv_decache function
  125. * if we use the 0x00 as the default value for tid_rxseq variable. So, we
  126. * initialize the tid_rxseq variable as the 0xffff.
  127. */
  128. for (i = 0; i < 16; i++)
  129. memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i],
  130. &wRxSeqInitialValue, 2);
  131. /* for A-MPDU Rx reordering buffer control */
  132. for (i = 0; i < 16; i++) {
  133. preorder_ctrl = &psta->recvreorder_ctrl[i];
  134. preorder_ctrl->padapter = pstapriv->padapter;
  135. preorder_ctrl->indicate_seq = 0xffff;
  136. preorder_ctrl->wend_b = 0xffff;
  137. preorder_ctrl->wsize_b = 64;
  138. _init_queue(&preorder_ctrl->pending_recvframe_queue);
  139. r8712_init_recv_timer(preorder_ctrl);
  140. }
  141. }
  142. exit:
  143. spin_unlock_irqrestore(&(pfree_sta_queue->lock), flags);
  144. return psta;
  145. }
  146. /* using pstapriv->sta_hash_lock to protect */
  147. void r8712_free_stainfo(struct _adapter *padapter, struct sta_info *psta)
  148. {
  149. int i;
  150. unsigned long irqL0;
  151. struct __queue *pfree_sta_queue;
  152. struct recv_reorder_ctrl *preorder_ctrl;
  153. struct sta_xmit_priv *pstaxmitpriv;
  154. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  155. struct sta_priv *pstapriv = &padapter->stapriv;
  156. if (psta == NULL)
  157. return;
  158. pfree_sta_queue = &pstapriv->free_sta_queue;
  159. pstaxmitpriv = &psta->sta_xmitpriv;
  160. spin_lock_irqsave(&(pxmitpriv->vo_pending.lock), irqL0);
  161. r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
  162. list_del_init(&(pstaxmitpriv->vo_q.tx_pending));
  163. spin_unlock_irqrestore(&(pxmitpriv->vo_pending.lock), irqL0);
  164. spin_lock_irqsave(&(pxmitpriv->vi_pending.lock), irqL0);
  165. r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
  166. list_del_init(&(pstaxmitpriv->vi_q.tx_pending));
  167. spin_unlock_irqrestore(&(pxmitpriv->vi_pending.lock), irqL0);
  168. spin_lock_irqsave(&(pxmitpriv->bk_pending.lock), irqL0);
  169. r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
  170. list_del_init(&(pstaxmitpriv->bk_q.tx_pending));
  171. spin_unlock_irqrestore(&(pxmitpriv->bk_pending.lock), irqL0);
  172. spin_lock_irqsave(&(pxmitpriv->be_pending.lock), irqL0);
  173. r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
  174. list_del_init(&(pstaxmitpriv->be_q.tx_pending));
  175. spin_unlock_irqrestore(&(pxmitpriv->be_pending.lock), irqL0);
  176. list_del_init(&psta->hash_list);
  177. pstapriv->asoc_sta_count--;
  178. /* re-init sta_info; 20061114 */
  179. _r8712_init_sta_xmit_priv(&psta->sta_xmitpriv);
  180. _r8712_init_sta_recv_priv(&psta->sta_recvpriv);
  181. /* for A-MPDU Rx reordering buffer control,
  182. * cancel reordering_ctrl_timer */
  183. for (i = 0; i < 16; i++) {
  184. preorder_ctrl = &psta->recvreorder_ctrl[i];
  185. del_timer(&preorder_ctrl->reordering_ctrl_timer);
  186. }
  187. spin_lock(&(pfree_sta_queue->lock));
  188. /* insert into free_sta_queue; 20061114 */
  189. list_add_tail(&psta->list, &pfree_sta_queue->queue);
  190. spin_unlock(&(pfree_sta_queue->lock));
  191. }
  192. /* free all stainfo which in sta_hash[all] */
  193. void r8712_free_all_stainfo(struct _adapter *padapter)
  194. {
  195. unsigned long irqL;
  196. struct list_head *plist, *phead;
  197. s32 index;
  198. struct sta_info *psta = NULL;
  199. struct sta_priv *pstapriv = &padapter->stapriv;
  200. struct sta_info *pbcmc_stainfo = r8712_get_bcmc_stainfo(padapter);
  201. if (pstapriv->asoc_sta_count == 1)
  202. return;
  203. spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
  204. for (index = 0; index < NUM_STA; index++) {
  205. phead = &(pstapriv->sta_hash[index]);
  206. plist = phead->next;
  207. while (!end_of_queue_search(phead, plist)) {
  208. psta = LIST_CONTAINOR(plist,
  209. struct sta_info, hash_list);
  210. plist = plist->next;
  211. if (pbcmc_stainfo != psta)
  212. r8712_free_stainfo(padapter, psta);
  213. }
  214. }
  215. spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
  216. }
  217. /* any station allocated can be searched by hash list */
  218. struct sta_info *r8712_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
  219. {
  220. unsigned long irqL;
  221. struct list_head *plist, *phead;
  222. struct sta_info *psta = NULL;
  223. u32 index;
  224. if (hwaddr == NULL)
  225. return NULL;
  226. index = wifi_mac_hash(hwaddr);
  227. spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
  228. phead = &(pstapriv->sta_hash[index]);
  229. plist = phead->next;
  230. while (!end_of_queue_search(phead, plist)) {
  231. psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
  232. if ((!memcmp(psta->hwaddr, hwaddr, ETH_ALEN))) {
  233. /* if found the matched address */
  234. break;
  235. }
  236. psta = NULL;
  237. plist = plist->next;
  238. }
  239. spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
  240. return psta;
  241. }
  242. void r8712_init_bcmc_stainfo(struct _adapter *padapter)
  243. {
  244. unsigned char bcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  245. struct sta_priv *pstapriv = &padapter->stapriv;
  246. r8712_alloc_stainfo(pstapriv, bcast_addr);
  247. }
  248. struct sta_info *r8712_get_bcmc_stainfo(struct _adapter *padapter)
  249. {
  250. struct sta_priv *pstapriv = &padapter->stapriv;
  251. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  252. return r8712_get_stainfo(pstapriv, bc_addr);
  253. }
  254. u8 r8712_access_ctrl(struct wlan_acl_pool *pacl_list, u8 *mac_addr)
  255. {
  256. return true;
  257. }