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 <osdep_service.h>
23 #include <drv_types.h>
24 #include <recv_osdep.h>
25 #include <mlme_osdep.h>
28 #include <linux/vmalloc.h>
30 #define ETHERNET_HEADER_SIZE 14 /* Ethernet Header Length */
31 #define LLC_HEADER_SIZE 6 /* LLC Header Length */
33 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
34 static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
36 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
37 static u8 rtw_bridge_tunnel_header[] = {
38 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
41 static u8 rtw_rfc1042_header[] = {
42 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
45 void rtw_signal_stat_timer_hdl(RTW_TIMER_HDL_ARGS);
47 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
50 _rtw_memset((u8 *)psta_recvpriv, 0, sizeof (struct sta_recv_priv));
52 spin_lock_init(&psta_recvpriv->lock);
54 _rtw_init_queue(&psta_recvpriv->defrag_q);
58 int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
62 struct recv_frame *precvframe;
66 spin_lock_init(&precvpriv->lock);
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 rtw_os_recv_resource_init(precvpriv, padapter);
78 precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(struct recv_frame) + RXFRAME_ALIGN_SZ);
80 if (precvpriv->pallocated_frame_buf == NULL) {
85 precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
87 precvframe = (struct recv_frame *)precvpriv->precv_frame_buf;
89 for (i = 0; i < NR_RECVFRAME; i++) {
90 _rtw_init_listhead(&(precvframe->list));
92 rtw_list_insert_tail(&(precvframe->list),
93 &(precvpriv->free_recv_queue.queue));
95 res = rtw_os_recv_resource_alloc(padapter, precvframe);
99 precvframe->adapter = padapter;
102 precvpriv->rx_pending_cnt = 1;
104 sema_init(&precvpriv->allrxreturnevt, 0);
106 res = rtw_hal_init_recv_priv(padapter);
108 _init_timer(&precvpriv->signal_stat_timer, padapter->pnetdev, RTW_TIMER_HDL_NAME(signal_stat), padapter);
110 precvpriv->signal_stat_sampling_interval = 1000; /* ms */
112 rtw_set_signal_stat_timer(precvpriv);
119 void _rtw_free_recv_priv (struct recv_priv *precvpriv)
121 struct adapter *padapter = precvpriv->adapter;
124 rtw_free_uc_swdec_pending_queue(padapter);
126 rtw_os_recv_resource_free(precvpriv);
128 if (precvpriv->pallocated_frame_buf) {
129 vfree(precvpriv->pallocated_frame_buf);
132 rtw_hal_free_recv_priv(padapter);
136 struct recv_frame *_rtw_alloc_recvframe (struct __queue *pfree_recv_queue)
138 struct recv_frame *hdr;
139 struct list_head *plist, *phead;
140 struct adapter *padapter;
141 struct recv_priv *precvpriv;
143 if (_rtw_queue_empty(pfree_recv_queue)) {
146 phead = get_list_head(pfree_recv_queue);
150 hdr = container_of(plist, struct recv_frame, list);
152 rtw_list_delete(&hdr->list);
153 padapter = hdr->adapter;
154 if (padapter != NULL) {
155 precvpriv = &padapter->recvpriv;
156 if (pfree_recv_queue == &precvpriv->free_recv_queue)
157 precvpriv->free_recvframe_cnt--;
162 return (struct recv_frame *)hdr;
165 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
167 struct recv_frame *precvframe;
169 spin_lock_bh(&pfree_recv_queue->lock);
171 precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
173 spin_unlock_bh(&pfree_recv_queue->lock);
178 void rtw_init_recvframe(struct recv_frame *precvframe, struct recv_priv *precvpriv)
180 /* Perry: This can be removed */
181 _rtw_init_listhead(&precvframe->list);
186 int rtw_free_recvframe(struct recv_frame *precvframe,
187 struct __queue *pfree_recv_queue)
189 struct adapter *padapter;
190 struct recv_priv *precvpriv;
194 padapter = precvframe->adapter;
195 precvpriv = &padapter->recvpriv;
196 if (precvframe->pkt) {
197 dev_kfree_skb_any(precvframe->pkt);/* free skb by driver */
198 precvframe->pkt = NULL;
201 spin_lock_bh(&pfree_recv_queue->lock);
203 rtw_list_delete(&(precvframe->list));
207 rtw_list_insert_tail(&(precvframe->list), get_list_head(pfree_recv_queue));
209 if (padapter != NULL) {
210 if (pfree_recv_queue == &precvpriv->free_recv_queue)
211 precvpriv->free_recvframe_cnt++;
214 spin_unlock_bh(&pfree_recv_queue->lock);
220 int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
222 struct adapter *padapter = precvframe->adapter;
223 struct recv_priv *precvpriv = &padapter->recvpriv;
226 rtw_list_delete(&(precvframe->list));
227 rtw_list_insert_tail(&(precvframe->list), get_list_head(queue));
229 if (padapter != NULL) {
230 if (queue == &precvpriv->free_recv_queue)
231 precvpriv->free_recvframe_cnt++;
238 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
242 spin_lock_bh(&queue->lock);
243 ret = _rtw_enqueue_recvframe(precvframe, queue);
244 spin_unlock_bh(&queue->lock);
250 caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
251 pframequeue: defrag_queue : will be accessed in recv_thread (passive)
253 using spinlock to protect
257 void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue)
259 struct recv_frame *hdr;
260 struct list_head *plist, *phead;
262 spin_lock(&pframequeue->lock);
264 phead = get_list_head(pframequeue);
267 while (rtw_end_of_queue_search(phead, plist) == false) {
268 hdr = container_of(plist, struct recv_frame, list);
272 rtw_free_recvframe((struct recv_frame *)hdr, pfree_recv_queue);
275 spin_unlock(&pframequeue->lock);
279 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter)
282 struct recv_frame *pending_frame;
283 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
284 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
285 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
292 int rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue)
294 spin_lock_bh(&queue->lock);
296 rtw_list_delete(&precvbuf->list);
297 rtw_list_insert_head(&precvbuf->list, get_list_head(queue));
299 spin_unlock_bh(&queue->lock);
304 int rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue)
307 spin_lock_irqsave(&queue->lock, irqL);
309 rtw_list_delete(&precvbuf->list);
311 rtw_list_insert_tail(&precvbuf->list, get_list_head(queue));
312 spin_unlock_irqrestore(&queue->lock, irqL);
316 struct recv_buf *rtw_dequeue_recvbuf (struct __queue *queue)
319 struct recv_buf *precvbuf;
320 struct list_head *plist, *phead;
322 spin_lock_irqsave(&queue->lock, irqL);
324 if (_rtw_queue_empty(queue)) {
327 phead = get_list_head(queue);
331 precvbuf = container_of(plist, struct recv_buf, list);
333 rtw_list_delete(&precvbuf->list);
336 spin_unlock_irqrestore(&queue->lock, irqL);
341 static int recvframe_chkmic(struct adapter *adapter,
342 struct recv_frame *precvframe)
344 int i, res = _SUCCESS;
347 u8 bmic_err = false, brpt_micerror = true;
348 u8 *pframe, *payload, *pframemic;
350 struct sta_info *stainfo;
351 struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
352 struct security_priv *psecuritypriv = &adapter->securitypriv;
354 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
355 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
357 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
359 if (prxattrib->encrypt == _TKIP_) {
360 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic:prxattrib->encrypt==_TKIP_\n"));
361 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",
362 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2], prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5]));
364 /* calculate mic code */
365 if (stainfo != NULL) {
366 if (IS_MCAST(prxattrib->ra)) {
367 if (!psecuritypriv) {
369 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n"));
370 DBG_88E("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
373 mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
375 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic: bcmc key\n"));
377 mickey = &stainfo->dot11tkiprxmickey.skey[0];
378 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic: unicast key\n"));
381 /* icv_len included the mic code */
382 datalen = precvframe->len-prxattrib->hdrlen -
383 prxattrib->iv_len-prxattrib->icv_len-8;
384 pframe = precvframe->rx_data;
385 payload = pframe+prxattrib->hdrlen+prxattrib->iv_len;
387 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n", prxattrib->iv_len, prxattrib->icv_len));
388 rtw_seccalctkipmic(mickey, pframe, payload, datalen, &miccode[0],
389 (unsigned char)prxattrib->priority); /* care the length of the data */
391 pframemic = payload+datalen;
395 for (i = 0; i < 8; i++) {
396 if (miccode[i] != *(pframemic+i)) {
397 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
398 ("recvframe_chkmic:miccode[%d](%02x)!=*(pframemic+%d)(%02x) ",
399 i, miccode[i], i, *(pframemic+i)));
405 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
406 ("\n *(pframemic-8)-*(pframemic-1)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
407 *(pframemic-8), *(pframemic-7), *(pframemic-6),
408 *(pframemic-5), *(pframemic-4), *(pframemic-3),
409 *(pframemic-2), *(pframemic-1)));
410 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
411 ("\n *(pframemic-16)-*(pframemic-9)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
412 *(pframemic-16), *(pframemic-15), *(pframemic-14),
413 *(pframemic-13), *(pframemic-12), *(pframemic-11),
414 *(pframemic-10), *(pframemic-9)));
417 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
418 ("\n ======demp packet (len=%d)======\n",
420 for (i = 0; i < precvframe->len; i += 8) {
421 RT_TRACE(_module_rtl871x_recv_c_,
423 ("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
424 *(precvframe->rx_data+i),
425 *(precvframe->rx_data+i+1),
426 *(precvframe->rx_data+i+2),
427 *(precvframe->rx_data+i+3),
428 *(precvframe->rx_data+i+4),
429 *(precvframe->rx_data+i+5),
430 *(precvframe->rx_data+i+6),
431 *(precvframe->rx_data+i+7)));
433 RT_TRACE(_module_rtl871x_recv_c_,
435 ("\n ====== demp packet end [len=%d]======\n",
437 RT_TRACE(_module_rtl871x_recv_c_,
443 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
444 ("ra=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x psecuritypriv->binstallGrpkey=%d ",
445 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2],
446 prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5], psecuritypriv->binstallGrpkey));
448 /* double check key_index for some timing issue , */
449 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
450 if ((IS_MCAST(prxattrib->ra) == true) && (prxattrib->key_index != pmlmeinfo->key_index))
451 brpt_micerror = false;
453 if ((prxattrib->bdecrypted) && (brpt_micerror)) {
454 rtw_handle_tkip_mic_err(adapter, (u8)IS_MCAST(prxattrib->ra));
455 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
456 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
458 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
459 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
464 if ((!psecuritypriv->bcheck_grpkey) && (IS_MCAST(prxattrib->ra))) {
465 psecuritypriv->bcheck_grpkey = true;
466 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("psecuritypriv->bcheck_grpkey = true"));
470 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
473 recvframe_pull_tail(precvframe, 8);
482 /* decrypt and set the ivlen, icvlen of the recv_frame */
483 static struct recv_frame *decryptor(struct adapter *padapter,
484 struct recv_frame *precv_frame)
486 struct rx_pkt_attrib *prxattrib = &precv_frame->attrib;
487 struct security_priv *psecuritypriv = &padapter->securitypriv;
488 struct recv_frame *return_packet = precv_frame;
491 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("prxstat->decrypted=%x prxattrib->encrypt=0x%03x\n", prxattrib->bdecrypted, prxattrib->encrypt));
493 if (prxattrib->encrypt > 0) {
494 u8 *iv = precv_frame->rx_data+prxattrib->hdrlen;
495 prxattrib->key_index = (((iv[3])>>6)&0x3);
497 if (prxattrib->key_index > WEP_KEYS) {
498 DBG_88E("prxattrib->key_index(%d)>WEP_KEYS\n", prxattrib->key_index);
500 switch (prxattrib->encrypt) {
503 prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
508 prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
514 if ((prxattrib->encrypt > 0) && ((prxattrib->bdecrypted == 0) || (psecuritypriv->sw_decrypt))) {
515 psecuritypriv->hw_decrypted = false;
517 switch (prxattrib->encrypt) {
520 rtw_wep_decrypt(padapter, (u8 *)precv_frame);
523 res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
526 res = rtw_aes_decrypt(padapter, (u8 *)precv_frame);
531 } else if (prxattrib->bdecrypted == 1 && prxattrib->encrypt > 0 &&
532 (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_))
533 psecuritypriv->hw_decrypted = true;
536 rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue);
537 return_packet = NULL;
541 return return_packet;
544 /* set the security information in the recv_frame */
545 static struct recv_frame *portctrl(struct adapter *adapter,
546 struct recv_frame *precv_frame)
550 struct recv_frame *pfhdr;
551 struct sta_info *psta;
552 struct sta_priv *pstapriv;
553 struct recv_frame *prtnframe;
555 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */
556 struct rx_pkt_attrib *pattrib;
559 pstapriv = &adapter->stapriv;
561 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
563 ptr = precv_frame->rx_data;
565 pattrib = &pfhdr->attrib;
566 psta_addr = pattrib->ta;
567 psta = rtw_get_stainfo(pstapriv, psta_addr);
571 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n", adapter->securitypriv.dot11AuthAlgrthm));
575 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE;
576 memcpy(ðer_type, ptr, 2);
577 ether_type = ntohs((unsigned short)ether_type);
579 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
581 /* only accept EAPOL frame */
582 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==1\n"));
584 if (ether_type == eapol_type) {
585 prtnframe = precv_frame;
587 /* free this frame */
588 rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
593 /* check decryption status, and decrypt the frame if needed */
594 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==0\n"));
595 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
596 ("portctrl:precv_frame->hdr.attrib.privacy=%x\n",
597 precv_frame->attrib.privacy));
599 if (pattrib->bdecrypted == 0)
600 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("portctrl:prxstat->decrypted=%x\n", pattrib->bdecrypted));
602 prtnframe = precv_frame;
603 /* check is the EAPOL frame or not (Rekey) */
604 if (ether_type == eapol_type) {
605 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("########portctrl:ether_type==0x888e\n"));
608 prtnframe = precv_frame;
610 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:ether_type=0x%04x\n", ether_type));
614 prtnframe = precv_frame;
621 static int recv_decache(struct recv_frame *precv_frame, u8 bretry,
622 struct stainfo_rxcache *prxcache)
624 int tid = precv_frame->attrib.priority;
626 u16 seq_ctrl = ((precv_frame->attrib.seq_num&0xffff) << 4) |
627 (precv_frame->attrib.frag_num & 0xf);
631 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid));
636 if (1) {/* if (bretry) */
637 if (seq_ctrl == prxcache->tid_rxseq[tid]) {
638 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]));
644 prxcache->tid_rxseq[tid] = seq_ctrl;
650 void process_pwrbit_data(struct adapter *padapter,
651 struct recv_frame *precv_frame)
653 #ifdef CONFIG_88EU_AP_MODE
654 unsigned char pwrbit;
655 u8 *ptr = precv_frame->rx_data;
656 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
657 struct sta_priv *pstapriv = &padapter->stapriv;
658 struct sta_info *psta = NULL;
660 psta = rtw_get_stainfo(pstapriv, pattrib->src);
662 pwrbit = GetPwrMgt(ptr);
666 if (!(psta->state & WIFI_SLEEP_STATE))
667 stop_sta_xmit(padapter, psta);
669 if (psta->state & WIFI_SLEEP_STATE)
670 wakeup_sta_to_xmit(padapter, psta);
677 static void process_wmmps_data(struct adapter *padapter,
678 struct recv_frame *precv_frame)
680 #ifdef CONFIG_88EU_AP_MODE
681 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
682 struct sta_priv *pstapriv = &padapter->stapriv;
683 struct sta_info *psta = NULL;
685 psta = rtw_get_stainfo(pstapriv, pattrib->src);
690 if (!psta->qos_option)
693 if (!(psta->qos_info&0xf))
696 if (psta->state&WIFI_SLEEP_STATE) {
699 switch (pattrib->priority) {
702 wmmps_ac = psta->uapsd_bk&BIT(1);
706 wmmps_ac = psta->uapsd_vi&BIT(1);
710 wmmps_ac = psta->uapsd_vo&BIT(1);
715 wmmps_ac = psta->uapsd_be&BIT(1);
720 if (psta->sleepq_ac_len > 0) {
721 /* process received triggered frame */
722 xmit_delivery_enabled_frames(padapter, psta);
724 /* issue one qos null frame with More data bit = 0 and the EOSP bit set (= 1) */
725 issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0);
733 static void count_rx_stats(struct adapter *padapter,
734 struct recv_frame *prframe,
735 struct sta_info *sta)
738 struct sta_info *psta = NULL;
739 struct stainfo_stats *pstats = NULL;
740 struct rx_pkt_attrib *pattrib = &prframe->attrib;
741 struct recv_priv *precvpriv = &padapter->recvpriv;
744 precvpriv->rx_bytes += sz;
746 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
748 if ((!MacAddr_isBcst(pattrib->dst)) && (!IS_MCAST(pattrib->dst)))
749 padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
754 psta = prframe->psta;
757 pstats = &psta->sta_stats;
759 pstats->rx_data_pkts++;
760 pstats->rx_bytes += sz;
764 int sta2sta_data_frame(
765 struct adapter *adapter,
766 struct recv_frame *precv_frame,
767 struct sta_info **psta
770 int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
771 struct sta_info **psta)
773 u8 *ptr = precv_frame->rx_data;
775 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
776 struct sta_priv *pstapriv = &adapter->stapriv;
777 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
778 u8 *mybssid = get_bssid(pmlmepriv);
779 u8 *myhwaddr = myid(&adapter->eeprompriv);
781 int bmcast = IS_MCAST(pattrib->dst);
784 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
785 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
786 /* filter packets that SA is myself or multicast or broadcast */
787 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
788 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
793 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
798 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
799 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
800 memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
805 sta_addr = pattrib->src;
806 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
807 /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */
808 if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN)) {
809 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("bssid!=TA under STATION_MODE; drop pkt\n"));
813 sta_addr = pattrib->bssid;
814 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
816 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
817 if (!IS_MCAST(pattrib->bssid)) {
821 } else { /* not mc-frame */
822 /* For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID */
823 if (memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN)) {
828 sta_addr = pattrib->src;
830 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
831 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
832 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
833 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
834 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
835 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
843 *psta = rtw_get_bcmc_stainfo(adapter);
845 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */
848 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under sta2sta_data_frame ; drop pkt\n"));
849 if (adapter->registrypriv.mp_mode == 1) {
850 if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
851 adapter->mppriv.rx_pktloss++;
861 static int ap2sta_data_frame (
862 struct adapter *adapter,
863 struct recv_frame *precv_frame,
864 struct sta_info **psta)
866 u8 *ptr = precv_frame->rx_data;
867 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
869 struct sta_priv *pstapriv = &adapter->stapriv;
870 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
871 u8 *mybssid = get_bssid(pmlmepriv);
872 u8 *myhwaddr = myid(&adapter->eeprompriv);
873 int bmcast = IS_MCAST(pattrib->dst);
876 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) &&
877 (check_fwstate(pmlmepriv, _FW_LINKED) == true ||
878 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) {
879 /* filter packets that SA is myself or multicast or broadcast */
880 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
881 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
886 /* da should be for me */
887 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
888 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
889 (" ap2sta_data_frame: compare DA fail; DA=%pM\n", (pattrib->dst)));
895 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
896 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
897 (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
898 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
899 (" ap2sta_data_frame: compare BSSID fail ; BSSID=%pM\n", (pattrib->bssid)));
900 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("mybssid=%pM\n", (mybssid)));
903 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid));
904 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
912 *psta = rtw_get_bcmc_stainfo(adapter);
914 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */
917 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
922 /* if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) { */
925 if (GetFrameSubType(ptr) & BIT(6)) {
926 /* No data, will not indicate to upper layer, temporily count it here */
927 count_rx_stats(adapter, precv_frame, *psta);
928 ret = RTW_RX_HANDLED;
931 } else if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) &&
932 (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
933 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
934 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
935 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
936 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
937 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
940 memcpy(pattrib->bssid, mybssid, ETH_ALEN);
942 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
944 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under MP_MODE ; drop pkt\n"));
948 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
950 ret = RTW_RX_HANDLED;
953 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
954 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
956 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid));
958 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
971 static int sta2ap_data_frame(struct adapter *adapter,
972 struct recv_frame *precv_frame,
973 struct sta_info **psta)
975 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
976 struct sta_priv *pstapriv = &adapter->stapriv;
977 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
978 u8 *ptr = precv_frame->rx_data;
979 unsigned char *mybssid = get_bssid(pmlmepriv);
983 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
984 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */
985 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
990 *psta = rtw_get_stainfo(pstapriv, pattrib->src);
992 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under AP_MODE; drop pkt\n"));
993 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
995 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
997 ret = RTW_RX_HANDLED;
1001 process_pwrbit_data(adapter, precv_frame);
1003 if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) {
1004 process_wmmps_data(adapter, precv_frame);
1007 if (GetFrameSubType(ptr) & BIT(6)) {
1008 /* No data, will not indicate to upper layer, temporily count it here */
1009 count_rx_stats(adapter, precv_frame, *psta);
1010 ret = RTW_RX_HANDLED;
1014 u8 *myhwaddr = myid(&adapter->eeprompriv);
1015 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
1016 ret = RTW_RX_HANDLED;
1019 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
1020 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1021 ret = RTW_RX_HANDLED;
1031 static int validate_recv_ctrl_frame(struct adapter *padapter,
1032 struct recv_frame *precv_frame)
1034 #ifdef CONFIG_88EU_AP_MODE
1035 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1036 struct sta_priv *pstapriv = &padapter->stapriv;
1037 u8 *pframe = precv_frame->rx_data;
1039 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
1042 /* receive the frames that ra(a1) is my address */
1043 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN))
1046 /* only handle ps-poll */
1047 if (GetFrameSubType(pframe) == WIFI_PSPOLL) {
1050 struct sta_info *psta = NULL;
1052 aid = GetAid(pframe);
1053 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1055 if ((psta == NULL) || (psta->aid != aid))
1058 /* for rx pkt statistics */
1059 psta->sta_stats.rx_ctrl_pkts++;
1061 switch (pattrib->priority) {
1064 wmmps_ac = psta->uapsd_bk&BIT(0);
1068 wmmps_ac = psta->uapsd_vi&BIT(0);
1072 wmmps_ac = psta->uapsd_vo&BIT(0);
1077 wmmps_ac = psta->uapsd_be&BIT(0);
1084 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
1085 DBG_88E("%s alive check-rx ps-poll\n", __func__);
1086 psta->expire_to = pstapriv->expire_to;
1087 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
1090 if ((psta->state&WIFI_SLEEP_STATE) && (pstapriv->sta_dz_bitmap&BIT(psta->aid))) {
1091 struct list_head *xmitframe_plist, *xmitframe_phead;
1092 struct xmit_frame *pxmitframe = NULL;
1094 spin_lock_bh(&psta->sleep_q.lock);
1096 xmitframe_phead = get_list_head(&psta->sleep_q);
1097 xmitframe_plist = xmitframe_phead->next;
1099 if ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == false) {
1100 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
1102 xmitframe_plist = xmitframe_plist->next;
1104 rtw_list_delete(&pxmitframe->list);
1108 if (psta->sleepq_len > 0)
1109 pxmitframe->attrib.mdata = 1;
1111 pxmitframe->attrib.mdata = 0;
1113 pxmitframe->attrib.triggered = 1;
1115 spin_unlock_bh(&psta->sleep_q.lock);
1116 if (rtw_hal_xmit(padapter, pxmitframe) == true)
1117 rtw_os_xmit_complete(padapter, pxmitframe);
1118 spin_lock_bh(&psta->sleep_q.lock);
1120 if (psta->sleepq_len == 0) {
1121 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1123 /* update BCN for TIM IE */
1124 /* update_BCNTIM(padapter); */
1125 update_beacon(padapter, _TIM_IE_, NULL, false);
1128 if (pstapriv->tim_bitmap&BIT(psta->aid)) {
1129 if (psta->sleepq_len == 0) {
1130 DBG_88E("no buffered packets to xmit\n");
1132 /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */
1133 issue_nulldata(padapter, psta->hwaddr, 0, 0, 0);
1135 DBG_88E("error!psta->sleepq_len=%d\n", psta->sleepq_len);
1136 psta->sleepq_len = 0;
1139 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1141 /* update BCN for TIM IE */
1142 /* update_BCNTIM(padapter); */
1143 update_beacon(padapter, _TIM_IE_, NULL, false);
1147 spin_unlock_bh(&psta->sleep_q.lock);
1156 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1157 struct recv_frame *precv_frame);
1159 static int validate_recv_mgnt_frame(struct adapter *padapter,
1160 struct recv_frame *precv_frame)
1162 struct sta_info *psta;
1164 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("+validate_recv_mgnt_frame\n"));
1166 precv_frame = recvframe_chk_defrag(padapter, precv_frame);
1167 if (precv_frame == NULL) {
1168 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("%s: fragment packet\n", __func__));
1172 /* for rx pkt statistics */
1173 psta = rtw_get_stainfo(&padapter->stapriv,
1174 GetAddr2Ptr(precv_frame->rx_data));
1176 psta->sta_stats.rx_mgnt_pkts++;
1177 if (GetFrameSubType(precv_frame->rx_data) == WIFI_BEACON) {
1178 psta->sta_stats.rx_beacon_pkts++;
1179 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBEREQ) {
1180 psta->sta_stats.rx_probereq_pkts++;
1181 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBERSP) {
1182 if (!memcmp(padapter->eeprompriv.mac_addr,
1183 GetAddr1Ptr(precv_frame->rx_data), ETH_ALEN))
1184 psta->sta_stats.rx_probersp_pkts++;
1185 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)) ||
1186 is_multicast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)))
1187 psta->sta_stats.rx_probersp_bm_pkts++;
1189 psta->sta_stats.rx_probersp_uo_pkts++;
1193 mgt_dispatcher(padapter, precv_frame);
1198 static int validate_recv_data_frame(struct adapter *adapter,
1199 struct recv_frame *precv_frame)
1202 u8 *psa, *pda, *pbssid;
1203 struct sta_info *psta = NULL;
1204 u8 *ptr = precv_frame->rx_data;
1205 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1206 struct security_priv *psecuritypriv = &adapter->securitypriv;
1210 bretry = GetRetry(ptr);
1213 pbssid = get_hdr_bssid(ptr);
1215 if (pbssid == NULL) {
1220 memcpy(pattrib->dst, pda, ETH_ALEN);
1221 memcpy(pattrib->src, psa, ETH_ALEN);
1223 memcpy(pattrib->bssid, pbssid, ETH_ALEN);
1225 switch (pattrib->to_fr_ds) {
1227 memcpy(pattrib->ra, pda, ETH_ALEN);
1228 memcpy(pattrib->ta, psa, ETH_ALEN);
1229 ret = sta2sta_data_frame(adapter, precv_frame, &psta);
1232 memcpy(pattrib->ra, pda, ETH_ALEN);
1233 memcpy(pattrib->ta, pbssid, ETH_ALEN);
1234 ret = ap2sta_data_frame(adapter, precv_frame, &psta);
1237 memcpy(pattrib->ra, pbssid, ETH_ALEN);
1238 memcpy(pattrib->ta, psa, ETH_ALEN);
1239 ret = sta2ap_data_frame(adapter, precv_frame, &psta);
1242 memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
1243 memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
1245 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" case 3\n"));
1254 } else if (ret == RTW_RX_HANDLED) {
1259 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" after to_fr_ds_chk; psta==NULL\n"));
1264 /* psta->rssi = prxcmd->rssi; */
1265 /* psta->signal_quality = prxcmd->sq; */
1266 precv_frame->psta = psta;
1269 pattrib->ack_policy = 0;
1270 /* parsing QC field */
1271 if (pattrib->qos == 1) {
1272 pattrib->priority = GetPriority((ptr + 24));
1273 pattrib->ack_policy = GetAckpolicy((ptr + 24));
1274 pattrib->amsdu = GetAMsdu((ptr + 24));
1275 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26;
1277 if (pattrib->priority != 0 && pattrib->priority != 3)
1278 adapter->recvpriv.bIsAnyNonBEPkts = true;
1280 pattrib->priority = 0;
1281 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24;
1284 if (pattrib->order)/* HT-CTRL 11n */
1285 pattrib->hdrlen += 4;
1287 precv_frame->preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
1289 /* decache, drop duplicate recv packets */
1290 if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) {
1291 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decache : drop pkt\n"));
1296 if (pattrib->privacy) {
1297 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("validate_recv_data_frame:pattrib->privacy=%x\n", pattrib->privacy));
1298 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)));
1300 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra));
1302 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n pattrib->encrypt=%d\n", pattrib->encrypt));
1304 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
1306 pattrib->encrypt = 0;
1307 pattrib->iv_len = 0;
1308 pattrib->icv_len = 0;
1317 static int validate_recv_frame(struct adapter *adapter,
1318 struct recv_frame *precv_frame)
1320 /* shall check frame subtype, to / from ds, da, bssid */
1322 /* then call check if rx seq/frag. duplicated. */
1326 int retval = _SUCCESS;
1328 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1329 u8 *ptr = precv_frame->rx_data;
1330 u8 ver = (unsigned char) (*ptr)&0x3;
1331 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1334 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
1335 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
1336 if (ch_set_idx >= 0)
1337 pmlmeext->channel_set[ch_set_idx].rx_count++;
1340 /* add version chk */
1342 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! (ver!=0)\n"));
1347 type = GetFrameType(ptr);
1348 subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */
1350 pattrib->to_fr_ds = get_tofr_ds(ptr);
1352 pattrib->frag_num = GetFragNum(ptr);
1353 pattrib->seq_num = GetSequence(ptr);
1355 pattrib->pw_save = GetPwrMgt(ptr);
1356 pattrib->mfrag = GetMFrag(ptr);
1357 pattrib->mdata = GetMData(ptr);
1358 pattrib->privacy = GetPrivacy(ptr);
1359 pattrib->order = GetOrder(ptr);
1361 /* Dump rx packets */
1362 rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
1363 if (bDumpRxPkt == 1) {/* dump all rx packets */
1365 DBG_88E("#############################\n");
1367 for (i = 0; i < 64; i = i+8)
1368 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1369 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1370 DBG_88E("#############################\n");
1371 } else if (bDumpRxPkt == 2) {
1372 if (type == WIFI_MGT_TYPE) {
1374 DBG_88E("#############################\n");
1376 for (i = 0; i < 64; i = i+8)
1377 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1378 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1379 DBG_88E("#############################\n");
1381 } else if (bDumpRxPkt == 3) {
1382 if (type == WIFI_DATA_TYPE) {
1384 DBG_88E("#############################\n");
1386 for (i = 0; i < 64; i = i+8)
1387 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1388 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1389 DBG_88E("#############################\n");
1393 case WIFI_MGT_TYPE: /* mgnt */
1394 retval = validate_recv_mgnt_frame(adapter, precv_frame);
1395 if (retval == _FAIL)
1396 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_mgnt_frame fail\n"));
1397 retval = _FAIL; /* only data frame return _SUCCESS */
1399 case WIFI_CTRL_TYPE: /* ctrl */
1400 retval = validate_recv_ctrl_frame(adapter, precv_frame);
1401 if (retval == _FAIL)
1402 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_ctrl_frame fail\n"));
1403 retval = _FAIL; /* only data frame return _SUCCESS */
1405 case WIFI_DATA_TYPE: /* data */
1406 rtw_led_control(adapter, LED_CTL_RX);
1407 pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
1408 retval = validate_recv_data_frame(adapter, precv_frame);
1409 if (retval == _FAIL) {
1410 struct recv_priv *precvpriv = &adapter->recvpriv;
1411 precvpriv->rx_drop++;
1415 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! type= 0x%x\n", type));
1426 /* remove the wlanhdr and add the eth_hdr */
1428 static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1435 struct ieee80211_snap_hdr *psnap;
1438 struct adapter *adapter = precvframe->adapter;
1439 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1440 u8 *ptr = precvframe->rx_data;
1441 struct rx_pkt_attrib *pattrib = &precvframe->attrib;
1443 if (pattrib->encrypt)
1444 recvframe_pull_tail(precvframe, pattrib->icv_len);
1446 psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
1447 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
1448 /* convert hdr + possible LLC headers into Ethernet header */
1449 if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
1450 (!memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) == false) &&
1451 (!memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2) == false)) ||
1452 !memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) {
1453 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1456 /* Leave Ethernet header part of hdr and full payload */
1460 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0);
1461 len = precvframe->len - rmv_len;
1463 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
1464 ("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x===\n\n", pattrib->hdrlen, pattrib->iv_len));
1466 memcpy(&be_tmp, ptr+rmv_len, 2);
1467 eth_type = ntohs(be_tmp); /* pattrib->ether_type */
1468 pattrib->eth_type = eth_type;
1470 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE))) {
1476 /* append rx status for mp test packets */
1477 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24);
1478 memcpy(ptr, get_rxmem(precvframe), 24);
1481 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
1484 memcpy(ptr, pattrib->dst, ETH_ALEN);
1485 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
1488 be_tmp = htons(len);
1489 memcpy(ptr+12, &be_tmp, 2);
1495 /* perform defrag */
1496 static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1497 struct __queue *defrag_q)
1499 struct list_head *plist, *phead;
1502 struct recv_frame *pfhdr, *pnfhdr;
1503 struct recv_frame *prframe, *pnextrframe;
1504 struct __queue *pfree_recv_queue;
1508 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
1510 phead = get_list_head(defrag_q);
1511 plist = phead->next;
1512 pfhdr = container_of(plist, struct recv_frame, list);
1513 prframe = (struct recv_frame *)pfhdr;
1514 rtw_list_delete(&(prframe->list));
1516 if (curfragnum != pfhdr->attrib.frag_num) {
1517 /* the first fragment number must be 0 */
1518 /* free the whole queue */
1519 rtw_free_recvframe(prframe, pfree_recv_queue);
1520 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1527 plist = get_list_head(defrag_q);
1529 plist = plist->next;
1531 while (rtw_end_of_queue_search(phead, plist) == false) {
1532 pnfhdr = container_of(plist, struct recv_frame, list);
1533 pnextrframe = (struct recv_frame *)pnfhdr;
1535 /* check the fragment sequence (2nd ~n fragment frame) */
1537 if (curfragnum != pnfhdr->attrib.frag_num) {
1538 /* the fragment number must be increasing (after decache) */
1539 /* release the defrag_q & prframe */
1540 rtw_free_recvframe(prframe, pfree_recv_queue);
1541 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1547 /* copy the 2nd~n fragment frame's payload to the first fragment */
1548 /* get the 2nd~last fragment frame's payload */
1550 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1552 recvframe_pull(pnextrframe, wlanhdr_offset);
1554 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1555 recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
1558 memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
1560 recvframe_put(prframe, pnfhdr->len);
1562 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
1563 plist = plist->next;
1566 /* free the defrag_q queue and return the prframe */
1567 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1569 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Performance defrag!!!!!\n"));
1575 /* check if need to defrag, if needed queue the frame to defrag_q */
1576 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1577 struct recv_frame *precv_frame)
1582 struct recv_frame *pfhdr;
1583 struct sta_info *psta;
1584 struct sta_priv *pstapriv;
1585 struct list_head *phead;
1586 struct recv_frame *prtnframe = NULL;
1587 struct __queue *pfree_recv_queue, *pdefrag_q;
1590 pstapriv = &padapter->stapriv;
1592 pfhdr = precv_frame;
1594 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1596 /* need to define struct of wlan header frame ctrl */
1597 ismfrag = pfhdr->attrib.mfrag;
1598 fragnum = pfhdr->attrib.frag_num;
1600 psta_addr = pfhdr->attrib.ta;
1601 psta = rtw_get_stainfo(pstapriv, psta_addr);
1603 u8 type = GetFrameType(pfhdr->rx_data);
1604 if (type != WIFI_DATA_TYPE) {
1605 psta = rtw_get_bcmc_stainfo(padapter);
1606 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1611 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1614 if ((ismfrag == 0) && (fragnum == 0))
1615 prtnframe = precv_frame;/* isn't a fragment frame */
1618 /* 0~(n-1) fragment frame */
1619 /* enqueue to defraf_g */
1620 if (pdefrag_q != NULL) {
1622 /* the first fragment */
1623 if (_rtw_queue_empty(pdefrag_q) == false) {
1624 /* free current defrag_q */
1625 rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
1629 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1631 phead = get_list_head(pdefrag_q);
1632 rtw_list_insert_tail(&pfhdr->list, phead);
1634 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Enqueuq: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1638 /* can't find this ta's defrag_queue, so free this recv_frame */
1639 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1641 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1645 if ((ismfrag == 0) && (fragnum != 0)) {
1646 /* the last fragment frame */
1647 /* enqueue the last fragment */
1648 if (pdefrag_q != NULL) {
1649 phead = get_list_head(pdefrag_q);
1650 rtw_list_insert_tail(&pfhdr->list, phead);
1652 /* call recvframe_defrag to defrag */
1653 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("defrag: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1654 precv_frame = recvframe_defrag(padapter, pdefrag_q);
1655 prtnframe = precv_frame;
1657 /* can't find this ta's defrag_queue, so free this recv_frame */
1658 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1660 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1664 if ((prtnframe != NULL) && (prtnframe->attrib.privacy)) {
1665 /* after defrag we must check tkip mic code */
1666 if (recvframe_chkmic(padapter, prtnframe) == _FAIL) {
1667 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic(padapter, prtnframe)==_FAIL\n"));
1668 rtw_free_recvframe(prtnframe, pfree_recv_queue);
1677 static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1679 int a_len, padding_len;
1680 u16 eth_type, nSubframe_Length;
1682 unsigned char *pdata;
1683 struct rx_pkt_attrib *pattrib;
1684 unsigned char *data_ptr;
1685 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1686 struct recv_priv *precvpriv = &padapter->recvpriv;
1687 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1691 pattrib = &prframe->attrib;
1693 recvframe_pull(prframe, prframe->attrib.hdrlen);
1695 if (prframe->attrib.iv_len > 0)
1696 recvframe_pull(prframe, prframe->attrib.iv_len);
1698 a_len = prframe->len;
1700 pdata = prframe->rx_data;
1702 while (a_len > ETH_HLEN) {
1703 /* Offset 12 denote 2 mac address */
1704 nSubframe_Length = RTW_GET_BE16(pdata + 12);
1706 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
1707 DBG_88E("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len, nSubframe_Length);
1711 /* move the data point to data content */
1715 /* Allocate new skb for releasing to upper layer */
1716 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1718 skb_reserve(sub_skb, 12);
1719 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
1720 memcpy(data_ptr, pdata, nSubframe_Length);
1722 sub_skb = skb_clone(prframe->pkt, GFP_ATOMIC);
1724 sub_skb->data = pdata;
1725 sub_skb->len = nSubframe_Length;
1726 skb_set_tail_pointer(sub_skb, nSubframe_Length);
1728 DBG_88E("skb_clone() Fail!!! , nr_subframes=%d\n", nr_subframes);
1733 subframes[nr_subframes++] = sub_skb;
1735 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
1736 DBG_88E("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1740 pdata += nSubframe_Length;
1741 a_len -= nSubframe_Length;
1743 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4-1));
1744 if (padding_len == 4) {
1748 if (a_len < padding_len) {
1751 pdata += padding_len;
1752 a_len -= padding_len;
1756 for (i = 0; i < nr_subframes; i++) {
1757 sub_skb = subframes[i];
1758 /* convert hdr + possible LLC headers into Ethernet header */
1759 eth_type = RTW_GET_BE16(&sub_skb->data[6]);
1760 if (sub_skb->len >= 8 &&
1761 ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
1762 eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
1763 !memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
1764 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1765 skb_pull(sub_skb, SNAP_SIZE);
1766 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1767 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1770 /* Leave Ethernet header part of hdr and full payload */
1771 len = htons(sub_skb->len);
1772 memcpy(skb_push(sub_skb, 2), &len, 2);
1773 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1774 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1777 /* Indicate the packets to upper layer */
1778 /* Insert NAT2.5 RX here! */
1779 sub_skb->protocol = eth_type_trans(sub_skb, padapter->pnetdev);
1780 sub_skb->dev = padapter->pnetdev;
1782 sub_skb->ip_summed = CHECKSUM_NONE;
1790 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1795 static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
1797 u8 wsize = preorder_ctrl->wsize_b;
1798 u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF;/* 4096; */
1800 /* Rx Reorder initialize condition. */
1801 if (preorder_ctrl->indicate_seq == 0xFFFF)
1802 preorder_ctrl->indicate_seq = seq_num;
1804 /* Drop out the packet which SeqNum is smaller than WinStart */
1805 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
1809 /* Sliding window manipulation. Conditions includes: */
1810 /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */
1811 /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */
1813 if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) {
1814 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1815 } else if (SN_LESS(wend, seq_num)) {
1816 if (seq_num >= (wsize - 1))
1817 preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
1819 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
1825 int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
1826 struct recv_frame *prframe)
1828 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1829 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1830 struct list_head *phead, *plist;
1831 struct recv_frame *hdr;
1832 struct rx_pkt_attrib *pnextattrib;
1834 phead = get_list_head(ppending_recvframe_queue);
1835 plist = phead->next;
1837 while (rtw_end_of_queue_search(phead, plist) == false) {
1838 hdr = container_of(plist, struct recv_frame, list);
1839 pnextattrib = &hdr->attrib;
1841 if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
1842 plist = plist->next;
1843 else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
1849 rtw_list_delete(&(prframe->list));
1851 rtw_list_insert_tail(&(prframe->list), plist);
1855 static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
1857 struct list_head *phead, *plist;
1858 struct recv_frame *prframe;
1859 struct recv_frame *prhdr;
1860 struct rx_pkt_attrib *pattrib;
1861 int bPktInBuf = false;
1862 struct recv_priv *precvpriv = &padapter->recvpriv;
1863 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1865 phead = get_list_head(ppending_recvframe_queue);
1866 plist = phead->next;
1868 /* Handling some condition for forced indicate case. */
1870 if (rtw_is_list_empty(phead))
1873 prhdr = container_of(plist, struct recv_frame, list);
1874 pattrib = &prhdr->attrib;
1875 preorder_ctrl->indicate_seq = pattrib->seq_num;
1878 /* Prepare indication list and indication. */
1879 /* Check if there is any packet need indicate. */
1880 while (!rtw_is_list_empty(phead)) {
1881 prhdr = container_of(plist, struct recv_frame, list);
1882 prframe = (struct recv_frame *)prhdr;
1883 pattrib = &prframe->attrib;
1885 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
1886 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1887 ("recv_indicatepkts_in_order: indicate=%d seq=%d amsdu=%d\n",
1888 preorder_ctrl->indicate_seq, pattrib->seq_num, pattrib->amsdu));
1889 plist = plist->next;
1890 rtw_list_delete(&(prframe->list));
1892 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
1893 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1895 /* Set this as a lock to make sure that only one thread is indicating packet. */
1897 /* indicate this recv_frame */
1898 if (!pattrib->amsdu) {
1899 if ((!padapter->bDriverStopped) &&
1900 (!padapter->bSurpriseRemoved))
1901 rtw_recv_indicatepkt(padapter, prframe);/* indicate this recv_frame */
1902 } else if (pattrib->amsdu == 1) {
1903 if (amsdu_to_msdu(padapter, prframe) != _SUCCESS)
1904 rtw_free_recvframe(prframe, &precvpriv->free_recv_queue);
1906 /* error condition; */
1909 /* Update local variables. */
1919 static int recv_indicatepkt_reorder(struct adapter *padapter,
1920 struct recv_frame *prframe)
1922 int retval = _SUCCESS;
1923 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1924 struct recv_reorder_ctrl *preorder_ctrl = prframe->preorder_ctrl;
1925 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1927 if (!pattrib->amsdu) {
1929 wlanhdr_to_ethhdr(prframe);
1931 if ((pattrib->qos != 1) || (pattrib->eth_type == 0x0806) ||
1932 (pattrib->ack_policy != 0)) {
1933 if ((!padapter->bDriverStopped) &&
1934 (!padapter->bSurpriseRemoved)) {
1935 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ recv_indicatepkt_reorder -recv_func recv_indicatepkt\n"));
1937 rtw_recv_indicatepkt(padapter, prframe);
1944 if (!preorder_ctrl->enable) {
1945 /* indicate this recv_frame */
1946 preorder_ctrl->indicate_seq = pattrib->seq_num;
1947 rtw_recv_indicatepkt(padapter, prframe);
1949 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1952 } else if (pattrib->amsdu == 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */
1953 if (!preorder_ctrl->enable) {
1954 preorder_ctrl->indicate_seq = pattrib->seq_num;
1955 retval = amsdu_to_msdu(padapter, prframe);
1957 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1962 spin_lock_bh(&ppending_recvframe_queue->lock);
1964 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1965 ("recv_indicatepkt_reorder: indicate=%d seq=%d\n",
1966 preorder_ctrl->indicate_seq, pattrib->seq_num));
1968 /* s2. check if winstart_b(indicate_seq) needs to been updated */
1969 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) {
1970 rtw_recv_indicatepkt(padapter, prframe);
1972 spin_unlock_bh(&ppending_recvframe_queue->lock);
1977 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1978 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
1982 /* Indication process. */
1983 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
1984 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
1986 /* For Rx Reorder condition: */
1987 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
1988 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
1991 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */
1992 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
1993 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
1994 spin_unlock_bh(&ppending_recvframe_queue->lock);
1996 spin_unlock_bh(&ppending_recvframe_queue->lock);
1997 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
2006 spin_unlock_bh(&ppending_recvframe_queue->lock);
2011 void rtw_reordering_ctrl_timeout_handler(void *pcontext)
2013 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)pcontext;
2014 struct adapter *padapter = preorder_ctrl->padapter;
2015 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
2017 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
2020 spin_lock_bh(&ppending_recvframe_queue->lock);
2022 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, true) == true)
2023 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
2025 spin_unlock_bh(&ppending_recvframe_queue->lock);
2028 static int process_recv_indicatepkts(struct adapter *padapter,
2029 struct recv_frame *prframe)
2031 int retval = _SUCCESS;
2032 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2033 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
2035 if (phtpriv->ht_option) { /* B/G/N Mode */
2036 if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) {
2037 /* including perform A-MPDU Rx Ordering Buffer Control */
2038 if ((!padapter->bDriverStopped) &&
2039 (!padapter->bSurpriseRemoved)) {
2044 } else { /* B/G mode */
2045 retval = wlanhdr_to_ethhdr (prframe);
2046 if (retval != _SUCCESS) {
2047 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("wlanhdr_to_ethhdr: drop pkt\n"));
2051 if ((!padapter->bDriverStopped) &&
2052 (!padapter->bSurpriseRemoved)) {
2053 /* indicate this recv_frame */
2054 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func recv_indicatepkt\n"));
2055 rtw_recv_indicatepkt(padapter, prframe);
2057 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func free_indicatepkt\n"));
2059 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
2068 static int recv_func_prehandle(struct adapter *padapter,
2069 struct recv_frame *rframe)
2072 struct rx_pkt_attrib *pattrib = &rframe->attrib;
2073 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2074 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2076 if (padapter->registrypriv.mp_mode == 1) {
2077 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)) { /* padapter->mppriv.check_mp_pkt == 0)) */
2078 if (pattrib->crc_err == 1)
2079 padapter->mppriv.rx_crcerrpktcount++;
2081 padapter->mppriv.rx_pktcount++;
2083 if (check_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE) == false) {
2084 RT_TRACE(_module_rtl871x_recv_c_, _drv_alert_, ("MP - Not in loopback mode , drop pkt\n"));
2086 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
2092 /* check the frame crtl field and decache */
2093 ret = validate_recv_frame(padapter, rframe);
2094 if (ret != _SUCCESS) {
2095 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recv_func: validate_recv_frame fail! drop pkt\n"));
2096 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
2104 static int recv_func_posthandle(struct adapter *padapter,
2105 struct recv_frame *prframe)
2108 struct recv_frame *orig_prframe = prframe;
2109 struct recv_priv *precvpriv = &padapter->recvpriv;
2110 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2113 rtw_led_control(padapter, LED_CTL_RX);
2115 prframe = decryptor(padapter, prframe);
2116 if (prframe == NULL) {
2117 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decryptor: drop pkt\n"));
2119 goto _recv_data_drop;
2122 prframe = recvframe_chk_defrag(padapter, prframe);
2123 if (prframe == NULL) {
2124 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chk_defrag: drop pkt\n"));
2125 goto _recv_data_drop;
2128 prframe = portctrl(padapter, prframe);
2129 if (prframe == NULL) {
2130 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("portctrl: drop pkt\n"));
2132 goto _recv_data_drop;
2135 count_rx_stats(padapter, prframe, NULL);
2137 ret = process_recv_indicatepkts(padapter, prframe);
2138 if (ret != _SUCCESS) {
2139 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recv_func: process_recv_indicatepkts fail!\n"));
2140 rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */
2141 goto _recv_data_drop;
2146 precvpriv->rx_drop++;
2150 static int recv_func(struct adapter *padapter, struct recv_frame *rframe)
2153 struct rx_pkt_attrib *prxattrib = &rframe->attrib;
2154 struct security_priv *psecuritypriv = &padapter->securitypriv;
2155 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
2157 /* check if need to handle uc_swdec_pending_queue*/
2158 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey) {
2159 struct recv_frame *pending_frame;
2161 while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) {
2162 if (recv_func_posthandle(padapter, pending_frame) == _SUCCESS)
2163 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
2167 ret = recv_func_prehandle(padapter, rframe);
2169 if (ret == _SUCCESS) {
2170 /* check if need to enqueue into uc_swdec_pending_queue*/
2171 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
2172 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 &&
2173 (prxattrib->bdecrypted == 0 || psecuritypriv->sw_decrypt) &&
2174 !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) &&
2175 !psecuritypriv->busetkipkey) {
2176 rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
2177 DBG_88E("%s: no key, enqueue uc_swdec_pending_queue\n", __func__);
2181 ret = recv_func_posthandle(padapter, rframe);
2188 s32 rtw_recv_entry(struct recv_frame *precvframe)
2190 struct adapter *padapter;
2191 struct recv_priv *precvpriv;
2195 padapter = precvframe->adapter;
2197 precvpriv = &padapter->recvpriv;
2199 ret = recv_func(padapter, precvframe);
2201 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("rtw_recv_entry: recv_func return fail!!!\n"));
2202 goto _recv_entry_drop;
2205 precvpriv->rx_pkts++;
2212 if (padapter->registrypriv.mp_mode == 1)
2213 padapter->mppriv.rx_pktloss = precvpriv->rx_drop;
2219 void rtw_signal_stat_timer_hdl(RTW_TIMER_HDL_ARGS)
2221 struct adapter *adapter = (struct adapter *)FunctionContext;
2222 struct recv_priv *recvpriv = &adapter->recvpriv;
2225 u8 avg_signal_strength = 0;
2226 u8 avg_signal_qual = 0;
2227 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2229 if (adapter->recvpriv.is_signal_dbg) {
2230 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */
2231 adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg;
2232 adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg);
2234 if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */
2235 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2236 /* after avg_vals are acquired, we can re-stat the signal values */
2237 recvpriv->signal_strength_data.update_req = 1;
2240 if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */
2241 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2242 /* after avg_vals are acquired, we can re-stat the signal values */
2243 recvpriv->signal_qual_data.update_req = 1;
2246 /* update value of signal_strength, rssi, signal_qual */
2247 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) {
2248 tmp_s = (avg_signal_strength+(_alpha-1)*recvpriv->signal_strength);
2250 tmp_s = tmp_s/_alpha + 1;
2252 tmp_s = tmp_s/_alpha;
2256 tmp_q = (avg_signal_qual+(_alpha-1)*recvpriv->signal_qual);
2258 tmp_q = tmp_q/_alpha + 1;
2260 tmp_q = tmp_q/_alpha;
2264 recvpriv->signal_strength = tmp_s;
2265 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2266 recvpriv->signal_qual = tmp_q;
2269 rtw_set_signal_stat_timer(recvpriv);