1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
15 #define _RTW_STA_MGT_C_
17 #include <osdep_service.h>
18 #include <drv_types.h>
19 #include <recv_osdep.h>
20 #include <xmit_osdep.h>
21 #include <mlme_osdep.h>
23 #include <linux/vmalloc.h>
25 static void _rtw_init_stainfo(struct sta_info *psta)
27 memset((u8 *)psta, 0, sizeof(struct sta_info));
29 spin_lock_init(&psta->lock);
30 INIT_LIST_HEAD(&psta->list);
31 INIT_LIST_HEAD(&psta->hash_list);
32 _rtw_init_queue(&psta->sleep_q);
35 _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
36 _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
38 #ifdef CONFIG_88EU_AP_MODE
40 INIT_LIST_HEAD(&psta->asoc_list);
42 INIT_LIST_HEAD(&psta->auth_list);
50 psta->bpairwise_key_installed = false;
53 psta->no_short_slot_time_set = 0;
54 psta->no_short_preamble_set = 0;
55 psta->no_ht_gf_set = 0;
57 psta->ht_20mhz_set = 0;
59 psta->under_exist_checking = 0;
61 psta->keep_alive_trycnt = 0;
63 #endif /* CONFIG_88EU_AP_MODE */
66 u32 _rtw_init_sta_priv(struct sta_priv *pstapriv)
68 struct sta_info *psta;
71 pstapriv->pallocated_stainfo_buf = vzalloc(sizeof(struct sta_info) * NUM_STA + 4);
73 if (!pstapriv->pallocated_stainfo_buf)
76 pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 -
77 ((size_t)(pstapriv->pallocated_stainfo_buf) & 3);
79 _rtw_init_queue(&pstapriv->free_sta_queue);
81 spin_lock_init(&pstapriv->sta_hash_lock);
83 pstapriv->asoc_sta_count = 0;
84 _rtw_init_queue(&pstapriv->sleep_q);
85 _rtw_init_queue(&pstapriv->wakeup_q);
87 psta = (struct sta_info *)(pstapriv->pstainfo_buf);
89 for (i = 0; i < NUM_STA; i++) {
90 _rtw_init_stainfo(psta);
92 INIT_LIST_HEAD(&(pstapriv->sta_hash[i]));
94 list_add_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue));
99 #ifdef CONFIG_88EU_AP_MODE
101 pstapriv->sta_dz_bitmap = 0;
102 pstapriv->tim_bitmap = 0;
104 INIT_LIST_HEAD(&pstapriv->asoc_list);
105 INIT_LIST_HEAD(&pstapriv->auth_list);
106 spin_lock_init(&pstapriv->asoc_list_lock);
107 spin_lock_init(&pstapriv->auth_list_lock);
108 pstapriv->asoc_list_cnt = 0;
109 pstapriv->auth_list_cnt = 0;
111 pstapriv->auth_to = 3; /* 3*2 = 6 sec */
112 pstapriv->assoc_to = 3;
113 pstapriv->expire_to = 3; /* 3*2 = 6 sec */
114 pstapriv->max_num_sta = NUM_STA;
120 inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)
122 int offset = (((u8 *)sta) - stapriv->pstainfo_buf)/sizeof(struct sta_info);
124 if (!stainfo_offset_valid(offset))
125 DBG_88E("%s invalid offset(%d), out of range!!!", __func__, offset);
130 inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)
132 if (!stainfo_offset_valid(offset))
133 DBG_88E("%s invalid offset(%d), out of range!!!", __func__, offset);
135 return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));
138 u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)
140 struct list_head *phead, *plist;
141 struct sta_info *psta = NULL;
142 struct recv_reorder_ctrl *preorder_ctrl;
146 /* delete all reordering_ctrl_timer */
147 spin_lock_bh(&pstapriv->sta_hash_lock);
148 for (index = 0; index < NUM_STA; index++) {
149 phead = &(pstapriv->sta_hash[index]);
152 while (phead != plist) {
155 psta = container_of(plist, struct sta_info,
159 for (i = 0; i < 16; i++) {
160 preorder_ctrl = &psta->recvreorder_ctrl[i];
161 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
165 spin_unlock_bh(&pstapriv->sta_hash_lock);
166 /*===============================*/
168 vfree(pstapriv->pallocated_stainfo_buf);
174 struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
177 struct list_head *phash_list;
178 struct sta_info *psta;
179 struct __queue *pfree_sta_queue;
180 struct recv_reorder_ctrl *preorder_ctrl;
182 u16 wRxSeqInitialValue = 0xffff;
184 pfree_sta_queue = &pstapriv->free_sta_queue;
186 spin_lock_bh(&pfree_sta_queue->lock);
187 psta = list_first_entry_or_null(&pfree_sta_queue->queue,
188 struct sta_info, list);
190 spin_unlock_bh(&pfree_sta_queue->lock);
192 list_del_init(&psta->list);
193 spin_unlock_bh(&pfree_sta_queue->lock);
194 _rtw_init_stainfo(psta);
195 memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
196 index = wifi_mac_hash(hwaddr);
197 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_info_, ("rtw_alloc_stainfo: index=%x", index));
198 if (index >= NUM_STA) {
199 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("ERROR => rtw_alloc_stainfo: index >= NUM_STA"));
203 phash_list = &pstapriv->sta_hash[index];
205 spin_lock_bh(&pstapriv->sta_hash_lock);
206 list_add_tail(&psta->hash_list, phash_list);
207 pstapriv->asoc_sta_count++;
208 spin_unlock_bh(&pstapriv->sta_hash_lock);
210 /* Commented by Albert 2009/08/13 */
211 /* For the SMC router, the sequence number of first packet of WPS handshake will be 0. */
212 /* In this case, this packet will be dropped by recv_decache function if we use the 0x00 as the default value for tid_rxseq variable. */
213 /* So, we initialize the tid_rxseq variable as the 0xffff. */
215 for (i = 0; i < 16; i++)
216 memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], &wRxSeqInitialValue, 2);
218 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_info_,
219 ("alloc number_%d stainfo with hwaddr = %pM\n",
220 pstapriv->asoc_sta_count, hwaddr));
222 init_addba_retry_timer(pstapriv->padapter, psta);
224 /* for A-MPDU Rx reordering buffer control */
225 for (i = 0; i < 16; i++) {
226 preorder_ctrl = &psta->recvreorder_ctrl[i];
228 preorder_ctrl->padapter = pstapriv->padapter;
230 preorder_ctrl->enable = false;
232 preorder_ctrl->indicate_seq = 0xffff;
233 preorder_ctrl->wend_b = 0xffff;
234 preorder_ctrl->wsize_b = 64;/* 64; */
236 _rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);
238 rtw_init_recv_timer(preorder_ctrl);
242 psta->rssi_stat.UndecoratedSmoothedPWDB = (-1);
243 psta->rssi_stat.UndecoratedSmoothedCCK = (-1);
245 /* init for the sequence number of received management frame */
246 psta->RxMgmtFrameSeqNum = 0xffff;
253 /* using pstapriv->sta_hash_lock to protect */
254 u32 rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
257 struct __queue *pfree_sta_queue;
258 struct recv_reorder_ctrl *preorder_ctrl;
259 struct sta_xmit_priv *pstaxmitpriv;
260 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
261 struct sta_priv *pstapriv = &padapter->stapriv;
266 pfree_sta_queue = &pstapriv->free_sta_queue;
268 pstaxmitpriv = &psta->sta_xmitpriv;
270 spin_lock_bh(&pxmitpriv->lock);
272 rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);
273 psta->sleepq_len = 0;
275 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
277 list_del_init(&(pstaxmitpriv->vo_q.tx_pending));
279 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
281 list_del_init(&(pstaxmitpriv->vi_q.tx_pending));
283 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
285 list_del_init(&(pstaxmitpriv->bk_q.tx_pending));
287 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
289 list_del_init(&(pstaxmitpriv->be_q.tx_pending));
291 spin_unlock_bh(&pxmitpriv->lock);
293 list_del_init(&psta->hash_list);
294 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_,
295 ("\n free number_%d stainfo with hwaddr=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
296 pstapriv->asoc_sta_count, psta->hwaddr[0], psta->hwaddr[1],
297 psta->hwaddr[2], psta->hwaddr[3], psta->hwaddr[4],
299 pstapriv->asoc_sta_count--;
301 /* re-init sta_info; 20061114 */
302 _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
303 _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
305 del_timer_sync(&psta->addba_retry_timer);
307 /* for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer */
308 for (i = 0; i < 16; i++) {
309 struct list_head *phead, *plist;
310 struct recv_frame *prframe;
311 struct __queue *ppending_recvframe_queue;
312 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
314 preorder_ctrl = &psta->recvreorder_ctrl[i];
316 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
318 ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
320 spin_lock_bh(&ppending_recvframe_queue->lock);
322 phead = get_list_head(ppending_recvframe_queue);
325 while (!list_empty(phead)) {
326 prframe = container_of(plist, struct recv_frame, list);
330 list_del_init(&(prframe->list));
332 rtw_free_recvframe(prframe, pfree_recv_queue);
335 spin_unlock_bh(&ppending_recvframe_queue->lock);
338 if (!(psta->state & WIFI_AP_STATE))
339 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, false);
341 #ifdef CONFIG_88EU_AP_MODE
343 spin_lock_bh(&pstapriv->auth_list_lock);
344 if (!list_empty(&psta->auth_list)) {
345 list_del_init(&psta->auth_list);
346 pstapriv->auth_list_cnt--;
348 spin_unlock_bh(&pstapriv->auth_list_lock);
352 psta->sleepq_ac_len = 0;
355 psta->max_sp_len = 0;
360 psta->has_legacy_ac = 0;
362 pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
363 pstapriv->tim_bitmap &= ~BIT(psta->aid);
365 if ((psta->aid > 0) && (pstapriv->sta_aid[psta->aid - 1] == psta)) {
366 pstapriv->sta_aid[psta->aid - 1] = NULL;
370 psta->under_exist_checking = 0;
372 #endif /* CONFIG_88EU_AP_MODE */
374 spin_lock_bh(&(pfree_sta_queue->lock));
375 list_add_tail(&psta->list, get_list_head(pfree_sta_queue));
376 spin_unlock_bh(&pfree_sta_queue->lock);
383 /* free all stainfo which in sta_hash[all] */
384 void rtw_free_all_stainfo(struct adapter *padapter)
386 struct list_head *plist, *phead;
388 struct sta_info *psta = NULL;
389 struct sta_priv *pstapriv = &padapter->stapriv;
390 struct sta_info *pbcmc_stainfo = rtw_get_bcmc_stainfo(padapter);
392 if (pstapriv->asoc_sta_count == 1)
395 spin_lock_bh(&pstapriv->sta_hash_lock);
397 for (index = 0; index < NUM_STA; index++) {
398 phead = &(pstapriv->sta_hash[index]);
401 while (phead != plist) {
402 psta = container_of(plist, struct sta_info, hash_list);
406 if (pbcmc_stainfo != psta)
407 rtw_free_stainfo(padapter, psta);
410 spin_unlock_bh(&pstapriv->sta_hash_lock);
413 /* any station allocated can be searched by hash list */
414 struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
416 struct list_head *plist, *phead;
417 struct sta_info *psta = NULL;
420 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
425 if (IS_MCAST(hwaddr))
430 index = wifi_mac_hash(addr);
432 spin_lock_bh(&pstapriv->sta_hash_lock);
434 phead = &(pstapriv->sta_hash[index]);
437 while (phead != plist) {
438 psta = container_of(plist, struct sta_info, hash_list);
440 if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
441 /* if found the matched address */
448 spin_unlock_bh(&pstapriv->sta_hash_lock);
452 u32 rtw_init_bcmc_stainfo(struct adapter *padapter)
454 struct sta_info *psta;
456 unsigned char bcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
457 struct sta_priv *pstapriv = &padapter->stapriv;
459 psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
463 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("rtw_alloc_stainfo fail"));
467 /* default broadcast & multicast use macid 1 */
474 struct sta_info *rtw_get_bcmc_stainfo(struct adapter *padapter)
476 struct sta_priv *pstapriv = &padapter->stapriv;
477 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
478 return rtw_get_stainfo(pstapriv, bc_addr);
481 u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
484 #ifdef CONFIG_88EU_AP_MODE
485 struct list_head *plist, *phead;
486 struct rtw_wlan_acl_node *paclnode;
488 struct sta_priv *pstapriv = &padapter->stapriv;
489 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
490 struct __queue *pacl_node_q = &pacl_list->acl_node_q;
492 spin_lock_bh(&(pacl_node_q->lock));
493 phead = get_list_head(pacl_node_q);
495 while (phead != plist) {
496 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
499 if (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
500 if (paclnode->valid) {
506 spin_unlock_bh(&pacl_node_q->lock);
508 if (pacl_list->mode == 1)/* accept unless in deny list */
509 res = (match) ? false : true;
510 else if (pacl_list->mode == 2)/* deny unless in accept list */
511 res = (match) ? true : false;