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)));
1411 memcpy(ptr, pattrib->dst, ETH_ALEN);
1412 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
1415 be_tmp = htons(len);
1416 memcpy(ptr+12, &be_tmp, 2);
1422 /* perform defrag */
1423 static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1424 struct __queue *defrag_q)
1426 struct list_head *plist, *phead;
1429 struct recv_frame *pfhdr, *pnfhdr;
1430 struct recv_frame *prframe, *pnextrframe;
1431 struct __queue *pfree_recv_queue;
1434 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
1436 phead = get_list_head(defrag_q);
1437 plist = phead->next;
1438 pfhdr = container_of(plist, struct recv_frame, list);
1439 prframe = (struct recv_frame *)pfhdr;
1440 list_del_init(&(prframe->list));
1442 if (curfragnum != pfhdr->attrib.frag_num) {
1443 /* the first fragment number must be 0 */
1444 /* free the whole queue */
1445 rtw_free_recvframe(prframe, pfree_recv_queue);
1446 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1453 plist = get_list_head(defrag_q);
1455 plist = plist->next;
1457 while (phead != plist) {
1458 pnfhdr = container_of(plist, struct recv_frame, list);
1459 pnextrframe = (struct recv_frame *)pnfhdr;
1461 /* check the fragment sequence (2nd ~n fragment frame) */
1463 if (curfragnum != pnfhdr->attrib.frag_num) {
1464 /* the fragment number must be increasing (after decache) */
1465 /* release the defrag_q & prframe */
1466 rtw_free_recvframe(prframe, pfree_recv_queue);
1467 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1473 /* copy the 2nd~n fragment frame's payload to the first fragment */
1474 /* get the 2nd~last fragment frame's payload */
1476 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1478 recvframe_pull(pnextrframe, wlanhdr_offset);
1480 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1481 recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
1484 memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
1486 recvframe_put(prframe, pnfhdr->len);
1488 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
1489 plist = plist->next;
1492 /* free the defrag_q queue and return the prframe */
1493 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1495 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Performance defrag!!!!!\n"));
1500 /* check if need to defrag, if needed queue the frame to defrag_q */
1501 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1502 struct recv_frame *precv_frame)
1507 struct recv_frame *pfhdr;
1508 struct sta_info *psta;
1509 struct sta_priv *pstapriv;
1510 struct list_head *phead;
1511 struct recv_frame *prtnframe = NULL;
1512 struct __queue *pfree_recv_queue, *pdefrag_q;
1514 pstapriv = &padapter->stapriv;
1516 pfhdr = precv_frame;
1518 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1520 /* need to define struct of wlan header frame ctrl */
1521 ismfrag = pfhdr->attrib.mfrag;
1522 fragnum = pfhdr->attrib.frag_num;
1524 psta_addr = pfhdr->attrib.ta;
1525 psta = rtw_get_stainfo(pstapriv, psta_addr);
1527 u8 type = GetFrameType(pfhdr->rx_data);
1528 if (type != WIFI_DATA_TYPE) {
1529 psta = rtw_get_bcmc_stainfo(padapter);
1530 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1535 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1538 if ((ismfrag == 0) && (fragnum == 0))
1539 prtnframe = precv_frame;/* isn't a fragment frame */
1542 /* 0~(n-1) fragment frame */
1543 /* enqueue to defraf_g */
1544 if (pdefrag_q != NULL) {
1546 /* the first fragment */
1547 if (!list_empty(&pdefrag_q->queue)) {
1548 /* free current defrag_q */
1549 rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
1553 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1555 phead = get_list_head(pdefrag_q);
1556 list_add_tail(&pfhdr->list, phead);
1558 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Enqueuq: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1562 /* can't find this ta's defrag_queue, so free this recv_frame */
1563 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1565 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1569 if ((ismfrag == 0) && (fragnum != 0)) {
1570 /* the last fragment frame */
1571 /* enqueue the last fragment */
1572 if (pdefrag_q != NULL) {
1573 phead = get_list_head(pdefrag_q);
1574 list_add_tail(&pfhdr->list, phead);
1576 /* call recvframe_defrag to defrag */
1577 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("defrag: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1578 precv_frame = recvframe_defrag(padapter, pdefrag_q);
1579 prtnframe = precv_frame;
1581 /* can't find this ta's defrag_queue, so free this recv_frame */
1582 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1584 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1588 if ((prtnframe != NULL) && (prtnframe->attrib.privacy)) {
1589 /* after defrag we must check tkip mic code */
1590 if (recvframe_chkmic(padapter, prtnframe) == _FAIL) {
1591 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic(padapter, prtnframe)==_FAIL\n"));
1592 rtw_free_recvframe(prtnframe, pfree_recv_queue);
1600 static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1602 int a_len, padding_len;
1603 u16 eth_type, nSubframe_Length;
1605 unsigned char *pdata;
1606 struct rx_pkt_attrib *pattrib;
1607 unsigned char *data_ptr;
1608 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1609 struct recv_priv *precvpriv = &padapter->recvpriv;
1610 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1613 pattrib = &prframe->attrib;
1615 recvframe_pull(prframe, prframe->attrib.hdrlen);
1617 if (prframe->attrib.iv_len > 0)
1618 recvframe_pull(prframe, prframe->attrib.iv_len);
1620 a_len = prframe->len;
1622 pdata = prframe->rx_data;
1624 while (a_len > ETH_HLEN) {
1625 /* Offset 12 denote 2 mac address */
1626 nSubframe_Length = get_unaligned_be16(pdata + 12);
1628 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
1629 DBG_88E("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len, nSubframe_Length);
1633 /* move the data point to data content */
1637 /* Allocate new skb for releasing to upper layer */
1638 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1640 skb_reserve(sub_skb, 12);
1641 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
1642 memcpy(data_ptr, pdata, nSubframe_Length);
1644 sub_skb = skb_clone(prframe->pkt, GFP_ATOMIC);
1646 sub_skb->data = pdata;
1647 sub_skb->len = nSubframe_Length;
1648 skb_set_tail_pointer(sub_skb, nSubframe_Length);
1650 DBG_88E("skb_clone() Fail!!! , nr_subframes=%d\n", nr_subframes);
1655 subframes[nr_subframes++] = sub_skb;
1657 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
1658 DBG_88E("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1662 pdata += nSubframe_Length;
1663 a_len -= nSubframe_Length;
1665 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4-1));
1666 if (padding_len == 4) {
1670 if (a_len < padding_len) {
1673 pdata += padding_len;
1674 a_len -= padding_len;
1678 for (i = 0; i < nr_subframes; i++) {
1679 sub_skb = subframes[i];
1680 /* convert hdr + possible LLC headers into Ethernet header */
1681 eth_type = get_unaligned_be16(&sub_skb->data[6]);
1682 if (sub_skb->len >= 8 &&
1683 ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
1684 eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
1685 !memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
1686 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1687 skb_pull(sub_skb, SNAP_SIZE);
1688 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1689 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1692 /* Leave Ethernet header part of hdr and full payload */
1693 len = htons(sub_skb->len);
1694 memcpy(skb_push(sub_skb, 2), &len, 2);
1695 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1696 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1699 /* Indicate the packets to upper layer */
1700 /* Insert NAT2.5 RX here! */
1701 sub_skb->protocol = eth_type_trans(sub_skb, padapter->pnetdev);
1702 sub_skb->dev = padapter->pnetdev;
1704 sub_skb->ip_summed = CHECKSUM_NONE;
1712 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1717 static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
1719 u8 wsize = preorder_ctrl->wsize_b;
1720 u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF;/* 4096; */
1722 /* Rx Reorder initialize condition. */
1723 if (preorder_ctrl->indicate_seq == 0xFFFF)
1724 preorder_ctrl->indicate_seq = seq_num;
1726 /* Drop out the packet which SeqNum is smaller than WinStart */
1727 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
1731 /* Sliding window manipulation. Conditions includes: */
1732 /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */
1733 /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */
1735 if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) {
1736 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1737 } else if (SN_LESS(wend, seq_num)) {
1738 if (seq_num >= (wsize - 1))
1739 preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
1741 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
1747 static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
1748 struct recv_frame *prframe)
1750 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1751 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1752 struct list_head *phead, *plist;
1753 struct recv_frame *hdr;
1754 struct rx_pkt_attrib *pnextattrib;
1756 phead = get_list_head(ppending_recvframe_queue);
1757 plist = phead->next;
1759 while (phead != plist) {
1760 hdr = container_of(plist, struct recv_frame, list);
1761 pnextattrib = &hdr->attrib;
1763 if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
1764 plist = plist->next;
1765 else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
1771 list_del_init(&(prframe->list));
1773 list_add_tail(&(prframe->list), plist);
1777 static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
1779 struct list_head *phead, *plist;
1780 struct recv_frame *prframe;
1781 struct recv_frame *prhdr;
1782 struct rx_pkt_attrib *pattrib;
1783 int bPktInBuf = false;
1784 struct recv_priv *precvpriv = &padapter->recvpriv;
1785 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1787 phead = get_list_head(ppending_recvframe_queue);
1788 plist = phead->next;
1790 /* Handling some condition for forced indicate case. */
1792 if (list_empty(phead))
1795 prhdr = container_of(plist, struct recv_frame, list);
1796 pattrib = &prhdr->attrib;
1797 preorder_ctrl->indicate_seq = pattrib->seq_num;
1800 /* Prepare indication list and indication. */
1801 /* Check if there is any packet need indicate. */
1802 while (!list_empty(phead)) {
1803 prhdr = container_of(plist, struct recv_frame, list);
1804 prframe = (struct recv_frame *)prhdr;
1805 pattrib = &prframe->attrib;
1807 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
1808 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1809 ("recv_indicatepkts_in_order: indicate=%d seq=%d amsdu=%d\n",
1810 preorder_ctrl->indicate_seq, pattrib->seq_num, pattrib->amsdu));
1811 plist = plist->next;
1812 list_del_init(&(prframe->list));
1814 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
1815 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1817 /* Set this as a lock to make sure that only one thread is indicating packet. */
1819 /* indicate this recv_frame */
1820 if (!pattrib->amsdu) {
1821 if ((!padapter->bDriverStopped) &&
1822 (!padapter->bSurpriseRemoved))
1823 rtw_recv_indicatepkt(padapter, prframe);/* indicate this recv_frame */
1824 } else if (pattrib->amsdu == 1) {
1825 if (amsdu_to_msdu(padapter, prframe) != _SUCCESS)
1826 rtw_free_recvframe(prframe, &precvpriv->free_recv_queue);
1828 /* error condition; */
1831 /* Update local variables. */
1841 static int recv_indicatepkt_reorder(struct adapter *padapter,
1842 struct recv_frame *prframe)
1844 int retval = _SUCCESS;
1845 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1846 struct recv_reorder_ctrl *preorder_ctrl = prframe->preorder_ctrl;
1847 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1849 if (!pattrib->amsdu) {
1851 wlanhdr_to_ethhdr(prframe);
1853 if ((pattrib->qos != 1) || (pattrib->eth_type == 0x0806) ||
1854 (pattrib->ack_policy != 0)) {
1855 if ((!padapter->bDriverStopped) &&
1856 (!padapter->bSurpriseRemoved)) {
1857 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ recv_indicatepkt_reorder -recv_func recv_indicatepkt\n"));
1859 rtw_recv_indicatepkt(padapter, prframe);
1866 if (!preorder_ctrl->enable) {
1867 /* indicate this recv_frame */
1868 preorder_ctrl->indicate_seq = pattrib->seq_num;
1869 rtw_recv_indicatepkt(padapter, prframe);
1871 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1874 } else if (pattrib->amsdu == 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */
1875 if (!preorder_ctrl->enable) {
1876 preorder_ctrl->indicate_seq = pattrib->seq_num;
1877 retval = amsdu_to_msdu(padapter, prframe);
1879 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1884 spin_lock_bh(&ppending_recvframe_queue->lock);
1886 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1887 ("recv_indicatepkt_reorder: indicate=%d seq=%d\n",
1888 preorder_ctrl->indicate_seq, pattrib->seq_num));
1890 /* s2. check if winstart_b(indicate_seq) needs to been updated */
1891 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) {
1892 rtw_recv_indicatepkt(padapter, prframe);
1894 spin_unlock_bh(&ppending_recvframe_queue->lock);
1899 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1900 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
1904 /* Indication process. */
1905 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
1906 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
1908 /* For Rx Reorder condition: */
1909 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
1910 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
1913 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */
1914 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
1915 mod_timer(&preorder_ctrl->reordering_ctrl_timer,
1916 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
1917 spin_unlock_bh(&ppending_recvframe_queue->lock);
1919 spin_unlock_bh(&ppending_recvframe_queue->lock);
1920 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
1929 spin_unlock_bh(&ppending_recvframe_queue->lock);
1934 void rtw_reordering_ctrl_timeout_handler(unsigned long data)
1936 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)data;
1937 struct adapter *padapter = preorder_ctrl->padapter;
1938 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1940 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
1943 spin_lock_bh(&ppending_recvframe_queue->lock);
1945 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, true) == true)
1946 mod_timer(&preorder_ctrl->reordering_ctrl_timer,
1947 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
1949 spin_unlock_bh(&ppending_recvframe_queue->lock);
1952 static int process_recv_indicatepkts(struct adapter *padapter,
1953 struct recv_frame *prframe)
1955 int retval = _SUCCESS;
1956 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1957 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
1959 if (phtpriv->ht_option) { /* B/G/N Mode */
1960 if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) {
1961 /* including perform A-MPDU Rx Ordering Buffer Control */
1962 if ((!padapter->bDriverStopped) &&
1963 (!padapter->bSurpriseRemoved)) {
1968 } else { /* B/G mode */
1969 retval = wlanhdr_to_ethhdr(prframe);
1970 if (retval != _SUCCESS) {
1971 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("wlanhdr_to_ethhdr: drop pkt\n"));
1975 if ((!padapter->bDriverStopped) &&
1976 (!padapter->bSurpriseRemoved)) {
1977 /* indicate this recv_frame */
1978 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func recv_indicatepkt\n"));
1979 rtw_recv_indicatepkt(padapter, prframe);
1981 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func free_indicatepkt\n"));
1983 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
1992 static int recv_func_prehandle(struct adapter *padapter,
1993 struct recv_frame *rframe)
1996 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1998 /* check the frame crtl field and decache */
1999 ret = validate_recv_frame(padapter, rframe);
2000 if (ret != _SUCCESS) {
2001 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recv_func: validate_recv_frame fail! drop pkt\n"));
2002 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
2010 static int recv_func_posthandle(struct adapter *padapter,
2011 struct recv_frame *prframe)
2014 struct recv_frame *orig_prframe = prframe;
2015 struct recv_priv *precvpriv = &padapter->recvpriv;
2016 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2019 rtw_led_control(padapter, LED_CTL_RX);
2021 prframe = decryptor(padapter, prframe);
2022 if (prframe == NULL) {
2023 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decryptor: drop pkt\n"));
2025 goto _recv_data_drop;
2028 prframe = recvframe_chk_defrag(padapter, prframe);
2029 if (prframe == NULL) {
2030 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chk_defrag: drop pkt\n"));
2031 goto _recv_data_drop;
2034 prframe = portctrl(padapter, prframe);
2035 if (prframe == NULL) {
2036 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("portctrl: drop pkt\n"));
2038 goto _recv_data_drop;
2041 count_rx_stats(padapter, prframe, NULL);
2043 ret = process_recv_indicatepkts(padapter, prframe);
2044 if (ret != _SUCCESS) {
2045 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recv_func: process_recv_indicatepkts fail!\n"));
2046 rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */
2047 goto _recv_data_drop;
2052 precvpriv->rx_drop++;
2056 static int recv_func(struct adapter *padapter, struct recv_frame *rframe)
2059 struct rx_pkt_attrib *prxattrib = &rframe->attrib;
2060 struct security_priv *psecuritypriv = &padapter->securitypriv;
2061 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
2063 /* check if need to handle uc_swdec_pending_queue*/
2064 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey) {
2065 struct recv_frame *pending_frame;
2067 while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) {
2068 if (recv_func_posthandle(padapter, pending_frame) == _SUCCESS)
2069 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
2073 ret = recv_func_prehandle(padapter, rframe);
2075 if (ret == _SUCCESS) {
2076 /* check if need to enqueue into uc_swdec_pending_queue*/
2077 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
2078 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 &&
2079 (prxattrib->bdecrypted == 0 || psecuritypriv->sw_decrypt) &&
2080 !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) &&
2081 !psecuritypriv->busetkipkey) {
2082 rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
2083 DBG_88E("%s: no key, enqueue uc_swdec_pending_queue\n", __func__);
2087 ret = recv_func_posthandle(padapter, rframe);
2094 s32 rtw_recv_entry(struct recv_frame *precvframe)
2096 struct adapter *padapter;
2097 struct recv_priv *precvpriv;
2100 padapter = precvframe->adapter;
2102 precvpriv = &padapter->recvpriv;
2104 ret = recv_func(padapter, precvframe);
2106 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("rtw_recv_entry: recv_func return fail!!!\n"));
2107 goto _recv_entry_drop;
2110 precvpriv->rx_pkts++;
2118 void rtw_signal_stat_timer_hdl(unsigned long data)
2120 struct adapter *adapter = (struct adapter *)data;
2121 struct recv_priv *recvpriv = &adapter->recvpriv;
2124 u8 avg_signal_strength = 0;
2125 u8 avg_signal_qual = 0;
2126 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2128 if (adapter->recvpriv.is_signal_dbg) {
2129 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */
2130 adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg;
2131 adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg);
2133 if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */
2134 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2135 /* after avg_vals are acquired, we can re-stat the signal values */
2136 recvpriv->signal_strength_data.update_req = 1;
2139 if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */
2140 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2141 /* after avg_vals are acquired, we can re-stat the signal values */
2142 recvpriv->signal_qual_data.update_req = 1;
2145 /* update value of signal_strength, rssi, signal_qual */
2146 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) {
2147 tmp_s = avg_signal_strength+(_alpha-1)*recvpriv->signal_strength;
2149 tmp_s = tmp_s/_alpha + 1;
2151 tmp_s = tmp_s/_alpha;
2155 tmp_q = avg_signal_qual+(_alpha-1)*recvpriv->signal_qual;
2157 tmp_q = tmp_q/_alpha + 1;
2159 tmp_q = tmp_q/_alpha;
2163 recvpriv->signal_strength = tmp_s;
2164 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2165 recvpriv->signal_qual = tmp_q;
2168 rtw_set_signal_stat_timer(recvpriv);