-
Notifications
You must be signed in to change notification settings - Fork 962
/
rtw_recv.c
executable file
·4984 lines (4030 loc) · 136 KB
/
rtw_recv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
*
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#define _RTW_RECV_C_
#include <drv_types.h>
#include <hal_data.h>
#if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
#error "Shall be Linux or Windows, but not both!\n"
#endif
#ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
void rtw_signal_stat_timer_hdl(RTW_TIMER_HDL_ARGS);
enum {
SIGNAL_STAT_CALC_PROFILE_0 = 0,
SIGNAL_STAT_CALC_PROFILE_1,
SIGNAL_STAT_CALC_PROFILE_MAX
};
u8 signal_stat_calc_profile[SIGNAL_STAT_CALC_PROFILE_MAX][2] = {
{4, 1}, /* Profile 0 => pre_stat : curr_stat = 4 : 1 */
{3, 7} /* Profile 1 => pre_stat : curr_stat = 3 : 7 */
};
#ifndef RTW_SIGNAL_STATE_CALC_PROFILE
#define RTW_SIGNAL_STATE_CALC_PROFILE SIGNAL_STAT_CALC_PROFILE_1
#endif
#endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
{
_func_enter_;
_rtw_memset((u8 *)psta_recvpriv, 0, sizeof (struct sta_recv_priv));
_rtw_spinlock_init(&psta_recvpriv->lock);
//for(i=0; i<MAX_RX_NUMBLKS; i++)
// _rtw_init_queue(&psta_recvpriv->blk_strms[i]);
_rtw_init_queue(&psta_recvpriv->defrag_q);
_func_exit_;
}
sint _rtw_init_recv_priv(struct recv_priv *precvpriv, _adapter *padapter)
{
sint i;
union recv_frame *precvframe;
sint res=_SUCCESS;
_func_enter_;
// We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc().
//_rtw_memset((unsigned char *)precvpriv, 0, sizeof (struct recv_priv));
_rtw_spinlock_init(&precvpriv->lock);
_rtw_init_queue(&precvpriv->free_recv_queue);
_rtw_init_queue(&precvpriv->recv_pending_queue);
_rtw_init_queue(&precvpriv->uc_swdec_pending_queue);
precvpriv->adapter = padapter;
precvpriv->free_recvframe_cnt = NR_RECVFRAME;
precvpriv->sink_udpport = 0;
precvpriv->pre_rtp_rxseq = 0;
precvpriv->cur_rtp_rxseq = 0;
rtw_os_recv_resource_init(precvpriv, padapter);
precvpriv->pallocated_frame_buf = rtw_zvmalloc(NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
if(precvpriv->pallocated_frame_buf==NULL){
res= _FAIL;
goto exit;
}
//_rtw_memset(precvpriv->pallocated_frame_buf, 0, NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
//precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf + RXFRAME_ALIGN_SZ -
// ((SIZE_PTR) (precvpriv->pallocated_frame_buf) &(RXFRAME_ALIGN_SZ-1));
precvframe = (union recv_frame*) precvpriv->precv_frame_buf;
for(i=0; i < NR_RECVFRAME ; i++)
{
_rtw_init_listhead(&(precvframe->u.list));
rtw_list_insert_tail(&(precvframe->u.list), &(precvpriv->free_recv_queue.queue));
res = rtw_os_recv_resource_alloc(padapter, precvframe);
precvframe->u.hdr.len = 0;
precvframe->u.hdr.adapter =padapter;
precvframe++;
}
#ifdef CONFIG_USB_HCI
ATOMIC_SET(&(precvpriv->rx_pending_cnt), 1);
_rtw_init_sema(&precvpriv->allrxreturnevt, 0);
#endif
res = rtw_hal_init_recv_priv(padapter);
#ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
rtw_init_timer(&precvpriv->signal_stat_timer, padapter, RTW_TIMER_HDL_NAME(signal_stat));
precvpriv->signal_stat_sampling_interval = 2000; //ms
//precvpriv->signal_stat_converging_constant = 5000; //ms
rtw_set_signal_stat_timer(precvpriv);
#endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
exit:
_func_exit_;
return res;
}
void rtw_mfree_recv_priv_lock(struct recv_priv *precvpriv);
void rtw_mfree_recv_priv_lock(struct recv_priv *precvpriv)
{
_rtw_spinlock_free(&precvpriv->lock);
#ifdef CONFIG_RECV_THREAD_MODE
_rtw_free_sema(&precvpriv->recv_sema);
_rtw_free_sema(&precvpriv->terminate_recvthread_sema);
#endif
_rtw_spinlock_free(&precvpriv->free_recv_queue.lock);
_rtw_spinlock_free(&precvpriv->recv_pending_queue.lock);
_rtw_spinlock_free(&precvpriv->free_recv_buf_queue.lock);
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
_rtw_spinlock_free(&precvpriv->recv_buf_pending_queue.lock);
#endif // CONFIG_USE_USB_BUFFER_ALLOC_RX
}
void _rtw_free_recv_priv (struct recv_priv *precvpriv)
{
_adapter *padapter = precvpriv->adapter;
_func_enter_;
rtw_free_uc_swdec_pending_queue(padapter);
rtw_mfree_recv_priv_lock(precvpriv);
rtw_os_recv_resource_free(precvpriv);
if(precvpriv->pallocated_frame_buf) {
rtw_vmfree(precvpriv->pallocated_frame_buf, NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
}
rtw_hal_free_recv_priv(padapter);
_func_exit_;
}
union recv_frame *_rtw_alloc_recvframe (_queue *pfree_recv_queue)
{
union recv_frame *precvframe;
_list *plist, *phead;
_adapter *padapter;
struct recv_priv *precvpriv;
_func_enter_;
if(_rtw_queue_empty(pfree_recv_queue) == _TRUE)
{
precvframe = NULL;
}
else
{
phead = get_list_head(pfree_recv_queue);
plist = get_next(phead);
precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
rtw_list_delete(&precvframe->u.hdr.list);
padapter=precvframe->u.hdr.adapter;
if(padapter !=NULL){
precvpriv=&padapter->recvpriv;
if(pfree_recv_queue == &precvpriv->free_recv_queue)
precvpriv->free_recvframe_cnt--;
}
}
_func_exit_;
return precvframe;
}
union recv_frame *rtw_alloc_recvframe (_queue *pfree_recv_queue)
{
_irqL irqL;
union recv_frame *precvframe;
_enter_critical_bh(&pfree_recv_queue->lock, &irqL);
precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
_exit_critical_bh(&pfree_recv_queue->lock, &irqL);
return precvframe;
}
void rtw_init_recvframe(union recv_frame *precvframe, struct recv_priv *precvpriv)
{
/* Perry: This can be removed */
_rtw_init_listhead(&precvframe->u.hdr.list);
precvframe->u.hdr.len=0;
}
int rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue)
{
_irqL irqL;
_adapter *padapter=precvframe->u.hdr.adapter;
struct recv_priv *precvpriv = &padapter->recvpriv;
_func_enter_;
#ifdef CONFIG_CONCURRENT_MODE
if(padapter->adapter_type > PRIMARY_ADAPTER)
{
padapter = padapter->pbuddy_adapter;//get primary_padapter
precvpriv = &padapter->recvpriv;
pfree_recv_queue = &precvpriv->free_recv_queue;
precvframe->u.hdr.adapter = padapter;
}
#endif
rtw_os_free_recvframe(precvframe);
_enter_critical_bh(&pfree_recv_queue->lock, &irqL);
rtw_list_delete(&(precvframe->u.hdr.list));
precvframe->u.hdr.len = 0;
rtw_list_insert_tail(&(precvframe->u.hdr.list), get_list_head(pfree_recv_queue));
if(padapter !=NULL){
if(pfree_recv_queue == &precvpriv->free_recv_queue)
precvpriv->free_recvframe_cnt++;
}
_exit_critical_bh(&pfree_recv_queue->lock, &irqL);
_func_exit_;
return _SUCCESS;
}
sint _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue)
{
_adapter *padapter=precvframe->u.hdr.adapter;
struct recv_priv *precvpriv = &padapter->recvpriv;
_func_enter_;
//_rtw_init_listhead(&(precvframe->u.hdr.list));
rtw_list_delete(&(precvframe->u.hdr.list));
rtw_list_insert_tail(&(precvframe->u.hdr.list), get_list_head(queue));
if (padapter != NULL) {
if (queue == &precvpriv->free_recv_queue)
precvpriv->free_recvframe_cnt++;
}
_func_exit_;
return _SUCCESS;
}
sint rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue)
{
sint ret;
_irqL irqL;
//_spinlock(&pfree_recv_queue->lock);
_enter_critical_bh(&queue->lock, &irqL);
ret = _rtw_enqueue_recvframe(precvframe, queue);
//_rtw_spinunlock(&pfree_recv_queue->lock);
_exit_critical_bh(&queue->lock, &irqL);
return ret;
}
/*
sint rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue)
{
return rtw_free_recvframe(precvframe, queue);
}
*/
/*
caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
pframequeue: defrag_queue : will be accessed in recv_thread (passive)
using spinlock to protect
*/
void rtw_free_recvframe_queue(_queue *pframequeue, _queue *pfree_recv_queue)
{
union recv_frame *precvframe;
_list *plist, *phead;
_func_enter_;
_rtw_spinlock(&pframequeue->lock);
phead = get_list_head(pframequeue);
plist = get_next(phead);
while(rtw_end_of_queue_search(phead, plist) == _FALSE)
{
precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
plist = get_next(plist);
//rtw_list_delete(&precvframe->u.hdr.list); // will do this in rtw_free_recvframe()
rtw_free_recvframe(precvframe, pfree_recv_queue);
}
_rtw_spinunlock(&pframequeue->lock);
_func_exit_;
}
u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter)
{
u32 cnt = 0;
union recv_frame *pending_frame;
while((pending_frame=rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
cnt++;
}
if (cnt)
DBG_871X(FUNC_ADPT_FMT" dequeue %d\n", FUNC_ADPT_ARG(adapter), cnt);
return cnt;
}
sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue)
{
_irqL irqL;
_enter_critical_bh(&queue->lock, &irqL);
rtw_list_delete(&precvbuf->list);
rtw_list_insert_head(&precvbuf->list, get_list_head(queue));
_exit_critical_bh(&queue->lock, &irqL);
return _SUCCESS;
}
sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue)
{
_irqL irqL;
#ifdef CONFIG_SDIO_HCI
_enter_critical_bh(&queue->lock, &irqL);
#else
_enter_critical_ex(&queue->lock, &irqL);
#endif/*#ifdef CONFIG_SDIO_HCI*/
rtw_list_delete(&precvbuf->list);
rtw_list_insert_tail(&precvbuf->list, get_list_head(queue));
#ifdef CONFIG_SDIO_HCI
_exit_critical_bh(&queue->lock, &irqL);
#else
_exit_critical_ex(&queue->lock, &irqL);
#endif/*#ifdef CONFIG_SDIO_HCI*/
return _SUCCESS;
}
struct recv_buf *rtw_dequeue_recvbuf (_queue *queue)
{
_irqL irqL;
struct recv_buf *precvbuf;
_list *plist, *phead;
#ifdef CONFIG_SDIO_HCI
_enter_critical_bh(&queue->lock, &irqL);
#else
_enter_critical_ex(&queue->lock, &irqL);
#endif/*#ifdef CONFIG_SDIO_HCI*/
if(_rtw_queue_empty(queue) == _TRUE)
{
precvbuf = NULL;
}
else
{
phead = get_list_head(queue);
plist = get_next(phead);
precvbuf = LIST_CONTAINOR(plist, struct recv_buf, list);
rtw_list_delete(&precvbuf->list);
}
#ifdef CONFIG_SDIO_HCI
_exit_critical_bh(&queue->lock, &irqL);
#else
_exit_critical_ex(&queue->lock, &irqL);
#endif/*#ifdef CONFIG_SDIO_HCI*/
return precvbuf;
}
sint recvframe_chkmic(_adapter *adapter, union recv_frame *precvframe);
sint recvframe_chkmic(_adapter *adapter, union recv_frame *precvframe){
sint i,res=_SUCCESS;
u32 datalen;
u8 miccode[8];
u8 bmic_err=_FALSE,brpt_micerror = _TRUE;
u8 *pframe, *payload,*pframemic;
u8 *mickey;
//u8 *iv,rxdata_key_idx=0;
struct sta_info *stainfo;
struct rx_pkt_attrib *prxattrib=&precvframe->u.hdr.attrib;
struct security_priv *psecuritypriv=&adapter->securitypriv;
struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
_func_enter_;
stainfo=rtw_get_stainfo(&adapter->stapriv ,&prxattrib->ta[0]);
if(prxattrib->encrypt ==_TKIP_)
{
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n recvframe_chkmic:prxattrib->encrypt ==_TKIP_\n"));
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n recvframe_chkmic:da=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
prxattrib->ra[0],prxattrib->ra[1],prxattrib->ra[2],prxattrib->ra[3],prxattrib->ra[4],prxattrib->ra[5]));
//calculate mic code
if(stainfo!= NULL)
{
if(IS_MCAST(prxattrib->ra))
{
//mickey=&psecuritypriv->dot118021XGrprxmickey.skey[0];
//iv = precvframe->u.hdr.rx_data+prxattrib->hdrlen;
//rxdata_key_idx =( ((iv[3])>>6)&0x3) ;
mickey=&psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n recvframe_chkmic: bcmc key \n"));
//DBG_871X("\n recvframe_chkmic: bcmc key psecuritypriv->dot118021XGrpKeyid(%d),pmlmeinfo->key_index(%d) ,recv key_id(%d)\n",
// psecuritypriv->dot118021XGrpKeyid,pmlmeinfo->key_index,rxdata_key_idx);
if(psecuritypriv->binstallGrpkey==_FALSE)
{
res=_FAIL;
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n"));
DBG_871X("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
goto exit;
}
}
else{
mickey=&stainfo->dot11tkiprxmickey.skey[0];
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n recvframe_chkmic: unicast key \n"));
}
datalen=precvframe->u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len-prxattrib->icv_len-8;//icv_len included the mic code
pframe=precvframe->u.hdr.rx_data;
payload=pframe+prxattrib->hdrlen+prxattrib->iv_len;
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n",prxattrib->iv_len,prxattrib->icv_len));
//rtw_seccalctkipmic(&stainfo->dot11tkiprxmickey.skey[0],pframe,payload, datalen ,&miccode[0],(unsigned char)prxattrib->priority); //care the length of the data
rtw_seccalctkipmic(mickey,pframe,payload, datalen ,&miccode[0],(unsigned char)prxattrib->priority); //care the length of the data
pframemic=payload+datalen;
bmic_err=_FALSE;
for(i=0;i<8;i++){
if(miccode[i] != *(pframemic+i)){
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvframe_chkmic:miccode[%d](%02x) != *(pframemic+%d)(%02x) ",i,miccode[i],i,*(pframemic+i)));
bmic_err=_TRUE;
}
}
if(bmic_err==_TRUE){
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n *(pframemic-8)-*(pframemic-1)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
*(pframemic-8),*(pframemic-7),*(pframemic-6),*(pframemic-5),*(pframemic-4),*(pframemic-3),*(pframemic-2),*(pframemic-1)));
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n *(pframemic-16)-*(pframemic-9)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
*(pframemic-16),*(pframemic-15),*(pframemic-14),*(pframemic-13),*(pframemic-12),*(pframemic-11),*(pframemic-10),*(pframemic-9)));
{
uint i;
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n ======demp packet (len=%d)======\n",precvframe->u.hdr.len));
for(i=0;i<precvframe->u.hdr.len;i=i+8){
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
*(precvframe->u.hdr.rx_data+i),*(precvframe->u.hdr.rx_data+i+1),
*(precvframe->u.hdr.rx_data+i+2),*(precvframe->u.hdr.rx_data+i+3),
*(precvframe->u.hdr.rx_data+i+4),*(precvframe->u.hdr.rx_data+i+5),
*(precvframe->u.hdr.rx_data+i+6),*(precvframe->u.hdr.rx_data+i+7)));
}
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n ======demp packet end [len=%d]======\n",precvframe->u.hdr.len));
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("\n hrdlen=%d, \n",prxattrib->hdrlen));
}
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("ra=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x psecuritypriv->binstallGrpkey=%d ",
prxattrib->ra[0],prxattrib->ra[1],prxattrib->ra[2],
prxattrib->ra[3],prxattrib->ra[4],prxattrib->ra[5],psecuritypriv->binstallGrpkey));
// double check key_index for some timing issue ,
// cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue
if((IS_MCAST(prxattrib->ra)==_TRUE) && (prxattrib->key_index != pmlmeinfo->key_index ))
brpt_micerror = _FALSE;
if((prxattrib->bdecrypted ==_TRUE)&& (brpt_micerror == _TRUE))
{
rtw_handle_tkip_mic_err(adapter, stainfo, (u8)IS_MCAST(prxattrib->ra));
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" mic error :prxattrib->bdecrypted=%d ",prxattrib->bdecrypted));
DBG_871X(" mic error :prxattrib->bdecrypted=%d\n",prxattrib->bdecrypted);
}
else
{
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" mic error :prxattrib->bdecrypted=%d ",prxattrib->bdecrypted));
DBG_871X(" mic error :prxattrib->bdecrypted=%d\n",prxattrib->bdecrypted);
}
res=_FAIL;
}
else{
//mic checked ok
if((psecuritypriv->bcheck_grpkey ==_FALSE)&&(IS_MCAST(prxattrib->ra)==_TRUE)){
psecuritypriv->bcheck_grpkey =_TRUE;
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("psecuritypriv->bcheck_grpkey =_TRUE"));
}
}
}
else
{
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
}
recvframe_pull_tail(precvframe, 8);
}
exit:
_func_exit_;
return res;
}
//decrypt and set the ivlen,icvlen of the recv_frame
union recv_frame * decryptor(_adapter *padapter,union recv_frame *precv_frame);
union recv_frame * decryptor(_adapter *padapter,union recv_frame *precv_frame)
{
struct rx_pkt_attrib *prxattrib = &precv_frame->u.hdr.attrib;
struct security_priv *psecuritypriv=&padapter->securitypriv;
union recv_frame *return_packet=precv_frame;
u32 res=_SUCCESS;
_func_enter_;
DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt);
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("prxstat->decrypted=%x prxattrib->encrypt = 0x%03x\n",prxattrib->bdecrypted,prxattrib->encrypt));
if(prxattrib->encrypt>0)
{
u8 *iv = precv_frame->u.hdr.rx_data+prxattrib->hdrlen;
prxattrib->key_index = ( ((iv[3])>>6)&0x3) ;
if(prxattrib->key_index > WEP_KEYS)
{
DBG_871X("prxattrib->key_index(%d) > WEP_KEYS \n", prxattrib->key_index);
switch(prxattrib->encrypt){
case _WEP40_:
case _WEP104_:
prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
break;
case _TKIP_:
case _AES_:
default:
prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
break;
}
}
}
if((prxattrib->encrypt>0) && ((prxattrib->bdecrypted==0) ||(psecuritypriv->sw_decrypt==_TRUE)))
{
#ifdef CONFIG_CONCURRENT_MODE
if(!IS_MCAST(prxattrib->ra))//bc/mc packets use sw decryption for concurrent mode
#endif
psecuritypriv->hw_decrypted=_FALSE;
#ifdef DBG_RX_DECRYPTOR
DBG_871X("[%s] %d:prxstat->bdecrypted:%d, prxattrib->encrypt:%d, Setting psecuritypriv->hw_decrypted = %d\n",
__FUNCTION__,
__LINE__,
prxattrib->bdecrypted,
prxattrib->encrypt,
psecuritypriv->hw_decrypted);
#endif
switch(prxattrib->encrypt){
case _WEP40_:
case _WEP104_:
DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_wep);
rtw_wep_decrypt(padapter, (u8 *)precv_frame);
break;
case _TKIP_:
DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_tkip);
res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
break;
case _AES_:
DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_aes);
res = rtw_aes_decrypt(padapter, (u8 * )precv_frame);
break;
#ifdef CONFIG_WAPI_SUPPORT
case _SMS4_:
DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_wapi);
rtw_sms4_decrypt(padapter, (u8 * )precv_frame);
break;
#endif
default:
break;
}
}
else if(prxattrib->bdecrypted==1
&& prxattrib->encrypt >0
&& (psecuritypriv->busetkipkey==1 || prxattrib->encrypt !=_TKIP_ )
)
{
#if 0
if((prxstat->icv==1)&&(prxattrib->encrypt!=_AES_))
{
psecuritypriv->hw_decrypted=_FALSE;
RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,("psecuritypriv->hw_decrypted=_FALSE"));
rtw_free_recvframe(precv_frame, &padapter->recvpriv.free_recv_queue);
return_packet=NULL;
}
else
#endif
{
DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_hw);
psecuritypriv->hw_decrypted=_TRUE;
#ifdef DBG_RX_DECRYPTOR
DBG_871X("[%s] %d:prxstat->bdecrypted:%d, prxattrib->encrypt:%d, Setting psecuritypriv->hw_decrypted = %d\n",
__FUNCTION__,
__LINE__,
prxattrib->bdecrypted,
prxattrib->encrypt,
psecuritypriv->hw_decrypted);
#endif
}
}
else {
DBG_COUNTER(padapter->rx_logs.core_rx_post_decrypt_unknown);
#ifdef DBG_RX_DECRYPTOR
DBG_871X("[%s] %d:prxstat->bdecrypted:%d, prxattrib->encrypt:%d, Setting psecuritypriv->hw_decrypted = %d\n",
__FUNCTION__,
__LINE__,
prxattrib->bdecrypted,
prxattrib->encrypt,
psecuritypriv->hw_decrypted);
#endif
}
if(res == _FAIL)
{
rtw_free_recvframe(return_packet,&padapter->recvpriv.free_recv_queue);
return_packet = NULL;
}
else
{
prxattrib->bdecrypted = _TRUE;
}
//recvframe_chkmic(adapter, precv_frame); //move to recvframme_defrag function
_func_exit_;
return return_packet;
}
//###set the security information in the recv_frame
union recv_frame * portctrl(_adapter *adapter,union recv_frame * precv_frame);
union recv_frame * portctrl(_adapter *adapter,union recv_frame * precv_frame)
{
u8 *psta_addr = NULL;
u8 *ptr;
uint auth_alg;
struct recv_frame_hdr *pfhdr;
struct sta_info *psta;
struct sta_priv *pstapriv ;
union recv_frame *prtnframe;
u16 ether_type=0;
u16 eapol_type = 0x888e;//for Funia BD's WPA issue
struct rx_pkt_attrib *pattrib;
_func_enter_;
pstapriv = &adapter->stapriv;
auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
ptr = get_recvframe_data(precv_frame);
pfhdr = &precv_frame->u.hdr;
pattrib = &pfhdr->attrib;
psta_addr = pattrib->ta;
prtnframe = NULL;
psta = rtw_get_stainfo(pstapriv, psta_addr);
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n",adapter->securitypriv.dot11AuthAlgrthm));
if(auth_alg==2)
{
if ((psta!=NULL) && (psta->ieee8021x_blocked))
{
//blocked
//only accept EAPOL frame
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("########portctrl:psta->ieee8021x_blocked==1\n"));
prtnframe=precv_frame;
//get ether_type
ptr=ptr+pfhdr->attrib.hdrlen+pfhdr->attrib.iv_len+LLC_HEADER_SIZE;
_rtw_memcpy(ðer_type,ptr, 2);
ether_type= ntohs((unsigned short )ether_type);
if (ether_type == eapol_type) {
prtnframe=precv_frame;
}
else {
//free this frame
rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
prtnframe=NULL;
}
}
else
{
//allowed
//check decryption status, and decrypt the frame if needed
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("########portctrl:psta->ieee8021x_blocked==0\n"));
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("portctrl:precv_frame->hdr.attrib.privacy=%x\n",precv_frame->u.hdr.attrib.privacy));
if (pattrib->bdecrypted == 0)
{
RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("portctrl:prxstat->decrypted=%x\n", pattrib->bdecrypted));
}
prtnframe=precv_frame;
//check is the EAPOL frame or not (Rekey)
//if(ether_type == eapol_type){
// RT_TRACE(_module_rtl871x_recv_c_,_drv_notice_,("########portctrl:ether_type == 0x888e\n"));
//check Rekey
// prtnframe=precv_frame;
//}
//else{
// RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("########portctrl:ether_type=0x%04x\n", ether_type));
//}
}
}
else
{
prtnframe=precv_frame;
}
_func_exit_;
return prtnframe;
}
sint recv_decache(union recv_frame *precv_frame, u8 bretry, struct stainfo_rxcache *prxcache);
sint recv_decache(union recv_frame *precv_frame, u8 bretry, struct stainfo_rxcache *prxcache)
{
sint tid = precv_frame->u.hdr.attrib.priority;
u16 seq_ctrl = ( (precv_frame->u.hdr.attrib.seq_num&0xffff) << 4) |
(precv_frame->u.hdr.attrib.frag_num & 0xf);
_func_enter_;
if(tid>15)
{
RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid));
return _FAIL;
}
if(1)//if(bretry)
{
if(seq_ctrl == prxcache->tid_rxseq[tid])
{
RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, seq_ctrl=0x%x, tid=0x%x, tid_rxseq=0x%x\n", seq_ctrl, tid, prxcache->tid_rxseq[tid]));
return _FAIL;
}
}
prxcache->tid_rxseq[tid] = seq_ctrl;
_func_exit_;
return _SUCCESS;
}
void process_pwrbit_data(_adapter *padapter, union recv_frame *precv_frame);
void process_pwrbit_data(_adapter *padapter, union recv_frame *precv_frame)
{
#ifdef CONFIG_AP_MODE
unsigned char pwrbit;
u8 *ptr = precv_frame->u.hdr.rx_data;
struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
struct sta_priv *pstapriv = &padapter->stapriv;
struct sta_info *psta=NULL;
psta = rtw_get_stainfo(pstapriv, pattrib->src);
pwrbit = GetPwrMgt(ptr);
if(psta)
{
if(pwrbit)
{
if(!(psta->state & WIFI_SLEEP_STATE))
{
//psta->state |= WIFI_SLEEP_STATE;
//pstapriv->sta_dz_bitmap |= BIT(psta->aid);
stop_sta_xmit(padapter, psta);
//DBG_871X("to sleep, sta_dz_bitmap=%x\n", pstapriv->sta_dz_bitmap);
}
}
else
{
if(psta->state & WIFI_SLEEP_STATE)
{
//psta->state ^= WIFI_SLEEP_STATE;
//pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
wakeup_sta_to_xmit(padapter, psta);
//DBG_871X("to wakeup, sta_dz_bitmap=%x\n", pstapriv->sta_dz_bitmap);
}
}
}
#endif
}
void process_wmmps_data(_adapter *padapter, union recv_frame *precv_frame);
void process_wmmps_data(_adapter *padapter, union recv_frame *precv_frame)
{
#ifdef CONFIG_AP_MODE
struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
struct sta_priv *pstapriv = &padapter->stapriv;
struct sta_info *psta=NULL;
psta = rtw_get_stainfo(pstapriv, pattrib->src);
if(!psta) return;
#ifdef CONFIG_TDLS
if( !(psta->tdls_sta_state & TDLS_LINKED_STATE ) )
{
#endif //CONFIG_TDLS
if(!psta->qos_option)
return;
if(!(psta->qos_info&0xf))
return;
#ifdef CONFIG_TDLS
}
#endif //CONFIG_TDLS
if(psta->state&WIFI_SLEEP_STATE)
{
u8 wmmps_ac=0;
switch(pattrib->priority)
{
case 1:
case 2:
wmmps_ac = psta->uapsd_bk&BIT(1);
break;
case 4:
case 5:
wmmps_ac = psta->uapsd_vi&BIT(1);
break;
case 6:
case 7:
wmmps_ac = psta->uapsd_vo&BIT(1);
break;
case 0:
case 3:
default:
wmmps_ac = psta->uapsd_be&BIT(1);
break;
}
if(wmmps_ac)
{
if(psta->sleepq_ac_len>0)
{
//process received triggered frame
xmit_delivery_enabled_frames(padapter, psta);
}
else
{
//issue one qos null frame with More data bit = 0 and the EOSP bit set (=1)
issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0);
}
}