1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2019 Realtek Corporation.
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 *****************************************************************************/
15 #define _RTW_STA_MGT_C_
16
17 #include <drv_types.h>
18
test_st_match_rule(_adapter * adapter,u8 * local_naddr,u8 * local_port,u8 * remote_naddr,u8 * remote_port)19 bool test_st_match_rule(_adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port)
20 {
21 if (ntohs(*((u16 *)local_port)) == 5001 || ntohs(*((u16 *)remote_port)) == 5001)
22 return _TRUE;
23 return _FALSE;
24 }
25
26 struct st_register test_st_reg = {
27 .s_proto = 0x06,
28 .rule = test_st_match_rule,
29 };
30
rtw_st_ctl_init(struct st_ctl_t * st_ctl)31 inline void rtw_st_ctl_init(struct st_ctl_t *st_ctl)
32 {
33 _rtw_memset(st_ctl->reg, 0 , sizeof(struct st_register) * SESSION_TRACKER_REG_ID_NUM);
34 _rtw_init_queue(&st_ctl->tracker_q);
35 }
36
rtw_st_ctl_clear_tracker_q(struct st_ctl_t * st_ctl)37 inline void rtw_st_ctl_clear_tracker_q(struct st_ctl_t *st_ctl)
38 {
39 _irqL irqL;
40 _list *plist, *phead;
41 struct session_tracker *st;
42
43 _enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);
44 phead = &st_ctl->tracker_q.queue;
45 plist = get_next(phead);
46 while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
47 st = LIST_CONTAINOR(plist, struct session_tracker, list);
48 plist = get_next(plist);
49 rtw_list_delete(&st->list);
50 rtw_mfree((u8 *)st, sizeof(struct session_tracker));
51 }
52 _exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);
53 }
54
rtw_st_ctl_deinit(struct st_ctl_t * st_ctl)55 inline void rtw_st_ctl_deinit(struct st_ctl_t *st_ctl)
56 {
57 rtw_st_ctl_clear_tracker_q(st_ctl);
58 _rtw_deinit_queue(&st_ctl->tracker_q);
59 }
60
rtw_st_ctl_register(struct st_ctl_t * st_ctl,u8 st_reg_id,struct st_register * reg)61 inline void rtw_st_ctl_register(struct st_ctl_t *st_ctl, u8 st_reg_id, struct st_register *reg)
62 {
63 if (st_reg_id >= SESSION_TRACKER_REG_ID_NUM) {
64 rtw_warn_on(1);
65 return;
66 }
67
68 st_ctl->reg[st_reg_id].s_proto = reg->s_proto;
69 st_ctl->reg[st_reg_id].rule = reg->rule;
70 }
71
rtw_st_ctl_unregister(struct st_ctl_t * st_ctl,u8 st_reg_id)72 inline void rtw_st_ctl_unregister(struct st_ctl_t *st_ctl, u8 st_reg_id)
73 {
74 int i;
75
76 if (st_reg_id >= SESSION_TRACKER_REG_ID_NUM) {
77 rtw_warn_on(1);
78 return;
79 }
80
81 st_ctl->reg[st_reg_id].s_proto = 0;
82 st_ctl->reg[st_reg_id].rule = NULL;
83
84 /* clear tracker queue if no session trecker registered */
85 for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++)
86 if (st_ctl->reg[i].s_proto != 0)
87 break;
88 if (i >= SESSION_TRACKER_REG_ID_NUM)
89 rtw_st_ctl_clear_tracker_q(st_ctl);
90 }
91
rtw_st_ctl_chk_reg_s_proto(struct st_ctl_t * st_ctl,u8 s_proto)92 inline bool rtw_st_ctl_chk_reg_s_proto(struct st_ctl_t *st_ctl, u8 s_proto)
93 {
94 bool ret = _FALSE;
95 int i;
96
97 for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++) {
98 if (st_ctl->reg[i].s_proto == s_proto) {
99 ret = _TRUE;
100 break;
101 }
102 }
103
104 return ret;
105 }
106
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 inline 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)
108 {
109 bool ret = _FALSE;
110 int i;
111 st_match_rule rule;
112
113 for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++) {
114 rule = st_ctl->reg[i].rule;
115 if (rule && rule(adapter, local_naddr, local_port, remote_naddr, remote_port) == _TRUE) {
116 ret = _TRUE;
117 break;
118 }
119 }
120
121 return ret;
122 }
123
rtw_st_ctl_rx(struct sta_info * sta,u8 * ehdr_pos)124 void rtw_st_ctl_rx(struct sta_info *sta, u8 *ehdr_pos)
125 {
126 _adapter *adapter = sta->padapter;
127 struct ethhdr *etherhdr = (struct ethhdr *)ehdr_pos;
128
129 if (ntohs(etherhdr->h_proto) == ETH_P_IP) {
130 u8 *ip = ehdr_pos + ETH_HLEN;
131
132 if (GET_IPV4_PROTOCOL(ip) == 0x06 /* TCP */
133 && rtw_st_ctl_chk_reg_s_proto(&sta->st_ctl, 0x06) == _TRUE
134 ) {
135 u8 *tcp = ip + GET_IPV4_IHL(ip) * 4;
136
137 if (rtw_st_ctl_chk_reg_rule(&sta->st_ctl, adapter, IPV4_DST(ip), TCP_DST(tcp), IPV4_SRC(ip), TCP_SRC(tcp)) == _TRUE) {
138 if (GET_TCP_SYN(tcp) && GET_TCP_ACK(tcp)) {
139 session_tracker_add_cmd(adapter, sta
140 , IPV4_DST(ip), TCP_DST(tcp)
141 , IPV4_SRC(ip), TCP_SRC(tcp));
142 if (DBG_SESSION_TRACKER)
143 RTW_INFO(FUNC_ADPT_FMT" local:"IP_FMT":"PORT_FMT", remote:"IP_FMT":"PORT_FMT" SYN-ACK\n"
144 , FUNC_ADPT_ARG(adapter)
145 , IP_ARG(IPV4_DST(ip)), PORT_ARG(TCP_DST(tcp))
146 , IP_ARG(IPV4_SRC(ip)), PORT_ARG(TCP_SRC(tcp)));
147 }
148 if (GET_TCP_FIN(tcp)) {
149 session_tracker_del_cmd(adapter, sta
150 , IPV4_DST(ip), TCP_DST(tcp)
151 , IPV4_SRC(ip), TCP_SRC(tcp));
152 if (DBG_SESSION_TRACKER)
153 RTW_INFO(FUNC_ADPT_FMT" local:"IP_FMT":"PORT_FMT", remote:"IP_FMT":"PORT_FMT" FIN\n"
154 , FUNC_ADPT_ARG(adapter)
155 , IP_ARG(IPV4_DST(ip)), PORT_ARG(TCP_DST(tcp))
156 , IP_ARG(IPV4_SRC(ip)), PORT_ARG(TCP_SRC(tcp)));
157 }
158 }
159
160 }
161 }
162 }
163
164 #define SESSION_TRACKER_FMT IP_FMT":"PORT_FMT" "IP_FMT":"PORT_FMT" %u %d"
165 #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)
166
dump_st_ctl(void * sel,struct st_ctl_t * st_ctl)167 void dump_st_ctl(void *sel, struct st_ctl_t *st_ctl)
168 {
169 int i;
170 _irqL irqL;
171 _list *plist, *phead;
172 struct session_tracker *st;
173
174 if (!DBG_SESSION_TRACKER)
175 return;
176
177 for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++)
178 RTW_PRINT_SEL(sel, "reg%d: %u %p\n", i, st_ctl->reg[i].s_proto, st_ctl->reg[i].rule);
179
180 _enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);
181 phead = &st_ctl->tracker_q.queue;
182 plist = get_next(phead);
183 while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
184 st = LIST_CONTAINOR(plist, struct session_tracker, list);
185 plist = get_next(plist);
186
187 RTW_PRINT_SEL(sel, SESSION_TRACKER_FMT"\n", SESSION_TRACKER_ARG(st));
188 }
189 _exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);
190
191 }
192
193 void _rtw_init_stainfo(struct sta_info *psta);
_rtw_init_stainfo(struct sta_info * psta)194 void _rtw_init_stainfo(struct sta_info *psta)
195 {
196 _rtw_memset((u8 *)psta, 0, sizeof(struct sta_info));
197
198 _rtw_spinlock_init(&psta->lock);
199 _rtw_init_listhead(&psta->list);
200 _rtw_init_listhead(&psta->hash_list);
201 /* _rtw_init_listhead(&psta->asoc_list); */
202 /* _rtw_init_listhead(&psta->sleep_list); */
203 /* _rtw_init_listhead(&psta->wakeup_list); */
204
205 _rtw_init_queue(&psta->sleep_q);
206 #ifdef CONFIG_RTW_MGMT_QUEUE
207 _rtw_init_queue(&psta->mgmt_sleep_q);
208 #endif
209 _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
210 _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
211
212 #ifdef CONFIG_AP_MODE
213 _rtw_init_listhead(&psta->asoc_list);
214 _rtw_init_listhead(&psta->auth_list);
215 psta->bpairwise_key_installed = _FALSE;
216
217 #ifdef CONFIG_RTW_80211R
218 psta->ft_pairwise_key_installed = _FALSE;
219 #endif
220 #endif /* CONFIG_AP_MODE */
221
222 rtw_st_ctl_init(&psta->st_ctl);
223 }
224
_rtw_init_sta_priv(struct sta_priv * pstapriv)225 u32 _rtw_init_sta_priv(struct sta_priv *pstapriv)
226 {
227 _adapter *adapter = container_of(pstapriv, _adapter, stapriv);
228 struct macid_ctl_t *macid_ctl = adapter_to_macidctl(adapter);
229 struct sta_info *psta;
230 s32 i;
231 u32 ret = _FAIL;
232
233 pstapriv->padapter = adapter;
234
235 pstapriv->pallocated_stainfo_buf = rtw_zvmalloc(
236 sizeof(struct sta_info) * NUM_STA + MEM_ALIGNMENT_OFFSET);
237 if (!pstapriv->pallocated_stainfo_buf)
238 goto exit;
239
240 pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf;
241 if ((SIZE_PTR)pstapriv->pstainfo_buf & MEM_ALIGNMENT_PADDING)
242 pstapriv->pstainfo_buf += MEM_ALIGNMENT_OFFSET -
243 ((SIZE_PTR)pstapriv->pstainfo_buf & MEM_ALIGNMENT_PADDING);
244
245 _rtw_init_queue(&pstapriv->free_sta_queue);
246
247 _rtw_spinlock_init(&pstapriv->sta_hash_lock);
248
249 /* _rtw_init_queue(&pstapriv->asoc_q); */
250 pstapriv->asoc_sta_count = 0;
251 _rtw_init_queue(&pstapriv->sleep_q);
252 _rtw_init_queue(&pstapriv->wakeup_q);
253
254 psta = (struct sta_info *)(pstapriv->pstainfo_buf);
255
256
257 for (i = 0; i < NUM_STA; i++) {
258 _rtw_init_stainfo(psta);
259
260 _rtw_init_listhead(&(pstapriv->sta_hash[i]));
261
262 rtw_list_insert_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue));
263
264 psta++;
265 }
266
267 pstapriv->adhoc_expire_to = 4; /* 4 * 2 = 8 sec */
268
269 #ifdef CONFIG_AP_MODE
270 pstapriv->max_aid = macid_ctl->num;
271 pstapriv->rr_aid = 0;
272 pstapriv->started_aid = 1;
273 pstapriv->sta_aid = rtw_zmalloc(pstapriv->max_aid * sizeof(struct sta_info *));
274 if (!pstapriv->sta_aid)
275 goto exit;
276 pstapriv->aid_bmp_len = AID_BMP_LEN(pstapriv->max_aid);
277 pstapriv->sta_dz_bitmap = rtw_zmalloc(pstapriv->aid_bmp_len);
278 if (!pstapriv->sta_dz_bitmap)
279 goto exit;
280 pstapriv->tim_bitmap = rtw_zmalloc(pstapriv->aid_bmp_len);
281 if (!pstapriv->tim_bitmap)
282 goto exit;
283
284 _rtw_init_listhead(&pstapriv->asoc_list);
285 _rtw_init_listhead(&pstapriv->auth_list);
286 _rtw_spinlock_init(&pstapriv->asoc_list_lock);
287 _rtw_spinlock_init(&pstapriv->auth_list_lock);
288 pstapriv->asoc_list_cnt = 0;
289 pstapriv->auth_list_cnt = 0;
290 #ifdef CONFIG_RTW_TOKEN_BASED_XMIT
291 pstapriv->tbtx_asoc_list_cnt = 0;
292 #endif
293
294 pstapriv->auth_to = 3; /* 3*2 = 6 sec */
295 pstapriv->assoc_to = 3;
296 /* pstapriv->expire_to = 900; */ /* 900*2 = 1800 sec = 30 min, expire after no any traffic. */
297 /* pstapriv->expire_to = 30; */ /* 30*2 = 60 sec = 1 min, expire after no any traffic. */
298 #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
299 pstapriv->expire_to = 3; /* 3*2 = 6 sec */
300 #else
301 pstapriv->expire_to = 60;/* 60*2 = 120 sec = 2 min, expire after no any traffic. */
302 #endif
303 #ifdef CONFIG_ATMEL_RC_PATCH
304 _rtw_memset(pstapriv->atmel_rc_pattern, 0, ETH_ALEN);
305 #endif
306 pstapriv->max_num_sta = NUM_STA;
307
308 #if CONFIG_RTW_MACADDR_ACL
309 for (i = 0; i < RTW_ACL_PERIOD_NUM; i++)
310 rtw_macaddr_acl_init(adapter, i);
311 #endif
312 #endif /* CONFIG_AP_MODE */
313
314 #if CONFIG_RTW_PRE_LINK_STA
315 rtw_pre_link_sta_ctl_init(pstapriv);
316 #endif
317
318 _rtw_spinlock_init(&pstapriv->tx_rpt_lock);
319
320 #if defined(DBG_ROAMING_TEST) || defined(CONFIG_RTW_REPEATER_SON)
321 rtw_set_rx_chk_limit(adapter,1);
322 #elif defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && !defined(CONFIG_LPS_LCLK_WD_TIMER)
323 rtw_set_rx_chk_limit(adapter,4);
324 #else
325 rtw_set_rx_chk_limit(adapter,8);
326 #endif
327
328 ret = _SUCCESS;
329
330 exit:
331 if (ret != _SUCCESS) {
332 if (pstapriv->pallocated_stainfo_buf)
333 rtw_vmfree(pstapriv->pallocated_stainfo_buf,
334 sizeof(struct sta_info) * NUM_STA + MEM_ALIGNMENT_OFFSET);
335 #ifdef CONFIG_AP_MODE
336 if (pstapriv->sta_aid)
337 rtw_mfree(pstapriv->sta_aid, pstapriv->max_aid * sizeof(struct sta_info *));
338 if (pstapriv->sta_dz_bitmap)
339 rtw_mfree(pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len);
340 #endif
341 }
342
343 return ret;
344 }
345
rtw_stainfo_offset(struct sta_priv * stapriv,struct sta_info * sta)346 inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)
347 {
348 int offset = (((u8 *)sta) - stapriv->pstainfo_buf) / sizeof(struct sta_info);
349
350 if (!stainfo_offset_valid(offset))
351 RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);
352
353 return offset;
354 }
355
rtw_get_stainfo_by_offset(struct sta_priv * stapriv,int offset)356 inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)
357 {
358 if (!stainfo_offset_valid(offset))
359 RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);
360
361 return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));
362 }
363
364 void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv);
_rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv * psta_xmitpriv)365 void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv)
366 {
367
368 _rtw_spinlock_free(&psta_xmitpriv->lock);
369
370 _rtw_spinlock_free(&(psta_xmitpriv->be_q.sta_pending.lock));
371 _rtw_spinlock_free(&(psta_xmitpriv->bk_q.sta_pending.lock));
372 _rtw_spinlock_free(&(psta_xmitpriv->vi_q.sta_pending.lock));
373 _rtw_spinlock_free(&(psta_xmitpriv->vo_q.sta_pending.lock));
374 #ifdef CONFIG_RTW_MGMT_QUEUE
375 _rtw_spinlock_free(&(psta_xmitpriv->mgmt_q.sta_pending.lock));
376 #endif
377 }
378
_rtw_free_sta_recv_priv_lock(struct sta_recv_priv * psta_recvpriv)379 static void _rtw_free_sta_recv_priv_lock(struct sta_recv_priv *psta_recvpriv)
380 {
381
382 _rtw_spinlock_free(&psta_recvpriv->lock);
383
384 _rtw_spinlock_free(&(psta_recvpriv->defrag_q.lock));
385
386
387 }
388
389 void rtw_mfree_stainfo(struct sta_info *psta);
rtw_mfree_stainfo(struct sta_info * psta)390 void rtw_mfree_stainfo(struct sta_info *psta)
391 {
392
393 if (&psta->lock != NULL)
394 _rtw_spinlock_free(&psta->lock);
395
396 _rtw_free_sta_xmit_priv_lock(&psta->sta_xmitpriv);
397 _rtw_free_sta_recv_priv_lock(&psta->sta_recvpriv);
398
399 }
400
401
402 /* this function is used to free the memory of lock || sema for all stainfos */
403 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv);
rtw_mfree_all_stainfo(struct sta_priv * pstapriv)404 void rtw_mfree_all_stainfo(struct sta_priv *pstapriv)
405 {
406 _irqL irqL;
407 _list *plist, *phead;
408 struct sta_info *psta = NULL;
409
410
411 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
412
413 phead = get_list_head(&pstapriv->free_sta_queue);
414 plist = get_next(phead);
415
416 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
417 psta = LIST_CONTAINOR(plist, struct sta_info , list);
418 plist = get_next(plist);
419
420 rtw_mfree_stainfo(psta);
421 }
422
423 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
424
425
426 }
427
428 void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv);
rtw_mfree_sta_priv_lock(struct sta_priv * pstapriv)429 void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv)
430 {
431 rtw_mfree_all_stainfo(pstapriv); /* be done before free sta_hash_lock */
432
433 _rtw_spinlock_free(&pstapriv->free_sta_queue.lock);
434
435 _rtw_spinlock_free(&pstapriv->sta_hash_lock);
436 _rtw_spinlock_free(&pstapriv->wakeup_q.lock);
437 _rtw_spinlock_free(&pstapriv->sleep_q.lock);
438
439 #ifdef CONFIG_AP_MODE
440 _rtw_spinlock_free(&pstapriv->asoc_list_lock);
441 _rtw_spinlock_free(&pstapriv->auth_list_lock);
442 #endif
443
444 }
445
_rtw_free_sta_priv(struct sta_priv * pstapriv)446 u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)
447 {
448 _irqL irqL;
449 _list *phead, *plist;
450 struct sta_info *psta = NULL;
451 struct recv_reorder_ctrl *preorder_ctrl;
452 int index;
453
454 if (pstapriv) {
455
456 /* delete all reordering_ctrl_timer */
457 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
458 for (index = 0; index < NUM_STA; index++) {
459 phead = &(pstapriv->sta_hash[index]);
460 plist = get_next(phead);
461
462 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
463 int i;
464 psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);
465 plist = get_next(plist);
466
467 for (i = 0; i < 16 ; i++) {
468 preorder_ctrl = &psta->recvreorder_ctrl[i];
469 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
470 }
471 }
472 }
473 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
474 /*===============================*/
475
476 rtw_mfree_sta_priv_lock(pstapriv);
477
478 #if CONFIG_RTW_MACADDR_ACL
479 for (index = 0; index < RTW_ACL_PERIOD_NUM; index++)
480 rtw_macaddr_acl_deinit(pstapriv->padapter, index);
481 #endif
482
483 #if CONFIG_RTW_PRE_LINK_STA
484 rtw_pre_link_sta_ctl_deinit(pstapriv);
485 #endif
486
487 _rtw_spinlock_free(&pstapriv->tx_rpt_lock);
488
489 if (pstapriv->pallocated_stainfo_buf)
490 rtw_vmfree(pstapriv->pallocated_stainfo_buf,
491 sizeof(struct sta_info) * NUM_STA + MEM_ALIGNMENT_OFFSET);
492 #ifdef CONFIG_AP_MODE
493 if (pstapriv->sta_aid)
494 rtw_mfree(pstapriv->sta_aid, pstapriv->max_aid * sizeof(struct sta_info *));
495 if (pstapriv->sta_dz_bitmap)
496 rtw_mfree(pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len);
497 if (pstapriv->tim_bitmap)
498 rtw_mfree(pstapriv->tim_bitmap, pstapriv->aid_bmp_len);
499 #endif
500 }
501
502 return _SUCCESS;
503 }
504
505
rtw_init_recv_timer(struct recv_reorder_ctrl * preorder_ctrl)506 static void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
507 {
508 _adapter *padapter = preorder_ctrl->padapter;
509
510 #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
511 rtw_init_timer(&(preorder_ctrl->reordering_ctrl_timer), padapter, rtw_reordering_ctrl_timeout_handler, preorder_ctrl);
512 #endif
513 }
514
515 /* struct sta_info *rtw_alloc_stainfo(_queue *pfree_sta_queue, unsigned char *hwaddr) */
rtw_alloc_stainfo(struct sta_priv * pstapriv,const u8 * hwaddr)516 struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr)
517 {
518 _irqL irqL2;
519 s32 index;
520 _list *phash_list;
521 struct sta_info *psta;
522 _queue *pfree_sta_queue;
523 struct recv_reorder_ctrl *preorder_ctrl;
524 int i = 0;
525 u16 wRxSeqInitialValue = 0xffff;
526
527
528 pfree_sta_queue = &pstapriv->free_sta_queue;
529
530 /* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL); */
531 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
532 if (_rtw_queue_empty(pfree_sta_queue) == _TRUE) {
533 /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */
534 /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */
535 psta = NULL;
536 } else {
537 psta = LIST_CONTAINOR(get_next(&pfree_sta_queue->queue), struct sta_info, list);
538
539 rtw_list_delete(&(psta->list));
540
541 /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */
542 _rtw_init_stainfo(psta);
543
544 psta->padapter = pstapriv->padapter;
545
546 _rtw_memcpy(psta->cmn.mac_addr, hwaddr, ETH_ALEN);
547
548 index = wifi_mac_hash(hwaddr);
549
550
551 if (index >= NUM_STA) {
552 psta = NULL;
553 goto exit;
554 }
555 phash_list = &(pstapriv->sta_hash[index]);
556
557 /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */
558
559 rtw_list_insert_tail(&psta->hash_list, phash_list);
560
561 pstapriv->asoc_sta_count++;
562
563 /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */
564
565 /* Commented by Albert 2009/08/13
566 * For the SMC router, the sequence number of first packet of WPS handshake will be 0.
567 * 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.
568 * So, we initialize the tid_rxseq variable as the 0xffff. */
569
570 for (i = 0; i < 16; i++) {
571 _rtw_memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], &wRxSeqInitialValue, 2);
572 _rtw_memcpy(&psta->sta_recvpriv.bmc_tid_rxseq[i], &wRxSeqInitialValue, 2);
573 _rtw_memset(&psta->sta_recvpriv.rxcache.iv[i], 0, sizeof(psta->sta_recvpriv.rxcache.iv[i]));
574 }
575 _rtw_memcpy(&psta->sta_recvpriv.nonqos_bmc_rxseq,&wRxSeqInitialValue,2);
576 _rtw_memcpy(&psta->sta_recvpriv.nonqos_rxseq,&wRxSeqInitialValue,2);
577
578 rtw_init_timer(&psta->addba_retry_timer, psta->padapter, addba_timer_hdl, psta);
579 #ifdef CONFIG_IEEE80211W
580 rtw_init_timer(&psta->dot11w_expire_timer, psta->padapter, sa_query_timer_hdl, psta);
581 #endif /* CONFIG_IEEE80211W */
582 #ifdef CONFIG_TDLS
583 rtw_init_tdls_timer(pstapriv->padapter, psta);
584 #endif /* CONFIG_TDLS */
585
586 /* for A-MPDU Rx reordering buffer control */
587 for (i = 0; i < 16 ; i++) {
588 preorder_ctrl = &psta->recvreorder_ctrl[i];
589 preorder_ctrl->padapter = pstapriv->padapter;
590 preorder_ctrl->tid = i;
591 preorder_ctrl->enable = _FALSE;
592 preorder_ctrl->indicate_seq = 0xffff;
593 #ifdef DBG_RX_SEQ
594 RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" tid:%u SN_CLEAR indicate_seq:%d\n"
595 , FUNC_ADPT_ARG(pstapriv->padapter), i, preorder_ctrl->indicate_seq);
596 #endif
597 preorder_ctrl->wend_b = 0xffff;
598 preorder_ctrl->wsize_b = 64;/* 64; */
599 preorder_ctrl->ampdu_size = RX_AMPDU_SIZE_INVALID;
600
601 _rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);
602
603 rtw_init_recv_timer(preorder_ctrl);
604 rtw_clear_bit(RTW_RECV_ACK_OR_TIMEOUT, &preorder_ctrl->rec_abba_rsp_ack);
605
606 }
607 ATOMIC_SET(&psta->keytrack, 0);
608
609 /* init for DM */
610 psta->cmn.rssi_stat.rssi = (-1);
611 psta->cmn.rssi_stat.rssi_cck = (-1);
612 psta->cmn.rssi_stat.rssi_ofdm = (-1);
613 #ifdef CONFIG_ATMEL_RC_PATCH
614 psta->flag_atmel_rc = 0;
615 #endif
616
617 #ifdef CONFIG_RTW_TOKEN_BASED_XMIT
618 psta->tbtx_enable = _FALSE;
619 #endif
620 /* init for the sequence number of received management frame */
621 psta->RxMgmtFrameSeqNum = 0xffff;
622 _rtw_memset(&psta->sta_stats, 0, sizeof(struct stainfo_stats));
623
624 rtw_alloc_macid(pstapriv->padapter, psta);
625
626 psta->tx_q_enable = 0;
627 _rtw_init_queue(&psta->tx_queue);
628 _init_workitem(&psta->tx_q_work, rtw_xmit_dequeue_callback, NULL);
629 }
630
631 exit:
632
633 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
634
635
636 if (psta)
637 rtw_mi_update_iface_status(&(pstapriv->padapter->mlmepriv), 0);
638
639 return psta;
640 }
641
642
643 /* using pstapriv->sta_hash_lock to protect */
rtw_free_stainfo(_adapter * padapter,struct sta_info * psta)644 u32 rtw_free_stainfo(_adapter *padapter , struct sta_info *psta)
645 {
646 int i;
647 _irqL irqL0;
648 _queue *pfree_sta_queue, *pdefrag_q = NULL;
649 struct recv_reorder_ctrl *preorder_ctrl;
650 struct sta_xmit_priv *pstaxmitpriv;
651 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
652 struct sta_priv *pstapriv = &padapter->stapriv;
653 struct hw_xmit *phwxmit;
654 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
655 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
656 int pending_qcnt[4];
657 u8 is_pre_link_sta = _FALSE;
658 _list *phead, *plist;
659 _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
660 union recv_frame *prframe;
661
662 if (psta == NULL)
663 goto exit;
664
665 #ifdef CONFIG_RTW_80211K
666 rm_post_event(padapter, RM_ID_FOR_ALL(psta->cmn.aid), RM_EV_cancel);
667 #endif
668
669 is_pre_link_sta = rtw_is_pre_link_sta(pstapriv, psta->cmn.mac_addr);
670
671 if (is_pre_link_sta == _FALSE) {
672 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
673 rtw_list_delete(&psta->hash_list);
674 pstapriv->asoc_sta_count--;
675 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
676 rtw_mi_update_iface_status(&(padapter->mlmepriv), 0);
677 } else {
678 _enter_critical_bh(&psta->lock, &irqL0);
679 psta->state = WIFI_FW_PRE_LINK;
680 _exit_critical_bh(&psta->lock, &irqL0);
681 }
682
683 _enter_critical_bh(&psta->lock, &irqL0);
684 psta->state &= ~WIFI_ASOC_STATE;
685 _exit_critical_bh(&psta->lock, &irqL0);
686
687 pfree_sta_queue = &pstapriv->free_sta_queue;
688
689
690 pstaxmitpriv = &psta->sta_xmitpriv;
691
692 /* rtw_list_delete(&psta->sleep_list); */
693
694 /* rtw_list_delete(&psta->wakeup_list); */
695
696 rtw_free_xmitframe_queue(pxmitpriv, &psta->tx_queue);
697 _rtw_deinit_queue(&psta->tx_queue);
698
699 _enter_critical_bh(&pxmitpriv->lock, &irqL0);
700
701 rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);
702 psta->sleepq_len = 0;
703
704 #ifdef CONFIG_RTW_MGMT_QUEUE
705 rtw_free_mgmt_xmitframe_queue(pxmitpriv, &psta->mgmt_sleep_q);
706 psta->mgmt_sleepq_len = 0;
707 #endif
708
709 /* vo */
710 /* _enter_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */
711 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
712 rtw_list_delete(&(pstaxmitpriv->vo_q.tx_pending));
713 phwxmit = pxmitpriv->hwxmits;
714 phwxmit->accnt -= pstaxmitpriv->vo_q.qcnt;
715 pending_qcnt[0] = pstaxmitpriv->vo_q.qcnt;
716 pstaxmitpriv->vo_q.qcnt = 0;
717 /* _exit_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */
718
719 /* vi */
720 /* _enter_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */
721 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
722 rtw_list_delete(&(pstaxmitpriv->vi_q.tx_pending));
723 phwxmit = pxmitpriv->hwxmits + 1;
724 phwxmit->accnt -= pstaxmitpriv->vi_q.qcnt;
725 pending_qcnt[1] = pstaxmitpriv->vi_q.qcnt;
726 pstaxmitpriv->vi_q.qcnt = 0;
727 /* _exit_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */
728
729 /* be */
730 /* _enter_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */
731 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
732 rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
733 phwxmit = pxmitpriv->hwxmits + 2;
734 phwxmit->accnt -= pstaxmitpriv->be_q.qcnt;
735 pending_qcnt[2] = pstaxmitpriv->be_q.qcnt;
736 pstaxmitpriv->be_q.qcnt = 0;
737 /* _exit_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */
738
739 /* bk */
740 /* _enter_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */
741 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
742 rtw_list_delete(&(pstaxmitpriv->bk_q.tx_pending));
743 phwxmit = pxmitpriv->hwxmits + 3;
744 phwxmit->accnt -= pstaxmitpriv->bk_q.qcnt;
745 pending_qcnt[3] = pstaxmitpriv->bk_q.qcnt;
746 pstaxmitpriv->bk_q.qcnt = 0;
747 /* _exit_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */
748
749 #ifdef CONFIG_RTW_MGMT_QUEUE
750 /* mgmt */
751 rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->mgmt_q.sta_pending);
752 rtw_list_delete(&(pstaxmitpriv->mgmt_q.tx_pending));
753 phwxmit = pxmitpriv->hwxmits + 4;
754 phwxmit->accnt -= pstaxmitpriv->mgmt_q.qcnt;
755 pstaxmitpriv->mgmt_q.qcnt = 0;
756 #endif
757
758 rtw_os_wake_queue_at_free_stainfo(padapter, pending_qcnt);
759
760 _exit_critical_bh(&pxmitpriv->lock, &irqL0);
761
762
763 /* re-init sta_info; 20061114 */ /* will be init in alloc_stainfo */
764 /* _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv); */
765 /* _rtw_init_sta_recv_priv(&psta->sta_recvpriv); */
766 #ifdef CONFIG_IEEE80211W
767 _cancel_timer_ex(&psta->dot11w_expire_timer);
768 #endif /* CONFIG_IEEE80211W */
769 _cancel_timer_ex(&psta->addba_retry_timer);
770
771 #ifdef CONFIG_TDLS
772 psta->tdls_sta_state = TDLS_STATE_NONE;
773 #endif /* CONFIG_TDLS */
774
775 /* for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer */
776 for (i = 0; i < 16 ; i++) {
777 _irqL irqL;
778 _queue *ppending_recvframe_queue;
779
780 preorder_ctrl = &psta->recvreorder_ctrl[i];
781 rtw_clear_bit(RTW_RECV_ACK_OR_TIMEOUT, &preorder_ctrl->rec_abba_rsp_ack);
782
783 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
784
785
786 ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
787
788 _enter_critical_bh(&ppending_recvframe_queue->lock, &irqL);
789
790 phead = get_list_head(ppending_recvframe_queue);
791 plist = get_next(phead);
792
793 while (!rtw_is_list_empty(phead)) {
794 prframe = LIST_CONTAINOR(plist, union recv_frame, u);
795
796 plist = get_next(plist);
797
798 rtw_list_delete(&(prframe->u.hdr.list));
799
800 rtw_free_recvframe(prframe, pfree_recv_queue);
801 }
802
803 _exit_critical_bh(&ppending_recvframe_queue->lock, &irqL);
804
805 }
806
807 /* CVE-2020-24586, clear defrag queue */
808 pdefrag_q = &psta->sta_recvpriv.defrag_q;
809 enter_critical_bh(&pdefrag_q->lock);
810 phead = get_list_head(pdefrag_q);
811 plist = get_next(phead);
812 while (!rtw_is_list_empty(phead)) {
813 prframe = LIST_CONTAINOR(plist, union recv_frame, u);
814 plist = get_next(plist);
815 rtw_list_delete(&(prframe->u.hdr.list));
816 rtw_free_recvframe(prframe, pfree_recv_queue);
817 }
818 exit_critical_bh(&pdefrag_q->lock);
819
820
821 if (!((psta->state & WIFI_AP_STATE) || MacAddr_isBcst(psta->cmn.mac_addr)) && is_pre_link_sta == _FALSE)
822 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _FALSE);
823
824
825 /* release mac id for non-bc/mc station, */
826 if (is_pre_link_sta == _FALSE)
827 rtw_release_macid(pstapriv->padapter, psta);
828
829 #ifdef CONFIG_AP_MODE
830
831 /*
832 _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
833 rtw_list_delete(&psta->asoc_list);
834 _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
835 */
836 _enter_critical_bh(&pstapriv->auth_list_lock, &irqL0);
837 if (!rtw_is_list_empty(&psta->auth_list)) {
838 rtw_list_delete(&psta->auth_list);
839 pstapriv->auth_list_cnt--;
840 }
841 _exit_critical_bh(&pstapriv->auth_list_lock, &irqL0);
842
843 psta->expire_to = 0;
844 #ifdef CONFIG_ATMEL_RC_PATCH
845 psta->flag_atmel_rc = 0;
846 #endif
847 psta->sleepq_ac_len = 0;
848 psta->qos_info = 0;
849
850 psta->max_sp_len = 0;
851 psta->uapsd_bk = 0;
852 psta->uapsd_be = 0;
853 psta->uapsd_vi = 0;
854 psta->uapsd_vo = 0;
855
856 psta->has_legacy_ac = 0;
857
858 #ifdef CONFIG_NATIVEAP_MLME
859
860 if (pmlmeinfo->state == _HW_STATE_AP_) {
861 rtw_tim_map_clear(padapter, pstapriv->sta_dz_bitmap, psta->cmn.aid);
862 rtw_tim_map_clear(padapter, pstapriv->tim_bitmap, psta->cmn.aid);
863
864 /* rtw_indicate_sta_disassoc_event(padapter, psta); */
865
866 if ((psta->cmn.aid > 0) && (pstapriv->sta_aid[psta->cmn.aid - 1] == psta)) {
867 pstapriv->sta_aid[psta->cmn.aid - 1] = NULL;
868 psta->cmn.aid = 0;
869 }
870 }
871
872 #endif /* CONFIG_NATIVEAP_MLME */
873
874 #if !defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && defined(CONFIG_80211N_HT)
875 psta->under_exist_checking = 0;
876 #endif
877
878 #endif /* CONFIG_AP_MODE */
879
880 rtw_st_ctl_deinit(&psta->st_ctl);
881
882 if (is_pre_link_sta == _FALSE) {
883 _rtw_spinlock_free(&psta->lock);
884
885 /* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL0); */
886 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
887 rtw_list_insert_tail(&psta->list, get_list_head(pfree_sta_queue));
888 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
889 /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL0); */
890 }
891
892 exit:
893 return _SUCCESS;
894 }
895
896 /* free all stainfo which in sta_hash[all] */
rtw_free_all_stainfo(_adapter * padapter)897 void rtw_free_all_stainfo(_adapter *padapter)
898 {
899 _irqL irqL;
900 _list *plist, *phead;
901 s32 index;
902 struct sta_info *psta = NULL;
903 struct sta_priv *pstapriv = &padapter->stapriv;
904 struct sta_info *pbcmc_stainfo = rtw_get_bcmc_stainfo(padapter);
905 u8 free_sta_num = 0;
906 char free_sta_list[NUM_STA];
907 int stainfo_offset;
908
909
910 if (pstapriv->asoc_sta_count == 1)
911 goto exit;
912
913 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
914
915 for (index = 0; index < NUM_STA; index++) {
916 phead = &(pstapriv->sta_hash[index]);
917 plist = get_next(phead);
918
919 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
920 psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);
921
922 plist = get_next(plist);
923
924 if (pbcmc_stainfo != psta) {
925 if (rtw_is_pre_link_sta(pstapriv, psta->cmn.mac_addr) == _FALSE)
926 rtw_list_delete(&psta->hash_list);
927
928 stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
929 if (stainfo_offset_valid(stainfo_offset))
930 free_sta_list[free_sta_num++] = stainfo_offset;
931 }
932
933 }
934 }
935
936 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
937
938
939 for (index = 0; index < free_sta_num; index++) {
940 psta = rtw_get_stainfo_by_offset(pstapriv, free_sta_list[index]);
941 rtw_free_stainfo(padapter , psta);
942 }
943
944 exit:
945 return;
946 }
947
948 /* any station allocated can be searched by hash list */
rtw_get_stainfo(struct sta_priv * pstapriv,const u8 * hwaddr)949 struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr)
950 {
951
952 _irqL irqL;
953
954 _list *plist, *phead;
955
956 struct sta_info *psta = NULL;
957
958 u32 index;
959
960 const u8 *addr;
961
962 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
963
964
965 if (hwaddr == NULL)
966 return NULL;
967
968 if (IS_MCAST(hwaddr))
969 addr = bc_addr;
970 else
971 addr = hwaddr;
972
973 index = wifi_mac_hash(addr);
974
975 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
976
977 phead = &(pstapriv->sta_hash[index]);
978 plist = get_next(phead);
979
980
981 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
982
983 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
984
985 if ((_rtw_memcmp(psta->cmn.mac_addr, addr, ETH_ALEN)) == _TRUE) {
986 /* if found the matched address */
987 break;
988 }
989 psta = NULL;
990 plist = get_next(plist);
991 }
992
993 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
994 return psta;
995
996 }
997
rtw_init_bcmc_stainfo(_adapter * padapter)998 u32 rtw_init_bcmc_stainfo(_adapter *padapter)
999 {
1000
1001 struct sta_info *psta;
1002 struct tx_servq *ptxservq;
1003 u32 res = _SUCCESS;
1004 NDIS_802_11_MAC_ADDRESS bcast_addr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1005
1006 struct sta_priv *pstapriv = &padapter->stapriv;
1007
1008
1009 psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
1010
1011 if (psta == NULL) {
1012 res = _FAIL;
1013 goto exit;
1014 }
1015 #ifdef CONFIG_BEAMFORMING
1016 psta->cmn.bf_info.g_id = 63;
1017 psta->cmn.bf_info.p_aid = 0;
1018 #endif
1019
1020 ptxservq = &(psta->sta_xmitpriv.be_q);
1021
1022 /*
1023 _enter_critical(&pstapending->lock, &irqL0);
1024
1025 if (rtw_is_list_empty(&ptxservq->tx_pending))
1026 rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(pstapending));
1027
1028 _exit_critical(&pstapending->lock, &irqL0);
1029 */
1030
1031 exit:
1032 return _SUCCESS;
1033
1034 }
1035
1036
rtw_get_bcmc_stainfo(_adapter * padapter)1037 struct sta_info *rtw_get_bcmc_stainfo(_adapter *padapter)
1038 {
1039 struct sta_info *psta;
1040 struct sta_priv *pstapriv = &padapter->stapriv;
1041 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1042 psta = rtw_get_stainfo(pstapriv, bc_addr);
1043 return psta;
1044
1045 }
1046
1047 #ifdef CONFIG_AP_MODE
rtw_aid_alloc(_adapter * adapter,struct sta_info * sta)1048 u16 rtw_aid_alloc(_adapter *adapter, struct sta_info *sta)
1049 {
1050 struct sta_priv *stapriv = &adapter->stapriv;
1051 u16 aid, i, used_cnt = 0;
1052
1053 for (i = 0; i < stapriv->max_aid; i++) {
1054 aid = ((i + stapriv->started_aid - 1) % stapriv->max_aid) + 1;
1055 if (stapriv->sta_aid[aid - 1] == NULL)
1056 break;
1057 if (++used_cnt >= stapriv->max_num_sta)
1058 break;
1059 }
1060
1061 /* check for aid limit and assoc limit */
1062 if (i >= stapriv->max_aid || used_cnt >= stapriv->max_num_sta)
1063 aid = 0;
1064
1065 sta->cmn.aid = aid;
1066 if (aid) {
1067 stapriv->sta_aid[aid - 1] = sta;
1068 if (stapriv->rr_aid)
1069 stapriv->started_aid = (aid % stapriv->max_aid) + 1;
1070 }
1071
1072 return aid;
1073 }
1074
dump_aid_status(void * sel,_adapter * adapter)1075 void dump_aid_status(void *sel, _adapter *adapter)
1076 {
1077 struct sta_priv *stapriv = &adapter->stapriv;
1078 u8 *aid_bmp;
1079 u16 i, used_cnt = 0;
1080
1081 aid_bmp = rtw_zmalloc(stapriv->aid_bmp_len);
1082 if (!aid_bmp)
1083 return;
1084
1085 for (i = 1; i <= stapriv->max_aid; i++) {
1086 if (stapriv->sta_aid[i - 1]) {
1087 aid_bmp[i / 8] |= BIT(i % 8);
1088 ++used_cnt;
1089 }
1090 }
1091
1092 RTW_PRINT_SEL(sel, "used_cnt:%u/%u\n", used_cnt, stapriv->max_aid);
1093 RTW_MAP_DUMP_SEL(sel, "aid_map:", aid_bmp, stapriv->aid_bmp_len);
1094 RTW_PRINT_SEL(sel, "\n");
1095
1096 RTW_PRINT_SEL(sel, "%-2s %-11s\n", "rr", "started_aid");
1097 RTW_PRINT_SEL(sel, "%2d %11d\n", stapriv->rr_aid, stapriv->started_aid);
1098
1099 rtw_mfree(aid_bmp, stapriv->aid_bmp_len);
1100 }
1101 #endif /* CONFIG_AP_MODE */
1102
1103 #if CONFIG_RTW_MACADDR_ACL
1104 const char *const _acl_period_str[RTW_ACL_PERIOD_NUM] = {
1105 "DEV",
1106 "BSS",
1107 };
1108
1109 const char *const _acl_mode_str[RTW_ACL_MODE_MAX] = {
1110 "DISABLED",
1111 "ACCEPT_UNLESS_LISTED",
1112 "DENY_UNLESS_LISTED",
1113 };
1114
_rtw_access_ctrl(_adapter * adapter,u8 period,const u8 * mac_addr)1115 u8 _rtw_access_ctrl(_adapter *adapter, u8 period, const u8 *mac_addr)
1116 {
1117 u8 res = _TRUE;
1118 _irqL irqL;
1119 _list *list, *head;
1120 struct rtw_wlan_acl_node *acl_node;
1121 u8 match = _FALSE;
1122 struct sta_priv *stapriv = &adapter->stapriv;
1123 struct wlan_acl_pool *acl;
1124 _queue *acl_node_q;
1125
1126 if (period >= RTW_ACL_PERIOD_NUM) {
1127 rtw_warn_on(1);
1128 goto exit;
1129 }
1130
1131 acl = &stapriv->acl_list[period];
1132 acl_node_q = &acl->acl_node_q;
1133
1134 if (acl->mode != RTW_ACL_MODE_ACCEPT_UNLESS_LISTED
1135 && acl->mode != RTW_ACL_MODE_DENY_UNLESS_LISTED)
1136 goto exit;
1137
1138 _enter_critical_bh(&(acl_node_q->lock), &irqL);
1139 head = get_list_head(acl_node_q);
1140 list = get_next(head);
1141 while (rtw_end_of_queue_search(head, list) == _FALSE) {
1142 acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
1143 list = get_next(list);
1144
1145 if (_rtw_memcmp(acl_node->addr, mac_addr, ETH_ALEN)) {
1146 if (acl_node->valid == _TRUE) {
1147 match = _TRUE;
1148 break;
1149 }
1150 }
1151 }
1152 _exit_critical_bh(&(acl_node_q->lock), &irqL);
1153
1154 if (acl->mode == RTW_ACL_MODE_ACCEPT_UNLESS_LISTED)
1155 res = (match == _TRUE) ? _FALSE : _TRUE;
1156 else /* RTW_ACL_MODE_DENY_UNLESS_LISTED */
1157 res = (match == _TRUE) ? _TRUE : _FALSE;
1158
1159 exit:
1160 return res;
1161 }
1162
rtw_access_ctrl(_adapter * adapter,const u8 * mac_addr)1163 u8 rtw_access_ctrl(_adapter *adapter, const u8 *mac_addr)
1164 {
1165 int i;
1166
1167 for (i = 0; i < RTW_ACL_PERIOD_NUM; i++)
1168 if (_rtw_access_ctrl(adapter, i, mac_addr) == _FALSE)
1169 return _FALSE;
1170
1171 return _TRUE;
1172 }
1173
dump_macaddr_acl(void * sel,_adapter * adapter)1174 void dump_macaddr_acl(void *sel, _adapter *adapter)
1175 {
1176 struct sta_priv *stapriv = &adapter->stapriv;
1177 struct wlan_acl_pool *acl;
1178 int i, j;
1179
1180 for (j = 0; j < RTW_ACL_PERIOD_NUM; j++) {
1181 RTW_PRINT_SEL(sel, "period:%s(%d)\n", acl_period_str(j), j);
1182
1183 acl = &stapriv->acl_list[j];
1184 RTW_PRINT_SEL(sel, "mode:%s(%d)\n", acl_mode_str(acl->mode), acl->mode);
1185 RTW_PRINT_SEL(sel, "num:%d/%d\n", acl->num, NUM_ACL);
1186 for (i = 0; i < NUM_ACL; i++) {
1187 if (acl->aclnode[i].valid == _FALSE)
1188 continue;
1189 RTW_PRINT_SEL(sel, MAC_FMT"\n", MAC_ARG(acl->aclnode[i].addr));
1190 }
1191 RTW_PRINT_SEL(sel, "\n");
1192 }
1193 }
1194 #endif /* CONFIG_RTW_MACADDR_ACL */
1195
rtw_is_pre_link_sta(struct sta_priv * stapriv,u8 * addr)1196 bool rtw_is_pre_link_sta(struct sta_priv *stapriv, u8 *addr)
1197 {
1198 #if CONFIG_RTW_PRE_LINK_STA
1199 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1200 struct sta_info *sta = NULL;
1201 u8 exist = _FALSE;
1202 int i;
1203 _irqL irqL;
1204
1205 _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1206 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1207 if (pre_link_sta_ctl->node[i].valid == _TRUE
1208 && _rtw_memcmp(pre_link_sta_ctl->node[i].addr, addr, ETH_ALEN) == _TRUE
1209 ) {
1210 exist = _TRUE;
1211 break;
1212 }
1213 }
1214 _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1215
1216 return exist;
1217 #else
1218 return _FALSE;
1219 #endif
1220 }
1221
1222 #if CONFIG_RTW_PRE_LINK_STA
rtw_pre_link_sta_add(struct sta_priv * stapriv,u8 * hwaddr)1223 struct sta_info *rtw_pre_link_sta_add(struct sta_priv *stapriv, u8 *hwaddr)
1224 {
1225 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1226 struct pre_link_sta_node_t *node = NULL;
1227 struct sta_info *sta = NULL;
1228 u8 exist = _FALSE;
1229 int i;
1230 _irqL irqL;
1231
1232 if (rtw_check_invalid_mac_address(hwaddr, _FALSE) == _TRUE)
1233 goto exit;
1234
1235 _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1236 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1237 if (pre_link_sta_ctl->node[i].valid == _TRUE
1238 && _rtw_memcmp(pre_link_sta_ctl->node[i].addr, hwaddr, ETH_ALEN) == _TRUE
1239 ) {
1240 node = &pre_link_sta_ctl->node[i];
1241 exist = _TRUE;
1242 break;
1243 }
1244
1245 if (node == NULL && pre_link_sta_ctl->node[i].valid == _FALSE)
1246 node = &pre_link_sta_ctl->node[i];
1247 }
1248
1249 if (exist == _FALSE && node) {
1250 _rtw_memcpy(node->addr, hwaddr, ETH_ALEN);
1251 node->valid = _TRUE;
1252 pre_link_sta_ctl->num++;
1253 }
1254 _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1255
1256 if (node == NULL)
1257 goto exit;
1258
1259 sta = rtw_get_stainfo(stapriv, hwaddr);
1260 if (sta)
1261 goto odm_hook;
1262
1263 sta = rtw_alloc_stainfo(stapriv, hwaddr);
1264 if (!sta)
1265 goto exit;
1266
1267 sta->state = WIFI_FW_PRE_LINK;
1268
1269 odm_hook:
1270 rtw_hal_set_odm_var(stapriv->padapter, HAL_ODM_STA_INFO, sta, _TRUE);
1271
1272 exit:
1273 return sta;
1274 }
1275
rtw_pre_link_sta_del(struct sta_priv * stapriv,u8 * hwaddr)1276 void rtw_pre_link_sta_del(struct sta_priv *stapriv, u8 *hwaddr)
1277 {
1278 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1279 struct pre_link_sta_node_t *node = NULL;
1280 struct sta_info *sta = NULL;
1281 u8 exist = _FALSE;
1282 int i;
1283 _irqL irqL;
1284
1285 if (rtw_check_invalid_mac_address(hwaddr, _FALSE) == _TRUE)
1286 goto exit;
1287
1288 _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1289 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1290 if (pre_link_sta_ctl->node[i].valid == _TRUE
1291 && _rtw_memcmp(pre_link_sta_ctl->node[i].addr, hwaddr, ETH_ALEN) == _TRUE
1292 ) {
1293 node = &pre_link_sta_ctl->node[i];
1294 exist = _TRUE;
1295 break;
1296 }
1297 }
1298
1299 if (exist == _TRUE && node) {
1300 node->valid = _FALSE;
1301 pre_link_sta_ctl->num--;
1302 }
1303 _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1304
1305 if (exist == _FALSE)
1306 goto exit;
1307
1308 sta = rtw_get_stainfo(stapriv, hwaddr);
1309 if (!sta)
1310 goto exit;
1311
1312 if (sta->state == WIFI_FW_PRE_LINK)
1313 rtw_free_stainfo(stapriv->padapter, sta);
1314
1315 exit:
1316 return;
1317 }
1318
rtw_pre_link_sta_ctl_reset(struct sta_priv * stapriv)1319 void rtw_pre_link_sta_ctl_reset(struct sta_priv *stapriv)
1320 {
1321 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1322 struct pre_link_sta_node_t *node = NULL;
1323 struct sta_info *sta = NULL;
1324 int i, j = 0;
1325 _irqL irqL;
1326
1327 u8 addrs[RTW_PRE_LINK_STA_NUM][ETH_ALEN];
1328
1329 _rtw_memset(addrs, 0, RTW_PRE_LINK_STA_NUM * ETH_ALEN);
1330
1331 _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1332 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1333 if (pre_link_sta_ctl->node[i].valid == _FALSE)
1334 continue;
1335 _rtw_memcpy(&(addrs[j][0]), pre_link_sta_ctl->node[i].addr, ETH_ALEN);
1336 pre_link_sta_ctl->node[i].valid = _FALSE;
1337 pre_link_sta_ctl->num--;
1338 j++;
1339 }
1340 _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
1341
1342 for (i = 0; i < j; i++) {
1343 sta = rtw_get_stainfo(stapriv, &(addrs[i][0]));
1344 if (!sta)
1345 continue;
1346
1347 if (sta->state == WIFI_FW_PRE_LINK)
1348 rtw_free_stainfo(stapriv->padapter, sta);
1349 }
1350 }
1351
rtw_pre_link_sta_ctl_init(struct sta_priv * stapriv)1352 void rtw_pre_link_sta_ctl_init(struct sta_priv *stapriv)
1353 {
1354 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1355 int i;
1356
1357 _rtw_spinlock_init(&pre_link_sta_ctl->lock);
1358 pre_link_sta_ctl->num = 0;
1359 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++)
1360 pre_link_sta_ctl->node[i].valid = _FALSE;
1361 }
1362
rtw_pre_link_sta_ctl_deinit(struct sta_priv * stapriv)1363 void rtw_pre_link_sta_ctl_deinit(struct sta_priv *stapriv)
1364 {
1365 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1366 int i;
1367
1368 rtw_pre_link_sta_ctl_reset(stapriv);
1369
1370 _rtw_spinlock_free(&pre_link_sta_ctl->lock);
1371 }
1372
dump_pre_link_sta_ctl(void * sel,struct sta_priv * stapriv)1373 void dump_pre_link_sta_ctl(void *sel, struct sta_priv *stapriv)
1374 {
1375 struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
1376 int i;
1377
1378 RTW_PRINT_SEL(sel, "num:%d/%d\n", pre_link_sta_ctl->num, RTW_PRE_LINK_STA_NUM);
1379
1380 for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
1381 if (pre_link_sta_ctl->node[i].valid == _FALSE)
1382 continue;
1383 RTW_PRINT_SEL(sel, MAC_FMT"\n", MAC_ARG(pre_link_sta_ctl->node[i].addr));
1384 }
1385 }
1386 #endif /* CONFIG_RTW_PRE_LINK_STA */
1387
1388