1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
9 #include <linux/ieee80211.h>
10 #include <linux/if_ether.h>
12 #include <osdep_service.h>
13 #include <drv_types.h>
14 #include <recv_osdep.h>
15 #include <mlme_osdep.h>
18 #include <linux/vmalloc.h>
19 #include <linux/etherdevice.h>
20 #include <net/cfg80211.h>
22 #define LLC_HEADER_SIZE 6 /* LLC Header Length */
24 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
25 static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
27 static void rtw_signal_stat_timer_hdl(struct timer_list *t);
29 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
31 memset((u8 *)psta_recvpriv, 0, sizeof(struct sta_recv_priv));
33 spin_lock_init(&psta_recvpriv->lock);
35 _rtw_init_queue(&psta_recvpriv->defrag_q);
38 int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
42 struct recv_frame *precvframe;
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);
50 precvpriv->adapter = padapter;
52 precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(struct recv_frame) + RXFRAME_ALIGN_SZ);
54 if (!precvpriv->pallocated_frame_buf)
57 precvframe = PTR_ALIGN(precvpriv->pallocated_frame_buf, RXFRAME_ALIGN_SZ);
59 for (i = 0; i < NR_RECVFRAME; i++) {
60 INIT_LIST_HEAD(&precvframe->list);
62 list_add_tail(&precvframe->list,
63 &precvpriv->free_recv_queue.queue);
65 precvframe->pkt = NULL;
67 precvframe->adapter = padapter;
70 res = rtw_hal_init_recv_priv(padapter);
72 timer_setup(&precvpriv->signal_stat_timer, rtw_signal_stat_timer_hdl,
75 precvpriv->signal_stat_sampling_interval = 1000; /* ms */
77 rtw_set_signal_stat_timer(precvpriv);
82 void _rtw_free_recv_priv(struct recv_priv *precvpriv)
84 struct adapter *padapter = precvpriv->adapter;
86 rtw_free_uc_swdec_pending_queue(padapter);
88 vfree(precvpriv->pallocated_frame_buf);
90 rtw_hal_free_recv_priv(padapter);
93 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
95 struct recv_frame *hdr;
97 hdr = list_first_entry_or_null(&pfree_recv_queue->queue,
98 struct recv_frame, list);
100 list_del_init(&hdr->list);
105 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
107 struct recv_frame *precvframe;
109 spin_lock_bh(&pfree_recv_queue->lock);
111 precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
113 spin_unlock_bh(&pfree_recv_queue->lock);
118 void rtw_free_recvframe(struct recv_frame *precvframe, struct __queue *pfree_recv_queue)
123 if (precvframe->pkt) {
124 dev_kfree_skb_any(precvframe->pkt);/* free skb by driver */
125 precvframe->pkt = NULL;
128 spin_lock_bh(&pfree_recv_queue->lock);
130 list_del_init(&precvframe->list);
132 list_add_tail(&precvframe->list, get_list_head(pfree_recv_queue));
134 spin_unlock_bh(&pfree_recv_queue->lock);
137 int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
139 list_del_init(&precvframe->list);
140 list_add_tail(&precvframe->list, get_list_head(queue));
145 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
149 spin_lock_bh(&queue->lock);
150 ret = _rtw_enqueue_recvframe(precvframe, queue);
151 spin_unlock_bh(&queue->lock);
157 * caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
158 * pframequeue: defrag_queue : will be accessed in recv_thread (passive)
160 * using spinlock to protect
164 void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue)
166 struct recv_frame *hdr;
167 struct list_head *plist, *phead;
169 spin_lock(&pframequeue->lock);
171 phead = get_list_head(pframequeue);
174 while (phead != plist) {
175 hdr = list_entry(plist, struct recv_frame, list);
179 rtw_free_recvframe(hdr, pfree_recv_queue);
182 spin_unlock(&pframequeue->lock);
185 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter)
188 struct recv_frame *pending_frame;
190 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
191 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
198 static int recvframe_chkmic(struct adapter *adapter,
199 struct recv_frame *precvframe)
201 int i, res = _SUCCESS;
204 u8 bmic_err = false, brpt_micerror = true;
205 u8 *pframe, *payload, *pframemic;
207 struct sta_info *stainfo;
208 struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
209 struct security_priv *psecuritypriv = &adapter->securitypriv;
211 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
212 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
214 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
216 if (prxattrib->encrypt == _TKIP_) {
217 /* calculate mic code */
219 if (is_multicast_ether_addr(prxattrib->ra)) {
220 if (!psecuritypriv) {
224 mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
226 mickey = &stainfo->dot11tkiprxmickey.skey[0];
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;
235 rtw_seccalctkipmic(mickey, pframe, payload, datalen, &miccode[0],
236 (unsigned char)prxattrib->priority); /* care the length of the data */
238 pframemic = payload + datalen;
242 for (i = 0; i < 8; i++) {
243 if (miccode[i] != *(pframemic + i))
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;
253 if ((prxattrib->bdecrypted) && (brpt_micerror))
254 rtw_handle_tkip_mic_err(adapter, (u8)is_multicast_ether_addr(prxattrib->ra));
258 if (!psecuritypriv->bcheck_grpkey &&
259 is_multicast_ether_addr(prxattrib->ra))
260 psecuritypriv->bcheck_grpkey = true;
264 skb_trim(precvframe->pkt, precvframe->pkt->len - 8);
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)
276 struct rx_pkt_attrib *prxattrib = &precv_frame->attrib;
277 struct security_priv *psecuritypriv = &padapter->securitypriv;
278 struct recv_frame *return_packet = precv_frame;
281 if (prxattrib->encrypt > 0) {
282 u8 *iv = precv_frame->pkt->data + prxattrib->hdrlen;
284 prxattrib->key_index = (((iv[3]) >> 6) & 0x3);
286 if (prxattrib->key_index > WEP_KEYS) {
287 switch (prxattrib->encrypt) {
290 prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
295 prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
301 if ((prxattrib->encrypt > 0) && (prxattrib->bdecrypted == 0)) {
302 psecuritypriv->hw_decrypted = false;
304 switch (prxattrib->encrypt) {
307 res = rtw_wep_decrypt(padapter, precv_frame);
310 res = rtw_tkip_decrypt(padapter, precv_frame);
313 res = rtw_aes_decrypt(padapter, precv_frame);
318 } else if (prxattrib->bdecrypted == 1 && prxattrib->encrypt > 0 &&
319 (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_))
320 psecuritypriv->hw_decrypted = true;
323 rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue);
324 return_packet = NULL;
327 return return_packet;
330 /* set the security information in the recv_frame */
331 static struct recv_frame *portctrl(struct adapter *adapter,
332 struct recv_frame *precv_frame)
336 struct recv_frame *pfhdr;
337 struct sta_info *psta;
338 struct sta_priv *pstapriv;
339 struct recv_frame *prtnframe;
341 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */
342 struct rx_pkt_attrib *pattrib;
345 pstapriv = &adapter->stapriv;
347 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
349 ptr = precv_frame->pkt->data;
351 pattrib = &pfhdr->attrib;
352 psta_addr = pattrib->ta;
353 psta = rtw_get_stainfo(pstapriv, psta_addr);
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);
363 if (psta && (psta->ieee8021x_blocked)) {
365 /* only accept EAPOL frame */
366 if (ether_type == eapol_type) {
367 prtnframe = precv_frame;
369 /* free this frame */
370 rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
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)
380 prtnframe = precv_frame;
383 prtnframe = precv_frame;
389 static int recv_decache(struct recv_frame *precv_frame, u8 bretry,
390 struct stainfo_rxcache *prxcache)
392 int tid = precv_frame->attrib.priority;
394 u16 seq_ctrl = ((precv_frame->attrib.seq_num & 0xffff) << 4) |
395 (precv_frame->attrib.frag_num & 0xf);
400 if (seq_ctrl == prxcache->tid_rxseq[tid])
403 prxcache->tid_rxseq[tid] = seq_ctrl;
408 static void process_pwrbit_data(struct adapter *padapter,
409 struct recv_frame *precv_frame)
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;
418 psta = rtw_get_stainfo(pstapriv, pattrib->src);
420 pwrbit = GetPwrMgt(ptr);
424 if (!(psta->state & WIFI_SLEEP_STATE))
425 stop_sta_xmit(padapter, psta);
427 if (psta->state & WIFI_SLEEP_STATE)
428 wakeup_sta_to_xmit(padapter, psta);
435 static void process_wmmps_data(struct adapter *padapter,
436 struct recv_frame *precv_frame)
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;
443 psta = rtw_get_stainfo(pstapriv, pattrib->src);
448 if (!psta->qos_option)
451 if (!(psta->qos_info & 0xf))
454 if (psta->state & WIFI_SLEEP_STATE) {
457 switch (pattrib->priority) {
460 wmmps_ac = psta->uapsd_bk & BIT(1);
464 wmmps_ac = psta->uapsd_vi & BIT(1);
468 wmmps_ac = psta->uapsd_vo & BIT(1);
473 wmmps_ac = psta->uapsd_be & BIT(1);
478 if (psta->sleepq_ac_len > 0) {
479 /* process received triggered frame */
480 xmit_delivery_enabled_frames(padapter, psta);
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);
491 static void count_rx_stats(struct adapter *padapter,
492 struct recv_frame *prframe,
493 struct sta_info *sta)
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;
501 sz = prframe->pkt->len;
502 precvpriv->rx_bytes += sz;
504 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
506 if (!is_multicast_ether_addr(pattrib->dst))
507 padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
512 psta = prframe->psta;
515 pstats = &psta->sta_stats;
517 pstats->rx_data_pkts++;
518 pstats->rx_bytes += sz;
522 static int sta2sta_data_frame(struct adapter *adapter,
523 struct recv_frame *precv_frame,
524 struct sta_info **psta)
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);
533 bool mcast = is_multicast_ether_addr(pattrib->dst);
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)) {
543 if (memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) {
548 if (is_zero_ether_addr(pattrib->bssid) ||
549 is_zero_ether_addr(mybssid) ||
550 memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
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)) {
562 sta_addr = pattrib->bssid;
563 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
565 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
566 if (!is_multicast_ether_addr(pattrib->bssid)) {
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)) {
577 sta_addr = pattrib->src;
584 *psta = rtw_get_bcmc_stainfo(adapter);
586 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */
597 static int ap2sta_data_frame(struct adapter *adapter,
598 struct recv_frame *precv_frame,
599 struct sta_info **psta)
601 u8 *ptr = precv_frame->pkt->data;
602 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
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);
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)) {
619 /* da should be for me */
620 if (memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) {
626 if (is_zero_ether_addr(pattrib->bssid) ||
627 is_zero_ether_addr(mybssid) ||
628 (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
630 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
637 *psta = rtw_get_bcmc_stainfo(adapter);
639 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */
646 /* if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) { */
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;
655 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
657 ret = RTW_RX_HANDLED;
660 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) {
661 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
663 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
674 static int sta2ap_data_frame(struct adapter *adapter,
675 struct recv_frame *precv_frame,
676 struct sta_info **psta)
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);
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)) {
692 *psta = rtw_get_stainfo(pstapriv, pattrib->src);
694 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
696 ret = RTW_RX_HANDLED;
700 process_pwrbit_data(adapter, precv_frame);
702 if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE)
703 process_wmmps_data(adapter, precv_frame);
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;
712 u8 *myhwaddr = myid(&adapter->eeprompriv);
714 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
715 ret = RTW_RX_HANDLED;
718 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
719 ret = RTW_RX_HANDLED;
728 static int validate_recv_ctrl_frame(struct adapter *padapter,
729 struct recv_frame *precv_frame)
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;
736 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
739 /* receive the frames that ra(a1) is my address */
740 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN))
743 /* only handle ps-poll */
744 if (GetFrameSubType(pframe) == (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL)) {
747 struct sta_info *psta = NULL;
749 aid = GetAid(pframe);
750 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
752 if ((!psta) || (psta->aid != aid))
755 /* for rx pkt statistics */
756 psta->sta_stats.rx_ctrl_pkts++;
758 switch (pattrib->priority) {
761 wmmps_ac = psta->uapsd_bk & BIT(0);
765 wmmps_ac = psta->uapsd_vi & BIT(0);
769 wmmps_ac = psta->uapsd_vo & BIT(0);
774 wmmps_ac = psta->uapsd_be & BIT(0);
781 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
782 psta->expire_to = pstapriv->expire_to;
783 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
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;
790 spin_lock_bh(&psta->sleep_q.lock);
792 xmitframe_phead = get_list_head(&psta->sleep_q);
793 xmitframe_plist = xmitframe_phead->next;
795 if (xmitframe_phead != xmitframe_plist) {
796 pxmitframe = list_entry(xmitframe_plist, struct xmit_frame, list);
798 xmitframe_plist = xmitframe_plist->next;
800 list_del_init(&pxmitframe->list);
804 if (psta->sleepq_len > 0)
805 pxmitframe->attrib.mdata = 1;
807 pxmitframe->attrib.mdata = 0;
809 pxmitframe->attrib.triggered = 1;
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);
816 if (psta->sleepq_len == 0) {
817 pstapriv->tim_bitmap &= ~BIT(psta->aid);
819 /* update BCN for TIM IE */
820 /* update_BCNTIM(padapter); */
821 update_beacon(padapter, WLAN_EID_TIM, NULL, false);
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);
829 psta->sleepq_len = 0;
831 pstapriv->tim_bitmap &= ~BIT(psta->aid);
833 /* update BCN for TIM IE */
834 /* update_BCNTIM(padapter); */
835 update_beacon(padapter, WLAN_EID_TIM, NULL, false);
839 spin_unlock_bh(&psta->sleep_q.lock);
848 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
849 struct recv_frame *precv_frame);
851 static int validate_recv_mgnt_frame(struct adapter *padapter,
852 struct recv_frame *precv_frame)
854 struct sta_info *psta;
856 precv_frame = recvframe_chk_defrag(padapter, precv_frame);
860 /* for rx pkt statistics */
861 psta = rtw_get_stainfo(&padapter->stapriv,
862 GetAddr2Ptr(precv_frame->pkt->data));
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++;
876 psta->sta_stats.rx_probersp_uo_pkts++;
880 mgt_dispatcher(padapter, precv_frame);
885 static int validate_recv_data_frame(struct adapter *adapter,
886 struct recv_frame *precv_frame)
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;
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);
906 memcpy(pattrib->dst, pda, ETH_ALEN);
907 memcpy(pattrib->src, psa, ETH_ALEN);
909 memcpy(pattrib->bssid, pbssid, ETH_ALEN);
911 switch (pattrib->to_fr_ds) {
913 memcpy(pattrib->ra, pda, ETH_ALEN);
914 memcpy(pattrib->ta, psa, ETH_ALEN);
915 ret = sta2sta_data_frame(adapter, precv_frame, &psta);
918 memcpy(pattrib->ra, pda, ETH_ALEN);
919 memcpy(pattrib->ta, pbssid, ETH_ALEN);
920 ret = ap2sta_data_frame(adapter, precv_frame, &psta);
923 memcpy(pattrib->ra, pbssid, ETH_ALEN);
924 memcpy(pattrib->ta, psa, ETH_ALEN);
925 ret = sta2ap_data_frame(adapter, precv_frame, &psta);
928 memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
929 memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
939 else if (ret == RTW_RX_HANDLED)
947 /* psta->rssi = prxcmd->rssi; */
948 /* psta->signal_quality = prxcmd->sq; */
949 precv_frame->psta = psta;
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;
960 if (pattrib->priority != 0 && pattrib->priority != 3)
961 adapter->recvpriv.bIsAnyNonBEPkts = true;
963 pattrib->priority = 0;
964 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24;
967 if (pattrib->order)/* HT-CTRL 11n */
968 pattrib->hdrlen += 4;
970 precv_frame->preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
972 /* decache, drop duplicate recv packets */
973 if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) {
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);
982 pattrib->encrypt = 0;
984 pattrib->icv_len = 0;
992 static int validate_recv_frame(struct adapter *adapter,
993 struct recv_frame *precv_frame)
995 /* shall check frame subtype, to / from ds, da, bssid */
997 /* then call check if rx seq/frag. duplicated. */
1001 int retval = _SUCCESS;
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;
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));
1011 if (ch_set_idx >= 0)
1012 pmlmeext->channel_set[ch_set_idx].rx_count++;
1015 /* add version chk */
1021 type = GetFrameType(ptr);
1022 subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */
1024 pattrib->to_fr_ds = get_tofr_ds(ptr);
1026 pattrib->frag_num = GetFragNum(ptr);
1027 pattrib->seq_num = GetSequence(ptr);
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);
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");
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");
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");
1060 case WIFI_MGT_TYPE: /* mgnt */
1061 retval = validate_recv_mgnt_frame(adapter, precv_frame);
1062 retval = _FAIL; /* only data frame return _SUCCESS */
1064 case WIFI_CTRL_TYPE: /* ctrl */
1065 retval = validate_recv_ctrl_frame(adapter, precv_frame);
1066 retval = _FAIL; /* only data frame return _SUCCESS */
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;
1075 precvpriv->rx_drop++;
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.
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()).
1091 * Hence forward the frame to the monitor anyway to preserve the order
1092 * in which frames were received.
1094 rtl88eu_mon_recv_hook(adapter->pmondev, precv_frame);
1101 /* remove the wlanhdr and add the eth_hdr */
1103 static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1110 struct ieee80211_snap_hdr *psnap;
1112 u8 *ptr = precvframe->pkt->data;
1113 struct rx_pkt_attrib *pattrib = &precvframe->attrib;
1115 if (pattrib->encrypt)
1116 skb_trim(precvframe->pkt, precvframe->pkt->len - pattrib->icv_len);
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 */
1128 /* Leave Ethernet header part of hdr and full payload */
1132 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0);
1133 len = precvframe->pkt->len - rmv_len;
1135 memcpy(&be_tmp, ptr + rmv_len, 2);
1136 eth_type = ntohs(be_tmp); /* pattrib->ether_type */
1137 pattrib->eth_type = eth_type;
1139 ptr = skb_pull(precvframe->pkt, rmv_len - sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0));
1143 memcpy(ptr, pattrib->dst, ETH_ALEN);
1144 memcpy(ptr + ETH_ALEN, pattrib->src, ETH_ALEN);
1147 be_tmp = htons(len);
1148 memcpy(ptr + 12, &be_tmp, 2);
1154 /* perform defrag */
1155 static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1156 struct __queue *defrag_q)
1158 struct list_head *plist, *phead;
1161 struct recv_frame *pnfhdr;
1162 struct recv_frame *prframe, *pnextrframe;
1163 struct __queue *pfree_recv_queue;
1166 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
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);
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);
1184 plist = get_list_head(defrag_q);
1186 plist = plist->next;
1188 while (phead != plist) {
1189 pnfhdr = list_entry(plist, struct recv_frame, list);
1190 pnextrframe = pnfhdr;
1192 /* check the fragment sequence (2nd ~n fragment frame) */
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);
1204 /* copy the 2nd~n fragment frame's payload to the first fragment */
1205 /* get the 2nd~last fragment frame's payload */
1207 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1209 skb_pull(pnextrframe->pkt, wlanhdr_offset);
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);
1214 skb_put_data(prframe->pkt, pnfhdr->pkt->data, pnfhdr->pkt->len);
1216 prframe->attrib.icv_len = pnfhdr->attrib.icv_len;
1217 plist = plist->next;
1220 /* free the defrag_q queue and return the prframe */
1221 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
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)
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;
1240 pstapriv = &padapter->stapriv;
1242 pfhdr = precv_frame;
1244 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1246 /* need to define struct of wlan header frame ctrl */
1247 ismfrag = pfhdr->attrib.mfrag;
1248 fragnum = pfhdr->attrib.frag_num;
1250 psta_addr = pfhdr->attrib.ta;
1251 psta = rtw_get_stainfo(pstapriv, psta_addr);
1253 u8 type = GetFrameType(pfhdr->pkt->data);
1255 if (type != WIFI_DATA_TYPE) {
1256 psta = rtw_get_bcmc_stainfo(padapter);
1257 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1262 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1265 if ((ismfrag == 0) && (fragnum == 0))
1266 prtnframe = precv_frame;/* isn't a fragment frame */
1269 /* 0~(n-1) fragment frame */
1270 /* enqueue to defraf_g */
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);
1279 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1281 phead = get_list_head(pdefrag_q);
1282 list_add_tail(&pfhdr->list, phead);
1286 /* can't find this ta's defrag_queue, so free this recv_frame */
1287 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1292 if ((ismfrag == 0) && (fragnum != 0)) {
1293 /* the last fragment frame */
1294 /* enqueue the last fragment */
1296 phead = get_list_head(pdefrag_q);
1297 list_add_tail(&pfhdr->list, phead);
1299 /* call recvframe_defrag to defrag */
1300 precv_frame = recvframe_defrag(padapter, pdefrag_q);
1301 prtnframe = precv_frame;
1303 /* can't find this ta's defrag_queue, so free this recv_frame */
1304 rtw_free_recvframe(precv_frame, pfree_recv_queue);
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);
1320 static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1322 int a_len, padding_len;
1323 u16 eth_type, nSubframe_Length;
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;
1332 pattrib = &prframe->attrib;
1334 skb_pull(prframe->pkt, prframe->attrib.hdrlen);
1336 if (prframe->attrib.iv_len > 0)
1337 skb_pull(prframe->pkt, prframe->attrib.iv_len);
1339 a_len = prframe->pkt->len;
1341 pdata = prframe->pkt->data;
1343 while (a_len > ETH_HLEN) {
1344 /* Offset 12 denote 2 mac address */
1345 nSubframe_Length = get_unaligned_be16(pdata + 12);
1347 if (a_len < (ETH_HLEN + nSubframe_Length))
1350 /* move the data point to data content */
1354 /* Allocate new skb for releasing to upper layer */
1355 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1359 skb_reserve(sub_skb, 12);
1360 skb_put_data(sub_skb, pdata, nSubframe_Length);
1362 subframes[nr_subframes++] = sub_skb;
1364 if (nr_subframes >= MAX_SUBFRAME_COUNT)
1367 pdata += nSubframe_Length;
1368 a_len -= nSubframe_Length;
1370 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4 - 1));
1371 if (padding_len == 4)
1374 if (a_len < padding_len)
1377 pdata += padding_len;
1378 a_len -= padding_len;
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);
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);
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;
1408 sub_skb->ip_summed = CHECKSUM_NONE;
1414 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1419 static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
1421 u8 wsize = preorder_ctrl->wsize_b;
1422 u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF;/* 4096; */
1424 /* Rx Reorder initialize condition. */
1425 if (preorder_ctrl->indicate_seq == 0xFFFF)
1426 preorder_ctrl->indicate_seq = seq_num;
1428 /* Drop out the packet which SeqNum is smaller than WinStart */
1429 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
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 */
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;
1443 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
1449 static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
1450 struct recv_frame *prframe)
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;
1458 phead = get_list_head(ppending_recvframe_queue);
1459 plist = phead->next;
1461 while (phead != plist) {
1462 hdr = list_entry(plist, struct recv_frame, list);
1463 pnextattrib = &hdr->attrib;
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))
1473 list_del_init(&prframe->list);
1475 list_add_tail(&prframe->list, plist);
1479 static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
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;
1489 phead = get_list_head(ppending_recvframe_queue);
1490 plist = phead->next;
1492 /* Handling some condition for forced indicate case. */
1494 if (list_empty(phead))
1497 prhdr = list_entry(plist, struct recv_frame, list);
1498 pattrib = &prhdr->attrib;
1499 preorder_ctrl->indicate_seq = pattrib->seq_num;
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);
1507 pattrib = &prframe->attrib;
1509 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
1510 plist = plist->next;
1511 list_del_init(&prframe->list);
1513 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
1514 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1516 /* Set this as a lock to make sure that only one thread is indicating packet. */
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);
1527 /* error condition; */
1530 /* Update local variables. */
1540 static int recv_indicatepkt_reorder(struct adapter *padapter,
1541 struct recv_frame *prframe)
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;
1548 if (!pattrib->amsdu) {
1550 wlanhdr_to_ethhdr(prframe);
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);
1563 if (!preorder_ctrl->enable) {
1564 /* indicate this recv_frame */
1565 preorder_ctrl->indicate_seq = pattrib->seq_num;
1566 rtw_recv_indicatepkt(padapter, prframe);
1568 preorder_ctrl->indicate_seq =
1569 (preorder_ctrl->indicate_seq + 1) % 4096;
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);
1577 preorder_ctrl->indicate_seq =
1578 (preorder_ctrl->indicate_seq + 1) % 4096;
1583 spin_lock_bh(&ppending_recvframe_queue->lock);
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);
1589 spin_unlock_bh(&ppending_recvframe_queue->lock);
1594 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1595 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
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. */
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. */
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);
1614 spin_unlock_bh(&ppending_recvframe_queue->lock);
1615 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
1624 spin_unlock_bh(&ppending_recvframe_queue->lock);
1629 void rtw_reordering_ctrl_timeout_handler(struct timer_list *t)
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;
1636 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
1639 spin_lock_bh(&ppending_recvframe_queue->lock);
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));
1645 spin_unlock_bh(&ppending_recvframe_queue->lock);
1648 static int process_recv_indicatepkts(struct adapter *padapter,
1649 struct recv_frame *prframe)
1651 int retval = _SUCCESS;
1652 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1653 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
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)) {
1663 } else { /* B/G mode */
1664 retval = wlanhdr_to_ethhdr(prframe);
1665 if (retval != _SUCCESS)
1668 if ((!padapter->bDriverStopped) &&
1669 (!padapter->bSurpriseRemoved))
1670 /* indicate this recv_frame */
1671 rtw_recv_indicatepkt(padapter, prframe);
1679 static int recv_func_prehandle(struct adapter *padapter,
1680 struct recv_frame *rframe)
1683 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
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 */
1696 static int recv_func_posthandle(struct adapter *padapter,
1697 struct recv_frame *prframe)
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;
1705 led_control_8188eu(padapter, LED_CTL_RX);
1707 prframe = decryptor(padapter, prframe);
1710 goto _recv_data_drop;
1713 prframe = recvframe_chk_defrag(padapter, prframe);
1715 goto _recv_data_drop;
1717 prframe = portctrl(padapter, prframe);
1720 goto _recv_data_drop;
1723 count_rx_stats(padapter, prframe, NULL);
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;
1733 precvpriv->rx_drop++;
1737 static int recv_func(struct adapter *padapter, struct recv_frame *rframe)
1740 struct rx_pkt_attrib *prxattrib = &rframe->attrib;
1741 struct security_priv *psecuritypriv = &padapter->securitypriv;
1742 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
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;
1748 while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue)))
1749 recv_func_posthandle(padapter, pending_frame);
1752 ret = recv_func_prehandle(padapter, rframe);
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);
1766 ret = recv_func_posthandle(padapter, rframe);
1773 int rtw_recv_entry(struct recv_frame *precvframe)
1775 struct adapter *padapter = precvframe->adapter;
1776 struct recv_priv *precvpriv = &padapter->recvpriv;
1779 ret = recv_func(padapter, precvframe);
1780 if (ret == _SUCCESS)
1781 precvpriv->rx_pkts++;
1786 static void rtw_signal_stat_timer_hdl(struct timer_list *t)
1788 struct adapter *adapter =
1789 from_timer(adapter, t, recvpriv.signal_stat_timer);
1790 struct recv_priv *recvpriv = &adapter->recvpriv;
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 */
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
1803 recvpriv->signal_strength_data.update_req = 1;
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
1812 recvpriv->signal_qual_data.update_req = 1;
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);
1823 tmp_q = avg_signal_qual +
1824 (_alpha - 1) * recvpriv->signal_qual;
1825 tmp_q = DIV_ROUND_UP(tmp_q, _alpha);
1829 recvpriv->signal_strength = tmp_s;
1830 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
1831 recvpriv->signal_qual = tmp_q;
1834 rtw_set_signal_stat_timer(recvpriv);