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