1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
17 #include <linux/ieee80211.h>
19 #include <osdep_service.h>
20 #include <drv_types.h>
21 #include <recv_osdep.h>
22 #include <mlme_osdep.h>
25 #include <linux/vmalloc.h>
27 #define ETHERNET_HEADER_SIZE 14 /* Ethernet Header Length */
28 #define LLC_HEADER_SIZE 6 /* LLC Header Length */
30 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
31 static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
33 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
34 static u8 rtw_bridge_tunnel_header[] = {
35 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
38 static u8 rtw_rfc1042_header[] = {
39 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
42 static void rtw_signal_stat_timer_hdl(unsigned long data);
44 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
47 memset((u8 *)psta_recvpriv, 0, sizeof(struct sta_recv_priv));
49 spin_lock_init(&psta_recvpriv->lock);
51 _rtw_init_queue(&psta_recvpriv->defrag_q);
55 int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
59 struct recv_frame *precvframe;
63 _rtw_init_queue(&precvpriv->free_recv_queue);
64 _rtw_init_queue(&precvpriv->recv_pending_queue);
65 _rtw_init_queue(&precvpriv->uc_swdec_pending_queue);
67 precvpriv->adapter = padapter;
69 precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(struct recv_frame) + RXFRAME_ALIGN_SZ);
71 if (!precvpriv->pallocated_frame_buf)
74 precvframe = PTR_ALIGN(precvpriv->pallocated_frame_buf, RXFRAME_ALIGN_SZ);
76 for (i = 0; i < NR_RECVFRAME; i++) {
77 INIT_LIST_HEAD(&(precvframe->list));
79 list_add_tail(&(precvframe->list),
80 &(precvpriv->free_recv_queue.queue));
82 precvframe->pkt = NULL;
84 precvframe->adapter = padapter;
87 res = rtw_hal_init_recv_priv(padapter);
89 setup_timer(&precvpriv->signal_stat_timer,
90 rtw_signal_stat_timer_hdl,
91 (unsigned long)padapter);
93 precvpriv->signal_stat_sampling_interval = 1000; /* ms */
95 rtw_set_signal_stat_timer(precvpriv);
100 void _rtw_free_recv_priv(struct recv_priv *precvpriv)
102 struct adapter *padapter = precvpriv->adapter;
104 rtw_free_uc_swdec_pending_queue(padapter);
106 vfree(precvpriv->pallocated_frame_buf);
108 rtw_hal_free_recv_priv(padapter);
112 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
114 struct recv_frame *hdr;
116 hdr = list_first_entry_or_null(&pfree_recv_queue->queue,
117 struct recv_frame, list);
119 list_del_init(&hdr->list);
124 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
126 struct recv_frame *precvframe;
128 spin_lock_bh(&pfree_recv_queue->lock);
130 precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
132 spin_unlock_bh(&pfree_recv_queue->lock);
137 int rtw_free_recvframe(struct recv_frame *precvframe,
138 struct __queue *pfree_recv_queue)
142 if (precvframe->pkt) {
143 dev_kfree_skb_any(precvframe->pkt);/* free skb by driver */
144 precvframe->pkt = NULL;
147 spin_lock_bh(&pfree_recv_queue->lock);
149 list_del_init(&(precvframe->list));
151 list_add_tail(&(precvframe->list), get_list_head(pfree_recv_queue));
153 spin_unlock_bh(&pfree_recv_queue->lock);
158 int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
160 list_del_init(&(precvframe->list));
161 list_add_tail(&(precvframe->list), get_list_head(queue));
166 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
170 spin_lock_bh(&queue->lock);
171 ret = _rtw_enqueue_recvframe(precvframe, queue);
172 spin_unlock_bh(&queue->lock);
178 caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
179 pframequeue: defrag_queue : will be accessed in recv_thread (passive)
181 using spinlock to protect
185 void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue)
187 struct recv_frame *hdr;
188 struct list_head *plist, *phead;
190 spin_lock(&pframequeue->lock);
192 phead = get_list_head(pframequeue);
195 while (phead != plist) {
196 hdr = container_of(plist, struct recv_frame, list);
200 rtw_free_recvframe(hdr, pfree_recv_queue);
203 spin_unlock(&pframequeue->lock);
207 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter)
210 struct recv_frame *pending_frame;
212 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
213 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
214 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
221 static int recvframe_chkmic(struct adapter *adapter,
222 struct recv_frame *precvframe)
224 int i, res = _SUCCESS;
227 u8 bmic_err = false, brpt_micerror = true;
228 u8 *pframe, *payload, *pframemic;
230 struct sta_info *stainfo;
231 struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
232 struct security_priv *psecuritypriv = &adapter->securitypriv;
234 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
235 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
237 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
239 if (prxattrib->encrypt == _TKIP_) {
240 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic:prxattrib->encrypt==_TKIP_\n"));
241 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic:da=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
242 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2], prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5]));
244 /* calculate mic code */
245 if (stainfo != NULL) {
246 if (IS_MCAST(prxattrib->ra)) {
247 if (!psecuritypriv) {
249 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n"));
250 DBG_88E("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
253 mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
255 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic: bcmc key\n"));
257 mickey = &stainfo->dot11tkiprxmickey.skey[0];
258 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic: unicast key\n"));
261 /* icv_len included the mic code */
262 datalen = precvframe->pkt->len-prxattrib->hdrlen -
263 prxattrib->iv_len-prxattrib->icv_len-8;
264 pframe = precvframe->pkt->data;
265 payload = pframe+prxattrib->hdrlen+prxattrib->iv_len;
267 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n", prxattrib->iv_len, prxattrib->icv_len));
268 rtw_seccalctkipmic(mickey, pframe, payload, datalen, &miccode[0],
269 (unsigned char)prxattrib->priority); /* care the length of the data */
271 pframemic = payload+datalen;
275 for (i = 0; i < 8; i++) {
276 if (miccode[i] != *(pframemic+i)) {
277 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
278 ("recvframe_chkmic:miccode[%d](%02x)!=*(pframemic+%d)(%02x) ",
279 i, miccode[i], i, *(pframemic+i)));
285 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
286 ("\n *(pframemic-8)-*(pframemic-1)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
287 *(pframemic-8), *(pframemic-7), *(pframemic-6),
288 *(pframemic-5), *(pframemic-4), *(pframemic-3),
289 *(pframemic-2), *(pframemic-1)));
290 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
291 ("\n *(pframemic-16)-*(pframemic-9)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
292 *(pframemic-16), *(pframemic-15), *(pframemic-14),
293 *(pframemic-13), *(pframemic-12), *(pframemic-11),
294 *(pframemic-10), *(pframemic-9)));
298 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
299 ("\n ======demp packet (len=%d)======\n",
300 precvframe->pkt->len));
301 for (i = 0; i < precvframe->pkt->len; i += 8) {
302 RT_TRACE(_module_rtl871x_recv_c_,
304 ("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
305 *(precvframe->pkt->data+i),
306 *(precvframe->pkt->data+i+1),
307 *(precvframe->pkt->data+i+2),
308 *(precvframe->pkt->data+i+3),
309 *(precvframe->pkt->data+i+4),
310 *(precvframe->pkt->data+i+5),
311 *(precvframe->pkt->data+i+6),
312 *(precvframe->pkt->data+i+7)));
314 RT_TRACE(_module_rtl871x_recv_c_,
316 ("\n ====== demp packet end [len=%d]======\n",
317 precvframe->pkt->len));
318 RT_TRACE(_module_rtl871x_recv_c_,
324 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
325 ("ra=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x psecuritypriv->binstallGrpkey=%d ",
326 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2],
327 prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5], psecuritypriv->binstallGrpkey));
329 /* double check key_index for some timing issue , */
330 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
331 if ((IS_MCAST(prxattrib->ra) == true) && (prxattrib->key_index != pmlmeinfo->key_index))
332 brpt_micerror = false;
334 if ((prxattrib->bdecrypted) && (brpt_micerror)) {
335 rtw_handle_tkip_mic_err(adapter, (u8)IS_MCAST(prxattrib->ra));
336 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
337 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
339 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
340 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
345 if ((!psecuritypriv->bcheck_grpkey) && (IS_MCAST(prxattrib->ra))) {
346 psecuritypriv->bcheck_grpkey = true;
347 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("psecuritypriv->bcheck_grpkey = true"));
351 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
354 skb_trim(precvframe->pkt, precvframe->pkt->len - 8);
362 /* decrypt and set the ivlen, icvlen of the recv_frame */
363 static struct recv_frame *decryptor(struct adapter *padapter,
364 struct recv_frame *precv_frame)
366 struct rx_pkt_attrib *prxattrib = &precv_frame->attrib;
367 struct security_priv *psecuritypriv = &padapter->securitypriv;
368 struct recv_frame *return_packet = precv_frame;
371 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("prxstat->decrypted=%x prxattrib->encrypt=0x%03x\n", prxattrib->bdecrypted, prxattrib->encrypt));
373 if (prxattrib->encrypt > 0) {
374 u8 *iv = precv_frame->pkt->data+prxattrib->hdrlen;
376 prxattrib->key_index = (((iv[3])>>6)&0x3);
378 if (prxattrib->key_index > WEP_KEYS) {
379 DBG_88E("prxattrib->key_index(%d)>WEP_KEYS\n", prxattrib->key_index);
381 switch (prxattrib->encrypt) {
384 prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
389 prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
395 if ((prxattrib->encrypt > 0) && (prxattrib->bdecrypted == 0)) {
396 psecuritypriv->hw_decrypted = false;
398 switch (prxattrib->encrypt) {
401 rtw_wep_decrypt(padapter, (u8 *)precv_frame);
404 res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
407 res = rtw_aes_decrypt(padapter, (u8 *)precv_frame);
412 } else if (prxattrib->bdecrypted == 1 && prxattrib->encrypt > 0 &&
413 (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_))
414 psecuritypriv->hw_decrypted = true;
417 rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue);
418 return_packet = NULL;
421 return return_packet;
424 /* set the security information in the recv_frame */
425 static struct recv_frame *portctrl(struct adapter *adapter,
426 struct recv_frame *precv_frame)
430 struct recv_frame *pfhdr;
431 struct sta_info *psta;
432 struct sta_priv *pstapriv;
433 struct recv_frame *prtnframe;
435 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */
436 struct rx_pkt_attrib *pattrib;
439 pstapriv = &adapter->stapriv;
441 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
443 ptr = precv_frame->pkt->data;
445 pattrib = &pfhdr->attrib;
446 psta_addr = pattrib->ta;
447 psta = rtw_get_stainfo(pstapriv, psta_addr);
451 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n", adapter->securitypriv.dot11AuthAlgrthm));
455 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE + pfhdr->attrib.iv_len;
456 memcpy(&be_tmp, ptr, 2);
457 ether_type = ntohs(be_tmp);
459 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
461 /* only accept EAPOL frame */
462 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==1\n"));
464 if (ether_type == eapol_type) {
465 prtnframe = precv_frame;
467 /* free this frame */
468 rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
473 /* check decryption status, and decrypt the frame if needed */
474 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==0\n"));
475 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
476 ("portctrl:precv_frame->hdr.attrib.privacy=%x\n",
477 precv_frame->attrib.privacy));
479 if (pattrib->bdecrypted == 0)
480 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("portctrl:prxstat->decrypted=%x\n", pattrib->bdecrypted));
482 prtnframe = precv_frame;
483 /* check is the EAPOL frame or not (Rekey) */
484 if (ether_type == eapol_type) {
485 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("########portctrl:ether_type==0x888e\n"));
488 prtnframe = precv_frame;
490 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:ether_type=0x%04x\n", ether_type));
494 prtnframe = precv_frame;
500 static int recv_decache(struct recv_frame *precv_frame, u8 bretry,
501 struct stainfo_rxcache *prxcache)
503 int tid = precv_frame->attrib.priority;
505 u16 seq_ctrl = ((precv_frame->attrib.seq_num&0xffff) << 4) |
506 (precv_frame->attrib.frag_num & 0xf);
509 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid));
514 if (1) {/* if (bretry) */
515 if (seq_ctrl == prxcache->tid_rxseq[tid]) {
516 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, seq_ctrl=0x%x, tid=0x%x, tid_rxseq=0x%x\n", seq_ctrl, tid, prxcache->tid_rxseq[tid]));
522 prxcache->tid_rxseq[tid] = seq_ctrl;
527 static void process_pwrbit_data(struct adapter *padapter,
528 struct recv_frame *precv_frame)
530 #ifdef CONFIG_88EU_AP_MODE
531 unsigned char pwrbit;
532 u8 *ptr = precv_frame->pkt->data;
533 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
534 struct sta_priv *pstapriv = &padapter->stapriv;
535 struct sta_info *psta = NULL;
537 psta = rtw_get_stainfo(pstapriv, pattrib->src);
539 pwrbit = GetPwrMgt(ptr);
543 if (!(psta->state & WIFI_SLEEP_STATE))
544 stop_sta_xmit(padapter, psta);
546 if (psta->state & WIFI_SLEEP_STATE)
547 wakeup_sta_to_xmit(padapter, psta);
554 static void process_wmmps_data(struct adapter *padapter,
555 struct recv_frame *precv_frame)
557 #ifdef CONFIG_88EU_AP_MODE
558 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
559 struct sta_priv *pstapriv = &padapter->stapriv;
560 struct sta_info *psta = NULL;
562 psta = rtw_get_stainfo(pstapriv, pattrib->src);
567 if (!psta->qos_option)
570 if (!(psta->qos_info&0xf))
573 if (psta->state&WIFI_SLEEP_STATE) {
576 switch (pattrib->priority) {
579 wmmps_ac = psta->uapsd_bk&BIT(1);
583 wmmps_ac = psta->uapsd_vi&BIT(1);
587 wmmps_ac = psta->uapsd_vo&BIT(1);
592 wmmps_ac = psta->uapsd_be&BIT(1);
597 if (psta->sleepq_ac_len > 0) {
598 /* process received triggered frame */
599 xmit_delivery_enabled_frames(padapter, psta);
601 /* issue one qos null frame with More data bit = 0 and the EOSP bit set (= 1) */
602 issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0);
610 static void count_rx_stats(struct adapter *padapter,
611 struct recv_frame *prframe,
612 struct sta_info *sta)
615 struct sta_info *psta = NULL;
616 struct stainfo_stats *pstats = NULL;
617 struct rx_pkt_attrib *pattrib = &prframe->attrib;
618 struct recv_priv *precvpriv = &padapter->recvpriv;
620 sz = prframe->pkt->len;
621 precvpriv->rx_bytes += sz;
623 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
625 if ((!MacAddr_isBcst(pattrib->dst)) && (!IS_MCAST(pattrib->dst)))
626 padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
631 psta = prframe->psta;
634 pstats = &psta->sta_stats;
636 pstats->rx_data_pkts++;
637 pstats->rx_bytes += sz;
641 int sta2sta_data_frame(
642 struct adapter *adapter,
643 struct recv_frame *precv_frame,
644 struct sta_info **psta
647 int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
648 struct sta_info **psta)
651 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
652 struct sta_priv *pstapriv = &adapter->stapriv;
653 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
654 u8 *mybssid = get_bssid(pmlmepriv);
655 u8 *myhwaddr = myid(&adapter->eeprompriv);
657 int bmcast = IS_MCAST(pattrib->dst);
659 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
660 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
661 /* filter packets that SA is myself or multicast or broadcast */
662 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
663 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
668 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
673 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
674 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
675 memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
680 sta_addr = pattrib->src;
681 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
682 /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */
683 if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN)) {
684 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("bssid!=TA under STATION_MODE; drop pkt\n"));
688 sta_addr = pattrib->bssid;
689 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
691 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
692 if (!IS_MCAST(pattrib->bssid)) {
696 } else { /* not mc-frame */
697 /* For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID */
698 if (memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN)) {
703 sta_addr = pattrib->src;
710 *psta = rtw_get_bcmc_stainfo(adapter);
712 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */
715 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under sta2sta_data_frame ; drop pkt\n"));
724 static int ap2sta_data_frame(
725 struct adapter *adapter,
726 struct recv_frame *precv_frame,
727 struct sta_info **psta)
729 u8 *ptr = precv_frame->pkt->data;
730 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
732 struct sta_priv *pstapriv = &adapter->stapriv;
733 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
734 u8 *mybssid = get_bssid(pmlmepriv);
735 u8 *myhwaddr = myid(&adapter->eeprompriv);
736 int bmcast = IS_MCAST(pattrib->dst);
738 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) &&
739 (check_fwstate(pmlmepriv, _FW_LINKED) == true ||
740 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) {
741 /* filter packets that SA is myself or multicast or broadcast */
742 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
743 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
748 /* da should be for me */
749 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
750 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
751 (" ap2sta_data_frame: compare DA fail; DA=%pM\n", (pattrib->dst)));
757 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
758 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
759 (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
760 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
761 (" ap2sta_data_frame: compare BSSID fail ; BSSID=%pM\n", (pattrib->bssid)));
762 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("mybssid=%pM\n", (mybssid)));
765 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid));
766 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
774 *psta = rtw_get_bcmc_stainfo(adapter);
776 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */
779 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
784 /* if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) { */
787 if (GetFrameSubType(ptr) & BIT(6)) {
788 /* No data, will not indicate to upper layer, temporily count it here */
789 count_rx_stats(adapter, precv_frame, *psta);
790 ret = RTW_RX_HANDLED;
793 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
795 ret = RTW_RX_HANDLED;
798 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
799 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
801 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid));
803 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
815 static int sta2ap_data_frame(struct adapter *adapter,
816 struct recv_frame *precv_frame,
817 struct sta_info **psta)
819 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
820 struct sta_priv *pstapriv = &adapter->stapriv;
821 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
822 u8 *ptr = precv_frame->pkt->data;
823 unsigned char *mybssid = get_bssid(pmlmepriv);
826 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
827 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */
828 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
833 *psta = rtw_get_stainfo(pstapriv, pattrib->src);
835 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under AP_MODE; drop pkt\n"));
836 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
838 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
840 ret = RTW_RX_HANDLED;
844 process_pwrbit_data(adapter, precv_frame);
846 if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE)
847 process_wmmps_data(adapter, precv_frame);
849 if (GetFrameSubType(ptr) & BIT(6)) {
850 /* No data, will not indicate to upper layer, temporily count it here */
851 count_rx_stats(adapter, precv_frame, *psta);
852 ret = RTW_RX_HANDLED;
856 u8 *myhwaddr = myid(&adapter->eeprompriv);
858 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
859 ret = RTW_RX_HANDLED;
862 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
863 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
864 ret = RTW_RX_HANDLED;
873 static int validate_recv_ctrl_frame(struct adapter *padapter,
874 struct recv_frame *precv_frame)
876 #ifdef CONFIG_88EU_AP_MODE
877 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
878 struct sta_priv *pstapriv = &padapter->stapriv;
879 u8 *pframe = precv_frame->pkt->data;
881 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
884 /* receive the frames that ra(a1) is my address */
885 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN))
888 /* only handle ps-poll */
889 if (GetFrameSubType(pframe) == WIFI_PSPOLL) {
892 struct sta_info *psta = NULL;
894 aid = GetAid(pframe);
895 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
897 if ((psta == NULL) || (psta->aid != aid))
900 /* for rx pkt statistics */
901 psta->sta_stats.rx_ctrl_pkts++;
903 switch (pattrib->priority) {
906 wmmps_ac = psta->uapsd_bk&BIT(0);
910 wmmps_ac = psta->uapsd_vi&BIT(0);
914 wmmps_ac = psta->uapsd_vo&BIT(0);
919 wmmps_ac = psta->uapsd_be&BIT(0);
926 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
927 DBG_88E("%s alive check-rx ps-poll\n", __func__);
928 psta->expire_to = pstapriv->expire_to;
929 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
932 if ((psta->state&WIFI_SLEEP_STATE) && (pstapriv->sta_dz_bitmap&BIT(psta->aid))) {
933 struct list_head *xmitframe_plist, *xmitframe_phead;
934 struct xmit_frame *pxmitframe = NULL;
936 spin_lock_bh(&psta->sleep_q.lock);
938 xmitframe_phead = get_list_head(&psta->sleep_q);
939 xmitframe_plist = xmitframe_phead->next;
941 if (xmitframe_phead != xmitframe_plist) {
942 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
944 xmitframe_plist = xmitframe_plist->next;
946 list_del_init(&pxmitframe->list);
950 if (psta->sleepq_len > 0)
951 pxmitframe->attrib.mdata = 1;
953 pxmitframe->attrib.mdata = 0;
955 pxmitframe->attrib.triggered = 1;
957 spin_unlock_bh(&psta->sleep_q.lock);
958 if (rtw_hal_xmit(padapter, pxmitframe) == true)
959 rtw_os_xmit_complete(padapter, pxmitframe);
960 spin_lock_bh(&psta->sleep_q.lock);
962 if (psta->sleepq_len == 0) {
963 pstapriv->tim_bitmap &= ~BIT(psta->aid);
965 /* update BCN for TIM IE */
966 /* update_BCNTIM(padapter); */
967 update_beacon(padapter, _TIM_IE_, NULL, false);
970 if (pstapriv->tim_bitmap&BIT(psta->aid)) {
971 if (psta->sleepq_len == 0) {
972 DBG_88E("no buffered packets to xmit\n");
974 /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */
975 issue_nulldata(padapter, psta->hwaddr, 0, 0, 0);
977 DBG_88E("error!psta->sleepq_len=%d\n", psta->sleepq_len);
978 psta->sleepq_len = 0;
981 pstapriv->tim_bitmap &= ~BIT(psta->aid);
983 /* update BCN for TIM IE */
984 /* update_BCNTIM(padapter); */
985 update_beacon(padapter, _TIM_IE_, NULL, false);
989 spin_unlock_bh(&psta->sleep_q.lock);
998 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
999 struct recv_frame *precv_frame);
1001 static int validate_recv_mgnt_frame(struct adapter *padapter,
1002 struct recv_frame *precv_frame)
1004 struct sta_info *psta;
1006 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("+validate_recv_mgnt_frame\n"));
1008 precv_frame = recvframe_chk_defrag(padapter, precv_frame);
1009 if (precv_frame == NULL) {
1010 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("%s: fragment packet\n", __func__));
1014 /* for rx pkt statistics */
1015 psta = rtw_get_stainfo(&padapter->stapriv,
1016 GetAddr2Ptr(precv_frame->pkt->data));
1018 psta->sta_stats.rx_mgnt_pkts++;
1019 if (GetFrameSubType(precv_frame->pkt->data) == WIFI_BEACON) {
1020 psta->sta_stats.rx_beacon_pkts++;
1021 } else if (GetFrameSubType(precv_frame->pkt->data) == WIFI_PROBEREQ) {
1022 psta->sta_stats.rx_probereq_pkts++;
1023 } else if (GetFrameSubType(precv_frame->pkt->data) == WIFI_PROBERSP) {
1024 if (!memcmp(padapter->eeprompriv.mac_addr,
1025 GetAddr1Ptr(precv_frame->pkt->data), ETH_ALEN))
1026 psta->sta_stats.rx_probersp_pkts++;
1027 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->pkt->data)) ||
1028 is_multicast_mac_addr(GetAddr1Ptr(precv_frame->pkt->data)))
1029 psta->sta_stats.rx_probersp_bm_pkts++;
1031 psta->sta_stats.rx_probersp_uo_pkts++;
1035 mgt_dispatcher(padapter, precv_frame);
1040 static int validate_recv_data_frame(struct adapter *adapter,
1041 struct recv_frame *precv_frame)
1044 u8 *psa, *pda, *pbssid;
1045 struct sta_info *psta = NULL;
1046 u8 *ptr = precv_frame->pkt->data;
1047 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1048 struct security_priv *psecuritypriv = &adapter->securitypriv;
1051 bretry = GetRetry(ptr);
1054 pbssid = get_hdr_bssid(ptr);
1056 if (pbssid == NULL) {
1061 memcpy(pattrib->dst, pda, ETH_ALEN);
1062 memcpy(pattrib->src, psa, ETH_ALEN);
1064 memcpy(pattrib->bssid, pbssid, ETH_ALEN);
1066 switch (pattrib->to_fr_ds) {
1068 memcpy(pattrib->ra, pda, ETH_ALEN);
1069 memcpy(pattrib->ta, psa, ETH_ALEN);
1070 ret = sta2sta_data_frame(adapter, precv_frame, &psta);
1073 memcpy(pattrib->ra, pda, ETH_ALEN);
1074 memcpy(pattrib->ta, pbssid, ETH_ALEN);
1075 ret = ap2sta_data_frame(adapter, precv_frame, &psta);
1078 memcpy(pattrib->ra, pbssid, ETH_ALEN);
1079 memcpy(pattrib->ta, psa, ETH_ALEN);
1080 ret = sta2ap_data_frame(adapter, precv_frame, &psta);
1083 memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
1084 memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
1086 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" case 3\n"));
1095 else if (ret == RTW_RX_HANDLED)
1099 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" after to_fr_ds_chk; psta==NULL\n"));
1104 /* psta->rssi = prxcmd->rssi; */
1105 /* psta->signal_quality = prxcmd->sq; */
1106 precv_frame->psta = psta;
1109 pattrib->ack_policy = 0;
1110 /* parsing QC field */
1111 if (pattrib->qos == 1) {
1112 pattrib->priority = GetPriority((ptr + 24));
1113 pattrib->ack_policy = GetAckpolicy((ptr + 24));
1114 pattrib->amsdu = GetAMsdu((ptr + 24));
1115 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26;
1117 if (pattrib->priority != 0 && pattrib->priority != 3)
1118 adapter->recvpriv.bIsAnyNonBEPkts = true;
1120 pattrib->priority = 0;
1121 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24;
1124 if (pattrib->order)/* HT-CTRL 11n */
1125 pattrib->hdrlen += 4;
1127 precv_frame->preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
1129 /* decache, drop duplicate recv packets */
1130 if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) {
1131 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decache : drop pkt\n"));
1136 if (pattrib->privacy) {
1137 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("validate_recv_data_frame:pattrib->privacy=%x\n", pattrib->privacy));
1138 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n ^^^^^^^^^^^IS_MCAST(pattrib->ra(0x%02x))=%d^^^^^^^^^^^^^^^6\n", pattrib->ra[0], IS_MCAST(pattrib->ra)));
1140 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra));
1142 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n pattrib->encrypt=%d\n", pattrib->encrypt));
1144 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
1146 pattrib->encrypt = 0;
1147 pattrib->iv_len = 0;
1148 pattrib->icv_len = 0;
1156 static int validate_recv_frame(struct adapter *adapter,
1157 struct recv_frame *precv_frame)
1159 /* shall check frame subtype, to / from ds, da, bssid */
1161 /* then call check if rx seq/frag. duplicated. */
1165 int retval = _SUCCESS;
1167 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1168 u8 *ptr = precv_frame->pkt->data;
1169 u8 ver = (unsigned char)(*ptr)&0x3;
1170 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1172 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
1173 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
1175 if (ch_set_idx >= 0)
1176 pmlmeext->channel_set[ch_set_idx].rx_count++;
1179 /* add version chk */
1181 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! (ver!=0)\n"));
1186 type = GetFrameType(ptr);
1187 subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */
1189 pattrib->to_fr_ds = get_tofr_ds(ptr);
1191 pattrib->frag_num = GetFragNum(ptr);
1192 pattrib->seq_num = GetSequence(ptr);
1194 pattrib->pw_save = GetPwrMgt(ptr);
1195 pattrib->mfrag = GetMFrag(ptr);
1196 pattrib->mdata = GetMData(ptr);
1197 pattrib->privacy = GetPrivacy(ptr);
1198 pattrib->order = GetOrder(ptr);
1200 /* Dump rx packets */
1201 rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
1202 if (bDumpRxPkt == 1) {/* dump all rx packets */
1203 if (_drv_err_ <= GlobalDebugLevel) {
1204 pr_info(DRIVER_PREFIX "#############################\n");
1205 print_hex_dump(KERN_INFO, DRIVER_PREFIX, DUMP_PREFIX_NONE,
1206 16, 1, ptr, 64, false);
1207 pr_info(DRIVER_PREFIX "#############################\n");
1209 } else if (bDumpRxPkt == 2) {
1210 if ((_drv_err_ <= GlobalDebugLevel) && (type == WIFI_MGT_TYPE)) {
1211 pr_info(DRIVER_PREFIX "#############################\n");
1212 print_hex_dump(KERN_INFO, DRIVER_PREFIX, DUMP_PREFIX_NONE,
1213 16, 1, ptr, 64, false);
1214 pr_info(DRIVER_PREFIX "#############################\n");
1216 } else if (bDumpRxPkt == 3) {
1217 if ((_drv_err_ <= GlobalDebugLevel) && (type == WIFI_DATA_TYPE)) {
1218 pr_info(DRIVER_PREFIX "#############################\n");
1219 print_hex_dump(KERN_INFO, DRIVER_PREFIX, DUMP_PREFIX_NONE,
1220 16, 1, ptr, 64, false);
1221 pr_info(DRIVER_PREFIX "#############################\n");
1225 case WIFI_MGT_TYPE: /* mgnt */
1226 retval = validate_recv_mgnt_frame(adapter, precv_frame);
1227 if (retval == _FAIL)
1228 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_mgnt_frame fail\n"));
1229 retval = _FAIL; /* only data frame return _SUCCESS */
1231 case WIFI_CTRL_TYPE: /* ctrl */
1232 retval = validate_recv_ctrl_frame(adapter, precv_frame);
1233 if (retval == _FAIL)
1234 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_ctrl_frame fail\n"));
1235 retval = _FAIL; /* only data frame return _SUCCESS */
1237 case WIFI_DATA_TYPE: /* data */
1238 LedControl8188eu(adapter, LED_CTL_RX);
1239 pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
1240 retval = validate_recv_data_frame(adapter, precv_frame);
1241 if (retval == _FAIL) {
1242 struct recv_priv *precvpriv = &adapter->recvpriv;
1244 precvpriv->rx_drop++;
1248 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! type= 0x%x\n", type));
1254 * This is the last moment before management and control frames get
1255 * discarded. So we need to forward them to the monitor now or never.
1257 * At the same time data frames can still be encrypted if software
1258 * decryption is in use. However, decryption can occur not until later
1259 * (see recv_func()).
1261 * Hence forward the frame to the monitor anyway to preserve the order
1262 * in which frames were received.
1264 rtl88eu_mon_recv_hook(adapter->pmondev, precv_frame);
1271 /* remove the wlanhdr and add the eth_hdr */
1273 static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1280 struct ieee80211_snap_hdr *psnap;
1282 u8 *ptr = precvframe->pkt->data;
1283 struct rx_pkt_attrib *pattrib = &precvframe->attrib;
1285 if (pattrib->encrypt)
1286 skb_trim(precvframe->pkt, precvframe->pkt->len - pattrib->icv_len);
1288 psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
1289 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
1290 /* convert hdr + possible LLC headers into Ethernet header */
1291 if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
1292 (!memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) == false) &&
1293 (!memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2) == false)) ||
1294 !memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) {
1295 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1298 /* Leave Ethernet header part of hdr and full payload */
1302 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0);
1303 len = precvframe->pkt->len - rmv_len;
1305 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
1306 ("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x===\n\n", pattrib->hdrlen, pattrib->iv_len));
1308 memcpy(&be_tmp, ptr+rmv_len, 2);
1309 eth_type = ntohs(be_tmp); /* pattrib->ether_type */
1310 pattrib->eth_type = eth_type;
1312 ptr = skb_pull(precvframe->pkt, rmv_len - sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0));
1316 memcpy(ptr, pattrib->dst, ETH_ALEN);
1317 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
1320 be_tmp = htons(len);
1321 memcpy(ptr+12, &be_tmp, 2);
1327 /* perform defrag */
1328 static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1329 struct __queue *defrag_q)
1331 struct list_head *plist, *phead;
1334 struct recv_frame *pfhdr, *pnfhdr;
1335 struct recv_frame *prframe, *pnextrframe;
1336 struct __queue *pfree_recv_queue;
1339 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
1341 phead = get_list_head(defrag_q);
1342 plist = phead->next;
1343 pfhdr = container_of(plist, struct recv_frame, list);
1345 list_del_init(&(prframe->list));
1347 if (curfragnum != pfhdr->attrib.frag_num) {
1348 /* the first fragment number must be 0 */
1349 /* free the whole queue */
1350 rtw_free_recvframe(prframe, pfree_recv_queue);
1351 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1358 plist = get_list_head(defrag_q);
1360 plist = plist->next;
1362 while (phead != plist) {
1363 pnfhdr = container_of(plist, struct recv_frame, list);
1364 pnextrframe = pnfhdr;
1366 /* check the fragment sequence (2nd ~n fragment frame) */
1368 if (curfragnum != pnfhdr->attrib.frag_num) {
1369 /* the fragment number must be increasing (after decache) */
1370 /* release the defrag_q & prframe */
1371 rtw_free_recvframe(prframe, pfree_recv_queue);
1372 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1378 /* copy the 2nd~n fragment frame's payload to the first fragment */
1379 /* get the 2nd~last fragment frame's payload */
1381 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1383 skb_pull(pnextrframe->pkt, wlanhdr_offset);
1385 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1386 skb_trim(prframe->pkt, prframe->pkt->len - pfhdr->attrib.icv_len);
1389 memcpy(skb_tail_pointer(pfhdr->pkt), pnfhdr->pkt->data,
1392 skb_put(prframe->pkt, pnfhdr->pkt->len);
1394 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
1395 plist = plist->next;
1398 /* free the defrag_q queue and return the prframe */
1399 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1401 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Performance defrag!!!!!\n"));
1406 /* check if need to defrag, if needed queue the frame to defrag_q */
1407 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1408 struct recv_frame *precv_frame)
1413 struct recv_frame *pfhdr;
1414 struct sta_info *psta;
1415 struct sta_priv *pstapriv;
1416 struct list_head *phead;
1417 struct recv_frame *prtnframe = NULL;
1418 struct __queue *pfree_recv_queue, *pdefrag_q;
1420 pstapriv = &padapter->stapriv;
1422 pfhdr = precv_frame;
1424 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1426 /* need to define struct of wlan header frame ctrl */
1427 ismfrag = pfhdr->attrib.mfrag;
1428 fragnum = pfhdr->attrib.frag_num;
1430 psta_addr = pfhdr->attrib.ta;
1431 psta = rtw_get_stainfo(pstapriv, psta_addr);
1433 u8 type = GetFrameType(pfhdr->pkt->data);
1435 if (type != WIFI_DATA_TYPE) {
1436 psta = rtw_get_bcmc_stainfo(padapter);
1437 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1442 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1445 if ((ismfrag == 0) && (fragnum == 0))
1446 prtnframe = precv_frame;/* isn't a fragment frame */
1449 /* 0~(n-1) fragment frame */
1450 /* enqueue to defraf_g */
1451 if (pdefrag_q != NULL) {
1453 /* the first fragment */
1454 if (!list_empty(&pdefrag_q->queue))
1455 /* free current defrag_q */
1456 rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
1459 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1461 phead = get_list_head(pdefrag_q);
1462 list_add_tail(&pfhdr->list, phead);
1464 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Enqueuq: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1468 /* can't find this ta's defrag_queue, so free this recv_frame */
1469 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1471 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1475 if ((ismfrag == 0) && (fragnum != 0)) {
1476 /* the last fragment frame */
1477 /* enqueue the last fragment */
1478 if (pdefrag_q != NULL) {
1479 phead = get_list_head(pdefrag_q);
1480 list_add_tail(&pfhdr->list, phead);
1482 /* call recvframe_defrag to defrag */
1483 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("defrag: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1484 precv_frame = recvframe_defrag(padapter, pdefrag_q);
1485 prtnframe = precv_frame;
1487 /* can't find this ta's defrag_queue, so free this recv_frame */
1488 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1490 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1494 if ((prtnframe != NULL) && (prtnframe->attrib.privacy)) {
1495 /* after defrag we must check tkip mic code */
1496 if (recvframe_chkmic(padapter, prtnframe) == _FAIL) {
1497 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic(padapter, prtnframe)==_FAIL\n"));
1498 rtw_free_recvframe(prtnframe, pfree_recv_queue);
1506 static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1508 int a_len, padding_len;
1509 u16 eth_type, nSubframe_Length;
1511 unsigned char *pdata;
1512 struct rx_pkt_attrib *pattrib;
1513 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1514 struct recv_priv *precvpriv = &padapter->recvpriv;
1515 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1518 pattrib = &prframe->attrib;
1520 skb_pull(prframe->pkt, prframe->attrib.hdrlen);
1522 if (prframe->attrib.iv_len > 0)
1523 skb_pull(prframe->pkt, prframe->attrib.iv_len);
1525 a_len = prframe->pkt->len;
1527 pdata = prframe->pkt->data;
1529 while (a_len > ETH_HLEN) {
1530 /* Offset 12 denote 2 mac address */
1531 nSubframe_Length = get_unaligned_be16(pdata + 12);
1533 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
1534 DBG_88E("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len, nSubframe_Length);
1538 /* move the data point to data content */
1542 /* Allocate new skb for releasing to upper layer */
1543 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1545 DBG_88E("dev_alloc_skb() Fail!!! , nr_subframes=%d\n", nr_subframes);
1549 skb_reserve(sub_skb, 12);
1550 skb_put_data(sub_skb, pdata, nSubframe_Length);
1552 subframes[nr_subframes++] = sub_skb;
1554 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
1555 DBG_88E("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1559 pdata += nSubframe_Length;
1560 a_len -= nSubframe_Length;
1562 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4-1));
1563 if (padding_len == 4)
1566 if (a_len < padding_len)
1569 pdata += padding_len;
1570 a_len -= padding_len;
1574 for (i = 0; i < nr_subframes; i++) {
1575 sub_skb = subframes[i];
1576 /* convert hdr + possible LLC headers into Ethernet header */
1577 eth_type = get_unaligned_be16(&sub_skb->data[6]);
1578 if (sub_skb->len >= 8 &&
1579 ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
1580 eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
1581 !memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
1582 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1583 skb_pull(sub_skb, SNAP_SIZE);
1584 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1585 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1588 /* Leave Ethernet header part of hdr and full payload */
1589 len = htons(sub_skb->len);
1590 memcpy(skb_push(sub_skb, 2), &len, 2);
1591 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1592 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1595 /* Indicate the packets to upper layer */
1596 /* Insert NAT2.5 RX here! */
1597 sub_skb->protocol = eth_type_trans(sub_skb, padapter->pnetdev);
1598 sub_skb->dev = padapter->pnetdev;
1600 sub_skb->ip_summed = CHECKSUM_NONE;
1606 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1611 static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
1613 u8 wsize = preorder_ctrl->wsize_b;
1614 u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF;/* 4096; */
1616 /* Rx Reorder initialize condition. */
1617 if (preorder_ctrl->indicate_seq == 0xFFFF)
1618 preorder_ctrl->indicate_seq = seq_num;
1620 /* Drop out the packet which SeqNum is smaller than WinStart */
1621 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
1625 /* Sliding window manipulation. Conditions includes: */
1626 /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */
1627 /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */
1629 if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) {
1630 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1631 } else if (SN_LESS(wend, seq_num)) {
1632 if (seq_num >= (wsize - 1))
1633 preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
1635 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
1641 static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
1642 struct recv_frame *prframe)
1644 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1645 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1646 struct list_head *phead, *plist;
1647 struct recv_frame *hdr;
1648 struct rx_pkt_attrib *pnextattrib;
1650 phead = get_list_head(ppending_recvframe_queue);
1651 plist = phead->next;
1653 while (phead != plist) {
1654 hdr = container_of(plist, struct recv_frame, list);
1655 pnextattrib = &hdr->attrib;
1657 if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
1658 plist = plist->next;
1659 else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
1665 list_del_init(&(prframe->list));
1667 list_add_tail(&(prframe->list), plist);
1671 static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
1673 struct list_head *phead, *plist;
1674 struct recv_frame *prframe;
1675 struct recv_frame *prhdr;
1676 struct rx_pkt_attrib *pattrib;
1677 int bPktInBuf = false;
1678 struct recv_priv *precvpriv = &padapter->recvpriv;
1679 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1681 phead = get_list_head(ppending_recvframe_queue);
1682 plist = phead->next;
1684 /* Handling some condition for forced indicate case. */
1686 if (list_empty(phead))
1689 prhdr = container_of(plist, struct recv_frame, list);
1690 pattrib = &prhdr->attrib;
1691 preorder_ctrl->indicate_seq = pattrib->seq_num;
1694 /* Prepare indication list and indication. */
1695 /* Check if there is any packet need indicate. */
1696 while (!list_empty(phead)) {
1697 prhdr = container_of(plist, struct recv_frame, list);
1699 pattrib = &prframe->attrib;
1701 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
1702 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1703 ("recv_indicatepkts_in_order: indicate=%d seq=%d amsdu=%d\n",
1704 preorder_ctrl->indicate_seq, pattrib->seq_num, pattrib->amsdu));
1705 plist = plist->next;
1706 list_del_init(&(prframe->list));
1708 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
1709 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1711 /* Set this as a lock to make sure that only one thread is indicating packet. */
1713 /* indicate this recv_frame */
1714 if (!pattrib->amsdu) {
1715 if ((!padapter->bDriverStopped) &&
1716 (!padapter->bSurpriseRemoved))
1717 rtw_recv_indicatepkt(padapter, prframe);/* indicate this recv_frame */
1718 } else if (pattrib->amsdu == 1) {
1719 if (amsdu_to_msdu(padapter, prframe) != _SUCCESS)
1720 rtw_free_recvframe(prframe, &precvpriv->free_recv_queue);
1722 /* error condition; */
1725 /* Update local variables. */
1735 static int recv_indicatepkt_reorder(struct adapter *padapter,
1736 struct recv_frame *prframe)
1738 int retval = _SUCCESS;
1739 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1740 struct recv_reorder_ctrl *preorder_ctrl = prframe->preorder_ctrl;
1741 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1743 if (!pattrib->amsdu) {
1745 wlanhdr_to_ethhdr(prframe);
1747 if ((pattrib->qos != 1) || (pattrib->eth_type == 0x0806) ||
1748 (pattrib->ack_policy != 0)) {
1749 if ((!padapter->bDriverStopped) &&
1750 (!padapter->bSurpriseRemoved)) {
1751 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ recv_indicatepkt_reorder -recv_func recv_indicatepkt\n"));
1753 rtw_recv_indicatepkt(padapter, prframe);
1760 if (!preorder_ctrl->enable) {
1761 /* indicate this recv_frame */
1762 preorder_ctrl->indicate_seq = pattrib->seq_num;
1763 rtw_recv_indicatepkt(padapter, prframe);
1765 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1768 } else if (pattrib->amsdu == 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */
1769 if (!preorder_ctrl->enable) {
1770 preorder_ctrl->indicate_seq = pattrib->seq_num;
1771 retval = amsdu_to_msdu(padapter, prframe);
1773 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1778 spin_lock_bh(&ppending_recvframe_queue->lock);
1780 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1781 ("recv_indicatepkt_reorder: indicate=%d seq=%d\n",
1782 preorder_ctrl->indicate_seq, pattrib->seq_num));
1784 /* s2. check if winstart_b(indicate_seq) needs to been updated */
1785 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) {
1786 rtw_recv_indicatepkt(padapter, prframe);
1788 spin_unlock_bh(&ppending_recvframe_queue->lock);
1793 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1794 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
1798 /* Indication process. */
1799 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
1800 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
1802 /* For Rx Reorder condition: */
1803 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
1804 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
1807 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */
1808 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
1809 mod_timer(&preorder_ctrl->reordering_ctrl_timer,
1810 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
1811 spin_unlock_bh(&ppending_recvframe_queue->lock);
1813 spin_unlock_bh(&ppending_recvframe_queue->lock);
1814 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
1823 spin_unlock_bh(&ppending_recvframe_queue->lock);
1828 void rtw_reordering_ctrl_timeout_handler(unsigned long data)
1830 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)data;
1831 struct adapter *padapter = preorder_ctrl->padapter;
1832 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1834 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
1837 spin_lock_bh(&ppending_recvframe_queue->lock);
1839 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, true) == true)
1840 mod_timer(&preorder_ctrl->reordering_ctrl_timer,
1841 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
1843 spin_unlock_bh(&ppending_recvframe_queue->lock);
1846 static int process_recv_indicatepkts(struct adapter *padapter,
1847 struct recv_frame *prframe)
1849 int retval = _SUCCESS;
1850 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1851 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
1853 if (phtpriv->ht_option) { /* B/G/N Mode */
1854 if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) {
1855 /* including perform A-MPDU Rx Ordering Buffer Control */
1856 if ((!padapter->bDriverStopped) &&
1857 (!padapter->bSurpriseRemoved)) {
1862 } else { /* B/G mode */
1863 retval = wlanhdr_to_ethhdr(prframe);
1864 if (retval != _SUCCESS) {
1865 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("wlanhdr_to_ethhdr: drop pkt\n"));
1869 if ((!padapter->bDriverStopped) &&
1870 (!padapter->bSurpriseRemoved)) {
1871 /* indicate this recv_frame */
1872 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func recv_indicatepkt\n"));
1873 rtw_recv_indicatepkt(padapter, prframe);
1875 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func free_indicatepkt\n"));
1877 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
1886 static int recv_func_prehandle(struct adapter *padapter,
1887 struct recv_frame *rframe)
1890 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1892 /* check the frame crtl field and decache */
1893 ret = validate_recv_frame(padapter, rframe);
1894 if (ret != _SUCCESS) {
1895 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recv_func: validate_recv_frame fail! drop pkt\n"));
1896 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
1904 static int recv_func_posthandle(struct adapter *padapter,
1905 struct recv_frame *prframe)
1908 struct recv_frame *orig_prframe = prframe;
1909 struct recv_priv *precvpriv = &padapter->recvpriv;
1910 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1913 LedControl8188eu(padapter, LED_CTL_RX);
1915 prframe = decryptor(padapter, prframe);
1916 if (prframe == NULL) {
1917 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decryptor: drop pkt\n"));
1919 goto _recv_data_drop;
1922 prframe = recvframe_chk_defrag(padapter, prframe);
1923 if (prframe == NULL) {
1924 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chk_defrag: drop pkt\n"));
1925 goto _recv_data_drop;
1928 prframe = portctrl(padapter, prframe);
1929 if (prframe == NULL) {
1930 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("portctrl: drop pkt\n"));
1932 goto _recv_data_drop;
1935 count_rx_stats(padapter, prframe, NULL);
1937 ret = process_recv_indicatepkts(padapter, prframe);
1938 if (ret != _SUCCESS) {
1939 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recv_func: process_recv_indicatepkts fail!\n"));
1940 rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */
1941 goto _recv_data_drop;
1946 precvpriv->rx_drop++;
1950 static int recv_func(struct adapter *padapter, struct recv_frame *rframe)
1953 struct rx_pkt_attrib *prxattrib = &rframe->attrib;
1954 struct security_priv *psecuritypriv = &padapter->securitypriv;
1955 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
1957 /* check if need to handle uc_swdec_pending_queue*/
1958 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey) {
1959 struct recv_frame *pending_frame;
1961 while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) {
1962 if (recv_func_posthandle(padapter, pending_frame) == _SUCCESS)
1963 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
1967 ret = recv_func_prehandle(padapter, rframe);
1969 if (ret == _SUCCESS) {
1970 /* check if need to enqueue into uc_swdec_pending_queue*/
1971 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
1972 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 &&
1973 prxattrib->bdecrypted == 0 &&
1974 !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) &&
1975 !psecuritypriv->busetkipkey) {
1976 rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
1977 DBG_88E("%s: no key, enqueue uc_swdec_pending_queue\n", __func__);
1981 ret = recv_func_posthandle(padapter, rframe);
1988 s32 rtw_recv_entry(struct recv_frame *precvframe)
1990 struct adapter *padapter;
1991 struct recv_priv *precvpriv;
1994 padapter = precvframe->adapter;
1996 precvpriv = &padapter->recvpriv;
1998 ret = recv_func(padapter, precvframe);
2000 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("rtw_recv_entry: recv_func return fail!!!\n"));
2001 goto _recv_entry_drop;
2004 precvpriv->rx_pkts++;
2012 static void rtw_signal_stat_timer_hdl(unsigned long data)
2014 struct adapter *adapter = (struct adapter *)data;
2015 struct recv_priv *recvpriv = &adapter->recvpriv;
2018 u8 avg_signal_strength = 0;
2019 u8 avg_signal_qual = 0;
2020 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2022 if (recvpriv->signal_strength_data.update_req == 0) {
2023 /* update_req is clear, means we got rx */
2024 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2025 /* after avg_vals are acquired, we can re-stat the signal
2028 recvpriv->signal_strength_data.update_req = 1;
2031 if (recvpriv->signal_qual_data.update_req == 0) {
2032 /* update_req is clear, means we got rx */
2033 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2034 /* after avg_vals are acquired, we can re-stat the signal
2037 recvpriv->signal_qual_data.update_req = 1;
2040 /* update value of signal_strength, rssi, signal_qual */
2041 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) {
2042 tmp_s = avg_signal_strength +
2043 (_alpha - 1) * recvpriv->signal_strength;
2044 tmp_s = DIV_ROUND_UP(tmp_s, _alpha);
2048 tmp_q = avg_signal_qual +
2049 (_alpha - 1) * recvpriv->signal_qual;
2050 tmp_q = DIV_ROUND_UP(tmp_q, _alpha);
2054 recvpriv->signal_strength = tmp_s;
2055 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2056 recvpriv->signal_qual = tmp_q;
2059 rtw_set_signal_stat_timer(recvpriv);