staging: r8188eu: remove RT_TRACE calls from core/rtw_recv.c
[linux-block.git] / drivers / staging / r8188eu / core / rtw_recv.c
CommitLineData
762b759a
LF
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2007 - 2012 Realtek Corporation. */
3
15865124
PP
4#define _RTW_RECV_C_
5
78f2b22e
GKH
6#include "../include/osdep_service.h"
7#include "../include/drv_types.h"
8#include "../include/recv_osdep.h"
9#include "../include/mlme_osdep.h"
10#include "../include/ip.h"
11#include "../include/if_ether.h"
12#include "../include/ethernet.h"
13#include "../include/usb_ops.h"
14#include "../include/wifi.h"
15865124
PP
15
16static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
17static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
18
19/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
20static u8 rtw_bridge_tunnel_header[] = {
21 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
22};
23
24static u8 rtw_rfc1042_header[] = {
25 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
26};
27
15865124 28void rtw_signal_stat_timer_hdl(struct timer_list *);
15865124
PP
29
30void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
31{
32
33 memset((u8 *)psta_recvpriv, 0, sizeof (struct sta_recv_priv));
34
35 spin_lock_init(&psta_recvpriv->lock);
36
37 _rtw_init_queue(&psta_recvpriv->defrag_q);
38
39}
40
41int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
42{
43 int i;
44
45 struct recv_frame *precvframe;
46
47 int res = _SUCCESS;
48
49 spin_lock_init(&precvpriv->lock);
50
51 _rtw_init_queue(&precvpriv->free_recv_queue);
52 _rtw_init_queue(&precvpriv->recv_pending_queue);
53 _rtw_init_queue(&precvpriv->uc_swdec_pending_queue);
54
55 precvpriv->adapter = padapter;
56
57 precvpriv->free_recvframe_cnt = NR_RECVFRAME;
58
59 rtw_os_recv_resource_init(precvpriv, padapter);
60
61 precvpriv->pallocated_frame_buf = rtw_zvmalloc(NR_RECVFRAME * sizeof(struct recv_frame) + RXFRAME_ALIGN_SZ);
62
552838fd 63 if (!precvpriv->pallocated_frame_buf) {
15865124
PP
64 res = _FAIL;
65 goto exit;
66 }
67
68 precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
69
70 precvframe = (struct recv_frame *)precvpriv->precv_frame_buf;
71
72 for (i = 0; i < NR_RECVFRAME; i++) {
73 INIT_LIST_HEAD(&(precvframe->list));
74
75 list_add_tail(&(precvframe->list), &(precvpriv->free_recv_queue.queue));
76
77 res = rtw_os_recv_resource_alloc(padapter, precvframe);
78
79 precvframe->len = 0;
80
81 precvframe->adapter = padapter;
82 precvframe++;
83 }
84 precvpriv->rx_pending_cnt = 1;
85
86 sema_init(&precvpriv->allrxreturnevt, 0);
87
88 res = rtw_hal_init_recv_priv(padapter);
89
15865124 90 timer_setup(&precvpriv->signal_stat_timer, rtw_signal_stat_timer_hdl, 0);
15865124
PP
91 precvpriv->signal_stat_sampling_interval = 1000; /* ms */
92
93 rtw_set_signal_stat_timer(precvpriv);
94exit:
95
96 return res;
97}
98
15865124
PP
99void _rtw_free_recv_priv (struct recv_priv *precvpriv)
100{
101 struct adapter *padapter = precvpriv->adapter;
102
103 rtw_free_uc_swdec_pending_queue(padapter);
104
15865124
PP
105 rtw_os_recv_resource_free(precvpriv);
106
71f09c5a 107 vfree(precvpriv->pallocated_frame_buf);
15865124
PP
108
109 rtw_hal_free_recv_priv(padapter);
15865124
PP
110}
111
112struct recv_frame *_rtw_alloc_recvframe (struct __queue *pfree_recv_queue)
113{
114 struct recv_frame *hdr;
115 struct list_head *plist, *phead;
116 struct adapter *padapter;
117 struct recv_priv *precvpriv;
118
119 if (list_empty(&pfree_recv_queue->queue)) {
120 hdr = NULL;
121 } else {
122 phead = get_list_head(pfree_recv_queue);
123
124 plist = phead->next;
125
126 hdr = container_of(plist, struct recv_frame, list);
127
128 list_del_init(&hdr->list);
129 padapter = hdr->adapter;
552838fd 130 if (padapter) {
15865124
PP
131 precvpriv = &padapter->recvpriv;
132 if (pfree_recv_queue == &precvpriv->free_recv_queue)
133 precvpriv->free_recvframe_cnt--;
134 }
135 }
136
137 return (struct recv_frame *)hdr;
138}
139
140struct recv_frame *rtw_alloc_recvframe (struct __queue *pfree_recv_queue)
141{
142 struct recv_frame *precvframe;
143
144 spin_lock_bh(&pfree_recv_queue->lock);
145
146 precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
147
148 spin_unlock_bh(&pfree_recv_queue->lock);
149
150 return precvframe;
151}
152
153void rtw_init_recvframe(struct recv_frame *precvframe, struct recv_priv *precvpriv)
154{
155 /* Perry: This can be removed */
156 INIT_LIST_HEAD(&precvframe->list);
157
158 precvframe->len = 0;
159}
160
161int rtw_free_recvframe(struct recv_frame *precvframe, struct __queue *pfree_recv_queue)
162{
163 struct adapter *padapter;
164 struct recv_priv *precvpriv;
165
166 if (!precvframe)
167 return _FAIL;
168 padapter = precvframe->adapter;
169 precvpriv = &padapter->recvpriv;
170 if (precvframe->pkt) {
171 dev_kfree_skb_any(precvframe->pkt);/* free skb by driver */
172 precvframe->pkt = NULL;
173 }
174
175 spin_lock_bh(&pfree_recv_queue->lock);
176
177 list_del_init(&(precvframe->list));
178
179 precvframe->len = 0;
180
181 list_add_tail(&(precvframe->list), get_list_head(pfree_recv_queue));
182
552838fd 183 if (padapter) {
15865124
PP
184 if (pfree_recv_queue == &precvpriv->free_recv_queue)
185 precvpriv->free_recvframe_cnt++;
186 }
187
188 spin_unlock_bh(&pfree_recv_queue->lock);
189
190 return _SUCCESS;
191}
192
193int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
194{
195 struct adapter *padapter = precvframe->adapter;
196 struct recv_priv *precvpriv = &padapter->recvpriv;
197
198 list_del_init(&(precvframe->list));
199 list_add_tail(&(precvframe->list), get_list_head(queue));
200
552838fd 201 if (padapter) {
15865124
PP
202 if (queue == &precvpriv->free_recv_queue)
203 precvpriv->free_recvframe_cnt++;
204 }
205
206 return _SUCCESS;
207}
208
209int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
210{
211 int ret;
212
213 spin_lock_bh(&queue->lock);
214 ret = _rtw_enqueue_recvframe(precvframe, queue);
215 spin_unlock_bh(&queue->lock);
216
217 return ret;
218}
219
220/*
221caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
222pframequeue: defrag_queue : will be accessed in recv_thread (passive)
223
224using spinlock to protect
225
226*/
227
228void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue)
229{
230 struct recv_frame *hdr;
231 struct list_head *plist, *phead;
232
233 spin_lock(&pframequeue->lock);
234
235 phead = get_list_head(pframequeue);
236 plist = phead->next;
237
238 while (phead != plist) {
239 hdr = container_of(plist, struct recv_frame, list);
240
241 plist = plist->next;
242
243 rtw_free_recvframe((struct recv_frame *)hdr, pfree_recv_queue);
244 }
245
246 spin_unlock(&pframequeue->lock);
247
248}
249
250u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter)
251{
252 u32 cnt = 0;
253 struct recv_frame *pending_frame;
254 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
255 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
256 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
257 cnt++;
258 }
259
260 return cnt;
261}
262
263int rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue)
264{
265 spin_lock_bh(&queue->lock);
266
267 list_del_init(&precvbuf->list);
268 list_add(&precvbuf->list, get_list_head(queue));
269
270 spin_unlock_bh(&queue->lock);
271
272 return _SUCCESS;
273}
274
275int rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue)
276{
277 unsigned long flags;
278
279 spin_lock_irqsave(&queue->lock, flags);
280
281 list_del_init(&precvbuf->list);
282
283 list_add_tail(&precvbuf->list, get_list_head(queue));
284 spin_unlock_irqrestore(&queue->lock, flags);
285 return _SUCCESS;
286}
287
288struct recv_buf *rtw_dequeue_recvbuf (struct __queue *queue)
289{
290 struct recv_buf *precvbuf;
291 struct list_head *plist, *phead;
292 unsigned long flags;
293
294 spin_lock_irqsave(&queue->lock, flags);
295
296 if (list_empty(&queue->queue)) {
297 precvbuf = NULL;
298 } else {
299 phead = get_list_head(queue);
300
301 plist = phead->next;
302
303 precvbuf = container_of(plist, struct recv_buf, list);
304
305 list_del_init(&precvbuf->list);
306 }
307
308 spin_unlock_irqrestore(&queue->lock, flags);
309
310 return precvbuf;
311}
312
313static int recvframe_chkmic(struct adapter *adapter, struct recv_frame *precvframe)
314{
315 int i, res = _SUCCESS;
316 u32 datalen;
317 u8 miccode[8];
318 u8 bmic_err = false, brpt_micerror = true;
319 u8 *pframe, *payload, *pframemic;
320 u8 *mickey;
321 struct sta_info *stainfo;
322 struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
323 struct security_priv *psecuritypriv = &adapter->securitypriv;
324
325 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
326 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
327
328 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
329
330 if (prxattrib->encrypt == _TKIP_) {
15865124 331 /* calculate mic code */
552838fd 332 if (stainfo) {
15865124
PP
333 if (IS_MCAST(prxattrib->ra)) {
334 mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
335
15865124
PP
336 if (!psecuritypriv) {
337 res = _FAIL;
15865124
PP
338 DBG_88E("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
339 goto exit;
340 }
341 } else {
342 mickey = &stainfo->dot11tkiprxmickey.skey[0];
15865124
PP
343 }
344
345 datalen = precvframe->len-prxattrib->hdrlen-prxattrib->iv_len-prxattrib->icv_len-8;/* icv_len included the mic code */
346 pframe = precvframe->rx_data;
347 payload = pframe+prxattrib->hdrlen+prxattrib->iv_len;
348
15865124
PP
349 rtw_seccalctkipmic(mickey, pframe, payload, datalen, &miccode[0],
350 (unsigned char)prxattrib->priority); /* care the length of the data */
351
352 pframemic = payload+datalen;
353
354 bmic_err = false;
355
356 for (i = 0; i < 8; i++) {
5ea6417a 357 if (miccode[i] != *(pframemic+i))
15865124 358 bmic_err = true;
15865124
PP
359 }
360
361 if (bmic_err) {
15865124
PP
362 /* double check key_index for some timing issue , */
363 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
364 if ((IS_MCAST(prxattrib->ra) == true) && (prxattrib->key_index != pmlmeinfo->key_index))
365 brpt_micerror = false;
366
367 if ((prxattrib->bdecrypted) && (brpt_micerror)) {
368 rtw_handle_tkip_mic_err(adapter, (u8)IS_MCAST(prxattrib->ra));
15865124
PP
369 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
370 } else {
15865124
PP
371 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
372 }
373 res = _FAIL;
374 } else {
375 /* mic checked ok */
5ea6417a 376 if ((!psecuritypriv->bcheck_grpkey) && (IS_MCAST(prxattrib->ra)))
15865124 377 psecuritypriv->bcheck_grpkey = true;
15865124 378 }
15865124
PP
379 }
380
381 recvframe_pull_tail(precvframe, 8);
382 }
383
384exit:
385
386 return res;
387}
388
389/* decrypt and set the ivlen, icvlen of the recv_frame */
390static struct recv_frame *decryptor(struct adapter *padapter, struct recv_frame *precv_frame)
391{
392 struct rx_pkt_attrib *prxattrib = &precv_frame->attrib;
393 struct security_priv *psecuritypriv = &padapter->securitypriv;
394 struct recv_frame *return_packet = precv_frame;
395 u32 res = _SUCCESS;
396
15865124
PP
397 if (prxattrib->encrypt > 0) {
398 u8 *iv = precv_frame->rx_data+prxattrib->hdrlen;
399 prxattrib->key_index = (((iv[3])>>6)&0x3);
400
401 if (prxattrib->key_index > WEP_KEYS) {
402 DBG_88E("prxattrib->key_index(%d)>WEP_KEYS\n", prxattrib->key_index);
403
404 switch (prxattrib->encrypt) {
405 case _WEP40_:
406 case _WEP104_:
407 prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
408 break;
409 case _TKIP_:
410 case _AES_:
411 default:
412 prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
413 break;
414 }
415 }
416 }
417
418 if ((prxattrib->encrypt > 0) && ((prxattrib->bdecrypted == 0) || (psecuritypriv->sw_decrypt))) {
419 psecuritypriv->hw_decrypted = false;
420
421 switch (prxattrib->encrypt) {
422 case _WEP40_:
423 case _WEP104_:
424 rtw_wep_decrypt(padapter, (u8 *)precv_frame);
425 break;
426 case _TKIP_:
427 res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
428 break;
429 case _AES_:
430 res = rtw_aes_decrypt(padapter, (u8 *)precv_frame);
431 break;
432 default:
433 break;
434 }
435 } else if (prxattrib->bdecrypted == 1 && prxattrib->encrypt > 0 &&
436 (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_))
437 psecuritypriv->hw_decrypted = true;
438
439 if (res == _FAIL) {
440 rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue);
441 return_packet = NULL;
442 } else {
443 prxattrib->bdecrypted = true;
444 }
445
446 return return_packet;
447}
448
449/* set the security information in the recv_frame */
450static struct recv_frame *portctrl(struct adapter *adapter, struct recv_frame *precv_frame)
451{
452 u8 *psta_addr, *ptr;
453 uint auth_alg;
454 struct recv_frame *pfhdr;
455 struct sta_info *psta;
456 struct sta_priv *pstapriv;
457 struct recv_frame *prtnframe;
458 u16 ether_type;
459 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */
460 struct rx_pkt_attrib *pattrib;
461 __be16 be_tmp;
462
463 pstapriv = &adapter->stapriv;
464
465 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
466
467 ptr = precv_frame->rx_data;
468 pfhdr = precv_frame;
469 pattrib = &pfhdr->attrib;
470 psta_addr = pattrib->ta;
471
472 prtnframe = NULL;
473
474 psta = rtw_get_stainfo(pstapriv, psta_addr);
15865124
PP
475
476 if (auth_alg == 2) {
552838fd 477 if (psta && psta->ieee8021x_blocked) {
15865124
PP
478 /* blocked */
479 /* only accept EAPOL frame */
15865124
PP
480 prtnframe = precv_frame;
481
482 /* get ether_type */
483 ptr = ptr+pfhdr->attrib.hdrlen+pfhdr->attrib.iv_len+LLC_HEADER_SIZE;
484 memcpy(&be_tmp, ptr, 2);
485 ether_type = ntohs(be_tmp);
486
487 if (ether_type == eapol_type) {
488 prtnframe = precv_frame;
489 } else {
490 /* free this frame */
491 rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
492 prtnframe = NULL;
493 }
494 } else {
495 /* allowed */
496 /* check decryption status, and decrypt the frame if needed */
15865124
PP
497 prtnframe = precv_frame;
498 /* check is the EAPOL frame or not (Rekey) */
5ea6417a 499 if (ether_type == eapol_type)
15865124 500 /* check Rekey */
15865124 501 prtnframe = precv_frame;
15865124
PP
502 }
503 } else {
504 prtnframe = precv_frame;
505 }
506
507 return prtnframe;
508}
509
510static int recv_decache(struct recv_frame *precv_frame, u8 bretry, struct stainfo_rxcache *prxcache)
511{
512 int tid = precv_frame->attrib.priority;
513
514 u16 seq_ctrl = ((precv_frame->attrib.seq_num&0xffff) << 4) |
515 (precv_frame->attrib.frag_num & 0xf);
516
5ea6417a 517 if (tid > 15)
15865124 518 return _FAIL;
15865124
PP
519
520 if (1) {/* if (bretry) */
5ea6417a 521 if (seq_ctrl == prxcache->tid_rxseq[tid])
15865124 522 return _FAIL;
15865124
PP
523 }
524
525 prxcache->tid_rxseq[tid] = seq_ctrl;
526
527 return _SUCCESS;
528}
529
530void process_pwrbit_data(struct adapter *padapter, struct recv_frame *precv_frame);
531void process_pwrbit_data(struct adapter *padapter, struct recv_frame *precv_frame)
532{
533#ifdef CONFIG_88EU_AP_MODE
534 unsigned char pwrbit;
535 u8 *ptr = precv_frame->rx_data;
536 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
537 struct sta_priv *pstapriv = &padapter->stapriv;
538 struct sta_info *psta = NULL;
539
540 psta = rtw_get_stainfo(pstapriv, pattrib->src);
541
542 pwrbit = GetPwrMgt(ptr);
543
544 if (psta) {
545 if (pwrbit) {
546 if (!(psta->state & WIFI_SLEEP_STATE))
547 stop_sta_xmit(padapter, psta);
548 } else {
549 if (psta->state & WIFI_SLEEP_STATE)
550 wakeup_sta_to_xmit(padapter, psta);
551 }
552 }
553
554#endif
555}
556
557static void process_wmmps_data(struct adapter *padapter, struct recv_frame *precv_frame)
558{
559#ifdef CONFIG_88EU_AP_MODE
560 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
561 struct sta_priv *pstapriv = &padapter->stapriv;
562 struct sta_info *psta = NULL;
563
564 psta = rtw_get_stainfo(pstapriv, pattrib->src);
565
566 if (!psta)
567 return;
568
569 if (!psta->qos_option)
570 return;
571
572 if (!(psta->qos_info&0xf))
573 return;
574
575 if (psta->state&WIFI_SLEEP_STATE) {
576 u8 wmmps_ac = 0;
577
578 switch (pattrib->priority) {
579 case 1:
580 case 2:
581 wmmps_ac = psta->uapsd_bk&BIT(1);
582 break;
583 case 4:
584 case 5:
585 wmmps_ac = psta->uapsd_vi&BIT(1);
586 break;
587 case 6:
588 case 7:
589 wmmps_ac = psta->uapsd_vo&BIT(1);
590 break;
591 case 0:
592 case 3:
593 default:
594 wmmps_ac = psta->uapsd_be&BIT(1);
595 break;
596 }
597
598 if (wmmps_ac) {
599 if (psta->sleepq_ac_len > 0) {
600 /* process received triggered frame */
601 xmit_delivery_enabled_frames(padapter, psta);
602 } else {
603 /* issue one qos null frame with More data bit = 0 and the EOSP bit set (= 1) */
604 issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0);
605 }
606 }
607 }
608
609#endif
610}
611
612static void count_rx_stats(struct adapter *padapter, struct recv_frame *prframe, struct sta_info *sta)
613{
614 int sz;
615 struct sta_info *psta = NULL;
616 struct stainfo_stats *pstats = NULL;
617 struct rx_pkt_attrib *pattrib = &prframe->attrib;
618 struct recv_priv *precvpriv = &padapter->recvpriv;
619
620 sz = get_recvframe_len(prframe);
621 precvpriv->rx_bytes += sz;
622
623 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
624
625 if ((!MacAddr_isBcst(pattrib->dst)) && (!IS_MCAST(pattrib->dst)))
626 padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
627
628 if (sta)
629 psta = sta;
630 else
631 psta = prframe->psta;
632
633 if (psta) {
634 pstats = &psta->sta_stats;
635
636 pstats->rx_data_pkts++;
637 pstats->rx_bytes += sz;
638 }
639}
640
641int sta2sta_data_frame(
642 struct adapter *adapter,
643 struct recv_frame *precv_frame,
644 struct sta_info **psta
645);
646
647int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame, struct sta_info **psta)
648{
649 u8 *ptr = precv_frame->rx_data;
650 int ret = _SUCCESS;
651 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
652 struct sta_priv *pstapriv = &adapter->stapriv;
653 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
654 u8 *mybssid = get_bssid(pmlmepriv);
655 u8 *myhwaddr = myid(&adapter->eeprompriv);
656 u8 *sta_addr = NULL;
657 int bmcast = IS_MCAST(pattrib->dst);
658
659 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
660 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
661 /* filter packets that SA is myself or multicast or broadcast */
662 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
15865124
PP
663 ret = _FAIL;
664 goto exit;
665 }
666
667 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
668 ret = _FAIL;
669 goto exit;
670 }
671
672 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
673 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
674 memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
675 ret = _FAIL;
676 goto exit;
677 }
678
679 sta_addr = pattrib->src;
680 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
681 /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */
682 if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN)) {
15865124
PP
683 ret = _FAIL;
684 goto exit;
685 }
686 sta_addr = pattrib->bssid;
687 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
688 if (bmcast) {
689 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
690 if (!IS_MCAST(pattrib->bssid)) {
691 ret = _FAIL;
692 goto exit;
693 }
694 } else { /* not mc-frame */
695 /* For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID */
696 if (memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN)) {
697 ret = _FAIL;
698 goto exit;
699 }
700
701 sta_addr = pattrib->src;
702 }
703 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
704 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
705 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
706 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
707 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
708 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
709
710 sta_addr = mybssid;
711 } else {
712 ret = _FAIL;
713 }
714
715 if (bmcast)
716 *psta = rtw_get_bcmc_stainfo(adapter);
717 else
718 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */
719
552838fd 720 if (!*psta) {
15865124
PP
721 if (adapter->registrypriv.mp_mode == 1) {
722 if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
723 adapter->mppriv.rx_pktloss++;
724 }
725 ret = _FAIL;
726 goto exit;
727 }
728
729exit:
730
731 return ret;
732}
733
734static int ap2sta_data_frame (
735 struct adapter *adapter,
736 struct recv_frame *precv_frame,
737 struct sta_info **psta)
738{
739 u8 *ptr = precv_frame->rx_data;
740 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
741 int ret = _SUCCESS;
742 struct sta_priv *pstapriv = &adapter->stapriv;
743 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
744 u8 *mybssid = get_bssid(pmlmepriv);
745 u8 *myhwaddr = myid(&adapter->eeprompriv);
746 int bmcast = IS_MCAST(pattrib->dst);
747
748 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) &&
749 (check_fwstate(pmlmepriv, _FW_LINKED) == true ||
750 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) {
751 /* filter packets that SA is myself or multicast or broadcast */
752 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
15865124
PP
753 ret = _FAIL;
754 goto exit;
755 }
756
757 /* da should be for me */
758 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
15865124
PP
759 ret = _FAIL;
760 goto exit;
761 }
762
763 /* check BSSID */
764 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
765 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
766 (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
15865124
PP
767 if (!bmcast) {
768 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid));
769 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
770 }
771
772 ret = _FAIL;
773 goto exit;
774 }
775
776 if (bmcast)
777 *psta = rtw_get_bcmc_stainfo(adapter);
778 else
779 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */
780
552838fd 781 if (!*psta) {
15865124
PP
782 ret = _FAIL;
783 goto exit;
784 }
785
786 /* if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) { */
787 /* */
788
789 if (GetFrameSubType(ptr) & BIT(6)) {
790 /* No data, will not indicate to upper layer, temporily count it here */
791 count_rx_stats(adapter, precv_frame, *psta);
792 ret = RTW_RX_HANDLED;
793 goto exit;
794 }
795 } else if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) &&
796 (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
797 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
798 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
799 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
800 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
801 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
802
803 /* */
804 memcpy(pattrib->bssid, mybssid, ETH_ALEN);
805
806 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
552838fd 807 if (!*psta) {
15865124
PP
808 ret = _FAIL;
809 goto exit;
810 }
811 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
812 /* Special case */
813 ret = RTW_RX_HANDLED;
814 goto exit;
815 } else {
816 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
817 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
552838fd 818 if (!*psta) {
15865124
PP
819 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid));
820
821 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
822 }
823 }
824
825 ret = _FAIL;
826 }
827
828exit:
829
830 return ret;
831}
832
833static int sta2ap_data_frame(struct adapter *adapter,
834 struct recv_frame *precv_frame,
835 struct sta_info **psta)
836{
837 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
838 struct sta_priv *pstapriv = &adapter->stapriv;
839 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
840 u8 *ptr = precv_frame->rx_data;
841 unsigned char *mybssid = get_bssid(pmlmepriv);
842 int ret = _SUCCESS;
843
844 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
845 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */
846 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
847 ret = _FAIL;
848 goto exit;
849 }
850
851 *psta = rtw_get_stainfo(pstapriv, pattrib->src);
552838fd 852 if (!*psta) {
15865124
PP
853 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
854
855 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
856
857 ret = RTW_RX_HANDLED;
858 goto exit;
859 }
860
861 process_pwrbit_data(adapter, precv_frame);
862
863 if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) {
864 process_wmmps_data(adapter, precv_frame);
865 }
866
867 if (GetFrameSubType(ptr) & BIT(6)) {
868 /* No data, will not indicate to upper layer, temporily count it here */
869 count_rx_stats(adapter, precv_frame, *psta);
870 ret = RTW_RX_HANDLED;
871 goto exit;
872 }
873 } else {
874 u8 *myhwaddr = myid(&adapter->eeprompriv);
875 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
876 ret = RTW_RX_HANDLED;
877 goto exit;
878 }
879 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
880 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
881 ret = RTW_RX_HANDLED;
882 goto exit;
883 }
884
885exit:
886
887 return ret;
888}
889
890static int validate_recv_ctrl_frame(struct adapter *padapter,
891 struct recv_frame *precv_frame)
892{
893#ifdef CONFIG_88EU_AP_MODE
894 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
895 struct sta_priv *pstapriv = &padapter->stapriv;
896 u8 *pframe = precv_frame->rx_data;
897 /* uint len = precv_frame->len; */
898
899 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
900 return _FAIL;
901
902 /* receive the frames that ra(a1) is my address */
903 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN))
904 return _FAIL;
905
906 /* only handle ps-poll */
907 if (GetFrameSubType(pframe) == WIFI_PSPOLL) {
908 u16 aid;
909 u8 wmmps_ac = 0;
910 struct sta_info *psta = NULL;
911
912 aid = GetAid(pframe);
913 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
914
552838fd 915 if (!psta || psta->aid != aid)
15865124
PP
916 return _FAIL;
917
918 /* for rx pkt statistics */
919 psta->sta_stats.rx_ctrl_pkts++;
920
921 switch (pattrib->priority) {
922 case 1:
923 case 2:
924 wmmps_ac = psta->uapsd_bk&BIT(0);
925 break;
926 case 4:
927 case 5:
928 wmmps_ac = psta->uapsd_vi&BIT(0);
929 break;
930 case 6:
931 case 7:
932 wmmps_ac = psta->uapsd_vo&BIT(0);
933 break;
934 case 0:
935 case 3:
936 default:
937 wmmps_ac = psta->uapsd_be&BIT(0);
938 break;
939 }
940
941 if (wmmps_ac)
942 return _FAIL;
943
944 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
945 DBG_88E("%s alive check-rx ps-poll\n", __func__);
946 psta->expire_to = pstapriv->expire_to;
947 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
948 }
949
950 if ((psta->state&WIFI_SLEEP_STATE) && (pstapriv->sta_dz_bitmap&BIT(psta->aid))) {
951 struct list_head *xmitframe_plist, *xmitframe_phead;
952 struct xmit_frame *pxmitframe = NULL;
953 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
954
955 spin_lock_bh(&pxmitpriv->lock);
956
957 xmitframe_phead = get_list_head(&psta->sleep_q);
958 xmitframe_plist = xmitframe_phead->next;
959
960 if (xmitframe_phead != xmitframe_plist) {
961 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
962
963 xmitframe_plist = xmitframe_plist->next;
964
965 list_del_init(&pxmitframe->list);
966
967 psta->sleepq_len--;
968
969 if (psta->sleepq_len > 0)
970 pxmitframe->attrib.mdata = 1;
971 else
972 pxmitframe->attrib.mdata = 0;
973
974 pxmitframe->attrib.triggered = 1;
975
976 rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
977
978 if (psta->sleepq_len == 0) {
979 pstapriv->tim_bitmap &= ~BIT(psta->aid);
980
981 /* upate BCN for TIM IE */
982 /* update_BCNTIM(padapter); */
983 update_beacon(padapter, _TIM_IE_, NULL, false);
984 }
985 } else {
986 if (pstapriv->tim_bitmap&BIT(psta->aid)) {
987 if (psta->sleepq_len == 0) {
988 DBG_88E("no buffered packets to xmit\n");
989
990 /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */
991 issue_nulldata(padapter, psta->hwaddr, 0, 0, 0);
992 } else {
993 DBG_88E("error!psta->sleepq_len=%d\n", psta->sleepq_len);
994 psta->sleepq_len = 0;
995 }
996
997 pstapriv->tim_bitmap &= ~BIT(psta->aid);
998
999 /* upate BCN for TIM IE */
1000 /* update_BCNTIM(padapter); */
1001 update_beacon(padapter, _TIM_IE_, NULL, false);
1002 }
1003 }
1004 spin_unlock_bh(&pxmitpriv->lock);
1005 }
1006 }
1007
1008#endif
1009
1010 return _FAIL;
1011}
1012
1013struct recv_frame *recvframe_chk_defrag(struct adapter *padapter, struct recv_frame *precv_frame);
1014
1015static int validate_recv_mgnt_frame(struct adapter *padapter,
1016 struct recv_frame *precv_frame)
1017{
1018 struct sta_info *psta;
1019
15865124 1020 precv_frame = recvframe_chk_defrag(padapter, precv_frame);
5ea6417a 1021 if (!precv_frame)
15865124 1022 return _SUCCESS;
15865124
PP
1023
1024 /* for rx pkt statistics */
1025 psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(precv_frame->rx_data));
1026 if (psta) {
1027 psta->sta_stats.rx_mgnt_pkts++;
1028 if (GetFrameSubType(precv_frame->rx_data) == WIFI_BEACON) {
1029 psta->sta_stats.rx_beacon_pkts++;
1030 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBEREQ) {
1031 psta->sta_stats.rx_probereq_pkts++;
1032 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBERSP) {
1033 if (!memcmp(padapter->eeprompriv.mac_addr, GetAddr1Ptr(precv_frame->rx_data), ETH_ALEN))
1034 psta->sta_stats.rx_probersp_pkts++;
1035 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)) ||
1036 is_multicast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)))
1037 psta->sta_stats.rx_probersp_bm_pkts++;
1038 else
1039 psta->sta_stats.rx_probersp_uo_pkts++;
1040 }
1041 }
1042
1043 mgt_dispatcher(padapter, precv_frame);
1044
1045 return _SUCCESS;
1046}
1047
1048static int validate_recv_data_frame(struct adapter *adapter,
1049 struct recv_frame *precv_frame)
1050{
1051 u8 bretry;
1052 u8 *psa, *pda, *pbssid;
1053 struct sta_info *psta = NULL;
1054 u8 *ptr = precv_frame->rx_data;
1055 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1056 struct security_priv *psecuritypriv = &adapter->securitypriv;
1057 int ret = _SUCCESS;
1058
1059 bretry = GetRetry(ptr);
1060 pda = get_da(ptr);
1061 psa = get_sa(ptr);
1062 pbssid = get_hdr_bssid(ptr);
1063
552838fd 1064 if (!pbssid) {
15865124
PP
1065 ret = _FAIL;
1066 goto exit;
1067 }
1068
1069 memcpy(pattrib->dst, pda, ETH_ALEN);
1070 memcpy(pattrib->src, psa, ETH_ALEN);
1071
1072 memcpy(pattrib->bssid, pbssid, ETH_ALEN);
1073
1074 switch (pattrib->to_fr_ds) {
1075 case 0:
1076 memcpy(pattrib->ra, pda, ETH_ALEN);
1077 memcpy(pattrib->ta, psa, ETH_ALEN);
1078 ret = sta2sta_data_frame(adapter, precv_frame, &psta);
1079 break;
1080 case 1:
1081 memcpy(pattrib->ra, pda, ETH_ALEN);
1082 memcpy(pattrib->ta, pbssid, ETH_ALEN);
1083 ret = ap2sta_data_frame(adapter, precv_frame, &psta);
1084 break;
1085 case 2:
1086 memcpy(pattrib->ra, pbssid, ETH_ALEN);
1087 memcpy(pattrib->ta, psa, ETH_ALEN);
1088 ret = sta2ap_data_frame(adapter, precv_frame, &psta);
1089 break;
1090 case 3:
1091 memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
1092 memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
1093 ret = _FAIL;
15865124
PP
1094 break;
1095 default:
1096 ret = _FAIL;
1097 break;
1098 }
1099
1100 if (ret == _FAIL) {
1101 goto exit;
1102 } else if (ret == RTW_RX_HANDLED) {
1103 goto exit;
1104 }
1105
552838fd 1106 if (!psta) {
15865124
PP
1107 ret = _FAIL;
1108 goto exit;
1109 }
1110
1111 /* psta->rssi = prxcmd->rssi; */
1112 /* psta->signal_quality = prxcmd->sq; */
1113 precv_frame->psta = psta;
1114
1115 pattrib->amsdu = 0;
1116 pattrib->ack_policy = 0;
1117 /* parsing QC field */
1118 if (pattrib->qos == 1) {
1119 pattrib->priority = GetPriority((ptr + 24));
1120 pattrib->ack_policy = GetAckpolicy((ptr + 24));
1121 pattrib->amsdu = GetAMsdu((ptr + 24));
1122 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26;
1123
1124 if (pattrib->priority != 0 && pattrib->priority != 3)
1125 adapter->recvpriv.bIsAnyNonBEPkts = true;
1126 } else {
1127 pattrib->priority = 0;
1128 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24;
1129 }
1130
1131 if (pattrib->order)/* HT-CTRL 11n */
1132 pattrib->hdrlen += 4;
1133
1134 precv_frame->preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
1135
1136 /* decache, drop duplicate recv packets */
1137 if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) {
15865124
PP
1138 ret = _FAIL;
1139 goto exit;
1140 }
1141
1142 if (pattrib->privacy) {
15865124
PP
1143 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra));
1144
15865124
PP
1145 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
1146 } else {
1147 pattrib->encrypt = 0;
1148 pattrib->iv_len = 0;
1149 pattrib->icv_len = 0;
1150 }
1151
1152exit:
1153
1154 return ret;
1155}
1156
1157static int validate_recv_frame(struct adapter *adapter, struct recv_frame *precv_frame)
1158{
1159 /* shall check frame subtype, to / from ds, da, bssid */
1160
1161 /* then call check if rx seq/frag. duplicated. */
1162
1163 u8 type;
1164 u8 subtype;
1165 int retval = _SUCCESS;
1166 u8 bDumpRxPkt;
1167 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1168 u8 *ptr = precv_frame->rx_data;
1169 u8 ver = (unsigned char) (*ptr)&0x3;
1170 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1171
1172 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
1173 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
1174 if (ch_set_idx >= 0)
1175 pmlmeext->channel_set[ch_set_idx].rx_count++;
1176 }
1177
1178 /* add version chk */
1179 if (ver != 0) {
15865124
PP
1180 retval = _FAIL;
1181 goto exit;
1182 }
1183
1184 type = GetFrameType(ptr);
1185 subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */
1186
1187 pattrib->to_fr_ds = get_tofr_ds(ptr);
1188
1189 pattrib->frag_num = GetFragNum(ptr);
1190 pattrib->seq_num = GetSequence(ptr);
1191
1192 pattrib->pw_save = GetPwrMgt(ptr);
1193 pattrib->mfrag = GetMFrag(ptr);
1194 pattrib->mdata = GetMData(ptr);
1195 pattrib->privacy = GetPrivacy(ptr);
1196 pattrib->order = GetOrder(ptr);
1197
1198 /* Dump rx packets */
1199 rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
1200 if (bDumpRxPkt == 1) {/* dump all rx packets */
1201 int i;
1202 DBG_88E("#############################\n");
1203
1204 for (i = 0; i < 64; i = i+8)
1205 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1206 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1207 DBG_88E("#############################\n");
1208 } else if (bDumpRxPkt == 2) {
1209 if (type == WIFI_MGT_TYPE) {
1210 int i;
1211 DBG_88E("#############################\n");
1212
1213 for (i = 0; i < 64; i = i+8)
1214 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1215 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1216 DBG_88E("#############################\n");
1217 }
1218 } else if (bDumpRxPkt == 3) {
1219 if (type == WIFI_DATA_TYPE) {
1220 int i;
1221 DBG_88E("#############################\n");
1222
1223 for (i = 0; i < 64; i = i+8)
1224 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1225 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1226 DBG_88E("#############################\n");
1227 }
1228 }
1229 switch (type) {
1230 case WIFI_MGT_TYPE: /* mgnt */
5ea6417a 1231 validate_recv_mgnt_frame(adapter, precv_frame);
15865124
PP
1232 retval = _FAIL; /* only data frame return _SUCCESS */
1233 break;
1234 case WIFI_CTRL_TYPE: /* ctrl */
5ea6417a 1235 validate_recv_ctrl_frame(adapter, precv_frame);
15865124
PP
1236 retval = _FAIL; /* only data frame return _SUCCESS */
1237 break;
1238 case WIFI_DATA_TYPE: /* data */
1239 rtw_led_control(adapter, LED_CTL_RX);
1240 pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
1241 retval = validate_recv_data_frame(adapter, precv_frame);
1242 if (retval == _FAIL) {
1243 struct recv_priv *precvpriv = &adapter->recvpriv;
1244 precvpriv->rx_drop++;
1245 }
1246 break;
1247 default:
15865124
PP
1248 retval = _FAIL;
1249 break;
1250 }
1251
1252exit:
1253
1254 return retval;
1255}
1256
1257/* remove the wlanhdr and add the eth_hdr */
1258
1259static int wlanhdr_to_ethhdr (struct recv_frame *precvframe)
1260{
1261 int rmv_len;
1262 u16 eth_type, len;
1263 __be16 be_tmp;
1264 u8 bsnaphdr;
1265 u8 *psnap_type;
1266 struct ieee80211_snap_hdr *psnap;
1267
1268 int ret = _SUCCESS;
1269 struct adapter *adapter = precvframe->adapter;
1270 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1271
1272 u8 *ptr = get_recvframe_data(precvframe); /* point to frame_ctrl field */
1273 struct rx_pkt_attrib *pattrib = &precvframe->attrib;
1274
1275 if (pattrib->encrypt)
1276 recvframe_pull_tail(precvframe, pattrib->icv_len);
1277
1278 psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
1279 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
1280 /* convert hdr + possible LLC headers into Ethernet header */
1281 if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
1282 memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) &&
1283 memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2)) ||
1284 !memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) {
1285 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1286 bsnaphdr = true;
1287 } else {
1288 /* Leave Ethernet header part of hdr and full payload */
1289 bsnaphdr = false;
1290 }
1291
1292 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0);
1293 len = precvframe->len - rmv_len;
1294
15865124
PP
1295 memcpy(&be_tmp, ptr+rmv_len, 2);
1296 eth_type = ntohs(be_tmp); /* pattrib->ether_type */
1297 pattrib->eth_type = eth_type;
1298
1299 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE))) {
1300 ptr += rmv_len;
1301 *ptr = 0x87;
1302 *(ptr+1) = 0x12;
1303
1304 eth_type = 0x8712;
1305 /* append rx status for mp test packets */
1306 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24);
1307 memcpy(ptr, get_rxmem(precvframe), 24);
1308 ptr += 24;
1309 } else {
1310 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
1311 }
1312
1313 memcpy(ptr, pattrib->dst, ETH_ALEN);
1314 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
1315
1316 if (!bsnaphdr) {
1317 be_tmp = htons(len);
1318 memcpy(ptr+12, &be_tmp, 2);
1319 }
1320
1321 return ret;
1322}
1323
1324/* perform defrag */
1325static struct recv_frame *recvframe_defrag(struct adapter *adapter, struct __queue *defrag_q)
1326{
1327 struct list_head *plist, *phead;
1328 u8 wlanhdr_offset;
1329 u8 curfragnum;
1330 struct recv_frame *pfhdr, *pnfhdr;
1331 struct recv_frame *prframe, *pnextrframe;
1332 struct __queue *pfree_recv_queue;
1333
1334 curfragnum = 0;
1335 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
1336
1337 phead = get_list_head(defrag_q);
1338 plist = phead->next;
1339 pfhdr = container_of(plist, struct recv_frame, list);
1340 prframe = (struct recv_frame *)pfhdr;
1341 list_del_init(&(prframe->list));
1342
1343 if (curfragnum != pfhdr->attrib.frag_num) {
1344 /* the first fragment number must be 0 */
1345 /* free the whole queue */
1346 rtw_free_recvframe(prframe, pfree_recv_queue);
1347 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1348
1349 return NULL;
1350 }
1351
1352 curfragnum++;
1353
1354 plist = get_list_head(defrag_q);
1355 plist = phead->next;
1356 pfhdr = container_of(plist, struct recv_frame, list);
1357 prframe = (struct recv_frame *)pfhdr;
1358 list_del_init(&(prframe->list));
1359
1360 plist = plist->next;
1361
1362 while (phead != plist) {
1363 pnfhdr = container_of(plist, struct recv_frame, list);
1364 pnextrframe = (struct recv_frame *)pnfhdr;
1365
1366 /* check the fragment sequence (2nd ~n fragment frame) */
1367
1368 if (curfragnum != pnfhdr->attrib.frag_num) {
1369 /* the fragment number must be increasing (after decache) */
1370 /* release the defrag_q & prframe */
1371 rtw_free_recvframe(prframe, pfree_recv_queue);
1372 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1373 return NULL;
1374 }
1375
1376 curfragnum++;
1377
1378 /* copy the 2nd~n fragment frame's payload to the first fragment */
1379 /* get the 2nd~last fragment frame's payload */
1380
1381 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1382
1383 recvframe_pull(pnextrframe, wlanhdr_offset);
1384
1385 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1386 recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
1387
1388 /* memcpy */
1389 memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
1390
1391 recvframe_put(prframe, pnfhdr->len);
1392
1393 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
1394 plist = plist->next;
1395 }
1396
1397 /* free the defrag_q queue and return the prframe */
1398 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1399
15865124
PP
1400 return prframe;
1401}
1402
1403/* check if need to defrag, if needed queue the frame to defrag_q */
1404struct recv_frame *recvframe_chk_defrag(struct adapter *padapter, struct recv_frame *precv_frame)
1405{
1406 u8 ismfrag;
1407 u8 fragnum;
1408 u8 *psta_addr;
1409 struct recv_frame *pfhdr;
1410 struct sta_info *psta;
1411 struct sta_priv *pstapriv;
1412 struct list_head *phead;
1413 struct recv_frame *prtnframe = NULL;
1414 struct __queue *pfree_recv_queue, *pdefrag_q;
1415
1416 pstapriv = &padapter->stapriv;
1417
1418 pfhdr = precv_frame;
1419
1420 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1421
1422 /* need to define struct of wlan header frame ctrl */
1423 ismfrag = pfhdr->attrib.mfrag;
1424 fragnum = pfhdr->attrib.frag_num;
1425
1426 psta_addr = pfhdr->attrib.ta;
1427 psta = rtw_get_stainfo(pstapriv, psta_addr);
552838fd 1428 if (!psta) {
15865124
PP
1429 u8 type = GetFrameType(pfhdr->rx_data);
1430 if (type != WIFI_DATA_TYPE) {
1431 psta = rtw_get_bcmc_stainfo(padapter);
1432 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1433 } else {
1434 pdefrag_q = NULL;
1435 }
1436 } else {
1437 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1438 }
1439
1440 if ((ismfrag == 0) && (fragnum == 0))
1441 prtnframe = precv_frame;/* isn't a fragment frame */
1442
1443 if (ismfrag == 1) {
1444 /* 0~(n-1) fragment frame */
1445 /* enqueue to defraf_g */
552838fd 1446 if (pdefrag_q) {
15865124
PP
1447 if (fragnum == 0) {
1448 /* the first fragment */
1449 if (!list_empty(&pdefrag_q->queue)) {
1450 /* free current defrag_q */
1451 rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
1452 }
1453 }
1454
1455 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1456
1457 phead = get_list_head(pdefrag_q);
1458 list_add_tail(&pfhdr->list, phead);
1459
15865124
PP
1460 prtnframe = NULL;
1461 } else {
1462 /* can't find this ta's defrag_queue, so free this recv_frame */
1463 if (precv_frame && pfree_recv_queue)
1464 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1465 prtnframe = NULL;
15865124
PP
1466 }
1467 }
1468
1469 if ((ismfrag == 0) && (fragnum != 0)) {
1470 /* the last fragment frame */
1471 /* enqueue the last fragment */
552838fd 1472 if (pdefrag_q) {
15865124
PP
1473 phead = get_list_head(pdefrag_q);
1474 list_add_tail(&pfhdr->list, phead);
1475
1476 /* call recvframe_defrag to defrag */
15865124
PP
1477 precv_frame = recvframe_defrag(padapter, pdefrag_q);
1478 prtnframe = precv_frame;
1479 } else {
1480 /* can't find this ta's defrag_queue, so free this recv_frame */
1481 if (precv_frame && pfree_recv_queue)
1482 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1483 prtnframe = NULL;
15865124
PP
1484 }
1485 }
1486
552838fd 1487 if (prtnframe && prtnframe->attrib.privacy) {
15865124
PP
1488 /* after defrag we must check tkip mic code */
1489 if (recvframe_chkmic(padapter, prtnframe) == _FAIL) {
15865124
PP
1490 if (precv_frame && pfree_recv_queue)
1491 rtw_free_recvframe(prtnframe, pfree_recv_queue);
1492 prtnframe = NULL;
1493 }
1494 }
1495
1496 return prtnframe;
1497}
1498
1499static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1500{
1501 int a_len, padding_len;
1502 u16 eth_type, nSubframe_Length;
1503 u8 nr_subframes, i;
1504 unsigned char *pdata;
1505 struct rx_pkt_attrib *pattrib;
1506 unsigned char *data_ptr;
1507 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1508 struct recv_priv *precvpriv = &padapter->recvpriv;
1509 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1510 int ret = _SUCCESS;
1511 nr_subframes = 0;
1512
1513 pattrib = &prframe->attrib;
1514
1515 recvframe_pull(prframe, prframe->attrib.hdrlen);
1516
1517 if (prframe->attrib.iv_len > 0)
1518 recvframe_pull(prframe, prframe->attrib.iv_len);
1519
1520 a_len = prframe->len;
1521
1522 pdata = prframe->rx_data;
1523
1524 while (a_len > ETH_HLEN) {
1525 /* Offset 12 denote 2 mac address */
1526 nSubframe_Length = RTW_GET_BE16(pdata + 12);
1527
1528 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
1529 DBG_88E("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len, nSubframe_Length);
1530 goto exit;
1531 }
1532
1533 /* move the data point to data content */
1534 pdata += ETH_HLEN;
1535 a_len -= ETH_HLEN;
1536
1537 /* Allocate new skb for releasing to upper layer */
1538 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1539 if (sub_skb) {
1540 skb_reserve(sub_skb, 12);
1541 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
1542 memcpy(data_ptr, pdata, nSubframe_Length);
1543 } else {
1544 sub_skb = skb_clone(prframe->pkt, GFP_ATOMIC);
1545 if (sub_skb) {
1546 sub_skb->data = pdata;
1547 sub_skb->len = nSubframe_Length;
1548 skb_set_tail_pointer(sub_skb, nSubframe_Length);
1549 } else {
1550 DBG_88E("skb_clone() Fail!!! , nr_subframes=%d\n", nr_subframes);
1551 break;
1552 }
1553 }
1554
1555 subframes[nr_subframes++] = sub_skb;
1556
1557 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
1558 DBG_88E("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1559 break;
1560 }
1561
1562 pdata += nSubframe_Length;
1563 a_len -= nSubframe_Length;
1564 if (a_len != 0) {
1565 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4-1));
1566 if (padding_len == 4) {
1567 padding_len = 0;
1568 }
1569
1570 if (a_len < padding_len) {
1571 goto exit;
1572 }
1573 pdata += padding_len;
1574 a_len -= padding_len;
1575 }
1576 }
1577
1578 for (i = 0; i < nr_subframes; i++) {
1579 sub_skb = subframes[i];
1580 /* convert hdr + possible LLC headers into Ethernet header */
1581 eth_type = RTW_GET_BE16(&sub_skb->data[6]);
1582 if (sub_skb->len >= 8 &&
1583 ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
1584 eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
1585 !memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
1586 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1587 skb_pull(sub_skb, SNAP_SIZE);
1588 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1589 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1590 } else {
1591 __be16 len;
1592 /* Leave Ethernet header part of hdr and full payload */
1593 len = htons(sub_skb->len);
1594 memcpy(skb_push(sub_skb, 2), &len, 2);
1595 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1596 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1597 }
1598
1599 /* Indicate the packets to upper layer */
1600 /* Insert NAT2.5 RX here! */
1601 sub_skb->protocol = eth_type_trans(sub_skb, padapter->pnetdev);
1602 sub_skb->dev = padapter->pnetdev;
1603
1604 sub_skb->ip_summed = CHECKSUM_NONE;
1605
1606 netif_rx(sub_skb);
1607 }
1608
1609exit:
1610
1611 prframe->len = 0;
1612 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1613
1614 return ret;
1615}
1616
1617static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
1618{
1619 u8 wsize = preorder_ctrl->wsize_b;
1620 u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF;/* 4096; */
1621
1622 /* Rx Reorder initialize condition. */
1623 if (preorder_ctrl->indicate_seq == 0xFFFF)
1624 preorder_ctrl->indicate_seq = seq_num;
1625
1626 /* Drop out the packet which SeqNum is smaller than WinStart */
1627 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
1628 return false;
1629
1630 /* */
1631 /* Sliding window manipulation. Conditions includes: */
1632 /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */
1633 /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */
1634 /* */
1635 if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) {
1636 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1637 } else if (SN_LESS(wend, seq_num)) {
1638 if (seq_num >= (wsize - 1))
1639 preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
1640 else
1641 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
1642 }
1643
1644 return true;
1645}
1646
1647int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, struct recv_frame *prframe);
1648int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, struct recv_frame *prframe)
1649{
1650 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1651 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1652 struct list_head *phead, *plist;
1653 struct recv_frame *hdr;
1654 struct rx_pkt_attrib *pnextattrib;
1655
1656 phead = get_list_head(ppending_recvframe_queue);
1657 plist = phead->next;
1658
1659 while (phead != plist) {
1660 hdr = container_of(plist, struct recv_frame, list);
1661 pnextattrib = &hdr->attrib;
1662
1663 if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
1664 plist = plist->next;
1665 else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
1666 return false;
1667 else
1668 break;
1669 }
1670
1671 list_del_init(&(prframe->list));
1672
1673 list_add_tail(&(prframe->list), plist);
1674 return true;
1675}
1676
1677static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
1678{
1679 struct list_head *phead, *plist;
1680 struct recv_frame *prframe;
1681 struct rx_pkt_attrib *pattrib;
1682 int bPktInBuf = false;
1683 struct recv_priv *precvpriv = &padapter->recvpriv;
1684 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1685
1686 phead = get_list_head(ppending_recvframe_queue);
1687 plist = phead->next;
1688
1689 /* Handling some condition for forced indicate case. */
1690 if (bforced) {
1691 if (list_empty(phead))
1692 return true;
1693
1694 prframe = container_of(plist, struct recv_frame, list);
1695 pattrib = &prframe->attrib;
1696 preorder_ctrl->indicate_seq = pattrib->seq_num;
1697 }
1698
1699 /* Prepare indication list and indication. */
1700 /* Check if there is any packet need indicate. */
1701 while (!list_empty(phead)) {
1702 prframe = container_of(plist, struct recv_frame, list);
1703 pattrib = &prframe->attrib;
1704
1705 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
15865124
PP
1706 plist = plist->next;
1707 list_del_init(&(prframe->list));
1708
1709 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
1710 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1711
1712 /* Set this as a lock to make sure that only one thread is indicating packet. */
1713
1714 /* indicate this recv_frame */
1715 if (!pattrib->amsdu) {
1716 if ((!padapter->bDriverStopped) &&
1717 (!padapter->bSurpriseRemoved))
1718 rtw_recv_indicatepkt(padapter, prframe);/* indicate this recv_frame */
1719 } else if (pattrib->amsdu == 1) {
1720 if (amsdu_to_msdu(padapter, prframe) != _SUCCESS)
1721 rtw_free_recvframe(prframe, &precvpriv->free_recv_queue);
1722 } else {
1723 /* error condition; */
1724 }
1725
1726 /* Update local variables. */
1727 bPktInBuf = false;
1728 } else {
1729 bPktInBuf = true;
1730 break;
1731 }
1732 }
1733 return bPktInBuf;
1734}
1735
1736static int recv_indicatepkt_reorder(struct adapter *padapter, struct recv_frame *prframe)
1737{
1738 int retval = _SUCCESS;
1739 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1740 struct recv_reorder_ctrl *preorder_ctrl = prframe->preorder_ctrl;
1741 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1742
1743 if (!pattrib->amsdu) {
1744 /* s1. */
1745 wlanhdr_to_ethhdr(prframe);
1746
1747 if (pattrib->qos != 1) {
1748 if (!padapter->bDriverStopped &&
1749 !padapter->bSurpriseRemoved) {
15865124
PP
1750 rtw_recv_indicatepkt(padapter, prframe);
1751 return _SUCCESS;
1752 }
1753
1754 return _FAIL;
1755 }
1756
1757 if (!preorder_ctrl->enable) {
1758 /* indicate this recv_frame */
1759 preorder_ctrl->indicate_seq = pattrib->seq_num;
1760 rtw_recv_indicatepkt(padapter, prframe);
1761
1762 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1763 return _SUCCESS;
1764 }
1765 } else if (pattrib->amsdu == 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */
1766 if (!preorder_ctrl->enable) {
1767 preorder_ctrl->indicate_seq = pattrib->seq_num;
1768 retval = amsdu_to_msdu(padapter, prframe);
1769
1770 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1771 return retval;
1772 }
1773 }
1774
1775 spin_lock_bh(&ppending_recvframe_queue->lock);
1776
15865124
PP
1777 /* s2. check if winstart_b(indicate_seq) needs to been updated */
1778 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num))
1779 goto _err_exit;
1780
1781 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1782 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
1783 goto _err_exit;
1784
1785 /* s4. */
1786 /* Indication process. */
1787 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
1788 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
1789 /* */
1790 /* For Rx Reorder condition: */
1791 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
1792 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
1793 /* */
1794
1795 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */
1796 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
1797 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
1798 spin_unlock_bh(&ppending_recvframe_queue->lock);
1799 } else {
1800 spin_unlock_bh(&ppending_recvframe_queue->lock);
1801 _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
1802 }
1803
1804_success_exit:
1805
1806 return _SUCCESS;
1807
1808_err_exit:
1809
1810 spin_unlock_bh(&ppending_recvframe_queue->lock);
1811
1812 return _FAIL;
1813}
1814
1815void rtw_reordering_ctrl_timeout_handler(void *pcontext)
1816{
1817 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)pcontext;
1818 struct adapter *padapter = preorder_ctrl->padapter;
1819 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1820
1821 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
1822 return;
1823
1824 spin_lock_bh(&ppending_recvframe_queue->lock);
1825
1826 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, true) == true)
1827 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
1828
1829 spin_unlock_bh(&ppending_recvframe_queue->lock);
1830}
1831
1832static int process_recv_indicatepkts(struct adapter *padapter, struct recv_frame *prframe)
1833{
1834 int retval = _SUCCESS;
1835 /* struct recv_priv *precvpriv = &padapter->recvpriv; */
1836 /* struct rx_pkt_attrib *pattrib = &prframe->attrib; */
1837 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1838 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
1839
1840 if (phtpriv->ht_option) { /* B/G/N Mode */
1841 /* prframe->preorder_ctrl = &precvpriv->recvreorder_ctrl[pattrib->priority]; */
1842
1843 if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) {
1844 /* including perform A-MPDU Rx Ordering Buffer Control */
1845 if ((!padapter->bDriverStopped) &&
1846 (!padapter->bSurpriseRemoved)) {
1847 retval = _FAIL;
1848 return retval;
1849 }
1850 }
1851 } else { /* B/G mode */
1852 retval = wlanhdr_to_ethhdr (prframe);
5ea6417a 1853 if (retval != _SUCCESS)
15865124 1854 return retval;
15865124
PP
1855
1856 if ((!padapter->bDriverStopped) &&
1857 (!padapter->bSurpriseRemoved)) {
1858 /* indicate this recv_frame */
15865124
PP
1859 rtw_recv_indicatepkt(padapter, prframe);
1860 } else {
15865124
PP
1861 retval = _FAIL;
1862 return retval;
1863 }
1864 }
1865
1866 return retval;
1867}
1868
1869static int recv_func_prehandle(struct adapter *padapter, struct recv_frame *rframe)
1870{
1871 int ret = _SUCCESS;
1872 struct rx_pkt_attrib *pattrib = &rframe->attrib;
1873 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1874 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1875
1876 if (padapter->registrypriv.mp_mode == 1) {
1877 if (pattrib->crc_err == 1)
1878 padapter->mppriv.rx_crcerrpktcount++;
1879 else
1880 padapter->mppriv.rx_pktcount++;
1881
1882 if (check_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE) == false) {
15865124
PP
1883 ret = _FAIL;
1884 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
1885 goto exit;
1886 }
1887 }
1888
1889 /* check the frame crtl field and decache */
1890 ret = validate_recv_frame(padapter, rframe);
1891 if (ret != _SUCCESS) {
15865124
PP
1892 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
1893 goto exit;
1894 }
1895
1896exit:
1897 return ret;
1898}
1899
1900static int recv_func_posthandle(struct adapter *padapter, struct recv_frame *prframe)
1901{
1902 int ret = _SUCCESS;
1903 struct recv_frame *orig_prframe = prframe;
1904 struct recv_priv *precvpriv = &padapter->recvpriv;
1905 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1906
1907 /* DATA FRAME */
1908 rtw_led_control(padapter, LED_CTL_RX);
1909
1910 prframe = decryptor(padapter, prframe);
552838fd 1911 if (!prframe) {
15865124
PP
1912 ret = _FAIL;
1913 goto _recv_data_drop;
1914 }
1915
1916 prframe = recvframe_chk_defrag(padapter, prframe);
5ea6417a 1917 if (!prframe)
15865124 1918 goto _recv_data_drop;
15865124
PP
1919
1920 prframe = portctrl(padapter, prframe);
552838fd 1921 if (!prframe) {
15865124
PP
1922 ret = _FAIL;
1923 goto _recv_data_drop;
1924 }
1925
1926 count_rx_stats(padapter, prframe, NULL);
1927
1928 ret = process_recv_indicatepkts(padapter, prframe);
1929 if (ret != _SUCCESS) {
15865124
PP
1930 rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */
1931 goto _recv_data_drop;
1932 }
1933 return ret;
1934
1935_recv_data_drop:
1936 precvpriv->rx_drop++;
1937 return ret;
1938}
1939
1940static int recv_func(struct adapter *padapter, struct recv_frame *rframe)
1941{
1942 int ret;
1943 struct rx_pkt_attrib *prxattrib = &rframe->attrib;
1944 struct security_priv *psecuritypriv = &padapter->securitypriv;
1945 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
1946 struct recv_priv *recvpriv = &padapter->recvpriv;
1947
1948 /* check if need to handle uc_swdec_pending_queue*/
1949 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
1950 psecuritypriv->busetkipkey) {
1951 struct recv_frame *pending_frame;
1952 int cnt = 0;
1953
1954 pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue);
1955 while (pending_frame) {
1956 cnt++;
1957 recv_func_posthandle(padapter, pending_frame);
1958 }
1959 }
1960
1961 ret = recv_func_prehandle(padapter, rframe);
1962
1963 if (ret == _SUCCESS) {
1964 /* check if need to enqueue into uc_swdec_pending_queue*/
1965 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
1966 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 &&
1967 (prxattrib->bdecrypted == 0 || psecuritypriv->sw_decrypt) &&
1968 psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPAPSK &&
1969 !psecuritypriv->busetkipkey) {
1970 rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
1971 DBG_88E("%s: no key, enqueue uc_swdec_pending_queue\n", __func__);
1972 if (recvpriv->free_recvframe_cnt < NR_RECVFRAME/4) {
1973 /* to prevent from recvframe starvation,
1974 * get recvframe from uc_swdec_pending_queue to
1975 * free_recvframe_cnt */
1976 rframe = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue);
1977 if (rframe)
1978 goto do_posthandle;
1979 }
1980 goto exit;
1981 }
1982do_posthandle:
1983 ret = recv_func_posthandle(padapter, rframe);
1984 }
1985
1986exit:
1987 return ret;
1988}
1989
1990s32 rtw_recv_entry(struct recv_frame *precvframe)
1991{
1992 struct adapter *padapter;
1993 struct recv_priv *precvpriv;
1994 s32 ret = _SUCCESS;
1995
1996 padapter = precvframe->adapter;
1997
1998 precvpriv = &padapter->recvpriv;
1999
2000 ret = recv_func(padapter, precvframe);
5ea6417a 2001 if (ret == _FAIL)
15865124 2002 goto _recv_entry_drop;
15865124
PP
2003
2004 precvpriv->rx_pkts++;
2005
2006 return ret;
2007
2008_recv_entry_drop:
2009
2010 if (padapter->registrypriv.mp_mode == 1)
2011 padapter->mppriv.rx_pktloss = precvpriv->rx_drop;
2012
2013 return ret;
2014}
2015
15865124 2016void rtw_signal_stat_timer_hdl(struct timer_list *t)
15865124 2017{
15865124 2018 struct adapter *adapter = from_timer(adapter, t, recvpriv.signal_stat_timer);
15865124
PP
2019 struct recv_priv *recvpriv = &adapter->recvpriv;
2020
2021 u32 tmp_s, tmp_q;
2022 u8 avg_signal_strength = 0;
2023 u8 avg_signal_qual = 0;
2024 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2025
2026 if (adapter->recvpriv.is_signal_dbg) {
2027 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */
2028 adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg;
2029 adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg);
2030 } else {
2031 if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */
2032 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2033 /* after avg_vals are accquired, we can re-stat the signal values */
2034 recvpriv->signal_strength_data.update_req = 1;
2035 }
2036
2037 if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */
2038 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2039 /* after avg_vals are accquired, we can re-stat the signal values */
2040 recvpriv->signal_qual_data.update_req = 1;
2041 }
2042
2043 /* update value of signal_strength, rssi, signal_qual */
2044 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) {
2045 tmp_s = (avg_signal_strength+(_alpha-1)*recvpriv->signal_strength);
2046 if (tmp_s % _alpha)
2047 tmp_s = tmp_s/_alpha + 1;
2048 else
2049 tmp_s = tmp_s/_alpha;
2050 if (tmp_s > 100)
2051 tmp_s = 100;
2052
2053 tmp_q = (avg_signal_qual+(_alpha-1)*recvpriv->signal_qual);
2054 if (tmp_q % _alpha)
2055 tmp_q = tmp_q/_alpha + 1;
2056 else
2057 tmp_q = tmp_q/_alpha;
2058 if (tmp_q > 100)
2059 tmp_q = 100;
2060
2061 recvpriv->signal_strength = tmp_s;
2062 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2063 recvpriv->signal_qual = tmp_q;
2064 }
2065 }
2066 rtw_set_signal_stat_timer(recvpriv);
2067}