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 _rtw_init_queue(&precvpriv->free_recv_queue);
67 _rtw_init_queue(&precvpriv->recv_pending_queue);
68 _rtw_init_queue(&precvpriv->uc_swdec_pending_queue);
70 precvpriv->adapter = padapter;
72 precvpriv->free_recvframe_cnt = NR_RECVFRAME;
74 precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(struct recv_frame) + RXFRAME_ALIGN_SZ);
76 if (precvpriv->pallocated_frame_buf == NULL) {
81 precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
83 precvframe = (struct recv_frame *)precvpriv->precv_frame_buf;
85 for (i = 0; i < NR_RECVFRAME; i++) {
86 _rtw_init_listhead(&(precvframe->list));
88 rtw_list_insert_tail(&(precvframe->list),
89 &(precvpriv->free_recv_queue.queue));
91 res = rtw_os_recv_resource_alloc(padapter, precvframe);
95 precvframe->adapter = padapter;
98 precvpriv->rx_pending_cnt = 1;
100 res = rtw_hal_init_recv_priv(padapter);
102 _init_timer(&precvpriv->signal_stat_timer, padapter->pnetdev, RTW_TIMER_HDL_NAME(signal_stat), padapter);
104 precvpriv->signal_stat_sampling_interval = 1000; /* ms */
106 rtw_set_signal_stat_timer(precvpriv);
113 void _rtw_free_recv_priv (struct recv_priv *precvpriv)
115 struct adapter *padapter = precvpriv->adapter;
118 rtw_free_uc_swdec_pending_queue(padapter);
120 if (precvpriv->pallocated_frame_buf) {
121 vfree(precvpriv->pallocated_frame_buf);
124 rtw_hal_free_recv_priv(padapter);
128 struct recv_frame *_rtw_alloc_recvframe (struct __queue *pfree_recv_queue)
130 struct recv_frame *hdr;
131 struct list_head *plist, *phead;
132 struct adapter *padapter;
133 struct recv_priv *precvpriv;
135 if (_rtw_queue_empty(pfree_recv_queue)) {
138 phead = get_list_head(pfree_recv_queue);
142 hdr = container_of(plist, struct recv_frame, list);
144 rtw_list_delete(&hdr->list);
145 padapter = hdr->adapter;
146 if (padapter != NULL) {
147 precvpriv = &padapter->recvpriv;
148 if (pfree_recv_queue == &precvpriv->free_recv_queue)
149 precvpriv->free_recvframe_cnt--;
154 return (struct recv_frame *)hdr;
157 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
159 struct recv_frame *precvframe;
161 spin_lock_bh(&pfree_recv_queue->lock);
163 precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
165 spin_unlock_bh(&pfree_recv_queue->lock);
170 void rtw_init_recvframe(struct recv_frame *precvframe, struct recv_priv *precvpriv)
172 /* Perry: This can be removed */
173 _rtw_init_listhead(&precvframe->list);
178 int rtw_free_recvframe(struct recv_frame *precvframe,
179 struct __queue *pfree_recv_queue)
181 struct adapter *padapter;
182 struct recv_priv *precvpriv;
186 padapter = precvframe->adapter;
187 precvpriv = &padapter->recvpriv;
188 if (precvframe->pkt) {
189 dev_kfree_skb_any(precvframe->pkt);/* free skb by driver */
190 precvframe->pkt = NULL;
193 spin_lock_bh(&pfree_recv_queue->lock);
195 rtw_list_delete(&(precvframe->list));
199 rtw_list_insert_tail(&(precvframe->list), get_list_head(pfree_recv_queue));
201 if (padapter != NULL) {
202 if (pfree_recv_queue == &precvpriv->free_recv_queue)
203 precvpriv->free_recvframe_cnt++;
206 spin_unlock_bh(&pfree_recv_queue->lock);
212 int _rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
214 struct adapter *padapter = precvframe->adapter;
215 struct recv_priv *precvpriv = &padapter->recvpriv;
218 rtw_list_delete(&(precvframe->list));
219 rtw_list_insert_tail(&(precvframe->list), get_list_head(queue));
221 if (padapter != NULL) {
222 if (queue == &precvpriv->free_recv_queue)
223 precvpriv->free_recvframe_cnt++;
230 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue)
234 spin_lock_bh(&queue->lock);
235 ret = _rtw_enqueue_recvframe(precvframe, queue);
236 spin_unlock_bh(&queue->lock);
242 caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
243 pframequeue: defrag_queue : will be accessed in recv_thread (passive)
245 using spinlock to protect
249 void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue)
251 struct recv_frame *hdr;
252 struct list_head *plist, *phead;
254 spin_lock(&pframequeue->lock);
256 phead = get_list_head(pframequeue);
259 while (rtw_end_of_queue_search(phead, plist) == false) {
260 hdr = container_of(plist, struct recv_frame, list);
264 rtw_free_recvframe((struct recv_frame *)hdr, pfree_recv_queue);
267 spin_unlock(&pframequeue->lock);
271 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter)
274 struct recv_frame *pending_frame;
275 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
276 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
277 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
284 static int recvframe_chkmic(struct adapter *adapter,
285 struct recv_frame *precvframe)
287 int i, res = _SUCCESS;
290 u8 bmic_err = false, brpt_micerror = true;
291 u8 *pframe, *payload, *pframemic;
293 struct sta_info *stainfo;
294 struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
295 struct security_priv *psecuritypriv = &adapter->securitypriv;
297 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
298 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
300 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
302 if (prxattrib->encrypt == _TKIP_) {
303 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic:prxattrib->encrypt==_TKIP_\n"));
304 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",
305 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2], prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5]));
307 /* calculate mic code */
308 if (stainfo != NULL) {
309 if (IS_MCAST(prxattrib->ra)) {
310 if (!psecuritypriv) {
312 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n"));
313 DBG_88E("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
316 mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
318 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic: bcmc key\n"));
320 mickey = &stainfo->dot11tkiprxmickey.skey[0];
321 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic: unicast key\n"));
324 /* icv_len included the mic code */
325 datalen = precvframe->len-prxattrib->hdrlen -
326 prxattrib->iv_len-prxattrib->icv_len-8;
327 pframe = precvframe->rx_data;
328 payload = pframe+prxattrib->hdrlen+prxattrib->iv_len;
330 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n", prxattrib->iv_len, prxattrib->icv_len));
331 rtw_seccalctkipmic(mickey, pframe, payload, datalen, &miccode[0],
332 (unsigned char)prxattrib->priority); /* care the length of the data */
334 pframemic = payload+datalen;
338 for (i = 0; i < 8; i++) {
339 if (miccode[i] != *(pframemic+i)) {
340 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
341 ("recvframe_chkmic:miccode[%d](%02x)!=*(pframemic+%d)(%02x) ",
342 i, miccode[i], i, *(pframemic+i)));
348 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
349 ("\n *(pframemic-8)-*(pframemic-1)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
350 *(pframemic-8), *(pframemic-7), *(pframemic-6),
351 *(pframemic-5), *(pframemic-4), *(pframemic-3),
352 *(pframemic-2), *(pframemic-1)));
353 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
354 ("\n *(pframemic-16)-*(pframemic-9)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
355 *(pframemic-16), *(pframemic-15), *(pframemic-14),
356 *(pframemic-13), *(pframemic-12), *(pframemic-11),
357 *(pframemic-10), *(pframemic-9)));
360 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
361 ("\n ======demp packet (len=%d)======\n",
363 for (i = 0; i < precvframe->len; i += 8) {
364 RT_TRACE(_module_rtl871x_recv_c_,
366 ("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
367 *(precvframe->rx_data+i),
368 *(precvframe->rx_data+i+1),
369 *(precvframe->rx_data+i+2),
370 *(precvframe->rx_data+i+3),
371 *(precvframe->rx_data+i+4),
372 *(precvframe->rx_data+i+5),
373 *(precvframe->rx_data+i+6),
374 *(precvframe->rx_data+i+7)));
376 RT_TRACE(_module_rtl871x_recv_c_,
378 ("\n ====== demp packet end [len=%d]======\n",
380 RT_TRACE(_module_rtl871x_recv_c_,
386 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
387 ("ra=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x psecuritypriv->binstallGrpkey=%d ",
388 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2],
389 prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5], psecuritypriv->binstallGrpkey));
391 /* double check key_index for some timing issue , */
392 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
393 if ((IS_MCAST(prxattrib->ra) == true) && (prxattrib->key_index != pmlmeinfo->key_index))
394 brpt_micerror = false;
396 if ((prxattrib->bdecrypted) && (brpt_micerror)) {
397 rtw_handle_tkip_mic_err(adapter, (u8)IS_MCAST(prxattrib->ra));
398 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
399 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
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);
407 if ((!psecuritypriv->bcheck_grpkey) && (IS_MCAST(prxattrib->ra))) {
408 psecuritypriv->bcheck_grpkey = true;
409 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("psecuritypriv->bcheck_grpkey = true"));
413 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
416 recvframe_pull_tail(precvframe, 8);
425 /* decrypt and set the ivlen, icvlen of the recv_frame */
426 static struct recv_frame *decryptor(struct adapter *padapter,
427 struct recv_frame *precv_frame)
429 struct rx_pkt_attrib *prxattrib = &precv_frame->attrib;
430 struct security_priv *psecuritypriv = &padapter->securitypriv;
431 struct recv_frame *return_packet = precv_frame;
434 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("prxstat->decrypted=%x prxattrib->encrypt=0x%03x\n", prxattrib->bdecrypted, prxattrib->encrypt));
436 if (prxattrib->encrypt > 0) {
437 u8 *iv = precv_frame->rx_data+prxattrib->hdrlen;
438 prxattrib->key_index = (((iv[3])>>6)&0x3);
440 if (prxattrib->key_index > WEP_KEYS) {
441 DBG_88E("prxattrib->key_index(%d)>WEP_KEYS\n", prxattrib->key_index);
443 switch (prxattrib->encrypt) {
446 prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
451 prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
457 if ((prxattrib->encrypt > 0) && ((prxattrib->bdecrypted == 0) || (psecuritypriv->sw_decrypt))) {
458 psecuritypriv->hw_decrypted = false;
460 switch (prxattrib->encrypt) {
463 rtw_wep_decrypt(padapter, (u8 *)precv_frame);
466 res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
469 res = rtw_aes_decrypt(padapter, (u8 *)precv_frame);
474 } else if (prxattrib->bdecrypted == 1 && prxattrib->encrypt > 0 &&
475 (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_))
476 psecuritypriv->hw_decrypted = true;
479 rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue);
480 return_packet = NULL;
484 return return_packet;
487 /* set the security information in the recv_frame */
488 static struct recv_frame *portctrl(struct adapter *adapter,
489 struct recv_frame *precv_frame)
493 struct recv_frame *pfhdr;
494 struct sta_info *psta;
495 struct sta_priv *pstapriv;
496 struct recv_frame *prtnframe;
498 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */
499 struct rx_pkt_attrib *pattrib;
503 pstapriv = &adapter->stapriv;
505 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
507 ptr = precv_frame->rx_data;
509 pattrib = &pfhdr->attrib;
510 psta_addr = pattrib->ta;
511 psta = rtw_get_stainfo(pstapriv, psta_addr);
515 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n", adapter->securitypriv.dot11AuthAlgrthm));
519 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE;
520 memcpy(&be_tmp, ptr, 2);
521 ether_type = ntohs(be_tmp);
523 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
525 /* only accept EAPOL frame */
526 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==1\n"));
528 if (ether_type == eapol_type) {
529 prtnframe = precv_frame;
531 /* free this frame */
532 rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
537 /* check decryption status, and decrypt the frame if needed */
538 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==0\n"));
539 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
540 ("portctrl:precv_frame->hdr.attrib.privacy=%x\n",
541 precv_frame->attrib.privacy));
543 if (pattrib->bdecrypted == 0)
544 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("portctrl:prxstat->decrypted=%x\n", pattrib->bdecrypted));
546 prtnframe = precv_frame;
547 /* check is the EAPOL frame or not (Rekey) */
548 if (ether_type == eapol_type) {
549 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("########portctrl:ether_type==0x888e\n"));
552 prtnframe = precv_frame;
554 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:ether_type=0x%04x\n", ether_type));
558 prtnframe = precv_frame;
565 static int recv_decache(struct recv_frame *precv_frame, u8 bretry,
566 struct stainfo_rxcache *prxcache)
568 int tid = precv_frame->attrib.priority;
570 u16 seq_ctrl = ((precv_frame->attrib.seq_num&0xffff) << 4) |
571 (precv_frame->attrib.frag_num & 0xf);
575 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid));
580 if (1) {/* if (bretry) */
581 if (seq_ctrl == prxcache->tid_rxseq[tid]) {
582 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]));
588 prxcache->tid_rxseq[tid] = seq_ctrl;
594 static void process_pwrbit_data(struct adapter *padapter,
595 struct recv_frame *precv_frame)
597 #ifdef CONFIG_88EU_AP_MODE
598 unsigned char pwrbit;
599 u8 *ptr = precv_frame->rx_data;
600 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
601 struct sta_priv *pstapriv = &padapter->stapriv;
602 struct sta_info *psta = NULL;
604 psta = rtw_get_stainfo(pstapriv, pattrib->src);
606 pwrbit = GetPwrMgt(ptr);
610 if (!(psta->state & WIFI_SLEEP_STATE))
611 stop_sta_xmit(padapter, psta);
613 if (psta->state & WIFI_SLEEP_STATE)
614 wakeup_sta_to_xmit(padapter, psta);
621 static void process_wmmps_data(struct adapter *padapter,
622 struct recv_frame *precv_frame)
624 #ifdef CONFIG_88EU_AP_MODE
625 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
626 struct sta_priv *pstapriv = &padapter->stapriv;
627 struct sta_info *psta = NULL;
629 psta = rtw_get_stainfo(pstapriv, pattrib->src);
634 if (!psta->qos_option)
637 if (!(psta->qos_info&0xf))
640 if (psta->state&WIFI_SLEEP_STATE) {
643 switch (pattrib->priority) {
646 wmmps_ac = psta->uapsd_bk&BIT(1);
650 wmmps_ac = psta->uapsd_vi&BIT(1);
654 wmmps_ac = psta->uapsd_vo&BIT(1);
659 wmmps_ac = psta->uapsd_be&BIT(1);
664 if (psta->sleepq_ac_len > 0) {
665 /* process received triggered frame */
666 xmit_delivery_enabled_frames(padapter, psta);
668 /* issue one qos null frame with More data bit = 0 and the EOSP bit set (= 1) */
669 issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0);
677 static void count_rx_stats(struct adapter *padapter,
678 struct recv_frame *prframe,
679 struct sta_info *sta)
682 struct sta_info *psta = NULL;
683 struct stainfo_stats *pstats = NULL;
684 struct rx_pkt_attrib *pattrib = &prframe->attrib;
685 struct recv_priv *precvpriv = &padapter->recvpriv;
688 precvpriv->rx_bytes += sz;
690 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
692 if ((!MacAddr_isBcst(pattrib->dst)) && (!IS_MCAST(pattrib->dst)))
693 padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
698 psta = prframe->psta;
701 pstats = &psta->sta_stats;
703 pstats->rx_data_pkts++;
704 pstats->rx_bytes += sz;
708 int sta2sta_data_frame(
709 struct adapter *adapter,
710 struct recv_frame *precv_frame,
711 struct sta_info **psta
714 int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
715 struct sta_info **psta)
717 u8 *ptr = precv_frame->rx_data;
719 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
720 struct sta_priv *pstapriv = &adapter->stapriv;
721 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
722 u8 *mybssid = get_bssid(pmlmepriv);
723 u8 *myhwaddr = myid(&adapter->eeprompriv);
725 int bmcast = IS_MCAST(pattrib->dst);
728 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
729 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
730 /* filter packets that SA is myself or multicast or broadcast */
731 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
732 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
737 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
742 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
743 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
744 memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
749 sta_addr = pattrib->src;
750 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
751 /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */
752 if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN)) {
753 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("bssid!=TA under STATION_MODE; drop pkt\n"));
757 sta_addr = pattrib->bssid;
758 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
760 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
761 if (!IS_MCAST(pattrib->bssid)) {
765 } else { /* not mc-frame */
766 /* For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID */
767 if (memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN)) {
772 sta_addr = pattrib->src;
774 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
775 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
776 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
777 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
778 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
779 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
787 *psta = rtw_get_bcmc_stainfo(adapter);
789 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */
792 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under sta2sta_data_frame ; drop pkt\n"));
793 if (adapter->registrypriv.mp_mode == 1) {
794 if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
795 adapter->mppriv.rx_pktloss++;
805 static int ap2sta_data_frame (
806 struct adapter *adapter,
807 struct recv_frame *precv_frame,
808 struct sta_info **psta)
810 u8 *ptr = precv_frame->rx_data;
811 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
813 struct sta_priv *pstapriv = &adapter->stapriv;
814 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
815 u8 *mybssid = get_bssid(pmlmepriv);
816 u8 *myhwaddr = myid(&adapter->eeprompriv);
817 int bmcast = IS_MCAST(pattrib->dst);
820 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) &&
821 (check_fwstate(pmlmepriv, _FW_LINKED) == true ||
822 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) {
823 /* filter packets that SA is myself or multicast or broadcast */
824 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
825 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
830 /* da should be for me */
831 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
832 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
833 (" ap2sta_data_frame: compare DA fail; DA=%pM\n", (pattrib->dst)));
839 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
840 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
841 (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
842 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
843 (" ap2sta_data_frame: compare BSSID fail ; BSSID=%pM\n", (pattrib->bssid)));
844 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("mybssid=%pM\n", (mybssid)));
847 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid));
848 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
856 *psta = rtw_get_bcmc_stainfo(adapter);
858 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */
861 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
866 /* if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) { */
869 if (GetFrameSubType(ptr) & BIT(6)) {
870 /* No data, will not indicate to upper layer, temporily count it here */
871 count_rx_stats(adapter, precv_frame, *psta);
872 ret = RTW_RX_HANDLED;
875 } else if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) &&
876 (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
877 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
878 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
879 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
880 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
881 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
884 memcpy(pattrib->bssid, mybssid, ETH_ALEN);
886 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
888 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under MP_MODE ; drop pkt\n"));
892 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
894 ret = RTW_RX_HANDLED;
897 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
898 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
900 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid));
902 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
915 static int sta2ap_data_frame(struct adapter *adapter,
916 struct recv_frame *precv_frame,
917 struct sta_info **psta)
919 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
920 struct sta_priv *pstapriv = &adapter->stapriv;
921 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
922 u8 *ptr = precv_frame->rx_data;
923 unsigned char *mybssid = get_bssid(pmlmepriv);
927 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
928 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */
929 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
934 *psta = rtw_get_stainfo(pstapriv, pattrib->src);
936 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under AP_MODE; drop pkt\n"));
937 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
939 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
941 ret = RTW_RX_HANDLED;
945 process_pwrbit_data(adapter, precv_frame);
947 if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) {
948 process_wmmps_data(adapter, precv_frame);
951 if (GetFrameSubType(ptr) & BIT(6)) {
952 /* No data, will not indicate to upper layer, temporily count it here */
953 count_rx_stats(adapter, precv_frame, *psta);
954 ret = RTW_RX_HANDLED;
958 u8 *myhwaddr = myid(&adapter->eeprompriv);
959 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
960 ret = RTW_RX_HANDLED;
963 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
964 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
965 ret = RTW_RX_HANDLED;
975 static int validate_recv_ctrl_frame(struct adapter *padapter,
976 struct recv_frame *precv_frame)
978 #ifdef CONFIG_88EU_AP_MODE
979 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
980 struct sta_priv *pstapriv = &padapter->stapriv;
981 u8 *pframe = precv_frame->rx_data;
983 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
986 /* receive the frames that ra(a1) is my address */
987 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN))
990 /* only handle ps-poll */
991 if (GetFrameSubType(pframe) == WIFI_PSPOLL) {
994 struct sta_info *psta = NULL;
996 aid = GetAid(pframe);
997 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
999 if ((psta == NULL) || (psta->aid != aid))
1002 /* for rx pkt statistics */
1003 psta->sta_stats.rx_ctrl_pkts++;
1005 switch (pattrib->priority) {
1008 wmmps_ac = psta->uapsd_bk&BIT(0);
1012 wmmps_ac = psta->uapsd_vi&BIT(0);
1016 wmmps_ac = psta->uapsd_vo&BIT(0);
1021 wmmps_ac = psta->uapsd_be&BIT(0);
1028 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
1029 DBG_88E("%s alive check-rx ps-poll\n", __func__);
1030 psta->expire_to = pstapriv->expire_to;
1031 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
1034 if ((psta->state&WIFI_SLEEP_STATE) && (pstapriv->sta_dz_bitmap&BIT(psta->aid))) {
1035 struct list_head *xmitframe_plist, *xmitframe_phead;
1036 struct xmit_frame *pxmitframe = NULL;
1038 spin_lock_bh(&psta->sleep_q.lock);
1040 xmitframe_phead = get_list_head(&psta->sleep_q);
1041 xmitframe_plist = xmitframe_phead->next;
1043 if ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == false) {
1044 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
1046 xmitframe_plist = xmitframe_plist->next;
1048 rtw_list_delete(&pxmitframe->list);
1052 if (psta->sleepq_len > 0)
1053 pxmitframe->attrib.mdata = 1;
1055 pxmitframe->attrib.mdata = 0;
1057 pxmitframe->attrib.triggered = 1;
1059 spin_unlock_bh(&psta->sleep_q.lock);
1060 if (rtw_hal_xmit(padapter, pxmitframe) == true)
1061 rtw_os_xmit_complete(padapter, pxmitframe);
1062 spin_lock_bh(&psta->sleep_q.lock);
1064 if (psta->sleepq_len == 0) {
1065 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1067 /* update BCN for TIM IE */
1068 /* update_BCNTIM(padapter); */
1069 update_beacon(padapter, _TIM_IE_, NULL, false);
1072 if (pstapriv->tim_bitmap&BIT(psta->aid)) {
1073 if (psta->sleepq_len == 0) {
1074 DBG_88E("no buffered packets to xmit\n");
1076 /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */
1077 issue_nulldata(padapter, psta->hwaddr, 0, 0, 0);
1079 DBG_88E("error!psta->sleepq_len=%d\n", psta->sleepq_len);
1080 psta->sleepq_len = 0;
1083 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1085 /* update BCN for TIM IE */
1086 /* update_BCNTIM(padapter); */
1087 update_beacon(padapter, _TIM_IE_, NULL, false);
1091 spin_unlock_bh(&psta->sleep_q.lock);
1100 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1101 struct recv_frame *precv_frame);
1103 static int validate_recv_mgnt_frame(struct adapter *padapter,
1104 struct recv_frame *precv_frame)
1106 struct sta_info *psta;
1108 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("+validate_recv_mgnt_frame\n"));
1110 precv_frame = recvframe_chk_defrag(padapter, precv_frame);
1111 if (precv_frame == NULL) {
1112 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("%s: fragment packet\n", __func__));
1116 /* for rx pkt statistics */
1117 psta = rtw_get_stainfo(&padapter->stapriv,
1118 GetAddr2Ptr(precv_frame->rx_data));
1120 psta->sta_stats.rx_mgnt_pkts++;
1121 if (GetFrameSubType(precv_frame->rx_data) == WIFI_BEACON) {
1122 psta->sta_stats.rx_beacon_pkts++;
1123 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBEREQ) {
1124 psta->sta_stats.rx_probereq_pkts++;
1125 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBERSP) {
1126 if (!memcmp(padapter->eeprompriv.mac_addr,
1127 GetAddr1Ptr(precv_frame->rx_data), ETH_ALEN))
1128 psta->sta_stats.rx_probersp_pkts++;
1129 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)) ||
1130 is_multicast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)))
1131 psta->sta_stats.rx_probersp_bm_pkts++;
1133 psta->sta_stats.rx_probersp_uo_pkts++;
1137 mgt_dispatcher(padapter, precv_frame);
1142 static int validate_recv_data_frame(struct adapter *adapter,
1143 struct recv_frame *precv_frame)
1146 u8 *psa, *pda, *pbssid;
1147 struct sta_info *psta = NULL;
1148 u8 *ptr = precv_frame->rx_data;
1149 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1150 struct security_priv *psecuritypriv = &adapter->securitypriv;
1154 bretry = GetRetry(ptr);
1157 pbssid = get_hdr_bssid(ptr);
1159 if (pbssid == NULL) {
1164 memcpy(pattrib->dst, pda, ETH_ALEN);
1165 memcpy(pattrib->src, psa, ETH_ALEN);
1167 memcpy(pattrib->bssid, pbssid, ETH_ALEN);
1169 switch (pattrib->to_fr_ds) {
1171 memcpy(pattrib->ra, pda, ETH_ALEN);
1172 memcpy(pattrib->ta, psa, ETH_ALEN);
1173 ret = sta2sta_data_frame(adapter, precv_frame, &psta);
1176 memcpy(pattrib->ra, pda, ETH_ALEN);
1177 memcpy(pattrib->ta, pbssid, ETH_ALEN);
1178 ret = ap2sta_data_frame(adapter, precv_frame, &psta);
1181 memcpy(pattrib->ra, pbssid, ETH_ALEN);
1182 memcpy(pattrib->ta, psa, ETH_ALEN);
1183 ret = sta2ap_data_frame(adapter, precv_frame, &psta);
1186 memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
1187 memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
1189 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" case 3\n"));
1198 } else if (ret == RTW_RX_HANDLED) {
1203 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" after to_fr_ds_chk; psta==NULL\n"));
1208 /* psta->rssi = prxcmd->rssi; */
1209 /* psta->signal_quality = prxcmd->sq; */
1210 precv_frame->psta = psta;
1213 pattrib->ack_policy = 0;
1214 /* parsing QC field */
1215 if (pattrib->qos == 1) {
1216 pattrib->priority = GetPriority((ptr + 24));
1217 pattrib->ack_policy = GetAckpolicy((ptr + 24));
1218 pattrib->amsdu = GetAMsdu((ptr + 24));
1219 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26;
1221 if (pattrib->priority != 0 && pattrib->priority != 3)
1222 adapter->recvpriv.bIsAnyNonBEPkts = true;
1224 pattrib->priority = 0;
1225 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24;
1228 if (pattrib->order)/* HT-CTRL 11n */
1229 pattrib->hdrlen += 4;
1231 precv_frame->preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
1233 /* decache, drop duplicate recv packets */
1234 if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) {
1235 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decache : drop pkt\n"));
1240 if (pattrib->privacy) {
1241 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("validate_recv_data_frame:pattrib->privacy=%x\n", pattrib->privacy));
1242 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)));
1244 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra));
1246 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n pattrib->encrypt=%d\n", pattrib->encrypt));
1248 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
1250 pattrib->encrypt = 0;
1251 pattrib->iv_len = 0;
1252 pattrib->icv_len = 0;
1261 static int validate_recv_frame(struct adapter *adapter,
1262 struct recv_frame *precv_frame)
1264 /* shall check frame subtype, to / from ds, da, bssid */
1266 /* then call check if rx seq/frag. duplicated. */
1270 int retval = _SUCCESS;
1272 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1273 u8 *ptr = precv_frame->rx_data;
1274 u8 ver = (unsigned char) (*ptr)&0x3;
1275 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1278 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
1279 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
1280 if (ch_set_idx >= 0)
1281 pmlmeext->channel_set[ch_set_idx].rx_count++;
1284 /* add version chk */
1286 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! (ver!=0)\n"));
1291 type = GetFrameType(ptr);
1292 subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */
1294 pattrib->to_fr_ds = get_tofr_ds(ptr);
1296 pattrib->frag_num = GetFragNum(ptr);
1297 pattrib->seq_num = GetSequence(ptr);
1299 pattrib->pw_save = GetPwrMgt(ptr);
1300 pattrib->mfrag = GetMFrag(ptr);
1301 pattrib->mdata = GetMData(ptr);
1302 pattrib->privacy = GetPrivacy(ptr);
1303 pattrib->order = GetOrder(ptr);
1305 /* Dump rx packets */
1306 rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
1307 if (bDumpRxPkt == 1) {/* dump all rx packets */
1309 DBG_88E("#############################\n");
1311 for (i = 0; i < 64; i = i+8)
1312 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1313 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1314 DBG_88E("#############################\n");
1315 } else if (bDumpRxPkt == 2) {
1316 if (type == WIFI_MGT_TYPE) {
1318 DBG_88E("#############################\n");
1320 for (i = 0; i < 64; i = i+8)
1321 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1322 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1323 DBG_88E("#############################\n");
1325 } else if (bDumpRxPkt == 3) {
1326 if (type == WIFI_DATA_TYPE) {
1328 DBG_88E("#############################\n");
1330 for (i = 0; i < 64; i = i+8)
1331 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1332 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1333 DBG_88E("#############################\n");
1337 case WIFI_MGT_TYPE: /* mgnt */
1338 retval = validate_recv_mgnt_frame(adapter, precv_frame);
1339 if (retval == _FAIL)
1340 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_mgnt_frame fail\n"));
1341 retval = _FAIL; /* only data frame return _SUCCESS */
1343 case WIFI_CTRL_TYPE: /* ctrl */
1344 retval = validate_recv_ctrl_frame(adapter, precv_frame);
1345 if (retval == _FAIL)
1346 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_ctrl_frame fail\n"));
1347 retval = _FAIL; /* only data frame return _SUCCESS */
1349 case WIFI_DATA_TYPE: /* data */
1350 rtw_led_control(adapter, LED_CTL_RX);
1351 pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
1352 retval = validate_recv_data_frame(adapter, precv_frame);
1353 if (retval == _FAIL) {
1354 struct recv_priv *precvpriv = &adapter->recvpriv;
1355 precvpriv->rx_drop++;
1359 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! type= 0x%x\n", type));
1370 /* remove the wlanhdr and add the eth_hdr */
1372 static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1379 struct ieee80211_snap_hdr *psnap;
1382 struct adapter *adapter = precvframe->adapter;
1383 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1384 u8 *ptr = precvframe->rx_data;
1385 struct rx_pkt_attrib *pattrib = &precvframe->attrib;
1387 if (pattrib->encrypt)
1388 recvframe_pull_tail(precvframe, pattrib->icv_len);
1390 psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
1391 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
1392 /* convert hdr + possible LLC headers into Ethernet header */
1393 if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
1394 (!memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) == false) &&
1395 (!memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2) == false)) ||
1396 !memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) {
1397 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1400 /* Leave Ethernet header part of hdr and full payload */
1404 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0);
1405 len = precvframe->len - rmv_len;
1407 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
1408 ("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x===\n\n", pattrib->hdrlen, pattrib->iv_len));
1410 memcpy(&be_tmp, ptr+rmv_len, 2);
1411 eth_type = ntohs(be_tmp); /* pattrib->ether_type */
1412 pattrib->eth_type = eth_type;
1414 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE))) {
1420 /* append rx status for mp test packets */
1421 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24);
1424 memcpy(ptr, get_rxmem(precvframe), 24);
1427 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
1432 memcpy(ptr, pattrib->dst, ETH_ALEN);
1433 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
1436 be_tmp = htons(len);
1437 memcpy(ptr+12, &be_tmp, 2);
1443 /* perform defrag */
1444 static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1445 struct __queue *defrag_q)
1447 struct list_head *plist, *phead;
1450 struct recv_frame *pfhdr, *pnfhdr;
1451 struct recv_frame *prframe, *pnextrframe;
1452 struct __queue *pfree_recv_queue;
1456 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
1458 phead = get_list_head(defrag_q);
1459 plist = phead->next;
1460 pfhdr = container_of(plist, struct recv_frame, list);
1461 prframe = (struct recv_frame *)pfhdr;
1462 rtw_list_delete(&(prframe->list));
1464 if (curfragnum != pfhdr->attrib.frag_num) {
1465 /* the first fragment number must be 0 */
1466 /* free the whole queue */
1467 rtw_free_recvframe(prframe, pfree_recv_queue);
1468 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1475 plist = get_list_head(defrag_q);
1477 plist = plist->next;
1479 while (rtw_end_of_queue_search(phead, plist) == false) {
1480 pnfhdr = container_of(plist, struct recv_frame, list);
1481 pnextrframe = (struct recv_frame *)pnfhdr;
1483 /* check the fragment sequence (2nd ~n fragment frame) */
1485 if (curfragnum != pnfhdr->attrib.frag_num) {
1486 /* the fragment number must be increasing (after decache) */
1487 /* release the defrag_q & prframe */
1488 rtw_free_recvframe(prframe, pfree_recv_queue);
1489 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1495 /* copy the 2nd~n fragment frame's payload to the first fragment */
1496 /* get the 2nd~last fragment frame's payload */
1498 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1500 recvframe_pull(pnextrframe, wlanhdr_offset);
1502 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1503 recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
1506 memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
1508 recvframe_put(prframe, pnfhdr->len);
1510 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
1511 plist = plist->next;
1514 /* free the defrag_q queue and return the prframe */
1515 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1517 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Performance defrag!!!!!\n"));
1523 /* check if need to defrag, if needed queue the frame to defrag_q */
1524 struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1525 struct recv_frame *precv_frame)
1530 struct recv_frame *pfhdr;
1531 struct sta_info *psta;
1532 struct sta_priv *pstapriv;
1533 struct list_head *phead;
1534 struct recv_frame *prtnframe = NULL;
1535 struct __queue *pfree_recv_queue, *pdefrag_q;
1538 pstapriv = &padapter->stapriv;
1540 pfhdr = precv_frame;
1542 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1544 /* need to define struct of wlan header frame ctrl */
1545 ismfrag = pfhdr->attrib.mfrag;
1546 fragnum = pfhdr->attrib.frag_num;
1548 psta_addr = pfhdr->attrib.ta;
1549 psta = rtw_get_stainfo(pstapriv, psta_addr);
1551 u8 type = GetFrameType(pfhdr->rx_data);
1552 if (type != WIFI_DATA_TYPE) {
1553 psta = rtw_get_bcmc_stainfo(padapter);
1554 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1559 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1562 if ((ismfrag == 0) && (fragnum == 0))
1563 prtnframe = precv_frame;/* isn't a fragment frame */
1566 /* 0~(n-1) fragment frame */
1567 /* enqueue to defraf_g */
1568 if (pdefrag_q != NULL) {
1570 /* the first fragment */
1571 if (_rtw_queue_empty(pdefrag_q) == false) {
1572 /* free current defrag_q */
1573 rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
1577 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1579 phead = get_list_head(pdefrag_q);
1580 rtw_list_insert_tail(&pfhdr->list, phead);
1582 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Enqueuq: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1586 /* can't find this ta's defrag_queue, so free this recv_frame */
1587 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1589 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1593 if ((ismfrag == 0) && (fragnum != 0)) {
1594 /* the last fragment frame */
1595 /* enqueue the last fragment */
1596 if (pdefrag_q != NULL) {
1597 phead = get_list_head(pdefrag_q);
1598 rtw_list_insert_tail(&pfhdr->list, phead);
1600 /* call recvframe_defrag to defrag */
1601 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("defrag: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1602 precv_frame = recvframe_defrag(padapter, pdefrag_q);
1603 prtnframe = precv_frame;
1605 /* can't find this ta's defrag_queue, so free this recv_frame */
1606 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1608 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1612 if ((prtnframe != NULL) && (prtnframe->attrib.privacy)) {
1613 /* after defrag we must check tkip mic code */
1614 if (recvframe_chkmic(padapter, prtnframe) == _FAIL) {
1615 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic(padapter, prtnframe)==_FAIL\n"));
1616 rtw_free_recvframe(prtnframe, pfree_recv_queue);
1625 static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1627 int a_len, padding_len;
1628 u16 eth_type, nSubframe_Length;
1630 unsigned char *pdata;
1631 struct rx_pkt_attrib *pattrib;
1632 unsigned char *data_ptr;
1633 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1634 struct recv_priv *precvpriv = &padapter->recvpriv;
1635 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1639 pattrib = &prframe->attrib;
1641 recvframe_pull(prframe, prframe->attrib.hdrlen);
1643 if (prframe->attrib.iv_len > 0)
1644 recvframe_pull(prframe, prframe->attrib.iv_len);
1646 a_len = prframe->len;
1648 pdata = prframe->rx_data;
1650 while (a_len > ETH_HLEN) {
1651 /* Offset 12 denote 2 mac address */
1652 nSubframe_Length = RTW_GET_BE16(pdata + 12);
1654 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
1655 DBG_88E("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len, nSubframe_Length);
1659 /* move the data point to data content */
1663 /* Allocate new skb for releasing to upper layer */
1664 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1666 skb_reserve(sub_skb, 12);
1667 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
1668 memcpy(data_ptr, pdata, nSubframe_Length);
1670 sub_skb = skb_clone(prframe->pkt, GFP_ATOMIC);
1672 sub_skb->data = pdata;
1673 sub_skb->len = nSubframe_Length;
1674 skb_set_tail_pointer(sub_skb, nSubframe_Length);
1676 DBG_88E("skb_clone() Fail!!! , nr_subframes=%d\n", nr_subframes);
1681 subframes[nr_subframes++] = sub_skb;
1683 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
1684 DBG_88E("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1688 pdata += nSubframe_Length;
1689 a_len -= nSubframe_Length;
1691 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4-1));
1692 if (padding_len == 4) {
1696 if (a_len < padding_len) {
1699 pdata += padding_len;
1700 a_len -= padding_len;
1704 for (i = 0; i < nr_subframes; i++) {
1705 sub_skb = subframes[i];
1706 /* convert hdr + possible LLC headers into Ethernet header */
1707 eth_type = RTW_GET_BE16(&sub_skb->data[6]);
1708 if (sub_skb->len >= 8 &&
1709 ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
1710 eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
1711 !memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
1712 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1713 skb_pull(sub_skb, SNAP_SIZE);
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 /* Leave Ethernet header part of hdr and full payload */
1719 len = htons(sub_skb->len);
1720 memcpy(skb_push(sub_skb, 2), &len, 2);
1721 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1722 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1725 /* Indicate the packets to upper layer */
1726 /* Insert NAT2.5 RX here! */
1727 sub_skb->protocol = eth_type_trans(sub_skb, padapter->pnetdev);
1728 sub_skb->dev = padapter->pnetdev;
1730 sub_skb->ip_summed = CHECKSUM_NONE;
1738 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1743 static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
1745 u8 wsize = preorder_ctrl->wsize_b;
1746 u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF;/* 4096; */
1748 /* Rx Reorder initialize condition. */
1749 if (preorder_ctrl->indicate_seq == 0xFFFF)
1750 preorder_ctrl->indicate_seq = seq_num;
1752 /* Drop out the packet which SeqNum is smaller than WinStart */
1753 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
1757 /* Sliding window manipulation. Conditions includes: */
1758 /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */
1759 /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */
1761 if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) {
1762 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1763 } else if (SN_LESS(wend, seq_num)) {
1764 if (seq_num >= (wsize - 1))
1765 preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
1767 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
1773 static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
1774 struct recv_frame *prframe)
1776 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1777 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1778 struct list_head *phead, *plist;
1779 struct recv_frame *hdr;
1780 struct rx_pkt_attrib *pnextattrib;
1782 phead = get_list_head(ppending_recvframe_queue);
1783 plist = phead->next;
1785 while (rtw_end_of_queue_search(phead, plist) == false) {
1786 hdr = container_of(plist, struct recv_frame, list);
1787 pnextattrib = &hdr->attrib;
1789 if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
1790 plist = plist->next;
1791 else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
1797 rtw_list_delete(&(prframe->list));
1799 rtw_list_insert_tail(&(prframe->list), plist);
1803 static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
1805 struct list_head *phead, *plist;
1806 struct recv_frame *prframe;
1807 struct recv_frame *prhdr;
1808 struct rx_pkt_attrib *pattrib;
1809 int bPktInBuf = false;
1810 struct recv_priv *precvpriv = &padapter->recvpriv;
1811 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1813 phead = get_list_head(ppending_recvframe_queue);
1814 plist = phead->next;
1816 /* Handling some condition for forced indicate case. */
1818 if (rtw_is_list_empty(phead))
1821 prhdr = container_of(plist, struct recv_frame, list);
1822 pattrib = &prhdr->attrib;
1823 preorder_ctrl->indicate_seq = pattrib->seq_num;
1826 /* Prepare indication list and indication. */
1827 /* Check if there is any packet need indicate. */
1828 while (!rtw_is_list_empty(phead)) {
1829 prhdr = container_of(plist, struct recv_frame, list);
1830 prframe = (struct recv_frame *)prhdr;
1831 pattrib = &prframe->attrib;
1833 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
1834 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1835 ("recv_indicatepkts_in_order: indicate=%d seq=%d amsdu=%d\n",
1836 preorder_ctrl->indicate_seq, pattrib->seq_num, pattrib->amsdu));
1837 plist = plist->next;
1838 rtw_list_delete(&(prframe->list));
1840 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
1841 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1843 /* Set this as a lock to make sure that only one thread is indicating packet. */
1845 /* indicate this recv_frame */
1846 if (!pattrib->amsdu) {
1847 if ((!padapter->bDriverStopped) &&
1848 (!padapter->bSurpriseRemoved))
1849 rtw_recv_indicatepkt(padapter, prframe);/* indicate this recv_frame */
1850 } else if (pattrib->amsdu == 1) {
1851 if (amsdu_to_msdu(padapter, prframe) != _SUCCESS)
1852 rtw_free_recvframe(prframe, &precvpriv->free_recv_queue);
1854 /* error condition; */
1857 /* Update local variables. */
1867 static int recv_indicatepkt_reorder(struct adapter *padapter,
1868 struct recv_frame *prframe)
1870 int retval = _SUCCESS;
1871 struct rx_pkt_attrib *pattrib = &prframe->attrib;
1872 struct recv_reorder_ctrl *preorder_ctrl = prframe->preorder_ctrl;
1873 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1875 if (!pattrib->amsdu) {
1877 wlanhdr_to_ethhdr(prframe);
1879 if ((pattrib->qos != 1) || (pattrib->eth_type == 0x0806) ||
1880 (pattrib->ack_policy != 0)) {
1881 if ((!padapter->bDriverStopped) &&
1882 (!padapter->bSurpriseRemoved)) {
1883 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ recv_indicatepkt_reorder -recv_func recv_indicatepkt\n"));
1885 rtw_recv_indicatepkt(padapter, prframe);
1892 if (!preorder_ctrl->enable) {
1893 /* indicate this recv_frame */
1894 preorder_ctrl->indicate_seq = pattrib->seq_num;
1895 rtw_recv_indicatepkt(padapter, prframe);
1897 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1900 } else if (pattrib->amsdu == 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */
1901 if (!preorder_ctrl->enable) {
1902 preorder_ctrl->indicate_seq = pattrib->seq_num;
1903 retval = amsdu_to_msdu(padapter, prframe);
1905 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1910 spin_lock_bh(&ppending_recvframe_queue->lock);
1912 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1913 ("recv_indicatepkt_reorder: indicate=%d seq=%d\n",
1914 preorder_ctrl->indicate_seq, pattrib->seq_num));
1916 /* s2. check if winstart_b(indicate_seq) needs to been updated */
1917 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) {
1918 rtw_recv_indicatepkt(padapter, prframe);
1920 spin_unlock_bh(&ppending_recvframe_queue->lock);
1925 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1926 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
1930 /* Indication process. */
1931 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
1932 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
1934 /* For Rx Reorder condition: */
1935 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
1936 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
1939 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */
1940 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
1941 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
1942 spin_unlock_bh(&ppending_recvframe_queue->lock);
1944 spin_unlock_bh(&ppending_recvframe_queue->lock);
1945 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
1954 spin_unlock_bh(&ppending_recvframe_queue->lock);
1959 void rtw_reordering_ctrl_timeout_handler(void *pcontext)
1961 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)pcontext;
1962 struct adapter *padapter = preorder_ctrl->padapter;
1963 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1965 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
1968 spin_lock_bh(&ppending_recvframe_queue->lock);
1970 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, true) == true)
1971 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
1973 spin_unlock_bh(&ppending_recvframe_queue->lock);
1976 static int process_recv_indicatepkts(struct adapter *padapter,
1977 struct recv_frame *prframe)
1979 int retval = _SUCCESS;
1980 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1981 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
1983 if (phtpriv->ht_option) { /* B/G/N Mode */
1984 if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) {
1985 /* including perform A-MPDU Rx Ordering Buffer Control */
1986 if ((!padapter->bDriverStopped) &&
1987 (!padapter->bSurpriseRemoved)) {
1992 } else { /* B/G mode */
1993 retval = wlanhdr_to_ethhdr (prframe);
1994 if (retval != _SUCCESS) {
1995 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("wlanhdr_to_ethhdr: drop pkt\n"));
1999 if ((!padapter->bDriverStopped) &&
2000 (!padapter->bSurpriseRemoved)) {
2001 /* indicate this recv_frame */
2002 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func recv_indicatepkt\n"));
2003 rtw_recv_indicatepkt(padapter, prframe);
2005 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func free_indicatepkt\n"));
2007 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
2016 static int recv_func_prehandle(struct adapter *padapter,
2017 struct recv_frame *rframe)
2020 struct rx_pkt_attrib *pattrib = &rframe->attrib;
2021 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2022 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2024 if (padapter->registrypriv.mp_mode == 1) {
2025 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)) { /* padapter->mppriv.check_mp_pkt == 0)) */
2026 if (pattrib->crc_err == 1)
2027 padapter->mppriv.rx_crcerrpktcount++;
2029 padapter->mppriv.rx_pktcount++;
2031 if (check_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE) == false) {
2032 RT_TRACE(_module_rtl871x_recv_c_, _drv_alert_, ("MP - Not in loopback mode , drop pkt\n"));
2034 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
2040 /* check the frame crtl field and decache */
2041 ret = validate_recv_frame(padapter, rframe);
2042 if (ret != _SUCCESS) {
2043 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recv_func: validate_recv_frame fail! drop pkt\n"));
2044 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
2052 static int recv_func_posthandle(struct adapter *padapter,
2053 struct recv_frame *prframe)
2056 struct recv_frame *orig_prframe = prframe;
2057 struct recv_priv *precvpriv = &padapter->recvpriv;
2058 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2061 rtw_led_control(padapter, LED_CTL_RX);
2063 prframe = decryptor(padapter, prframe);
2064 if (prframe == NULL) {
2065 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decryptor: drop pkt\n"));
2067 goto _recv_data_drop;
2070 prframe = recvframe_chk_defrag(padapter, prframe);
2071 if (prframe == NULL) {
2072 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chk_defrag: drop pkt\n"));
2073 goto _recv_data_drop;
2076 prframe = portctrl(padapter, prframe);
2077 if (prframe == NULL) {
2078 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("portctrl: drop pkt\n"));
2080 goto _recv_data_drop;
2083 count_rx_stats(padapter, prframe, NULL);
2085 ret = process_recv_indicatepkts(padapter, prframe);
2086 if (ret != _SUCCESS) {
2087 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recv_func: process_recv_indicatepkts fail!\n"));
2088 rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */
2089 goto _recv_data_drop;
2094 precvpriv->rx_drop++;
2098 static int recv_func(struct adapter *padapter, struct recv_frame *rframe)
2101 struct rx_pkt_attrib *prxattrib = &rframe->attrib;
2102 struct security_priv *psecuritypriv = &padapter->securitypriv;
2103 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
2105 /* check if need to handle uc_swdec_pending_queue*/
2106 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey) {
2107 struct recv_frame *pending_frame;
2109 while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) {
2110 if (recv_func_posthandle(padapter, pending_frame) == _SUCCESS)
2111 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
2115 ret = recv_func_prehandle(padapter, rframe);
2117 if (ret == _SUCCESS) {
2118 /* check if need to enqueue into uc_swdec_pending_queue*/
2119 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
2120 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 &&
2121 (prxattrib->bdecrypted == 0 || psecuritypriv->sw_decrypt) &&
2122 !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) &&
2123 !psecuritypriv->busetkipkey) {
2124 rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
2125 DBG_88E("%s: no key, enqueue uc_swdec_pending_queue\n", __func__);
2129 ret = recv_func_posthandle(padapter, rframe);
2136 s32 rtw_recv_entry(struct recv_frame *precvframe)
2138 struct adapter *padapter;
2139 struct recv_priv *precvpriv;
2143 padapter = precvframe->adapter;
2145 precvpriv = &padapter->recvpriv;
2147 ret = recv_func(padapter, precvframe);
2149 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("rtw_recv_entry: recv_func return fail!!!\n"));
2150 goto _recv_entry_drop;
2153 precvpriv->rx_pkts++;
2160 if (padapter->registrypriv.mp_mode == 1)
2161 padapter->mppriv.rx_pktloss = precvpriv->rx_drop;
2167 void rtw_signal_stat_timer_hdl(RTW_TIMER_HDL_ARGS)
2169 struct adapter *adapter = (struct adapter *)FunctionContext;
2170 struct recv_priv *recvpriv = &adapter->recvpriv;
2173 u8 avg_signal_strength = 0;
2174 u8 avg_signal_qual = 0;
2175 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2177 if (adapter->recvpriv.is_signal_dbg) {
2178 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */
2179 adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg;
2180 adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg);
2182 if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */
2183 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2184 /* after avg_vals are acquired, we can re-stat the signal values */
2185 recvpriv->signal_strength_data.update_req = 1;
2188 if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */
2189 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2190 /* after avg_vals are acquired, we can re-stat the signal values */
2191 recvpriv->signal_qual_data.update_req = 1;
2194 /* update value of signal_strength, rssi, signal_qual */
2195 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) {
2196 tmp_s = (avg_signal_strength+(_alpha-1)*recvpriv->signal_strength);
2198 tmp_s = tmp_s/_alpha + 1;
2200 tmp_s = tmp_s/_alpha;
2204 tmp_q = (avg_signal_qual+(_alpha-1)*recvpriv->signal_qual);
2206 tmp_q = tmp_q/_alpha + 1;
2208 tmp_q = tmp_q/_alpha;
2212 recvpriv->signal_strength = tmp_s;
2213 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2214 recvpriv->signal_qual = tmp_q;
2217 rtw_set_signal_stat_timer(recvpriv);