1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3
4 #define _RECV_OSDEP_C_
5
6 #include "../include/osdep_service.h"
7 #include "../include/drv_types.h"
8
9 #include "../include/wifi.h"
10 #include "../include/recv_osdep.h"
11
12 #include "../include/osdep_intf.h"
13 #include "../include/usb_ops.h"
14
15 /* alloc os related resource in struct recv_buf */
rtw_os_recvbuf_resource_alloc(struct adapter * padapter,struct recv_buf * precvbuf)16 int rtw_os_recvbuf_resource_alloc(struct adapter *padapter,
17 struct recv_buf *precvbuf)
18 {
19 int res = _SUCCESS;
20
21 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
22 if (!precvbuf->purb)
23 res = _FAIL;
24 precvbuf->pskb = NULL;
25 precvbuf->reuse = false;
26 return res;
27 }
28
29 /* free os related resource in struct recv_buf */
rtw_os_recvbuf_resource_free(struct adapter * padapter,struct recv_buf * precvbuf)30 int rtw_os_recvbuf_resource_free(struct adapter *padapter,
31 struct recv_buf *precvbuf)
32 {
33 usb_free_urb(precvbuf->purb);
34 return _SUCCESS;
35 }
36
rtw_handle_tkip_mic_err(struct adapter * padapter,u8 bgroup)37 void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup)
38 {
39 union iwreq_data wrqu;
40 struct iw_michaelmicfailure ev;
41 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
42 struct security_priv *psecuritypriv = &padapter->securitypriv;
43 u32 cur_time = 0;
44
45 if (psecuritypriv->last_mic_err_time == 0) {
46 psecuritypriv->last_mic_err_time = jiffies;
47 } else {
48 cur_time = jiffies;
49
50 if (cur_time - psecuritypriv->last_mic_err_time < 60 * HZ) {
51 psecuritypriv->btkip_countermeasure = true;
52 psecuritypriv->last_mic_err_time = 0;
53 psecuritypriv->btkip_countermeasure_time = cur_time;
54 } else {
55 psecuritypriv->last_mic_err_time = jiffies;
56 }
57 }
58
59 memset(&ev, 0x00, sizeof(ev));
60 if (bgroup)
61 ev.flags |= IW_MICFAILURE_GROUP;
62 else
63 ev.flags |= IW_MICFAILURE_PAIRWISE;
64
65 ev.src_addr.sa_family = ARPHRD_ETHER;
66 memcpy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
67 memset(&wrqu, 0x00, sizeof(wrqu));
68 wrqu.data.length = sizeof(ev);
69 wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE,
70 &wrqu, (char *)&ev);
71 }
72
rtw_recv_indicatepkt(struct adapter * padapter,struct recv_frame * precv_frame)73 int rtw_recv_indicatepkt(struct adapter *padapter,
74 struct recv_frame *precv_frame)
75 {
76 struct recv_priv *precvpriv;
77 struct __queue *pfree_recv_queue;
78 struct sk_buff *skb;
79 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
80
81 precvpriv = &padapter->recvpriv;
82 pfree_recv_queue = &precvpriv->free_recv_queue;
83
84 skb = precv_frame->pkt;
85 if (!skb)
86 goto _recv_indicatepkt_drop;
87
88 skb->data = precv_frame->rx_data;
89
90 skb_set_tail_pointer(skb, precv_frame->len);
91
92 skb->len = precv_frame->len;
93
94 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
95 struct sk_buff *pskb2 = NULL;
96 struct sta_info *psta = NULL;
97 struct sta_priv *pstapriv = &padapter->stapriv;
98 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
99 bool bmcast = is_multicast_ether_addr(pattrib->dst);
100
101 if (memcmp(pattrib->dst, myid(&padapter->eeprompriv),
102 ETH_ALEN)) {
103 if (bmcast) {
104 psta = rtw_get_bcmc_stainfo(padapter);
105 pskb2 = skb_clone(skb, GFP_ATOMIC);
106 } else {
107 psta = rtw_get_stainfo(pstapriv, pattrib->dst);
108 }
109
110 if (psta) {
111 struct net_device *pnetdev;
112
113 pnetdev = (struct net_device *)padapter->pnetdev;
114 skb->dev = pnetdev;
115 skb_set_queue_mapping(skb, rtw_recv_select_queue(skb));
116
117 rtw_xmit_entry(skb, pnetdev);
118
119 if (bmcast)
120 skb = pskb2;
121 else
122 goto _recv_indicatepkt_end;
123 }
124 }
125 }
126
127 rcu_read_lock();
128 rcu_dereference(padapter->pnetdev->rx_handler_data);
129 rcu_read_unlock();
130
131 skb->ip_summed = CHECKSUM_NONE;
132 skb->dev = padapter->pnetdev;
133 skb->protocol = eth_type_trans(skb, padapter->pnetdev);
134
135 netif_rx(skb);
136
137 _recv_indicatepkt_end:
138
139 /* pointers to NULL before rtw_free_recvframe() */
140 precv_frame->pkt = NULL;
141
142 rtw_free_recvframe(precv_frame, pfree_recv_queue);
143
144 return _SUCCESS;
145
146 _recv_indicatepkt_drop:
147
148 /* enqueue back to free_recv_queue */
149 rtw_free_recvframe(precv_frame, pfree_recv_queue);
150
151 return _FAIL;
152 }
153
_rtw_reordering_ctrl_timeout_handler(struct timer_list * t)154 static void _rtw_reordering_ctrl_timeout_handler(struct timer_list *t)
155 {
156 struct recv_reorder_ctrl *preorder_ctrl;
157
158 preorder_ctrl = from_timer(preorder_ctrl, t, reordering_ctrl_timer);
159 rtw_reordering_ctrl_timeout_handler(preorder_ctrl);
160 }
161
rtw_init_recv_timer(struct recv_reorder_ctrl * preorder_ctrl)162 void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
163 {
164 timer_setup(&preorder_ctrl->reordering_ctrl_timer, _rtw_reordering_ctrl_timeout_handler, 0);
165 }
166