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