Path: blob/master/ALFA-W1F1/RTL8814AU/core/rtw_sta_mgt.c
1307 views
/******************************************************************************1*2* Copyright(c) 2007 - 2019 Realtek Corporation.3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of version 2 of the GNU General Public License as6* published by the Free Software Foundation.7*8* This program is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13*****************************************************************************/14#define _RTW_STA_MGT_C_1516#include <drv_types.h>1718bool test_st_match_rule(_adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port)19{20if (ntohs(*((u16 *)local_port)) == 5001 || ntohs(*((u16 *)remote_port)) == 5001)21return _TRUE;22return _FALSE;23}2425struct st_register test_st_reg = {26.s_proto = 0x06,27.rule = test_st_match_rule,28};2930inline void rtw_st_ctl_init(struct st_ctl_t *st_ctl)31{32_rtw_memset(st_ctl->reg, 0 , sizeof(struct st_register) * SESSION_TRACKER_REG_ID_NUM);33_rtw_init_queue(&st_ctl->tracker_q);34}3536inline void rtw_st_ctl_clear_tracker_q(struct st_ctl_t *st_ctl)37{38_irqL irqL;39_list *plist, *phead;40struct session_tracker *st;4142_enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);43phead = &st_ctl->tracker_q.queue;44plist = get_next(phead);45while (rtw_end_of_queue_search(phead, plist) == _FALSE) {46st = LIST_CONTAINOR(plist, struct session_tracker, list);47plist = get_next(plist);48rtw_list_delete(&st->list);49rtw_mfree((u8 *)st, sizeof(struct session_tracker));50}51_exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);52}5354inline void rtw_st_ctl_deinit(struct st_ctl_t *st_ctl)55{56rtw_st_ctl_clear_tracker_q(st_ctl);57_rtw_deinit_queue(&st_ctl->tracker_q);58}5960inline void rtw_st_ctl_register(struct st_ctl_t *st_ctl, u8 st_reg_id, struct st_register *reg)61{62if (st_reg_id >= SESSION_TRACKER_REG_ID_NUM) {63rtw_warn_on(1);64return;65}6667st_ctl->reg[st_reg_id].s_proto = reg->s_proto;68st_ctl->reg[st_reg_id].rule = reg->rule;69}7071inline void rtw_st_ctl_unregister(struct st_ctl_t *st_ctl, u8 st_reg_id)72{73int i;7475if (st_reg_id >= SESSION_TRACKER_REG_ID_NUM) {76rtw_warn_on(1);77return;78}7980st_ctl->reg[st_reg_id].s_proto = 0;81st_ctl->reg[st_reg_id].rule = NULL;8283/* clear tracker queue if no session trecker registered */84for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++)85if (st_ctl->reg[i].s_proto != 0)86break;87if (i >= SESSION_TRACKER_REG_ID_NUM)88rtw_st_ctl_clear_tracker_q(st_ctl);89}9091inline bool rtw_st_ctl_chk_reg_s_proto(struct st_ctl_t *st_ctl, u8 s_proto)92{93bool ret = _FALSE;94int i;9596for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++) {97if (st_ctl->reg[i].s_proto == s_proto) {98ret = _TRUE;99break;100}101}102103return ret;104}105106inline 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)107{108bool ret = _FALSE;109int i;110st_match_rule rule;111112for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++) {113rule = st_ctl->reg[i].rule;114if (rule && rule(adapter, local_naddr, local_port, remote_naddr, remote_port) == _TRUE) {115ret = _TRUE;116break;117}118}119120return ret;121}122123void rtw_st_ctl_rx(struct sta_info *sta, u8 *ehdr_pos)124{125_adapter *adapter = sta->padapter;126struct ethhdr *etherhdr = (struct ethhdr *)ehdr_pos;127128if (ntohs(etherhdr->h_proto) == ETH_P_IP) {129u8 *ip = ehdr_pos + ETH_HLEN;130131if (GET_IPV4_PROTOCOL(ip) == 0x06 /* TCP */132&& rtw_st_ctl_chk_reg_s_proto(&sta->st_ctl, 0x06) == _TRUE133) {134u8 *tcp = ip + GET_IPV4_IHL(ip) * 4;135136if (rtw_st_ctl_chk_reg_rule(&sta->st_ctl, adapter, IPV4_DST(ip), TCP_DST(tcp), IPV4_SRC(ip), TCP_SRC(tcp)) == _TRUE) {137if (GET_TCP_SYN(tcp) && GET_TCP_ACK(tcp)) {138session_tracker_add_cmd(adapter, sta139, IPV4_DST(ip), TCP_DST(tcp)140, IPV4_SRC(ip), TCP_SRC(tcp));141if (DBG_SESSION_TRACKER)142RTW_INFO(FUNC_ADPT_FMT" local:"IP_FMT":"PORT_FMT", remote:"IP_FMT":"PORT_FMT" SYN-ACK\n"143, FUNC_ADPT_ARG(adapter)144, IP_ARG(IPV4_DST(ip)), PORT_ARG(TCP_DST(tcp))145, IP_ARG(IPV4_SRC(ip)), PORT_ARG(TCP_SRC(tcp)));146}147if (GET_TCP_FIN(tcp)) {148session_tracker_del_cmd(adapter, sta149, IPV4_DST(ip), TCP_DST(tcp)150, IPV4_SRC(ip), TCP_SRC(tcp));151if (DBG_SESSION_TRACKER)152RTW_INFO(FUNC_ADPT_FMT" local:"IP_FMT":"PORT_FMT", remote:"IP_FMT":"PORT_FMT" FIN\n"153, FUNC_ADPT_ARG(adapter)154, IP_ARG(IPV4_DST(ip)), PORT_ARG(TCP_DST(tcp))155, IP_ARG(IPV4_SRC(ip)), PORT_ARG(TCP_SRC(tcp)));156}157}158159}160}161}162163#define SESSION_TRACKER_FMT IP_FMT":"PORT_FMT" "IP_FMT":"PORT_FMT" %u %d"164#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)165166void dump_st_ctl(void *sel, struct st_ctl_t *st_ctl)167{168int i;169_irqL irqL;170_list *plist, *phead;171struct session_tracker *st;172173if (!DBG_SESSION_TRACKER)174return;175176for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++)177RTW_PRINT_SEL(sel, "reg%d: %u %p\n", i, st_ctl->reg[i].s_proto, st_ctl->reg[i].rule);178179_enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);180phead = &st_ctl->tracker_q.queue;181plist = get_next(phead);182while (rtw_end_of_queue_search(phead, plist) == _FALSE) {183st = LIST_CONTAINOR(plist, struct session_tracker, list);184plist = get_next(plist);185186RTW_PRINT_SEL(sel, SESSION_TRACKER_FMT"\n", SESSION_TRACKER_ARG(st));187}188_exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);189190}191192void _rtw_init_stainfo(struct sta_info *psta);193void _rtw_init_stainfo(struct sta_info *psta)194{195_rtw_memset((u8 *)psta, 0, sizeof(struct sta_info));196197_rtw_spinlock_init(&psta->lock);198_rtw_init_listhead(&psta->list);199_rtw_init_listhead(&psta->hash_list);200/* _rtw_init_listhead(&psta->asoc_list); */201/* _rtw_init_listhead(&psta->sleep_list); */202/* _rtw_init_listhead(&psta->wakeup_list); */203204_rtw_init_queue(&psta->sleep_q);205206_rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);207_rtw_init_sta_recv_priv(&psta->sta_recvpriv);208209#ifdef CONFIG_AP_MODE210_rtw_init_listhead(&psta->asoc_list);211_rtw_init_listhead(&psta->auth_list);212psta->bpairwise_key_installed = _FALSE;213214#ifdef CONFIG_RTW_80211R215psta->ft_pairwise_key_installed = _FALSE;216#endif217#endif /* CONFIG_AP_MODE */218219rtw_st_ctl_init(&psta->st_ctl);220}221222u32 _rtw_init_sta_priv(struct sta_priv *pstapriv)223{224_adapter *adapter = container_of(pstapriv, _adapter, stapriv);225struct macid_ctl_t *macid_ctl = adapter_to_macidctl(adapter);226struct sta_info *psta;227s32 i;228u32 ret = _FAIL;229230pstapriv->padapter = adapter;231232pstapriv->pallocated_stainfo_buf = rtw_zvmalloc(233sizeof(struct sta_info) * NUM_STA + MEM_ALIGNMENT_OFFSET);234if (!pstapriv->pallocated_stainfo_buf)235goto exit;236237pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf;238if ((SIZE_PTR)pstapriv->pstainfo_buf & MEM_ALIGNMENT_PADDING)239pstapriv->pstainfo_buf += MEM_ALIGNMENT_OFFSET -240((SIZE_PTR)pstapriv->pstainfo_buf & MEM_ALIGNMENT_PADDING);241242_rtw_init_queue(&pstapriv->free_sta_queue);243244_rtw_spinlock_init(&pstapriv->sta_hash_lock);245246/* _rtw_init_queue(&pstapriv->asoc_q); */247pstapriv->asoc_sta_count = 0;248_rtw_init_queue(&pstapriv->sleep_q);249_rtw_init_queue(&pstapriv->wakeup_q);250251psta = (struct sta_info *)(pstapriv->pstainfo_buf);252253254for (i = 0; i < NUM_STA; i++) {255_rtw_init_stainfo(psta);256257_rtw_init_listhead(&(pstapriv->sta_hash[i]));258259rtw_list_insert_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue));260261psta++;262}263264pstapriv->adhoc_expire_to = 4; /* 4 * 2 = 8 sec */265266#ifdef CONFIG_AP_MODE267pstapriv->max_aid = macid_ctl->num;268pstapriv->rr_aid = 0;269pstapriv->started_aid = 1;270pstapriv->sta_aid = rtw_zmalloc(pstapriv->max_aid * sizeof(struct sta_info *));271if (!pstapriv->sta_aid)272goto exit;273pstapriv->aid_bmp_len = AID_BMP_LEN(pstapriv->max_aid);274pstapriv->sta_dz_bitmap = rtw_zmalloc(pstapriv->aid_bmp_len);275if (!pstapriv->sta_dz_bitmap)276goto exit;277pstapriv->tim_bitmap = rtw_zmalloc(pstapriv->aid_bmp_len);278if (!pstapriv->tim_bitmap)279goto exit;280281_rtw_init_listhead(&pstapriv->asoc_list);282_rtw_init_listhead(&pstapriv->auth_list);283_rtw_spinlock_init(&pstapriv->asoc_list_lock);284_rtw_spinlock_init(&pstapriv->auth_list_lock);285pstapriv->asoc_list_cnt = 0;286pstapriv->auth_list_cnt = 0;287288pstapriv->auth_to = 3; /* 3*2 = 6 sec */289pstapriv->assoc_to = 3;290/* pstapriv->expire_to = 900; */ /* 900*2 = 1800 sec = 30 min, expire after no any traffic. */291/* pstapriv->expire_to = 30; */ /* 30*2 = 60 sec = 1 min, expire after no any traffic. */292#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK293pstapriv->expire_to = 3; /* 3*2 = 6 sec */294#else295pstapriv->expire_to = 60;/* 60*2 = 120 sec = 2 min, expire after no any traffic. */296#endif297#ifdef CONFIG_ATMEL_RC_PATCH298_rtw_memset(pstapriv->atmel_rc_pattern, 0, ETH_ALEN);299#endif300pstapriv->max_num_sta = NUM_STA;301302#endif303304#if CONFIG_RTW_MACADDR_ACL305for (i = 0; i < RTW_ACL_PERIOD_NUM; i++)306rtw_macaddr_acl_init(adapter, i);307#endif308309#if CONFIG_RTW_PRE_LINK_STA310rtw_pre_link_sta_ctl_init(pstapriv);311#endif312313#if defined(DBG_ROAMING_TEST) || defined(CONFIG_RTW_REPEATER_SON)314rtw_set_rx_chk_limit(adapter,1);315#elif defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && !defined(CONFIG_LPS_LCLK_WD_TIMER)316rtw_set_rx_chk_limit(adapter,4);317#else318rtw_set_rx_chk_limit(adapter,8);319#endif320321ret = _SUCCESS;322323exit:324if (ret != _SUCCESS) {325if (pstapriv->pallocated_stainfo_buf)326rtw_vmfree(pstapriv->pallocated_stainfo_buf,327sizeof(struct sta_info) * NUM_STA + MEM_ALIGNMENT_OFFSET);328#ifdef CONFIG_AP_MODE329if (pstapriv->sta_aid)330rtw_mfree(pstapriv->sta_aid, pstapriv->max_aid * sizeof(struct sta_info *));331if (pstapriv->sta_dz_bitmap)332rtw_mfree(pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len);333#endif334}335336return ret;337}338339inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)340{341int offset = (((u8 *)sta) - stapriv->pstainfo_buf) / sizeof(struct sta_info);342343if (!stainfo_offset_valid(offset))344RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);345346return offset;347}348349inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)350{351if (!stainfo_offset_valid(offset))352RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);353354return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));355}356357void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv);358void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv)359{360361_rtw_spinlock_free(&psta_xmitpriv->lock);362363_rtw_spinlock_free(&(psta_xmitpriv->be_q.sta_pending.lock));364_rtw_spinlock_free(&(psta_xmitpriv->bk_q.sta_pending.lock));365_rtw_spinlock_free(&(psta_xmitpriv->vi_q.sta_pending.lock));366_rtw_spinlock_free(&(psta_xmitpriv->vo_q.sta_pending.lock));367}368369static void _rtw_free_sta_recv_priv_lock(struct sta_recv_priv *psta_recvpriv)370{371372_rtw_spinlock_free(&psta_recvpriv->lock);373374_rtw_spinlock_free(&(psta_recvpriv->defrag_q.lock));375376377}378379void rtw_mfree_stainfo(struct sta_info *psta);380void rtw_mfree_stainfo(struct sta_info *psta)381{382383if (&psta->lock != NULL)384_rtw_spinlock_free(&psta->lock);385386_rtw_free_sta_xmit_priv_lock(&psta->sta_xmitpriv);387_rtw_free_sta_recv_priv_lock(&psta->sta_recvpriv);388389}390391392/* this function is used to free the memory of lock || sema for all stainfos */393void rtw_mfree_all_stainfo(struct sta_priv *pstapriv);394void rtw_mfree_all_stainfo(struct sta_priv *pstapriv)395{396_irqL irqL;397_list *plist, *phead;398struct sta_info *psta = NULL;399400401_enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);402403phead = get_list_head(&pstapriv->free_sta_queue);404plist = get_next(phead);405406while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {407psta = LIST_CONTAINOR(plist, struct sta_info , list);408plist = get_next(plist);409410rtw_mfree_stainfo(psta);411}412413_exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);414415416}417418void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv);419void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv)420{421rtw_mfree_all_stainfo(pstapriv); /* be done before free sta_hash_lock */422423_rtw_spinlock_free(&pstapriv->free_sta_queue.lock);424425_rtw_spinlock_free(&pstapriv->sta_hash_lock);426_rtw_spinlock_free(&pstapriv->wakeup_q.lock);427_rtw_spinlock_free(&pstapriv->sleep_q.lock);428429#ifdef CONFIG_AP_MODE430_rtw_spinlock_free(&pstapriv->asoc_list_lock);431_rtw_spinlock_free(&pstapriv->auth_list_lock);432#endif433434}435436u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)437{438_irqL irqL;439_list *phead, *plist;440struct sta_info *psta = NULL;441struct recv_reorder_ctrl *preorder_ctrl;442int index;443444if (pstapriv) {445446/* delete all reordering_ctrl_timer */447_enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);448for (index = 0; index < NUM_STA; index++) {449phead = &(pstapriv->sta_hash[index]);450plist = get_next(phead);451452while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {453int i;454psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);455plist = get_next(plist);456457for (i = 0; i < 16 ; i++) {458preorder_ctrl = &psta->recvreorder_ctrl[i];459_cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);460}461}462}463_exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);464/*===============================*/465466rtw_mfree_sta_priv_lock(pstapriv);467468#if CONFIG_RTW_MACADDR_ACL469for (index = 0; index < RTW_ACL_PERIOD_NUM; index++)470rtw_macaddr_acl_deinit(pstapriv->padapter, index);471#endif472473#if CONFIG_RTW_PRE_LINK_STA474rtw_pre_link_sta_ctl_deinit(pstapriv);475#endif476477if (pstapriv->pallocated_stainfo_buf)478rtw_vmfree(pstapriv->pallocated_stainfo_buf,479sizeof(struct sta_info) * NUM_STA + MEM_ALIGNMENT_OFFSET);480#ifdef CONFIG_AP_MODE481if (pstapriv->sta_aid)482rtw_mfree(pstapriv->sta_aid, pstapriv->max_aid * sizeof(struct sta_info *));483if (pstapriv->sta_dz_bitmap)484rtw_mfree(pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len);485if (pstapriv->tim_bitmap)486rtw_mfree(pstapriv->tim_bitmap, pstapriv->aid_bmp_len);487#endif488}489490return _SUCCESS;491}492493494static void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)495{496_adapter *padapter = preorder_ctrl->padapter;497498#if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)499rtw_init_timer(&(preorder_ctrl->reordering_ctrl_timer), padapter, rtw_reordering_ctrl_timeout_handler, preorder_ctrl);500#endif501}502503/* struct sta_info *rtw_alloc_stainfo(_queue *pfree_sta_queue, unsigned char *hwaddr) */504struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr)505{506_irqL irqL2;507s32 index;508_list *phash_list;509struct sta_info *psta;510_queue *pfree_sta_queue;511struct recv_reorder_ctrl *preorder_ctrl;512int i = 0;513u16 wRxSeqInitialValue = 0xffff;514515516pfree_sta_queue = &pstapriv->free_sta_queue;517518/* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL); */519_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);520if (_rtw_queue_empty(pfree_sta_queue) == _TRUE) {521/* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */522_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);523psta = NULL;524} else {525psta = LIST_CONTAINOR(get_next(&pfree_sta_queue->queue), struct sta_info, list);526527rtw_list_delete(&(psta->list));528529/* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */530_rtw_init_stainfo(psta);531532psta->padapter = pstapriv->padapter;533534_rtw_memcpy(psta->cmn.mac_addr, hwaddr, ETH_ALEN);535536index = wifi_mac_hash(hwaddr);537538539if (index >= NUM_STA) {540psta = NULL;541goto exit;542}543phash_list = &(pstapriv->sta_hash[index]);544545/* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */546547rtw_list_insert_tail(&psta->hash_list, phash_list);548549pstapriv->asoc_sta_count++;550551/* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */552553/* Commented by Albert 2009/08/13554* For the SMC router, the sequence number of first packet of WPS handshake will be 0.555* 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.556* So, we initialize the tid_rxseq variable as the 0xffff. */557558for (i = 0; i < 16; i++) {559_rtw_memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], &wRxSeqInitialValue, 2);560_rtw_memcpy(&psta->sta_recvpriv.bmc_tid_rxseq[i], &wRxSeqInitialValue, 2);561_rtw_memset(&psta->sta_recvpriv.rxcache.iv[i], 0, sizeof(psta->sta_recvpriv.rxcache.iv[i]));562}563564rtw_init_timer(&psta->addba_retry_timer, psta->padapter, addba_timer_hdl, psta);565#ifdef CONFIG_IEEE80211W566rtw_init_timer(&psta->dot11w_expire_timer, psta->padapter, sa_query_timer_hdl, psta);567#endif /* CONFIG_IEEE80211W */568#ifdef CONFIG_TDLS569rtw_init_tdls_timer(pstapriv->padapter, psta);570#endif /* CONFIG_TDLS */571572/* for A-MPDU Rx reordering buffer control */573for (i = 0; i < 16 ; i++) {574preorder_ctrl = &psta->recvreorder_ctrl[i];575preorder_ctrl->padapter = pstapriv->padapter;576preorder_ctrl->tid = i;577preorder_ctrl->enable = _FALSE;578preorder_ctrl->indicate_seq = 0xffff;579#ifdef DBG_RX_SEQ580RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" tid:%u SN_CLEAR indicate_seq:%d\n"581, FUNC_ADPT_ARG(pstapriv->padapter), i, preorder_ctrl->indicate_seq);582#endif583preorder_ctrl->wend_b = 0xffff;584/* preorder_ctrl->wsize_b = (NR_RECVBUFF-2); */585preorder_ctrl->wsize_b = 64;/* 64; */586preorder_ctrl->ampdu_size = RX_AMPDU_SIZE_INVALID;587588_rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);589590rtw_init_recv_timer(preorder_ctrl);591rtw_clear_bit(RTW_RECV_ACK_OR_TIMEOUT, &preorder_ctrl->rec_abba_rsp_ack);592593}594595596/* init for DM */597psta->cmn.rssi_stat.rssi = (-1);598psta->cmn.rssi_stat.rssi_cck = (-1);599psta->cmn.rssi_stat.rssi_ofdm = (-1);600#ifdef CONFIG_ATMEL_RC_PATCH601psta->flag_atmel_rc = 0;602#endif603/* init for the sequence number of received management frame */604psta->RxMgmtFrameSeqNum = 0xffff;605_rtw_memset(&psta->sta_stats, 0, sizeof(struct stainfo_stats));606607rtw_alloc_macid(pstapriv->padapter, psta);608609psta->tx_q_enable = 0;610_rtw_init_queue(&psta->tx_queue);611_init_workitem(&psta->tx_q_work, rtw_xmit_dequeue_callback, NULL);612}613614exit:615616_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);617618619if (psta)620rtw_mi_update_iface_status(&(pstapriv->padapter->mlmepriv), 0);621622return psta;623}624625626/* using pstapriv->sta_hash_lock to protect */627u32 rtw_free_stainfo(_adapter *padapter , struct sta_info *psta)628{629int i;630_irqL irqL0;631_queue *pfree_sta_queue;632struct recv_reorder_ctrl *preorder_ctrl;633struct sta_xmit_priv *pstaxmitpriv;634struct xmit_priv *pxmitpriv = &padapter->xmitpriv;635struct sta_priv *pstapriv = &padapter->stapriv;636struct hw_xmit *phwxmit;637struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;638struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);639640int pending_qcnt[4];641u8 is_pre_link_sta = _FALSE;642643if (psta == NULL)644goto exit;645646#ifdef CONFIG_RTW_80211K647rm_post_event(padapter, RM_ID_FOR_ALL(psta->cmn.aid), RM_EV_cancel);648#endif649650is_pre_link_sta = rtw_is_pre_link_sta(pstapriv, psta->cmn.mac_addr);651652if (is_pre_link_sta == _FALSE) {653_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);654rtw_list_delete(&psta->hash_list);655pstapriv->asoc_sta_count--;656_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);657rtw_mi_update_iface_status(&(padapter->mlmepriv), 0);658} else {659_enter_critical_bh(&psta->lock, &irqL0);660psta->state = WIFI_FW_PRE_LINK;661_exit_critical_bh(&psta->lock, &irqL0);662}663664_enter_critical_bh(&psta->lock, &irqL0);665psta->state &= ~_FW_LINKED;666_exit_critical_bh(&psta->lock, &irqL0);667668pfree_sta_queue = &pstapriv->free_sta_queue;669670671pstaxmitpriv = &psta->sta_xmitpriv;672673/* rtw_list_delete(&psta->sleep_list); */674675/* rtw_list_delete(&psta->wakeup_list); */676677rtw_free_xmitframe_queue(pxmitpriv, &psta->tx_queue);678_rtw_deinit_queue(&psta->tx_queue);679680_enter_critical_bh(&pxmitpriv->lock, &irqL0);681682rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);683psta->sleepq_len = 0;684685/* vo */686/* _enter_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */687rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);688rtw_list_delete(&(pstaxmitpriv->vo_q.tx_pending));689phwxmit = pxmitpriv->hwxmits;690phwxmit->accnt -= pstaxmitpriv->vo_q.qcnt;691pending_qcnt[0] = pstaxmitpriv->vo_q.qcnt;692pstaxmitpriv->vo_q.qcnt = 0;693/* _exit_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */694695/* vi */696/* _enter_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */697rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);698rtw_list_delete(&(pstaxmitpriv->vi_q.tx_pending));699phwxmit = pxmitpriv->hwxmits + 1;700phwxmit->accnt -= pstaxmitpriv->vi_q.qcnt;701pending_qcnt[1] = pstaxmitpriv->vi_q.qcnt;702pstaxmitpriv->vi_q.qcnt = 0;703/* _exit_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */704705/* be */706/* _enter_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */707rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);708rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));709phwxmit = pxmitpriv->hwxmits + 2;710phwxmit->accnt -= pstaxmitpriv->be_q.qcnt;711pending_qcnt[2] = pstaxmitpriv->be_q.qcnt;712pstaxmitpriv->be_q.qcnt = 0;713/* _exit_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */714715/* bk */716/* _enter_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */717rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);718rtw_list_delete(&(pstaxmitpriv->bk_q.tx_pending));719phwxmit = pxmitpriv->hwxmits + 3;720phwxmit->accnt -= pstaxmitpriv->bk_q.qcnt;721pending_qcnt[3] = pstaxmitpriv->bk_q.qcnt;722pstaxmitpriv->bk_q.qcnt = 0;723/* _exit_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */724725rtw_os_wake_queue_at_free_stainfo(padapter, pending_qcnt);726727_exit_critical_bh(&pxmitpriv->lock, &irqL0);728729730/* re-init sta_info; 20061114 */ /* will be init in alloc_stainfo */731/* _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv); */732/* _rtw_init_sta_recv_priv(&psta->sta_recvpriv); */733#ifdef CONFIG_IEEE80211W734_cancel_timer_ex(&psta->dot11w_expire_timer);735#endif /* CONFIG_IEEE80211W */736_cancel_timer_ex(&psta->addba_retry_timer);737738#ifdef CONFIG_TDLS739psta->tdls_sta_state = TDLS_STATE_NONE;740#endif /* CONFIG_TDLS */741742/* for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer */743for (i = 0; i < 16 ; i++) {744_irqL irqL;745_list *phead, *plist;746union recv_frame *prframe;747_queue *ppending_recvframe_queue;748_queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;749750preorder_ctrl = &psta->recvreorder_ctrl[i];751rtw_clear_bit(RTW_RECV_ACK_OR_TIMEOUT, &preorder_ctrl->rec_abba_rsp_ack);752753_cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);754755756ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;757758_enter_critical_bh(&ppending_recvframe_queue->lock, &irqL);759760phead = get_list_head(ppending_recvframe_queue);761plist = get_next(phead);762763while (!rtw_is_list_empty(phead)) {764prframe = LIST_CONTAINOR(plist, union recv_frame, u);765766plist = get_next(plist);767768rtw_list_delete(&(prframe->u.hdr.list));769770rtw_free_recvframe(prframe, pfree_recv_queue);771}772773_exit_critical_bh(&ppending_recvframe_queue->lock, &irqL);774775}776777if (!((psta->state & WIFI_AP_STATE) || MacAddr_isBcst(psta->cmn.mac_addr)) && is_pre_link_sta == _FALSE)778rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _FALSE);779780781/* release mac id for non-bc/mc station, */782if (is_pre_link_sta == _FALSE)783rtw_release_macid(pstapriv->padapter, psta);784785#ifdef CONFIG_AP_MODE786787/*788_enter_critical_bh(&pstapriv->asoc_list_lock, &irqL0);789rtw_list_delete(&psta->asoc_list);790_exit_critical_bh(&pstapriv->asoc_list_lock, &irqL0);791*/792_enter_critical_bh(&pstapriv->auth_list_lock, &irqL0);793if (!rtw_is_list_empty(&psta->auth_list)) {794rtw_list_delete(&psta->auth_list);795pstapriv->auth_list_cnt--;796}797_exit_critical_bh(&pstapriv->auth_list_lock, &irqL0);798799psta->expire_to = 0;800#ifdef CONFIG_ATMEL_RC_PATCH801psta->flag_atmel_rc = 0;802#endif803psta->sleepq_ac_len = 0;804psta->qos_info = 0;805806psta->max_sp_len = 0;807psta->uapsd_bk = 0;808psta->uapsd_be = 0;809psta->uapsd_vi = 0;810psta->uapsd_vo = 0;811812psta->has_legacy_ac = 0;813814#ifdef CONFIG_NATIVEAP_MLME815816if (pmlmeinfo->state == _HW_STATE_AP_) {817rtw_tim_map_clear(padapter, pstapriv->sta_dz_bitmap, psta->cmn.aid);818rtw_tim_map_clear(padapter, pstapriv->tim_bitmap, psta->cmn.aid);819820/* rtw_indicate_sta_disassoc_event(padapter, psta); */821822if ((psta->cmn.aid > 0) && (pstapriv->sta_aid[psta->cmn.aid - 1] == psta)) {823pstapriv->sta_aid[psta->cmn.aid - 1] = NULL;824psta->cmn.aid = 0;825}826}827828#endif /* CONFIG_NATIVEAP_MLME */829830#ifdef CONFIG_TX_MCAST2UNI831psta->under_exist_checking = 0;832#endif /* CONFIG_TX_MCAST2UNI */833834#endif /* CONFIG_AP_MODE */835836rtw_st_ctl_deinit(&psta->st_ctl);837838if (is_pre_link_sta == _FALSE) {839_rtw_spinlock_free(&psta->lock);840841/* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL0); */842_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);843rtw_list_insert_tail(&psta->list, get_list_head(pfree_sta_queue));844_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);845/* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL0); */846}847848exit:849return _SUCCESS;850}851852/* free all stainfo which in sta_hash[all] */853void rtw_free_all_stainfo(_adapter *padapter)854{855_irqL irqL;856_list *plist, *phead;857s32 index;858struct sta_info *psta = NULL;859struct sta_priv *pstapriv = &padapter->stapriv;860struct sta_info *pbcmc_stainfo = rtw_get_bcmc_stainfo(padapter);861u8 free_sta_num = 0;862char free_sta_list[NUM_STA];863int stainfo_offset;864865866if (pstapriv->asoc_sta_count == 1)867goto exit;868869_enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);870871for (index = 0; index < NUM_STA; index++) {872phead = &(pstapriv->sta_hash[index]);873plist = get_next(phead);874875while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {876psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);877878plist = get_next(plist);879880if (pbcmc_stainfo != psta) {881if (rtw_is_pre_link_sta(pstapriv, psta->cmn.mac_addr) == _FALSE)882rtw_list_delete(&psta->hash_list);883884stainfo_offset = rtw_stainfo_offset(pstapriv, psta);885if (stainfo_offset_valid(stainfo_offset))886free_sta_list[free_sta_num++] = stainfo_offset;887}888889}890}891892_exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);893894895for (index = 0; index < free_sta_num; index++) {896psta = rtw_get_stainfo_by_offset(pstapriv, free_sta_list[index]);897rtw_free_stainfo(padapter , psta);898}899900exit:901return;902}903904/* any station allocated can be searched by hash list */905struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr)906{907908_irqL irqL;909910_list *plist, *phead;911912struct sta_info *psta = NULL;913914u32 index;915916const u8 *addr;917918u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};919920921if (hwaddr == NULL)922return NULL;923924if (IS_MCAST(hwaddr))925addr = bc_addr;926else927addr = hwaddr;928929index = wifi_mac_hash(addr);930931_enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);932933phead = &(pstapriv->sta_hash[index]);934plist = get_next(phead);935936937while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {938939psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);940941if ((_rtw_memcmp(psta->cmn.mac_addr, addr, ETH_ALEN)) == _TRUE) {942/* if found the matched address */943break;944}945psta = NULL;946plist = get_next(plist);947}948949_exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);950return psta;951952}953954u32 rtw_init_bcmc_stainfo(_adapter *padapter)955{956957struct sta_info *psta;958struct tx_servq *ptxservq;959u32 res = _SUCCESS;960NDIS_802_11_MAC_ADDRESS bcast_addr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};961962struct sta_priv *pstapriv = &padapter->stapriv;963/* _queue *pstapending = &padapter->xmitpriv.bm_pending; */964965966psta = rtw_alloc_stainfo(pstapriv, bcast_addr);967968if (psta == NULL) {969res = _FAIL;970goto exit;971}972#ifdef CONFIG_BEAMFORMING973psta->cmn.bf_info.g_id = 63;974psta->cmn.bf_info.p_aid = 0;975#endif976977ptxservq = &(psta->sta_xmitpriv.be_q);978979/*980_enter_critical(&pstapending->lock, &irqL0);981982if (rtw_is_list_empty(&ptxservq->tx_pending))983rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(pstapending));984985_exit_critical(&pstapending->lock, &irqL0);986*/987988exit:989return _SUCCESS;990991}992993994struct sta_info *rtw_get_bcmc_stainfo(_adapter *padapter)995{996struct sta_info *psta;997struct sta_priv *pstapriv = &padapter->stapriv;998u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};999psta = rtw_get_stainfo(pstapriv, bc_addr);1000return psta;10011002}10031004#ifdef CONFIG_AP_MODE1005u16 rtw_aid_alloc(_adapter *adapter, struct sta_info *sta)1006{1007struct sta_priv *stapriv = &adapter->stapriv;1008u16 aid, i, used_cnt = 0;10091010for (i = 0; i < stapriv->max_aid; i++) {1011aid = ((i + stapriv->started_aid - 1) % stapriv->max_aid) + 1;1012if (stapriv->sta_aid[aid - 1] == NULL)1013break;1014if (++used_cnt >= stapriv->max_num_sta)1015break;1016}10171018/* check for aid limit and assoc limit */1019if (i >= stapriv->max_aid || used_cnt >= stapriv->max_num_sta)1020aid = 0;10211022sta->cmn.aid = aid;1023if (aid) {1024stapriv->sta_aid[aid - 1] = sta;1025if (stapriv->rr_aid)1026stapriv->started_aid = (aid % stapriv->max_aid) + 1;1027}10281029return aid;1030}10311032void dump_aid_status(void *sel, _adapter *adapter)1033{1034struct sta_priv *stapriv = &adapter->stapriv;1035u8 *aid_bmp;1036u16 i, used_cnt = 0;10371038aid_bmp = rtw_zmalloc(stapriv->aid_bmp_len);1039if (!aid_bmp)1040return;10411042for (i = 1; i <= stapriv->max_aid; i++) {1043if (stapriv->sta_aid[i - 1]) {1044aid_bmp[i / 8] |= BIT(i % 8);1045++used_cnt;1046}1047}10481049RTW_PRINT_SEL(sel, "used_cnt:%u/%u\n", used_cnt, stapriv->max_aid);1050RTW_MAP_DUMP_SEL(sel, "aid_map:", aid_bmp, stapriv->aid_bmp_len);1051RTW_PRINT_SEL(sel, "\n");10521053RTW_PRINT_SEL(sel, "%-2s %-11s\n", "rr", "started_aid");1054RTW_PRINT_SEL(sel, "%2d %11d\n", stapriv->rr_aid, stapriv->started_aid);10551056rtw_mfree(aid_bmp, stapriv->aid_bmp_len);1057}1058#endif /* CONFIG_AP_MODE */10591060#if CONFIG_RTW_MACADDR_ACL1061const char *const _acl_period_str[RTW_ACL_PERIOD_NUM] = {1062"DEV",1063"BSS",1064};10651066const char *const _acl_mode_str[RTW_ACL_MODE_MAX] = {1067"DISABLED",1068"ACCEPT_UNLESS_LISTED",1069"DENY_UNLESS_LISTED",1070};10711072u8 _rtw_access_ctrl(_adapter *adapter, u8 period, const u8 *mac_addr)1073{1074u8 res = _TRUE;1075_irqL irqL;1076_list *list, *head;1077struct rtw_wlan_acl_node *acl_node;1078u8 match = _FALSE;1079struct sta_priv *stapriv = &adapter->stapriv;1080struct wlan_acl_pool *acl;1081_queue *acl_node_q;10821083if (period >= RTW_ACL_PERIOD_NUM) {1084rtw_warn_on(1);1085goto exit;1086}10871088acl = &stapriv->acl_list[period];1089acl_node_q = &acl->acl_node_q;10901091if (acl->mode != RTW_ACL_MODE_ACCEPT_UNLESS_LISTED1092&& acl->mode != RTW_ACL_MODE_DENY_UNLESS_LISTED)1093goto exit;10941095_enter_critical_bh(&(acl_node_q->lock), &irqL);1096head = get_list_head(acl_node_q);1097list = get_next(head);1098while (rtw_end_of_queue_search(head, list) == _FALSE) {1099acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);1100list = get_next(list);11011102if (_rtw_memcmp(acl_node->addr, mac_addr, ETH_ALEN)) {1103if (acl_node->valid == _TRUE) {1104match = _TRUE;1105break;1106}1107}1108}1109_exit_critical_bh(&(acl_node_q->lock), &irqL);11101111if (acl->mode == RTW_ACL_MODE_ACCEPT_UNLESS_LISTED)1112res = (match == _TRUE) ? _FALSE : _TRUE;1113else /* RTW_ACL_MODE_DENY_UNLESS_LISTED */1114res = (match == _TRUE) ? _TRUE : _FALSE;11151116exit:1117return res;1118}11191120u8 rtw_access_ctrl(_adapter *adapter, const u8 *mac_addr)1121{1122int i;11231124for (i = 0; i < RTW_ACL_PERIOD_NUM; i++)1125if (_rtw_access_ctrl(adapter, i, mac_addr) == _FALSE)1126return _FALSE;11271128return _TRUE;1129}11301131void dump_macaddr_acl(void *sel, _adapter *adapter)1132{1133struct sta_priv *stapriv = &adapter->stapriv;1134struct wlan_acl_pool *acl;1135int i, j;11361137for (j = 0; j < RTW_ACL_PERIOD_NUM; j++) {1138RTW_PRINT_SEL(sel, "period:%s(%d)\n", acl_period_str(j), j);11391140acl = &stapriv->acl_list[j];1141RTW_PRINT_SEL(sel, "mode:%s(%d)\n", acl_mode_str(acl->mode), acl->mode);1142RTW_PRINT_SEL(sel, "num:%d/%d\n", acl->num, NUM_ACL);1143for (i = 0; i < NUM_ACL; i++) {1144if (acl->aclnode[i].valid == _FALSE)1145continue;1146RTW_PRINT_SEL(sel, MAC_FMT"\n", MAC_ARG(acl->aclnode[i].addr));1147}1148RTW_PRINT_SEL(sel, "\n");1149}1150}1151#endif /* CONFIG_RTW_MACADDR_ACL */11521153bool rtw_is_pre_link_sta(struct sta_priv *stapriv, u8 *addr)1154{1155#if CONFIG_RTW_PRE_LINK_STA1156struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;1157struct sta_info *sta = NULL;1158u8 exist = _FALSE;1159int i;1160_irqL irqL;11611162_enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);1163for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {1164if (pre_link_sta_ctl->node[i].valid == _TRUE1165&& _rtw_memcmp(pre_link_sta_ctl->node[i].addr, addr, ETH_ALEN) == _TRUE1166) {1167exist = _TRUE;1168break;1169}1170}1171_exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);11721173return exist;1174#else1175return _FALSE;1176#endif1177}11781179#if CONFIG_RTW_PRE_LINK_STA1180struct sta_info *rtw_pre_link_sta_add(struct sta_priv *stapriv, u8 *hwaddr)1181{1182struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;1183struct pre_link_sta_node_t *node = NULL;1184struct sta_info *sta = NULL;1185u8 exist = _FALSE;1186int i;1187_irqL irqL;11881189if (rtw_check_invalid_mac_address(hwaddr, _FALSE) == _TRUE)1190goto exit;11911192_enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);1193for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {1194if (pre_link_sta_ctl->node[i].valid == _TRUE1195&& _rtw_memcmp(pre_link_sta_ctl->node[i].addr, hwaddr, ETH_ALEN) == _TRUE1196) {1197node = &pre_link_sta_ctl->node[i];1198exist = _TRUE;1199break;1200}12011202if (node == NULL && pre_link_sta_ctl->node[i].valid == _FALSE)1203node = &pre_link_sta_ctl->node[i];1204}12051206if (exist == _FALSE && node) {1207_rtw_memcpy(node->addr, hwaddr, ETH_ALEN);1208node->valid = _TRUE;1209pre_link_sta_ctl->num++;1210}1211_exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);12121213if (node == NULL)1214goto exit;12151216sta = rtw_get_stainfo(stapriv, hwaddr);1217if (sta)1218goto odm_hook;12191220sta = rtw_alloc_stainfo(stapriv, hwaddr);1221if (!sta)1222goto exit;12231224sta->state = WIFI_FW_PRE_LINK;12251226odm_hook:1227rtw_hal_set_odm_var(stapriv->padapter, HAL_ODM_STA_INFO, sta, _TRUE);12281229exit:1230return sta;1231}12321233void rtw_pre_link_sta_del(struct sta_priv *stapriv, u8 *hwaddr)1234{1235struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;1236struct pre_link_sta_node_t *node = NULL;1237struct sta_info *sta = NULL;1238u8 exist = _FALSE;1239int i;1240_irqL irqL;12411242if (rtw_check_invalid_mac_address(hwaddr, _FALSE) == _TRUE)1243goto exit;12441245_enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);1246for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {1247if (pre_link_sta_ctl->node[i].valid == _TRUE1248&& _rtw_memcmp(pre_link_sta_ctl->node[i].addr, hwaddr, ETH_ALEN) == _TRUE1249) {1250node = &pre_link_sta_ctl->node[i];1251exist = _TRUE;1252break;1253}1254}12551256if (exist == _TRUE && node) {1257node->valid = _FALSE;1258pre_link_sta_ctl->num--;1259}1260_exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);12611262if (exist == _FALSE)1263goto exit;12641265sta = rtw_get_stainfo(stapriv, hwaddr);1266if (!sta)1267goto exit;12681269if (sta->state == WIFI_FW_PRE_LINK)1270rtw_free_stainfo(stapriv->padapter, sta);12711272exit:1273return;1274}12751276void rtw_pre_link_sta_ctl_reset(struct sta_priv *stapriv)1277{1278struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;1279struct pre_link_sta_node_t *node = NULL;1280struct sta_info *sta = NULL;1281int i, j = 0;1282_irqL irqL;12831284u8 addrs[RTW_PRE_LINK_STA_NUM][ETH_ALEN];12851286_rtw_memset(addrs, 0, RTW_PRE_LINK_STA_NUM * ETH_ALEN);12871288_enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);1289for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {1290if (pre_link_sta_ctl->node[i].valid == _FALSE)1291continue;1292_rtw_memcpy(&(addrs[j][0]), pre_link_sta_ctl->node[i].addr, ETH_ALEN);1293pre_link_sta_ctl->node[i].valid = _FALSE;1294pre_link_sta_ctl->num--;1295j++;1296}1297_exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);12981299for (i = 0; i < j; i++) {1300sta = rtw_get_stainfo(stapriv, &(addrs[i][0]));1301if (!sta)1302continue;13031304if (sta->state == WIFI_FW_PRE_LINK)1305rtw_free_stainfo(stapriv->padapter, sta);1306}1307}13081309void rtw_pre_link_sta_ctl_init(struct sta_priv *stapriv)1310{1311struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;1312int i;13131314_rtw_spinlock_init(&pre_link_sta_ctl->lock);1315pre_link_sta_ctl->num = 0;1316for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++)1317pre_link_sta_ctl->node[i].valid = _FALSE;1318}13191320void rtw_pre_link_sta_ctl_deinit(struct sta_priv *stapriv)1321{1322struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;1323int i;13241325rtw_pre_link_sta_ctl_reset(stapriv);13261327_rtw_spinlock_free(&pre_link_sta_ctl->lock);1328}13291330void dump_pre_link_sta_ctl(void *sel, struct sta_priv *stapriv)1331{1332struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;1333int i;13341335RTW_PRINT_SEL(sel, "num:%d/%d\n", pre_link_sta_ctl->num, RTW_PRE_LINK_STA_NUM);13361337for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {1338if (pre_link_sta_ctl->node[i].valid == _FALSE)1339continue;1340RTW_PRINT_SEL(sel, MAC_FMT"\n", MAC_ARG(pre_link_sta_ctl->node[i].addr));1341}1342}1343#endif /* CONFIG_RTW_PRE_LINK_STA */1344134513461347