linux/drivers/staging/rtl8712/rtl871x_sta_mgt.c
<<
>>
Prefs
   1/******************************************************************************
   2 * rtl871x_sta_mgt.c
   3 *
   4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
   5 * Linux device driver for RTL8192SU
   6 *
   7 * This program is free software; you can redistribute it and/or modify it
   8 * under the terms of version 2 of the GNU General Public License as
   9 * published by the Free Software Foundation.
  10 *
  11 * This program is distributed in the hope that it will be useful, but WITHOUT
  12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  14 * more details.
  15 *
  16 * You should have received a copy of the GNU General Public License along with
  17 * this program; if not, write to the Free Software Foundation, Inc.,
  18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  19 *
  20 * Modifications for inclusion into the Linux staging tree are
  21 * Copyright(c) 2010 Larry Finger. All rights reserved.
  22 *
  23 * Contact information:
  24 * WLAN FAE <wlanfae@realtek.com>
  25 * Larry Finger <Larry.Finger@lwfinger.net>
  26 *
  27 ******************************************************************************/
  28
  29#define _RTL871X_STA_MGT_C_
  30
  31#include "osdep_service.h"
  32#include "drv_types.h"
  33#include "recv_osdep.h"
  34#include "xmit_osdep.h"
  35#include "sta_info.h"
  36
  37static void _init_stainfo(struct sta_info *psta)
  38{
  39        memset((u8 *)psta, 0, sizeof(struct sta_info));
  40         spin_lock_init(&psta->lock);
  41        _init_listhead(&psta->list);
  42        _init_listhead(&psta->hash_list);
  43        _r8712_init_sta_xmit_priv(&psta->sta_xmitpriv);
  44        _r8712_init_sta_recv_priv(&psta->sta_recvpriv);
  45#ifdef CONFIG_R8712_AP
  46        _init_listhead(&psta->asoc_list);
  47        _init_listhead(&psta->auth_list);
  48#endif
  49}
  50
  51u32 _r8712_init_sta_priv(struct sta_priv *pstapriv)
  52{
  53        struct sta_info *psta;
  54        s32 i;
  55
  56        pstapriv->pallocated_stainfo_buf = _malloc(sizeof(struct sta_info) *
  57                                                   NUM_STA + 4);
  58        if (pstapriv->pallocated_stainfo_buf == NULL)
  59                return _FAIL;
  60        pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 -
  61                ((addr_t)(pstapriv->pallocated_stainfo_buf) & 3);
  62        _init_queue(&pstapriv->free_sta_queue);
  63        spin_lock_init(&pstapriv->sta_hash_lock);
  64        pstapriv->asoc_sta_count = 0;
  65        _init_queue(&pstapriv->sleep_q);
  66        _init_queue(&pstapriv->wakeup_q);
  67        psta = (struct sta_info *)(pstapriv->pstainfo_buf);
  68        for (i = 0; i < NUM_STA; i++) {
  69                _init_stainfo(psta);
  70                _init_listhead(&(pstapriv->sta_hash[i]));
  71                list_insert_tail(&psta->list,
  72                                 get_list_head(&pstapriv->free_sta_queue));
  73                psta++;
  74        }
  75#ifdef CONFIG_R8712_AP
  76        _init_listhead(&pstapriv->asoc_list);
  77        _init_listhead(&pstapriv->auth_list);
  78#endif
  79        return _SUCCESS;
  80}
  81
  82/* this function is used to free the memory of lock || sema for all stainfos */
  83static void mfree_all_stainfo(struct sta_priv *pstapriv)
  84{
  85        unsigned long irqL;
  86        struct list_head *plist, *phead;
  87        struct sta_info *psta = NULL;
  88
  89        spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
  90        phead = get_list_head(&pstapriv->free_sta_queue);
  91        plist = get_next(phead);
  92        while ((end_of_queue_search(phead, plist)) == false) {
  93                psta = LIST_CONTAINOR(plist, struct sta_info, list);
  94                plist = get_next(plist);
  95        }
  96
  97        spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
  98}
  99
 100
 101static void mfree_sta_priv_lock(struct  sta_priv *pstapriv)
 102{
 103         mfree_all_stainfo(pstapriv); /* be done before free sta_hash_lock */
 104}
 105
 106u32 _r8712_free_sta_priv(struct sta_priv *pstapriv)
 107{
 108        if (pstapriv) {
 109                mfree_sta_priv_lock(pstapriv);
 110                kfree(pstapriv->pallocated_stainfo_buf);
 111        }
 112        return _SUCCESS;
 113}
 114
 115struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
 116{
 117        uint tmp_aid;
 118        s32     index;
 119        struct list_head *phash_list;
 120        struct sta_info *psta;
 121        struct  __queue *pfree_sta_queue;
 122        struct recv_reorder_ctrl *preorder_ctrl;
 123        int i = 0;
 124        u16  wRxSeqInitialValue = 0xffff;
 125        unsigned long flags;
 126
 127        pfree_sta_queue = &pstapriv->free_sta_queue;
 128        spin_lock_irqsave(&(pfree_sta_queue->lock), flags);
 129        if (_queue_empty(pfree_sta_queue) == true)
 130                psta = NULL;
 131        else {
 132                psta = LIST_CONTAINOR(get_next(&pfree_sta_queue->queue),
 133                                      struct sta_info, list);
 134                list_delete(&(psta->list));
 135                tmp_aid = psta->aid;
 136                _init_stainfo(psta);
 137                memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
 138                index = wifi_mac_hash(hwaddr);
 139                if (index >= NUM_STA) {
 140                        psta = NULL;
 141                        goto exit;
 142                }
 143                phash_list = &(pstapriv->sta_hash[index]);
 144                list_insert_tail(&psta->hash_list, phash_list);
 145                pstapriv->asoc_sta_count++ ;
 146
 147/* For the SMC router, the sequence number of first packet of WPS handshake
 148 * will be 0. In this case, this packet will be dropped by recv_decache function
 149 * if we use the 0x00 as the default value for tid_rxseq variable. So, we
 150 * initialize the tid_rxseq variable as the 0xffff.
 151 */
 152                for (i = 0; i < 16; i++)
 153                        memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i],
 154                                &wRxSeqInitialValue, 2);
 155                /* for A-MPDU Rx reordering buffer control */
 156                for (i = 0; i < 16 ; i++) {
 157                        preorder_ctrl = &psta->recvreorder_ctrl[i];
 158                        preorder_ctrl->padapter = pstapriv->padapter;
 159                        preorder_ctrl->indicate_seq = 0xffff;
 160                        preorder_ctrl->wend_b = 0xffff;
 161                        preorder_ctrl->wsize_b = 64;
 162                        _init_queue(&preorder_ctrl->pending_recvframe_queue);
 163                        r8712_init_recv_timer(preorder_ctrl);
 164                }
 165        }
 166exit:
 167        spin_unlock_irqrestore(&(pfree_sta_queue->lock), flags);
 168        return psta;
 169}
 170
 171/* using pstapriv->sta_hash_lock to protect */
 172void r8712_free_stainfo(struct _adapter *padapter, struct sta_info *psta)
 173{
 174        int i;
 175        unsigned long irqL0;
 176        struct  __queue *pfree_sta_queue;
 177        struct recv_reorder_ctrl *preorder_ctrl;
 178        struct  sta_xmit_priv *pstaxmitpriv;
 179        struct  xmit_priv *pxmitpriv = &padapter->xmitpriv;
 180        struct  sta_priv *pstapriv = &padapter->stapriv;
 181
 182        if (psta == NULL)
 183                return;
 184        pfree_sta_queue = &pstapriv->free_sta_queue;
 185        pstaxmitpriv = &psta->sta_xmitpriv;
 186        spin_lock_irqsave(&(pxmitpriv->vo_pending.lock), irqL0);
 187        r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
 188        list_delete(&(pstaxmitpriv->vo_q.tx_pending));
 189        spin_unlock_irqrestore(&(pxmitpriv->vo_pending.lock), irqL0);
 190        spin_lock_irqsave(&(pxmitpriv->vi_pending.lock), irqL0);
 191        r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
 192        list_delete(&(pstaxmitpriv->vi_q.tx_pending));
 193        spin_unlock_irqrestore(&(pxmitpriv->vi_pending.lock), irqL0);
 194        spin_lock_irqsave(&(pxmitpriv->bk_pending.lock), irqL0);
 195        r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
 196        list_delete(&(pstaxmitpriv->bk_q.tx_pending));
 197        spin_unlock_irqrestore(&(pxmitpriv->bk_pending.lock), irqL0);
 198        spin_lock_irqsave(&(pxmitpriv->be_pending.lock), irqL0);
 199        r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
 200        list_delete(&(pstaxmitpriv->be_q.tx_pending));
 201        spin_unlock_irqrestore(&(pxmitpriv->be_pending.lock), irqL0);
 202        list_delete(&psta->hash_list);
 203        pstapriv->asoc_sta_count--;
 204        /* re-init sta_info; 20061114 */
 205        _r8712_init_sta_xmit_priv(&psta->sta_xmitpriv);
 206        _r8712_init_sta_recv_priv(&psta->sta_recvpriv);
 207        /* for A-MPDU Rx reordering buffer control,
 208         * cancel reordering_ctrl_timer */
 209        for (i = 0; i < 16; i++) {
 210                preorder_ctrl = &psta->recvreorder_ctrl[i];
 211                _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
 212        }
 213        spin_lock(&(pfree_sta_queue->lock));
 214        /* insert into free_sta_queue; 20061114 */
 215        list_insert_tail(&psta->list, get_list_head(pfree_sta_queue));
 216        spin_unlock(&(pfree_sta_queue->lock));
 217}
 218
 219/* free all stainfo which in sta_hash[all] */
 220void r8712_free_all_stainfo(struct _adapter *padapter)
 221{
 222        unsigned long irqL;
 223        struct list_head *plist, *phead;
 224        s32 index;
 225        struct sta_info *psta = NULL;
 226        struct  sta_priv *pstapriv = &padapter->stapriv;
 227        struct sta_info *pbcmc_stainfo = r8712_get_bcmc_stainfo(padapter);
 228
 229        if (pstapriv->asoc_sta_count == 1)
 230                return;
 231        spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
 232        for (index = 0; index < NUM_STA; index++) {
 233                phead = &(pstapriv->sta_hash[index]);
 234                plist = get_next(phead);
 235                while ((end_of_queue_search(phead, plist)) == false) {
 236                        psta = LIST_CONTAINOR(plist,
 237                                              struct sta_info, hash_list);
 238                        plist = get_next(plist);
 239                        if (pbcmc_stainfo != psta)
 240                                r8712_free_stainfo(padapter , psta);
 241                }
 242        }
 243        spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
 244}
 245
 246/* any station allocated can be searched by hash list */
 247struct sta_info *r8712_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
 248{
 249        unsigned long    irqL;
 250        struct list_head *plist, *phead;
 251        struct sta_info *psta = NULL;
 252        u32     index;
 253
 254        if (hwaddr == NULL)
 255                return NULL;
 256        index = wifi_mac_hash(hwaddr);
 257        spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
 258        phead = &(pstapriv->sta_hash[index]);
 259        plist = get_next(phead);
 260        while ((end_of_queue_search(phead, plist)) == false) {
 261                psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
 262                if ((!memcmp(psta->hwaddr, hwaddr, ETH_ALEN))) {
 263                        /* if found the matched address */
 264                        break;
 265                }
 266                psta = NULL;
 267                plist = get_next(plist);
 268        }
 269        spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
 270        return psta;
 271}
 272
 273void r8712_init_bcmc_stainfo(struct _adapter *padapter)
 274{
 275        struct sta_info *psta;
 276        struct tx_servq *ptxservq;
 277        unsigned char bcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 278        struct  sta_priv *pstapriv = &padapter->stapriv;
 279
 280        psta = r8712_alloc_stainfo(pstapriv, bcast_addr);
 281        if (psta == NULL)
 282                return;
 283        ptxservq = &(psta->sta_xmitpriv.be_q);
 284}
 285
 286struct sta_info *r8712_get_bcmc_stainfo(struct _adapter *padapter)
 287{
 288        struct sta_info *psta;
 289        struct sta_priv *pstapriv = &padapter->stapriv;
 290        u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 291
 292        psta = r8712_get_stainfo(pstapriv, bc_addr);
 293        return psta;
 294}
 295
 296
 297u8 r8712_access_ctrl(struct wlan_acl_pool *pacl_list, u8 *mac_addr)
 298{
 299        return true;
 300}
 301