1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 #include <linux/ieee80211.h>
24 #include <osdep_service.h>
25 #include <drv_types.h>
26 #include <recv_osdep.h>
27 #include <mlme_osdep.h>
29 #include <linux/vmalloc.h>
31 #define ETHERNET_HEADER_SIZE 14 /* Ethernet Header Length */
32 #define LLC_HEADER_SIZE 6 /* LLC Header Length */
34 static u8 SNAP_ETH_TYPE_IPX
[2] = {0x81, 0x37};
35 static u8 SNAP_ETH_TYPE_APPLETALK_AARP
[2] = {0x80, 0xf3};
37 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
38 static u8 rtw_bridge_tunnel_header
[] = {
39 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8
42 static u8 rtw_rfc1042_header
[] = {
43 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00
46 void rtw_signal_stat_timer_hdl(unsigned long data
);
48 void _rtw_init_sta_recv_priv(struct sta_recv_priv
*psta_recvpriv
)
51 memset((u8
*)psta_recvpriv
, 0, sizeof(struct sta_recv_priv
));
53 spin_lock_init(&psta_recvpriv
->lock
);
55 _rtw_init_queue(&psta_recvpriv
->defrag_q
);
59 int _rtw_init_recv_priv(struct recv_priv
*precvpriv
, struct adapter
*padapter
)
63 struct recv_frame
*precvframe
;
67 _rtw_init_queue(&precvpriv
->free_recv_queue
);
68 _rtw_init_queue(&precvpriv
->recv_pending_queue
);
69 _rtw_init_queue(&precvpriv
->uc_swdec_pending_queue
);
71 precvpriv
->adapter
= padapter
;
73 precvpriv
->free_recvframe_cnt
= NR_RECVFRAME
;
75 precvpriv
->pallocated_frame_buf
= vzalloc(NR_RECVFRAME
* sizeof(struct recv_frame
) + RXFRAME_ALIGN_SZ
);
77 if (!precvpriv
->pallocated_frame_buf
)
80 precvpriv
->precv_frame_buf
= (u8
*)N_BYTE_ALIGMENT((size_t)(precvpriv
->pallocated_frame_buf
), RXFRAME_ALIGN_SZ
);
82 precvframe
= (struct recv_frame
*)precvpriv
->precv_frame_buf
;
84 for (i
= 0; i
< NR_RECVFRAME
; i
++) {
85 INIT_LIST_HEAD(&(precvframe
->list
));
87 list_add_tail(&(precvframe
->list
),
88 &(precvpriv
->free_recv_queue
.queue
));
90 rtw_os_recv_resource_alloc(precvframe
);
94 precvframe
->adapter
= padapter
;
97 precvpriv
->rx_pending_cnt
= 1;
99 res
= rtw_hal_init_recv_priv(padapter
);
101 setup_timer(&precvpriv
->signal_stat_timer
,
102 rtw_signal_stat_timer_hdl
,
103 (unsigned long)padapter
);
105 precvpriv
->signal_stat_sampling_interval
= 1000; /* ms */
107 rtw_set_signal_stat_timer(precvpriv
);
112 void _rtw_free_recv_priv(struct recv_priv
*precvpriv
)
114 struct adapter
*padapter
= precvpriv
->adapter
;
116 rtw_free_uc_swdec_pending_queue(padapter
);
118 if (precvpriv
->pallocated_frame_buf
) {
119 vfree(precvpriv
->pallocated_frame_buf
);
122 rtw_hal_free_recv_priv(padapter
);
126 struct recv_frame
*_rtw_alloc_recvframe(struct __queue
*pfree_recv_queue
)
128 struct recv_frame
*hdr
;
129 struct list_head
*plist
, *phead
;
130 struct adapter
*padapter
;
131 struct recv_priv
*precvpriv
;
133 if (list_empty(&pfree_recv_queue
->queue
)) {
136 phead
= get_list_head(pfree_recv_queue
);
140 hdr
= container_of(plist
, struct recv_frame
, list
);
142 list_del_init(&hdr
->list
);
143 padapter
= hdr
->adapter
;
144 if (padapter
!= NULL
) {
145 precvpriv
= &padapter
->recvpriv
;
146 if (pfree_recv_queue
== &precvpriv
->free_recv_queue
)
147 precvpriv
->free_recvframe_cnt
--;
151 return (struct recv_frame
*)hdr
;
154 struct recv_frame
*rtw_alloc_recvframe(struct __queue
*pfree_recv_queue
)
156 struct recv_frame
*precvframe
;
158 spin_lock_bh(&pfree_recv_queue
->lock
);
160 precvframe
= _rtw_alloc_recvframe(pfree_recv_queue
);
162 spin_unlock_bh(&pfree_recv_queue
->lock
);
167 int rtw_free_recvframe(struct recv_frame
*precvframe
,
168 struct __queue
*pfree_recv_queue
)
170 struct adapter
*padapter
;
171 struct recv_priv
*precvpriv
;
175 padapter
= precvframe
->adapter
;
176 precvpriv
= &padapter
->recvpriv
;
177 if (precvframe
->pkt
) {
178 dev_kfree_skb_any(precvframe
->pkt
);/* free skb by driver */
179 precvframe
->pkt
= NULL
;
182 spin_lock_bh(&pfree_recv_queue
->lock
);
184 list_del_init(&(precvframe
->list
));
188 list_add_tail(&(precvframe
->list
), get_list_head(pfree_recv_queue
));
190 if (padapter
!= NULL
) {
191 if (pfree_recv_queue
== &precvpriv
->free_recv_queue
)
192 precvpriv
->free_recvframe_cnt
++;
195 spin_unlock_bh(&pfree_recv_queue
->lock
);
200 int _rtw_enqueue_recvframe(struct recv_frame
*precvframe
, struct __queue
*queue
)
202 struct adapter
*padapter
= precvframe
->adapter
;
203 struct recv_priv
*precvpriv
= &padapter
->recvpriv
;
205 list_del_init(&(precvframe
->list
));
206 list_add_tail(&(precvframe
->list
), get_list_head(queue
));
208 if (padapter
!= NULL
) {
209 if (queue
== &precvpriv
->free_recv_queue
)
210 precvpriv
->free_recvframe_cnt
++;
216 int rtw_enqueue_recvframe(struct recv_frame
*precvframe
, struct __queue
*queue
)
220 spin_lock_bh(&queue
->lock
);
221 ret
= _rtw_enqueue_recvframe(precvframe
, queue
);
222 spin_unlock_bh(&queue
->lock
);
228 caller : defrag ; recvframe_chk_defrag in recv_thread (passive)
229 pframequeue: defrag_queue : will be accessed in recv_thread (passive)
231 using spinlock to protect
235 void rtw_free_recvframe_queue(struct __queue
*pframequeue
, struct __queue
*pfree_recv_queue
)
237 struct recv_frame
*hdr
;
238 struct list_head
*plist
, *phead
;
240 spin_lock(&pframequeue
->lock
);
242 phead
= get_list_head(pframequeue
);
245 while (phead
!= plist
) {
246 hdr
= container_of(plist
, struct recv_frame
, list
);
250 rtw_free_recvframe((struct recv_frame
*)hdr
, pfree_recv_queue
);
253 spin_unlock(&pframequeue
->lock
);
257 u32
rtw_free_uc_swdec_pending_queue(struct adapter
*adapter
)
260 struct recv_frame
*pending_frame
;
261 while ((pending_frame
= rtw_alloc_recvframe(&adapter
->recvpriv
.uc_swdec_pending_queue
))) {
262 rtw_free_recvframe(pending_frame
, &adapter
->recvpriv
.free_recv_queue
);
263 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__
);
270 static int recvframe_chkmic(struct adapter
*adapter
,
271 struct recv_frame
*precvframe
)
273 int i
, res
= _SUCCESS
;
276 u8 bmic_err
= false, brpt_micerror
= true;
277 u8
*pframe
, *payload
, *pframemic
;
279 struct sta_info
*stainfo
;
280 struct rx_pkt_attrib
*prxattrib
= &precvframe
->attrib
;
281 struct security_priv
*psecuritypriv
= &adapter
->securitypriv
;
283 struct mlme_ext_priv
*pmlmeext
= &adapter
->mlmeextpriv
;
284 struct mlme_ext_info
*pmlmeinfo
= &(pmlmeext
->mlmext_info
);
286 stainfo
= rtw_get_stainfo(&adapter
->stapriv
, &prxattrib
->ta
[0]);
288 if (prxattrib
->encrypt
== _TKIP_
) {
289 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("\n recvframe_chkmic:prxattrib->encrypt==_TKIP_\n"));
290 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",
291 prxattrib
->ra
[0], prxattrib
->ra
[1], prxattrib
->ra
[2], prxattrib
->ra
[3], prxattrib
->ra
[4], prxattrib
->ra
[5]));
293 /* calculate mic code */
294 if (stainfo
!= NULL
) {
295 if (IS_MCAST(prxattrib
->ra
)) {
296 if (!psecuritypriv
) {
298 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n"));
299 DBG_88E("\n recvframe_chkmic:didn't install group key!!!!!!!!!!\n");
302 mickey
= &psecuritypriv
->dot118021XGrprxmickey
[prxattrib
->key_index
].skey
[0];
304 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("\n recvframe_chkmic: bcmc key\n"));
306 mickey
= &stainfo
->dot11tkiprxmickey
.skey
[0];
307 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("\n recvframe_chkmic: unicast key\n"));
310 /* icv_len included the mic code */
311 datalen
= precvframe
->len
-prxattrib
->hdrlen
-
312 prxattrib
->iv_len
-prxattrib
->icv_len
-8;
313 pframe
= precvframe
->rx_data
;
314 payload
= pframe
+prxattrib
->hdrlen
+prxattrib
->iv_len
;
316 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n", prxattrib
->iv_len
, prxattrib
->icv_len
));
317 rtw_seccalctkipmic(mickey
, pframe
, payload
, datalen
, &miccode
[0],
318 (unsigned char)prxattrib
->priority
); /* care the length of the data */
320 pframemic
= payload
+datalen
;
324 for (i
= 0; i
< 8; i
++) {
325 if (miccode
[i
] != *(pframemic
+i
)) {
326 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
,
327 ("recvframe_chkmic:miccode[%d](%02x)!=*(pframemic+%d)(%02x) ",
328 i
, miccode
[i
], i
, *(pframemic
+i
)));
334 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
,
335 ("\n *(pframemic-8)-*(pframemic-1)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
336 *(pframemic
-8), *(pframemic
-7), *(pframemic
-6),
337 *(pframemic
-5), *(pframemic
-4), *(pframemic
-3),
338 *(pframemic
-2), *(pframemic
-1)));
339 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
,
340 ("\n *(pframemic-16)-*(pframemic-9)=0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
341 *(pframemic
-16), *(pframemic
-15), *(pframemic
-14),
342 *(pframemic
-13), *(pframemic
-12), *(pframemic
-11),
343 *(pframemic
-10), *(pframemic
-9)));
346 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
,
347 ("\n ======demp packet (len=%d)======\n",
349 for (i
= 0; i
< precvframe
->len
; i
+= 8) {
350 RT_TRACE(_module_rtl871x_recv_c_
,
352 ("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
353 *(precvframe
->rx_data
+i
),
354 *(precvframe
->rx_data
+i
+1),
355 *(precvframe
->rx_data
+i
+2),
356 *(precvframe
->rx_data
+i
+3),
357 *(precvframe
->rx_data
+i
+4),
358 *(precvframe
->rx_data
+i
+5),
359 *(precvframe
->rx_data
+i
+6),
360 *(precvframe
->rx_data
+i
+7)));
362 RT_TRACE(_module_rtl871x_recv_c_
,
364 ("\n ====== demp packet end [len=%d]======\n",
366 RT_TRACE(_module_rtl871x_recv_c_
,
372 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
,
373 ("ra=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x psecuritypriv->binstallGrpkey=%d ",
374 prxattrib
->ra
[0], prxattrib
->ra
[1], prxattrib
->ra
[2],
375 prxattrib
->ra
[3], prxattrib
->ra
[4], prxattrib
->ra
[5], psecuritypriv
->binstallGrpkey
));
377 /* double check key_index for some timing issue , */
378 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
379 if ((IS_MCAST(prxattrib
->ra
) == true) && (prxattrib
->key_index
!= pmlmeinfo
->key_index
))
380 brpt_micerror
= false;
382 if ((prxattrib
->bdecrypted
) && (brpt_micerror
)) {
383 rtw_handle_tkip_mic_err(adapter
, (u8
)IS_MCAST(prxattrib
->ra
));
384 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, (" mic error :prxattrib->bdecrypted=%d ", prxattrib
->bdecrypted
));
385 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib
->bdecrypted
);
387 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, (" mic error :prxattrib->bdecrypted=%d ", prxattrib
->bdecrypted
));
388 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib
->bdecrypted
);
393 if ((!psecuritypriv
->bcheck_grpkey
) && (IS_MCAST(prxattrib
->ra
))) {
394 psecuritypriv
->bcheck_grpkey
= true;
395 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("psecuritypriv->bcheck_grpkey = true"));
399 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
402 recvframe_pull_tail(precvframe
, 8);
410 /* decrypt and set the ivlen, icvlen of the recv_frame */
411 static struct recv_frame
*decryptor(struct adapter
*padapter
,
412 struct recv_frame
*precv_frame
)
414 struct rx_pkt_attrib
*prxattrib
= &precv_frame
->attrib
;
415 struct security_priv
*psecuritypriv
= &padapter
->securitypriv
;
416 struct recv_frame
*return_packet
= precv_frame
;
419 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("prxstat->decrypted=%x prxattrib->encrypt=0x%03x\n", prxattrib
->bdecrypted
, prxattrib
->encrypt
));
421 if (prxattrib
->encrypt
> 0) {
422 u8
*iv
= precv_frame
->rx_data
+prxattrib
->hdrlen
;
423 prxattrib
->key_index
= (((iv
[3])>>6)&0x3);
425 if (prxattrib
->key_index
> WEP_KEYS
) {
426 DBG_88E("prxattrib->key_index(%d)>WEP_KEYS\n", prxattrib
->key_index
);
428 switch (prxattrib
->encrypt
) {
431 prxattrib
->key_index
= psecuritypriv
->dot11PrivacyKeyIndex
;
436 prxattrib
->key_index
= psecuritypriv
->dot118021XGrpKeyid
;
442 if ((prxattrib
->encrypt
> 0) && ((prxattrib
->bdecrypted
== 0) || (psecuritypriv
->sw_decrypt
))) {
443 psecuritypriv
->hw_decrypted
= false;
445 switch (prxattrib
->encrypt
) {
448 rtw_wep_decrypt(padapter
, (u8
*)precv_frame
);
451 res
= rtw_tkip_decrypt(padapter
, (u8
*)precv_frame
);
454 res
= rtw_aes_decrypt(padapter
, (u8
*)precv_frame
);
459 } else if (prxattrib
->bdecrypted
== 1 && prxattrib
->encrypt
> 0 &&
460 (psecuritypriv
->busetkipkey
== 1 || prxattrib
->encrypt
!= _TKIP_
))
461 psecuritypriv
->hw_decrypted
= true;
464 rtw_free_recvframe(return_packet
, &padapter
->recvpriv
.free_recv_queue
);
465 return_packet
= NULL
;
468 return return_packet
;
471 /* set the security information in the recv_frame */
472 static struct recv_frame
*portctrl(struct adapter
*adapter
,
473 struct recv_frame
*precv_frame
)
477 struct recv_frame
*pfhdr
;
478 struct sta_info
*psta
;
479 struct sta_priv
*pstapriv
;
480 struct recv_frame
*prtnframe
;
482 u16 eapol_type
= 0x888e;/* for Funia BD's WPA issue */
483 struct rx_pkt_attrib
*pattrib
;
486 pstapriv
= &adapter
->stapriv
;
488 auth_alg
= adapter
->securitypriv
.dot11AuthAlgrthm
;
490 ptr
= precv_frame
->rx_data
;
492 pattrib
= &pfhdr
->attrib
;
493 psta_addr
= pattrib
->ta
;
494 psta
= rtw_get_stainfo(pstapriv
, psta_addr
);
498 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n", adapter
->securitypriv
.dot11AuthAlgrthm
));
502 ptr
= ptr
+ pfhdr
->attrib
.hdrlen
+ LLC_HEADER_SIZE
;
503 memcpy(&be_tmp
, ptr
, 2);
504 ether_type
= ntohs(be_tmp
);
506 if ((psta
!= NULL
) && (psta
->ieee8021x_blocked
)) {
508 /* only accept EAPOL frame */
509 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("########portctrl:psta->ieee8021x_blocked==1\n"));
511 if (ether_type
== eapol_type
) {
512 prtnframe
= precv_frame
;
514 /* free this frame */
515 rtw_free_recvframe(precv_frame
, &adapter
->recvpriv
.free_recv_queue
);
520 /* check decryption status, and decrypt the frame if needed */
521 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("########portctrl:psta->ieee8021x_blocked==0\n"));
522 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
,
523 ("portctrl:precv_frame->hdr.attrib.privacy=%x\n",
524 precv_frame
->attrib
.privacy
));
526 if (pattrib
->bdecrypted
== 0)
527 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("portctrl:prxstat->decrypted=%x\n", pattrib
->bdecrypted
));
529 prtnframe
= precv_frame
;
530 /* check is the EAPOL frame or not (Rekey) */
531 if (ether_type
== eapol_type
) {
532 RT_TRACE(_module_rtl871x_recv_c_
, _drv_notice_
, ("########portctrl:ether_type==0x888e\n"));
535 prtnframe
= precv_frame
;
537 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("########portctrl:ether_type=0x%04x\n", ether_type
));
541 prtnframe
= precv_frame
;
547 static int recv_decache(struct recv_frame
*precv_frame
, u8 bretry
,
548 struct stainfo_rxcache
*prxcache
)
550 int tid
= precv_frame
->attrib
.priority
;
552 u16 seq_ctrl
= ((precv_frame
->attrib
.seq_num
&0xffff) << 4) |
553 (precv_frame
->attrib
.frag_num
& 0xf);
556 RT_TRACE(_module_rtl871x_recv_c_
, _drv_notice_
, ("recv_decache, (tid>15)! seq_ctrl=0x%x, tid=0x%x\n", seq_ctrl
, tid
));
561 if (1) {/* if (bretry) */
562 if (seq_ctrl
== prxcache
->tid_rxseq
[tid
]) {
563 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
]));
569 prxcache
->tid_rxseq
[tid
] = seq_ctrl
;
574 static void process_pwrbit_data(struct adapter
*padapter
,
575 struct recv_frame
*precv_frame
)
577 #ifdef CONFIG_88EU_AP_MODE
578 unsigned char pwrbit
;
579 u8
*ptr
= precv_frame
->rx_data
;
580 struct rx_pkt_attrib
*pattrib
= &precv_frame
->attrib
;
581 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
582 struct sta_info
*psta
= NULL
;
584 psta
= rtw_get_stainfo(pstapriv
, pattrib
->src
);
586 pwrbit
= GetPwrMgt(ptr
);
590 if (!(psta
->state
& WIFI_SLEEP_STATE
))
591 stop_sta_xmit(padapter
, psta
);
593 if (psta
->state
& WIFI_SLEEP_STATE
)
594 wakeup_sta_to_xmit(padapter
, psta
);
601 static void process_wmmps_data(struct adapter
*padapter
,
602 struct recv_frame
*precv_frame
)
604 #ifdef CONFIG_88EU_AP_MODE
605 struct rx_pkt_attrib
*pattrib
= &precv_frame
->attrib
;
606 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
607 struct sta_info
*psta
= NULL
;
609 psta
= rtw_get_stainfo(pstapriv
, pattrib
->src
);
614 if (!psta
->qos_option
)
617 if (!(psta
->qos_info
&0xf))
620 if (psta
->state
&WIFI_SLEEP_STATE
) {
623 switch (pattrib
->priority
) {
626 wmmps_ac
= psta
->uapsd_bk
&BIT(1);
630 wmmps_ac
= psta
->uapsd_vi
&BIT(1);
634 wmmps_ac
= psta
->uapsd_vo
&BIT(1);
639 wmmps_ac
= psta
->uapsd_be
&BIT(1);
644 if (psta
->sleepq_ac_len
> 0) {
645 /* process received triggered frame */
646 xmit_delivery_enabled_frames(padapter
, psta
);
648 /* issue one qos null frame with More data bit = 0 and the EOSP bit set (= 1) */
649 issue_qos_nulldata(padapter
, psta
->hwaddr
, (u16
)pattrib
->priority
, 0, 0);
657 static void count_rx_stats(struct adapter
*padapter
,
658 struct recv_frame
*prframe
,
659 struct sta_info
*sta
)
662 struct sta_info
*psta
= NULL
;
663 struct stainfo_stats
*pstats
= NULL
;
664 struct rx_pkt_attrib
*pattrib
= &prframe
->attrib
;
665 struct recv_priv
*precvpriv
= &padapter
->recvpriv
;
668 precvpriv
->rx_bytes
+= sz
;
670 padapter
->mlmepriv
.LinkDetectInfo
.NumRxOkInPeriod
++;
672 if ((!MacAddr_isBcst(pattrib
->dst
)) && (!IS_MCAST(pattrib
->dst
)))
673 padapter
->mlmepriv
.LinkDetectInfo
.NumRxUnicastOkInPeriod
++;
678 psta
= prframe
->psta
;
681 pstats
= &psta
->sta_stats
;
683 pstats
->rx_data_pkts
++;
684 pstats
->rx_bytes
+= sz
;
688 int sta2sta_data_frame(
689 struct adapter
*adapter
,
690 struct recv_frame
*precv_frame
,
691 struct sta_info
**psta
694 int sta2sta_data_frame(struct adapter
*adapter
, struct recv_frame
*precv_frame
,
695 struct sta_info
**psta
)
697 u8
*ptr
= precv_frame
->rx_data
;
699 struct rx_pkt_attrib
*pattrib
= &precv_frame
->attrib
;
700 struct sta_priv
*pstapriv
= &adapter
->stapriv
;
701 struct mlme_priv
*pmlmepriv
= &adapter
->mlmepriv
;
702 u8
*mybssid
= get_bssid(pmlmepriv
);
703 u8
*myhwaddr
= myid(&adapter
->eeprompriv
);
705 int bmcast
= IS_MCAST(pattrib
->dst
);
707 if ((check_fwstate(pmlmepriv
, WIFI_ADHOC_STATE
) == true) ||
708 (check_fwstate(pmlmepriv
, WIFI_ADHOC_MASTER_STATE
) == true)) {
709 /* filter packets that SA is myself or multicast or broadcast */
710 if (!memcmp(myhwaddr
, pattrib
->src
, ETH_ALEN
)) {
711 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, (" SA==myself\n"));
716 if ((memcmp(myhwaddr
, pattrib
->dst
, ETH_ALEN
)) && (!bmcast
)) {
721 if (!memcmp(pattrib
->bssid
, "\x0\x0\x0\x0\x0\x0", ETH_ALEN
) ||
722 !memcmp(mybssid
, "\x0\x0\x0\x0\x0\x0", ETH_ALEN
) ||
723 memcmp(pattrib
->bssid
, mybssid
, ETH_ALEN
)) {
728 sta_addr
= pattrib
->src
;
729 } else if (check_fwstate(pmlmepriv
, WIFI_STATION_STATE
)) {
730 /* For Station mode, sa and bssid should always be BSSID, and DA is my mac-address */
731 if (memcmp(pattrib
->bssid
, pattrib
->src
, ETH_ALEN
)) {
732 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("bssid!=TA under STATION_MODE; drop pkt\n"));
736 sta_addr
= pattrib
->bssid
;
737 } else if (check_fwstate(pmlmepriv
, WIFI_AP_STATE
)) {
739 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
740 if (!IS_MCAST(pattrib
->bssid
)) {
744 } else { /* not mc-frame */
745 /* For AP mode, if DA is non-MCAST, then it must be BSSID, and bssid == BSSID */
746 if (memcmp(pattrib
->bssid
, pattrib
->dst
, ETH_ALEN
)) {
751 sta_addr
= pattrib
->src
;
753 } else if (check_fwstate(pmlmepriv
, WIFI_MP_STATE
)) {
754 memcpy(pattrib
->dst
, GetAddr1Ptr(ptr
), ETH_ALEN
);
755 memcpy(pattrib
->src
, GetAddr2Ptr(ptr
), ETH_ALEN
);
756 memcpy(pattrib
->bssid
, GetAddr3Ptr(ptr
), ETH_ALEN
);
757 memcpy(pattrib
->ra
, pattrib
->dst
, ETH_ALEN
);
758 memcpy(pattrib
->ta
, pattrib
->src
, ETH_ALEN
);
766 *psta
= rtw_get_bcmc_stainfo(adapter
);
768 *psta
= rtw_get_stainfo(pstapriv
, sta_addr
); /* get ap_info */
771 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("can't get psta under sta2sta_data_frame ; drop pkt\n"));
780 static int ap2sta_data_frame(
781 struct adapter
*adapter
,
782 struct recv_frame
*precv_frame
,
783 struct sta_info
**psta
)
785 u8
*ptr
= precv_frame
->rx_data
;
786 struct rx_pkt_attrib
*pattrib
= &precv_frame
->attrib
;
788 struct sta_priv
*pstapriv
= &adapter
->stapriv
;
789 struct mlme_priv
*pmlmepriv
= &adapter
->mlmepriv
;
790 u8
*mybssid
= get_bssid(pmlmepriv
);
791 u8
*myhwaddr
= myid(&adapter
->eeprompriv
);
792 int bmcast
= IS_MCAST(pattrib
->dst
);
794 if ((check_fwstate(pmlmepriv
, WIFI_STATION_STATE
) == true) &&
795 (check_fwstate(pmlmepriv
, _FW_LINKED
) == true ||
796 check_fwstate(pmlmepriv
, _FW_UNDER_LINKING
))) {
797 /* filter packets that SA is myself or multicast or broadcast */
798 if (!memcmp(myhwaddr
, pattrib
->src
, ETH_ALEN
)) {
799 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, (" SA==myself\n"));
804 /* da should be for me */
805 if ((memcmp(myhwaddr
, pattrib
->dst
, ETH_ALEN
)) && (!bmcast
)) {
806 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
,
807 (" ap2sta_data_frame: compare DA fail; DA=%pM\n", (pattrib
->dst
)));
813 if (!memcmp(pattrib
->bssid
, "\x0\x0\x0\x0\x0\x0", ETH_ALEN
) ||
814 !memcmp(mybssid
, "\x0\x0\x0\x0\x0\x0", ETH_ALEN
) ||
815 (memcmp(pattrib
->bssid
, mybssid
, ETH_ALEN
))) {
816 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
,
817 (" ap2sta_data_frame: compare BSSID fail ; BSSID=%pM\n", (pattrib
->bssid
)));
818 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("mybssid=%pM\n", (mybssid
)));
821 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib
->bssid
));
822 issue_deauth(adapter
, pattrib
->bssid
, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
830 *psta
= rtw_get_bcmc_stainfo(adapter
);
832 *psta
= rtw_get_stainfo(pstapriv
, pattrib
->bssid
); /* get ap_info */
835 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("ap2sta: can't get psta under STATION_MODE ; drop pkt\n"));
840 /* if ((GetFrameSubType(ptr) & WIFI_QOS_DATA_TYPE) == WIFI_QOS_DATA_TYPE) { */
843 if (GetFrameSubType(ptr
) & BIT(6)) {
844 /* No data, will not indicate to upper layer, temporily count it here */
845 count_rx_stats(adapter
, precv_frame
, *psta
);
846 ret
= RTW_RX_HANDLED
;
849 } else if ((check_fwstate(pmlmepriv
, WIFI_MP_STATE
) == true) &&
850 (check_fwstate(pmlmepriv
, _FW_LINKED
) == true)) {
851 memcpy(pattrib
->dst
, GetAddr1Ptr(ptr
), ETH_ALEN
);
852 memcpy(pattrib
->src
, GetAddr2Ptr(ptr
), ETH_ALEN
);
853 memcpy(pattrib
->bssid
, GetAddr3Ptr(ptr
), ETH_ALEN
);
854 memcpy(pattrib
->ra
, pattrib
->dst
, ETH_ALEN
);
855 memcpy(pattrib
->ta
, pattrib
->src
, ETH_ALEN
);
858 memcpy(pattrib
->bssid
, mybssid
, ETH_ALEN
);
860 *psta
= rtw_get_stainfo(pstapriv
, pattrib
->bssid
); /* get sta_info */
862 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("can't get psta under MP_MODE ; drop pkt\n"));
866 } else if (check_fwstate(pmlmepriv
, WIFI_AP_STATE
)) {
868 ret
= RTW_RX_HANDLED
;
871 if (!memcmp(myhwaddr
, pattrib
->dst
, ETH_ALEN
) && (!bmcast
)) {
872 *psta
= rtw_get_stainfo(pstapriv
, pattrib
->bssid
); /* get sta_info */
874 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib
->bssid
));
876 issue_deauth(adapter
, pattrib
->bssid
, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
888 static int sta2ap_data_frame(struct adapter
*adapter
,
889 struct recv_frame
*precv_frame
,
890 struct sta_info
**psta
)
892 struct rx_pkt_attrib
*pattrib
= &precv_frame
->attrib
;
893 struct sta_priv
*pstapriv
= &adapter
->stapriv
;
894 struct mlme_priv
*pmlmepriv
= &adapter
->mlmepriv
;
895 u8
*ptr
= precv_frame
->rx_data
;
896 unsigned char *mybssid
= get_bssid(pmlmepriv
);
899 if (check_fwstate(pmlmepriv
, WIFI_AP_STATE
) == true) {
900 /* For AP mode, RA = BSSID, TX = STA(SRC_ADDR), A3 = DST_ADDR */
901 if (memcmp(pattrib
->bssid
, mybssid
, ETH_ALEN
)) {
906 *psta
= rtw_get_stainfo(pstapriv
, pattrib
->src
);
908 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("can't get psta under AP_MODE; drop pkt\n"));
909 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib
->src
));
911 issue_deauth(adapter
, pattrib
->src
, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
913 ret
= RTW_RX_HANDLED
;
917 process_pwrbit_data(adapter
, precv_frame
);
919 if ((GetFrameSubType(ptr
) & WIFI_QOS_DATA_TYPE
) == WIFI_QOS_DATA_TYPE
) {
920 process_wmmps_data(adapter
, precv_frame
);
923 if (GetFrameSubType(ptr
) & BIT(6)) {
924 /* No data, will not indicate to upper layer, temporily count it here */
925 count_rx_stats(adapter
, precv_frame
, *psta
);
926 ret
= RTW_RX_HANDLED
;
930 u8
*myhwaddr
= myid(&adapter
->eeprompriv
);
931 if (memcmp(pattrib
->ra
, myhwaddr
, ETH_ALEN
)) {
932 ret
= RTW_RX_HANDLED
;
935 DBG_88E("issue_deauth to sta=%pM for the reason(7)\n", (pattrib
->src
));
936 issue_deauth(adapter
, pattrib
->src
, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
);
937 ret
= RTW_RX_HANDLED
;
946 static int validate_recv_ctrl_frame(struct adapter
*padapter
,
947 struct recv_frame
*precv_frame
)
949 #ifdef CONFIG_88EU_AP_MODE
950 struct rx_pkt_attrib
*pattrib
= &precv_frame
->attrib
;
951 struct sta_priv
*pstapriv
= &padapter
->stapriv
;
952 u8
*pframe
= precv_frame
->rx_data
;
954 if (GetFrameType(pframe
) != WIFI_CTRL_TYPE
)
957 /* receive the frames that ra(a1) is my address */
958 if (memcmp(GetAddr1Ptr(pframe
), myid(&padapter
->eeprompriv
), ETH_ALEN
))
961 /* only handle ps-poll */
962 if (GetFrameSubType(pframe
) == WIFI_PSPOLL
) {
965 struct sta_info
*psta
= NULL
;
967 aid
= GetAid(pframe
);
968 psta
= rtw_get_stainfo(pstapriv
, GetAddr2Ptr(pframe
));
970 if ((psta
== NULL
) || (psta
->aid
!= aid
))
973 /* for rx pkt statistics */
974 psta
->sta_stats
.rx_ctrl_pkts
++;
976 switch (pattrib
->priority
) {
979 wmmps_ac
= psta
->uapsd_bk
&BIT(0);
983 wmmps_ac
= psta
->uapsd_vi
&BIT(0);
987 wmmps_ac
= psta
->uapsd_vo
&BIT(0);
992 wmmps_ac
= psta
->uapsd_be
&BIT(0);
999 if (psta
->state
& WIFI_STA_ALIVE_CHK_STATE
) {
1000 DBG_88E("%s alive check-rx ps-poll\n", __func__
);
1001 psta
->expire_to
= pstapriv
->expire_to
;
1002 psta
->state
^= WIFI_STA_ALIVE_CHK_STATE
;
1005 if ((psta
->state
&WIFI_SLEEP_STATE
) && (pstapriv
->sta_dz_bitmap
&BIT(psta
->aid
))) {
1006 struct list_head
*xmitframe_plist
, *xmitframe_phead
;
1007 struct xmit_frame
*pxmitframe
= NULL
;
1009 spin_lock_bh(&psta
->sleep_q
.lock
);
1011 xmitframe_phead
= get_list_head(&psta
->sleep_q
);
1012 xmitframe_plist
= xmitframe_phead
->next
;
1014 if (xmitframe_phead
!= xmitframe_plist
) {
1015 pxmitframe
= container_of(xmitframe_plist
, struct xmit_frame
, list
);
1017 xmitframe_plist
= xmitframe_plist
->next
;
1019 list_del_init(&pxmitframe
->list
);
1023 if (psta
->sleepq_len
> 0)
1024 pxmitframe
->attrib
.mdata
= 1;
1026 pxmitframe
->attrib
.mdata
= 0;
1028 pxmitframe
->attrib
.triggered
= 1;
1030 spin_unlock_bh(&psta
->sleep_q
.lock
);
1031 if (rtw_hal_xmit(padapter
, pxmitframe
) == true)
1032 rtw_os_xmit_complete(padapter
, pxmitframe
);
1033 spin_lock_bh(&psta
->sleep_q
.lock
);
1035 if (psta
->sleepq_len
== 0) {
1036 pstapriv
->tim_bitmap
&= ~BIT(psta
->aid
);
1038 /* update BCN for TIM IE */
1039 /* update_BCNTIM(padapter); */
1040 update_beacon(padapter
, _TIM_IE_
, NULL
, false);
1043 if (pstapriv
->tim_bitmap
&BIT(psta
->aid
)) {
1044 if (psta
->sleepq_len
== 0) {
1045 DBG_88E("no buffered packets to xmit\n");
1047 /* issue nulldata with More data bit = 0 to indicate we have no buffered packets */
1048 issue_nulldata(padapter
, psta
->hwaddr
, 0, 0, 0);
1050 DBG_88E("error!psta->sleepq_len=%d\n", psta
->sleepq_len
);
1051 psta
->sleepq_len
= 0;
1054 pstapriv
->tim_bitmap
&= ~BIT(psta
->aid
);
1056 /* update BCN for TIM IE */
1057 /* update_BCNTIM(padapter); */
1058 update_beacon(padapter
, _TIM_IE_
, NULL
, false);
1062 spin_unlock_bh(&psta
->sleep_q
.lock
);
1071 struct recv_frame
*recvframe_chk_defrag(struct adapter
*padapter
,
1072 struct recv_frame
*precv_frame
);
1074 static int validate_recv_mgnt_frame(struct adapter
*padapter
,
1075 struct recv_frame
*precv_frame
)
1077 struct sta_info
*psta
;
1079 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("+validate_recv_mgnt_frame\n"));
1081 precv_frame
= recvframe_chk_defrag(padapter
, precv_frame
);
1082 if (precv_frame
== NULL
) {
1083 RT_TRACE(_module_rtl871x_recv_c_
, _drv_notice_
, ("%s: fragment packet\n", __func__
));
1087 /* for rx pkt statistics */
1088 psta
= rtw_get_stainfo(&padapter
->stapriv
,
1089 GetAddr2Ptr(precv_frame
->rx_data
));
1091 psta
->sta_stats
.rx_mgnt_pkts
++;
1092 if (GetFrameSubType(precv_frame
->rx_data
) == WIFI_BEACON
) {
1093 psta
->sta_stats
.rx_beacon_pkts
++;
1094 } else if (GetFrameSubType(precv_frame
->rx_data
) == WIFI_PROBEREQ
) {
1095 psta
->sta_stats
.rx_probereq_pkts
++;
1096 } else if (GetFrameSubType(precv_frame
->rx_data
) == WIFI_PROBERSP
) {
1097 if (!memcmp(padapter
->eeprompriv
.mac_addr
,
1098 GetAddr1Ptr(precv_frame
->rx_data
), ETH_ALEN
))
1099 psta
->sta_stats
.rx_probersp_pkts
++;
1100 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame
->rx_data
)) ||
1101 is_multicast_mac_addr(GetAddr1Ptr(precv_frame
->rx_data
)))
1102 psta
->sta_stats
.rx_probersp_bm_pkts
++;
1104 psta
->sta_stats
.rx_probersp_uo_pkts
++;
1108 mgt_dispatcher(padapter
, precv_frame
);
1113 static int validate_recv_data_frame(struct adapter
*adapter
,
1114 struct recv_frame
*precv_frame
)
1117 u8
*psa
, *pda
, *pbssid
;
1118 struct sta_info
*psta
= NULL
;
1119 u8
*ptr
= precv_frame
->rx_data
;
1120 struct rx_pkt_attrib
*pattrib
= &precv_frame
->attrib
;
1121 struct security_priv
*psecuritypriv
= &adapter
->securitypriv
;
1124 bretry
= GetRetry(ptr
);
1127 pbssid
= get_hdr_bssid(ptr
);
1129 if (pbssid
== NULL
) {
1134 memcpy(pattrib
->dst
, pda
, ETH_ALEN
);
1135 memcpy(pattrib
->src
, psa
, ETH_ALEN
);
1137 memcpy(pattrib
->bssid
, pbssid
, ETH_ALEN
);
1139 switch (pattrib
->to_fr_ds
) {
1141 memcpy(pattrib
->ra
, pda
, ETH_ALEN
);
1142 memcpy(pattrib
->ta
, psa
, ETH_ALEN
);
1143 ret
= sta2sta_data_frame(adapter
, precv_frame
, &psta
);
1146 memcpy(pattrib
->ra
, pda
, ETH_ALEN
);
1147 memcpy(pattrib
->ta
, pbssid
, ETH_ALEN
);
1148 ret
= ap2sta_data_frame(adapter
, precv_frame
, &psta
);
1151 memcpy(pattrib
->ra
, pbssid
, ETH_ALEN
);
1152 memcpy(pattrib
->ta
, psa
, ETH_ALEN
);
1153 ret
= sta2ap_data_frame(adapter
, precv_frame
, &psta
);
1156 memcpy(pattrib
->ra
, GetAddr1Ptr(ptr
), ETH_ALEN
);
1157 memcpy(pattrib
->ta
, GetAddr2Ptr(ptr
), ETH_ALEN
);
1159 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, (" case 3\n"));
1168 } else if (ret
== RTW_RX_HANDLED
) {
1173 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, (" after to_fr_ds_chk; psta==NULL\n"));
1178 /* psta->rssi = prxcmd->rssi; */
1179 /* psta->signal_quality = prxcmd->sq; */
1180 precv_frame
->psta
= psta
;
1183 pattrib
->ack_policy
= 0;
1184 /* parsing QC field */
1185 if (pattrib
->qos
== 1) {
1186 pattrib
->priority
= GetPriority((ptr
+ 24));
1187 pattrib
->ack_policy
= GetAckpolicy((ptr
+ 24));
1188 pattrib
->amsdu
= GetAMsdu((ptr
+ 24));
1189 pattrib
->hdrlen
= pattrib
->to_fr_ds
== 3 ? 32 : 26;
1191 if (pattrib
->priority
!= 0 && pattrib
->priority
!= 3)
1192 adapter
->recvpriv
.bIsAnyNonBEPkts
= true;
1194 pattrib
->priority
= 0;
1195 pattrib
->hdrlen
= pattrib
->to_fr_ds
== 3 ? 30 : 24;
1198 if (pattrib
->order
)/* HT-CTRL 11n */
1199 pattrib
->hdrlen
+= 4;
1201 precv_frame
->preorder_ctrl
= &psta
->recvreorder_ctrl
[pattrib
->priority
];
1203 /* decache, drop duplicate recv packets */
1204 if (recv_decache(precv_frame
, bretry
, &psta
->sta_recvpriv
.rxcache
) == _FAIL
) {
1205 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("decache : drop pkt\n"));
1210 if (pattrib
->privacy
) {
1211 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("validate_recv_data_frame:pattrib->privacy=%x\n", pattrib
->privacy
));
1212 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
)));
1214 GET_ENCRY_ALGO(psecuritypriv
, psta
, pattrib
->encrypt
, IS_MCAST(pattrib
->ra
));
1216 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("\n pattrib->encrypt=%d\n", pattrib
->encrypt
));
1218 SET_ICE_IV_LEN(pattrib
->iv_len
, pattrib
->icv_len
, pattrib
->encrypt
);
1220 pattrib
->encrypt
= 0;
1221 pattrib
->iv_len
= 0;
1222 pattrib
->icv_len
= 0;
1230 static int validate_recv_frame(struct adapter
*adapter
,
1231 struct recv_frame
*precv_frame
)
1233 /* shall check frame subtype, to / from ds, da, bssid */
1235 /* then call check if rx seq/frag. duplicated. */
1239 int retval
= _SUCCESS
;
1241 struct rx_pkt_attrib
*pattrib
= &precv_frame
->attrib
;
1242 u8
*ptr
= precv_frame
->rx_data
;
1243 u8 ver
= (unsigned char)(*ptr
)&0x3;
1244 struct mlme_ext_priv
*pmlmeext
= &adapter
->mlmeextpriv
;
1246 if (pmlmeext
->sitesurvey_res
.state
== SCAN_PROCESS
) {
1247 int ch_set_idx
= rtw_ch_set_search_ch(pmlmeext
->channel_set
, rtw_get_oper_ch(adapter
));
1248 if (ch_set_idx
>= 0)
1249 pmlmeext
->channel_set
[ch_set_idx
].rx_count
++;
1252 /* add version chk */
1254 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("validate_recv_data_frame fail! (ver!=0)\n"));
1259 type
= GetFrameType(ptr
);
1260 subtype
= GetFrameSubType(ptr
); /* bit(7)~bit(2) */
1262 pattrib
->to_fr_ds
= get_tofr_ds(ptr
);
1264 pattrib
->frag_num
= GetFragNum(ptr
);
1265 pattrib
->seq_num
= GetSequence(ptr
);
1267 pattrib
->pw_save
= GetPwrMgt(ptr
);
1268 pattrib
->mfrag
= GetMFrag(ptr
);
1269 pattrib
->mdata
= GetMData(ptr
);
1270 pattrib
->privacy
= GetPrivacy(ptr
);
1271 pattrib
->order
= GetOrder(ptr
);
1273 /* Dump rx packets */
1274 rtw_hal_get_def_var(adapter
, HAL_DEF_DBG_DUMP_RXPKT
, &(bDumpRxPkt
));
1275 if (bDumpRxPkt
== 1) {/* dump all rx packets */
1277 DBG_88E("#############################\n");
1279 for (i
= 0; i
< 64; i
= i
+8)
1280 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr
+i
),
1281 *(ptr
+i
+1), *(ptr
+i
+2), *(ptr
+i
+3), *(ptr
+i
+4), *(ptr
+i
+5), *(ptr
+i
+6), *(ptr
+i
+7));
1282 DBG_88E("#############################\n");
1283 } else if (bDumpRxPkt
== 2) {
1284 if (type
== WIFI_MGT_TYPE
) {
1286 DBG_88E("#############################\n");
1288 for (i
= 0; i
< 64; i
= i
+8)
1289 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr
+i
),
1290 *(ptr
+i
+1), *(ptr
+i
+2), *(ptr
+i
+3), *(ptr
+i
+4), *(ptr
+i
+5), *(ptr
+i
+6), *(ptr
+i
+7));
1291 DBG_88E("#############################\n");
1293 } else if (bDumpRxPkt
== 3) {
1294 if (type
== WIFI_DATA_TYPE
) {
1296 DBG_88E("#############################\n");
1298 for (i
= 0; i
< 64; i
= i
+8)
1299 DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr
+i
),
1300 *(ptr
+i
+1), *(ptr
+i
+2), *(ptr
+i
+3), *(ptr
+i
+4), *(ptr
+i
+5), *(ptr
+i
+6), *(ptr
+i
+7));
1301 DBG_88E("#############################\n");
1305 case WIFI_MGT_TYPE
: /* mgnt */
1306 retval
= validate_recv_mgnt_frame(adapter
, precv_frame
);
1307 if (retval
== _FAIL
)
1308 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("validate_recv_mgnt_frame fail\n"));
1309 retval
= _FAIL
; /* only data frame return _SUCCESS */
1311 case WIFI_CTRL_TYPE
: /* ctrl */
1312 retval
= validate_recv_ctrl_frame(adapter
, precv_frame
);
1313 if (retval
== _FAIL
)
1314 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("validate_recv_ctrl_frame fail\n"));
1315 retval
= _FAIL
; /* only data frame return _SUCCESS */
1317 case WIFI_DATA_TYPE
: /* data */
1318 rtw_led_control(adapter
, LED_CTL_RX
);
1319 pattrib
->qos
= (subtype
& BIT(7)) ? 1 : 0;
1320 retval
= validate_recv_data_frame(adapter
, precv_frame
);
1321 if (retval
== _FAIL
) {
1322 struct recv_priv
*precvpriv
= &adapter
->recvpriv
;
1323 precvpriv
->rx_drop
++;
1327 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("validate_recv_data_frame fail! type= 0x%x\n", type
));
1337 /* remove the wlanhdr and add the eth_hdr */
1339 static int wlanhdr_to_ethhdr(struct recv_frame
*precvframe
)
1346 struct ieee80211_snap_hdr
*psnap
;
1348 struct adapter
*adapter
= precvframe
->adapter
;
1349 struct mlme_priv
*pmlmepriv
= &adapter
->mlmepriv
;
1350 u8
*ptr
= precvframe
->rx_data
;
1351 struct rx_pkt_attrib
*pattrib
= &precvframe
->attrib
;
1353 if (pattrib
->encrypt
)
1354 recvframe_pull_tail(precvframe
, pattrib
->icv_len
);
1356 psnap
= (struct ieee80211_snap_hdr
*)(ptr
+pattrib
->hdrlen
+ pattrib
->iv_len
);
1357 psnap_type
= ptr
+pattrib
->hdrlen
+ pattrib
->iv_len
+SNAP_SIZE
;
1358 /* convert hdr + possible LLC headers into Ethernet header */
1359 if ((!memcmp(psnap
, rtw_rfc1042_header
, SNAP_SIZE
) &&
1360 (!memcmp(psnap_type
, SNAP_ETH_TYPE_IPX
, 2) == false) &&
1361 (!memcmp(psnap_type
, SNAP_ETH_TYPE_APPLETALK_AARP
, 2) == false)) ||
1362 !memcmp(psnap
, rtw_bridge_tunnel_header
, SNAP_SIZE
)) {
1363 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1366 /* Leave Ethernet header part of hdr and full payload */
1370 rmv_len
= pattrib
->hdrlen
+ pattrib
->iv_len
+ (bsnaphdr
? SNAP_SIZE
: 0);
1371 len
= precvframe
->len
- rmv_len
;
1373 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
,
1374 ("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x===\n\n", pattrib
->hdrlen
, pattrib
->iv_len
));
1376 memcpy(&be_tmp
, ptr
+rmv_len
, 2);
1377 eth_type
= ntohs(be_tmp
); /* pattrib->ether_type */
1378 pattrib
->eth_type
= eth_type
;
1380 if ((check_fwstate(pmlmepriv
, WIFI_MP_STATE
))) {
1386 /* append rx status for mp test packets */
1387 ptr
= recvframe_pull(precvframe
, (rmv_len
-sizeof(struct ethhdr
)+2)-24);
1388 memcpy(ptr
, get_rxmem(precvframe
), 24);
1391 ptr
= recvframe_pull(precvframe
, (rmv_len
-sizeof(struct ethhdr
) + (bsnaphdr
? 2 : 0)));
1394 memcpy(ptr
, pattrib
->dst
, ETH_ALEN
);
1395 memcpy(ptr
+ETH_ALEN
, pattrib
->src
, ETH_ALEN
);
1398 be_tmp
= htons(len
);
1399 memcpy(ptr
+12, &be_tmp
, 2);
1405 /* perform defrag */
1406 static struct recv_frame
*recvframe_defrag(struct adapter
*adapter
,
1407 struct __queue
*defrag_q
)
1409 struct list_head
*plist
, *phead
;
1412 struct recv_frame
*pfhdr
, *pnfhdr
;
1413 struct recv_frame
*prframe
, *pnextrframe
;
1414 struct __queue
*pfree_recv_queue
;
1417 pfree_recv_queue
= &adapter
->recvpriv
.free_recv_queue
;
1419 phead
= get_list_head(defrag_q
);
1420 plist
= phead
->next
;
1421 pfhdr
= container_of(plist
, struct recv_frame
, list
);
1422 prframe
= (struct recv_frame
*)pfhdr
;
1423 list_del_init(&(prframe
->list
));
1425 if (curfragnum
!= pfhdr
->attrib
.frag_num
) {
1426 /* the first fragment number must be 0 */
1427 /* free the whole queue */
1428 rtw_free_recvframe(prframe
, pfree_recv_queue
);
1429 rtw_free_recvframe_queue(defrag_q
, pfree_recv_queue
);
1436 plist
= get_list_head(defrag_q
);
1438 plist
= plist
->next
;
1440 while (phead
!= plist
) {
1441 pnfhdr
= container_of(plist
, struct recv_frame
, list
);
1442 pnextrframe
= (struct recv_frame
*)pnfhdr
;
1444 /* check the fragment sequence (2nd ~n fragment frame) */
1446 if (curfragnum
!= pnfhdr
->attrib
.frag_num
) {
1447 /* the fragment number must be increasing (after decache) */
1448 /* release the defrag_q & prframe */
1449 rtw_free_recvframe(prframe
, pfree_recv_queue
);
1450 rtw_free_recvframe_queue(defrag_q
, pfree_recv_queue
);
1456 /* copy the 2nd~n fragment frame's payload to the first fragment */
1457 /* get the 2nd~last fragment frame's payload */
1459 wlanhdr_offset
= pnfhdr
->attrib
.hdrlen
+ pnfhdr
->attrib
.iv_len
;
1461 recvframe_pull(pnextrframe
, wlanhdr_offset
);
1463 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1464 recvframe_pull_tail(prframe
, pfhdr
->attrib
.icv_len
);
1467 memcpy(pfhdr
->rx_tail
, pnfhdr
->rx_data
, pnfhdr
->len
);
1469 recvframe_put(prframe
, pnfhdr
->len
);
1471 pfhdr
->attrib
.icv_len
= pnfhdr
->attrib
.icv_len
;
1472 plist
= plist
->next
;
1475 /* free the defrag_q queue and return the prframe */
1476 rtw_free_recvframe_queue(defrag_q
, pfree_recv_queue
);
1478 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("Performance defrag!!!!!\n"));
1483 /* check if need to defrag, if needed queue the frame to defrag_q */
1484 struct recv_frame
*recvframe_chk_defrag(struct adapter
*padapter
,
1485 struct recv_frame
*precv_frame
)
1490 struct recv_frame
*pfhdr
;
1491 struct sta_info
*psta
;
1492 struct sta_priv
*pstapriv
;
1493 struct list_head
*phead
;
1494 struct recv_frame
*prtnframe
= NULL
;
1495 struct __queue
*pfree_recv_queue
, *pdefrag_q
;
1497 pstapriv
= &padapter
->stapriv
;
1499 pfhdr
= precv_frame
;
1501 pfree_recv_queue
= &padapter
->recvpriv
.free_recv_queue
;
1503 /* need to define struct of wlan header frame ctrl */
1504 ismfrag
= pfhdr
->attrib
.mfrag
;
1505 fragnum
= pfhdr
->attrib
.frag_num
;
1507 psta_addr
= pfhdr
->attrib
.ta
;
1508 psta
= rtw_get_stainfo(pstapriv
, psta_addr
);
1510 u8 type
= GetFrameType(pfhdr
->rx_data
);
1511 if (type
!= WIFI_DATA_TYPE
) {
1512 psta
= rtw_get_bcmc_stainfo(padapter
);
1513 pdefrag_q
= &psta
->sta_recvpriv
.defrag_q
;
1518 pdefrag_q
= &psta
->sta_recvpriv
.defrag_q
;
1521 if ((ismfrag
== 0) && (fragnum
== 0))
1522 prtnframe
= precv_frame
;/* isn't a fragment frame */
1525 /* 0~(n-1) fragment frame */
1526 /* enqueue to defraf_g */
1527 if (pdefrag_q
!= NULL
) {
1529 /* the first fragment */
1530 if (!list_empty(&pdefrag_q
->queue
)) {
1531 /* free current defrag_q */
1532 rtw_free_recvframe_queue(pdefrag_q
, pfree_recv_queue
);
1536 /* Then enqueue the 0~(n-1) fragment into the defrag_q */
1538 phead
= get_list_head(pdefrag_q
);
1539 list_add_tail(&pfhdr
->list
, phead
);
1541 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("Enqueuq: ismfrag=%d, fragnum=%d\n", ismfrag
, fragnum
));
1545 /* can't find this ta's defrag_queue, so free this recv_frame */
1546 rtw_free_recvframe(precv_frame
, pfree_recv_queue
);
1548 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag
, fragnum
));
1552 if ((ismfrag
== 0) && (fragnum
!= 0)) {
1553 /* the last fragment frame */
1554 /* enqueue the last fragment */
1555 if (pdefrag_q
!= NULL
) {
1556 phead
= get_list_head(pdefrag_q
);
1557 list_add_tail(&pfhdr
->list
, phead
);
1559 /* call recvframe_defrag to defrag */
1560 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("defrag: ismfrag=%d, fragnum=%d\n", ismfrag
, fragnum
));
1561 precv_frame
= recvframe_defrag(padapter
, pdefrag_q
);
1562 prtnframe
= precv_frame
;
1564 /* can't find this ta's defrag_queue, so free this recv_frame */
1565 rtw_free_recvframe(precv_frame
, pfree_recv_queue
);
1567 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("Free because pdefrag_q==NULL: ismfrag=%d, fragnum=%d\n", ismfrag
, fragnum
));
1571 if ((prtnframe
!= NULL
) && (prtnframe
->attrib
.privacy
)) {
1572 /* after defrag we must check tkip mic code */
1573 if (recvframe_chkmic(padapter
, prtnframe
) == _FAIL
) {
1574 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("recvframe_chkmic(padapter, prtnframe)==_FAIL\n"));
1575 rtw_free_recvframe(prtnframe
, pfree_recv_queue
);
1583 static int amsdu_to_msdu(struct adapter
*padapter
, struct recv_frame
*prframe
)
1585 int a_len
, padding_len
;
1586 u16 eth_type
, nSubframe_Length
;
1588 unsigned char *pdata
;
1589 struct rx_pkt_attrib
*pattrib
;
1590 unsigned char *data_ptr
;
1591 struct sk_buff
*sub_skb
, *subframes
[MAX_SUBFRAME_COUNT
];
1592 struct recv_priv
*precvpriv
= &padapter
->recvpriv
;
1593 struct __queue
*pfree_recv_queue
= &(precvpriv
->free_recv_queue
);
1596 pattrib
= &prframe
->attrib
;
1598 recvframe_pull(prframe
, prframe
->attrib
.hdrlen
);
1600 if (prframe
->attrib
.iv_len
> 0)
1601 recvframe_pull(prframe
, prframe
->attrib
.iv_len
);
1603 a_len
= prframe
->len
;
1605 pdata
= prframe
->rx_data
;
1607 while (a_len
> ETH_HLEN
) {
1608 /* Offset 12 denote 2 mac address */
1609 nSubframe_Length
= get_unaligned_be16(pdata
+ 12);
1611 if (a_len
< (ETHERNET_HEADER_SIZE
+ nSubframe_Length
)) {
1612 DBG_88E("nRemain_Length is %d and nSubframe_Length is : %d\n", a_len
, nSubframe_Length
);
1616 /* move the data point to data content */
1620 /* Allocate new skb for releasing to upper layer */
1621 sub_skb
= dev_alloc_skb(nSubframe_Length
+ 12);
1623 skb_reserve(sub_skb
, 12);
1624 data_ptr
= (u8
*)skb_put(sub_skb
, nSubframe_Length
);
1625 memcpy(data_ptr
, pdata
, nSubframe_Length
);
1627 sub_skb
= skb_clone(prframe
->pkt
, GFP_ATOMIC
);
1629 sub_skb
->data
= pdata
;
1630 sub_skb
->len
= nSubframe_Length
;
1631 skb_set_tail_pointer(sub_skb
, nSubframe_Length
);
1633 DBG_88E("skb_clone() Fail!!! , nr_subframes=%d\n", nr_subframes
);
1638 subframes
[nr_subframes
++] = sub_skb
;
1640 if (nr_subframes
>= MAX_SUBFRAME_COUNT
) {
1641 DBG_88E("ParseSubframe(): Too many Subframes! Packets dropped!\n");
1645 pdata
+= nSubframe_Length
;
1646 a_len
-= nSubframe_Length
;
1648 padding_len
= 4 - ((nSubframe_Length
+ ETH_HLEN
) & (4-1));
1649 if (padding_len
== 4) {
1653 if (a_len
< padding_len
) {
1656 pdata
+= padding_len
;
1657 a_len
-= padding_len
;
1661 for (i
= 0; i
< nr_subframes
; i
++) {
1662 sub_skb
= subframes
[i
];
1663 /* convert hdr + possible LLC headers into Ethernet header */
1664 eth_type
= get_unaligned_be16(&sub_skb
->data
[6]);
1665 if (sub_skb
->len
>= 8 &&
1666 ((!memcmp(sub_skb
->data
, rtw_rfc1042_header
, SNAP_SIZE
) &&
1667 eth_type
!= ETH_P_AARP
&& eth_type
!= ETH_P_IPX
) ||
1668 !memcmp(sub_skb
->data
, rtw_bridge_tunnel_header
, SNAP_SIZE
))) {
1669 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1670 skb_pull(sub_skb
, SNAP_SIZE
);
1671 memcpy(skb_push(sub_skb
, ETH_ALEN
), pattrib
->src
, ETH_ALEN
);
1672 memcpy(skb_push(sub_skb
, ETH_ALEN
), pattrib
->dst
, ETH_ALEN
);
1675 /* Leave Ethernet header part of hdr and full payload */
1676 len
= htons(sub_skb
->len
);
1677 memcpy(skb_push(sub_skb
, 2), &len
, 2);
1678 memcpy(skb_push(sub_skb
, ETH_ALEN
), pattrib
->src
, ETH_ALEN
);
1679 memcpy(skb_push(sub_skb
, ETH_ALEN
), pattrib
->dst
, ETH_ALEN
);
1682 /* Indicate the packets to upper layer */
1683 /* Insert NAT2.5 RX here! */
1684 sub_skb
->protocol
= eth_type_trans(sub_skb
, padapter
->pnetdev
);
1685 sub_skb
->dev
= padapter
->pnetdev
;
1687 sub_skb
->ip_summed
= CHECKSUM_NONE
;
1695 rtw_free_recvframe(prframe
, pfree_recv_queue
);/* free this recv_frame */
1700 static int check_indicate_seq(struct recv_reorder_ctrl
*preorder_ctrl
, u16 seq_num
)
1702 u8 wsize
= preorder_ctrl
->wsize_b
;
1703 u16 wend
= (preorder_ctrl
->indicate_seq
+ wsize
- 1) & 0xFFF;/* 4096; */
1705 /* Rx Reorder initialize condition. */
1706 if (preorder_ctrl
->indicate_seq
== 0xFFFF)
1707 preorder_ctrl
->indicate_seq
= seq_num
;
1709 /* Drop out the packet which SeqNum is smaller than WinStart */
1710 if (SN_LESS(seq_num
, preorder_ctrl
->indicate_seq
))
1714 /* Sliding window manipulation. Conditions includes: */
1715 /* 1. Incoming SeqNum is equal to WinStart =>Window shift 1 */
1716 /* 2. Incoming SeqNum is larger than the WinEnd => Window shift N */
1718 if (SN_EQUAL(seq_num
, preorder_ctrl
->indicate_seq
)) {
1719 preorder_ctrl
->indicate_seq
= (preorder_ctrl
->indicate_seq
+ 1) & 0xFFF;
1720 } else if (SN_LESS(wend
, seq_num
)) {
1721 if (seq_num
>= (wsize
- 1))
1722 preorder_ctrl
->indicate_seq
= seq_num
+ 1 - wsize
;
1724 preorder_ctrl
->indicate_seq
= 0xFFF - (wsize
- (seq_num
+ 1)) + 1;
1730 static int enqueue_reorder_recvframe(struct recv_reorder_ctrl
*preorder_ctrl
,
1731 struct recv_frame
*prframe
)
1733 struct rx_pkt_attrib
*pattrib
= &prframe
->attrib
;
1734 struct __queue
*ppending_recvframe_queue
= &preorder_ctrl
->pending_recvframe_queue
;
1735 struct list_head
*phead
, *plist
;
1736 struct recv_frame
*hdr
;
1737 struct rx_pkt_attrib
*pnextattrib
;
1739 phead
= get_list_head(ppending_recvframe_queue
);
1740 plist
= phead
->next
;
1742 while (phead
!= plist
) {
1743 hdr
= container_of(plist
, struct recv_frame
, list
);
1744 pnextattrib
= &hdr
->attrib
;
1746 if (SN_LESS(pnextattrib
->seq_num
, pattrib
->seq_num
))
1747 plist
= plist
->next
;
1748 else if (SN_EQUAL(pnextattrib
->seq_num
, pattrib
->seq_num
))
1754 list_del_init(&(prframe
->list
));
1756 list_add_tail(&(prframe
->list
), plist
);
1760 static int recv_indicatepkts_in_order(struct adapter
*padapter
, struct recv_reorder_ctrl
*preorder_ctrl
, int bforced
)
1762 struct list_head
*phead
, *plist
;
1763 struct recv_frame
*prframe
;
1764 struct recv_frame
*prhdr
;
1765 struct rx_pkt_attrib
*pattrib
;
1766 int bPktInBuf
= false;
1767 struct recv_priv
*precvpriv
= &padapter
->recvpriv
;
1768 struct __queue
*ppending_recvframe_queue
= &preorder_ctrl
->pending_recvframe_queue
;
1770 phead
= get_list_head(ppending_recvframe_queue
);
1771 plist
= phead
->next
;
1773 /* Handling some condition for forced indicate case. */
1775 if (list_empty(phead
))
1778 prhdr
= container_of(plist
, struct recv_frame
, list
);
1779 pattrib
= &prhdr
->attrib
;
1780 preorder_ctrl
->indicate_seq
= pattrib
->seq_num
;
1783 /* Prepare indication list and indication. */
1784 /* Check if there is any packet need indicate. */
1785 while (!list_empty(phead
)) {
1786 prhdr
= container_of(plist
, struct recv_frame
, list
);
1787 prframe
= (struct recv_frame
*)prhdr
;
1788 pattrib
= &prframe
->attrib
;
1790 if (!SN_LESS(preorder_ctrl
->indicate_seq
, pattrib
->seq_num
)) {
1791 RT_TRACE(_module_rtl871x_recv_c_
, _drv_notice_
,
1792 ("recv_indicatepkts_in_order: indicate=%d seq=%d amsdu=%d\n",
1793 preorder_ctrl
->indicate_seq
, pattrib
->seq_num
, pattrib
->amsdu
));
1794 plist
= plist
->next
;
1795 list_del_init(&(prframe
->list
));
1797 if (SN_EQUAL(preorder_ctrl
->indicate_seq
, pattrib
->seq_num
))
1798 preorder_ctrl
->indicate_seq
= (preorder_ctrl
->indicate_seq
+ 1) & 0xFFF;
1800 /* Set this as a lock to make sure that only one thread is indicating packet. */
1802 /* indicate this recv_frame */
1803 if (!pattrib
->amsdu
) {
1804 if ((!padapter
->bDriverStopped
) &&
1805 (!padapter
->bSurpriseRemoved
))
1806 rtw_recv_indicatepkt(padapter
, prframe
);/* indicate this recv_frame */
1807 } else if (pattrib
->amsdu
== 1) {
1808 if (amsdu_to_msdu(padapter
, prframe
) != _SUCCESS
)
1809 rtw_free_recvframe(prframe
, &precvpriv
->free_recv_queue
);
1811 /* error condition; */
1814 /* Update local variables. */
1824 static int recv_indicatepkt_reorder(struct adapter
*padapter
,
1825 struct recv_frame
*prframe
)
1827 int retval
= _SUCCESS
;
1828 struct rx_pkt_attrib
*pattrib
= &prframe
->attrib
;
1829 struct recv_reorder_ctrl
*preorder_ctrl
= prframe
->preorder_ctrl
;
1830 struct __queue
*ppending_recvframe_queue
= &preorder_ctrl
->pending_recvframe_queue
;
1832 if (!pattrib
->amsdu
) {
1834 wlanhdr_to_ethhdr(prframe
);
1836 if ((pattrib
->qos
!= 1) || (pattrib
->eth_type
== 0x0806) ||
1837 (pattrib
->ack_policy
!= 0)) {
1838 if ((!padapter
->bDriverStopped
) &&
1839 (!padapter
->bSurpriseRemoved
)) {
1840 RT_TRACE(_module_rtl871x_recv_c_
, _drv_notice_
, ("@@@@ recv_indicatepkt_reorder -recv_func recv_indicatepkt\n"));
1842 rtw_recv_indicatepkt(padapter
, prframe
);
1849 if (!preorder_ctrl
->enable
) {
1850 /* indicate this recv_frame */
1851 preorder_ctrl
->indicate_seq
= pattrib
->seq_num
;
1852 rtw_recv_indicatepkt(padapter
, prframe
);
1854 preorder_ctrl
->indicate_seq
= (preorder_ctrl
->indicate_seq
+ 1)%4096;
1857 } else if (pattrib
->amsdu
== 1) { /* temp filter -> means didn't support A-MSDUs in a A-MPDU */
1858 if (!preorder_ctrl
->enable
) {
1859 preorder_ctrl
->indicate_seq
= pattrib
->seq_num
;
1860 retval
= amsdu_to_msdu(padapter
, prframe
);
1862 preorder_ctrl
->indicate_seq
= (preorder_ctrl
->indicate_seq
+ 1)%4096;
1867 spin_lock_bh(&ppending_recvframe_queue
->lock
);
1869 RT_TRACE(_module_rtl871x_recv_c_
, _drv_notice_
,
1870 ("recv_indicatepkt_reorder: indicate=%d seq=%d\n",
1871 preorder_ctrl
->indicate_seq
, pattrib
->seq_num
));
1873 /* s2. check if winstart_b(indicate_seq) needs to been updated */
1874 if (!check_indicate_seq(preorder_ctrl
, pattrib
->seq_num
)) {
1875 rtw_recv_indicatepkt(padapter
, prframe
);
1877 spin_unlock_bh(&ppending_recvframe_queue
->lock
);
1882 /* s3. Insert all packet into Reorder Queue to maintain its ordering. */
1883 if (!enqueue_reorder_recvframe(preorder_ctrl
, prframe
))
1887 /* Indication process. */
1888 /* After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets */
1889 /* with the SeqNum smaller than latest WinStart and buffer other packets. */
1891 /* For Rx Reorder condition: */
1892 /* 1. All packets with SeqNum smaller than WinStart => Indicate */
1893 /* 2. All packets with SeqNum larger than or equal to WinStart => Buffer it. */
1896 /* recv_indicatepkts_in_order(padapter, preorder_ctrl, true); */
1897 if (recv_indicatepkts_in_order(padapter
, preorder_ctrl
, false)) {
1898 mod_timer(&preorder_ctrl
->reordering_ctrl_timer
,
1899 jiffies
+ msecs_to_jiffies(REORDER_WAIT_TIME
));
1900 spin_unlock_bh(&ppending_recvframe_queue
->lock
);
1902 spin_unlock_bh(&ppending_recvframe_queue
->lock
);
1903 del_timer_sync(&preorder_ctrl
->reordering_ctrl_timer
);
1912 spin_unlock_bh(&ppending_recvframe_queue
->lock
);
1917 void rtw_reordering_ctrl_timeout_handler(unsigned long data
)
1919 struct recv_reorder_ctrl
*preorder_ctrl
= (struct recv_reorder_ctrl
*)data
;
1920 struct adapter
*padapter
= preorder_ctrl
->padapter
;
1921 struct __queue
*ppending_recvframe_queue
= &preorder_ctrl
->pending_recvframe_queue
;
1923 if (padapter
->bDriverStopped
|| padapter
->bSurpriseRemoved
)
1926 spin_lock_bh(&ppending_recvframe_queue
->lock
);
1928 if (recv_indicatepkts_in_order(padapter
, preorder_ctrl
, true) == true)
1929 mod_timer(&preorder_ctrl
->reordering_ctrl_timer
,
1930 jiffies
+ msecs_to_jiffies(REORDER_WAIT_TIME
));
1932 spin_unlock_bh(&ppending_recvframe_queue
->lock
);
1935 static int process_recv_indicatepkts(struct adapter
*padapter
,
1936 struct recv_frame
*prframe
)
1938 int retval
= _SUCCESS
;
1939 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
1940 struct ht_priv
*phtpriv
= &pmlmepriv
->htpriv
;
1942 if (phtpriv
->ht_option
) { /* B/G/N Mode */
1943 if (recv_indicatepkt_reorder(padapter
, prframe
) != _SUCCESS
) {
1944 /* including perform A-MPDU Rx Ordering Buffer Control */
1945 if ((!padapter
->bDriverStopped
) &&
1946 (!padapter
->bSurpriseRemoved
)) {
1951 } else { /* B/G mode */
1952 retval
= wlanhdr_to_ethhdr(prframe
);
1953 if (retval
!= _SUCCESS
) {
1954 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("wlanhdr_to_ethhdr: drop pkt\n"));
1958 if ((!padapter
->bDriverStopped
) &&
1959 (!padapter
->bSurpriseRemoved
)) {
1960 /* indicate this recv_frame */
1961 RT_TRACE(_module_rtl871x_recv_c_
, _drv_notice_
, ("@@@@ process_recv_indicatepkts- recv_func recv_indicatepkt\n"));
1962 rtw_recv_indicatepkt(padapter
, prframe
);
1964 RT_TRACE(_module_rtl871x_recv_c_
, _drv_notice_
, ("@@@@ process_recv_indicatepkts- recv_func free_indicatepkt\n"));
1966 RT_TRACE(_module_rtl871x_recv_c_
, _drv_notice_
, ("recv_func:bDriverStopped(%d) OR bSurpriseRemoved(%d)", padapter
->bDriverStopped
, padapter
->bSurpriseRemoved
));
1975 static int recv_func_prehandle(struct adapter
*padapter
,
1976 struct recv_frame
*rframe
)
1979 struct __queue
*pfree_recv_queue
= &padapter
->recvpriv
.free_recv_queue
;
1981 /* check the frame crtl field and decache */
1982 ret
= validate_recv_frame(padapter
, rframe
);
1983 if (ret
!= _SUCCESS
) {
1984 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("recv_func: validate_recv_frame fail! drop pkt\n"));
1985 rtw_free_recvframe(rframe
, pfree_recv_queue
);/* free this recv_frame */
1993 static int recv_func_posthandle(struct adapter
*padapter
,
1994 struct recv_frame
*prframe
)
1997 struct recv_frame
*orig_prframe
= prframe
;
1998 struct recv_priv
*precvpriv
= &padapter
->recvpriv
;
1999 struct __queue
*pfree_recv_queue
= &padapter
->recvpriv
.free_recv_queue
;
2002 rtw_led_control(padapter
, LED_CTL_RX
);
2004 prframe
= decryptor(padapter
, prframe
);
2005 if (prframe
== NULL
) {
2006 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("decryptor: drop pkt\n"));
2008 goto _recv_data_drop
;
2011 prframe
= recvframe_chk_defrag(padapter
, prframe
);
2012 if (prframe
== NULL
) {
2013 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("recvframe_chk_defrag: drop pkt\n"));
2014 goto _recv_data_drop
;
2017 prframe
= portctrl(padapter
, prframe
);
2018 if (prframe
== NULL
) {
2019 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("portctrl: drop pkt\n"));
2021 goto _recv_data_drop
;
2024 count_rx_stats(padapter
, prframe
, NULL
);
2026 ret
= process_recv_indicatepkts(padapter
, prframe
);
2027 if (ret
!= _SUCCESS
) {
2028 RT_TRACE(_module_rtl871x_recv_c_
, _drv_err_
, ("recv_func: process_recv_indicatepkts fail!\n"));
2029 rtw_free_recvframe(orig_prframe
, pfree_recv_queue
);/* free this recv_frame */
2030 goto _recv_data_drop
;
2035 precvpriv
->rx_drop
++;
2039 static int recv_func(struct adapter
*padapter
, struct recv_frame
*rframe
)
2042 struct rx_pkt_attrib
*prxattrib
= &rframe
->attrib
;
2043 struct security_priv
*psecuritypriv
= &padapter
->securitypriv
;
2044 struct mlme_priv
*mlmepriv
= &padapter
->mlmepriv
;
2046 /* check if need to handle uc_swdec_pending_queue*/
2047 if (check_fwstate(mlmepriv
, WIFI_STATION_STATE
) && psecuritypriv
->busetkipkey
) {
2048 struct recv_frame
*pending_frame
;
2050 while ((pending_frame
= rtw_alloc_recvframe(&padapter
->recvpriv
.uc_swdec_pending_queue
))) {
2051 if (recv_func_posthandle(padapter
, pending_frame
) == _SUCCESS
)
2052 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__
);
2056 ret
= recv_func_prehandle(padapter
, rframe
);
2058 if (ret
== _SUCCESS
) {
2059 /* check if need to enqueue into uc_swdec_pending_queue*/
2060 if (check_fwstate(mlmepriv
, WIFI_STATION_STATE
) &&
2061 !IS_MCAST(prxattrib
->ra
) && prxattrib
->encrypt
> 0 &&
2062 (prxattrib
->bdecrypted
== 0 || psecuritypriv
->sw_decrypt
) &&
2063 !is_wep_enc(psecuritypriv
->dot11PrivacyAlgrthm
) &&
2064 !psecuritypriv
->busetkipkey
) {
2065 rtw_enqueue_recvframe(rframe
, &padapter
->recvpriv
.uc_swdec_pending_queue
);
2066 DBG_88E("%s: no key, enqueue uc_swdec_pending_queue\n", __func__
);
2070 ret
= recv_func_posthandle(padapter
, rframe
);
2077 s32
rtw_recv_entry(struct recv_frame
*precvframe
)
2079 struct adapter
*padapter
;
2080 struct recv_priv
*precvpriv
;
2083 padapter
= precvframe
->adapter
;
2085 precvpriv
= &padapter
->recvpriv
;
2087 ret
= recv_func(padapter
, precvframe
);
2089 RT_TRACE(_module_rtl871x_recv_c_
, _drv_info_
, ("rtw_recv_entry: recv_func return fail!!!\n"));
2090 goto _recv_entry_drop
;
2093 precvpriv
->rx_pkts
++;
2101 void rtw_signal_stat_timer_hdl(unsigned long data
)
2103 struct adapter
*adapter
= (struct adapter
*)data
;
2104 struct recv_priv
*recvpriv
= &adapter
->recvpriv
;
2107 u8 avg_signal_strength
= 0;
2108 u8 avg_signal_qual
= 0;
2109 u8 _alpha
= 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2111 if (adapter
->recvpriv
.is_signal_dbg
) {
2112 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */
2113 adapter
->recvpriv
.signal_strength
= adapter
->recvpriv
.signal_strength_dbg
;
2114 adapter
->recvpriv
.rssi
= (s8
)translate_percentage_to_dbm((u8
)adapter
->recvpriv
.signal_strength_dbg
);
2116 if (recvpriv
->signal_strength_data
.update_req
== 0) {/* update_req is clear, means we got rx */
2117 avg_signal_strength
= recvpriv
->signal_strength_data
.avg_val
;
2118 /* after avg_vals are acquired, we can re-stat the signal values */
2119 recvpriv
->signal_strength_data
.update_req
= 1;
2122 if (recvpriv
->signal_qual_data
.update_req
== 0) {/* update_req is clear, means we got rx */
2123 avg_signal_qual
= recvpriv
->signal_qual_data
.avg_val
;
2124 /* after avg_vals are acquired, we can re-stat the signal values */
2125 recvpriv
->signal_qual_data
.update_req
= 1;
2128 /* update value of signal_strength, rssi, signal_qual */
2129 if (check_fwstate(&adapter
->mlmepriv
, _FW_UNDER_SURVEY
) == false) {
2130 tmp_s
= avg_signal_strength
+(_alpha
-1)*recvpriv
->signal_strength
;
2132 tmp_s
= tmp_s
/_alpha
+ 1;
2134 tmp_s
= tmp_s
/_alpha
;
2138 tmp_q
= avg_signal_qual
+(_alpha
-1)*recvpriv
->signal_qual
;
2140 tmp_q
= tmp_q
/_alpha
+ 1;
2142 tmp_q
= tmp_q
/_alpha
;
2146 recvpriv
->signal_strength
= tmp_s
;
2147 recvpriv
->rssi
= (s8
)translate_percentage_to_dbm(tmp_s
);
2148 recvpriv
->signal_qual
= tmp_q
;
2151 rtw_set_signal_stat_timer(recvpriv
);