1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  * recv_linux.c
4  *
5  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
6  * Linux device driver for RTL8192SU
7  *
8  * Modifications for inclusion into the Linux staging tree are
9  * Copyright(c) 2010 Larry Finger. All rights reserved.
10  *
11  * Contact information:
12  * WLAN FAE <wlanfae@realtek.com>.
13  * Larry Finger <Larry.Finger@lwfinger.net>
14  *
15  ******************************************************************************/
16 
17 #define _RECV_OSDEP_C_
18 
19 #include <linux/usb.h>
20 
21 #include "osdep_service.h"
22 #include "drv_types.h"
23 #include "wifi.h"
24 #include "recv_osdep.h"
25 #include "osdep_intf.h"
26 #include "ethernet.h"
27 #include <linux/if_arp.h>
28 #include "usb_ops.h"
29 
30 /*init os related resource in struct recv_priv*/
31 /*alloc os related resource in union recv_frame*/
r8712_os_recv_resource_alloc(struct _adapter * padapter,union recv_frame * precvframe)32 void r8712_os_recv_resource_alloc(struct _adapter *padapter,
33 				  union recv_frame *precvframe)
34 {
35 	precvframe->u.hdr.pkt_newalloc = NULL;
36 	precvframe->u.hdr.pkt = NULL;
37 }
38 
39 /*alloc os related resource in struct recv_buf*/
r8712_os_recvbuf_resource_alloc(struct _adapter * padapter,struct recv_buf * precvbuf)40 int r8712_os_recvbuf_resource_alloc(struct _adapter *padapter,
41 				    struct recv_buf *precvbuf)
42 {
43 	int res = 0;
44 
45 	precvbuf->irp_pending = false;
46 	precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
47 	if (!precvbuf->purb)
48 		res = -ENOMEM;
49 	precvbuf->pskb = NULL;
50 	precvbuf->pallocated_buf = NULL;
51 	precvbuf->pbuf = NULL;
52 	precvbuf->pdata = NULL;
53 	precvbuf->phead = NULL;
54 	precvbuf->ptail = NULL;
55 	precvbuf->pend = NULL;
56 	precvbuf->transfer_len = 0;
57 	precvbuf->len = 0;
58 	return res;
59 }
60 
61 /*free os related resource in struct recv_buf*/
r8712_os_recvbuf_resource_free(struct _adapter * padapter,struct recv_buf * precvbuf)62 void r8712_os_recvbuf_resource_free(struct _adapter *padapter,
63 				    struct recv_buf *precvbuf)
64 {
65 	if (precvbuf->pskb)
66 		dev_kfree_skb_any(precvbuf->pskb);
67 	if (precvbuf->purb) {
68 		usb_kill_urb(precvbuf->purb);
69 		usb_free_urb(precvbuf->purb);
70 	}
71 }
72 
r8712_handle_tkip_mic_err(struct _adapter * adapter,u8 bgroup)73 void r8712_handle_tkip_mic_err(struct _adapter *adapter, u8 bgroup)
74 {
75 	union iwreq_data wrqu;
76 	struct iw_michaelmicfailure ev;
77 	struct mlme_priv *mlmepriv  = &adapter->mlmepriv;
78 
79 	memset(&ev, 0x00, sizeof(ev));
80 	if (bgroup)
81 		ev.flags |= IW_MICFAILURE_GROUP;
82 	else
83 		ev.flags |= IW_MICFAILURE_PAIRWISE;
84 	ev.src_addr.sa_family = ARPHRD_ETHER;
85 	ether_addr_copy(ev.src_addr.sa_data, &mlmepriv->assoc_bssid[0]);
86 	memset(&wrqu, 0x00, sizeof(wrqu));
87 	wrqu.data.length = sizeof(ev);
88 	wireless_send_event(adapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu,
89 			    (char *)&ev);
90 }
91 
r8712_recv_indicatepkt(struct _adapter * adapter,union recv_frame * recvframe)92 void r8712_recv_indicatepkt(struct _adapter *adapter,
93 			    union recv_frame *recvframe)
94 {
95 	struct recv_priv *recvpriv;
96 	struct  __queue	*free_recv_queue;
97 	_pkt *skb;
98 	struct rx_pkt_attrib *attrib = &recvframe->u.hdr.attrib;
99 
100 	recvpriv = &adapter->recvpriv;
101 	free_recv_queue = &recvpriv->free_recv_queue;
102 	skb = recvframe->u.hdr.pkt;
103 	if (!skb)
104 		goto _recv_indicatepkt_drop;
105 	skb->data = recvframe->u.hdr.rx_data;
106 	skb->len = recvframe->u.hdr.len;
107 	skb_set_tail_pointer(skb, skb->len);
108 	if ((attrib->tcpchk_valid == 1) && (attrib->tcp_chkrpt == 1))
109 		skb->ip_summed = CHECKSUM_UNNECESSARY;
110 	else
111 		skb->ip_summed = CHECKSUM_NONE;
112 	skb->dev = adapter->pnetdev;
113 	skb->protocol = eth_type_trans(skb, adapter->pnetdev);
114 	netif_rx(skb);
115 	recvframe->u.hdr.pkt = NULL; /* pointers to NULL before
116 				      * r8712_free_recvframe()
117 				      */
118 	r8712_free_recvframe(recvframe, free_recv_queue);
119 	return;
120 _recv_indicatepkt_drop:
121 	 /*enqueue back to free_recv_queue*/
122 	if (recvframe)
123 		r8712_free_recvframe(recvframe, free_recv_queue);
124 	recvpriv->rx_drop++;
125 }
126 
_r8712_reordering_ctrl_timeout_handler(struct timer_list * t)127 static void _r8712_reordering_ctrl_timeout_handler (struct timer_list *t)
128 {
129 	struct recv_reorder_ctrl *reorder_ctrl =
130 			 from_timer(reorder_ctrl, t, reordering_ctrl_timer);
131 
132 	r8712_reordering_ctrl_timeout_handler(reorder_ctrl);
133 }
134 
r8712_init_recv_timer(struct recv_reorder_ctrl * preorder_ctrl)135 void r8712_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
136 {
137 	timer_setup(&preorder_ctrl->reordering_ctrl_timer,
138 		    _r8712_reordering_ctrl_timeout_handler, 0);
139 }
140