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 ******************************************************************************/
15 #define _RTW_STA_MGT_C_
17 #include <osdep_service.h>
18 #include <drv_types.h>
19 #include <recv_osdep.h>
20 #include <xmit_osdep.h>
21 #include <mlme_osdep.h>
23 #include <linux/vmalloc.h>
25 static void _rtw_init_stainfo(struct sta_info *psta)
27 memset((u8 *)psta, 0, sizeof(struct sta_info));
29 spin_lock_init(&psta->lock);
30 INIT_LIST_HEAD(&psta->list);
31 INIT_LIST_HEAD(&psta->hash_list);
32 _rtw_init_queue(&psta->sleep_q);
35 _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
36 _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
38 #ifdef CONFIG_88EU_AP_MODE
40 INIT_LIST_HEAD(&psta->asoc_list);
42 INIT_LIST_HEAD(&psta->auth_list);
50 psta->bpairwise_key_installed = false;
53 psta->no_short_slot_time_set = 0;
54 psta->no_short_preamble_set = 0;
55 psta->no_ht_gf_set = 0;
57 psta->ht_20mhz_set = 0;
59 psta->under_exist_checking = 0;
61 psta->keep_alive_trycnt = 0;
63 #endif /* CONFIG_88EU_AP_MODE */
67 u32 _rtw_init_sta_priv(struct sta_priv *pstapriv)
69 struct sta_info *psta;
73 pstapriv->pallocated_stainfo_buf = vzalloc(sizeof(struct sta_info) * NUM_STA + 4);
75 if (!pstapriv->pallocated_stainfo_buf)
78 pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 -
79 ((size_t)(pstapriv->pallocated_stainfo_buf) & 3);
81 _rtw_init_queue(&pstapriv->free_sta_queue);
83 spin_lock_init(&pstapriv->sta_hash_lock);
85 pstapriv->asoc_sta_count = 0;
86 _rtw_init_queue(&pstapriv->sleep_q);
87 _rtw_init_queue(&pstapriv->wakeup_q);
89 psta = (struct sta_info *)(pstapriv->pstainfo_buf);
91 for (i = 0; i < NUM_STA; i++) {
92 _rtw_init_stainfo(psta);
94 INIT_LIST_HEAD(&(pstapriv->sta_hash[i]));
96 list_add_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue));
101 #ifdef CONFIG_88EU_AP_MODE
103 pstapriv->sta_dz_bitmap = 0;
104 pstapriv->tim_bitmap = 0;
106 INIT_LIST_HEAD(&pstapriv->asoc_list);
107 INIT_LIST_HEAD(&pstapriv->auth_list);
108 spin_lock_init(&pstapriv->asoc_list_lock);
109 spin_lock_init(&pstapriv->auth_list_lock);
110 pstapriv->asoc_list_cnt = 0;
111 pstapriv->auth_list_cnt = 0;
113 pstapriv->auth_to = 3; /* 3*2 = 6 sec */
114 pstapriv->assoc_to = 3;
115 pstapriv->expire_to = 3; /* 3*2 = 6 sec */
116 pstapriv->max_num_sta = NUM_STA;
123 inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)
125 int offset = (((u8 *)sta) - stapriv->pstainfo_buf)/sizeof(struct sta_info);
127 if (!stainfo_offset_valid(offset))
128 DBG_88E("%s invalid offset(%d), out of range!!!", __func__, offset);
133 inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)
135 if (!stainfo_offset_valid(offset))
136 DBG_88E("%s invalid offset(%d), out of range!!!", __func__, offset);
138 return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));
141 u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)
143 struct list_head *phead, *plist;
144 struct sta_info *psta = NULL;
145 struct recv_reorder_ctrl *preorder_ctrl;
149 /* delete all reordering_ctrl_timer */
150 spin_lock_bh(&pstapriv->sta_hash_lock);
151 for (index = 0; index < NUM_STA; index++) {
152 phead = &(pstapriv->sta_hash[index]);
155 while (phead != plist) {
157 psta = container_of(plist, struct sta_info,
161 for (i = 0; i < 16; i++) {
162 preorder_ctrl = &psta->recvreorder_ctrl[i];
163 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
167 spin_unlock_bh(&pstapriv->sta_hash_lock);
168 /*===============================*/
170 vfree(pstapriv->pallocated_stainfo_buf);
176 struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
179 struct list_head *phash_list;
180 struct sta_info *psta;
181 struct __queue *pfree_sta_queue;
182 struct recv_reorder_ctrl *preorder_ctrl;
184 u16 wRxSeqInitialValue = 0xffff;
186 pfree_sta_queue = &pstapriv->free_sta_queue;
188 spin_lock_bh(&pfree_sta_queue->lock);
189 psta = list_first_entry_or_null(&pfree_sta_queue->queue,
190 struct sta_info, list);
192 spin_unlock_bh(&pfree_sta_queue->lock);
194 list_del_init(&psta->list);
195 spin_unlock_bh(&pfree_sta_queue->lock);
196 _rtw_init_stainfo(psta);
197 memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
198 index = wifi_mac_hash(hwaddr);
199 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_info_, ("rtw_alloc_stainfo: index=%x", index));
200 if (index >= NUM_STA) {
201 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("ERROR => rtw_alloc_stainfo: index >= NUM_STA"));
205 phash_list = &pstapriv->sta_hash[index];
207 spin_lock_bh(&pstapriv->sta_hash_lock);
208 list_add_tail(&psta->hash_list, phash_list);
209 pstapriv->asoc_sta_count++;
210 spin_unlock_bh(&pstapriv->sta_hash_lock);
212 /* Commented by Albert 2009/08/13 */
213 /* For the SMC router, the sequence number of first packet of WPS handshake will be 0. */
214 /* 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. */
215 /* So, we initialize the tid_rxseq variable as the 0xffff. */
217 for (i = 0; i < 16; i++)
218 memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], &wRxSeqInitialValue, 2);
220 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_info_,
221 ("alloc number_%d stainfo with hwaddr = %pM\n",
222 pstapriv->asoc_sta_count, hwaddr));
224 init_addba_retry_timer(pstapriv->padapter, psta);
226 /* for A-MPDU Rx reordering buffer control */
227 for (i = 0; i < 16; i++) {
228 preorder_ctrl = &psta->recvreorder_ctrl[i];
230 preorder_ctrl->padapter = pstapriv->padapter;
232 preorder_ctrl->enable = false;
234 preorder_ctrl->indicate_seq = 0xffff;
235 preorder_ctrl->wend_b = 0xffff;
236 preorder_ctrl->wsize_b = 64;/* 64; */
238 _rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);
240 rtw_init_recv_timer(preorder_ctrl);
244 psta->rssi_stat.UndecoratedSmoothedPWDB = (-1);
245 psta->rssi_stat.UndecoratedSmoothedCCK = (-1);
247 /* init for the sequence number of received management frame */
248 psta->RxMgmtFrameSeqNum = 0xffff;
255 /* using pstapriv->sta_hash_lock to protect */
256 u32 rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
259 struct __queue *pfree_sta_queue;
260 struct recv_reorder_ctrl *preorder_ctrl;
261 struct sta_xmit_priv *pstaxmitpriv;
262 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
263 struct sta_priv *pstapriv = &padapter->stapriv;
269 pfree_sta_queue = &pstapriv->free_sta_queue;
271 pstaxmitpriv = &psta->sta_xmitpriv;
273 spin_lock_bh(&pxmitpriv->lock);
275 rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);
276 psta->sleepq_len = 0;
278 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
280 list_del_init(&(pstaxmitpriv->vo_q.tx_pending));
282 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
284 list_del_init(&(pstaxmitpriv->vi_q.tx_pending));
286 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
288 list_del_init(&(pstaxmitpriv->bk_q.tx_pending));
290 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
292 list_del_init(&(pstaxmitpriv->be_q.tx_pending));
294 spin_unlock_bh(&pxmitpriv->lock);
296 list_del_init(&psta->hash_list);
297 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_,
298 ("\n free number_%d stainfo with hwaddr=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
299 pstapriv->asoc_sta_count, psta->hwaddr[0], psta->hwaddr[1],
300 psta->hwaddr[2], psta->hwaddr[3], psta->hwaddr[4],
302 pstapriv->asoc_sta_count--;
304 /* re-init sta_info; 20061114 */
305 _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
306 _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
308 del_timer_sync(&psta->addba_retry_timer);
310 /* for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer */
311 for (i = 0; i < 16; i++) {
312 struct list_head *phead, *plist;
313 struct recv_frame *prhdr;
314 struct recv_frame *prframe;
315 struct __queue *ppending_recvframe_queue;
316 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
318 preorder_ctrl = &psta->recvreorder_ctrl[i];
320 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
322 ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
324 spin_lock_bh(&ppending_recvframe_queue->lock);
326 phead = get_list_head(ppending_recvframe_queue);
329 while (!list_empty(phead)) {
330 prhdr = container_of(plist, struct recv_frame, list);
331 prframe = (struct recv_frame *)prhdr;
335 list_del_init(&(prframe->list));
337 rtw_free_recvframe(prframe, pfree_recv_queue);
340 spin_unlock_bh(&ppending_recvframe_queue->lock);
343 if (!(psta->state & WIFI_AP_STATE))
344 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, false);
346 #ifdef CONFIG_88EU_AP_MODE
348 spin_lock_bh(&pstapriv->auth_list_lock);
349 if (!list_empty(&psta->auth_list)) {
350 list_del_init(&psta->auth_list);
351 pstapriv->auth_list_cnt--;
353 spin_unlock_bh(&pstapriv->auth_list_lock);
357 psta->sleepq_ac_len = 0;
360 psta->max_sp_len = 0;
365 psta->has_legacy_ac = 0;
367 pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
368 pstapriv->tim_bitmap &= ~BIT(psta->aid);
370 if ((psta->aid > 0) && (pstapriv->sta_aid[psta->aid - 1] == psta)) {
371 pstapriv->sta_aid[psta->aid - 1] = NULL;
375 psta->under_exist_checking = 0;
377 #endif /* CONFIG_88EU_AP_MODE */
379 spin_lock_bh(&(pfree_sta_queue->lock));
380 list_add_tail(&psta->list, get_list_head(pfree_sta_queue));
381 spin_unlock_bh(&pfree_sta_queue->lock);
389 /* free all stainfo which in sta_hash[all] */
390 void rtw_free_all_stainfo(struct adapter *padapter)
392 struct list_head *plist, *phead;
394 struct sta_info *psta = NULL;
395 struct sta_priv *pstapriv = &padapter->stapriv;
396 struct sta_info *pbcmc_stainfo = rtw_get_bcmc_stainfo(padapter);
399 if (pstapriv->asoc_sta_count == 1)
402 spin_lock_bh(&pstapriv->sta_hash_lock);
404 for (index = 0; index < NUM_STA; index++) {
405 phead = &(pstapriv->sta_hash[index]);
408 while (phead != plist) {
409 psta = container_of(plist, struct sta_info, hash_list);
413 if (pbcmc_stainfo != psta)
414 rtw_free_stainfo(padapter, psta);
417 spin_unlock_bh(&pstapriv->sta_hash_lock);
420 /* any station allocated can be searched by hash list */
421 struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
423 struct list_head *plist, *phead;
424 struct sta_info *psta = NULL;
427 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
433 if (IS_MCAST(hwaddr))
438 index = wifi_mac_hash(addr);
440 spin_lock_bh(&pstapriv->sta_hash_lock);
442 phead = &(pstapriv->sta_hash[index]);
445 while (phead != plist) {
446 psta = container_of(plist, struct sta_info, hash_list);
448 if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
449 /* if found the matched address */
456 spin_unlock_bh(&pstapriv->sta_hash_lock);
460 u32 rtw_init_bcmc_stainfo(struct adapter *padapter)
462 struct sta_info *psta;
464 unsigned char bcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
465 struct sta_priv *pstapriv = &padapter->stapriv;
468 psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
472 RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("rtw_alloc_stainfo fail"));
476 /* default broadcast & multicast use macid 1 */
483 struct sta_info *rtw_get_bcmc_stainfo(struct adapter *padapter)
485 struct sta_priv *pstapriv = &padapter->stapriv;
486 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
487 return rtw_get_stainfo(pstapriv, bc_addr);
490 u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
493 #ifdef CONFIG_88EU_AP_MODE
494 struct list_head *plist, *phead;
495 struct rtw_wlan_acl_node *paclnode;
497 struct sta_priv *pstapriv = &padapter->stapriv;
498 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
499 struct __queue *pacl_node_q = &pacl_list->acl_node_q;
501 spin_lock_bh(&(pacl_node_q->lock));
502 phead = get_list_head(pacl_node_q);
504 while (phead != plist) {
505 paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
508 if (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
509 if (paclnode->valid) {
515 spin_unlock_bh(&pacl_node_q->lock);
517 if (pacl_list->mode == 1)/* accept unless in deny list */
518 res = (match) ? false : true;
519 else if (pacl_list->mode == 2)/* deny unless in accept list */
520 res = (match) ? true : false;