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 union recv_frame *precvframe;
66 spin_lock_init(&precvpriv->lock);
68 _rtw_init_queue(&precvpriv->free_recv_queue);
69 _rtw_init_queue(&precvpriv->recv_pending_queue);
70 _rtw_init_queue(&precvpriv->uc_swdec_pending_queue);
72 precvpriv->adapter = padapter;
74 precvpriv->free_recvframe_cnt = NR_RECVFRAME;
76 rtw_os_recv_resource_init(precvpriv, padapter);
78 precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ);
80 if (precvpriv->pallocated_frame_buf == NULL) {
85 precvpriv->precv_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_frame_buf), RXFRAME_ALIGN_SZ);
87 precvframe = (union recv_frame *)precvpriv->precv_frame_buf;
89 for (i = 0; i < NR_RECVFRAME; i++) {
90 _rtw_init_listhead(&(precvframe->u.list));
92 rtw_list_insert_tail(&(precvframe->u.list), &(precvpriv->free_recv_queue.queue));
94 res = rtw_os_recv_resource_alloc(padapter, precvframe);
96 precvframe->u.hdr.len = 0;
98 precvframe->u.hdr.adapter = padapter;
101 precvpriv->rx_pending_cnt = 1;
103 sema_init(&precvpriv->allrxreturnevt, 0);
105 res = rtw_hal_init_recv_priv(padapter);
107 _init_timer(&precvpriv->signal_stat_timer, padapter->pnetdev, RTW_TIMER_HDL_NAME(signal_stat), padapter);
109 precvpriv->signal_stat_sampling_interval = 1000; /* ms */
111 rtw_set_signal_stat_timer(precvpriv);
118 void _rtw_free_recv_priv (struct recv_priv *precvpriv)
120 struct adapter *padapter = precvpriv->adapter;
123 rtw_free_uc_swdec_pending_queue(padapter);
125 rtw_os_recv_resource_free(precvpriv);
127 if (precvpriv->pallocated_frame_buf) {
128 vfree(precvpriv->pallocated_frame_buf);
131 rtw_hal_free_recv_priv(padapter);
135 union recv_frame *_rtw_alloc_recvframe (struct __queue *pfree_recv_queue)
137 struct recv_frame_hdr *hdr;
138 struct list_head *plist, *phead;
139 struct adapter *padapter;
140 struct recv_priv *precvpriv;
142 if (_rtw_queue_empty(pfree_recv_queue)) {
145 phead = get_list_head(pfree_recv_queue);
149 hdr = container_of(plist, struct recv_frame_hdr, list);
151 rtw_list_delete(&hdr->list);
152 padapter = hdr->adapter;
153 if (padapter != NULL) {
154 precvpriv = &padapter->recvpriv;
155 if (pfree_recv_queue == &precvpriv->free_recv_queue)
156 precvpriv->free_recvframe_cnt--;
161 return (union recv_frame *)hdr;
164 union recv_frame *rtw_alloc_recvframe (struct __queue *pfree_recv_queue)
166 union recv_frame *precvframe;
168 spin_lock_bh(&pfree_recv_queue->lock);
170 precvframe = _rtw_alloc_recvframe(pfree_recv_queue);
172 spin_unlock_bh(&pfree_recv_queue->lock);
177 void rtw_init_recvframe(union recv_frame *precvframe, struct recv_priv *precvpriv)
179 /* Perry: This can be removed */
180 _rtw_init_listhead(&precvframe->u.hdr.list);
182 precvframe->u.hdr.len = 0;
185 int rtw_free_recvframe(union recv_frame *precvframe, struct __queue *pfree_recv_queue)
187 struct adapter *padapter;
188 struct recv_priv *precvpriv;
192 padapter = precvframe->u.hdr.adapter;
193 precvpriv = &padapter->recvpriv;
194 if (precvframe->u.hdr.pkt) {
195 dev_kfree_skb_any(precvframe->u.hdr.pkt);/* free skb by driver */
196 precvframe->u.hdr.pkt = NULL;
199 spin_lock_bh(&pfree_recv_queue->lock);
201 rtw_list_delete(&(precvframe->u.hdr.list));
203 precvframe->u.hdr.len = 0;
205 rtw_list_insert_tail(&(precvframe->u.hdr.list), get_list_head(pfree_recv_queue));
207 if (padapter != NULL) {
208 if (pfree_recv_queue == &precvpriv->free_recv_queue)
209 precvpriv->free_recvframe_cnt++;
212 spin_unlock_bh(&pfree_recv_queue->lock);
218 int _rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue)
220 struct adapter *padapter = precvframe->u.hdr.adapter;
221 struct recv_priv *precvpriv = &padapter->recvpriv;
224 rtw_list_delete(&(precvframe->u.hdr.list));
225 rtw_list_insert_tail(&(precvframe->u.hdr.list), get_list_head(queue));
227 if (padapter != NULL) {
228 if (queue == &precvpriv->free_recv_queue)
229 precvpriv->free_recvframe_cnt++;
236 int rtw_enqueue_recvframe(union recv_frame *precvframe, struct __queue *queue)
240 spin_lock_bh(&queue->lock);
241 ret = _rtw_enqueue_recvframe(precvframe, queue);
242 spin_unlock_bh(&queue->lock);
248 caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
249 pframequeue: defrag_queue : will be accessed in recv_thread (passive)
251 using spinlock to protect
255 void rtw_free_recvframe_queue(struct __queue *pframequeue, struct __queue *pfree_recv_queue)
257 struct recv_frame_hdr *hdr;
258 struct list_head *plist, *phead;
260 spin_lock(&pframequeue->lock);
262 phead = get_list_head(pframequeue);
265 while (rtw_end_of_queue_search(phead, plist) == false) {
266 hdr = container_of(plist, struct recv_frame_hdr, list);
270 rtw_free_recvframe((union recv_frame *)hdr, pfree_recv_queue);
273 spin_unlock(&pframequeue->lock);
277 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter)
280 union recv_frame *pending_frame;
281 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
282 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
283 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
290 int rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue)
292 spin_lock_bh(&queue->lock);
294 rtw_list_delete(&precvbuf->list);
295 rtw_list_insert_head(&precvbuf->list, get_list_head(queue));
297 spin_unlock_bh(&queue->lock);
302 int rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue)
305 spin_lock_irqsave(&queue->lock, irqL);
307 rtw_list_delete(&precvbuf->list);
309 rtw_list_insert_tail(&precvbuf->list, get_list_head(queue));
310 spin_unlock_irqrestore(&queue->lock, irqL);
314 struct recv_buf *rtw_dequeue_recvbuf (struct __queue *queue)
317 struct recv_buf *precvbuf;
318 struct list_head *plist, *phead;
320 spin_lock_irqsave(&queue->lock, irqL);
322 if (_rtw_queue_empty(queue)) {
325 phead = get_list_head(queue);
329 precvbuf = container_of(plist, struct recv_buf, list);
331 rtw_list_delete(&precvbuf->list);
334 spin_unlock_irqrestore(&queue->lock, irqL);
339 static int recvframe_chkmic(struct adapter *adapter, union recv_frame *precvframe)
341 int i, res = _SUCCESS;
344 u8 bmic_err = false, brpt_micerror = true;
345 u8 *pframe, *payload, *pframemic;
347 struct sta_info *stainfo;
348 struct rx_pkt_attrib *prxattrib = &precvframe->u.hdr.attrib;
349 struct security_priv *psecuritypriv = &adapter->securitypriv;
351 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
352 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
354 stainfo = rtw_get_stainfo(&adapter->stapriv, &prxattrib->ta[0]);
356 if (prxattrib->encrypt == _TKIP_) {
357 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic:prxattrib->encrypt==_TKIP_\n"));
358 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",
359 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2], prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5]));
361 /* calculate mic code */
362 if (stainfo != NULL) {
363 if (IS_MCAST(prxattrib->ra)) {
364 mickey = &psecuritypriv->dot118021XGrprxmickey[prxattrib->key_index].skey[0];
366 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n recvframe_chkmic: bcmc key\n"));
368 if (!psecuritypriv) {
370 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n"));
371 DBG_88E("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
375 mickey = &stainfo->dot11tkiprxmickey.skey[0];
376 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n recvframe_chkmic: unicast key\n"));
379 datalen = precvframe->u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len-prxattrib->icv_len-8;/* icv_len included the mic code */
380 pframe = precvframe->u.hdr.rx_data;
381 payload = pframe+prxattrib->hdrlen+prxattrib->iv_len;
383 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n", prxattrib->iv_len, prxattrib->icv_len));
384 rtw_seccalctkipmic(mickey, pframe, payload, datalen, &miccode[0],
385 (unsigned char)prxattrib->priority); /* care the length of the data */
387 pframemic = payload+datalen;
391 for (i = 0; i < 8; i++) {
392 if (miccode[i] != *(pframemic+i)) {
393 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
394 ("recvframe_chkmic:miccode[%d](%02x)!=*(pframemic+%d)(%02x) ",
395 i, miccode[i], i, *(pframemic+i)));
401 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
402 ("\n *(pframemic-8)-*(pframemic-1)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
403 *(pframemic-8), *(pframemic-7), *(pframemic-6),
404 *(pframemic-5), *(pframemic-4), *(pframemic-3),
405 *(pframemic-2), *(pframemic-1)));
406 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
407 ("\n *(pframemic-16)-*(pframemic-9)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
408 *(pframemic-16), *(pframemic-15), *(pframemic-14),
409 *(pframemic-13), *(pframemic-12), *(pframemic-11),
410 *(pframemic-10), *(pframemic-9)));
413 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n ======demp packet (len=%d)======\n", precvframe->u.hdr.len));
414 for (i = 0; i < precvframe->u.hdr.len; i = i+8) {
415 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
416 *(precvframe->u.hdr.rx_data+i), *(precvframe->u.hdr.rx_data+i+1),
417 *(precvframe->u.hdr.rx_data+i+2), *(precvframe->u.hdr.rx_data+i+3),
418 *(precvframe->u.hdr.rx_data+i+4), *(precvframe->u.hdr.rx_data+i+5),
419 *(precvframe->u.hdr.rx_data+i+6), *(precvframe->u.hdr.rx_data+i+7)));
421 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n ====== demp packet end [len=%d]======\n", precvframe->u.hdr.len));
422 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("\n hrdlen=%d,\n", prxattrib->hdrlen));
425 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
426 ("ra=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x psecuritypriv->binstallGrpkey=%d ",
427 prxattrib->ra[0], prxattrib->ra[1], prxattrib->ra[2],
428 prxattrib->ra[3], prxattrib->ra[4], prxattrib->ra[5], psecuritypriv->binstallGrpkey));
430 /* double check key_index for some timing issue , */
431 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
432 if ((IS_MCAST(prxattrib->ra) == true) && (prxattrib->key_index != pmlmeinfo->key_index))
433 brpt_micerror = false;
435 if ((prxattrib->bdecrypted) && (brpt_micerror)) {
436 rtw_handle_tkip_mic_err(adapter, (u8)IS_MCAST(prxattrib->ra));
437 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
438 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
440 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
441 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
446 if ((!psecuritypriv->bcheck_grpkey) && (IS_MCAST(prxattrib->ra))) {
447 psecuritypriv->bcheck_grpkey = true;
448 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("psecuritypriv->bcheck_grpkey = true"));
452 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
455 recvframe_pull_tail(precvframe, 8);
464 /* decrypt and set the ivlen, icvlen of the recv_frame */
465 static union recv_frame *decryptor(struct adapter *padapter, union recv_frame *precv_frame)
467 struct rx_pkt_attrib *prxattrib = &precv_frame->u.hdr.attrib;
468 struct security_priv *psecuritypriv = &padapter->securitypriv;
469 union recv_frame *return_packet = precv_frame;
472 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("prxstat->decrypted=%x prxattrib->encrypt=0x%03x\n", prxattrib->bdecrypted, prxattrib->encrypt));
474 if (prxattrib->encrypt > 0) {
475 u8 *iv = precv_frame->u.hdr.rx_data+prxattrib->hdrlen;
476 prxattrib->key_index = (((iv[3])>>6)&0x3);
478 if (prxattrib->key_index > WEP_KEYS) {
479 DBG_88E("prxattrib->key_index(%d)>WEP_KEYS\n", prxattrib->key_index);
481 switch (prxattrib->encrypt) {
484 prxattrib->key_index = psecuritypriv->dot11PrivacyKeyIndex;
489 prxattrib->key_index = psecuritypriv->dot118021XGrpKeyid;
495 if ((prxattrib->encrypt > 0) && ((prxattrib->bdecrypted == 0) || (psecuritypriv->sw_decrypt))) {
496 psecuritypriv->hw_decrypted = false;
498 switch (prxattrib->encrypt) {
501 rtw_wep_decrypt(padapter, (u8 *)precv_frame);
504 res = rtw_tkip_decrypt(padapter, (u8 *)precv_frame);
507 res = rtw_aes_decrypt(padapter, (u8 *)precv_frame);
512 } else if (prxattrib->bdecrypted == 1 && prxattrib->encrypt > 0 &&
513 (psecuritypriv->busetkipkey == 1 || prxattrib->encrypt != _TKIP_))
514 psecuritypriv->hw_decrypted = true;
517 rtw_free_recvframe(return_packet, &padapter->recvpriv.free_recv_queue);
518 return_packet = NULL;
522 return return_packet;
525 /* set the security information in the recv_frame */
526 static union recv_frame *portctrl(struct adapter *adapter, union recv_frame *precv_frame)
528 u8 *psta_addr = NULL, *ptr;
530 struct recv_frame_hdr *pfhdr;
531 struct sta_info *psta;
532 struct sta_priv *pstapriv;
533 union recv_frame *prtnframe;
535 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */
536 struct rx_pkt_attrib *pattrib;
540 pstapriv = &adapter->stapriv;
541 psta = rtw_get_stainfo(pstapriv, psta_addr);
543 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
545 ptr = get_recvframe_data(precv_frame);
546 pfhdr = &precv_frame->u.hdr;
547 pattrib = &pfhdr->attrib;
548 psta_addr = pattrib->ta;
552 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n", adapter->securitypriv.dot11AuthAlgrthm));
555 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
557 /* only accept EAPOL frame */
558 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==1\n"));
560 prtnframe = precv_frame;
563 ptr = ptr+pfhdr->attrib.hdrlen+pfhdr->attrib.iv_len+LLC_HEADER_SIZE;
564 memcpy(&be_tmp, ptr, 2);
565 ether_type = ntohs(be_tmp);
567 if (ether_type == eapol_type) {
568 prtnframe = precv_frame;
570 /* free this frame */
571 rtw_free_recvframe(precv_frame, &adapter->recvpriv.free_recv_queue);
576 /* check decryption status, and decrypt the frame if needed */
577 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==0\n"));
578 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("portctrl:precv_frame->hdr.attrib.privacy=%x\n", precv_frame->u.hdr.attrib.privacy));
580 if (pattrib->bdecrypted == 0)
581 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("portctrl:prxstat->decrypted=%x\n", pattrib->bdecrypted));
583 prtnframe = precv_frame;
584 /* check is the EAPOL frame or not (Rekey) */
585 if (ether_type == eapol_type) {
586 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("########portctrl:ether_type==0x888e\n"));
589 prtnframe = precv_frame;
591 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:ether_type=0x%04x\n", ether_type));
595 prtnframe = precv_frame;
602 static int recv_decache(union recv_frame *precv_frame, u8 bretry, struct stainfo_rxcache *prxcache)
604 int tid = precv_frame->u.hdr.attrib.priority;
606 u16 seq_ctrl = ((precv_frame->u.hdr.attrib.seq_num&0xffff) << 4) |
607 (precv_frame->u.hdr.attrib.frag_num & 0xf);
611 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl, tid));
616 if (1) {/* if (bretry) */
617 if (seq_ctrl == prxcache->tid_rxseq[tid]) {
618 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]));
624 prxcache->tid_rxseq[tid] = seq_ctrl;
630 void process_pwrbit_data(struct adapter *padapter, union recv_frame *precv_frame);
631 void process_pwrbit_data(struct adapter *padapter, union recv_frame *precv_frame)
633 #ifdef CONFIG_88EU_AP_MODE
634 unsigned char pwrbit;
635 u8 *ptr = precv_frame->u.hdr.rx_data;
636 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
637 struct sta_priv *pstapriv = &padapter->stapriv;
638 struct sta_info *psta = NULL;
640 psta = rtw_get_stainfo(pstapriv, pattrib->src);
642 pwrbit = GetPwrMgt(ptr);
646 if (!(psta->state & WIFI_SLEEP_STATE))
647 stop_sta_xmit(padapter, psta);
649 if (psta->state & WIFI_SLEEP_STATE)
650 wakeup_sta_to_xmit(padapter, psta);
657 static void process_wmmps_data(struct adapter *padapter, union recv_frame *precv_frame)
659 #ifdef CONFIG_88EU_AP_MODE
660 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
661 struct sta_priv *pstapriv = &padapter->stapriv;
662 struct sta_info *psta = NULL;
664 psta = rtw_get_stainfo(pstapriv, pattrib->src);
669 if (!psta->qos_option)
672 if (!(psta->qos_info&0xf))
675 if (psta->state&WIFI_SLEEP_STATE) {
678 switch (pattrib->priority) {
681 wmmps_ac = psta->uapsd_bk&BIT(1);
685 wmmps_ac = psta->uapsd_vi&BIT(1);
689 wmmps_ac = psta->uapsd_vo&BIT(1);
694 wmmps_ac = psta->uapsd_be&BIT(1);
699 if (psta->sleepq_ac_len > 0) {
700 /* process received triggered frame */
701 xmit_delivery_enabled_frames(padapter, psta);
703 /* issue one qos null frame with More data bit = 0 and the EOSP bit set (= 1) */
704 issue_qos_nulldata(padapter, psta->hwaddr, (u16)pattrib->priority, 0, 0);
712 static void count_rx_stats(struct adapter *padapter, union recv_frame *prframe, struct sta_info *sta)
715 struct sta_info *psta = NULL;
716 struct stainfo_stats *pstats = NULL;
717 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
718 struct recv_priv *precvpriv = &padapter->recvpriv;
720 sz = get_recvframe_len(prframe);
721 precvpriv->rx_bytes += sz;
723 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
725 if ((!MacAddr_isBcst(pattrib->dst)) && (!IS_MCAST(pattrib->dst)))
726 padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod++;
731 psta = prframe->u.hdr.psta;
734 pstats = &psta->sta_stats;
736 pstats->rx_data_pkts++;
737 pstats->rx_bytes += sz;
741 int sta2sta_data_frame(
742 struct adapter *adapter,
743 union recv_frame *precv_frame,
744 struct sta_info **psta
747 int sta2sta_data_frame(struct adapter *adapter, union recv_frame *precv_frame, struct sta_info **psta)
749 u8 *ptr = precv_frame->u.hdr.rx_data;
751 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
752 struct sta_priv *pstapriv = &adapter->stapriv;
753 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
754 u8 *mybssid = get_bssid(pmlmepriv);
755 u8 *myhwaddr = myid(&adapter->eeprompriv);
757 int bmcast = IS_MCAST(pattrib->dst);
760 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
761 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
762 /* filter packets that SA is myself or multicast or broadcast */
763 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
764 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
769 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
774 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
775 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
776 memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
781 sta_addr = pattrib->src;
782 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
783 /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */
784 if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN)) {
785 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("bssid!=TA under STATION_MODE; drop pkt\n"));
789 sta_addr = pattrib->bssid;
790 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
792 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
793 if (!IS_MCAST(pattrib->bssid)) {
797 } else { /* not mc-frame */
798 /* For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID */
799 if (memcmp(pattrib->bssid, pattrib->dst, ETH_ALEN)) {
804 sta_addr = pattrib->src;
806 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
807 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
808 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
809 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
810 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
811 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
819 *psta = rtw_get_bcmc_stainfo(adapter);
821 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */
824 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under sta2sta_data_frame ; drop pkt\n"));
825 if (adapter->registrypriv.mp_mode == 1) {
826 if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
827 adapter->mppriv.rx_pktloss++;
837 static int ap2sta_data_frame (
838 struct adapter *adapter,
839 union recv_frame *precv_frame,
840 struct sta_info **psta)
842 u8 *ptr = precv_frame->u.hdr.rx_data;
843 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
845 struct sta_priv *pstapriv = &adapter->stapriv;
846 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
847 u8 *mybssid = get_bssid(pmlmepriv);
848 u8 *myhwaddr = myid(&adapter->eeprompriv);
849 int bmcast = IS_MCAST(pattrib->dst);
852 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) &&
853 (check_fwstate(pmlmepriv, _FW_LINKED) == true ||
854 check_fwstate(pmlmepriv, _FW_UNDER_LINKING))) {
855 /* filter packets that SA is myself or multicast or broadcast */
856 if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN)) {
857 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" SA==myself\n"));
862 /* da should be for me */
863 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) {
864 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
865 (" ap2sta_data_frame: compare DA fail; DA=%pM\n", (pattrib->dst)));
871 if (!memcmp(pattrib->bssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
872 !memcmp(mybssid, "\x0\x0\x0\x0\x0\x0", ETH_ALEN) ||
873 (memcmp(pattrib->bssid, mybssid, ETH_ALEN))) {
874 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
875 (" ap2sta_data_frame: compare BSSID fail ; BSSID=%pM\n", (pattrib->bssid)));
876 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("mybssid=%pM\n", (mybssid)));
879 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid));
880 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
888 *psta = rtw_get_bcmc_stainfo(adapter);
890 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */
893 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
898 /* if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) { */
901 if (GetFrameSubType(ptr) & BIT(6)) {
902 /* No data, will not indicate to upper layer, temporily count it here */
903 count_rx_stats(adapter, precv_frame, *psta);
904 ret = RTW_RX_HANDLED;
907 } else if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) &&
908 (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
909 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
910 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
911 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
912 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
913 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
916 memcpy(pattrib->bssid, mybssid, ETH_ALEN);
918 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
920 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under MP_MODE ; drop pkt\n"));
924 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
926 ret = RTW_RX_HANDLED;
929 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) {
930 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
932 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid));
934 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
947 static int sta2ap_data_frame(struct adapter *adapter,
948 union recv_frame *precv_frame,
949 struct sta_info **psta)
951 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
952 struct sta_priv *pstapriv = &adapter->stapriv;
953 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
954 u8 *ptr = precv_frame->u.hdr.rx_data;
955 unsigned char *mybssid = get_bssid(pmlmepriv);
959 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
960 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */
961 if (memcmp(pattrib->bssid, mybssid, ETH_ALEN)) {
966 *psta = rtw_get_stainfo(pstapriv, pattrib->src);
968 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under AP_MODE; drop pkt\n"));
969 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
971 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
973 ret = RTW_RX_HANDLED;
977 process_pwrbit_data(adapter, precv_frame);
979 if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) {
980 process_wmmps_data(adapter, precv_frame);
983 if (GetFrameSubType(ptr) & BIT(6)) {
984 /* No data, will not indicate to upper layer, temporily count it here */
985 count_rx_stats(adapter, precv_frame, *psta);
986 ret = RTW_RX_HANDLED;
990 u8 *myhwaddr = myid(&adapter->eeprompriv);
991 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
992 ret = RTW_RX_HANDLED;
995 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib->src));
996 issue_deauth(adapter, pattrib->src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
997 ret = RTW_RX_HANDLED;
1007 static int validate_recv_ctrl_frame(struct adapter *padapter,
1008 union recv_frame *precv_frame)
1010 #ifdef CONFIG_88EU_AP_MODE
1011 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1012 struct sta_priv *pstapriv = &padapter->stapriv;
1013 u8 *pframe = precv_frame->u.hdr.rx_data;
1014 /* uint len = precv_frame->u.hdr.len; */
1016 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
1019 /* receive the frames that ra(a1) is my address */
1020 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN))
1023 /* only handle ps-poll */
1024 if (GetFrameSubType(pframe) == WIFI_PSPOLL) {
1027 struct sta_info *psta = NULL;
1029 aid = GetAid(pframe);
1030 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1032 if ((psta == NULL) || (psta->aid != aid))
1035 /* for rx pkt statistics */
1036 psta->sta_stats.rx_ctrl_pkts++;
1038 switch (pattrib->priority) {
1041 wmmps_ac = psta->uapsd_bk&BIT(0);
1045 wmmps_ac = psta->uapsd_vi&BIT(0);
1049 wmmps_ac = psta->uapsd_vo&BIT(0);
1054 wmmps_ac = psta->uapsd_be&BIT(0);
1061 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
1062 DBG_88E("%s alive check-rx ps-poll\n", __func__);
1063 psta->expire_to = pstapriv->expire_to;
1064 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
1067 if ((psta->state&WIFI_SLEEP_STATE) && (pstapriv->sta_dz_bitmap&BIT(psta->aid))) {
1068 struct list_head *xmitframe_plist, *xmitframe_phead;
1069 struct xmit_frame *pxmitframe = NULL;
1071 spin_lock_bh(&psta->sleep_q.lock);
1073 xmitframe_phead = get_list_head(&psta->sleep_q);
1074 xmitframe_plist = xmitframe_phead->next;
1076 if ((rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) == false) {
1077 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
1079 xmitframe_plist = xmitframe_plist->next;
1081 rtw_list_delete(&pxmitframe->list);
1085 if (psta->sleepq_len > 0)
1086 pxmitframe->attrib.mdata = 1;
1088 pxmitframe->attrib.mdata = 0;
1090 pxmitframe->attrib.triggered = 1;
1092 spin_unlock_bh(&psta->sleep_q.lock);
1093 if (rtw_hal_xmit(padapter, pxmitframe) == true)
1094 rtw_os_xmit_complete(padapter, pxmitframe);
1095 spin_lock_bh(&psta->sleep_q.lock);
1097 if (psta->sleepq_len == 0) {
1098 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1100 /* upate BCN for TIM IE */
1101 /* update_BCNTIM(padapter); */
1102 update_beacon(padapter, _TIM_IE_, NULL, false);
1105 if (pstapriv->tim_bitmap&BIT(psta->aid)) {
1106 if (psta->sleepq_len == 0) {
1107 DBG_88E("no buffered packets to xmit\n");
1109 /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */
1110 issue_nulldata(padapter, psta->hwaddr, 0, 0, 0);
1112 DBG_88E("error!psta->sleepq_len=%d\n", psta->sleepq_len);
1113 psta->sleepq_len = 0;
1116 pstapriv->tim_bitmap &= ~BIT(psta->aid);
1118 /* upate BCN for TIM IE */
1119 /* update_BCNTIM(padapter); */
1120 update_beacon(padapter, _TIM_IE_, NULL, false);
1124 spin_unlock_bh(&psta->sleep_q.lock);
1133 union recv_frame *recvframe_chk_defrag(struct adapter *padapter, union recv_frame *precv_frame);
1135 static int validate_recv_mgnt_frame(struct adapter *padapter,
1136 union recv_frame *precv_frame)
1138 struct sta_info *psta;
1140 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("+validate_recv_mgnt_frame\n"));
1142 precv_frame = recvframe_chk_defrag(padapter, precv_frame);
1143 if (precv_frame == NULL) {
1144 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("%s: fragment packet\n", __func__));
1148 /* for rx pkt statistics */
1149 psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(precv_frame->u.hdr.rx_data));
1151 psta->sta_stats.rx_mgnt_pkts++;
1152 if (GetFrameSubType(precv_frame->u.hdr.rx_data) == WIFI_BEACON) {
1153 psta->sta_stats.rx_beacon_pkts++;
1154 } else if (GetFrameSubType(precv_frame->u.hdr.rx_data) == WIFI_PROBEREQ) {
1155 psta->sta_stats.rx_probereq_pkts++;
1156 } else if (GetFrameSubType(precv_frame->u.hdr.rx_data) == WIFI_PROBERSP) {
1157 if (!memcmp(padapter->eeprompriv.mac_addr, GetAddr1Ptr(precv_frame->u.hdr.rx_data), ETH_ALEN) == true)
1158 psta->sta_stats.rx_probersp_pkts++;
1159 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->u.hdr.rx_data)) ||
1160 is_multicast_mac_addr(GetAddr1Ptr(precv_frame->u.hdr.rx_data)))
1161 psta->sta_stats.rx_probersp_bm_pkts++;
1163 psta->sta_stats.rx_probersp_uo_pkts++;
1167 mgt_dispatcher(padapter, precv_frame);
1172 static int validate_recv_data_frame(struct adapter *adapter,
1173 union recv_frame *precv_frame)
1176 u8 *psa, *pda, *pbssid;
1177 struct sta_info *psta = NULL;
1178 u8 *ptr = precv_frame->u.hdr.rx_data;
1179 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1180 struct security_priv *psecuritypriv = &adapter->securitypriv;
1184 bretry = GetRetry(ptr);
1187 pbssid = get_hdr_bssid(ptr);
1189 if (pbssid == NULL) {
1194 memcpy(pattrib->dst, pda, ETH_ALEN);
1195 memcpy(pattrib->src, psa, ETH_ALEN);
1197 memcpy(pattrib->bssid, pbssid, ETH_ALEN);
1199 switch (pattrib->to_fr_ds) {
1201 memcpy(pattrib->ra, pda, ETH_ALEN);
1202 memcpy(pattrib->ta, psa, ETH_ALEN);
1203 ret = sta2sta_data_frame(adapter, precv_frame, &psta);
1206 memcpy(pattrib->ra, pda, ETH_ALEN);
1207 memcpy(pattrib->ta, pbssid, ETH_ALEN);
1208 ret = ap2sta_data_frame(adapter, precv_frame, &psta);
1211 memcpy(pattrib->ra, pbssid, ETH_ALEN);
1212 memcpy(pattrib->ta, psa, ETH_ALEN);
1213 ret = sta2ap_data_frame(adapter, precv_frame, &psta);
1216 memcpy(pattrib->ra, GetAddr1Ptr(ptr), ETH_ALEN);
1217 memcpy(pattrib->ta, GetAddr2Ptr(ptr), ETH_ALEN);
1219 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" case 3\n"));
1228 } else if (ret == RTW_RX_HANDLED) {
1233 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" after to_fr_ds_chk; psta==NULL\n"));
1238 /* psta->rssi = prxcmd->rssi; */
1239 /* psta->signal_quality = prxcmd->sq; */
1240 precv_frame->u.hdr.psta = psta;
1243 pattrib->ack_policy = 0;
1244 /* parsing QC field */
1245 if (pattrib->qos == 1) {
1246 pattrib->priority = GetPriority((ptr + 24));
1247 pattrib->ack_policy = GetAckpolicy((ptr + 24));
1248 pattrib->amsdu = GetAMsdu((ptr + 24));
1249 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 32 : 26;
1251 if (pattrib->priority != 0 && pattrib->priority != 3)
1252 adapter->recvpriv.bIsAnyNonBEPkts = true;
1254 pattrib->priority = 0;
1255 pattrib->hdrlen = pattrib->to_fr_ds == 3 ? 30 : 24;
1258 if (pattrib->order)/* HT-CTRL 11n */
1259 pattrib->hdrlen += 4;
1261 precv_frame->u.hdr.preorder_ctrl = &psta->recvreorder_ctrl[pattrib->priority];
1263 /* decache, drop duplicate recv packets */
1264 if (recv_decache(precv_frame, bretry, &psta->sta_recvpriv.rxcache) == _FAIL) {
1265 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decache : drop pkt\n"));
1270 if (pattrib->privacy) {
1271 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("validate_recv_data_frame:pattrib->privacy=%x\n", pattrib->privacy));
1272 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)));
1274 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra));
1276 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n pattrib->encrypt=%d\n", pattrib->encrypt));
1278 SET_ICE_IV_LEN(pattrib->iv_len, pattrib->icv_len, pattrib->encrypt);
1280 pattrib->encrypt = 0;
1281 pattrib->iv_len = 0;
1282 pattrib->icv_len = 0;
1291 static int validate_recv_frame(struct adapter *adapter, union recv_frame *precv_frame)
1293 /* shall check frame subtype, to / from ds, da, bssid */
1295 /* then call check if rx seq/frag. duplicated. */
1299 int retval = _SUCCESS;
1301 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
1302 u8 *ptr = precv_frame->u.hdr.rx_data;
1303 u8 ver = (unsigned char) (*ptr)&0x3;
1304 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1307 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
1308 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
1309 if (ch_set_idx >= 0)
1310 pmlmeext->channel_set[ch_set_idx].rx_count++;
1313 /* add version chk */
1315 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! (ver!=0)\n"));
1320 type = GetFrameType(ptr);
1321 subtype = GetFrameSubType(ptr); /* bit(7)~bit(2) */
1323 pattrib->to_fr_ds = get_tofr_ds(ptr);
1325 pattrib->frag_num = GetFragNum(ptr);
1326 pattrib->seq_num = GetSequence(ptr);
1328 pattrib->pw_save = GetPwrMgt(ptr);
1329 pattrib->mfrag = GetMFrag(ptr);
1330 pattrib->mdata = GetMData(ptr);
1331 pattrib->privacy = GetPrivacy(ptr);
1332 pattrib->order = GetOrder(ptr);
1334 /* Dump rx packets */
1335 rtw_hal_get_def_var(adapter, HAL_DEF_DBG_DUMP_RXPKT, &(bDumpRxPkt));
1336 if (bDumpRxPkt == 1) {/* dump all rx packets */
1338 DBG_88E("#############################\n");
1340 for (i = 0; i < 64; i = i+8)
1341 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1342 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1343 DBG_88E("#############################\n");
1344 } else if (bDumpRxPkt == 2) {
1345 if (type == WIFI_MGT_TYPE) {
1347 DBG_88E("#############################\n");
1349 for (i = 0; i < 64; i = i+8)
1350 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1351 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1352 DBG_88E("#############################\n");
1354 } else if (bDumpRxPkt == 3) {
1355 if (type == WIFI_DATA_TYPE) {
1357 DBG_88E("#############################\n");
1359 for (i = 0; i < 64; i = i+8)
1360 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
1361 *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
1362 DBG_88E("#############################\n");
1366 case WIFI_MGT_TYPE: /* mgnt */
1367 retval = validate_recv_mgnt_frame(adapter, precv_frame);
1368 if (retval == _FAIL)
1369 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_mgnt_frame fail\n"));
1370 retval = _FAIL; /* only data frame return _SUCCESS */
1372 case WIFI_CTRL_TYPE: /* ctrl */
1373 retval = validate_recv_ctrl_frame(adapter, precv_frame);
1374 if (retval == _FAIL)
1375 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_ctrl_frame fail\n"));
1376 retval = _FAIL; /* only data frame return _SUCCESS */
1378 case WIFI_DATA_TYPE: /* data */
1379 rtw_led_control(adapter, LED_CTL_RX);
1380 pattrib->qos = (subtype & BIT(7)) ? 1 : 0;
1381 retval = validate_recv_data_frame(adapter, precv_frame);
1382 if (retval == _FAIL) {
1383 struct recv_priv *precvpriv = &adapter->recvpriv;
1384 precvpriv->rx_drop++;
1388 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("validate_recv_data_frame fail! type= 0x%x\n", type));
1399 /* remove the wlanhdr and add the eth_hdr */
1401 static int wlanhdr_to_ethhdr (union recv_frame *precvframe)
1408 struct ieee80211_snap_hdr *psnap;
1411 struct adapter *adapter = precvframe->u.hdr.adapter;
1412 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1414 u8 *ptr = get_recvframe_data(precvframe); /* point to frame_ctrl field */
1415 struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
1418 if (pattrib->encrypt)
1419 recvframe_pull_tail(precvframe, pattrib->icv_len);
1421 psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
1422 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
1423 /* convert hdr + possible LLC headers into Ethernet header */
1424 if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
1425 (!memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) == false) &&
1426 (!memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2) == false)) ||
1427 !memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) {
1428 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1431 /* Leave Ethernet header part of hdr and full payload */
1435 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0);
1436 len = precvframe->u.hdr.len - rmv_len;
1438 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
1439 ("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x===\n\n", pattrib->hdrlen, pattrib->iv_len));
1441 memcpy(&be_tmp, ptr+rmv_len, 2);
1442 eth_type = ntohs(be_tmp); /* pattrib->ether_type */
1443 pattrib->eth_type = eth_type;
1445 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE))) {
1451 /* append rx status for mp test packets */
1452 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24);
1453 memcpy(ptr, get_rxmem(precvframe), 24);
1456 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
1459 memcpy(ptr, pattrib->dst, ETH_ALEN);
1460 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
1463 be_tmp = htons(len);
1464 memcpy(ptr+12, &be_tmp, 2);
1470 /* perform defrag */
1471 static union recv_frame *recvframe_defrag(struct adapter *adapter, struct __queue *defrag_q)
1473 struct list_head *plist, *phead;
1476 struct recv_frame_hdr *pfhdr, *pnfhdr;
1477 union recv_frame *prframe, *pnextrframe;
1478 struct __queue *pfree_recv_queue;
1482 pfree_recv_queue = &adapter->recvpriv.free_recv_queue;
1484 phead = get_list_head(defrag_q);
1485 plist = phead->next;
1486 pfhdr = container_of(plist, struct recv_frame_hdr, list);
1487 prframe = (union recv_frame *)pfhdr;
1488 rtw_list_delete(&(prframe->u.list));
1490 if (curfragnum != pfhdr->attrib.frag_num) {
1491 /* the first fragment number must be 0 */
1492 /* free the whole queue */
1493 rtw_free_recvframe(prframe, pfree_recv_queue);
1494 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1501 plist = get_list_head(defrag_q);
1503 plist = plist->next;
1505 while (rtw_end_of_queue_search(phead, plist) == false) {
1506 pnfhdr = container_of(plist, struct recv_frame_hdr , list);
1507 pnextrframe = (union recv_frame *)pnfhdr;
1509 /* check the fragment sequence (2nd ~n fragment frame) */
1511 if (curfragnum != pnfhdr->attrib.frag_num) {
1512 /* the fragment number must be increasing (after decache) */
1513 /* release the defrag_q & prframe */
1514 rtw_free_recvframe(prframe, pfree_recv_queue);
1515 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1521 /* copy the 2nd~n fragment frame's payload to the first fragment */
1522 /* get the 2nd~last fragment frame's payload */
1524 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1526 recvframe_pull(pnextrframe, wlanhdr_offset);
1528 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1529 recvframe_pull_tail(prframe, pfhdr->attrib.icv_len);
1532 memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len);
1534 recvframe_put(prframe, pnfhdr->len);
1536 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
1537 plist = plist->next;
1540 /* free the defrag_q queue and return the prframe */
1541 rtw_free_recvframe_queue(defrag_q, pfree_recv_queue);
1543 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Performance defrag!!!!!\n"));
1549 /* check if need to defrag, if needed queue the frame to defrag_q */
1550 union recv_frame *recvframe_chk_defrag(struct adapter *padapter, union recv_frame *precv_frame)
1555 struct recv_frame_hdr *pfhdr;
1556 struct sta_info *psta;
1557 struct sta_priv *pstapriv;
1558 struct list_head *phead;
1559 union recv_frame *prtnframe = NULL;
1560 struct __queue *pfree_recv_queue, *pdefrag_q;
1563 pstapriv = &padapter->stapriv;
1565 pfhdr = &precv_frame->u.hdr;
1567 pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
1569 /* need to define struct of wlan header frame ctrl */
1570 ismfrag = pfhdr->attrib.mfrag;
1571 fragnum = pfhdr->attrib.frag_num;
1573 psta_addr = pfhdr->attrib.ta;
1574 psta = rtw_get_stainfo(pstapriv, psta_addr);
1576 u8 type = GetFrameType(pfhdr->rx_data);
1577 if (type != WIFI_DATA_TYPE) {
1578 psta = rtw_get_bcmc_stainfo(padapter);
1579 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1584 pdefrag_q = &psta->sta_recvpriv.defrag_q;
1587 if ((ismfrag == 0) && (fragnum == 0))
1588 prtnframe = precv_frame;/* isn't a fragment frame */
1591 /* 0~(n-1) fragment frame */
1592 /* enqueue to defraf_g */
1593 if (pdefrag_q != NULL) {
1595 /* the first fragment */
1596 if (_rtw_queue_empty(pdefrag_q) == false) {
1597 /* free current defrag_q */
1598 rtw_free_recvframe_queue(pdefrag_q, pfree_recv_queue);
1602 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1604 phead = get_list_head(pdefrag_q);
1605 rtw_list_insert_tail(&pfhdr->list, phead);
1607 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("Enqueuq: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1611 /* can't find this ta's defrag_queue, so free this recv_frame */
1612 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1614 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1618 if ((ismfrag == 0) && (fragnum != 0)) {
1619 /* the last fragment frame */
1620 /* enqueue the last fragment */
1621 if (pdefrag_q != NULL) {
1622 phead = get_list_head(pdefrag_q);
1623 rtw_list_insert_tail(&pfhdr->list, phead);
1625 /* call recvframe_defrag to defrag */
1626 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("defrag: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1627 precv_frame = recvframe_defrag(padapter, pdefrag_q);
1628 prtnframe = precv_frame;
1630 /* can't find this ta's defrag_queue, so free this recv_frame */
1631 rtw_free_recvframe(precv_frame, pfree_recv_queue);
1633 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag, fragnum));
1637 if ((prtnframe != NULL) && (prtnframe->u.hdr.attrib.privacy)) {
1638 /* after defrag we must check tkip mic code */
1639 if (recvframe_chkmic(padapter, prtnframe) == _FAIL) {
1640 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic(padapter, prtnframe)==_FAIL\n"));
1641 rtw_free_recvframe(prtnframe, pfree_recv_queue);
1650 static int amsdu_to_msdu(struct adapter *padapter, union recv_frame *prframe)
1652 int a_len, padding_len;
1653 u16 eth_type, nSubframe_Length;
1655 unsigned char *pdata;
1656 struct rx_pkt_attrib *pattrib;
1657 unsigned char *data_ptr;
1658 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1659 struct recv_priv *precvpriv = &padapter->recvpriv;
1660 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1664 pattrib = &prframe->u.hdr.attrib;
1666 recvframe_pull(prframe, prframe->u.hdr.attrib.hdrlen);
1668 if (prframe->u.hdr.attrib.iv_len > 0)
1669 recvframe_pull(prframe, prframe->u.hdr.attrib.iv_len);
1671 a_len = prframe->u.hdr.len;
1673 pdata = prframe->u.hdr.rx_data;
1675 while (a_len > ETH_HLEN) {
1676 /* Offset 12 denote 2 mac address */
1677 nSubframe_Length = RTW_GET_BE16(pdata + 12);
1679 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
1680 DBG_88E("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len, nSubframe_Length);
1684 /* move the data point to data content */
1688 /* Allocate new skb for releasing to upper layer */
1689 sub_skb = dev_alloc_skb(nSubframe_Length + 12);
1691 skb_reserve(sub_skb, 12);
1692 data_ptr = (u8 *)skb_put(sub_skb, nSubframe_Length);
1693 memcpy(data_ptr, pdata, nSubframe_Length);
1695 sub_skb = skb_clone(prframe->u.hdr.pkt, GFP_ATOMIC);
1697 sub_skb->data = pdata;
1698 sub_skb->len = nSubframe_Length;
1699 skb_set_tail_pointer(sub_skb, nSubframe_Length);
1701 DBG_88E("skb_clone() Fail!!! , nr_subframes=%d\n", nr_subframes);
1706 subframes[nr_subframes++] = sub_skb;
1708 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
1709 DBG_88E("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1713 pdata += nSubframe_Length;
1714 a_len -= nSubframe_Length;
1716 padding_len = 4 - ((nSubframe_Length + ETH_HLEN) & (4-1));
1717 if (padding_len == 4) {
1721 if (a_len < padding_len) {
1724 pdata += padding_len;
1725 a_len -= padding_len;
1729 for (i = 0; i < nr_subframes; i++) {
1730 sub_skb = subframes[i];
1731 /* convert hdr + possible LLC headers into Ethernet header */
1732 eth_type = RTW_GET_BE16(&sub_skb->data[6]);
1733 if (sub_skb->len >= 8 &&
1734 ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) &&
1735 eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) ||
1736 !memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) {
1737 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1738 skb_pull(sub_skb, SNAP_SIZE);
1739 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1740 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1743 /* Leave Ethernet header part of hdr and full payload */
1744 len = htons(sub_skb->len);
1745 memcpy(skb_push(sub_skb, 2), &len, 2);
1746 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN);
1747 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN);
1750 /* Indicate the packets to upper layer */
1751 /* Insert NAT2.5 RX here! */
1752 sub_skb->protocol = eth_type_trans(sub_skb, padapter->pnetdev);
1753 sub_skb->dev = padapter->pnetdev;
1755 sub_skb->ip_summed = CHECKSUM_NONE;
1762 prframe->u.hdr.len = 0;
1763 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1768 static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
1770 u8 wsize = preorder_ctrl->wsize_b;
1771 u16 wend = (preorder_ctrl->indicate_seq + wsize - 1) & 0xFFF;/* 4096; */
1773 /* Rx Reorder initialize condition. */
1774 if (preorder_ctrl->indicate_seq == 0xFFFF)
1775 preorder_ctrl->indicate_seq = seq_num;
1777 /* Drop out the packet which SeqNum is smaller than WinStart */
1778 if (SN_LESS(seq_num, preorder_ctrl->indicate_seq))
1782 /* Sliding window manipulation. Conditions includes: */
1783 /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */
1784 /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */
1786 if (SN_EQUAL(seq_num, preorder_ctrl->indicate_seq)) {
1787 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1788 } else if (SN_LESS(wend, seq_num)) {
1789 if (seq_num >= (wsize - 1))
1790 preorder_ctrl->indicate_seq = seq_num + 1 - wsize;
1792 preorder_ctrl->indicate_seq = 0xFFF - (wsize - (seq_num + 1)) + 1;
1798 int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, union recv_frame *prframe);
1799 int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl, union recv_frame *prframe)
1801 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
1802 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1803 struct list_head *phead, *plist;
1804 struct recv_frame_hdr *hdr;
1805 struct rx_pkt_attrib *pnextattrib;
1807 phead = get_list_head(ppending_recvframe_queue);
1808 plist = phead->next;
1810 while (rtw_end_of_queue_search(phead, plist) == false) {
1811 hdr = container_of(plist, struct recv_frame_hdr, list);
1812 pnextattrib = &hdr->attrib;
1814 if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
1815 plist = plist->next;
1816 else if (SN_EQUAL(pnextattrib->seq_num, pattrib->seq_num))
1822 rtw_list_delete(&(prframe->u.hdr.list));
1824 rtw_list_insert_tail(&(prframe->u.hdr.list), plist);
1828 static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reorder_ctrl *preorder_ctrl, int bforced)
1830 struct list_head *phead, *plist;
1831 union recv_frame *prframe;
1832 struct recv_frame_hdr *prhdr;
1833 struct rx_pkt_attrib *pattrib;
1834 int bPktInBuf = false;
1835 struct recv_priv *precvpriv = &padapter->recvpriv;
1836 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1838 phead = get_list_head(ppending_recvframe_queue);
1839 plist = phead->next;
1841 /* Handling some condition for forced indicate case. */
1843 if (rtw_is_list_empty(phead))
1846 prhdr = container_of(plist, struct recv_frame_hdr, list);
1847 pattrib = &prhdr->attrib;
1848 preorder_ctrl->indicate_seq = pattrib->seq_num;
1851 /* Prepare indication list and indication. */
1852 /* Check if there is any packet need indicate. */
1853 while (!rtw_is_list_empty(phead)) {
1854 prhdr = container_of(plist, struct recv_frame_hdr, list);
1855 prframe = (union recv_frame *)prhdr;
1856 pattrib = &prframe->u.hdr.attrib;
1858 if (!SN_LESS(preorder_ctrl->indicate_seq, pattrib->seq_num)) {
1859 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1860 ("recv_indicatepkts_in_order: indicate=%d seq=%d amsdu=%d\n",
1861 preorder_ctrl->indicate_seq, pattrib->seq_num, pattrib->amsdu));
1862 plist = plist->next;
1863 rtw_list_delete(&(prframe->u.hdr.list));
1865 if (SN_EQUAL(preorder_ctrl->indicate_seq, pattrib->seq_num))
1866 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1) & 0xFFF;
1868 /* Set this as a lock to make sure that only one thread is indicating packet. */
1870 /* indicate this recv_frame */
1871 if (!pattrib->amsdu) {
1872 if ((!padapter->bDriverStopped) &&
1873 (!padapter->bSurpriseRemoved))
1874 rtw_recv_indicatepkt(padapter, prframe);/* indicate this recv_frame */
1875 } else if (pattrib->amsdu == 1) {
1876 if (amsdu_to_msdu(padapter, prframe) != _SUCCESS)
1877 rtw_free_recvframe(prframe, &precvpriv->free_recv_queue);
1879 /* error condition; */
1882 /* Update local variables. */
1892 static int recv_indicatepkt_reorder(struct adapter *padapter, union recv_frame *prframe)
1894 int retval = _SUCCESS;
1895 struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
1896 struct recv_reorder_ctrl *preorder_ctrl = prframe->u.hdr.preorder_ctrl;
1897 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1899 if (!pattrib->amsdu) {
1901 wlanhdr_to_ethhdr(prframe);
1903 if ((pattrib->qos != 1) || (pattrib->eth_type == 0x0806) ||
1904 (pattrib->ack_policy != 0)) {
1905 if ((!padapter->bDriverStopped) &&
1906 (!padapter->bSurpriseRemoved)) {
1907 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ recv_indicatepkt_reorder -recv_func recv_indicatepkt\n"));
1909 rtw_recv_indicatepkt(padapter, prframe);
1916 if (!preorder_ctrl->enable) {
1917 /* indicate this recv_frame */
1918 preorder_ctrl->indicate_seq = pattrib->seq_num;
1919 rtw_recv_indicatepkt(padapter, prframe);
1921 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1924 } else if (pattrib->amsdu == 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */
1925 if (!preorder_ctrl->enable) {
1926 preorder_ctrl->indicate_seq = pattrib->seq_num;
1927 retval = amsdu_to_msdu(padapter, prframe);
1929 preorder_ctrl->indicate_seq = (preorder_ctrl->indicate_seq + 1)%4096;
1934 spin_lock_bh(&ppending_recvframe_queue->lock);
1936 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
1937 ("recv_indicatepkt_reorder: indicate=%d seq=%d\n",
1938 preorder_ctrl->indicate_seq, pattrib->seq_num));
1940 /* s2. check if winstart_b(indicate_seq) needs to been updated */
1941 if (!check_indicate_seq(preorder_ctrl, pattrib->seq_num)) {
1942 rtw_recv_indicatepkt(padapter, prframe);
1944 spin_unlock_bh(&ppending_recvframe_queue->lock);
1949 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1950 if (!enqueue_reorder_recvframe(preorder_ctrl, prframe))
1954 /* Indication process. */
1955 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
1956 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
1958 /* For Rx Reorder condition: */
1959 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
1960 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
1963 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */
1964 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, false)) {
1965 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
1966 spin_unlock_bh(&ppending_recvframe_queue->lock);
1968 spin_unlock_bh(&ppending_recvframe_queue->lock);
1969 del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
1978 spin_unlock_bh(&ppending_recvframe_queue->lock);
1983 void rtw_reordering_ctrl_timeout_handler(void *pcontext)
1985 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)pcontext;
1986 struct adapter *padapter = preorder_ctrl->padapter;
1987 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1989 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
1992 spin_lock_bh(&ppending_recvframe_queue->lock);
1994 if (recv_indicatepkts_in_order(padapter, preorder_ctrl, true) == true)
1995 _set_timer(&preorder_ctrl->reordering_ctrl_timer, REORDER_WAIT_TIME);
1997 spin_unlock_bh(&ppending_recvframe_queue->lock);
2000 static int process_recv_indicatepkts(struct adapter *padapter, union recv_frame *prframe)
2002 int retval = _SUCCESS;
2003 /* struct recv_priv *precvpriv = &padapter->recvpriv; */
2004 /* struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib; */
2005 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2006 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
2008 if (phtpriv->ht_option) { /* B/G/N Mode */
2009 /* prframe->u.hdr.preorder_ctrl = &precvpriv->recvreorder_ctrl[pattrib->priority]; */
2011 if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) {
2012 /* including perform A-MPDU Rx Ordering Buffer Control */
2013 if ((!padapter->bDriverStopped) &&
2014 (!padapter->bSurpriseRemoved)) {
2019 } else { /* B/G mode */
2020 retval = wlanhdr_to_ethhdr (prframe);
2021 if (retval != _SUCCESS) {
2022 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("wlanhdr_to_ethhdr: drop pkt\n"));
2026 if ((!padapter->bDriverStopped) &&
2027 (!padapter->bSurpriseRemoved)) {
2028 /* indicate this recv_frame */
2029 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func recv_indicatepkt\n"));
2030 rtw_recv_indicatepkt(padapter, prframe);
2032 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("@@@@ process_recv_indicatepkts- recv_func free_indicatepkt\n"));
2034 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter->bDriverStopped, padapter->bSurpriseRemoved));
2043 static int recv_func_prehandle(struct adapter *padapter, union recv_frame *rframe)
2046 struct rx_pkt_attrib *pattrib = &rframe->u.hdr.attrib;
2047 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2048 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2050 if (padapter->registrypriv.mp_mode == 1) {
2051 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)) { /* padapter->mppriv.check_mp_pkt == 0)) */
2052 if (pattrib->crc_err == 1)
2053 padapter->mppriv.rx_crcerrpktcount++;
2055 padapter->mppriv.rx_pktcount++;
2057 if (check_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE) == false) {
2058 RT_TRACE(_module_rtl871x_recv_c_, _drv_alert_, ("MP - Not in loopback mode , drop pkt\n"));
2060 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
2066 /* check the frame crtl field and decache */
2067 ret = validate_recv_frame(padapter, rframe);
2068 if (ret != _SUCCESS) {
2069 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recv_func: validate_recv_frame fail! drop pkt\n"));
2070 rtw_free_recvframe(rframe, pfree_recv_queue);/* free this recv_frame */
2078 static int recv_func_posthandle(struct adapter *padapter, union recv_frame *prframe)
2081 union recv_frame *orig_prframe = prframe;
2082 struct recv_priv *precvpriv = &padapter->recvpriv;
2083 struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
2086 rtw_led_control(padapter, LED_CTL_RX);
2088 prframe = decryptor(padapter, prframe);
2089 if (prframe == NULL) {
2090 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("decryptor: drop pkt\n"));
2092 goto _recv_data_drop;
2095 prframe = recvframe_chk_defrag(padapter, prframe);
2096 if (prframe == NULL) {
2097 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chk_defrag: drop pkt\n"));
2098 goto _recv_data_drop;
2101 prframe = portctrl(padapter, prframe);
2102 if (prframe == NULL) {
2103 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("portctrl: drop pkt\n"));
2105 goto _recv_data_drop;
2108 count_rx_stats(padapter, prframe, NULL);
2110 ret = process_recv_indicatepkts(padapter, prframe);
2111 if (ret != _SUCCESS) {
2112 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recv_func: process_recv_indicatepkts fail!\n"));
2113 rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */
2114 goto _recv_data_drop;
2119 precvpriv->rx_drop++;
2123 static int recv_func(struct adapter *padapter, union recv_frame *rframe)
2126 struct rx_pkt_attrib *prxattrib = &rframe->u.hdr.attrib;
2127 struct security_priv *psecuritypriv = &padapter->securitypriv;
2128 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
2130 /* check if need to handle uc_swdec_pending_queue*/
2131 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && psecuritypriv->busetkipkey) {
2132 union recv_frame *pending_frame;
2134 while ((pending_frame = rtw_alloc_recvframe(&padapter->recvpriv.uc_swdec_pending_queue))) {
2135 if (recv_func_posthandle(padapter, pending_frame) == _SUCCESS)
2136 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
2140 ret = recv_func_prehandle(padapter, rframe);
2142 if (ret == _SUCCESS) {
2143 /* check if need to enqueue into uc_swdec_pending_queue*/
2144 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
2145 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 &&
2146 (prxattrib->bdecrypted == 0 || psecuritypriv->sw_decrypt) &&
2147 !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) &&
2148 !psecuritypriv->busetkipkey) {
2149 rtw_enqueue_recvframe(rframe, &padapter->recvpriv.uc_swdec_pending_queue);
2150 DBG_88E("%s: no key, enqueue uc_swdec_pending_queue\n", __func__);
2154 ret = recv_func_posthandle(padapter, rframe);
2161 s32 rtw_recv_entry(union recv_frame *precvframe)
2163 struct adapter *padapter;
2164 struct recv_priv *precvpriv;
2168 padapter = precvframe->u.hdr.adapter;
2170 precvpriv = &padapter->recvpriv;
2172 ret = recv_func(padapter, precvframe);
2174 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("rtw_recv_entry: recv_func return fail!!!\n"));
2175 goto _recv_entry_drop;
2178 precvpriv->rx_pkts++;
2185 if (padapter->registrypriv.mp_mode == 1)
2186 padapter->mppriv.rx_pktloss = precvpriv->rx_drop;
2192 void rtw_signal_stat_timer_hdl(RTW_TIMER_HDL_ARGS)
2194 struct adapter *adapter = (struct adapter *)FunctionContext;
2195 struct recv_priv *recvpriv = &adapter->recvpriv;
2198 u8 avg_signal_strength = 0;
2199 u8 avg_signal_qual = 0;
2200 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2202 if (adapter->recvpriv.is_signal_dbg) {
2203 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */
2204 adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg;
2205 adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg);
2207 if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */
2208 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2209 /* after avg_vals are accquired, we can re-stat the signal values */
2210 recvpriv->signal_strength_data.update_req = 1;
2213 if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */
2214 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2215 /* after avg_vals are accquired, we can re-stat the signal values */
2216 recvpriv->signal_qual_data.update_req = 1;
2219 /* update value of signal_strength, rssi, signal_qual */
2220 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) {
2221 tmp_s = (avg_signal_strength+(_alpha-1)*recvpriv->signal_strength);
2223 tmp_s = tmp_s/_alpha + 1;
2225 tmp_s = tmp_s/_alpha;
2229 tmp_q = (avg_signal_qual+(_alpha-1)*recvpriv->signal_qual);
2231 tmp_q = tmp_q/_alpha + 1;
2233 tmp_q = tmp_q/_alpha;
2237 recvpriv->signal_strength = tmp_s;
2238 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2239 recvpriv->signal_qual = tmp_q;
2242 rtw_set_signal_stat_timer(recvpriv);