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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #define _RTW_STA_MGT_C_
22 #include <drv_types.h>
24 #if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
26 #error "Shall be Linux or Windows, but not both!\n"
31 bool test_st_match_rule(_adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port)
33 if (ntohs(*((u16 *)local_port)) == 5001 || ntohs(*((u16 *)remote_port)) == 5001)
38 struct st_register test_st_reg = {
40 .rule = test_st_match_rule,
43 inline void rtw_st_ctl_init(struct st_ctl_t *st_ctl)
45 _rtw_memset(st_ctl->reg, 0 , sizeof(struct st_register) * SESSION_TRACKER_REG_ID_NUM);
46 _rtw_init_queue(&st_ctl->tracker_q);
49 inline void rtw_st_ctl_clear_tracker_q(struct st_ctl_t *st_ctl)
53 struct session_tracker *st;
55 _enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);
56 phead = &st_ctl->tracker_q.queue;
57 plist = get_next(phead);
58 while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
59 st = LIST_CONTAINOR(plist, struct session_tracker, list);
60 plist = get_next(plist);
61 rtw_list_delete(&st->list);
62 rtw_mfree((u8 *)st, sizeof(struct session_tracker));
64 _exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);
67 inline void rtw_st_ctl_deinit(struct st_ctl_t *st_ctl)
69 rtw_st_ctl_clear_tracker_q(st_ctl);
70 _rtw_deinit_queue(&st_ctl->tracker_q);
73 inline void rtw_st_ctl_register(struct st_ctl_t *st_ctl, u8 st_reg_id, struct st_register *reg)
75 if (st_reg_id >= SESSION_TRACKER_REG_ID_NUM) {
80 st_ctl->reg[st_reg_id].s_proto = reg->s_proto;
81 st_ctl->reg[st_reg_id].rule = reg->rule;
84 inline void rtw_st_ctl_unregister(struct st_ctl_t *st_ctl, u8 st_reg_id)
88 if (st_reg_id >= SESSION_TRACKER_REG_ID_NUM) {
93 st_ctl->reg[st_reg_id].s_proto = 0;
94 st_ctl->reg[st_reg_id].rule = NULL;
96 /* clear tracker queue if no session trecker registered */
97 for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++)
98 if (st_ctl->reg[i].s_proto != 0)
100 if (i >= SESSION_TRACKER_REG_ID_NUM)
101 rtw_st_ctl_clear_tracker_q(st_ctl);
104 inline bool rtw_st_ctl_chk_reg_s_proto(struct st_ctl_t *st_ctl, u8 s_proto)
109 for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++) {
110 if (st_ctl->reg[i].s_proto == s_proto) {
119 inline bool rtw_st_ctl_chk_reg_rule(struct st_ctl_t *st_ctl, _adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port)
125 for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++) {
126 rule = st_ctl->reg[i].rule;
127 if (rule && rule(adapter, local_naddr, local_port, remote_naddr, remote_port) == _TRUE) {
136 #define SESSION_TRACKER_FMT IP_FMT":"PORT_FMT" "IP_FMT":"PORT_FMT" %u %d"
137 #define SESSION_TRACKER_ARG(st) IP_ARG(&(st)->local_naddr), PORT_ARG(&(st)->local_port), IP_ARG(&(st)->remote_naddr), PORT_ARG(&(st)->remote_port), (st)->status, rtw_get_passing_time_ms((st)->set_time)
139 void dump_st_ctl(void *sel, struct st_ctl_t *st_ctl)
143 _list *plist, *phead;
144 struct session_tracker *st;
146 if (!DBG_SESSION_TRACKER)
149 for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++)
150 DBG_871X_SEL_NL(sel, "reg%d: %u %p\n", i, st_ctl->reg[i].s_proto, st_ctl->reg[i].rule);
152 _enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);
153 phead = &st_ctl->tracker_q.queue;
154 plist = get_next(phead);
155 while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
156 st = LIST_CONTAINOR(plist, struct session_tracker, list);
157 plist = get_next(plist);
159 DBG_871X_SEL_NL(sel, SESSION_TRACKER_FMT"\n", SESSION_TRACKER_ARG(st));
161 _exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);
165 void _rtw_init_stainfo(struct sta_info *psta);
166 void _rtw_init_stainfo(struct sta_info *psta)
171 _rtw_memset((u8 *)psta, 0, sizeof (struct sta_info));
173 _rtw_spinlock_init(&psta->lock);
174 _rtw_init_listhead(&psta->list);
175 _rtw_init_listhead(&psta->hash_list);
176 //_rtw_init_listhead(&psta->asoc_list);
177 //_rtw_init_listhead(&psta->sleep_list);
178 //_rtw_init_listhead(&psta->wakeup_list);
180 _rtw_init_queue(&psta->sleep_q);
181 psta->sleepq_len = 0;
183 _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
184 _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
186 #ifdef CONFIG_AP_MODE
188 _rtw_init_listhead(&psta->asoc_list);
190 _rtw_init_listhead(&psta->auth_list);
196 psta->capability = 0;
198 psta->bpairwise_key_installed = _FALSE;
201 #ifdef CONFIG_NATIVEAP_MLME
202 psta->nonerp_set = 0;
203 psta->no_short_slot_time_set = 0;
204 psta->no_short_preamble_set = 0;
205 psta->no_ht_gf_set = 0;
207 psta->ht_20mhz_set = 0;
208 psta->ht_40mhz_intolerant = 0;
211 #ifdef CONFIG_TX_MCAST2UNI
212 psta->under_exist_checking = 0;
213 #endif // CONFIG_TX_MCAST2UNI
215 psta->keep_alive_trycnt = 0;
217 #endif // CONFIG_AP_MODE
219 rtw_st_ctl_init(&psta->st_ctl);
225 u32 _rtw_init_sta_priv(struct sta_priv *pstapriv)
227 struct sta_info *psta;
232 pstapriv->pallocated_stainfo_buf = rtw_zvmalloc (sizeof(struct sta_info) * NUM_STA+ 4);
234 if(!pstapriv->pallocated_stainfo_buf)
237 pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 -
238 ((SIZE_PTR)(pstapriv->pallocated_stainfo_buf ) & 3);
240 _rtw_init_queue(&pstapriv->free_sta_queue);
242 _rtw_spinlock_init(&pstapriv->sta_hash_lock);
244 //_rtw_init_queue(&pstapriv->asoc_q);
245 pstapriv->asoc_sta_count = 0;
246 _rtw_init_queue(&pstapriv->sleep_q);
247 _rtw_init_queue(&pstapriv->wakeup_q);
249 psta = (struct sta_info *)(pstapriv->pstainfo_buf);
252 for(i = 0; i < NUM_STA; i++)
254 _rtw_init_stainfo(psta);
256 _rtw_init_listhead(&(pstapriv->sta_hash[i]));
258 rtw_list_insert_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue));
263 pstapriv->adhoc_expire_to = 4; /* 4 * 2 = 8 sec */
265 #ifdef CONFIG_AP_MODE
267 pstapriv->sta_dz_bitmap = 0;
268 pstapriv->tim_bitmap = 0;
270 _rtw_init_listhead(&pstapriv->asoc_list);
271 _rtw_init_listhead(&pstapriv->auth_list);
272 _rtw_spinlock_init(&pstapriv->asoc_list_lock);
273 _rtw_spinlock_init(&pstapriv->auth_list_lock);
274 pstapriv->asoc_list_cnt = 0;
275 pstapriv->auth_list_cnt = 0;
277 pstapriv->auth_to = 3; // 3*2 = 6 sec
278 pstapriv->assoc_to = 3;
279 //pstapriv->expire_to = 900;// 900*2 = 1800 sec = 30 min, expire after no any traffic.
280 //pstapriv->expire_to = 30;// 30*2 = 60 sec = 1 min, expire after no any traffic.
281 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
282 pstapriv->expire_to = 3; // 3*2 = 6 sec
284 pstapriv->expire_to = 60;// 60*2 = 120 sec = 2 min, expire after no any traffic.
286 #ifdef CONFIG_ATMEL_RC_PATCH
287 _rtw_memset( pstapriv->atmel_rc_pattern, 0, ETH_ALEN);
289 pstapriv->max_num_sta = NUM_STA;
299 inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)
301 int offset = (((u8 *)sta) - stapriv->pstainfo_buf)/sizeof(struct sta_info);
303 if (!stainfo_offset_valid(offset))
304 DBG_871X("%s invalid offset(%d), out of range!!!", __func__, offset);
309 inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)
311 if (!stainfo_offset_valid(offset))
312 DBG_871X("%s invalid offset(%d), out of range!!!", __func__, offset);
314 return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));
317 void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv);
318 void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv)
322 _rtw_spinlock_free(&psta_xmitpriv->lock);
324 _rtw_spinlock_free(&(psta_xmitpriv->be_q.sta_pending.lock));
325 _rtw_spinlock_free(&(psta_xmitpriv->bk_q.sta_pending.lock));
326 _rtw_spinlock_free(&(psta_xmitpriv->vi_q.sta_pending.lock));
327 _rtw_spinlock_free(&(psta_xmitpriv->vo_q.sta_pending.lock));
331 static void _rtw_free_sta_recv_priv_lock(struct sta_recv_priv *psta_recvpriv)
335 _rtw_spinlock_free(&psta_recvpriv->lock);
337 _rtw_spinlock_free(&(psta_recvpriv->defrag_q.lock));
343 void rtw_mfree_stainfo(struct sta_info *psta);
344 void rtw_mfree_stainfo(struct sta_info *psta)
348 if(&psta->lock != NULL)
349 _rtw_spinlock_free(&psta->lock);
351 _rtw_free_sta_xmit_priv_lock(&psta->sta_xmitpriv);
352 _rtw_free_sta_recv_priv_lock(&psta->sta_recvpriv);
358 // this function is used to free the memory of lock || sema for all stainfos
359 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv );
360 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv )
363 _list *plist, *phead;
364 struct sta_info *psta = NULL;
368 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
370 phead = get_list_head(&pstapriv->free_sta_queue);
371 plist = get_next(phead);
373 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
375 psta = LIST_CONTAINOR(plist, struct sta_info ,list);
376 plist = get_next(plist);
378 rtw_mfree_stainfo(psta);
381 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
387 void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv);
388 void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv)
390 #ifdef CONFIG_AP_MODE
391 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
394 rtw_mfree_all_stainfo(pstapriv); //be done before free sta_hash_lock
396 _rtw_spinlock_free(&pstapriv->free_sta_queue.lock);
398 _rtw_spinlock_free(&pstapriv->sta_hash_lock);
399 _rtw_spinlock_free(&pstapriv->wakeup_q.lock);
400 _rtw_spinlock_free(&pstapriv->sleep_q.lock);
402 #ifdef CONFIG_AP_MODE
403 _rtw_spinlock_free(&pstapriv->asoc_list_lock);
404 _rtw_spinlock_free(&pstapriv->auth_list_lock);
405 _rtw_spinlock_free(&pacl_list->acl_node_q.lock);
410 u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)
413 _list *phead, *plist;
414 struct sta_info *psta = NULL;
415 struct recv_reorder_ctrl *preorder_ctrl;
421 /* delete all reordering_ctrl_timer */
422 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
423 for(index = 0; index < NUM_STA; index++)
425 phead = &(pstapriv->sta_hash[index]);
426 plist = get_next(phead);
428 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
431 psta = LIST_CONTAINOR(plist, struct sta_info ,hash_list);
432 plist = get_next(plist);
434 for(i=0; i < 16 ; i++)
436 preorder_ctrl = &psta->recvreorder_ctrl[i];
437 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
441 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
442 /*===============================*/
444 rtw_mfree_sta_priv_lock(pstapriv);
446 if(pstapriv->pallocated_stainfo_buf) {
447 rtw_vmfree(pstapriv->pallocated_stainfo_buf, sizeof(struct sta_info)*NUM_STA+4);
456 //struct sta_info *rtw_alloc_stainfo(_queue *pfree_sta_queue, unsigned char *hwaddr)
457 struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr)
463 struct sta_info *psta;
464 _queue *pfree_sta_queue;
465 struct recv_reorder_ctrl *preorder_ctrl;
467 u16 wRxSeqInitialValue = 0xffff;
471 pfree_sta_queue = &pstapriv->free_sta_queue;
473 //_enter_critical_bh(&(pfree_sta_queue->lock), &irqL);
474 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
475 if (_rtw_queue_empty(pfree_sta_queue) == _TRUE)
477 //_exit_critical_bh(&(pfree_sta_queue->lock), &irqL);
478 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
483 psta = LIST_CONTAINOR(get_next(&pfree_sta_queue->queue), struct sta_info, list);
485 rtw_list_delete(&(psta->list));
487 //_exit_critical_bh(&(pfree_sta_queue->lock), &irqL);
491 _rtw_init_stainfo(psta);
493 psta->padapter = pstapriv->padapter;
495 _rtw_memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
497 index = wifi_mac_hash(hwaddr);
499 RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_info_,("rtw_alloc_stainfo: index = %x", index));
501 if(index >= NUM_STA){
502 RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_err_,("ERROR=> rtw_alloc_stainfo: index >= NUM_STA"));
506 phash_list = &(pstapriv->sta_hash[index]);
508 //_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
510 rtw_list_insert_tail(&psta->hash_list, phash_list);
512 pstapriv->asoc_sta_count ++ ;
514 //_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
516 // Commented by Albert 2009/08/13
517 // For the SMC router, the sequence number of first packet of WPS handshake will be 0.
518 // 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.
519 // So, we initialize the tid_rxseq variable as the 0xffff.
521 for (i = 0; i < 16; i++) {
522 _rtw_memcpy( &psta->sta_recvpriv.rxcache.tid_rxseq[ i ], &wRxSeqInitialValue, 2 );
523 _rtw_memset(&psta->sta_recvpriv.rxcache.iv[i], 0, sizeof(psta->sta_recvpriv.rxcache.iv[i]));
526 RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_info_,("alloc number_%d stainfo with hwaddr = %x %x %x %x %x %x \n",
527 pstapriv->asoc_sta_count , hwaddr[0], hwaddr[1], hwaddr[2],hwaddr[3],hwaddr[4],hwaddr[5]));
529 init_addba_retry_timer(pstapriv->padapter, psta);
530 #ifdef CONFIG_IEEE80211W
531 init_dot11w_expire_timer(pstapriv->padapter, psta);
532 #endif /* CONFIG_IEEE80211W */
534 rtw_init_tdls_timer(pstapriv->padapter, psta);
537 //for A-MPDU Rx reordering buffer control
538 for(i=0; i < 16 ; i++)
540 preorder_ctrl = &psta->recvreorder_ctrl[i];
542 preorder_ctrl->padapter = pstapriv->padapter;
544 preorder_ctrl->enable = _FALSE;
546 preorder_ctrl->indicate_seq = 0xffff;
548 DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d\n", __FUNCTION__, __LINE__,
549 preorder_ctrl->indicate_seq);
551 preorder_ctrl->wend_b= 0xffff;
552 //preorder_ctrl->wsize_b = (NR_RECVBUFF-2);
553 preorder_ctrl->wsize_b = 64;//64;
554 preorder_ctrl->ampdu_size = RX_AMPDU_SIZE_INVALID;
556 _rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);
558 rtw_init_recv_timer(preorder_ctrl);
563 psta->rssi_stat.UndecoratedSmoothedPWDB = (-1);
564 psta->rssi_stat.UndecoratedSmoothedCCK = (-1);
565 #ifdef CONFIG_ATMEL_RC_PATCH
566 psta->flag_atmel_rc = 0;
568 /* init for the sequence number of received management frame */
569 psta->RxMgmtFrameSeqNum = 0xffff;
570 psta->ra_rpt_linked = _FALSE;
572 //alloc mac id for non-bc/mc station,
573 rtw_alloc_macid(pstapriv->padapter, psta);
579 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
589 // using pstapriv->sta_hash_lock to protect
590 u32 rtw_free_stainfo(_adapter *padapter , struct sta_info *psta)
594 _queue *pfree_sta_queue;
595 struct recv_reorder_ctrl *preorder_ctrl;
596 struct sta_xmit_priv *pstaxmitpriv;
597 struct xmit_priv *pxmitpriv= &padapter->xmitpriv;
598 struct sta_priv *pstapriv = &padapter->stapriv;
599 struct hw_xmit *phwxmit;
607 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
608 rtw_list_delete(&psta->hash_list);
609 RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_err_,("\n free number_%d stainfo with hwaddr = 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x \n",pstapriv->asoc_sta_count , psta->hwaddr[0], psta->hwaddr[1], psta->hwaddr[2],psta->hwaddr[3],psta->hwaddr[4],psta->hwaddr[5]));
610 pstapriv->asoc_sta_count --;
611 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
614 _enter_critical_bh(&psta->lock, &irqL0);
615 psta->state &= ~_FW_LINKED;
616 _exit_critical_bh(&psta->lock, &irqL0);
618 pfree_sta_queue = &pstapriv->free_sta_queue;
621 pstaxmitpriv = &psta->sta_xmitpriv;
623 //rtw_list_delete(&psta->sleep_list);
625 //rtw_list_delete(&psta->wakeup_list);
627 _enter_critical_bh(&pxmitpriv->lock, &irqL0);
629 rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);
630 psta->sleepq_len = 0;
633 //_enter_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0);
634 rtw_free_xmitframe_queue( pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
635 rtw_list_delete(&(pstaxmitpriv->vo_q.tx_pending));
636 phwxmit = pxmitpriv->hwxmits;
637 phwxmit->accnt -= pstaxmitpriv->vo_q.qcnt;
638 pending_qcnt[0] = pstaxmitpriv->vo_q.qcnt;
639 pstaxmitpriv->vo_q.qcnt = 0;
640 //_exit_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0);
643 //_enter_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0);
644 rtw_free_xmitframe_queue( pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
645 rtw_list_delete(&(pstaxmitpriv->vi_q.tx_pending));
646 phwxmit = pxmitpriv->hwxmits+1;
647 phwxmit->accnt -= pstaxmitpriv->vi_q.qcnt;
648 pending_qcnt[1] = pstaxmitpriv->vi_q.qcnt;
649 pstaxmitpriv->vi_q.qcnt = 0;
650 //_exit_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0);
653 //_enter_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0);
654 rtw_free_xmitframe_queue( pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
655 rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
656 phwxmit = pxmitpriv->hwxmits+2;
657 phwxmit->accnt -= pstaxmitpriv->be_q.qcnt;
658 pending_qcnt[2] = pstaxmitpriv->be_q.qcnt;
659 pstaxmitpriv->be_q.qcnt = 0;
660 //_exit_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0);
663 //_enter_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0);
664 rtw_free_xmitframe_queue( pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
665 rtw_list_delete(&(pstaxmitpriv->bk_q.tx_pending));
666 phwxmit = pxmitpriv->hwxmits+3;
667 phwxmit->accnt -= pstaxmitpriv->bk_q.qcnt;
668 pending_qcnt[3] = pstaxmitpriv->bk_q.qcnt;
669 pstaxmitpriv->bk_q.qcnt = 0;
670 //_exit_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0);
672 rtw_os_wake_queue_at_free_stainfo(padapter, pending_qcnt);
674 _exit_critical_bh(&pxmitpriv->lock, &irqL0);
677 // re-init sta_info; 20061114 // will be init in alloc_stainfo
678 //_rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
679 //_rtw_init_sta_recv_priv(&psta->sta_recvpriv);
680 #ifdef CONFIG_IEEE80211W
681 _cancel_timer_ex(&psta->dot11w_expire_timer);
682 #endif /* CONFIG_IEEE80211W */
683 _cancel_timer_ex(&psta->addba_retry_timer);
686 psta->tdls_sta_state = TDLS_STATE_NONE;
687 rtw_free_tdls_timer(psta);
690 //for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer
691 for(i=0; i < 16 ; i++)
694 _list *phead, *plist;
695 union recv_frame *prframe;
696 _queue *ppending_recvframe_queue;
697 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
699 preorder_ctrl = &psta->recvreorder_ctrl[i];
701 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
704 ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
706 _enter_critical_bh(&ppending_recvframe_queue->lock, &irqL);
708 phead = get_list_head(ppending_recvframe_queue);
709 plist = get_next(phead);
711 while(!rtw_is_list_empty(phead))
713 prframe = LIST_CONTAINOR(plist, union recv_frame, u);
715 plist = get_next(plist);
717 rtw_list_delete(&(prframe->u.hdr.list));
719 rtw_free_recvframe(prframe, pfree_recv_queue);
722 _exit_critical_bh(&ppending_recvframe_queue->lock, &irqL);
726 if (!(psta->state & WIFI_AP_STATE))
727 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _FALSE);
730 //release mac id for non-bc/mc station,
731 rtw_release_macid(pstapriv->padapter, psta);
733 #ifdef CONFIG_AP_MODE
736 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
737 rtw_list_delete(&psta->asoc_list);
738 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
740 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL0);
741 if (!rtw_is_list_empty(&psta->auth_list)) {
742 rtw_list_delete(&psta->auth_list);
743 pstapriv->auth_list_cnt--;
745 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL0);
748 #ifdef CONFIG_ATMEL_RC_PATCH
749 psta->flag_atmel_rc = 0;
751 psta->sleepq_ac_len = 0;
754 psta->max_sp_len = 0;
760 psta->has_legacy_ac = 0;
762 #ifdef CONFIG_NATIVEAP_MLME
764 pstapriv->sta_dz_bitmap &=~BIT(psta->aid);
765 pstapriv->tim_bitmap &=~BIT(psta->aid);
767 //rtw_indicate_sta_disassoc_event(padapter, psta);
769 if ((psta->aid >0)&&(pstapriv->sta_aid[psta->aid - 1] == psta))
771 pstapriv->sta_aid[psta->aid - 1] = NULL;
775 #endif // CONFIG_NATIVEAP_MLME
777 #ifdef CONFIG_TX_MCAST2UNI
778 psta->under_exist_checking = 0;
779 #endif // CONFIG_TX_MCAST2UNI
781 #endif // CONFIG_AP_MODE
783 rtw_st_ctl_deinit(&psta->st_ctl);
785 _rtw_spinlock_free(&psta->lock);
787 //_enter_critical_bh(&(pfree_sta_queue->lock), &irqL0);
788 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
789 rtw_list_insert_tail(&psta->list, get_list_head(pfree_sta_queue));
790 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
791 //_exit_critical_bh(&(pfree_sta_queue->lock), &irqL0);
801 // free all stainfo which in sta_hash[all]
802 void rtw_free_all_stainfo(_adapter *padapter)
805 _list *plist, *phead;
807 struct sta_info *psta = NULL;
808 struct sta_priv *pstapriv = &padapter->stapriv;
809 struct sta_info* pbcmc_stainfo =rtw_get_bcmc_stainfo( padapter);
811 char free_sta_list[NUM_STA];
816 if(pstapriv->asoc_sta_count==1)
819 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
821 for(index=0; index< NUM_STA; index++)
823 phead = &(pstapriv->sta_hash[index]);
824 plist = get_next(phead);
826 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
828 psta = LIST_CONTAINOR(plist, struct sta_info ,hash_list);
830 plist = get_next(plist);
832 if(pbcmc_stainfo!=psta)
834 rtw_list_delete(&psta->hash_list);
835 //rtw_free_stainfo(padapter , psta);
836 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
837 if (stainfo_offset_valid(stainfo_offset)) {
838 free_sta_list[free_sta_num++] = stainfo_offset;
845 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
848 for (index = 0; index < free_sta_num; index++)
850 psta = rtw_get_stainfo_by_offset(pstapriv, free_sta_list[index]);
851 rtw_free_stainfo(padapter , psta);
860 /* any station allocated can be searched by hash list */
861 struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr)
866 _list *plist, *phead;
868 struct sta_info *psta = NULL;
874 const u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
881 if(IS_MCAST((unsigned char *)hwaddr))
890 index = wifi_mac_hash(addr);
892 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
894 phead = &(pstapriv->sta_hash[index]);
895 plist = get_next(phead);
898 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
901 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
903 if ((_rtw_memcmp(psta->hwaddr, addr, ETH_ALEN))== _TRUE)
904 { // if found the matched address
908 plist = get_next(plist);
911 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
917 u32 rtw_init_bcmc_stainfo(_adapter* padapter)
920 struct sta_info *psta;
921 struct tx_servq *ptxservq;
923 NDIS_802_11_MAC_ADDRESS bcast_addr= {0xff,0xff,0xff,0xff,0xff,0xff};
925 struct sta_priv *pstapriv = &padapter->stapriv;
926 //_queue *pstapending = &padapter->xmitpriv.bm_pending;
930 psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
934 RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_err_,("rtw_alloc_stainfo fail"));
937 ptxservq= &(psta->sta_xmitpriv.be_q);
940 _enter_critical(&pstapending->lock, &irqL0);
942 if (rtw_is_list_empty(&ptxservq->tx_pending))
943 rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(pstapending));
945 _exit_critical(&pstapending->lock, &irqL0);
955 struct sta_info* rtw_get_bcmc_stainfo(_adapter* padapter)
957 struct sta_info *psta;
958 struct sta_priv *pstapriv = &padapter->stapriv;
959 u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
961 psta = rtw_get_stainfo(pstapriv, bc_addr);
967 u8 rtw_access_ctrl(_adapter *padapter, u8 *mac_addr)
970 #ifdef CONFIG_AP_MODE
972 _list *plist, *phead;
973 struct rtw_wlan_acl_node *paclnode;
975 struct sta_priv *pstapriv = &padapter->stapriv;
976 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
977 _queue *pacl_node_q =&pacl_list->acl_node_q;
979 _enter_critical_bh(&(pacl_node_q->lock), &irqL);
980 phead = get_list_head(pacl_node_q);
981 plist = get_next(phead);
982 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
984 paclnode = LIST_CONTAINOR(plist, struct rtw_wlan_acl_node, list);
985 plist = get_next(plist);
987 if(_rtw_memcmp(paclnode->addr, mac_addr, ETH_ALEN))
989 if(paclnode->valid == _TRUE)
996 _exit_critical_bh(&(pacl_node_q->lock), &irqL);
999 if(pacl_list->mode == 1)//accept unless in deny list
1001 res = (match == _TRUE) ? _FALSE:_TRUE;
1003 else if(pacl_list->mode == 2)//deny unless in accept list
1005 res = (match == _TRUE) ? _TRUE:_FALSE;