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