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)
170 _rtw_memset((u8 *)psta, 0, sizeof(struct sta_info));
172 _rtw_spinlock_init(&psta->lock);
173 _rtw_init_listhead(&psta->list);
174 _rtw_init_listhead(&psta->hash_list);
175 /* _rtw_init_listhead(&psta->asoc_list); */
176 /* _rtw_init_listhead(&psta->sleep_list); */
177 /* _rtw_init_listhead(&psta->wakeup_list); */
179 _rtw_init_queue(&psta->sleep_q);
180 psta->sleepq_len = 0;
182 _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
183 _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
185 #ifdef CONFIG_AP_MODE
187 _rtw_init_listhead(&psta->asoc_list);
189 _rtw_init_listhead(&psta->auth_list);
195 psta->capability = 0;
197 psta->bpairwise_key_installed = _FALSE;
199 #ifdef CONFIG_RTW_80211R
200 psta->ft_pairwise_key_installed = _FALSE;
203 #ifdef CONFIG_NATIVEAP_MLME
204 psta->nonerp_set = 0;
205 psta->no_short_slot_time_set = 0;
206 psta->no_short_preamble_set = 0;
207 psta->no_ht_gf_set = 0;
209 psta->ht_20mhz_set = 0;
210 psta->ht_40mhz_intolerant = 0;
213 #ifdef CONFIG_TX_MCAST2UNI
214 psta->under_exist_checking = 0;
215 #endif /* CONFIG_TX_MCAST2UNI */
217 psta->keep_alive_trycnt = 0;
219 #endif /* CONFIG_AP_MODE */
221 rtw_st_ctl_init(&psta->st_ctl);
226 u32 _rtw_init_sta_priv(struct sta_priv *pstapriv)
228 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));
296 #if CONFIG_RTW_PRE_LINK_STA
297 rtw_pre_link_sta_ctl_init(pstapriv);
304 inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)
306 int offset = (((u8 *)sta) - stapriv->pstainfo_buf) / sizeof(struct sta_info);
308 if (!stainfo_offset_valid(offset))
309 RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);
314 inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)
316 if (!stainfo_offset_valid(offset))
317 RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);
319 return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));
322 void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv);
323 void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv)
326 _rtw_spinlock_free(&psta_xmitpriv->lock);
328 _rtw_spinlock_free(&(psta_xmitpriv->be_q.sta_pending.lock));
329 _rtw_spinlock_free(&(psta_xmitpriv->bk_q.sta_pending.lock));
330 _rtw_spinlock_free(&(psta_xmitpriv->vi_q.sta_pending.lock));
331 _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)
337 _rtw_spinlock_free(&psta_recvpriv->lock);
339 _rtw_spinlock_free(&(psta_recvpriv->defrag_q.lock));
344 void rtw_mfree_stainfo(struct sta_info *psta);
345 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);
357 /* this function is used to free the memory of lock || sema for all stainfos */
358 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv);
359 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv)
362 _list *plist, *phead;
363 struct sta_info *psta = NULL;
366 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
368 phead = get_list_head(&pstapriv->free_sta_queue);
369 plist = get_next(phead);
371 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
372 psta = LIST_CONTAINOR(plist, struct sta_info , list);
373 plist = get_next(plist);
375 rtw_mfree_stainfo(psta);
378 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
383 void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv);
384 void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv)
386 rtw_mfree_all_stainfo(pstapriv); /* be done before free sta_hash_lock */
388 _rtw_spinlock_free(&pstapriv->free_sta_queue.lock);
390 _rtw_spinlock_free(&pstapriv->sta_hash_lock);
391 _rtw_spinlock_free(&pstapriv->wakeup_q.lock);
392 _rtw_spinlock_free(&pstapriv->sleep_q.lock);
394 #ifdef CONFIG_AP_MODE
395 _rtw_spinlock_free(&pstapriv->asoc_list_lock);
396 _rtw_spinlock_free(&pstapriv->auth_list_lock);
401 u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)
404 _list *phead, *plist;
405 struct sta_info *psta = NULL;
406 struct recv_reorder_ctrl *preorder_ctrl;
411 /* delete all reordering_ctrl_timer */
412 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
413 for (index = 0; index < NUM_STA; index++) {
414 phead = &(pstapriv->sta_hash[index]);
415 plist = get_next(phead);
417 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
419 psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);
420 plist = get_next(plist);
422 for (i = 0; i < 16 ; i++) {
423 preorder_ctrl = &psta->recvreorder_ctrl[i];
424 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
428 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
429 /*===============================*/
431 rtw_mfree_sta_priv_lock(pstapriv);
433 #if CONFIG_RTW_MACADDR_ACL
434 _rtw_deinit_queue(&(pstapriv->acl_list.acl_node_q));
437 #if CONFIG_RTW_PRE_LINK_STA
438 rtw_pre_link_sta_ctl_deinit(pstapriv);
441 if (pstapriv->pallocated_stainfo_buf)
442 rtw_vmfree(pstapriv->pallocated_stainfo_buf, sizeof(struct sta_info) * NUM_STA + 4);
449 /* struct sta_info *rtw_alloc_stainfo(_queue *pfree_sta_queue, unsigned char *hwaddr) */
450 struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
456 struct sta_info *psta;
457 _queue *pfree_sta_queue;
458 struct recv_reorder_ctrl *preorder_ctrl;
460 u16 wRxSeqInitialValue = 0xffff;
463 pfree_sta_queue = &pstapriv->free_sta_queue;
465 /* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL); */
466 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
467 if (_rtw_queue_empty(pfree_sta_queue) == _TRUE) {
468 /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */
469 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
472 psta = LIST_CONTAINOR(get_next(&pfree_sta_queue->queue), struct sta_info, list);
474 rtw_list_delete(&(psta->list));
476 /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */
480 _rtw_init_stainfo(psta);
482 psta->padapter = pstapriv->padapter;
484 _rtw_memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
486 index = wifi_mac_hash(hwaddr);
489 if (index >= NUM_STA) {
493 phash_list = &(pstapriv->sta_hash[index]);
495 /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */
497 rtw_list_insert_tail(&psta->hash_list, phash_list);
499 pstapriv->asoc_sta_count++;
501 /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */
503 /* Commented by Albert 2009/08/13
504 * For the SMC router, the sequence number of first packet of WPS handshake will be 0.
505 * 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.
506 * So, we initialize the tid_rxseq variable as the 0xffff. */
508 for (i = 0; i < 16; i++)
509 _rtw_memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], &wRxSeqInitialValue, 2);
512 init_addba_retry_timer(pstapriv->padapter, psta);
513 #ifdef CONFIG_IEEE80211W
514 init_dot11w_expire_timer(pstapriv->padapter, psta);
515 #endif /* CONFIG_IEEE80211W */
517 rtw_init_tdls_timer(pstapriv->padapter, psta);
518 #endif /* CONFIG_TDLS */
520 /* for A-MPDU Rx reordering buffer control */
521 for (i = 0; i < 16 ; i++) {
522 preorder_ctrl = &psta->recvreorder_ctrl[i];
524 preorder_ctrl->padapter = pstapriv->padapter;
526 preorder_ctrl->enable = _FALSE;
528 preorder_ctrl->indicate_seq = 0xffff;
530 RTW_INFO("DBG_RX_SEQ %s:%d IndicateSeq: %d\n", __FUNCTION__, __LINE__,
531 preorder_ctrl->indicate_seq);
533 preorder_ctrl->wend_b = 0xffff;
534 /* preorder_ctrl->wsize_b = (NR_RECVBUFF-2); */
535 preorder_ctrl->wsize_b = 64;/* 64; */
536 preorder_ctrl->ampdu_size = RX_AMPDU_SIZE_INVALID;
538 _rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);
540 rtw_init_recv_timer(preorder_ctrl);
545 psta->rssi_stat.undecorated_smoothed_pwdb = (-1);
546 psta->rssi_stat.undecorated_smoothed_cck = (-1);
547 #ifdef CONFIG_ATMEL_RC_PATCH
548 psta->flag_atmel_rc = 0;
550 /* init for the sequence number of received management frame */
551 psta->RxMgmtFrameSeqNum = 0xffff;
552 psta->ra_rpt_linked = _FALSE;
554 rtw_alloc_macid(pstapriv->padapter, psta);
560 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
564 rtw_mi_update_iface_status(&(pstapriv->padapter->mlmepriv), 0);
570 /* using pstapriv->sta_hash_lock to protect */
571 u32 rtw_free_stainfo(_adapter *padapter , struct sta_info *psta)
575 _queue *pfree_sta_queue;
576 struct recv_reorder_ctrl *preorder_ctrl;
577 struct sta_xmit_priv *pstaxmitpriv;
578 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
579 struct sta_priv *pstapriv = &padapter->stapriv;
580 struct hw_xmit *phwxmit;
582 u8 is_pre_link_sta = _FALSE;
587 is_pre_link_sta = rtw_is_pre_link_sta(pstapriv, psta->hwaddr);
589 if (is_pre_link_sta == _FALSE) {
590 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
591 rtw_list_delete(&psta->hash_list);
592 pstapriv->asoc_sta_count--;
593 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
594 rtw_mi_update_iface_status(&(padapter->mlmepriv), 0);
596 _enter_critical_bh(&psta->lock, &irqL0);
597 psta->state = WIFI_FW_PRE_LINK;
598 _exit_critical_bh(&psta->lock, &irqL0);
601 _enter_critical_bh(&psta->lock, &irqL0);
602 psta->state &= ~_FW_LINKED;
603 _exit_critical_bh(&psta->lock, &irqL0);
605 pfree_sta_queue = &pstapriv->free_sta_queue;
608 pstaxmitpriv = &psta->sta_xmitpriv;
610 /* rtw_list_delete(&psta->sleep_list); */
612 /* rtw_list_delete(&psta->wakeup_list); */
614 _enter_critical_bh(&pxmitpriv->lock, &irqL0);
616 rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);
617 psta->sleepq_len = 0;
620 /* _enter_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */
621 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
622 rtw_list_delete(&(pstaxmitpriv->vo_q.tx_pending));
623 phwxmit = pxmitpriv->hwxmits;
624 phwxmit->accnt -= pstaxmitpriv->vo_q.qcnt;
625 pending_qcnt[0] = pstaxmitpriv->vo_q.qcnt;
626 pstaxmitpriv->vo_q.qcnt = 0;
627 /* _exit_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */
630 /* _enter_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */
631 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
632 rtw_list_delete(&(pstaxmitpriv->vi_q.tx_pending));
633 phwxmit = pxmitpriv->hwxmits + 1;
634 phwxmit->accnt -= pstaxmitpriv->vi_q.qcnt;
635 pending_qcnt[1] = pstaxmitpriv->vi_q.qcnt;
636 pstaxmitpriv->vi_q.qcnt = 0;
637 /* _exit_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */
640 /* _enter_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */
641 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
642 rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
643 phwxmit = pxmitpriv->hwxmits + 2;
644 phwxmit->accnt -= pstaxmitpriv->be_q.qcnt;
645 pending_qcnt[2] = pstaxmitpriv->be_q.qcnt;
646 pstaxmitpriv->be_q.qcnt = 0;
647 /* _exit_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */
650 /* _enter_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */
651 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
652 rtw_list_delete(&(pstaxmitpriv->bk_q.tx_pending));
653 phwxmit = pxmitpriv->hwxmits + 3;
654 phwxmit->accnt -= pstaxmitpriv->bk_q.qcnt;
655 pending_qcnt[3] = pstaxmitpriv->bk_q.qcnt;
656 pstaxmitpriv->bk_q.qcnt = 0;
657 /* _exit_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */
659 rtw_os_wake_queue_at_free_stainfo(padapter, pending_qcnt);
661 _exit_critical_bh(&pxmitpriv->lock, &irqL0);
664 /* re-init sta_info; 20061114 */ /* will be init in alloc_stainfo */
665 /* _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv); */
666 /* _rtw_init_sta_recv_priv(&psta->sta_recvpriv); */
667 #ifdef CONFIG_IEEE80211W
668 _cancel_timer_ex(&psta->dot11w_expire_timer);
669 #endif /* CONFIG_IEEE80211W */
670 _cancel_timer_ex(&psta->addba_retry_timer);
673 psta->tdls_sta_state = TDLS_STATE_NONE;
674 rtw_free_tdls_timer(psta);
675 #endif /* CONFIG_TDLS */
677 /* for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer */
678 for (i = 0; i < 16 ; i++) {
680 _list *phead, *plist;
681 union recv_frame *prframe;
682 _queue *ppending_recvframe_queue;
683 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
685 preorder_ctrl = &psta->recvreorder_ctrl[i];
687 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
690 ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
692 _enter_critical_bh(&ppending_recvframe_queue->lock, &irqL);
694 phead = get_list_head(ppending_recvframe_queue);
695 plist = get_next(phead);
697 while (!rtw_is_list_empty(phead)) {
698 prframe = LIST_CONTAINOR(plist, union recv_frame, u);
700 plist = get_next(plist);
702 rtw_list_delete(&(prframe->u.hdr.list));
704 rtw_free_recvframe(prframe, pfree_recv_queue);
707 _exit_critical_bh(&ppending_recvframe_queue->lock, &irqL);
711 if (!((psta->state & WIFI_AP_STATE) || MacAddr_isBcst(psta->hwaddr)) && is_pre_link_sta == _FALSE)
712 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _FALSE);
715 /* release mac id for non-bc/mc station, */
716 if (is_pre_link_sta == _FALSE)
717 rtw_release_macid(pstapriv->padapter, psta);
719 #ifdef CONFIG_AP_MODE
722 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
723 rtw_list_delete(&psta->asoc_list);
724 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
726 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL0);
727 if (!rtw_is_list_empty(&psta->auth_list)) {
728 rtw_list_delete(&psta->auth_list);
729 pstapriv->auth_list_cnt--;
731 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL0);
734 #ifdef CONFIG_ATMEL_RC_PATCH
735 psta->flag_atmel_rc = 0;
737 psta->sleepq_ac_len = 0;
740 psta->max_sp_len = 0;
746 psta->has_legacy_ac = 0;
748 #ifdef CONFIG_NATIVEAP_MLME
750 pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
751 pstapriv->tim_bitmap &= ~BIT(psta->aid);
753 /* rtw_indicate_sta_disassoc_event(padapter, psta); */
755 if ((psta->aid > 0) && (pstapriv->sta_aid[psta->aid - 1] == psta)) {
756 pstapriv->sta_aid[psta->aid - 1] = NULL;
760 #endif /* CONFIG_NATIVEAP_MLME */
762 #ifdef CONFIG_TX_MCAST2UNI
763 psta->under_exist_checking = 0;
764 #endif /* CONFIG_TX_MCAST2UNI */
766 #endif /* CONFIG_AP_MODE */
768 rtw_st_ctl_deinit(&psta->st_ctl);
770 if (is_pre_link_sta == _FALSE) {
771 _rtw_spinlock_free(&psta->lock);
773 /* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL0); */
774 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
775 rtw_list_insert_tail(&psta->list, get_list_head(pfree_sta_queue));
776 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
777 /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL0); */
784 /* free all stainfo which in sta_hash[all] */
785 void rtw_free_all_stainfo(_adapter *padapter)
788 _list *plist, *phead;
790 struct sta_info *psta = NULL;
791 struct sta_priv *pstapriv = &padapter->stapriv;
792 struct sta_info *pbcmc_stainfo = rtw_get_bcmc_stainfo(padapter);
794 char free_sta_list[NUM_STA];
798 if (pstapriv->asoc_sta_count == 1)
801 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
803 for (index = 0; index < NUM_STA; index++) {
804 phead = &(pstapriv->sta_hash[index]);
805 plist = get_next(phead);
807 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
808 psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);
810 plist = get_next(plist);
812 if (pbcmc_stainfo != psta) {
813 if (rtw_is_pre_link_sta(pstapriv, psta->hwaddr) == _FALSE)
814 rtw_list_delete(&psta->hash_list);
816 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
817 if (stainfo_offset_valid(stainfo_offset))
818 free_sta_list[free_sta_num++] = stainfo_offset;
824 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
827 for (index = 0; index < free_sta_num; index++) {
828 psta = rtw_get_stainfo_by_offset(pstapriv, free_sta_list[index]);
829 rtw_free_stainfo(padapter , psta);
836 /* any station allocated can be searched by hash list */
837 struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
842 _list *plist, *phead;
844 struct sta_info *psta = NULL;
850 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
856 if (IS_MCAST(hwaddr))
861 index = wifi_mac_hash(addr);
863 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
865 phead = &(pstapriv->sta_hash[index]);
866 plist = get_next(phead);
869 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
871 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
873 if ((_rtw_memcmp(psta->hwaddr, addr, ETH_ALEN)) == _TRUE) {
874 /* if found the matched address */
878 plist = get_next(plist);
881 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
886 u32 rtw_init_bcmc_stainfo(_adapter *padapter)
889 struct sta_info *psta;
890 struct tx_servq *ptxservq;
892 NDIS_802_11_MAC_ADDRESS bcast_addr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
894 struct sta_priv *pstapriv = &padapter->stapriv;
895 /* _queue *pstapending = &padapter->xmitpriv.bm_pending; */
898 psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
904 #ifdef CONFIG_BEAMFORMING
908 ptxservq = &(psta->sta_xmitpriv.be_q);
911 _enter_critical(&pstapending->lock, &irqL0);
913 if (rtw_is_list_empty(&ptxservq->tx_pending))
914 rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(pstapending));
916 _exit_critical(&pstapending->lock, &irqL0);
925 struct sta_info *rtw_get_bcmc_stainfo(_adapter *padapter)
927 struct sta_info *psta;
928 struct sta_priv *pstapriv = &padapter->stapriv;
929 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
930 psta = rtw_get_stainfo(pstapriv, bc_addr);
935 #if CONFIG_RTW_MACADDR_ACL
936 const char *const _acl_mode_str[] = {
938 "ACCEPT_UNLESS_LISTED",
939 "DENY_UNLESS_LISTED",
942 u8 rtw_access_ctrl(_adapter *adapter, u8 *mac_addr)
947 struct rtw_wlan_acl_node *acl_node;
949 struct sta_priv *stapriv = &adapter->stapriv;
950 struct wlan_acl_pool *acl = &stapriv->acl_list;
951 _queue *acl_node_q = &acl->acl_node_q;
953 _enter_critical_bh(&(acl_node_q->lock), &irqL);
954 head = get_list_head(acl_node_q);
955 list = get_next(head);
956 while (rtw_end_of_queue_search(head, list) == _FALSE) {
957 acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
958 list = get_next(list);
960 if (_rtw_memcmp(acl_node->addr, mac_addr, ETH_ALEN)) {
961 if (acl_node->valid == _TRUE) {
967 _exit_critical_bh(&(acl_node_q->lock), &irqL);
969 if (acl->mode == RTW_ACL_MODE_ACCEPT_UNLESS_LISTED)
970 res = (match == _TRUE) ? _FALSE : _TRUE;
971 else if (acl->mode == RTW_ACL_MODE_DENY_UNLESS_LISTED)
972 res = (match == _TRUE) ? _TRUE : _FALSE;
979 void dump_macaddr_acl(void *sel, _adapter *adapter)
981 struct sta_priv *stapriv = &adapter->stapriv;
982 struct wlan_acl_pool *acl = &stapriv->acl_list;
985 RTW_PRINT_SEL(sel, "mode:%s(%d)\n", acl_mode_str(acl->mode), acl->mode);
986 RTW_PRINT_SEL(sel, "num:%d/%d\n", acl->num, NUM_ACL);
987 for (i = 0; i < NUM_ACL; i++) {
988 if (acl->aclnode[i].valid == _FALSE)
990 RTW_PRINT_SEL(sel, MAC_FMT"\n", MAC_ARG(acl->aclnode[i].addr));
993 #endif /* CONFIG_RTW_MACADDR_ACL */
995 bool rtw_is_pre_link_sta(struct sta_priv *stapriv, u8 *addr)
997 #if CONFIG_RTW_PRE_LINK_STA
998 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
999 struct sta_info *sta = NULL;
1004 _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1005 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1006 if (pre_link_sta_ctl->node[i].valid == _TRUE
1007 && _rtw_memcmp(pre_link_sta_ctl->node[i].addr, addr, ETH_ALEN) == _TRUE
1013 _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1021 #if CONFIG_RTW_PRE_LINK_STA
1022 struct sta_info *rtw_pre_link_sta_add(struct sta_priv *stapriv, u8 *hwaddr)
1024 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1025 struct pre_link_sta_node_t *node = NULL;
1026 struct sta_info *sta = NULL;
1031 if (rtw_check_invalid_mac_address(hwaddr, _FALSE) == _TRUE)
1034 _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1035 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1036 if (pre_link_sta_ctl->node[i].valid == _TRUE
1037 && _rtw_memcmp(pre_link_sta_ctl->node[i].addr, hwaddr, ETH_ALEN) == _TRUE
1039 node = &pre_link_sta_ctl->node[i];
1044 if (node == NULL && pre_link_sta_ctl->node[i].valid == _FALSE)
1045 node = &pre_link_sta_ctl->node[i];
1048 if (exist == _FALSE && node) {
1049 _rtw_memcpy(node->addr, hwaddr, ETH_ALEN);
1050 node->valid = _TRUE;
1051 pre_link_sta_ctl->num++;
1053 _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1058 sta = rtw_get_stainfo(stapriv, hwaddr);
1062 sta = rtw_alloc_stainfo(stapriv, hwaddr);
1066 sta->state = WIFI_FW_PRE_LINK;
1069 rtw_hal_set_odm_var(stapriv->padapter, HAL_ODM_STA_INFO, sta, _TRUE);
1075 void rtw_pre_link_sta_del(struct sta_priv *stapriv, u8 *hwaddr)
1077 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1078 struct pre_link_sta_node_t *node = NULL;
1079 struct sta_info *sta = NULL;
1084 if (rtw_check_invalid_mac_address(hwaddr, _FALSE) == _TRUE)
1087 _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1088 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1089 if (pre_link_sta_ctl->node[i].valid == _TRUE
1090 && _rtw_memcmp(pre_link_sta_ctl->node[i].addr, hwaddr, ETH_ALEN) == _TRUE
1092 node = &pre_link_sta_ctl->node[i];
1098 if (exist == _TRUE && node) {
1099 node->valid = _FALSE;
1100 pre_link_sta_ctl->num--;
1102 _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1104 if (exist == _FALSE)
1107 sta = rtw_get_stainfo(stapriv, hwaddr);
1111 if (sta->state == WIFI_FW_PRE_LINK)
1112 rtw_free_stainfo(stapriv->padapter, sta);
1118 void rtw_pre_link_sta_ctl_reset(struct sta_priv *stapriv)
1120 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1121 struct pre_link_sta_node_t *node = NULL;
1122 struct sta_info *sta = NULL;
1126 u8 addrs[RTW_PRE_LINK_STA_NUM][ETH_ALEN];
1128 _rtw_memset(addrs, 0, RTW_PRE_LINK_STA_NUM * ETH_ALEN);
1130 _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1131 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1132 if (pre_link_sta_ctl->node[i].valid == _FALSE)
1134 _rtw_memcpy(&(addrs[j][0]), pre_link_sta_ctl->node[i].addr, ETH_ALEN);
1135 pre_link_sta_ctl->node[i].valid = _FALSE;
1136 pre_link_sta_ctl->num--;
1139 _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1141 for (i = 0; i < j; i++) {
1142 sta = rtw_get_stainfo(stapriv, &(addrs[i][0]));
1146 if (sta->state == WIFI_FW_PRE_LINK)
1147 rtw_free_stainfo(stapriv->padapter, sta);
1151 void rtw_pre_link_sta_ctl_init(struct sta_priv *stapriv)
1153 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1156 _rtw_spinlock_init(&pre_link_sta_ctl->lock);
1157 pre_link_sta_ctl->num = 0;
1158 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++)
1159 pre_link_sta_ctl->node[i].valid = _FALSE;
1162 void rtw_pre_link_sta_ctl_deinit(struct sta_priv *stapriv)
1164 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1167 rtw_pre_link_sta_ctl_reset(stapriv);
1169 _rtw_spinlock_free(&pre_link_sta_ctl->lock);
1172 void dump_pre_link_sta_ctl(void *sel, struct sta_priv *stapriv)
1174 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1177 RTW_PRINT_SEL(sel, "num:%d/%d\n", pre_link_sta_ctl->num, RTW_PRE_LINK_STA_NUM);
1179 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1180 if (pre_link_sta_ctl->node[i].valid == _FALSE)
1182 RTW_PRINT_SEL(sel, MAC_FMT"\n", MAC_ARG(pre_link_sta_ctl->node[i].addr));
1185 #endif /* CONFIG_RTW_PRE_LINK_STA */