add rk3288 pinctrl dts code
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rtl8723bs / core / rtw_sta_mgt.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *                                        
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.
8  *
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
12  * more details.
13  *
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
17  *
18  *
19  ******************************************************************************/
20 #define _RTW_STA_MGT_C_
21
22 #include <drv_types.h>
23
24 #if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
25
26 #error "Shall be Linux or Windows, but not both!\n"
27
28 #endif
29
30
31 void _rtw_init_stainfo(struct sta_info *psta);
32 void _rtw_init_stainfo(struct sta_info *psta)
33 {
34
35 _func_enter_;
36
37         _rtw_memset((u8 *)psta, 0, sizeof (struct sta_info));
38
39          _rtw_spinlock_init(&psta->lock);
40         _rtw_init_listhead(&psta->list);
41         _rtw_init_listhead(&psta->hash_list);
42         //_rtw_init_listhead(&psta->asoc_list);
43         //_rtw_init_listhead(&psta->sleep_list);
44         //_rtw_init_listhead(&psta->wakeup_list);       
45
46         _rtw_init_queue(&psta->sleep_q);
47         psta->sleepq_len = 0;
48
49         _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
50         _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
51         
52 #ifdef CONFIG_AP_MODE
53
54         _rtw_init_listhead(&psta->asoc_list);
55
56         _rtw_init_listhead(&psta->auth_list);
57         
58         psta->expire_to = 0;
59         
60         psta->flags = 0;
61         
62         psta->capability = 0;
63
64         psta->bpairwise_key_installed = _FALSE;
65
66
67 #ifdef CONFIG_NATIVEAP_MLME
68         psta->nonerp_set = 0;
69         psta->no_short_slot_time_set = 0;
70         psta->no_short_preamble_set = 0;
71         psta->no_ht_gf_set = 0;
72         psta->no_ht_set = 0;
73         psta->ht_20mhz_set = 0;
74 #endif  
75
76 #ifdef CONFIG_TX_MCAST2UNI
77         psta->under_exist_checking = 0;
78 #endif  // CONFIG_TX_MCAST2UNI
79         
80         psta->keep_alive_trycnt = 0;
81
82 #endif  // CONFIG_AP_MODE       
83         
84 _func_exit_;    
85
86 }
87
88 u32     _rtw_init_sta_priv(struct       sta_priv *pstapriv)
89 {
90         struct sta_info *psta;
91         s32 i;
92
93 _func_enter_;   
94
95         pstapriv->pallocated_stainfo_buf = rtw_zvmalloc (sizeof(struct sta_info) * NUM_STA+ 4);
96         
97         if(!pstapriv->pallocated_stainfo_buf)
98                 return _FAIL;
99
100         pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 - 
101                 ((SIZE_PTR)(pstapriv->pallocated_stainfo_buf ) & 3);
102
103         _rtw_init_queue(&pstapriv->free_sta_queue);
104
105         _rtw_spinlock_init(&pstapriv->sta_hash_lock);
106         
107         //_rtw_init_queue(&pstapriv->asoc_q);
108         pstapriv->asoc_sta_count = 0;
109         _rtw_init_queue(&pstapriv->sleep_q);
110         _rtw_init_queue(&pstapriv->wakeup_q);
111
112         psta = (struct sta_info *)(pstapriv->pstainfo_buf);
113
114                 
115         for(i = 0; i < NUM_STA; i++)
116         {
117                 _rtw_init_stainfo(psta);
118
119                 _rtw_init_listhead(&(pstapriv->sta_hash[i]));
120
121                 rtw_list_insert_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue));
122
123                 psta++;
124         }
125
126         
127
128 #ifdef CONFIG_AP_MODE
129
130         pstapriv->sta_dz_bitmap = 0;
131         pstapriv->tim_bitmap = 0;
132
133         _rtw_init_listhead(&pstapriv->asoc_list);
134         _rtw_init_listhead(&pstapriv->auth_list);
135         _rtw_spinlock_init(&pstapriv->asoc_list_lock);
136         _rtw_spinlock_init(&pstapriv->auth_list_lock);
137         pstapriv->asoc_list_cnt = 0;
138         pstapriv->auth_list_cnt = 0;
139
140         pstapriv->auth_to = 3; // 3*2 = 6 sec 
141         pstapriv->assoc_to = 3;
142         //pstapriv->expire_to = 900;// 900*2 = 1800 sec = 30 min, expire after no any traffic.
143         //pstapriv->expire_to = 30;// 30*2 = 60 sec = 1 min, expire after no any traffic.
144 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
145         pstapriv->expire_to = 3; // 3*2 = 6 sec
146 #else
147         pstapriv->expire_to = 60;// 60*2 = 120 sec = 2 min, expire after no any traffic.
148 #endif  
149 #ifdef CONFIG_ATMEL_RC_PATCH
150         _rtw_memset(  pstapriv->atmel_rc_pattern, 0, ETH_ALEN);
151 #endif  
152         pstapriv->max_num_sta = NUM_STA;
153                 
154 #endif
155         
156 _func_exit_;            
157
158         return _SUCCESS;
159         
160 }
161
162 inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)
163 {
164         int offset = (((u8 *)sta) - stapriv->pstainfo_buf)/sizeof(struct sta_info);
165
166         if (!stainfo_offset_valid(offset))
167                 DBG_871X("%s invalid offset(%d), out of range!!!", __func__, offset);
168
169         return offset;
170 }
171
172 inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)
173 {
174         if (!stainfo_offset_valid(offset))
175                 DBG_871X("%s invalid offset(%d), out of range!!!", __func__, offset);
176
177         return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));
178 }
179
180 void    _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv);
181 void    _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv)
182 {
183 _func_enter_;
184
185         _rtw_spinlock_free(&psta_xmitpriv->lock);
186
187         _rtw_spinlock_free(&(psta_xmitpriv->be_q.sta_pending.lock));
188         _rtw_spinlock_free(&(psta_xmitpriv->bk_q.sta_pending.lock));
189         _rtw_spinlock_free(&(psta_xmitpriv->vi_q.sta_pending.lock));
190         _rtw_spinlock_free(&(psta_xmitpriv->vo_q.sta_pending.lock));
191 _func_exit_;    
192 }
193
194 static void     _rtw_free_sta_recv_priv_lock(struct sta_recv_priv *psta_recvpriv)
195 {
196 _func_enter_;   
197
198         _rtw_spinlock_free(&psta_recvpriv->lock);
199
200         _rtw_spinlock_free(&(psta_recvpriv->defrag_q.lock));
201
202 _func_exit_;
203
204 }
205
206 void rtw_mfree_stainfo(struct sta_info *psta);
207 void rtw_mfree_stainfo(struct sta_info *psta)
208 {
209 _func_enter_;
210
211         if(&psta->lock != NULL)
212                  _rtw_spinlock_free(&psta->lock);
213
214         _rtw_free_sta_xmit_priv_lock(&psta->sta_xmitpriv);
215         _rtw_free_sta_recv_priv_lock(&psta->sta_recvpriv);
216         
217 _func_exit_;    
218 }
219
220
221 // this function is used to free the memory of lock || sema for all stainfos
222 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv );
223 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv )
224 {
225         _irqL    irqL;
226         _list   *plist, *phead;
227         struct sta_info *psta = NULL;
228         
229 _func_enter_;   
230
231         _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
232
233         phead = get_list_head(&pstapriv->free_sta_queue);
234         plist = get_next(phead);
235                 
236         while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
237         {
238                 psta = LIST_CONTAINOR(plist, struct sta_info ,list);
239                 plist = get_next(plist);
240
241                 rtw_mfree_stainfo(psta);
242         }
243         
244         _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
245
246 _func_exit_;    
247
248 }
249
250 void rtw_mfree_sta_priv_lock(struct     sta_priv *pstapriv);
251 void rtw_mfree_sta_priv_lock(struct     sta_priv *pstapriv)
252 {
253 #ifdef CONFIG_AP_MODE
254         struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
255 #endif
256
257          rtw_mfree_all_stainfo(pstapriv); //be done before free sta_hash_lock
258
259         _rtw_spinlock_free(&pstapriv->free_sta_queue.lock);
260
261         _rtw_spinlock_free(&pstapriv->sta_hash_lock);
262         _rtw_spinlock_free(&pstapriv->wakeup_q.lock);
263         _rtw_spinlock_free(&pstapriv->sleep_q.lock);
264
265 #ifdef CONFIG_AP_MODE
266         _rtw_spinlock_free(&pstapriv->asoc_list_lock);
267         _rtw_spinlock_free(&pstapriv->auth_list_lock);
268         _rtw_spinlock_free(&pacl_list->acl_node_q.lock);
269 #endif
270
271 }
272
273 u32     _rtw_free_sta_priv(struct       sta_priv *pstapriv)
274 {
275         _irqL   irqL;
276         _list   *phead, *plist;
277         struct sta_info *psta = NULL;
278         struct recv_reorder_ctrl *preorder_ctrl;
279         int     index;
280
281 _func_enter_;
282         if(pstapriv){
283
284                 /*      delete all reordering_ctrl_timer                */ 
285                 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
286                 for(index = 0; index < NUM_STA; index++)
287                 {
288                         phead = &(pstapriv->sta_hash[index]);
289                         plist = get_next(phead);
290                         
291                         while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
292                         {
293                                 int i;  
294                                 psta = LIST_CONTAINOR(plist, struct sta_info ,hash_list);
295                                 plist = get_next(plist);
296
297                                 for(i=0; i < 16 ; i++)
298                                 {
299                                         preorder_ctrl = &psta->recvreorder_ctrl[i];
300                                         _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);        
301                                 }
302                         }
303                 }
304                 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
305                 /*===============================*/
306                 
307                 rtw_mfree_sta_priv_lock(pstapriv);
308
309                 if(pstapriv->pallocated_stainfo_buf) {
310                         rtw_vmfree(pstapriv->pallocated_stainfo_buf, sizeof(struct sta_info)*NUM_STA+4);
311                 }
312         }
313         
314 _func_exit_;
315         return _SUCCESS;
316 }
317
318
319 //struct        sta_info *rtw_alloc_stainfo(_queue *pfree_sta_queue, unsigned char *hwaddr)
320 struct  sta_info *rtw_alloc_stainfo(struct      sta_priv *pstapriv, u8 *hwaddr) 
321 {       
322         _irqL irqL, irqL2;
323         uint tmp_aid;
324         s32     index;
325         _list   *phash_list;
326         struct sta_info *psta;
327         _queue *pfree_sta_queue;
328         struct recv_reorder_ctrl *preorder_ctrl;
329         int i = 0;
330         u16  wRxSeqInitialValue = 0xffff;
331         
332 _func_enter_;   
333
334         pfree_sta_queue = &pstapriv->free_sta_queue;
335
336         //_enter_critical_bh(&(pfree_sta_queue->lock), &irqL);
337         _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
338         if (_rtw_queue_empty(pfree_sta_queue) == _TRUE)
339         {
340                 //_exit_critical_bh(&(pfree_sta_queue->lock), &irqL);
341                 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
342                 psta = NULL;
343         }
344         else
345         {
346                 psta = LIST_CONTAINOR(get_next(&pfree_sta_queue->queue), struct sta_info, list);
347                 
348                 rtw_list_delete(&(psta->list));
349
350                 //_exit_critical_bh(&(pfree_sta_queue->lock), &irqL);
351                 
352                 tmp_aid = psta->aid;    
353         
354                 _rtw_init_stainfo(psta);
355
356                 psta->padapter = pstapriv->padapter;
357
358                 _rtw_memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
359
360                 index = wifi_mac_hash(hwaddr);
361
362                 RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_info_,("rtw_alloc_stainfo: index  = %x", index));
363
364                 if(index >= NUM_STA){
365                         RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_err_,("ERROR=> rtw_alloc_stainfo: index >= NUM_STA"));
366                         psta= NULL;     
367                         goto exit;
368                 }
369                 phash_list = &(pstapriv->sta_hash[index]);
370
371                 //_enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
372
373                 rtw_list_insert_tail(&psta->hash_list, phash_list);
374
375                 pstapriv->asoc_sta_count ++ ;
376
377                 //_exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
378
379 // Commented by Albert 2009/08/13
380 // For the SMC router, the sequence number of first packet of WPS handshake will be 0.
381 // 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.
382 // So, we initialize the tid_rxseq variable as the 0xffff.
383
384                 for( i = 0; i < 16; i++ )
385                 {
386                      _rtw_memcpy( &psta->sta_recvpriv.rxcache.tid_rxseq[ i ], &wRxSeqInitialValue, 2 );
387                 }
388
389                 RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_info_,("alloc number_%d stainfo  with hwaddr = %x %x %x %x %x %x  \n", 
390                 pstapriv->asoc_sta_count , hwaddr[0], hwaddr[1], hwaddr[2],hwaddr[3],hwaddr[4],hwaddr[5]));
391
392                 init_addba_retry_timer(pstapriv->padapter, psta);
393
394 #ifdef CONFIG_TDLS
395                 psta->padapter = pstapriv->padapter;
396                 init_TPK_timer(pstapriv->padapter, psta);
397                 init_ch_switch_timer(pstapriv->padapter, psta);
398                 init_base_ch_timer(pstapriv->padapter, psta);
399                 init_off_ch_timer(pstapriv->padapter, psta);
400                 init_handshake_timer(pstapriv->padapter, psta);
401                 init_tdls_alive_timer(pstapriv->padapter, psta);
402 #endif //CONFIG_TDLS
403
404                 //for A-MPDU Rx reordering buffer control
405                 for(i=0; i < 16 ; i++)
406                 {
407                         preorder_ctrl = &psta->recvreorder_ctrl[i];
408
409                         preorder_ctrl->padapter = pstapriv->padapter;
410                 
411                         preorder_ctrl->enable = _FALSE;
412                 
413                         preorder_ctrl->indicate_seq = 0xffff;
414                         #ifdef DBG_RX_SEQ
415                         DBG_871X("DBG_RX_SEQ %s:%d IndicateSeq: %d\n", __FUNCTION__, __LINE__,
416                                 preorder_ctrl->indicate_seq);
417                         #endif
418                         preorder_ctrl->wend_b= 0xffff;       
419                         //preorder_ctrl->wsize_b = (NR_RECVBUFF-2);
420                         preorder_ctrl->wsize_b = 64;//64;
421
422                         _rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);
423
424                         rtw_init_recv_timer(preorder_ctrl);
425                 }
426
427
428                 //init for DM
429                 psta->rssi_stat.UndecoratedSmoothedPWDB = (-1);
430                 psta->rssi_stat.UndecoratedSmoothedCCK = (-1);
431 #ifdef CONFIG_ATMEL_RC_PATCH
432                 psta->flag_atmel_rc = 0;
433 #endif
434                 /* init for the sequence number of received management frame */
435                 psta->RxMgmtFrameSeqNum = 0xffff;
436
437                 //alloc mac id for non-bc/mc station,
438                 rtw_alloc_macid(pstapriv->padapter, psta);
439
440         }
441         
442 exit:
443
444         _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
445
446 _func_exit_;
447
448         return psta;
449
450
451 }
452
453
454 // using pstapriv->sta_hash_lock to protect
455 u32     rtw_free_stainfo(_adapter *padapter , struct sta_info *psta)
456 {       
457         int i;
458         _irqL irqL0;
459         _queue *pfree_sta_queue;
460         struct recv_reorder_ctrl *preorder_ctrl;
461         struct  sta_xmit_priv   *pstaxmitpriv;
462         struct  xmit_priv       *pxmitpriv= &padapter->xmitpriv;
463         struct  sta_priv *pstapriv = &padapter->stapriv;
464         struct hw_xmit *phwxmit;
465
466
467 _func_enter_;   
468         
469         if (psta == NULL)
470                 goto exit;
471
472
473         _enter_critical_bh(&psta->lock, &irqL0);
474         psta->state &= ~_FW_LINKED;
475         _exit_critical_bh(&psta->lock, &irqL0);
476
477         pfree_sta_queue = &pstapriv->free_sta_queue;
478
479
480         pstaxmitpriv = &psta->sta_xmitpriv;
481         
482         //rtw_list_delete(&psta->sleep_list);
483         
484         //rtw_list_delete(&psta->wakeup_list);
485         
486         _enter_critical_bh(&pxmitpriv->lock, &irqL0);
487         
488         rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);
489         psta->sleepq_len = 0;
490         
491         //vo
492         //_enter_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0);
493         rtw_free_xmitframe_queue( pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
494         rtw_list_delete(&(pstaxmitpriv->vo_q.tx_pending));
495         phwxmit = pxmitpriv->hwxmits;
496         phwxmit->accnt -= pstaxmitpriv->vo_q.qcnt;
497         pstaxmitpriv->vo_q.qcnt = 0;
498         //_exit_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0);
499
500         //vi
501         //_enter_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0);
502         rtw_free_xmitframe_queue( pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
503         rtw_list_delete(&(pstaxmitpriv->vi_q.tx_pending));
504         phwxmit = pxmitpriv->hwxmits+1;
505         phwxmit->accnt -= pstaxmitpriv->vi_q.qcnt;
506         pstaxmitpriv->vi_q.qcnt = 0;
507         //_exit_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0);
508
509         //be
510         //_enter_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0);
511         rtw_free_xmitframe_queue( pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
512         rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
513         phwxmit = pxmitpriv->hwxmits+2;
514         phwxmit->accnt -= pstaxmitpriv->be_q.qcnt;
515         pstaxmitpriv->be_q.qcnt = 0;
516         //_exit_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0);
517         
518         //bk
519         //_enter_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0);
520         rtw_free_xmitframe_queue( pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
521         rtw_list_delete(&(pstaxmitpriv->bk_q.tx_pending));
522         phwxmit = pxmitpriv->hwxmits+3;
523         phwxmit->accnt -= pstaxmitpriv->bk_q.qcnt;
524         pstaxmitpriv->bk_q.qcnt = 0;
525         //_exit_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0);
526         
527         _exit_critical_bh(&pxmitpriv->lock, &irqL0);
528         
529         rtw_list_delete(&psta->hash_list);
530         RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_err_,("\n free number_%d stainfo  with hwaddr = 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x  \n",pstapriv->asoc_sta_count , psta->hwaddr[0], psta->hwaddr[1], psta->hwaddr[2],psta->hwaddr[3],psta->hwaddr[4],psta->hwaddr[5]));
531         pstapriv->asoc_sta_count --;
532         
533         
534         // re-init sta_info; 20061114 // will be init in alloc_stainfo
535         //_rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
536         //_rtw_init_sta_recv_priv(&psta->sta_recvpriv);
537
538         _cancel_timer_ex(&psta->addba_retry_timer);
539
540 #ifdef CONFIG_TDLS
541         _cancel_timer_ex(&psta->TPK_timer);
542         _cancel_timer_ex(&psta->option_timer);
543         _cancel_timer_ex(&psta->base_ch_timer);
544         _cancel_timer_ex(&psta->off_ch_timer);
545         _cancel_timer_ex(&psta->alive_timer1);
546         _cancel_timer_ex(&psta->alive_timer2);
547 #endif //CONFIG_TDLS
548
549         //for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer
550         for(i=0; i < 16 ; i++)
551         {
552                 _irqL irqL;
553                 _list   *phead, *plist;
554                 union recv_frame *prframe;
555                 _queue *ppending_recvframe_queue;
556                 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
557         
558                 preorder_ctrl = &psta->recvreorder_ctrl[i];
559                 
560                 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);                
561
562                 
563                 ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
564
565                 _enter_critical_bh(&ppending_recvframe_queue->lock, &irqL);
566
567                 phead =         get_list_head(ppending_recvframe_queue);
568                 plist = get_next(phead);
569                 
570                 while(!rtw_is_list_empty(phead))
571                 {       
572                         prframe = LIST_CONTAINOR(plist, union recv_frame, u);
573                         
574                         plist = get_next(plist);
575                         
576                         rtw_list_delete(&(prframe->u.hdr.list));
577
578                         rtw_free_recvframe(prframe, pfree_recv_queue);
579                 }
580
581                 _exit_critical_bh(&ppending_recvframe_queue->lock, &irqL);
582                 
583         }
584
585         if (!(psta->state & WIFI_AP_STATE))
586                 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _FALSE);
587                         
588
589         //release mac id for non-bc/mc station,
590         rtw_release_macid(pstapriv->padapter, psta);
591
592 #ifdef CONFIG_AP_MODE
593
594 /*
595         _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
596         rtw_list_delete(&psta->asoc_list);      
597         _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
598 */
599         _enter_critical_bh(&pstapriv->auth_list_lock, &irqL0);
600         if (!rtw_is_list_empty(&psta->auth_list)) {
601                 rtw_list_delete(&psta->auth_list);
602                 pstapriv->auth_list_cnt--;
603         }
604         _exit_critical_bh(&pstapriv->auth_list_lock, &irqL0);
605         
606         psta->expire_to = 0;
607 #ifdef CONFIG_ATMEL_RC_PATCH
608         psta->flag_atmel_rc = 0;
609 #endif
610         psta->sleepq_ac_len = 0;
611         psta->qos_info = 0;
612
613         psta->max_sp_len = 0;
614         psta->uapsd_bk = 0;
615         psta->uapsd_be = 0;
616         psta->uapsd_vi = 0;
617         psta->uapsd_vo = 0;
618
619         psta->has_legacy_ac = 0;
620
621 #ifdef CONFIG_NATIVEAP_MLME
622         
623         pstapriv->sta_dz_bitmap &=~BIT(psta->aid);
624         pstapriv->tim_bitmap &=~BIT(psta->aid); 
625
626         //rtw_indicate_sta_disassoc_event(padapter, psta);
627
628         if ((psta->aid >0)&&(pstapriv->sta_aid[psta->aid - 1] == psta))
629         {
630                 pstapriv->sta_aid[psta->aid - 1] = NULL;
631                 psta->aid = 0;
632         }       
633         
634 #endif  // CONFIG_NATIVEAP_MLME 
635
636 #ifdef CONFIG_TX_MCAST2UNI
637         psta->under_exist_checking = 0;
638 #endif  // CONFIG_TX_MCAST2UNI
639
640 #endif  // CONFIG_AP_MODE       
641
642          _rtw_spinlock_free(&psta->lock);
643
644         //_enter_critical_bh(&(pfree_sta_queue->lock), &irqL0);
645         rtw_list_insert_tail(&psta->list, get_list_head(pfree_sta_queue));
646         //_exit_critical_bh(&(pfree_sta_queue->lock), &irqL0);
647
648 exit:
649         
650 _func_exit_;    
651
652         return _SUCCESS;
653         
654 }
655
656 // free all stainfo which in sta_hash[all]
657 void rtw_free_all_stainfo(_adapter *padapter)
658 {
659         _irqL    irqL;
660         _list   *plist, *phead;
661         s32     index;
662         struct sta_info *psta = NULL;
663         struct  sta_priv *pstapriv = &padapter->stapriv;
664         struct sta_info* pbcmc_stainfo =rtw_get_bcmc_stainfo( padapter);
665         
666 _func_enter_;   
667
668         if(pstapriv->asoc_sta_count==1)
669                 goto exit;
670
671         _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
672
673         for(index=0; index< NUM_STA; index++)
674         {
675                 phead = &(pstapriv->sta_hash[index]);
676                 plist = get_next(phead);
677                 
678                 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
679                 {
680                         psta = LIST_CONTAINOR(plist, struct sta_info ,hash_list);
681
682                         plist = get_next(plist);
683
684                         if(pbcmc_stainfo!=psta)                                 
685                                 rtw_free_stainfo(padapter , psta);
686                         
687                 }
688         }
689         
690         _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
691         
692 exit:   
693         
694 _func_exit_;    
695
696 }
697
698 /* any station allocated can be searched by hash list */
699 struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
700 {
701
702         _irqL    irqL;
703
704         _list   *plist, *phead;
705
706         struct sta_info *psta = NULL;
707         
708         u32     index;
709
710         u8 *addr;
711
712         u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
713
714 _func_enter_;
715
716         if(hwaddr==NULL)
717                 return NULL;
718                 
719         if(IS_MCAST(hwaddr))
720         {
721                 addr = bc_addr;
722         }
723         else
724         {
725                 addr = hwaddr;
726         }
727
728         index = wifi_mac_hash(addr);
729
730         _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
731         
732         phead = &(pstapriv->sta_hash[index]);
733         plist = get_next(phead);
734
735
736         while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
737         {
738         
739                 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
740                 
741                 if ((_rtw_memcmp(psta->hwaddr, addr, ETH_ALEN))== _TRUE) 
742                 { // if found the matched address
743                         break;
744                 }
745                 psta=NULL;
746                 plist = get_next(plist);
747         }
748
749         _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
750 _func_exit_;    
751         return psta;
752         
753 }
754
755 u32 rtw_init_bcmc_stainfo(_adapter* padapter)
756 {
757
758         struct sta_info         *psta;
759         struct tx_servq *ptxservq;
760         u32 res=_SUCCESS;
761         NDIS_802_11_MAC_ADDRESS bcast_addr= {0xff,0xff,0xff,0xff,0xff,0xff};
762         
763         struct  sta_priv *pstapriv = &padapter->stapriv;
764         //_queue        *pstapending = &padapter->xmitpriv.bm_pending; 
765         
766 _func_enter_;
767
768         psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
769         
770         if(psta==NULL){
771                 res=_FAIL;
772                 RT_TRACE(_module_rtl871x_sta_mgt_c_,_drv_err_,("rtw_alloc_stainfo fail"));
773                 goto exit;
774         }
775
776         // default broadcast & multicast use macid 1
777         psta->mac_id = 1;
778
779         ptxservq= &(psta->sta_xmitpriv.be_q);
780
781 /*
782         _enter_critical(&pstapending->lock, &irqL0);
783
784         if (rtw_is_list_empty(&ptxservq->tx_pending))
785                 rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(pstapending));
786
787         _exit_critical(&pstapending->lock, &irqL0);
788 */
789         
790 exit:
791 _func_exit_;            
792         return _SUCCESS;
793
794 }
795
796
797 struct sta_info* rtw_get_bcmc_stainfo(_adapter* padapter)
798 {
799         struct sta_info         *psta;
800         struct sta_priv         *pstapriv = &padapter->stapriv;
801         u8 bc_addr[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
802 _func_enter_;
803          psta = rtw_get_stainfo(pstapriv, bc_addr);
804 _func_exit_;             
805         return psta;
806
807 }
808
809 u8 rtw_access_ctrl(_adapter *padapter, u8 *mac_addr)
810 {
811         u8 res = _TRUE;
812 #ifdef  CONFIG_AP_MODE
813         _irqL irqL;
814         _list   *plist, *phead;
815         struct rtw_wlan_acl_node *paclnode;
816         u8 match = _FALSE;
817         struct sta_priv *pstapriv = &padapter->stapriv;
818         struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
819         _queue  *pacl_node_q =&pacl_list->acl_node_q;
820         
821         _enter_critical_bh(&(pacl_node_q->lock), &irqL);
822         phead = get_list_head(pacl_node_q);
823         plist = get_next(phead);                
824         while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
825         {
826                 paclnode = LIST_CONTAINOR(plist, struct rtw_wlan_acl_node, list);
827                 plist = get_next(plist);
828
829                 if(_rtw_memcmp(paclnode->addr, mac_addr, ETH_ALEN))
830                 {
831                         if(paclnode->valid == _TRUE)
832                         {
833                                 match = _TRUE;
834                                 break;
835                         }
836                 }               
837         }       
838         _exit_critical_bh(&(pacl_node_q->lock), &irqL);
839         
840
841         if(pacl_list->mode == 1)//accept unless in deny list
842         {
843                 res = (match == _TRUE) ?  _FALSE:_TRUE;
844         }       
845         else if(pacl_list->mode == 2)//deny unless in accept list
846         {
847                 res = (match == _TRUE) ?  _TRUE:_FALSE;
848         }
849         else
850         {
851                  res = _TRUE;
852         }               
853         
854 #endif
855
856         return res;
857
858 }
859