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 RTW_PRINT_SEL(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 RTW_PRINT_SEL(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++) {
253 _rtw_init_stainfo(psta);
255 _rtw_init_listhead(&(pstapriv->sta_hash[i]));
257 rtw_list_insert_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue));
262 pstapriv->adhoc_expire_to = 4; /* 4 * 2 = 8 sec */
264 #ifdef CONFIG_AP_MODE
266 pstapriv->sta_dz_bitmap = 0;
267 pstapriv->tim_bitmap = 0;
269 _rtw_init_listhead(&pstapriv->asoc_list);
270 _rtw_init_listhead(&pstapriv->auth_list);
271 _rtw_spinlock_init(&pstapriv->asoc_list_lock);
272 _rtw_spinlock_init(&pstapriv->auth_list_lock);
273 pstapriv->asoc_list_cnt = 0;
274 pstapriv->auth_list_cnt = 0;
276 pstapriv->auth_to = 3; /* 3*2 = 6 sec */
277 pstapriv->assoc_to = 3;
278 /* pstapriv->expire_to = 900; */ /* 900*2 = 1800 sec = 30 min, expire after no any traffic. */
279 /* pstapriv->expire_to = 30; */ /* 30*2 = 60 sec = 1 min, expire after no any traffic. */
280 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
281 pstapriv->expire_to = 3; /* 3*2 = 6 sec */
283 pstapriv->expire_to = 60;/* 60*2 = 120 sec = 2 min, expire after no any traffic. */
285 #ifdef CONFIG_ATMEL_RC_PATCH
286 _rtw_memset(pstapriv->atmel_rc_pattern, 0, ETH_ALEN);
288 pstapriv->max_num_sta = NUM_STA;
292 #if CONFIG_RTW_MACADDR_ACL
293 _rtw_init_queue(&(pstapriv->acl_list.acl_node_q));
302 inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)
304 int offset = (((u8 *)sta) - stapriv->pstainfo_buf) / sizeof(struct sta_info);
306 if (!stainfo_offset_valid(offset))
307 RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);
312 inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)
314 if (!stainfo_offset_valid(offset))
315 RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);
317 return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));
320 void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv);
321 void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv)
325 _rtw_spinlock_free(&psta_xmitpriv->lock);
327 _rtw_spinlock_free(&(psta_xmitpriv->be_q.sta_pending.lock));
328 _rtw_spinlock_free(&(psta_xmitpriv->bk_q.sta_pending.lock));
329 _rtw_spinlock_free(&(psta_xmitpriv->vi_q.sta_pending.lock));
330 _rtw_spinlock_free(&(psta_xmitpriv->vo_q.sta_pending.lock));
334 static void _rtw_free_sta_recv_priv_lock(struct sta_recv_priv *psta_recvpriv)
338 _rtw_spinlock_free(&psta_recvpriv->lock);
340 _rtw_spinlock_free(&(psta_recvpriv->defrag_q.lock));
346 void rtw_mfree_stainfo(struct sta_info *psta);
347 void rtw_mfree_stainfo(struct sta_info *psta)
351 if (&psta->lock != NULL)
352 _rtw_spinlock_free(&psta->lock);
354 _rtw_free_sta_xmit_priv_lock(&psta->sta_xmitpriv);
355 _rtw_free_sta_recv_priv_lock(&psta->sta_recvpriv);
361 /* this function is used to free the memory of lock || sema for all stainfos */
362 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv);
363 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv)
366 _list *plist, *phead;
367 struct sta_info *psta = NULL;
371 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
373 phead = get_list_head(&pstapriv->free_sta_queue);
374 plist = get_next(phead);
376 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
377 psta = LIST_CONTAINOR(plist, struct sta_info , list);
378 plist = get_next(plist);
380 rtw_mfree_stainfo(psta);
383 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
389 void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv);
390 void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv)
392 rtw_mfree_all_stainfo(pstapriv); /* be done before free sta_hash_lock */
394 _rtw_spinlock_free(&pstapriv->free_sta_queue.lock);
396 _rtw_spinlock_free(&pstapriv->sta_hash_lock);
397 _rtw_spinlock_free(&pstapriv->wakeup_q.lock);
398 _rtw_spinlock_free(&pstapriv->sleep_q.lock);
400 #ifdef CONFIG_AP_MODE
401 _rtw_spinlock_free(&pstapriv->asoc_list_lock);
402 _rtw_spinlock_free(&pstapriv->auth_list_lock);
407 u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)
410 _list *phead, *plist;
411 struct sta_info *psta = NULL;
412 struct recv_reorder_ctrl *preorder_ctrl;
418 /* delete all reordering_ctrl_timer */
419 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
420 for (index = 0; index < NUM_STA; index++) {
421 phead = &(pstapriv->sta_hash[index]);
422 plist = get_next(phead);
424 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
426 psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);
427 plist = get_next(plist);
429 for (i = 0; i < 16 ; i++) {
430 preorder_ctrl = &psta->recvreorder_ctrl[i];
431 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
435 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
436 /*===============================*/
438 rtw_mfree_sta_priv_lock(pstapriv);
440 #if CONFIG_RTW_MACADDR_ACL
441 _rtw_deinit_queue(&(pstapriv->acl_list.acl_node_q));
444 if (pstapriv->pallocated_stainfo_buf)
445 rtw_vmfree(pstapriv->pallocated_stainfo_buf, sizeof(struct sta_info) * NUM_STA + 4);
453 /* struct sta_info *rtw_alloc_stainfo(_queue *pfree_sta_queue, unsigned char *hwaddr) */
454 struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
460 struct sta_info *psta;
461 _queue *pfree_sta_queue;
462 struct recv_reorder_ctrl *preorder_ctrl;
464 u16 wRxSeqInitialValue = 0xffff;
468 pfree_sta_queue = &pstapriv->free_sta_queue;
470 /* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL); */
471 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
472 if (_rtw_queue_empty(pfree_sta_queue) == _TRUE) {
473 /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */
474 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
477 psta = LIST_CONTAINOR(get_next(&pfree_sta_queue->queue), struct sta_info, list);
479 rtw_list_delete(&(psta->list));
481 /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */
485 _rtw_init_stainfo(psta);
487 psta->padapter = pstapriv->padapter;
489 _rtw_memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
491 index = wifi_mac_hash(hwaddr);
493 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_info_, ("rtw_alloc_stainfo: index = %x", index));
495 if (index >= NUM_STA) {
496 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("ERROR=> rtw_alloc_stainfo: index >= NUM_STA"));
500 phash_list = &(pstapriv->sta_hash[index]);
502 /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */
504 rtw_list_insert_tail(&psta->hash_list, phash_list);
506 pstapriv->asoc_sta_count++;
508 /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */
510 /* Commented by Albert 2009/08/13
511 * For the SMC router, the sequence number of first packet of WPS handshake will be 0.
512 * 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.
513 * So, we initialize the tid_rxseq variable as the 0xffff. */
515 for (i = 0; i < 16; i++)
516 _rtw_memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], &wRxSeqInitialValue, 2);
518 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_info_, ("alloc number_%d stainfo with hwaddr = %x %x %x %x %x %x\n",
519 pstapriv->asoc_sta_count , hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]));
521 init_addba_retry_timer(pstapriv->padapter, psta);
522 #ifdef CONFIG_IEEE80211W
523 init_dot11w_expire_timer(pstapriv->padapter, psta);
524 #endif /* CONFIG_IEEE80211W */
526 rtw_init_tdls_timer(pstapriv->padapter, psta);
527 #endif /* CONFIG_TDLS */
529 /* for A-MPDU Rx reordering buffer control */
530 for (i = 0; i < 16 ; i++) {
531 preorder_ctrl = &psta->recvreorder_ctrl[i];
533 preorder_ctrl->padapter = pstapriv->padapter;
535 preorder_ctrl->enable = _FALSE;
537 preorder_ctrl->indicate_seq = 0xffff;
539 RTW_INFO("DBG_RX_SEQ %s:%d IndicateSeq: %d\n", __FUNCTION__, __LINE__,
540 preorder_ctrl->indicate_seq);
542 preorder_ctrl->wend_b = 0xffff;
543 /* preorder_ctrl->wsize_b = (NR_RECVBUFF-2); */
544 preorder_ctrl->wsize_b = 64;/* 64; */
545 preorder_ctrl->ampdu_size = RX_AMPDU_SIZE_INVALID;
547 _rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);
549 rtw_init_recv_timer(preorder_ctrl);
554 psta->rssi_stat.UndecoratedSmoothedPWDB = (-1);
555 psta->rssi_stat.UndecoratedSmoothedCCK = (-1);
556 #ifdef CONFIG_ATMEL_RC_PATCH
557 psta->flag_atmel_rc = 0;
559 /* init for the sequence number of received management frame */
560 psta->RxMgmtFrameSeqNum = 0xffff;
561 psta->ra_rpt_linked = _FALSE;
563 rtw_alloc_macid(pstapriv->padapter, psta);
569 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
579 /* using pstapriv->sta_hash_lock to protect */
580 u32 rtw_free_stainfo(_adapter *padapter , struct sta_info *psta)
584 _queue *pfree_sta_queue;
585 struct recv_reorder_ctrl *preorder_ctrl;
586 struct sta_xmit_priv *pstaxmitpriv;
587 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
588 struct sta_priv *pstapriv = &padapter->stapriv;
589 struct hw_xmit *phwxmit;
597 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
598 rtw_list_delete(&psta->hash_list);
599 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],
600 psta->hwaddr[1], psta->hwaddr[2], psta->hwaddr[3], psta->hwaddr[4], psta->hwaddr[5]));
601 pstapriv->asoc_sta_count--;
602 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
605 _enter_critical_bh(&psta->lock, &irqL0);
606 psta->state &= ~_FW_LINKED;
607 _exit_critical_bh(&psta->lock, &irqL0);
609 pfree_sta_queue = &pstapriv->free_sta_queue;
612 pstaxmitpriv = &psta->sta_xmitpriv;
614 /* rtw_list_delete(&psta->sleep_list); */
616 /* rtw_list_delete(&psta->wakeup_list); */
618 _enter_critical_bh(&pxmitpriv->lock, &irqL0);
620 rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);
621 psta->sleepq_len = 0;
624 /* _enter_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */
625 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
626 rtw_list_delete(&(pstaxmitpriv->vo_q.tx_pending));
627 phwxmit = pxmitpriv->hwxmits;
628 phwxmit->accnt -= pstaxmitpriv->vo_q.qcnt;
629 pending_qcnt[0] = pstaxmitpriv->vo_q.qcnt;
630 pstaxmitpriv->vo_q.qcnt = 0;
631 /* _exit_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */
634 /* _enter_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */
635 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
636 rtw_list_delete(&(pstaxmitpriv->vi_q.tx_pending));
637 phwxmit = pxmitpriv->hwxmits + 1;
638 phwxmit->accnt -= pstaxmitpriv->vi_q.qcnt;
639 pending_qcnt[1] = pstaxmitpriv->vi_q.qcnt;
640 pstaxmitpriv->vi_q.qcnt = 0;
641 /* _exit_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */
644 /* _enter_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */
645 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
646 rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
647 phwxmit = pxmitpriv->hwxmits + 2;
648 phwxmit->accnt -= pstaxmitpriv->be_q.qcnt;
649 pending_qcnt[2] = pstaxmitpriv->be_q.qcnt;
650 pstaxmitpriv->be_q.qcnt = 0;
651 /* _exit_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */
654 /* _enter_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */
655 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
656 rtw_list_delete(&(pstaxmitpriv->bk_q.tx_pending));
657 phwxmit = pxmitpriv->hwxmits + 3;
658 phwxmit->accnt -= pstaxmitpriv->bk_q.qcnt;
659 pending_qcnt[3] = pstaxmitpriv->bk_q.qcnt;
660 pstaxmitpriv->bk_q.qcnt = 0;
661 /* _exit_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */
663 rtw_os_wake_queue_at_free_stainfo(padapter, pending_qcnt);
665 _exit_critical_bh(&pxmitpriv->lock, &irqL0);
668 /* re-init sta_info; 20061114 */ /* will be init in alloc_stainfo */
669 /* _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv); */
670 /* _rtw_init_sta_recv_priv(&psta->sta_recvpriv); */
671 #ifdef CONFIG_IEEE80211W
672 _cancel_timer_ex(&psta->dot11w_expire_timer);
673 #endif /* CONFIG_IEEE80211W */
674 _cancel_timer_ex(&psta->addba_retry_timer);
677 psta->tdls_sta_state = TDLS_STATE_NONE;
678 rtw_free_tdls_timer(psta);
679 #endif /* CONFIG_TDLS */
681 /* for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer */
682 for (i = 0; i < 16 ; i++) {
684 _list *phead, *plist;
685 union recv_frame *prframe;
686 _queue *ppending_recvframe_queue;
687 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
689 preorder_ctrl = &psta->recvreorder_ctrl[i];
691 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
694 ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
696 _enter_critical_bh(&ppending_recvframe_queue->lock, &irqL);
698 phead = get_list_head(ppending_recvframe_queue);
699 plist = get_next(phead);
701 while (!rtw_is_list_empty(phead)) {
702 prframe = LIST_CONTAINOR(plist, union recv_frame, u);
704 plist = get_next(plist);
706 rtw_list_delete(&(prframe->u.hdr.list));
708 rtw_free_recvframe(prframe, pfree_recv_queue);
711 _exit_critical_bh(&ppending_recvframe_queue->lock, &irqL);
715 if (!((psta->state & WIFI_AP_STATE) || MacAddr_isBcst(psta->hwaddr)))
716 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _FALSE);
719 /* release mac id for non-bc/mc station, */
720 rtw_release_macid(pstapriv->padapter, psta);
722 #ifdef CONFIG_AP_MODE
725 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
726 rtw_list_delete(&psta->asoc_list);
727 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
729 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL0);
730 if (!rtw_is_list_empty(&psta->auth_list)) {
731 rtw_list_delete(&psta->auth_list);
732 pstapriv->auth_list_cnt--;
734 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL0);
737 #ifdef CONFIG_ATMEL_RC_PATCH
738 psta->flag_atmel_rc = 0;
740 psta->sleepq_ac_len = 0;
743 psta->max_sp_len = 0;
749 psta->has_legacy_ac = 0;
751 #ifdef CONFIG_NATIVEAP_MLME
753 pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
754 pstapriv->tim_bitmap &= ~BIT(psta->aid);
756 /* rtw_indicate_sta_disassoc_event(padapter, psta); */
758 if ((psta->aid > 0) && (pstapriv->sta_aid[psta->aid - 1] == psta)) {
759 pstapriv->sta_aid[psta->aid - 1] = NULL;
763 #endif /* CONFIG_NATIVEAP_MLME */
765 #ifdef CONFIG_TX_MCAST2UNI
766 psta->under_exist_checking = 0;
767 #endif /* CONFIG_TX_MCAST2UNI */
769 #endif /* CONFIG_AP_MODE */
771 rtw_st_ctl_deinit(&psta->st_ctl);
773 _rtw_spinlock_free(&psta->lock);
775 /* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL0); */
776 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
777 rtw_list_insert_tail(&psta->list, get_list_head(pfree_sta_queue));
778 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
779 /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL0); */
789 /* free all stainfo which in sta_hash[all] */
790 void rtw_free_all_stainfo(_adapter *padapter)
793 _list *plist, *phead;
795 struct sta_info *psta = NULL;
796 struct sta_priv *pstapriv = &padapter->stapriv;
797 struct sta_info *pbcmc_stainfo = rtw_get_bcmc_stainfo(padapter);
799 char free_sta_list[NUM_STA];
804 if (pstapriv->asoc_sta_count == 1)
807 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
809 for (index = 0; index < NUM_STA; index++) {
810 phead = &(pstapriv->sta_hash[index]);
811 plist = get_next(phead);
813 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
814 psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);
816 plist = get_next(plist);
818 if (pbcmc_stainfo != psta) {
819 rtw_list_delete(&psta->hash_list);
820 /* rtw_free_stainfo(padapter , psta); */
821 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
822 if (stainfo_offset_valid(stainfo_offset))
823 free_sta_list[free_sta_num++] = stainfo_offset;
829 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
832 for (index = 0; index < free_sta_num; index++) {
833 psta = rtw_get_stainfo_by_offset(pstapriv, free_sta_list[index]);
834 rtw_free_stainfo(padapter , psta);
843 /* any station allocated can be searched by hash list */
844 struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
849 _list *plist, *phead;
851 struct sta_info *psta = NULL;
857 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
864 if (IS_MCAST(hwaddr))
869 index = wifi_mac_hash(addr);
871 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
873 phead = &(pstapriv->sta_hash[index]);
874 plist = get_next(phead);
877 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
879 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
881 if ((_rtw_memcmp(psta->hwaddr, addr, ETH_ALEN)) == _TRUE) {
882 /* if found the matched address */
886 plist = get_next(plist);
889 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
895 u32 rtw_init_bcmc_stainfo(_adapter *padapter)
898 struct sta_info *psta;
899 struct tx_servq *ptxservq;
901 NDIS_802_11_MAC_ADDRESS bcast_addr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
903 struct sta_priv *pstapriv = &padapter->stapriv;
904 /* _queue *pstapending = &padapter->xmitpriv.bm_pending; */
908 psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
912 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("rtw_alloc_stainfo fail"));
915 #ifdef CONFIG_BEAMFORMING
919 ptxservq = &(psta->sta_xmitpriv.be_q);
922 _enter_critical(&pstapending->lock, &irqL0);
924 if (rtw_is_list_empty(&ptxservq->tx_pending))
925 rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(pstapending));
927 _exit_critical(&pstapending->lock, &irqL0);
937 struct sta_info *rtw_get_bcmc_stainfo(_adapter *padapter)
939 struct sta_info *psta;
940 struct sta_priv *pstapriv = &padapter->stapriv;
941 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
943 psta = rtw_get_stainfo(pstapriv, bc_addr);
949 #if CONFIG_RTW_MACADDR_ACL
950 u8 rtw_access_ctrl(_adapter *adapter, u8 *mac_addr)
955 struct rtw_wlan_acl_node *acl_node;
957 struct sta_priv *stapriv = &adapter->stapriv;
958 struct wlan_acl_pool *acl = &stapriv->acl_list;
959 _queue *acl_node_q = &acl->acl_node_q;
961 _enter_critical_bh(&(acl_node_q->lock), &irqL);
962 head = get_list_head(acl_node_q);
963 list = get_next(head);
964 while (rtw_end_of_queue_search(head, list) == _FALSE) {
965 acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
966 list = get_next(list);
968 if (_rtw_memcmp(acl_node->addr, mac_addr, ETH_ALEN)) {
969 if (acl_node->valid == _TRUE) {
975 _exit_critical_bh(&(acl_node_q->lock), &irqL);
977 if (acl->mode == RTW_ACL_MODE_ACCEPT_UNLESS_LISTED)
978 res = (match == _TRUE) ? _FALSE : _TRUE;
979 else if (acl->mode == RTW_ACL_MODE_DENY_UNLESS_LISTED)
980 res = (match == _TRUE) ? _TRUE : _FALSE;
986 #endif /* CONFIG_RTW_MACADDR_ACL */