Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 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 | |
| 37 | static void _init_stainfo(struct sta_info *psta) |
| 38 | { |
| 39 | memset((u8 *)psta, 0, sizeof(struct sta_info)); |
| 40 | spin_lock_init(&psta->lock); |
James A Shackleford | 534c4ac | 2014-06-24 22:52:34 -0400 | [diff] [blame] | 41 | INIT_LIST_HEAD(&psta->list); |
| 42 | INIT_LIST_HEAD(&psta->hash_list); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 43 | _r8712_init_sta_xmit_priv(&psta->sta_xmitpriv); |
| 44 | _r8712_init_sta_recv_priv(&psta->sta_recvpriv); |
James A Shackleford | 534c4ac | 2014-06-24 22:52:34 -0400 | [diff] [blame] | 45 | INIT_LIST_HEAD(&psta->asoc_list); |
| 46 | INIT_LIST_HEAD(&psta->auth_list); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | u32 _r8712_init_sta_priv(struct sta_priv *pstapriv) |
| 50 | { |
| 51 | struct sta_info *psta; |
| 52 | s32 i; |
| 53 | |
Vitaly Osipov | 91d435f | 2014-05-24 18:19:27 +1000 | [diff] [blame] | 54 | pstapriv->pallocated_stainfo_buf = kmalloc(sizeof(struct sta_info) * |
| 55 | NUM_STA + 4, GFP_ATOMIC); |
Bhumika Goyal | 9155c92 | 2016-02-24 16:09:31 +0530 | [diff] [blame] | 56 | if (!pstapriv->pallocated_stainfo_buf) |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 57 | return _FAIL; |
| 58 | pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 - |
| 59 | ((addr_t)(pstapriv->pallocated_stainfo_buf) & 3); |
| 60 | _init_queue(&pstapriv->free_sta_queue); |
| 61 | spin_lock_init(&pstapriv->sta_hash_lock); |
| 62 | pstapriv->asoc_sta_count = 0; |
| 63 | _init_queue(&pstapriv->sleep_q); |
| 64 | _init_queue(&pstapriv->wakeup_q); |
| 65 | psta = (struct sta_info *)(pstapriv->pstainfo_buf); |
| 66 | for (i = 0; i < NUM_STA; i++) { |
| 67 | _init_stainfo(psta); |
James A Shackleford | 534c4ac | 2014-06-24 22:52:34 -0400 | [diff] [blame] | 68 | INIT_LIST_HEAD(&(pstapriv->sta_hash[i])); |
James A Shackleford | e99a428 | 2014-06-24 22:52:39 -0400 | [diff] [blame] | 69 | list_add_tail(&psta->list, &pstapriv->free_sta_queue.queue); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 70 | psta++; |
| 71 | } |
James A Shackleford | 534c4ac | 2014-06-24 22:52:34 -0400 | [diff] [blame] | 72 | INIT_LIST_HEAD(&pstapriv->asoc_list); |
| 73 | INIT_LIST_HEAD(&pstapriv->auth_list); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 74 | return _SUCCESS; |
| 75 | } |
| 76 | |
| 77 | /* this function is used to free the memory of lock || sema for all stainfos */ |
| 78 | static void mfree_all_stainfo(struct sta_priv *pstapriv) |
| 79 | { |
| 80 | unsigned long irqL; |
| 81 | struct list_head *plist, *phead; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 82 | |
| 83 | spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL); |
James A Shackleford | e99a428 | 2014-06-24 22:52:39 -0400 | [diff] [blame] | 84 | phead = &pstapriv->free_sta_queue.queue; |
James A Shackleford | 849fb0a | 2014-06-24 22:52:38 -0400 | [diff] [blame] | 85 | plist = phead->next; |
Luis de Bethencourt | 1ca9688 | 2015-10-19 18:14:29 +0100 | [diff] [blame] | 86 | while (!end_of_queue_search(phead, plist)) |
James A Shackleford | 849fb0a | 2014-06-24 22:52:38 -0400 | [diff] [blame] | 87 | plist = plist->next; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 88 | |
| 89 | spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL); |
| 90 | } |
| 91 | |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 92 | u32 _r8712_free_sta_priv(struct sta_priv *pstapriv) |
| 93 | { |
| 94 | if (pstapriv) { |
Amitoj Kaur Chawla | ec85e8c | 2015-11-05 02:36:58 +0530 | [diff] [blame] | 95 | /* be done before free sta_hash_lock */ |
| 96 | mfree_all_stainfo(pstapriv); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 97 | kfree(pstapriv->pallocated_stainfo_buf); |
| 98 | } |
| 99 | return _SUCCESS; |
| 100 | } |
| 101 | |
| 102 | struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr) |
| 103 | { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 104 | s32 index; |
| 105 | struct list_head *phash_list; |
| 106 | struct sta_info *psta; |
| 107 | struct __queue *pfree_sta_queue; |
| 108 | struct recv_reorder_ctrl *preorder_ctrl; |
| 109 | int i = 0; |
| 110 | u16 wRxSeqInitialValue = 0xffff; |
| 111 | unsigned long flags; |
| 112 | |
| 113 | pfree_sta_queue = &pstapriv->free_sta_queue; |
Geliang Tang | 818ff7b | 2016-02-01 22:47:03 +0800 | [diff] [blame] | 114 | spin_lock_irqsave(&pfree_sta_queue->lock, flags); |
| 115 | psta = list_first_entry_or_null(&pfree_sta_queue->queue, |
| 116 | struct sta_info, list); |
| 117 | if (psta) { |
| 118 | list_del_init(&psta->list); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 119 | _init_stainfo(psta); |
| 120 | memcpy(psta->hwaddr, hwaddr, ETH_ALEN); |
| 121 | index = wifi_mac_hash(hwaddr); |
| 122 | if (index >= NUM_STA) { |
| 123 | psta = NULL; |
| 124 | goto exit; |
| 125 | } |
Geliang Tang | 818ff7b | 2016-02-01 22:47:03 +0800 | [diff] [blame] | 126 | phash_list = &pstapriv->sta_hash[index]; |
James A Shackleford | fdfbf78 | 2014-06-24 22:52:36 -0400 | [diff] [blame] | 127 | list_add_tail(&psta->hash_list, phash_list); |
Thomas Cort | 77e73e8 | 2013-10-01 11:26:55 -0400 | [diff] [blame] | 128 | pstapriv->asoc_sta_count++; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 129 | |
| 130 | /* For the SMC router, the sequence number of first packet of WPS handshake |
| 131 | * will be 0. In this case, this packet will be dropped by recv_decache function |
| 132 | * if we use the 0x00 as the default value for tid_rxseq variable. So, we |
| 133 | * initialize the tid_rxseq variable as the 0xffff. |
| 134 | */ |
| 135 | for (i = 0; i < 16; i++) |
| 136 | memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], |
| 137 | &wRxSeqInitialValue, 2); |
| 138 | /* for A-MPDU Rx reordering buffer control */ |
Thomas Cort | 77e73e8 | 2013-10-01 11:26:55 -0400 | [diff] [blame] | 139 | for (i = 0; i < 16; i++) { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 140 | preorder_ctrl = &psta->recvreorder_ctrl[i]; |
| 141 | preorder_ctrl->padapter = pstapriv->padapter; |
| 142 | preorder_ctrl->indicate_seq = 0xffff; |
| 143 | preorder_ctrl->wend_b = 0xffff; |
| 144 | preorder_ctrl->wsize_b = 64; |
| 145 | _init_queue(&preorder_ctrl->pending_recvframe_queue); |
| 146 | r8712_init_recv_timer(preorder_ctrl); |
| 147 | } |
| 148 | } |
| 149 | exit: |
Geliang Tang | 818ff7b | 2016-02-01 22:47:03 +0800 | [diff] [blame] | 150 | spin_unlock_irqrestore(&pfree_sta_queue->lock, flags); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 151 | return psta; |
| 152 | } |
| 153 | |
| 154 | /* using pstapriv->sta_hash_lock to protect */ |
| 155 | void r8712_free_stainfo(struct _adapter *padapter, struct sta_info *psta) |
| 156 | { |
| 157 | int i; |
| 158 | unsigned long irqL0; |
| 159 | struct __queue *pfree_sta_queue; |
| 160 | struct recv_reorder_ctrl *preorder_ctrl; |
| 161 | struct sta_xmit_priv *pstaxmitpriv; |
| 162 | struct xmit_priv *pxmitpriv = &padapter->xmitpriv; |
| 163 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 164 | |
| 165 | if (psta == NULL) |
| 166 | return; |
| 167 | pfree_sta_queue = &pstapriv->free_sta_queue; |
| 168 | pstaxmitpriv = &psta->sta_xmitpriv; |
| 169 | spin_lock_irqsave(&(pxmitpriv->vo_pending.lock), irqL0); |
| 170 | r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending); |
James A Shackleford | 29197b7 | 2014-06-24 22:52:37 -0400 | [diff] [blame] | 171 | list_del_init(&(pstaxmitpriv->vo_q.tx_pending)); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 172 | spin_unlock_irqrestore(&(pxmitpriv->vo_pending.lock), irqL0); |
| 173 | spin_lock_irqsave(&(pxmitpriv->vi_pending.lock), irqL0); |
| 174 | r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending); |
James A Shackleford | 29197b7 | 2014-06-24 22:52:37 -0400 | [diff] [blame] | 175 | list_del_init(&(pstaxmitpriv->vi_q.tx_pending)); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 176 | spin_unlock_irqrestore(&(pxmitpriv->vi_pending.lock), irqL0); |
| 177 | spin_lock_irqsave(&(pxmitpriv->bk_pending.lock), irqL0); |
| 178 | r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending); |
James A Shackleford | 29197b7 | 2014-06-24 22:52:37 -0400 | [diff] [blame] | 179 | list_del_init(&(pstaxmitpriv->bk_q.tx_pending)); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 180 | spin_unlock_irqrestore(&(pxmitpriv->bk_pending.lock), irqL0); |
| 181 | spin_lock_irqsave(&(pxmitpriv->be_pending.lock), irqL0); |
| 182 | r8712_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending); |
James A Shackleford | 29197b7 | 2014-06-24 22:52:37 -0400 | [diff] [blame] | 183 | list_del_init(&(pstaxmitpriv->be_q.tx_pending)); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 184 | spin_unlock_irqrestore(&(pxmitpriv->be_pending.lock), irqL0); |
James A Shackleford | 29197b7 | 2014-06-24 22:52:37 -0400 | [diff] [blame] | 185 | list_del_init(&psta->hash_list); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 186 | pstapriv->asoc_sta_count--; |
| 187 | /* re-init sta_info; 20061114 */ |
| 188 | _r8712_init_sta_xmit_priv(&psta->sta_xmitpriv); |
| 189 | _r8712_init_sta_recv_priv(&psta->sta_recvpriv); |
| 190 | /* for A-MPDU Rx reordering buffer control, |
Raphaƫl Beamonte | bef611a | 2016-09-09 11:31:45 -0400 | [diff] [blame] | 191 | * cancel reordering_ctrl_timer |
| 192 | */ |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 193 | for (i = 0; i < 16; i++) { |
| 194 | preorder_ctrl = &psta->recvreorder_ctrl[i]; |
Sudip Mukherjee | a1471eb | 2015-05-15 14:49:39 +0530 | [diff] [blame] | 195 | del_timer(&preorder_ctrl->reordering_ctrl_timer); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 196 | } |
| 197 | spin_lock(&(pfree_sta_queue->lock)); |
| 198 | /* insert into free_sta_queue; 20061114 */ |
James A Shackleford | e99a428 | 2014-06-24 22:52:39 -0400 | [diff] [blame] | 199 | list_add_tail(&psta->list, &pfree_sta_queue->queue); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 200 | spin_unlock(&(pfree_sta_queue->lock)); |
| 201 | } |
| 202 | |
| 203 | /* free all stainfo which in sta_hash[all] */ |
| 204 | void r8712_free_all_stainfo(struct _adapter *padapter) |
| 205 | { |
| 206 | unsigned long irqL; |
| 207 | struct list_head *plist, *phead; |
| 208 | s32 index; |
| 209 | struct sta_info *psta = NULL; |
| 210 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 211 | struct sta_info *pbcmc_stainfo = r8712_get_bcmc_stainfo(padapter); |
| 212 | |
| 213 | if (pstapriv->asoc_sta_count == 1) |
| 214 | return; |
| 215 | spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL); |
| 216 | for (index = 0; index < NUM_STA; index++) { |
| 217 | phead = &(pstapriv->sta_hash[index]); |
James A Shackleford | 849fb0a | 2014-06-24 22:52:38 -0400 | [diff] [blame] | 218 | plist = phead->next; |
Luis de Bethencourt | 1ca9688 | 2015-10-19 18:14:29 +0100 | [diff] [blame] | 219 | while (!end_of_queue_search(phead, plist)) { |
Geliang Tang | fcc2cf1 | 2016-04-05 09:58:04 +0800 | [diff] [blame] | 220 | psta = container_of(plist, |
| 221 | struct sta_info, hash_list); |
James A Shackleford | 849fb0a | 2014-06-24 22:52:38 -0400 | [diff] [blame] | 222 | plist = plist->next; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 223 | if (pbcmc_stainfo != psta) |
Max Perepelitsyn | 0636b46 | 2015-01-02 14:08:08 +0600 | [diff] [blame] | 224 | r8712_free_stainfo(padapter, psta); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL); |
| 228 | } |
| 229 | |
| 230 | /* any station allocated can be searched by hash list */ |
| 231 | struct sta_info *r8712_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr) |
| 232 | { |
| 233 | unsigned long irqL; |
| 234 | struct list_head *plist, *phead; |
| 235 | struct sta_info *psta = NULL; |
| 236 | u32 index; |
| 237 | |
| 238 | if (hwaddr == NULL) |
| 239 | return NULL; |
| 240 | index = wifi_mac_hash(hwaddr); |
| 241 | spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL); |
| 242 | phead = &(pstapriv->sta_hash[index]); |
James A Shackleford | 849fb0a | 2014-06-24 22:52:38 -0400 | [diff] [blame] | 243 | plist = phead->next; |
Luis de Bethencourt | 1ca9688 | 2015-10-19 18:14:29 +0100 | [diff] [blame] | 244 | while (!end_of_queue_search(phead, plist)) { |
Geliang Tang | fcc2cf1 | 2016-04-05 09:58:04 +0800 | [diff] [blame] | 245 | psta = container_of(plist, struct sta_info, hash_list); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 246 | if ((!memcmp(psta->hwaddr, hwaddr, ETH_ALEN))) { |
| 247 | /* if found the matched address */ |
| 248 | break; |
| 249 | } |
| 250 | psta = NULL; |
James A Shackleford | 849fb0a | 2014-06-24 22:52:38 -0400 | [diff] [blame] | 251 | plist = plist->next; |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 252 | } |
| 253 | spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL); |
| 254 | return psta; |
| 255 | } |
| 256 | |
| 257 | void r8712_init_bcmc_stainfo(struct _adapter *padapter) |
| 258 | { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 259 | unsigned char bcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 260 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 261 | |
Sudip Mukherjee | e29d3eb | 2014-10-27 17:42:25 +0530 | [diff] [blame] | 262 | r8712_alloc_stainfo(pstapriv, bcast_addr); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | struct sta_info *r8712_get_bcmc_stainfo(struct _adapter *padapter) |
| 266 | { |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 267 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 268 | u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 269 | |
Prasanna Karthik | 05871f9 | 2015-06-04 04:48:51 +0000 | [diff] [blame] | 270 | return r8712_get_stainfo(pstapriv, bc_addr); |
Larry Finger | 2865d42 | 2010-08-20 10:15:30 -0500 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | |
| 274 | u8 r8712_access_ctrl(struct wlan_acl_pool *pacl_list, u8 *mac_addr) |
| 275 | { |
| 276 | return true; |
| 277 | } |