blob: 6ae8cdc1bfd1c5320f8f3ecdc2f20e4df47dfedf [file] [log] [blame]
Larry Finger2865d422010-08-20 10:15:30 -05001/******************************************************************************
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
29#define _RTL871X_STA_MGT_C_
30
31#include "osdep_service.h"
32#include "drv_types.h"
33#include "recv_osdep.h"
34#include "xmit_osdep.h"
35#include "sta_info.h"
36
37static void _init_stainfo(struct sta_info *psta)
38{
39 memset((u8 *)psta, 0, sizeof(struct sta_info));
40 spin_lock_init(&psta->lock);
James A Shackleford534c4ac2014-06-24 22:52:34 -040041 INIT_LIST_HEAD(&psta->list);
42 INIT_LIST_HEAD(&psta->hash_list);
Larry Finger2865d422010-08-20 10:15:30 -050043 _r8712_init_sta_xmit_priv(&psta->sta_xmitpriv);
44 _r8712_init_sta_recv_priv(&psta->sta_recvpriv);
James A Shackleford534c4ac2014-06-24 22:52:34 -040045 INIT_LIST_HEAD(&psta->asoc_list);
46 INIT_LIST_HEAD(&psta->auth_list);
Larry Finger2865d422010-08-20 10:15:30 -050047}
48
49u32 _r8712_init_sta_priv(struct sta_priv *pstapriv)
50{
51 struct sta_info *psta;
52 s32 i;
53
Vitaly Osipov91d435f2014-05-24 18:19:27 +100054 pstapriv->pallocated_stainfo_buf = kmalloc(sizeof(struct sta_info) *
55 NUM_STA + 4, GFP_ATOMIC);
Larry Finger2865d422010-08-20 10:15:30 -050056 if (pstapriv->pallocated_stainfo_buf == NULL)
57 return _FAIL;
58 pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 -
59 ((addr_t)(pstapriv->pallocated_stainfo_buf) & 3);
60 _init_queue(&pstapriv->free_sta_queue);
61 spin_lock_init(&pstapriv->sta_hash_lock);
62 pstapriv->asoc_sta_count = 0;
63 _init_queue(&pstapriv->sleep_q);
64 _init_queue(&pstapriv->wakeup_q);
65 psta = (struct sta_info *)(pstapriv->pstainfo_buf);
66 for (i = 0; i < NUM_STA; i++) {
67 _init_stainfo(psta);
James A Shackleford534c4ac2014-06-24 22:52:34 -040068 INIT_LIST_HEAD(&(pstapriv->sta_hash[i]));
James A Shackleforde99a4282014-06-24 22:52:39 -040069 list_add_tail(&psta->list, &pstapriv->free_sta_queue.queue);
Larry Finger2865d422010-08-20 10:15:30 -050070 psta++;
71 }
James A Shackleford534c4ac2014-06-24 22:52:34 -040072 INIT_LIST_HEAD(&pstapriv->asoc_list);
73 INIT_LIST_HEAD(&pstapriv->auth_list);
Larry Finger2865d422010-08-20 10:15:30 -050074 return _SUCCESS;
75}
76
77/* this function is used to free the memory of lock || sema for all stainfos */
78static void mfree_all_stainfo(struct sta_priv *pstapriv)
79{
80 unsigned long irqL;
81 struct list_head *plist, *phead;
Larry Finger2865d422010-08-20 10:15:30 -050082
83 spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
James A Shackleforde99a4282014-06-24 22:52:39 -040084 phead = &pstapriv->free_sta_queue.queue;
James A Shackleford849fb0a2014-06-24 22:52:38 -040085 plist = phead->next;
Paul Hedman3002b1a2014-12-02 20:34:13 -060086 while ((end_of_queue_search(phead, plist)) == false)
James A Shackleford849fb0a2014-06-24 22:52:38 -040087 plist = plist->next;
Larry Finger2865d422010-08-20 10:15:30 -050088
89 spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
90}
91
92
93static void mfree_sta_priv_lock(struct sta_priv *pstapriv)
94{
95 mfree_all_stainfo(pstapriv); /* be done before free sta_hash_lock */
96}
97
98u32 _r8712_free_sta_priv(struct sta_priv *pstapriv)
99{
100 if (pstapriv) {
101 mfree_sta_priv_lock(pstapriv);
102 kfree(pstapriv->pallocated_stainfo_buf);
103 }
104 return _SUCCESS;
105}
106
107struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
108{
Larry Finger2865d422010-08-20 10:15:30 -0500109 s32 index;
110 struct list_head *phash_list;
111 struct sta_info *psta;
112 struct __queue *pfree_sta_queue;
113 struct recv_reorder_ctrl *preorder_ctrl;
114 int i = 0;
115 u16 wRxSeqInitialValue = 0xffff;
116 unsigned long flags;
117
118 pfree_sta_queue = &pstapriv->free_sta_queue;
119 spin_lock_irqsave(&(pfree_sta_queue->lock), flags);
James A Shackleforddf353f62014-06-24 22:52:40 -0400120 if (list_empty(&pfree_sta_queue->queue))
Larry Finger2865d422010-08-20 10:15:30 -0500121 psta = NULL;
122 else {
James A Shackleford849fb0a2014-06-24 22:52:38 -0400123 psta = LIST_CONTAINOR(pfree_sta_queue->queue.next,
Larry Finger2865d422010-08-20 10:15:30 -0500124 struct sta_info, list);
James A Shackleford29197b72014-06-24 22:52:37 -0400125 list_del_init(&(psta->list));
Larry Finger2865d422010-08-20 10:15:30 -0500126 _init_stainfo(psta);
127 memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
128 index = wifi_mac_hash(hwaddr);
129 if (index >= NUM_STA) {
130 psta = NULL;
131 goto exit;
132 }
133 phash_list = &(pstapriv->sta_hash[index]);
James A Shacklefordfdfbf782014-06-24 22:52:36 -0400134 list_add_tail(&psta->hash_list, phash_list);
Thomas Cort77e73e82013-10-01 11:26:55 -0400135 pstapriv->asoc_sta_count++;
Larry Finger2865d422010-08-20 10:15:30 -0500136
137/* For the SMC router, the sequence number of first packet of WPS handshake
138 * will be 0. In this case, this packet will be dropped by recv_decache function
139 * if we use the 0x00 as the default value for tid_rxseq variable. So, we
140 * initialize the tid_rxseq variable as the 0xffff.
141 */
142 for (i = 0; i < 16; i++)
143 memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i],
144 &wRxSeqInitialValue, 2);
145 /* for A-MPDU Rx reordering buffer control */
Thomas Cort77e73e82013-10-01 11:26:55 -0400146 for (i = 0; i < 16; i++) {
Larry Finger2865d422010-08-20 10:15:30 -0500147 preorder_ctrl = &psta->recvreorder_ctrl[i];
148 preorder_ctrl->padapter = pstapriv->padapter;
149 preorder_ctrl->indicate_seq = 0xffff;
150 preorder_ctrl->wend_b = 0xffff;
151 preorder_ctrl->wsize_b = 64;
152 _init_queue(&preorder_ctrl->pending_recvframe_queue);
153 r8712_init_recv_timer(preorder_ctrl);
154 }
155 }
156exit:
157 spin_unlock_irqrestore(&(pfree_sta_queue->lock), flags);
158 return psta;
159}
160
161/* using pstapriv->sta_hash_lock to protect */
162void r8712_free_stainfo(struct _adapter *padapter, struct sta_info *psta)
163{
164 int i;
165 unsigned long irqL0;
166 struct __queue *pfree_sta_queue;
167 struct recv_reorder_ctrl *preorder_ctrl;
168 struct sta_xmit_priv *pstaxmitpriv;
169 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
170 struct sta_priv *pstapriv = &padapter->stapriv;
171
172 if (psta == NULL)
173 return;
174 pfree_sta_queue = &pstapriv->free_sta_queue;
175 pstaxmitpriv = &psta->sta_xmitpriv;
176 spin_lock_irqsave(&(pxmitpriv->vo_pending.lock), irqL0);
177 r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
James A Shackleford29197b72014-06-24 22:52:37 -0400178 list_del_init(&(pstaxmitpriv->vo_q.tx_pending));
Larry Finger2865d422010-08-20 10:15:30 -0500179 spin_unlock_irqrestore(&(pxmitpriv->vo_pending.lock), irqL0);
180 spin_lock_irqsave(&(pxmitpriv->vi_pending.lock), irqL0);
181 r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
James A Shackleford29197b72014-06-24 22:52:37 -0400182 list_del_init(&(pstaxmitpriv->vi_q.tx_pending));
Larry Finger2865d422010-08-20 10:15:30 -0500183 spin_unlock_irqrestore(&(pxmitpriv->vi_pending.lock), irqL0);
184 spin_lock_irqsave(&(pxmitpriv->bk_pending.lock), irqL0);
185 r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
James A Shackleford29197b72014-06-24 22:52:37 -0400186 list_del_init(&(pstaxmitpriv->bk_q.tx_pending));
Larry Finger2865d422010-08-20 10:15:30 -0500187 spin_unlock_irqrestore(&(pxmitpriv->bk_pending.lock), irqL0);
188 spin_lock_irqsave(&(pxmitpriv->be_pending.lock), irqL0);
189 r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
James A Shackleford29197b72014-06-24 22:52:37 -0400190 list_del_init(&(pstaxmitpriv->be_q.tx_pending));
Larry Finger2865d422010-08-20 10:15:30 -0500191 spin_unlock_irqrestore(&(pxmitpriv->be_pending.lock), irqL0);
James A Shackleford29197b72014-06-24 22:52:37 -0400192 list_del_init(&psta->hash_list);
Larry Finger2865d422010-08-20 10:15:30 -0500193 pstapriv->asoc_sta_count--;
194 /* re-init sta_info; 20061114 */
195 _r8712_init_sta_xmit_priv(&psta->sta_xmitpriv);
196 _r8712_init_sta_recv_priv(&psta->sta_recvpriv);
197 /* for A-MPDU Rx reordering buffer control,
198 * cancel reordering_ctrl_timer */
199 for (i = 0; i < 16; i++) {
200 preorder_ctrl = &psta->recvreorder_ctrl[i];
Sudip Mukherjeea1471eb2015-05-15 14:49:39 +0530201 del_timer(&preorder_ctrl->reordering_ctrl_timer);
Larry Finger2865d422010-08-20 10:15:30 -0500202 }
203 spin_lock(&(pfree_sta_queue->lock));
204 /* insert into free_sta_queue; 20061114 */
James A Shackleforde99a4282014-06-24 22:52:39 -0400205 list_add_tail(&psta->list, &pfree_sta_queue->queue);
Larry Finger2865d422010-08-20 10:15:30 -0500206 spin_unlock(&(pfree_sta_queue->lock));
207}
208
209/* free all stainfo which in sta_hash[all] */
210void r8712_free_all_stainfo(struct _adapter *padapter)
211{
212 unsigned long irqL;
213 struct list_head *plist, *phead;
214 s32 index;
215 struct sta_info *psta = NULL;
216 struct sta_priv *pstapriv = &padapter->stapriv;
217 struct sta_info *pbcmc_stainfo = r8712_get_bcmc_stainfo(padapter);
218
219 if (pstapriv->asoc_sta_count == 1)
220 return;
221 spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
222 for (index = 0; index < NUM_STA; index++) {
223 phead = &(pstapriv->sta_hash[index]);
James A Shackleford849fb0a2014-06-24 22:52:38 -0400224 plist = phead->next;
Larry Finger2865d422010-08-20 10:15:30 -0500225 while ((end_of_queue_search(phead, plist)) == false) {
226 psta = LIST_CONTAINOR(plist,
227 struct sta_info, hash_list);
James A Shackleford849fb0a2014-06-24 22:52:38 -0400228 plist = plist->next;
Larry Finger2865d422010-08-20 10:15:30 -0500229 if (pbcmc_stainfo != psta)
Max Perepelitsyn0636b462015-01-02 14:08:08 +0600230 r8712_free_stainfo(padapter, psta);
Larry Finger2865d422010-08-20 10:15:30 -0500231 }
232 }
233 spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
234}
235
236/* any station allocated can be searched by hash list */
237struct sta_info *r8712_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
238{
239 unsigned long irqL;
240 struct list_head *plist, *phead;
241 struct sta_info *psta = NULL;
242 u32 index;
243
244 if (hwaddr == NULL)
245 return NULL;
246 index = wifi_mac_hash(hwaddr);
247 spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
248 phead = &(pstapriv->sta_hash[index]);
James A Shackleford849fb0a2014-06-24 22:52:38 -0400249 plist = phead->next;
Larry Finger2865d422010-08-20 10:15:30 -0500250 while ((end_of_queue_search(phead, plist)) == false) {
251 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
252 if ((!memcmp(psta->hwaddr, hwaddr, ETH_ALEN))) {
253 /* if found the matched address */
254 break;
255 }
256 psta = NULL;
James A Shackleford849fb0a2014-06-24 22:52:38 -0400257 plist = plist->next;
Larry Finger2865d422010-08-20 10:15:30 -0500258 }
259 spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
260 return psta;
261}
262
263void r8712_init_bcmc_stainfo(struct _adapter *padapter)
264{
Larry Finger2865d422010-08-20 10:15:30 -0500265 unsigned char bcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
266 struct sta_priv *pstapriv = &padapter->stapriv;
267
Sudip Mukherjeee29d3eb2014-10-27 17:42:25 +0530268 r8712_alloc_stainfo(pstapriv, bcast_addr);
Larry Finger2865d422010-08-20 10:15:30 -0500269}
270
271struct sta_info *r8712_get_bcmc_stainfo(struct _adapter *padapter)
272{
Larry Finger2865d422010-08-20 10:15:30 -0500273 struct sta_priv *pstapriv = &padapter->stapriv;
274 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
275
Prasanna Karthik05871f92015-06-04 04:48:51 +0000276 return r8712_get_stainfo(pstapriv, bc_addr);
Larry Finger2865d422010-08-20 10:15:30 -0500277}
278
279
280u8 r8712_access_ctrl(struct wlan_acl_pool *pacl_list, u8 *mac_addr)
281{
282 return true;
283}