GNU Linux-libre 4.9.337-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_frame */
25 void rtw_os_recv_resource_alloc(struct recv_frame *precvframe)
26 {
27         precvframe->pkt = NULL;
28 }
29
30 /* alloc os related resource in struct recv_buf */
31 int rtw_os_recvbuf_resource_alloc(struct adapter *padapter,
32                                   struct recv_buf *precvbuf)
33 {
34         precvbuf->pskb = NULL;
35         precvbuf->reuse = false;
36         precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
37         if (!precvbuf->purb)
38                 return _FAIL;
39         return _SUCCESS;
40 }
41
42 void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup)
43 {
44         union iwreq_data wrqu;
45         struct iw_michaelmicfailure    ev;
46         struct mlme_priv *pmlmepriv  = &padapter->mlmepriv;
47         struct security_priv    *psecuritypriv = &padapter->securitypriv;
48         u32 cur_time = 0;
49
50         if (psecuritypriv->last_mic_err_time == 0) {
51                 psecuritypriv->last_mic_err_time = jiffies;
52         } else {
53                 cur_time = jiffies;
54
55                 if (cur_time - psecuritypriv->last_mic_err_time < 60*HZ) {
56                         psecuritypriv->btkip_countermeasure = true;
57                         psecuritypriv->last_mic_err_time = 0;
58                         psecuritypriv->btkip_countermeasure_time = cur_time;
59                 } else {
60                         psecuritypriv->last_mic_err_time = jiffies;
61                 }
62         }
63
64         memset(&ev, 0x00, sizeof(ev));
65         if (bgroup)
66                 ev.flags |= IW_MICFAILURE_GROUP;
67         else
68                 ev.flags |= IW_MICFAILURE_PAIRWISE;
69
70         ev.src_addr.sa_family = ARPHRD_ETHER;
71         memcpy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
72         memset(&wrqu, 0x00, sizeof(wrqu));
73         wrqu.data.length = sizeof(ev);
74         wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE,
75                             &wrqu, (char *)&ev);
76 }
77
78 int rtw_recv_indicatepkt(struct adapter *padapter,
79                          struct recv_frame *precv_frame)
80 {
81         struct recv_priv *precvpriv;
82         struct __queue *pfree_recv_queue;
83         struct sk_buff *skb;
84         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
85
86
87         precvpriv = &(padapter->recvpriv);
88         pfree_recv_queue = &(precvpriv->free_recv_queue);
89
90         skb = precv_frame->pkt;
91         if (!skb) {
92                 RT_TRACE(_module_recv_osdep_c_, _drv_err_,
93                          ("rtw_recv_indicatepkt():skb == NULL something wrong!!!!\n"));
94                 goto _recv_indicatepkt_drop;
95         }
96
97         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
98                  ("rtw_recv_indicatepkt():skb != NULL !!!\n"));
99         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
100                  ("rtw_recv_indicatepkt():precv_frame->rx_head =%p  precv_frame->hdr.rx_data =%p\n",
101                  precv_frame->rx_head, precv_frame->rx_data));
102         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
103                  ("precv_frame->hdr.rx_tail =%p precv_frame->rx_end =%p precv_frame->hdr.len =%d\n",
104                  precv_frame->rx_tail, precv_frame->rx_end,
105                  precv_frame->len));
106
107         skb->data = precv_frame->rx_data;
108
109         skb_set_tail_pointer(skb, precv_frame->len);
110
111         skb->len = precv_frame->len;
112
113         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
114                  ("skb->head =%p skb->data =%p skb->tail =%p skb->end =%p skb->len =%d\n",
115                  skb->head, skb->data, skb_tail_pointer(skb),
116                  skb_end_pointer(skb), skb->len));
117
118         if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
119                 struct sk_buff *pskb2 = NULL;
120                 struct sta_info *psta = NULL;
121                 struct sta_priv *pstapriv = &padapter->stapriv;
122                 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
123                 int bmcast = IS_MCAST(pattrib->dst);
124
125                 if (memcmp(pattrib->dst, myid(&padapter->eeprompriv),
126                            ETH_ALEN)) {
127                         if (bmcast) {
128                                 psta = rtw_get_bcmc_stainfo(padapter);
129                                 pskb2 = skb_clone(skb, GFP_ATOMIC);
130                         } else {
131                                 psta = rtw_get_stainfo(pstapriv, pattrib->dst);
132                         }
133
134                         if (psta) {
135                                 struct net_device *pnetdev;
136
137                                 pnetdev = (struct net_device *)padapter->pnetdev;
138                                 skb->dev = pnetdev;
139                                 skb_set_queue_mapping(skb, rtw_recv_select_queue(skb));
140
141                                 rtw_xmit_entry(skb, pnetdev);
142
143                                 if (bmcast)
144                                         skb = pskb2;
145                                 else
146                                         goto _recv_indicatepkt_end;
147                         }
148                 }
149         }
150
151         rcu_read_lock();
152         rcu_dereference(padapter->pnetdev->rx_handler_data);
153         rcu_read_unlock();
154
155         skb->ip_summed = CHECKSUM_NONE;
156         skb->dev = padapter->pnetdev;
157         skb->protocol = eth_type_trans(skb, padapter->pnetdev);
158
159         netif_rx(skb);
160
161 _recv_indicatepkt_end:
162
163         /*  pointers to NULL before rtw_free_recvframe() */
164         precv_frame->pkt = NULL;
165
166         rtw_free_recvframe(precv_frame, pfree_recv_queue);
167
168         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
169                  ("\n rtw_recv_indicatepkt :after netif_rx!!!!\n"));
170
171
172         return _SUCCESS;
173
174 _recv_indicatepkt_drop:
175
176          /* enqueue back to free_recv_queue */
177         rtw_free_recvframe(precv_frame, pfree_recv_queue);
178
179          return _FAIL;
180 }
181
182 void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
183 {
184
185         setup_timer(&preorder_ctrl->reordering_ctrl_timer,
186                     rtw_reordering_ctrl_timeout_handler,
187                     (unsigned long)preorder_ctrl);
188 }