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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 #include <linux/ieee80211.h>
24 #include <osdep_service.h>
25 #include <drv_types.h>
26 #include <recv_osdep.h>
27 #include <mlme_osdep.h>
30 #include <linux/vmalloc.h>
32 #define ETHERNET_HEADER_SIZE 14 /* Ethernet Header Length */
33 #define LLC_HEADER_SIZE 6 /* LLC Header Length */
35 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
36 static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
38 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
39 static u8 rtw_bridge_tunnel_header[] = {
40 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
43 static u8 rtw_rfc1042_header[] = {
44 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
47 void rtw_signal_stat_timer_hdl(unsigned long data);
49 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
52 memset((u8 *)psta_recvpriv, 0, sizeof(struct sta_recv_priv));
54 spin_lock_init(&psta_recvpriv->lock);
56 _rtw_init_queue(&psta_recvpriv->defrag_q);
60 int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
64 struct recv_frame *precvframe;
68 _rtw_init_queue(&precvpriv->free_recv_queue);
69 _rtw_init_queue(&precvpriv->recv_pending_queue);
70 _rtw_init_queue(&precvpriv->uc_swdec_pending_queue);
72 precvpriv->adapter = padapter;
74 precvpriv->free_recvframe_cnt = NR_RECVFRAME;
76 precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(struct recv_frame) + RXFRAME_ALIGN_SZ);
78 if (!precvpriv->pallocated_frame_buf)
81 precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
83 precvframe = (struct recv_frame *)precvpriv->precv_frame_buf;
85 for (i = 0; i < NR_RECVFRAME; i++) {
86 INIT_LIST_HEAD(&(precvframe->list));
88 list_add_tail(&(precvframe->list),
89 &(precvpriv->free_recv_queue.queue));
91 rtw_os_recv_resource_alloc(precvframe);
95 precvframe->adapter = padapter;
98 precvpriv->rx_pending_cnt = 1;
100 res = rtw_hal_init_recv_priv(padapter);
102 setup_timer(&precvpriv->signal_stat_timer,
103 rtw_signal_stat_timer_hdl,
104 (unsigned long)padapter);
106 precvpriv->signal_stat_sampling_interval = 1000; /* ms */
108 rtw_set_signal_stat_timer(precvpriv);
113 void _rtw_free_recv_priv(struct recv_priv *precvpriv)
115 struct adapter *padapter = precvpriv->adapter;
117 rtw_free_uc_swdec_pending_queue(padapter);
119 if (precvpriv->pallocated_frame_buf) {
120 vfree(precvpriv->pallocated_frame_buf);
123 rtw_hal_free_recv_priv(padapter);
127 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
129 struct recv_frame *hdr;
130 struct list_head *plist, *phead;
131 struct adapter *padapter;
132 struct recv_priv *precvpriv;
134 if (list_empty(&pfree_recv_queue->queue)) {
137 phead = get_list_head(pfree_recv_queue);
141 hdr = container_of(plist, struct recv_frame, list);
143 list_del_init(&hdr->list);
144 padapter = hdr->adapter;
145 if (padapter != NULL) {
146 precvpriv = &padapter->recvpriv;
147 if (pfree_recv_queue == &precvpriv->free_recv_queue)
148 precvpriv->free_recvframe_cnt--;
152 return (struct recv_frame *)hdr;
155 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
157 struct recv_frame *precvframe;
159 spin_lock_bh(&pfree_recv_queue->lock);
161 precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
163 spin_unlock_bh(&pfree_recv_queue->lock);
168 int rtw_free_recvframe(struct recv_frame *precvframe,
169 struct __queue *pfree_recv_queue)
171 struct adapter *padapter;
172 struct recv_priv *precvpriv;
176 padapter = precvframe->adapter;
177 precvpriv = &padapter->recvpriv;
178 if (precvframe->pkt) {
179 dev_kfree_skb_any(precvframe->pkt);/* free skb by driver */
180 precvframe->pkt = NULL;
183 spin_lock_bh(&pfree_recv_queue->lock);
185 list_del_init(&(precvframe->list));
189 list_add_tail(&(precvframe->list), get_list_head(pfree_recv_queue));
191 if (padapter != NULL) {
192 if (pfree_recv_queue == &precvpriv->free_recv_queue)
193 precvpriv->free_recvframe_cnt++;
196 spin_unlock_bh(&pfree_recv_queue->lock);
201 int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
203 struct adapter *padapter = precvframe->adapter;
204 struct recv_priv *precvpriv = &padapter->recvpriv;
206 list_del_init(&(precvframe->list));
207 list_add_tail(&(precvframe->list), get_list_head(queue));
209 if (padapter != NULL) {
210 if (queue == &precvpriv->free_recv_queue)
211 precvpriv->free_recvframe_cnt++;
217 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
221 spin_lock_bh(&queue->lock);
222 ret = _rtw_enqueue_recvframe(precvframe, queue);
223 spin_unlock_bh(&queue->lock);
229 caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
230 pframequeue: defrag_queue : will be accessed in recv_thread (passive)
232 using spinlock to protect
236 void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue)
238 struct recv_frame *hdr;
239 struct list_head *plist, *phead;
241 spin_lock(&pframequeue->lock);
243 phead = get_list_head(pframequeue);
246 while (phead != plist) {
247 hdr = container_of(plist, struct recv_frame, list);
251 rtw_free_recvframe((struct recv_frame *)hdr, pfree_recv_queue);
254 spin_unlock(&pframequeue->lock);
258 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter)
261 struct recv_frame *pending_frame;
262 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
263 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
264 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
271 static int recvframe_chkmic(struct adapter *adapter,
272 struct recv_frame *precvframe)
274 int i, res = _SUCCESS;
277 u8 bmic_err = false, brpt_micerror = true;
278 u8 *pframe, *payload, *pframemic;
280 struct sta_info *stainfo;
281 struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
282 struct security_priv *psecuritypriv = &adapter->securitypriv;
284 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
285 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
287 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
289 if (prxattrib->encrypt == _TKIP_) {
290 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic:prxattrib->encrypt==_TKIP_\n"));
291 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",
292 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2], prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5]));
294 /* calculate mic code */
295 if (stainfo != NULL) {
296 if (IS_MCAST(prxattrib->ra)) {
297 if (!psecuritypriv) {
299 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n"));
300 DBG_88E("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
303 mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
305 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic: bcmc key\n"));
307 mickey = &stainfo->dot11tkiprxmickey.skey[0];
308 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic: unicast key\n"));
311 /* icv_len included the mic code */
312 datalen = precvframe->len-prxattrib->hdrlen -
313 prxattrib->iv_len-prxattrib->icv_len-8;
314 pframe = precvframe->rx_data;
315 payload = pframe+prxattrib->hdrlen+prxattrib->iv_len;
317 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n", prxattrib->iv_len, prxattrib->icv_len));
318 rtw_seccalctkipmic(mickey, pframe, payload, datalen, &miccode[0],
319 (unsigned char)prxattrib->priority); /* care the length of the data */
321 pframemic = payload+datalen;
325 for (i = 0; i < 8; i++) {
326 if (miccode[i] != *(pframemic+i)) {
327 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
328 ("recvframe_chkmic:miccode[%d](%02x)!=*(pframemic+%d)(%02x) ",
329 i, miccode[i], i, *(pframemic+i)));
335 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
336 ("\n *(pframemic-8)-*(pframemic-1)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
337 *(pframemic-8), *(pframemic-7), *(pframemic-6),
338 *(pframemic-5), *(pframemic-4), *(pframemic-3),
339 *(pframemic-2), *(pframemic-1)));
340 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
341 ("\n *(pframemic-16)-*(pframemic-9)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
342 *(pframemic-16), *(pframemic-15), *(pframemic-14),
343 *(pframemic-13), *(pframemic-12), *(pframemic-11),
344 *(pframemic-10), *(pframemic-9)));
347 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
348 ("\n ======demp packet (len=%d)======\n",
350 for (i = 0; i < precvframe->len; i += 8) {
351 RT_TRACE(_module_rtl871x_recv_c_,
353 ("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
354 *(precvframe->rx_data+i),
355 *(precvframe->rx_data+i+1),
356 *(precvframe->rx_data+i+2),
357 *(precvframe->rx_data+i+3),
358 *(precvframe->rx_data+i+4),
359 *(precvframe->rx_data+i+5),
360 *(precvframe->rx_data+i+6),
361 *(precvframe->rx_data+i+7)));
363 RT_TRACE(_module_rtl871x_recv_c_,
365 ("\n ====== demp packet end [len=%d]======\n",
367 RT_TRACE(_module_rtl871x_recv_c_,
373 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
374 ("ra=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x psecuritypriv->binstallGrpkey=%d ",
375 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2],
376 prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5], psecuritypriv->binstallGrpkey));
378 /* double check key_index for some timing issue , */
379 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
380 if ((IS_MCAST(prxattrib->ra) == true) && (prxattrib->key_index != pmlmeinfo->key_index))
381 brpt_micerror = false;
383 if ((prxattrib->bdecrypted) && (brpt_micerror)) {
384 rtw_handle_tkip_mic_err(adapter, (u8)IS_MCAST(prxattrib->ra));
385 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
386 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
388 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
389 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
394 if ((!psecuritypriv->bcheck_grpkey) && (IS_MCAST(prxattrib->ra))) {
395 psecuritypriv->bcheck_grpkey = true;
396 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("psecuritypriv->bcheck_grpkey = true"));
400 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
403 recvframe_pull_tail(precvframe, 8);
411 /* decrypt and set the ivlen, icvlen of the recv_frame */
412 static struct recv_frame *decryptor(struct adapter *padapter,
413 struct recv_frame *precv_frame)
415 struct rx_pkt_attrib *prxattrib = &precv_frame->attrib;
416 struct security_priv *psecuritypriv = &padapter->securitypriv;
417 struct recv_frame *return_packet = precv_frame;
420 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("prxstat->decrypted=%x prxattrib->encrypt=0x%03x\n", prxattrib->bdecrypted, prxattrib->encrypt));
422 if (prxattrib->encrypt > 0) {
423 u8 *iv = precv_frame->rx_data+prxattrib->hdrlen;
424 prxattrib->key_index = (((iv[3])>>6)&0x3);
426 if (prxattrib->key_index > WEP_KEYS) {
427 DBG_88E("prxattrib->key_index(%d)>WEP_KEYS\n", prxattrib->key_index);
429 switch (prxattrib->encrypt) {
432 prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
437 prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
443 if ((prxattrib->encrypt > 0) && ((prxattrib->bdecrypted == 0) || (psecuritypriv->sw_decrypt))) {
444 psecuritypriv->hw_decrypted = false;
446 switch (prxattrib->encrypt) {
449 rtw_wep_decrypt(padapter, (u8 *)precv_frame);
452 res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
455 res = rtw_aes_decrypt(padapter, (u8 *)precv_frame);
460 } else if (prxattrib->bdecrypted == 1 && prxattrib->encrypt > 0 &&
461 (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_))
462 psecuritypriv->hw_decrypted = true;
465 rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue);
466 return_packet = NULL;
469 return return_packet;
472 /* set the security information in the recv_frame */
473 static struct recv_frame *portctrl(struct adapter *adapter,
474 struct recv_frame *precv_frame)
478 struct recv_frame *pfhdr;
479 struct sta_info *psta;
480 struct sta_priv *pstapriv;
481 struct recv_frame *prtnframe;
483 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */
484 struct rx_pkt_attrib *pattrib;
487 pstapriv = &adapter->stapriv;
489 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
491 ptr = precv_frame->rx_data;
493 pattrib = &pfhdr->attrib;
494 psta_addr = pattrib->ta;
495 psta = rtw_get_stainfo(pstapriv, psta_addr);
499 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n", adapter->securitypriv.dot11AuthAlgrthm));
503 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE;
504 memcpy(&be_tmp, ptr, 2);
505 ether_type = ntohs(be_tmp);
507 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
509 /* only accept EAPOL frame */
510 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==1\n"));
512 if (ether_type == eapol_type) {
513 prtnframe = precv_frame;
515 /* free this frame */
516 rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
521 /* check decryption status, and decrypt the frame if needed */
522 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==0\n"));
523 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
524 ("portctrl:precv_frame->hdr.attrib.privacy=%x\n",
525 precv_frame->attrib.privacy));
527 if (pattrib->bdecrypted == 0)
528 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("portctrl:prxstat->decrypted=%x\n", pattrib->bdecrypted));
530 prtnframe = precv_frame;
531 /* check is the EAPOL frame or not (Rekey) */
532 if (ether_type == eapol_type) {
533 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("########portctrl:ether_type==0x888e\n"));
536 prtnframe = precv_frame;
538 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:ether_type=0x%04x\n", ether_type));
542 prtnframe = precv_frame;
548 static int recv_decache(struct recv_frame *precv_frame, u8 bretry,
549 struct stainfo_rxcache *prxcache)
551 int tid = precv_frame->attrib.priority;
553 u16 seq_ctrl = ((precv_frame->attrib.seq_num&0xffff) << 4) |
554 (precv_frame->attrib.frag_num & 0xf);
557 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid));
562 if (1) {/* if (bretry) */
563 if (seq_ctrl == prxcache->tid_rxseq[tid]) {
564 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]));
570 prxcache->tid_rxseq[tid] = seq_ctrl;
575 static void process_pwrbit_data(struct adapter *padapter,
576 struct recv_frame *precv_frame)
578 #ifdef CONFIG_88EU_AP_MODE
579 unsigned char pwrbit;
580 u8 *ptr = precv_frame->rx_data;
581 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
582 struct sta_priv *pstapriv = &padapter->stapriv;
583 struct sta_info *psta = NULL;
585 psta = rtw_get_stainfo(pstapriv, pattrib->src);
587 pwrbit = GetPwrMgt(ptr);
591 if (!(psta->state & WIFI_SLEEP_STATE))
592 stop_sta_xmit(padapter, psta);
594 if (psta->state & WIFI_SLEEP_STATE)
595 wakeup_sta_to_xmit(padapter, psta);
602 static void process_wmmps_data(struct adapter *padapter,
603 struct recv_frame *precv_frame)
605 #ifdef CONFIG_88EU_AP_MODE
606 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
607 struct sta_priv *pstapriv = &padapter->stapriv;
608 struct sta_info *psta = NULL;
610 psta = rtw_get_stainfo(pstapriv, pattrib->src);
615 if (!psta->qos_option)
618 if (!(psta->qos_info&0xf))
621 if (psta->state&WIFI_SLEEP_STATE) {
624 switch (pattrib->priority) {
627 wmmps_ac = psta->uapsd_bk&BIT(1);
631 wmmps_ac = psta->uapsd_vi&BIT(1);
635 wmmps_ac = psta->uapsd_vo&BIT(1);
640 wmmps_ac = psta->uapsd_be&BIT(1);
645 if (psta->sleepq_ac_len > 0) {
646 /* process received triggered frame */
647 xmit_delivery_enabled_frames(padapter, psta);
649 /* issue one qos null frame with More data bit = 0 and the EOSP bit set (= 1) */
650 issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0);
658 static void count_rx_stats(struct adapter *padapter,
659 struct recv_frame *prframe,
660 struct sta_info *sta)
663 struct sta_info *psta = NULL;
664 struct stainfo_stats *pstats = NULL;
665 struct rx_pkt_attrib *pattrib = &prframe->attrib;
666 struct recv_priv *precvpriv = &padapter->recvpriv;
669 precvpriv->rx_bytes += sz;
671 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
673 if ((!MacAddr_isBcst(pattrib->dst)) && (!IS_MCAST(pattrib->dst)))
674 padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
679 psta = prframe->psta;
682 pstats = &psta->sta_stats;
684 pstats->rx_data_pkts++;
685 pstats->rx_bytes += sz;
689 int sta2sta_data_frame(
690 struct adapter *adapter,
691 struct recv_frame *precv_frame,
692 struct sta_info **psta
695 int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
696 struct sta_info **psta)
698 u8 *ptr = precv_frame->rx_data;
700 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
701 struct sta_priv *pstapriv = &adapter->stapriv;
702 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
703 u8 *mybssid = get_bssid(pmlmepriv);
704 u8 *myhwaddr = myid(&adapter->eeprompriv);
706 int bmcast = IS_MCAST(pattrib->dst);
708 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
709 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
710 /* filter packets that SA is myself or multicast or broadcast */
711 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
712 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
717 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
722 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
723 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
724 memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
729 sta_addr = pattrib->src;
730 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
731 /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */
732 if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN)) {
733 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("bssid!=TA under STATION_MODE; drop pkt\n"));
737 sta_addr = pattrib->bssid;
738 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
740 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
741 if (!IS_MCAST(pattrib->bssid)) {
745 } else { /* not mc-frame */
746 /* For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID */
747 if (memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN)) {
752 sta_addr = pattrib->src;
754 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
755 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
756 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
757 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
758 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
759 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
767 *psta = rtw_get_bcmc_stainfo(adapter);
769 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */
772 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under sta2sta_data_frame ; drop pkt\n"));
781 static int ap2sta_data_frame(
782 struct adapter *adapter,
783 struct recv_frame *precv_frame,
784 struct sta_info **psta)
786 u8 *ptr = precv_frame->rx_data;
787 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
789 struct sta_priv *pstapriv = &adapter->stapriv;
790 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
791 u8 *mybssid = get_bssid(pmlmepriv);
792 u8 *myhwaddr = myid(&adapter->eeprompriv);
793 int bmcast = IS_MCAST(pattrib->dst);
795 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) &&
796 (check_fwstate(pmlmepriv, _FW_LINKED) == true ||
797 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) {
798 /* filter packets that SA is myself or multicast or broadcast */
799 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
800 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
805 /* da should be for me */
806 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
807 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
808 (" ap2sta_data_frame: compare DA fail; DA=%pM\n", (pattrib->dst)));
814 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
815 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
816 (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
817 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
818 (" ap2sta_data_frame: compare BSSID fail ; BSSID=%pM\n", (pattrib->bssid)));
819 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("mybssid=%pM\n", (mybssid)));
822 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid));
823 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
831 *psta = rtw_get_bcmc_stainfo(adapter);
833 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */
836 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
841 /* if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) { */
844 if (GetFrameSubType(ptr) & BIT(6)) {
845 /* No data, will not indicate to upper layer, temporily count it here */
846 count_rx_stats(adapter, precv_frame, *psta);
847 ret = RTW_RX_HANDLED;
850 } else if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) &&
851 (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
852 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
853 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
854 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
855 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
856 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
859 memcpy(pattrib->bssid, mybssid, ETH_ALEN);
861 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
863 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under MP_MODE ; drop pkt\n"));
867 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
869 ret = RTW_RX_HANDLED;
872 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
873 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
875 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid));
877 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
889 static int sta2ap_data_frame(struct adapter *adapter,
890 struct recv_frame *precv_frame,
891 struct sta_info **psta)
893 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
894 struct sta_priv *pstapriv = &adapter->stapriv;
895 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
896 u8 *ptr = precv_frame->rx_data;
897 unsigned char *mybssid = get_bssid(pmlmepriv);
900 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
901 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */
902 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
907 *psta = rtw_get_stainfo(pstapriv, pattrib->src);
909 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under AP_MODE; drop pkt\n"));
910 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
912 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
914 ret = RTW_RX_HANDLED;
918 process_pwrbit_data(adapter, precv_frame);
920 if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) {
921 process_wmmps_data(adapter, precv_frame);
924 if (GetFrameSubType(ptr) & BIT(6)) {
925 /* No data, will not indicate to upper layer, temporily count it here */
926 count_rx_stats(adapter, precv_frame, *psta);
927 ret = RTW_RX_HANDLED;
931 u8 *myhwaddr = myid(&adapter->eeprompriv);
932 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
933 ret = RTW_RX_HANDLED;
936 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
937 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
938 ret = RTW_RX_HANDLED;
947 static int validate_recv_ctrl_frame(struct adapter *padapter,
948 struct recv_frame *precv_frame)
950 #ifdef CONFIG_88EU_AP_MODE
951 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
952 struct sta_priv *pstapriv = &padapter->stapriv;
953 u8 *pframe = precv_frame->rx_data;
955 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
958 /* receive the frames that ra(a1) is my address */
959 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN))
962 /* only handle ps-poll */
963 if (GetFrameSubType(pframe) == WIFI_PSPOLL) {
966 struct sta_info *psta = NULL;
968 aid = GetAid(pframe);
969 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
971 if ((psta == NULL) || (psta->aid != aid))
974 /* for rx pkt statistics */
975 psta->sta_stats.rx_ctrl_pkts++;
977 switch (pattrib->priority) {
980 wmmps_ac = psta->uapsd_bk&BIT(0);
984 wmmps_ac = psta->uapsd_vi&BIT(0);
988 wmmps_ac = psta->uapsd_vo&BIT(0);
993 wmmps_ac = psta->uapsd_be&BIT(0);
1000 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
1001 DBG_88E("%s alive check-rx ps-poll\n", __func__);
1002 psta->expire_to = pstapriv->expire_to;
1003 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
1006 if ((psta->state&WIFI_SLEEP_STATE) && (pstapriv->sta_dz_bitmap&BIT(psta->aid))) {
1007 struct list_head *xmitframe_plist, *xmitframe_phead;
1008 struct xmit_frame *pxmitframe = NULL;
1010 spin_lock_bh(&psta->sleep_q.lock);
1012 xmitframe_phead = get_list_head(&psta->sleep_q);
1013 xmitframe_plist = xmitframe_phead->next;
1015 if (xmitframe_phead != xmitframe_plist) {
1016 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
1018 xmitframe_plist = xmitframe_plist->next;
1020 list_del_init(&pxmitframe->list);
1024 if (psta->sleepq_len > 0)
1025 pxmitframe->attrib.mdata = 1;
1027 pxmitframe->attrib.mdata = 0;
1029 pxmitframe->attrib.triggered = 1;
1031 spin_unlock_bh(&psta->sleep_q.lock);
1032 if (rtw_hal_xmit(padapter, pxmitframe) == true)
1033 rtw_os_xmit_complete(padapter, pxmitframe);
1034 spin_lock_bh(&psta->sleep_q.lock);
1036 if (psta->sleepq_len == 0) {
1037 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1039 /* update BCN for TIM IE */
1040 /* update_BCNTIM(padapter); */
1041 update_beacon(padapter, _TIM_IE_, NULL, false);
1044 if (pstapriv->tim_bitmap&BIT(psta->aid)) {
1045 if (psta->sleepq_len == 0) {
1046 DBG_88E("no buffered packets to xmit\n");
1048 /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */
1049 issue_nulldata(padapter, psta->hwaddr, 0, 0, 0);
1051 DBG_88E("error!psta->sleepq_len=%d\n", psta->sleepq_len);
1052 psta->sleepq_len = 0;
1055 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1057 /* update BCN for TIM IE */
1058 /* update_BCNTIM(padapter); */
1059 update_beacon(padapter, _TIM_IE_, NULL, false);
1063 spin_unlock_bh(&psta->sleep_q.lock);
1072 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1073 struct recv_frame *precv_frame);
1075 static int validate_recv_mgnt_frame(struct adapter *padapter,
1076 struct recv_frame *precv_frame)
1078 struct sta_info *psta;
1080 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("+validate_recv_mgnt_frame\n"));
1082 precv_frame = recvframe_chk_defrag(padapter, precv_frame);
1083 if (precv_frame == NULL) {
1084 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("%s: fragment packet\n", __func__));
1088 /* for rx pkt statistics */
1089 psta = rtw_get_stainfo(&padapter->stapriv,
1090 GetAddr2Ptr(precv_frame->rx_data));
1092 psta->sta_stats.rx_mgnt_pkts++;
1093 if (GetFrameSubType(precv_frame->rx_data) == WIFI_BEACON) {
1094 psta->sta_stats.rx_beacon_pkts++;
1095 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBEREQ) {
1096 psta->sta_stats.rx_probereq_pkts++;
1097 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBERSP) {
1098 if (!memcmp(padapter->eeprompriv.mac_addr,
1099 GetAddr1Ptr(precv_frame->rx_data), ETH_ALEN))
1100 psta->sta_stats.rx_probersp_pkts++;
1101 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)) ||
1102 is_multicast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)))
1103 psta->sta_stats.rx_probersp_bm_pkts++;
1105 psta->sta_stats.rx_probersp_uo_pkts++;
1109 mgt_dispatcher(padapter, precv_frame);
1114 static int validate_recv_data_frame(struct adapter *adapter,
1115 struct recv_frame *precv_frame)
1118 u8 *psa, *pda, *pbssid;
1119 struct sta_info *psta = NULL;
1120 u8 *ptr = precv_frame->rx_data;
1121 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1122 struct security_priv *psecuritypriv = &adapter->securitypriv;
1125 bretry = GetRetry(ptr);
1128 pbssid = get_hdr_bssid(ptr);
1130 if (pbssid == NULL) {
1135 memcpy(pattrib->dst, pda, ETH_ALEN);
1136 memcpy(pattrib->src, psa, ETH_ALEN);
1138 memcpy(pattrib->bssid, pbssid, ETH_ALEN);
1140 switch (pattrib->to_fr_ds) {
1142 memcpy(pattrib->ra, pda, ETH_ALEN);
1143 memcpy(pattrib->ta, psa, ETH_ALEN);
1144 ret = sta2sta_data_frame(adapter, precv_frame, &psta);
1147 memcpy(pattrib->ra, pda, ETH_ALEN);
1148 memcpy(pattrib->ta, pbssid, ETH_ALEN);
1149 ret = ap2sta_data_frame(adapter, precv_frame, &psta);
1152 memcpy(pattrib->ra, pbssid, ETH_ALEN);
1153 memcpy(pattrib->ta, psa, ETH_ALEN);
1154 ret = sta2ap_data_frame(adapter, precv_frame, &psta);
1157 memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
1158 memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
1160 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" case 3\n"));
1169 } else if (ret == RTW_RX_HANDLED) {
1174 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" after to_fr_ds_chk; psta==NULL\n"));
1179 /* psta->rssi = prxcmd->rssi; */
1180 /* psta->signal_quality = prxcmd->sq; */
1181 precv_frame->psta = psta;
1184 pattrib->ack_policy = 0;
1185 /* parsing QC field */
1186 if (pattrib->qos == 1) {
1187 pattrib->priority = GetPriority((ptr + 24));
1188 pattrib->ack_policy = GetAckpolicy((ptr + 24));
1189 pattrib->amsdu = GetAMsdu((ptr + 24));
1190 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26;
1192 if (pattrib->priority != 0 && pattrib->priority != 3)
1193 adapter->recvpriv.bIsAnyNonBEPkts = true;
1195 pattrib->priority = 0;
1196 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24;
1199 if (pattrib->order)/* HT-CTRL 11n */
1200 pattrib->hdrlen += 4;
1202 precv_frame->preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
1204 /* decache, drop duplicate recv packets */
1205 if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) {
1206 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decache : drop pkt\n"));
1211 if (pattrib->privacy) {
1212 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("validate_recv_data_frame:pattrib->privacy=%x\n", pattrib->privacy));
1213 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)));
1215 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra));
1217 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n pattrib->encrypt=%d\n", pattrib->encrypt));
1219 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
1221 pattrib->encrypt = 0;
1222 pattrib->iv_len = 0;
1223 pattrib->icv_len = 0;
1231 static int validate_recv_frame(struct adapter *adapter,
1232 struct recv_frame *precv_frame)
1234 /* shall check frame subtype, to / from ds, da, bssid */
1236 /* then call check if rx seq/frag. duplicated. */
1240 int retval = _SUCCESS;
1242 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1243 u8 *ptr = precv_frame->rx_data;
1244 u8 ver = (unsigned char)(*ptr)&0x3;
1245 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1247 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
1248 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
1249 if (ch_set_idx >= 0)
1250 pmlmeext->channel_set[ch_set_idx].rx_count++;
1253 /* add version chk */
1255 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! (ver!=0)\n"));
1260 type = GetFrameType(ptr);
1261 subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */
1263 pattrib->to_fr_ds = get_tofr_ds(ptr);
1265 pattrib->frag_num = GetFragNum(ptr);
1266 pattrib->seq_num = GetSequence(ptr);
1268 pattrib->pw_save = GetPwrMgt(ptr);
1269 pattrib->mfrag = GetMFrag(ptr);
1270 pattrib->mdata = GetMData(ptr);
1271 pattrib->privacy = GetPrivacy(ptr);
1272 pattrib->order = GetOrder(ptr);
1274 /* Dump rx packets */
1275 rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
1276 if (bDumpRxPkt == 1) {/* dump all rx packets */
1278 DBG_88E("#############################\n");
1280 for (i = 0; i < 64; i += 8)
1281 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1282 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1283 DBG_88E("#############################\n");
1284 } else if (bDumpRxPkt == 2) {
1285 if (type == WIFI_MGT_TYPE) {
1287 DBG_88E("#############################\n");
1289 for (i = 0; i < 64; i += 8)
1290 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1291 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1292 DBG_88E("#############################\n");
1294 } else if (bDumpRxPkt == 3) {
1295 if (type == WIFI_DATA_TYPE) {
1297 DBG_88E("#############################\n");
1299 for (i = 0; i < 64; i += 8)
1300 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1301 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1302 DBG_88E("#############################\n");
1306 case WIFI_MGT_TYPE: /* mgnt */
1307 retval = validate_recv_mgnt_frame(adapter, precv_frame);
1308 if (retval == _FAIL)
1309 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_mgnt_frame fail\n"));
1310 retval = _FAIL; /* only data frame return _SUCCESS */
1312 case WIFI_CTRL_TYPE: /* ctrl */
1313 retval = validate_recv_ctrl_frame(adapter, precv_frame);
1314 if (retval == _FAIL)
1315 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_ctrl_frame fail\n"));
1316 retval = _FAIL; /* only data frame return _SUCCESS */
1318 case WIFI_DATA_TYPE: /* data */
1319 rtw_led_control(adapter, LED_CTL_RX);
1320 pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
1321 retval = validate_recv_data_frame(adapter, precv_frame);
1322 if (retval == _FAIL) {
1323 struct recv_priv *precvpriv = &adapter->recvpriv;
1324 precvpriv->rx_drop++;
1328 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! type= 0x%x\n", type));
1334 * This is the last moment before management and control frames get
1335 * discarded. So we need to forward them to the monitor now or never.
1337 * At the same time data frames can still be encrypted if software
1338 * decryption is in use. However, decryption can occur not until later
1339 * (see recv_func()).
1341 * Hence forward the frame to the monitor anyway to preserve the order
1342 * in which frames were received.
1344 rtl88eu_mon_recv_hook(adapter->pmondev, precv_frame);
1351 /* remove the wlanhdr and add the eth_hdr */
1353 static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1360 struct ieee80211_snap_hdr *psnap;
1362 struct adapter *adapter = precvframe->adapter;
1363 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1364 u8 *ptr = precvframe->rx_data;
1365 struct rx_pkt_attrib *pattrib = &precvframe->attrib;
1367 if (pattrib->encrypt)
1368 recvframe_pull_tail(precvframe, pattrib->icv_len);
1370 psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
1371 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
1372 /* convert hdr + possible LLC headers into Ethernet header */
1373 if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
1374 (!memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) == false) &&
1375 (!memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2) == false)) ||
1376 !memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) {
1377 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1380 /* Leave Ethernet header part of hdr and full payload */
1384 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0);
1385 len = precvframe->len - rmv_len;
1387 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
1388 ("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x===\n\n", pattrib->hdrlen, pattrib->iv_len));
1390 memcpy(&be_tmp, ptr+rmv_len, 2);
1391 eth_type = ntohs(be_tmp); /* pattrib->ether_type */
1392 pattrib->eth_type = eth_type;
1394 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE))) {
1400 /* append rx status for mp test packets */
1401 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24);
1402 memcpy(ptr, get_rxmem(precvframe), 24);
1405 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
1408 memcpy(ptr, pattrib->dst, ETH_ALEN);
1409 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
1412 be_tmp = htons(len);
1413 memcpy(ptr+12, &be_tmp, 2);
1419 /* perform defrag */
1420 static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1421 struct __queue *defrag_q)
1423 struct list_head *plist, *phead;
1426 struct recv_frame *pfhdr, *pnfhdr;
1427 struct recv_frame *prframe, *pnextrframe;
1428 struct __queue *pfree_recv_queue;
1431 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
1433 phead = get_list_head(defrag_q);
1434 plist = phead->next;
1435 pfhdr = container_of(plist, struct recv_frame, list);
1436 prframe = (struct recv_frame *)pfhdr;
1437 list_del_init(&(prframe->list));
1439 if (curfragnum != pfhdr->attrib.frag_num) {
1440 /* the first fragment number must be 0 */
1441 /* free the whole queue */
1442 rtw_free_recvframe(prframe, pfree_recv_queue);
1443 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1450 plist = get_list_head(defrag_q);
1452 plist = plist->next;
1454 while (phead != plist) {
1455 pnfhdr = container_of(plist, struct recv_frame, list);
1456 pnextrframe = (struct recv_frame *)pnfhdr;
1458 /* check the fragment sequence (2nd ~n fragment frame) */
1460 if (curfragnum != pnfhdr->attrib.frag_num) {
1461 /* the fragment number must be increasing (after decache) */
1462 /* release the defrag_q & prframe */
1463 rtw_free_recvframe(prframe, pfree_recv_queue);
1464 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1470 /* copy the 2nd~n fragment frame's payload to the first fragment */
1471 /* get the 2nd~last fragment frame's payload */
1473 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1475 recvframe_pull(pnextrframe, wlanhdr_offset);
1477 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1478 recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
1481 memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
1483 recvframe_put(prframe, pnfhdr->len);
1485 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
1486 plist = plist->next;
1489 /* free the defrag_q queue and return the prframe */
1490 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1492 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Performance defrag!!!!!\n"));
1497 /* check if need to defrag, if needed queue the frame to defrag_q */
1498 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1499 struct recv_frame *precv_frame)
1504 struct recv_frame *pfhdr;
1505 struct sta_info *psta;
1506 struct sta_priv *pstapriv;
1507 struct list_head *phead;
1508 struct recv_frame *prtnframe = NULL;
1509 struct __queue *pfree_recv_queue, *pdefrag_q;
1511 pstapriv = &padapter->stapriv;
1513 pfhdr = precv_frame;
1515 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1517 /* need to define struct of wlan header frame ctrl */
1518 ismfrag = pfhdr->attrib.mfrag;
1519 fragnum = pfhdr->attrib.frag_num;
1521 psta_addr = pfhdr->attrib.ta;
1522 psta = rtw_get_stainfo(pstapriv, psta_addr);
1524 u8 type = GetFrameType(pfhdr->rx_data);
1525 if (type != WIFI_DATA_TYPE) {
1526 psta = rtw_get_bcmc_stainfo(padapter);
1527 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1532 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1535 if ((ismfrag == 0) && (fragnum == 0))
1536 prtnframe = precv_frame;/* isn't a fragment frame */
1539 /* 0~(n-1) fragment frame */
1540 /* enqueue to defraf_g */
1541 if (pdefrag_q != NULL) {
1543 /* the first fragment */
1544 if (!list_empty(&pdefrag_q->queue)) {
1545 /* free current defrag_q */
1546 rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
1550 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1552 phead = get_list_head(pdefrag_q);
1553 list_add_tail(&pfhdr->list, phead);
1555 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Enqueuq: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1559 /* can't find this ta's defrag_queue, so free this recv_frame */
1560 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1562 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1566 if ((ismfrag == 0) && (fragnum != 0)) {
1567 /* the last fragment frame */
1568 /* enqueue the last fragment */
1569 if (pdefrag_q != NULL) {
1570 phead = get_list_head(pdefrag_q);
1571 list_add_tail(&pfhdr->list, phead);
1573 /* call recvframe_defrag to defrag */
1574 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("defrag: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1575 precv_frame = recvframe_defrag(padapter, pdefrag_q);
1576 prtnframe = precv_frame;
1578 /* can't find this ta's defrag_queue, so free this recv_frame */
1579 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1581 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1585 if ((prtnframe != NULL) && (prtnframe->attrib.privacy)) {
1586 /* after defrag we must check tkip mic code */
1587 if (recvframe_chkmic(padapter, prtnframe) == _FAIL) {
1588 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic(padapter, prtnframe)==_FAIL\n"));
1589 rtw_free_recvframe(prtnframe, pfree_recv_queue);
1597 static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1599 int a_len, padding_len;
1600 u16 eth_type, nSubframe_Length;
1602 unsigned char *pdata;
1603 struct rx_pkt_attrib *pattrib;
1604 unsigned char *data_ptr;
1605 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1606 struct recv_priv *precvpriv = &padapter->recvpriv;
1607 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1610 pattrib = &prframe->attrib;
1612 recvframe_pull(prframe, prframe->attrib.hdrlen);
1614 if (prframe->attrib.iv_len > 0)
1615 recvframe_pull(prframe, prframe->attrib.iv_len);
1617 a_len = prframe->len;
1619 pdata = prframe->rx_data;
1621 while (a_len > ETH_HLEN) {
1622 /* Offset 12 denote 2 mac address */
1623 nSubframe_Length = get_unaligned_be16(pdata + 12);
1625 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
1626 DBG_88E("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len, nSubframe_Length);
1630 /* move the data point to data content */
1634 /* Allocate new skb for releasing to upper layer */
1635 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1637 skb_reserve(sub_skb, 12);
1638 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
1639 memcpy(data_ptr, pdata, nSubframe_Length);
1641 sub_skb = skb_clone(prframe->pkt, GFP_ATOMIC);
1643 sub_skb->data = pdata;
1644 sub_skb->len = nSubframe_Length;
1645 skb_set_tail_pointer(sub_skb, nSubframe_Length);
1647 DBG_88E("skb_clone() Fail!!! , nr_subframes=%d\n", nr_subframes);
1652 subframes[nr_subframes++] = sub_skb;
1654 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
1655 DBG_88E("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1659 pdata += nSubframe_Length;
1660 a_len -= nSubframe_Length;
1662 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4-1));
1663 if (padding_len == 4) {
1667 if (a_len < padding_len) {
1670 pdata += padding_len;
1671 a_len -= padding_len;
1675 for (i = 0; i < nr_subframes; i++) {
1676 sub_skb = subframes[i];
1677 /* convert hdr + possible LLC headers into Ethernet header */
1678 eth_type = get_unaligned_be16(&sub_skb->data[6]);
1679 if (sub_skb->len >= 8 &&
1680 ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
1681 eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
1682 !memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
1683 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1684 skb_pull(sub_skb, SNAP_SIZE);
1685 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1686 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1689 /* Leave Ethernet header part of hdr and full payload */
1690 len = htons(sub_skb->len);
1691 memcpy(skb_push(sub_skb, 2), &len, 2);
1692 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1693 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1696 /* Indicate the packets to upper layer */
1697 /* Insert NAT2.5 RX here! */
1698 sub_skb->protocol = eth_type_trans(sub_skb, padapter->pnetdev);
1699 sub_skb->dev = padapter->pnetdev;
1701 sub_skb->ip_summed = CHECKSUM_NONE;
1709 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1714 static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
1716 u8 wsize = preorder_ctrl->wsize_b;
1717 u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF;/* 4096; */
1719 /* Rx Reorder initialize condition. */
1720 if (preorder_ctrl->indicate_seq == 0xFFFF)
1721 preorder_ctrl->indicate_seq = seq_num;
1723 /* Drop out the packet which SeqNum is smaller than WinStart */
1724 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
1728 /* Sliding window manipulation. Conditions includes: */
1729 /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */
1730 /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */
1732 if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) {
1733 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1734 } else if (SN_LESS(wend, seq_num)) {
1735 if (seq_num >= (wsize - 1))
1736 preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
1738 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
1744 static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
1745 struct recv_frame *prframe)
1747 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1748 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1749 struct list_head *phead, *plist;
1750 struct recv_frame *hdr;
1751 struct rx_pkt_attrib *pnextattrib;
1753 phead = get_list_head(ppending_recvframe_queue);
1754 plist = phead->next;
1756 while (phead != plist) {
1757 hdr = container_of(plist, struct recv_frame, list);
1758 pnextattrib = &hdr->attrib;
1760 if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
1761 plist = plist->next;
1762 else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
1768 list_del_init(&(prframe->list));
1770 list_add_tail(&(prframe->list), plist);
1774 static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
1776 struct list_head *phead, *plist;
1777 struct recv_frame *prframe;
1778 struct recv_frame *prhdr;
1779 struct rx_pkt_attrib *pattrib;
1780 int bPktInBuf = false;
1781 struct recv_priv *precvpriv = &padapter->recvpriv;
1782 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1784 phead = get_list_head(ppending_recvframe_queue);
1785 plist = phead->next;
1787 /* Handling some condition for forced indicate case. */
1789 if (list_empty(phead))
1792 prhdr = container_of(plist, struct recv_frame, list);
1793 pattrib = &prhdr->attrib;
1794 preorder_ctrl->indicate_seq = pattrib->seq_num;
1797 /* Prepare indication list and indication. */
1798 /* Check if there is any packet need indicate. */
1799 while (!list_empty(phead)) {
1800 prhdr = container_of(plist, struct recv_frame, list);
1801 prframe = (struct recv_frame *)prhdr;
1802 pattrib = &prframe->attrib;
1804 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
1805 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1806 ("recv_indicatepkts_in_order: indicate=%d seq=%d amsdu=%d\n",
1807 preorder_ctrl->indicate_seq, pattrib->seq_num, pattrib->amsdu));
1808 plist = plist->next;
1809 list_del_init(&(prframe->list));
1811 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
1812 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1814 /* Set this as a lock to make sure that only one thread is indicating packet. */
1816 /* indicate this recv_frame */
1817 if (!pattrib->amsdu) {
1818 if ((!padapter->bDriverStopped) &&
1819 (!padapter->bSurpriseRemoved))
1820 rtw_recv_indicatepkt(padapter, prframe);/* indicate this recv_frame */
1821 } else if (pattrib->amsdu == 1) {
1822 if (amsdu_to_msdu(padapter, prframe) != _SUCCESS)
1823 rtw_free_recvframe(prframe, &precvpriv->free_recv_queue);
1825 /* error condition; */
1828 /* Update local variables. */
1838 static int recv_indicatepkt_reorder(struct adapter *padapter,
1839 struct recv_frame *prframe)
1841 int retval = _SUCCESS;
1842 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1843 struct recv_reorder_ctrl *preorder_ctrl = prframe->preorder_ctrl;
1844 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1846 if (!pattrib->amsdu) {
1848 wlanhdr_to_ethhdr(prframe);
1850 if ((pattrib->qos != 1) || (pattrib->eth_type == 0x0806) ||
1851 (pattrib->ack_policy != 0)) {
1852 if ((!padapter->bDriverStopped) &&
1853 (!padapter->bSurpriseRemoved)) {
1854 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ recv_indicatepkt_reorder -recv_func recv_indicatepkt\n"));
1856 rtw_recv_indicatepkt(padapter, prframe);
1863 if (!preorder_ctrl->enable) {
1864 /* indicate this recv_frame */
1865 preorder_ctrl->indicate_seq = pattrib->seq_num;
1866 rtw_recv_indicatepkt(padapter, prframe);
1868 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1871 } else if (pattrib->amsdu == 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */
1872 if (!preorder_ctrl->enable) {
1873 preorder_ctrl->indicate_seq = pattrib->seq_num;
1874 retval = amsdu_to_msdu(padapter, prframe);
1876 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1881 spin_lock_bh(&ppending_recvframe_queue->lock);
1883 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1884 ("recv_indicatepkt_reorder: indicate=%d seq=%d\n",
1885 preorder_ctrl->indicate_seq, pattrib->seq_num));
1887 /* s2. check if winstart_b(indicate_seq) needs to been updated */
1888 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) {
1889 rtw_recv_indicatepkt(padapter, prframe);
1891 spin_unlock_bh(&ppending_recvframe_queue->lock);
1896 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1897 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
1901 /* Indication process. */
1902 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
1903 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
1905 /* For Rx Reorder condition: */
1906 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
1907 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
1910 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */
1911 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
1912 mod_timer(&preorder_ctrl->reordering_ctrl_timer,
1913 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
1914 spin_unlock_bh(&ppending_recvframe_queue->lock);
1916 spin_unlock_bh(&ppending_recvframe_queue->lock);
1917 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
1926 spin_unlock_bh(&ppending_recvframe_queue->lock);
1931 void rtw_reordering_ctrl_timeout_handler(unsigned long data)
1933 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)data;
1934 struct adapter *padapter = preorder_ctrl->padapter;
1935 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1937 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
1940 spin_lock_bh(&ppending_recvframe_queue->lock);
1942 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, true) == true)
1943 mod_timer(&preorder_ctrl->reordering_ctrl_timer,
1944 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
1946 spin_unlock_bh(&ppending_recvframe_queue->lock);
1949 static int process_recv_indicatepkts(struct adapter *padapter,
1950 struct recv_frame *prframe)
1952 int retval = _SUCCESS;
1953 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1954 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
1956 if (phtpriv->ht_option) { /* B/G/N Mode */
1957 if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) {
1958 /* including perform A-MPDU Rx Ordering Buffer Control */
1959 if ((!padapter->bDriverStopped) &&
1960 (!padapter->bSurpriseRemoved)) {
1965 } else { /* B/G mode */
1966 retval = wlanhdr_to_ethhdr(prframe);
1967 if (retval != _SUCCESS) {
1968 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("wlanhdr_to_ethhdr: drop pkt\n"));
1972 if ((!padapter->bDriverStopped) &&
1973 (!padapter->bSurpriseRemoved)) {
1974 /* indicate this recv_frame */
1975 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func recv_indicatepkt\n"));
1976 rtw_recv_indicatepkt(padapter, prframe);
1978 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func free_indicatepkt\n"));
1980 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
1989 static int recv_func_prehandle(struct adapter *padapter,
1990 struct recv_frame *rframe)
1993 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1995 /* check the frame crtl field and decache */
1996 ret = validate_recv_frame(padapter, rframe);
1997 if (ret != _SUCCESS) {
1998 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recv_func: validate_recv_frame fail! drop pkt\n"));
1999 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
2007 static int recv_func_posthandle(struct adapter *padapter,
2008 struct recv_frame *prframe)
2011 struct recv_frame *orig_prframe = prframe;
2012 struct recv_priv *precvpriv = &padapter->recvpriv;
2013 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2016 rtw_led_control(padapter, LED_CTL_RX);
2018 prframe = decryptor(padapter, prframe);
2019 if (prframe == NULL) {
2020 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decryptor: drop pkt\n"));
2022 goto _recv_data_drop;
2025 prframe = recvframe_chk_defrag(padapter, prframe);
2026 if (prframe == NULL) {
2027 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chk_defrag: drop pkt\n"));
2028 goto _recv_data_drop;
2031 prframe = portctrl(padapter, prframe);
2032 if (prframe == NULL) {
2033 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("portctrl: drop pkt\n"));
2035 goto _recv_data_drop;
2038 count_rx_stats(padapter, prframe, NULL);
2040 ret = process_recv_indicatepkts(padapter, prframe);
2041 if (ret != _SUCCESS) {
2042 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recv_func: process_recv_indicatepkts fail!\n"));
2043 rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */
2044 goto _recv_data_drop;
2049 precvpriv->rx_drop++;
2053 static int recv_func(struct adapter *padapter, struct recv_frame *rframe)
2056 struct rx_pkt_attrib *prxattrib = &rframe->attrib;
2057 struct security_priv *psecuritypriv = &padapter->securitypriv;
2058 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
2060 /* check if need to handle uc_swdec_pending_queue*/
2061 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey) {
2062 struct recv_frame *pending_frame;
2064 while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) {
2065 if (recv_func_posthandle(padapter, pending_frame) == _SUCCESS)
2066 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
2070 ret = recv_func_prehandle(padapter, rframe);
2072 if (ret == _SUCCESS) {
2073 /* check if need to enqueue into uc_swdec_pending_queue*/
2074 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
2075 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 &&
2076 (prxattrib->bdecrypted == 0 || psecuritypriv->sw_decrypt) &&
2077 !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) &&
2078 !psecuritypriv->busetkipkey) {
2079 rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
2080 DBG_88E("%s: no key, enqueue uc_swdec_pending_queue\n", __func__);
2084 ret = recv_func_posthandle(padapter, rframe);
2091 s32 rtw_recv_entry(struct recv_frame *precvframe)
2093 struct adapter *padapter;
2094 struct recv_priv *precvpriv;
2097 padapter = precvframe->adapter;
2099 precvpriv = &padapter->recvpriv;
2101 ret = recv_func(padapter, precvframe);
2103 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("rtw_recv_entry: recv_func return fail!!!\n"));
2104 goto _recv_entry_drop;
2107 precvpriv->rx_pkts++;
2115 void rtw_signal_stat_timer_hdl(unsigned long data)
2117 struct adapter *adapter = (struct adapter *)data;
2118 struct recv_priv *recvpriv = &adapter->recvpriv;
2121 u8 avg_signal_strength = 0;
2122 u8 avg_signal_qual = 0;
2123 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2125 if (adapter->recvpriv.is_signal_dbg) {
2126 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */
2127 adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg;
2128 adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg);
2130 if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */
2131 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2132 /* after avg_vals are acquired, we can re-stat the signal values */
2133 recvpriv->signal_strength_data.update_req = 1;
2136 if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */
2137 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2138 /* after avg_vals are acquired, we can re-stat the signal values */
2139 recvpriv->signal_qual_data.update_req = 1;
2142 /* update value of signal_strength, rssi, signal_qual */
2143 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) {
2144 tmp_s = avg_signal_strength+(_alpha-1)*recvpriv->signal_strength;
2146 tmp_s = tmp_s/_alpha + 1;
2148 tmp_s = tmp_s/_alpha;
2152 tmp_q = avg_signal_qual+(_alpha-1)*recvpriv->signal_qual;
2154 tmp_q = tmp_q/_alpha + 1;
2156 tmp_q = tmp_q/_alpha;
2160 recvpriv->signal_strength = tmp_s;
2161 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2162 recvpriv->signal_qual = tmp_q;
2165 rtw_set_signal_stat_timer(recvpriv);