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>
29 #include <linux/vmalloc.h>
31 #define ETHERNET_HEADER_SIZE 14 /* Ethernet Header Length */
32 #define LLC_HEADER_SIZE 6 /* LLC Header Length */
34 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
35 static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
37 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
38 static u8 rtw_bridge_tunnel_header[] = {
39 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
42 static u8 rtw_rfc1042_header[] = {
43 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
46 void rtw_signal_stat_timer_hdl(unsigned long data);
48 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
51 memset((u8 *)psta_recvpriv, 0, sizeof(struct sta_recv_priv));
53 spin_lock_init(&psta_recvpriv->lock);
55 _rtw_init_queue(&psta_recvpriv->defrag_q);
59 int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
63 struct recv_frame *precvframe;
67 _rtw_init_queue(&precvpriv->free_recv_queue);
68 _rtw_init_queue(&precvpriv->recv_pending_queue);
69 _rtw_init_queue(&precvpriv->uc_swdec_pending_queue);
71 precvpriv->adapter = padapter;
73 precvpriv->free_recvframe_cnt = NR_RECVFRAME;
75 precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(struct recv_frame) + RXFRAME_ALIGN_SZ);
77 if (precvpriv->pallocated_frame_buf == NULL) {
82 precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
84 precvframe = (struct recv_frame *)precvpriv->precv_frame_buf;
86 for (i = 0; i < NR_RECVFRAME; i++) {
87 INIT_LIST_HEAD(&(precvframe->list));
89 list_add_tail(&(precvframe->list),
90 &(precvpriv->free_recv_queue.queue));
92 res = rtw_os_recv_resource_alloc(precvframe);
96 precvframe->adapter = padapter;
99 precvpriv->rx_pending_cnt = 1;
101 res = rtw_hal_init_recv_priv(padapter);
103 setup_timer(&precvpriv->signal_stat_timer,
104 rtw_signal_stat_timer_hdl,
105 (unsigned long)padapter);
107 precvpriv->signal_stat_sampling_interval = 1000; /* ms */
109 rtw_set_signal_stat_timer(precvpriv);
116 void _rtw_free_recv_priv(struct recv_priv *precvpriv)
118 struct adapter *padapter = precvpriv->adapter;
121 rtw_free_uc_swdec_pending_queue(padapter);
123 if (precvpriv->pallocated_frame_buf) {
124 vfree(precvpriv->pallocated_frame_buf);
127 rtw_hal_free_recv_priv(padapter);
131 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
133 struct recv_frame *hdr;
134 struct list_head *plist, *phead;
135 struct adapter *padapter;
136 struct recv_priv *precvpriv;
138 if (list_empty(&pfree_recv_queue->queue)) {
141 phead = get_list_head(pfree_recv_queue);
145 hdr = container_of(plist, struct recv_frame, list);
147 list_del_init(&hdr->list);
148 padapter = hdr->adapter;
149 if (padapter != NULL) {
150 precvpriv = &padapter->recvpriv;
151 if (pfree_recv_queue == &precvpriv->free_recv_queue)
152 precvpriv->free_recvframe_cnt--;
157 return (struct recv_frame *)hdr;
160 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
162 struct recv_frame *precvframe;
164 spin_lock_bh(&pfree_recv_queue->lock);
166 precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
168 spin_unlock_bh(&pfree_recv_queue->lock);
173 void rtw_init_recvframe(struct recv_frame *precvframe, struct recv_priv *precvpriv)
175 /* Perry: This can be removed */
176 INIT_LIST_HEAD(&precvframe->list);
181 int rtw_free_recvframe(struct recv_frame *precvframe,
182 struct __queue *pfree_recv_queue)
184 struct adapter *padapter;
185 struct recv_priv *precvpriv;
189 padapter = precvframe->adapter;
190 precvpriv = &padapter->recvpriv;
191 if (precvframe->pkt) {
192 dev_kfree_skb_any(precvframe->pkt);/* free skb by driver */
193 precvframe->pkt = NULL;
196 spin_lock_bh(&pfree_recv_queue->lock);
198 list_del_init(&(precvframe->list));
202 list_add_tail(&(precvframe->list), get_list_head(pfree_recv_queue));
204 if (padapter != NULL) {
205 if (pfree_recv_queue == &precvpriv->free_recv_queue)
206 precvpriv->free_recvframe_cnt++;
209 spin_unlock_bh(&pfree_recv_queue->lock);
215 int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
217 struct adapter *padapter = precvframe->adapter;
218 struct recv_priv *precvpriv = &padapter->recvpriv;
221 list_del_init(&(precvframe->list));
222 list_add_tail(&(precvframe->list), get_list_head(queue));
224 if (padapter != NULL) {
225 if (queue == &precvpriv->free_recv_queue)
226 precvpriv->free_recvframe_cnt++;
233 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
237 spin_lock_bh(&queue->lock);
238 ret = _rtw_enqueue_recvframe(precvframe, queue);
239 spin_unlock_bh(&queue->lock);
245 caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
246 pframequeue: defrag_queue : will be accessed in recv_thread (passive)
248 using spinlock to protect
252 void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue)
254 struct recv_frame *hdr;
255 struct list_head *plist, *phead;
257 spin_lock(&pframequeue->lock);
259 phead = get_list_head(pframequeue);
262 while (phead != plist) {
263 hdr = container_of(plist, struct recv_frame, list);
267 rtw_free_recvframe((struct recv_frame *)hdr, pfree_recv_queue);
270 spin_unlock(&pframequeue->lock);
274 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter)
277 struct recv_frame *pending_frame;
278 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
279 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
280 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
287 static int recvframe_chkmic(struct adapter *adapter,
288 struct recv_frame *precvframe)
290 int i, res = _SUCCESS;
293 u8 bmic_err = false, brpt_micerror = true;
294 u8 *pframe, *payload, *pframemic;
296 struct sta_info *stainfo;
297 struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
298 struct security_priv *psecuritypriv = &adapter->securitypriv;
300 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
301 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
303 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
305 if (prxattrib->encrypt == _TKIP_) {
306 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic:prxattrib->encrypt==_TKIP_\n"));
307 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",
308 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2], prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5]));
310 /* calculate mic code */
311 if (stainfo != NULL) {
312 if (IS_MCAST(prxattrib->ra)) {
313 if (!psecuritypriv) {
315 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n"));
316 DBG_88E("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
319 mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
321 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic: bcmc key\n"));
323 mickey = &stainfo->dot11tkiprxmickey.skey[0];
324 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic: unicast key\n"));
327 /* icv_len included the mic code */
328 datalen = precvframe->len-prxattrib->hdrlen -
329 prxattrib->iv_len-prxattrib->icv_len-8;
330 pframe = precvframe->rx_data;
331 payload = pframe+prxattrib->hdrlen+prxattrib->iv_len;
333 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n", prxattrib->iv_len, prxattrib->icv_len));
334 rtw_seccalctkipmic(mickey, pframe, payload, datalen, &miccode[0],
335 (unsigned char)prxattrib->priority); /* care the length of the data */
337 pframemic = payload+datalen;
341 for (i = 0; i < 8; i++) {
342 if (miccode[i] != *(pframemic+i)) {
343 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
344 ("recvframe_chkmic:miccode[%d](%02x)!=*(pframemic+%d)(%02x) ",
345 i, miccode[i], i, *(pframemic+i)));
351 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
352 ("\n *(pframemic-8)-*(pframemic-1)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
353 *(pframemic-8), *(pframemic-7), *(pframemic-6),
354 *(pframemic-5), *(pframemic-4), *(pframemic-3),
355 *(pframemic-2), *(pframemic-1)));
356 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
357 ("\n *(pframemic-16)-*(pframemic-9)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
358 *(pframemic-16), *(pframemic-15), *(pframemic-14),
359 *(pframemic-13), *(pframemic-12), *(pframemic-11),
360 *(pframemic-10), *(pframemic-9)));
363 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
364 ("\n ======demp packet (len=%d)======\n",
366 for (i = 0; i < precvframe->len; i += 8) {
367 RT_TRACE(_module_rtl871x_recv_c_,
369 ("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
370 *(precvframe->rx_data+i),
371 *(precvframe->rx_data+i+1),
372 *(precvframe->rx_data+i+2),
373 *(precvframe->rx_data+i+3),
374 *(precvframe->rx_data+i+4),
375 *(precvframe->rx_data+i+5),
376 *(precvframe->rx_data+i+6),
377 *(precvframe->rx_data+i+7)));
379 RT_TRACE(_module_rtl871x_recv_c_,
381 ("\n ====== demp packet end [len=%d]======\n",
383 RT_TRACE(_module_rtl871x_recv_c_,
389 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
390 ("ra=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x psecuritypriv->binstallGrpkey=%d ",
391 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2],
392 prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5], psecuritypriv->binstallGrpkey));
394 /* double check key_index for some timing issue , */
395 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
396 if ((IS_MCAST(prxattrib->ra) == true) && (prxattrib->key_index != pmlmeinfo->key_index))
397 brpt_micerror = false;
399 if ((prxattrib->bdecrypted) && (brpt_micerror)) {
400 rtw_handle_tkip_mic_err(adapter, (u8)IS_MCAST(prxattrib->ra));
401 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
402 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
404 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
405 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
410 if ((!psecuritypriv->bcheck_grpkey) && (IS_MCAST(prxattrib->ra))) {
411 psecuritypriv->bcheck_grpkey = true;
412 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("psecuritypriv->bcheck_grpkey = true"));
416 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
419 recvframe_pull_tail(precvframe, 8);
428 /* decrypt and set the ivlen, icvlen of the recv_frame */
429 static struct recv_frame *decryptor(struct adapter *padapter,
430 struct recv_frame *precv_frame)
432 struct rx_pkt_attrib *prxattrib = &precv_frame->attrib;
433 struct security_priv *psecuritypriv = &padapter->securitypriv;
434 struct recv_frame *return_packet = precv_frame;
437 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("prxstat->decrypted=%x prxattrib->encrypt=0x%03x\n", prxattrib->bdecrypted, prxattrib->encrypt));
439 if (prxattrib->encrypt > 0) {
440 u8 *iv = precv_frame->rx_data+prxattrib->hdrlen;
441 prxattrib->key_index = (((iv[3])>>6)&0x3);
443 if (prxattrib->key_index > WEP_KEYS) {
444 DBG_88E("prxattrib->key_index(%d)>WEP_KEYS\n", prxattrib->key_index);
446 switch (prxattrib->encrypt) {
449 prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
454 prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
460 if ((prxattrib->encrypt > 0) && ((prxattrib->bdecrypted == 0) || (psecuritypriv->sw_decrypt))) {
461 psecuritypriv->hw_decrypted = false;
463 switch (prxattrib->encrypt) {
466 rtw_wep_decrypt(padapter, (u8 *)precv_frame);
469 res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
472 res = rtw_aes_decrypt(padapter, (u8 *)precv_frame);
477 } else if (prxattrib->bdecrypted == 1 && prxattrib->encrypt > 0 &&
478 (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_))
479 psecuritypriv->hw_decrypted = true;
482 rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue);
483 return_packet = NULL;
487 return return_packet;
490 /* set the security information in the recv_frame */
491 static struct recv_frame *portctrl(struct adapter *adapter,
492 struct recv_frame *precv_frame)
496 struct recv_frame *pfhdr;
497 struct sta_info *psta;
498 struct sta_priv *pstapriv;
499 struct recv_frame *prtnframe;
501 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */
502 struct rx_pkt_attrib *pattrib;
506 pstapriv = &adapter->stapriv;
508 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
510 ptr = precv_frame->rx_data;
512 pattrib = &pfhdr->attrib;
513 psta_addr = pattrib->ta;
514 psta = rtw_get_stainfo(pstapriv, psta_addr);
518 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n", adapter->securitypriv.dot11AuthAlgrthm));
522 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE;
523 memcpy(&be_tmp, ptr, 2);
524 ether_type = ntohs(be_tmp);
526 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
528 /* only accept EAPOL frame */
529 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==1\n"));
531 if (ether_type == eapol_type) {
532 prtnframe = precv_frame;
534 /* free this frame */
535 rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
540 /* check decryption status, and decrypt the frame if needed */
541 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==0\n"));
542 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
543 ("portctrl:precv_frame->hdr.attrib.privacy=%x\n",
544 precv_frame->attrib.privacy));
546 if (pattrib->bdecrypted == 0)
547 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("portctrl:prxstat->decrypted=%x\n", pattrib->bdecrypted));
549 prtnframe = precv_frame;
550 /* check is the EAPOL frame or not (Rekey) */
551 if (ether_type == eapol_type) {
552 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("########portctrl:ether_type==0x888e\n"));
555 prtnframe = precv_frame;
557 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:ether_type=0x%04x\n", ether_type));
561 prtnframe = precv_frame;
568 static int recv_decache(struct recv_frame *precv_frame, u8 bretry,
569 struct stainfo_rxcache *prxcache)
571 int tid = precv_frame->attrib.priority;
573 u16 seq_ctrl = ((precv_frame->attrib.seq_num&0xffff) << 4) |
574 (precv_frame->attrib.frag_num & 0xf);
578 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid));
583 if (1) {/* if (bretry) */
584 if (seq_ctrl == prxcache->tid_rxseq[tid]) {
585 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]));
591 prxcache->tid_rxseq[tid] = seq_ctrl;
597 static void process_pwrbit_data(struct adapter *padapter,
598 struct recv_frame *precv_frame)
600 #ifdef CONFIG_88EU_AP_MODE
601 unsigned char pwrbit;
602 u8 *ptr = precv_frame->rx_data;
603 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
604 struct sta_priv *pstapriv = &padapter->stapriv;
605 struct sta_info *psta = NULL;
607 psta = rtw_get_stainfo(pstapriv, pattrib->src);
609 pwrbit = GetPwrMgt(ptr);
613 if (!(psta->state & WIFI_SLEEP_STATE))
614 stop_sta_xmit(padapter, psta);
616 if (psta->state & WIFI_SLEEP_STATE)
617 wakeup_sta_to_xmit(padapter, psta);
624 static void process_wmmps_data(struct adapter *padapter,
625 struct recv_frame *precv_frame)
627 #ifdef CONFIG_88EU_AP_MODE
628 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
629 struct sta_priv *pstapriv = &padapter->stapriv;
630 struct sta_info *psta = NULL;
632 psta = rtw_get_stainfo(pstapriv, pattrib->src);
637 if (!psta->qos_option)
640 if (!(psta->qos_info&0xf))
643 if (psta->state&WIFI_SLEEP_STATE) {
646 switch (pattrib->priority) {
649 wmmps_ac = psta->uapsd_bk&BIT(1);
653 wmmps_ac = psta->uapsd_vi&BIT(1);
657 wmmps_ac = psta->uapsd_vo&BIT(1);
662 wmmps_ac = psta->uapsd_be&BIT(1);
667 if (psta->sleepq_ac_len > 0) {
668 /* process received triggered frame */
669 xmit_delivery_enabled_frames(padapter, psta);
671 /* issue one qos null frame with More data bit = 0 and the EOSP bit set (= 1) */
672 issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0);
680 static void count_rx_stats(struct adapter *padapter,
681 struct recv_frame *prframe,
682 struct sta_info *sta)
685 struct sta_info *psta = NULL;
686 struct stainfo_stats *pstats = NULL;
687 struct rx_pkt_attrib *pattrib = &prframe->attrib;
688 struct recv_priv *precvpriv = &padapter->recvpriv;
691 precvpriv->rx_bytes += sz;
693 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
695 if ((!MacAddr_isBcst(pattrib->dst)) && (!IS_MCAST(pattrib->dst)))
696 padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
701 psta = prframe->psta;
704 pstats = &psta->sta_stats;
706 pstats->rx_data_pkts++;
707 pstats->rx_bytes += sz;
711 int sta2sta_data_frame(
712 struct adapter *adapter,
713 struct recv_frame *precv_frame,
714 struct sta_info **psta
717 int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
718 struct sta_info **psta)
720 u8 *ptr = precv_frame->rx_data;
722 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
723 struct sta_priv *pstapriv = &adapter->stapriv;
724 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
725 u8 *mybssid = get_bssid(pmlmepriv);
726 u8 *myhwaddr = myid(&adapter->eeprompriv);
728 int bmcast = IS_MCAST(pattrib->dst);
731 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
732 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
733 /* filter packets that SA is myself or multicast or broadcast */
734 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
735 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
740 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
745 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
746 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
747 memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
752 sta_addr = pattrib->src;
753 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
754 /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */
755 if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN)) {
756 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("bssid!=TA under STATION_MODE; drop pkt\n"));
760 sta_addr = pattrib->bssid;
761 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
763 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
764 if (!IS_MCAST(pattrib->bssid)) {
768 } else { /* not mc-frame */
769 /* For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID */
770 if (memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN)) {
775 sta_addr = pattrib->src;
777 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
778 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
779 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
780 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
781 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
782 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
790 *psta = rtw_get_bcmc_stainfo(adapter);
792 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */
795 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under sta2sta_data_frame ; drop pkt\n"));
804 static int ap2sta_data_frame(
805 struct adapter *adapter,
806 struct recv_frame *precv_frame,
807 struct sta_info **psta)
809 u8 *ptr = precv_frame->rx_data;
810 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
812 struct sta_priv *pstapriv = &adapter->stapriv;
813 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
814 u8 *mybssid = get_bssid(pmlmepriv);
815 u8 *myhwaddr = myid(&adapter->eeprompriv);
816 int bmcast = IS_MCAST(pattrib->dst);
819 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) &&
820 (check_fwstate(pmlmepriv, _FW_LINKED) == true ||
821 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) {
822 /* filter packets that SA is myself or multicast or broadcast */
823 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
824 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
829 /* da should be for me */
830 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
831 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
832 (" ap2sta_data_frame: compare DA fail; DA=%pM\n", (pattrib->dst)));
838 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
839 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
840 (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
841 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
842 (" ap2sta_data_frame: compare BSSID fail ; BSSID=%pM\n", (pattrib->bssid)));
843 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("mybssid=%pM\n", (mybssid)));
846 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid));
847 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
855 *psta = rtw_get_bcmc_stainfo(adapter);
857 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */
860 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
865 /* if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) { */
868 if (GetFrameSubType(ptr) & BIT(6)) {
869 /* No data, will not indicate to upper layer, temporily count it here */
870 count_rx_stats(adapter, precv_frame, *psta);
871 ret = RTW_RX_HANDLED;
874 } else if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) &&
875 (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
876 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
877 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
878 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
879 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
880 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
883 memcpy(pattrib->bssid, mybssid, ETH_ALEN);
885 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
887 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under MP_MODE ; drop pkt\n"));
891 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
893 ret = RTW_RX_HANDLED;
896 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
897 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
899 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid));
901 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
914 static int sta2ap_data_frame(struct adapter *adapter,
915 struct recv_frame *precv_frame,
916 struct sta_info **psta)
918 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
919 struct sta_priv *pstapriv = &adapter->stapriv;
920 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
921 u8 *ptr = precv_frame->rx_data;
922 unsigned char *mybssid = get_bssid(pmlmepriv);
926 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
927 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */
928 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
933 *psta = rtw_get_stainfo(pstapriv, pattrib->src);
935 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under AP_MODE; drop pkt\n"));
936 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
938 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
940 ret = RTW_RX_HANDLED;
944 process_pwrbit_data(adapter, precv_frame);
946 if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) {
947 process_wmmps_data(adapter, precv_frame);
950 if (GetFrameSubType(ptr) & BIT(6)) {
951 /* No data, will not indicate to upper layer, temporily count it here */
952 count_rx_stats(adapter, precv_frame, *psta);
953 ret = RTW_RX_HANDLED;
957 u8 *myhwaddr = myid(&adapter->eeprompriv);
958 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
959 ret = RTW_RX_HANDLED;
962 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
963 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
964 ret = RTW_RX_HANDLED;
974 static int validate_recv_ctrl_frame(struct adapter *padapter,
975 struct recv_frame *precv_frame)
977 #ifdef CONFIG_88EU_AP_MODE
978 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
979 struct sta_priv *pstapriv = &padapter->stapriv;
980 u8 *pframe = precv_frame->rx_data;
982 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
985 /* receive the frames that ra(a1) is my address */
986 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN))
989 /* only handle ps-poll */
990 if (GetFrameSubType(pframe) == WIFI_PSPOLL) {
993 struct sta_info *psta = NULL;
995 aid = GetAid(pframe);
996 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
998 if ((psta == NULL) || (psta->aid != aid))
1001 /* for rx pkt statistics */
1002 psta->sta_stats.rx_ctrl_pkts++;
1004 switch (pattrib->priority) {
1007 wmmps_ac = psta->uapsd_bk&BIT(0);
1011 wmmps_ac = psta->uapsd_vi&BIT(0);
1015 wmmps_ac = psta->uapsd_vo&BIT(0);
1020 wmmps_ac = psta->uapsd_be&BIT(0);
1027 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
1028 DBG_88E("%s alive check-rx ps-poll\n", __func__);
1029 psta->expire_to = pstapriv->expire_to;
1030 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
1033 if ((psta->state&WIFI_SLEEP_STATE) && (pstapriv->sta_dz_bitmap&BIT(psta->aid))) {
1034 struct list_head *xmitframe_plist, *xmitframe_phead;
1035 struct xmit_frame *pxmitframe = NULL;
1037 spin_lock_bh(&psta->sleep_q.lock);
1039 xmitframe_phead = get_list_head(&psta->sleep_q);
1040 xmitframe_plist = xmitframe_phead->next;
1042 if (xmitframe_phead != xmitframe_plist) {
1043 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
1045 xmitframe_plist = xmitframe_plist->next;
1047 list_del_init(&pxmitframe->list);
1051 if (psta->sleepq_len > 0)
1052 pxmitframe->attrib.mdata = 1;
1054 pxmitframe->attrib.mdata = 0;
1056 pxmitframe->attrib.triggered = 1;
1058 spin_unlock_bh(&psta->sleep_q.lock);
1059 if (rtw_hal_xmit(padapter, pxmitframe) == true)
1060 rtw_os_xmit_complete(padapter, pxmitframe);
1061 spin_lock_bh(&psta->sleep_q.lock);
1063 if (psta->sleepq_len == 0) {
1064 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1066 /* update BCN for TIM IE */
1067 /* update_BCNTIM(padapter); */
1068 update_beacon(padapter, _TIM_IE_, NULL, false);
1071 if (pstapriv->tim_bitmap&BIT(psta->aid)) {
1072 if (psta->sleepq_len == 0) {
1073 DBG_88E("no buffered packets to xmit\n");
1075 /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */
1076 issue_nulldata(padapter, psta->hwaddr, 0, 0, 0);
1078 DBG_88E("error!psta->sleepq_len=%d\n", psta->sleepq_len);
1079 psta->sleepq_len = 0;
1082 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1084 /* update BCN for TIM IE */
1085 /* update_BCNTIM(padapter); */
1086 update_beacon(padapter, _TIM_IE_, NULL, false);
1090 spin_unlock_bh(&psta->sleep_q.lock);
1099 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1100 struct recv_frame *precv_frame);
1102 static int validate_recv_mgnt_frame(struct adapter *padapter,
1103 struct recv_frame *precv_frame)
1105 struct sta_info *psta;
1107 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("+validate_recv_mgnt_frame\n"));
1109 precv_frame = recvframe_chk_defrag(padapter, precv_frame);
1110 if (precv_frame == NULL) {
1111 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("%s: fragment packet\n", __func__));
1115 /* for rx pkt statistics */
1116 psta = rtw_get_stainfo(&padapter->stapriv,
1117 GetAddr2Ptr(precv_frame->rx_data));
1119 psta->sta_stats.rx_mgnt_pkts++;
1120 if (GetFrameSubType(precv_frame->rx_data) == WIFI_BEACON) {
1121 psta->sta_stats.rx_beacon_pkts++;
1122 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBEREQ) {
1123 psta->sta_stats.rx_probereq_pkts++;
1124 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBERSP) {
1125 if (!memcmp(padapter->eeprompriv.mac_addr,
1126 GetAddr1Ptr(precv_frame->rx_data), ETH_ALEN))
1127 psta->sta_stats.rx_probersp_pkts++;
1128 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)) ||
1129 is_multicast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)))
1130 psta->sta_stats.rx_probersp_bm_pkts++;
1132 psta->sta_stats.rx_probersp_uo_pkts++;
1136 mgt_dispatcher(padapter, precv_frame);
1141 static int validate_recv_data_frame(struct adapter *adapter,
1142 struct recv_frame *precv_frame)
1145 u8 *psa, *pda, *pbssid;
1146 struct sta_info *psta = NULL;
1147 u8 *ptr = precv_frame->rx_data;
1148 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1149 struct security_priv *psecuritypriv = &adapter->securitypriv;
1153 bretry = GetRetry(ptr);
1156 pbssid = get_hdr_bssid(ptr);
1158 if (pbssid == NULL) {
1163 memcpy(pattrib->dst, pda, ETH_ALEN);
1164 memcpy(pattrib->src, psa, ETH_ALEN);
1166 memcpy(pattrib->bssid, pbssid, ETH_ALEN);
1168 switch (pattrib->to_fr_ds) {
1170 memcpy(pattrib->ra, pda, ETH_ALEN);
1171 memcpy(pattrib->ta, psa, ETH_ALEN);
1172 ret = sta2sta_data_frame(adapter, precv_frame, &psta);
1175 memcpy(pattrib->ra, pda, ETH_ALEN);
1176 memcpy(pattrib->ta, pbssid, ETH_ALEN);
1177 ret = ap2sta_data_frame(adapter, precv_frame, &psta);
1180 memcpy(pattrib->ra, pbssid, ETH_ALEN);
1181 memcpy(pattrib->ta, psa, ETH_ALEN);
1182 ret = sta2ap_data_frame(adapter, precv_frame, &psta);
1185 memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
1186 memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
1188 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" case 3\n"));
1197 } else if (ret == RTW_RX_HANDLED) {
1202 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" after to_fr_ds_chk; psta==NULL\n"));
1207 /* psta->rssi = prxcmd->rssi; */
1208 /* psta->signal_quality = prxcmd->sq; */
1209 precv_frame->psta = psta;
1212 pattrib->ack_policy = 0;
1213 /* parsing QC field */
1214 if (pattrib->qos == 1) {
1215 pattrib->priority = GetPriority((ptr + 24));
1216 pattrib->ack_policy = GetAckpolicy((ptr + 24));
1217 pattrib->amsdu = GetAMsdu((ptr + 24));
1218 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26;
1220 if (pattrib->priority != 0 && pattrib->priority != 3)
1221 adapter->recvpriv.bIsAnyNonBEPkts = true;
1223 pattrib->priority = 0;
1224 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24;
1227 if (pattrib->order)/* HT-CTRL 11n */
1228 pattrib->hdrlen += 4;
1230 precv_frame->preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
1232 /* decache, drop duplicate recv packets */
1233 if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) {
1234 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decache : drop pkt\n"));
1239 if (pattrib->privacy) {
1240 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("validate_recv_data_frame:pattrib->privacy=%x\n", pattrib->privacy));
1241 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)));
1243 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra));
1245 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n pattrib->encrypt=%d\n", pattrib->encrypt));
1247 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
1249 pattrib->encrypt = 0;
1250 pattrib->iv_len = 0;
1251 pattrib->icv_len = 0;
1260 static int validate_recv_frame(struct adapter *adapter,
1261 struct recv_frame *precv_frame)
1263 /* shall check frame subtype, to / from ds, da, bssid */
1265 /* then call check if rx seq/frag. duplicated. */
1269 int retval = _SUCCESS;
1271 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1272 u8 *ptr = precv_frame->rx_data;
1273 u8 ver = (unsigned char)(*ptr)&0x3;
1274 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1277 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
1278 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
1279 if (ch_set_idx >= 0)
1280 pmlmeext->channel_set[ch_set_idx].rx_count++;
1283 /* add version chk */
1285 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! (ver!=0)\n"));
1290 type = GetFrameType(ptr);
1291 subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */
1293 pattrib->to_fr_ds = get_tofr_ds(ptr);
1295 pattrib->frag_num = GetFragNum(ptr);
1296 pattrib->seq_num = GetSequence(ptr);
1298 pattrib->pw_save = GetPwrMgt(ptr);
1299 pattrib->mfrag = GetMFrag(ptr);
1300 pattrib->mdata = GetMData(ptr);
1301 pattrib->privacy = GetPrivacy(ptr);
1302 pattrib->order = GetOrder(ptr);
1304 /* Dump rx packets */
1305 rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
1306 if (bDumpRxPkt == 1) {/* dump all rx packets */
1308 DBG_88E("#############################\n");
1310 for (i = 0; i < 64; i = i+8)
1311 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1312 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1313 DBG_88E("#############################\n");
1314 } else if (bDumpRxPkt == 2) {
1315 if (type == WIFI_MGT_TYPE) {
1317 DBG_88E("#############################\n");
1319 for (i = 0; i < 64; i = i+8)
1320 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1321 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1322 DBG_88E("#############################\n");
1324 } else if (bDumpRxPkt == 3) {
1325 if (type == WIFI_DATA_TYPE) {
1327 DBG_88E("#############################\n");
1329 for (i = 0; i < 64; i = i+8)
1330 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1331 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1332 DBG_88E("#############################\n");
1336 case WIFI_MGT_TYPE: /* mgnt */
1337 retval = validate_recv_mgnt_frame(adapter, precv_frame);
1338 if (retval == _FAIL)
1339 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_mgnt_frame fail\n"));
1340 retval = _FAIL; /* only data frame return _SUCCESS */
1342 case WIFI_CTRL_TYPE: /* ctrl */
1343 retval = validate_recv_ctrl_frame(adapter, precv_frame);
1344 if (retval == _FAIL)
1345 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_ctrl_frame fail\n"));
1346 retval = _FAIL; /* only data frame return _SUCCESS */
1348 case WIFI_DATA_TYPE: /* data */
1349 rtw_led_control(adapter, LED_CTL_RX);
1350 pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
1351 retval = validate_recv_data_frame(adapter, precv_frame);
1352 if (retval == _FAIL) {
1353 struct recv_priv *precvpriv = &adapter->recvpriv;
1354 precvpriv->rx_drop++;
1358 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! type= 0x%x\n", type));
1369 /* remove the wlanhdr and add the eth_hdr */
1371 static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1378 struct ieee80211_snap_hdr *psnap;
1380 struct adapter *adapter = precvframe->adapter;
1381 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1382 u8 *ptr = precvframe->rx_data;
1383 struct rx_pkt_attrib *pattrib = &precvframe->attrib;
1385 if (pattrib->encrypt)
1386 recvframe_pull_tail(precvframe, pattrib->icv_len);
1388 psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
1389 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
1390 /* convert hdr + possible LLC headers into Ethernet header */
1391 if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
1392 (!memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) == false) &&
1393 (!memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2) == false)) ||
1394 !memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) {
1395 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1398 /* Leave Ethernet header part of hdr and full payload */
1402 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0);
1403 len = precvframe->len - rmv_len;
1405 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
1406 ("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x===\n\n", pattrib->hdrlen, pattrib->iv_len));
1408 memcpy(&be_tmp, ptr+rmv_len, 2);
1409 eth_type = ntohs(be_tmp); /* pattrib->ether_type */
1410 pattrib->eth_type = eth_type;
1412 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE))) {
1418 /* append rx status for mp test packets */
1419 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24);
1420 memcpy(ptr, get_rxmem(precvframe), 24);
1423 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
1426 memcpy(ptr, pattrib->dst, ETH_ALEN);
1427 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
1430 be_tmp = htons(len);
1431 memcpy(ptr+12, &be_tmp, 2);
1437 /* perform defrag */
1438 static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1439 struct __queue *defrag_q)
1441 struct list_head *plist, *phead;
1444 struct recv_frame *pfhdr, *pnfhdr;
1445 struct recv_frame *prframe, *pnextrframe;
1446 struct __queue *pfree_recv_queue;
1450 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
1452 phead = get_list_head(defrag_q);
1453 plist = phead->next;
1454 pfhdr = container_of(plist, struct recv_frame, list);
1455 prframe = (struct recv_frame *)pfhdr;
1456 list_del_init(&(prframe->list));
1458 if (curfragnum != pfhdr->attrib.frag_num) {
1459 /* the first fragment number must be 0 */
1460 /* free the whole queue */
1461 rtw_free_recvframe(prframe, pfree_recv_queue);
1462 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1469 plist = get_list_head(defrag_q);
1471 plist = plist->next;
1473 while (phead != plist) {
1474 pnfhdr = container_of(plist, struct recv_frame, list);
1475 pnextrframe = (struct recv_frame *)pnfhdr;
1477 /* check the fragment sequence (2nd ~n fragment frame) */
1479 if (curfragnum != pnfhdr->attrib.frag_num) {
1480 /* the fragment number must be increasing (after decache) */
1481 /* release the defrag_q & prframe */
1482 rtw_free_recvframe(prframe, pfree_recv_queue);
1483 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1489 /* copy the 2nd~n fragment frame's payload to the first fragment */
1490 /* get the 2nd~last fragment frame's payload */
1492 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1494 recvframe_pull(pnextrframe, wlanhdr_offset);
1496 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1497 recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
1500 memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
1502 recvframe_put(prframe, pnfhdr->len);
1504 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
1505 plist = plist->next;
1508 /* free the defrag_q queue and return the prframe */
1509 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1511 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Performance defrag!!!!!\n"));
1517 /* check if need to defrag, if needed queue the frame to defrag_q */
1518 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1519 struct recv_frame *precv_frame)
1524 struct recv_frame *pfhdr;
1525 struct sta_info *psta;
1526 struct sta_priv *pstapriv;
1527 struct list_head *phead;
1528 struct recv_frame *prtnframe = NULL;
1529 struct __queue *pfree_recv_queue, *pdefrag_q;
1532 pstapriv = &padapter->stapriv;
1534 pfhdr = precv_frame;
1536 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1538 /* need to define struct of wlan header frame ctrl */
1539 ismfrag = pfhdr->attrib.mfrag;
1540 fragnum = pfhdr->attrib.frag_num;
1542 psta_addr = pfhdr->attrib.ta;
1543 psta = rtw_get_stainfo(pstapriv, psta_addr);
1545 u8 type = GetFrameType(pfhdr->rx_data);
1546 if (type != WIFI_DATA_TYPE) {
1547 psta = rtw_get_bcmc_stainfo(padapter);
1548 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1553 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1556 if ((ismfrag == 0) && (fragnum == 0))
1557 prtnframe = precv_frame;/* isn't a fragment frame */
1560 /* 0~(n-1) fragment frame */
1561 /* enqueue to defraf_g */
1562 if (pdefrag_q != NULL) {
1564 /* the first fragment */
1565 if (!list_empty(&pdefrag_q->queue)) {
1566 /* free current defrag_q */
1567 rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
1571 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1573 phead = get_list_head(pdefrag_q);
1574 list_add_tail(&pfhdr->list, phead);
1576 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Enqueuq: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1580 /* can't find this ta's defrag_queue, so free this recv_frame */
1581 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1583 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1587 if ((ismfrag == 0) && (fragnum != 0)) {
1588 /* the last fragment frame */
1589 /* enqueue the last fragment */
1590 if (pdefrag_q != NULL) {
1591 phead = get_list_head(pdefrag_q);
1592 list_add_tail(&pfhdr->list, phead);
1594 /* call recvframe_defrag to defrag */
1595 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("defrag: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1596 precv_frame = recvframe_defrag(padapter, pdefrag_q);
1597 prtnframe = precv_frame;
1599 /* can't find this ta's defrag_queue, so free this recv_frame */
1600 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1602 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1606 if ((prtnframe != NULL) && (prtnframe->attrib.privacy)) {
1607 /* after defrag we must check tkip mic code */
1608 if (recvframe_chkmic(padapter, prtnframe) == _FAIL) {
1609 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic(padapter, prtnframe)==_FAIL\n"));
1610 rtw_free_recvframe(prtnframe, pfree_recv_queue);
1619 static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1621 int a_len, padding_len;
1622 u16 eth_type, nSubframe_Length;
1624 unsigned char *pdata;
1625 struct rx_pkt_attrib *pattrib;
1626 unsigned char *data_ptr;
1627 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1628 struct recv_priv *precvpriv = &padapter->recvpriv;
1629 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1632 pattrib = &prframe->attrib;
1634 recvframe_pull(prframe, prframe->attrib.hdrlen);
1636 if (prframe->attrib.iv_len > 0)
1637 recvframe_pull(prframe, prframe->attrib.iv_len);
1639 a_len = prframe->len;
1641 pdata = prframe->rx_data;
1643 while (a_len > ETH_HLEN) {
1644 /* Offset 12 denote 2 mac address */
1645 nSubframe_Length = get_unaligned_be16(pdata + 12);
1647 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
1648 DBG_88E("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len, nSubframe_Length);
1652 /* move the data point to data content */
1656 /* Allocate new skb for releasing to upper layer */
1657 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1659 skb_reserve(sub_skb, 12);
1660 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
1661 memcpy(data_ptr, pdata, nSubframe_Length);
1663 sub_skb = skb_clone(prframe->pkt, GFP_ATOMIC);
1665 sub_skb->data = pdata;
1666 sub_skb->len = nSubframe_Length;
1667 skb_set_tail_pointer(sub_skb, nSubframe_Length);
1669 DBG_88E("skb_clone() Fail!!! , nr_subframes=%d\n", nr_subframes);
1674 subframes[nr_subframes++] = sub_skb;
1676 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
1677 DBG_88E("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1681 pdata += nSubframe_Length;
1682 a_len -= nSubframe_Length;
1684 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4-1));
1685 if (padding_len == 4) {
1689 if (a_len < padding_len) {
1692 pdata += padding_len;
1693 a_len -= padding_len;
1697 for (i = 0; i < nr_subframes; i++) {
1698 sub_skb = subframes[i];
1699 /* convert hdr + possible LLC headers into Ethernet header */
1700 eth_type = get_unaligned_be16(&sub_skb->data[6]);
1701 if (sub_skb->len >= 8 &&
1702 ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
1703 eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
1704 !memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
1705 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1706 skb_pull(sub_skb, SNAP_SIZE);
1707 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1708 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1711 /* Leave Ethernet header part of hdr and full payload */
1712 len = htons(sub_skb->len);
1713 memcpy(skb_push(sub_skb, 2), &len, 2);
1714 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1715 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1718 /* Indicate the packets to upper layer */
1719 /* Insert NAT2.5 RX here! */
1720 sub_skb->protocol = eth_type_trans(sub_skb, padapter->pnetdev);
1721 sub_skb->dev = padapter->pnetdev;
1723 sub_skb->ip_summed = CHECKSUM_NONE;
1731 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1736 static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
1738 u8 wsize = preorder_ctrl->wsize_b;
1739 u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF;/* 4096; */
1741 /* Rx Reorder initialize condition. */
1742 if (preorder_ctrl->indicate_seq == 0xFFFF)
1743 preorder_ctrl->indicate_seq = seq_num;
1745 /* Drop out the packet which SeqNum is smaller than WinStart */
1746 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
1750 /* Sliding window manipulation. Conditions includes: */
1751 /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */
1752 /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */
1754 if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) {
1755 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1756 } else if (SN_LESS(wend, seq_num)) {
1757 if (seq_num >= (wsize - 1))
1758 preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
1760 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
1766 static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
1767 struct recv_frame *prframe)
1769 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1770 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1771 struct list_head *phead, *plist;
1772 struct recv_frame *hdr;
1773 struct rx_pkt_attrib *pnextattrib;
1775 phead = get_list_head(ppending_recvframe_queue);
1776 plist = phead->next;
1778 while (phead != plist) {
1779 hdr = container_of(plist, struct recv_frame, list);
1780 pnextattrib = &hdr->attrib;
1782 if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
1783 plist = plist->next;
1784 else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
1790 list_del_init(&(prframe->list));
1792 list_add_tail(&(prframe->list), plist);
1796 static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
1798 struct list_head *phead, *plist;
1799 struct recv_frame *prframe;
1800 struct recv_frame *prhdr;
1801 struct rx_pkt_attrib *pattrib;
1802 int bPktInBuf = false;
1803 struct recv_priv *precvpriv = &padapter->recvpriv;
1804 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1806 phead = get_list_head(ppending_recvframe_queue);
1807 plist = phead->next;
1809 /* Handling some condition for forced indicate case. */
1811 if (list_empty(phead))
1814 prhdr = container_of(plist, struct recv_frame, list);
1815 pattrib = &prhdr->attrib;
1816 preorder_ctrl->indicate_seq = pattrib->seq_num;
1819 /* Prepare indication list and indication. */
1820 /* Check if there is any packet need indicate. */
1821 while (!list_empty(phead)) {
1822 prhdr = container_of(plist, struct recv_frame, list);
1823 prframe = (struct recv_frame *)prhdr;
1824 pattrib = &prframe->attrib;
1826 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
1827 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1828 ("recv_indicatepkts_in_order: indicate=%d seq=%d amsdu=%d\n",
1829 preorder_ctrl->indicate_seq, pattrib->seq_num, pattrib->amsdu));
1830 plist = plist->next;
1831 list_del_init(&(prframe->list));
1833 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
1834 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1836 /* Set this as a lock to make sure that only one thread is indicating packet. */
1838 /* indicate this recv_frame */
1839 if (!pattrib->amsdu) {
1840 if ((!padapter->bDriverStopped) &&
1841 (!padapter->bSurpriseRemoved))
1842 rtw_recv_indicatepkt(padapter, prframe);/* indicate this recv_frame */
1843 } else if (pattrib->amsdu == 1) {
1844 if (amsdu_to_msdu(padapter, prframe) != _SUCCESS)
1845 rtw_free_recvframe(prframe, &precvpriv->free_recv_queue);
1847 /* error condition; */
1850 /* Update local variables. */
1860 static int recv_indicatepkt_reorder(struct adapter *padapter,
1861 struct recv_frame *prframe)
1863 int retval = _SUCCESS;
1864 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1865 struct recv_reorder_ctrl *preorder_ctrl = prframe->preorder_ctrl;
1866 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1868 if (!pattrib->amsdu) {
1870 wlanhdr_to_ethhdr(prframe);
1872 if ((pattrib->qos != 1) || (pattrib->eth_type == 0x0806) ||
1873 (pattrib->ack_policy != 0)) {
1874 if ((!padapter->bDriverStopped) &&
1875 (!padapter->bSurpriseRemoved)) {
1876 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ recv_indicatepkt_reorder -recv_func recv_indicatepkt\n"));
1878 rtw_recv_indicatepkt(padapter, prframe);
1885 if (!preorder_ctrl->enable) {
1886 /* indicate this recv_frame */
1887 preorder_ctrl->indicate_seq = pattrib->seq_num;
1888 rtw_recv_indicatepkt(padapter, prframe);
1890 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1893 } else if (pattrib->amsdu == 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */
1894 if (!preorder_ctrl->enable) {
1895 preorder_ctrl->indicate_seq = pattrib->seq_num;
1896 retval = amsdu_to_msdu(padapter, prframe);
1898 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1903 spin_lock_bh(&ppending_recvframe_queue->lock);
1905 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1906 ("recv_indicatepkt_reorder: indicate=%d seq=%d\n",
1907 preorder_ctrl->indicate_seq, pattrib->seq_num));
1909 /* s2. check if winstart_b(indicate_seq) needs to been updated */
1910 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) {
1911 rtw_recv_indicatepkt(padapter, prframe);
1913 spin_unlock_bh(&ppending_recvframe_queue->lock);
1918 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1919 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
1923 /* Indication process. */
1924 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
1925 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
1927 /* For Rx Reorder condition: */
1928 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
1929 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
1932 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */
1933 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
1934 mod_timer(&preorder_ctrl->reordering_ctrl_timer,
1935 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
1936 spin_unlock_bh(&ppending_recvframe_queue->lock);
1938 spin_unlock_bh(&ppending_recvframe_queue->lock);
1939 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
1948 spin_unlock_bh(&ppending_recvframe_queue->lock);
1953 void rtw_reordering_ctrl_timeout_handler(unsigned long data)
1955 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)data;
1956 struct adapter *padapter = preorder_ctrl->padapter;
1957 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1959 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
1962 spin_lock_bh(&ppending_recvframe_queue->lock);
1964 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, true) == true)
1965 mod_timer(&preorder_ctrl->reordering_ctrl_timer,
1966 jiffies + msecs_to_jiffies(REORDER_WAIT_TIME));
1968 spin_unlock_bh(&ppending_recvframe_queue->lock);
1971 static int process_recv_indicatepkts(struct adapter *padapter,
1972 struct recv_frame *prframe)
1974 int retval = _SUCCESS;
1975 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1976 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
1978 if (phtpriv->ht_option) { /* B/G/N Mode */
1979 if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) {
1980 /* including perform A-MPDU Rx Ordering Buffer Control */
1981 if ((!padapter->bDriverStopped) &&
1982 (!padapter->bSurpriseRemoved)) {
1987 } else { /* B/G mode */
1988 retval = wlanhdr_to_ethhdr(prframe);
1989 if (retval != _SUCCESS) {
1990 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("wlanhdr_to_ethhdr: drop pkt\n"));
1994 if ((!padapter->bDriverStopped) &&
1995 (!padapter->bSurpriseRemoved)) {
1996 /* indicate this recv_frame */
1997 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func recv_indicatepkt\n"));
1998 rtw_recv_indicatepkt(padapter, prframe);
2000 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func free_indicatepkt\n"));
2002 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
2011 static int recv_func_prehandle(struct adapter *padapter,
2012 struct recv_frame *rframe)
2015 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2017 /* check the frame crtl field and decache */
2018 ret = validate_recv_frame(padapter, rframe);
2019 if (ret != _SUCCESS) {
2020 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recv_func: validate_recv_frame fail! drop pkt\n"));
2021 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
2029 static int recv_func_posthandle(struct adapter *padapter,
2030 struct recv_frame *prframe)
2033 struct recv_frame *orig_prframe = prframe;
2034 struct recv_priv *precvpriv = &padapter->recvpriv;
2035 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2038 rtw_led_control(padapter, LED_CTL_RX);
2040 prframe = decryptor(padapter, prframe);
2041 if (prframe == NULL) {
2042 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decryptor: drop pkt\n"));
2044 goto _recv_data_drop;
2047 prframe = recvframe_chk_defrag(padapter, prframe);
2048 if (prframe == NULL) {
2049 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chk_defrag: drop pkt\n"));
2050 goto _recv_data_drop;
2053 prframe = portctrl(padapter, prframe);
2054 if (prframe == NULL) {
2055 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("portctrl: drop pkt\n"));
2057 goto _recv_data_drop;
2060 count_rx_stats(padapter, prframe, NULL);
2062 ret = process_recv_indicatepkts(padapter, prframe);
2063 if (ret != _SUCCESS) {
2064 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recv_func: process_recv_indicatepkts fail!\n"));
2065 rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */
2066 goto _recv_data_drop;
2071 precvpriv->rx_drop++;
2075 static int recv_func(struct adapter *padapter, struct recv_frame *rframe)
2078 struct rx_pkt_attrib *prxattrib = &rframe->attrib;
2079 struct security_priv *psecuritypriv = &padapter->securitypriv;
2080 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
2082 /* check if need to handle uc_swdec_pending_queue*/
2083 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey) {
2084 struct recv_frame *pending_frame;
2086 while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) {
2087 if (recv_func_posthandle(padapter, pending_frame) == _SUCCESS)
2088 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
2092 ret = recv_func_prehandle(padapter, rframe);
2094 if (ret == _SUCCESS) {
2095 /* check if need to enqueue into uc_swdec_pending_queue*/
2096 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
2097 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 &&
2098 (prxattrib->bdecrypted == 0 || psecuritypriv->sw_decrypt) &&
2099 !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) &&
2100 !psecuritypriv->busetkipkey) {
2101 rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
2102 DBG_88E("%s: no key, enqueue uc_swdec_pending_queue\n", __func__);
2106 ret = recv_func_posthandle(padapter, rframe);
2113 s32 rtw_recv_entry(struct recv_frame *precvframe)
2115 struct adapter *padapter;
2116 struct recv_priv *precvpriv;
2120 padapter = precvframe->adapter;
2122 precvpriv = &padapter->recvpriv;
2124 ret = recv_func(padapter, precvframe);
2126 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("rtw_recv_entry: recv_func return fail!!!\n"));
2127 goto _recv_entry_drop;
2130 precvpriv->rx_pkts++;
2139 void rtw_signal_stat_timer_hdl(unsigned long data)
2141 struct adapter *adapter = (struct adapter *)data;
2142 struct recv_priv *recvpriv = &adapter->recvpriv;
2145 u8 avg_signal_strength = 0;
2146 u8 avg_signal_qual = 0;
2147 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2149 if (adapter->recvpriv.is_signal_dbg) {
2150 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */
2151 adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg;
2152 adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg);
2154 if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */
2155 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2156 /* after avg_vals are acquired, we can re-stat the signal values */
2157 recvpriv->signal_strength_data.update_req = 1;
2160 if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */
2161 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2162 /* after avg_vals are acquired, we can re-stat the signal values */
2163 recvpriv->signal_qual_data.update_req = 1;
2166 /* update value of signal_strength, rssi, signal_qual */
2167 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) {
2168 tmp_s = avg_signal_strength+(_alpha-1)*recvpriv->signal_strength;
2170 tmp_s = tmp_s/_alpha + 1;
2172 tmp_s = tmp_s/_alpha;
2176 tmp_q = avg_signal_qual+(_alpha-1)*recvpriv->signal_qual;
2178 tmp_q = tmp_q/_alpha + 1;
2180 tmp_q = tmp_q/_alpha;
2184 recvpriv->signal_strength = tmp_s;
2185 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2186 recvpriv->signal_qual = tmp_q;
2189 rtw_set_signal_stat_timer(recvpriv);