Merge tag 'gfs2-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/steve...
[cascardo/linux.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  * 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
17  *
18  *
19  ******************************************************************************/
20 #define _RECV_OSDEP_C_
21
22 #include <osdep_service.h>
23 #include <drv_types.h>
24
25 #include <wifi.h>
26 #include <recv_osdep.h>
27
28 #include <osdep_intf.h>
29 #include <usb_ops.h>
30
31 /* init os related resource in struct recv_priv */
32 int rtw_os_recv_resource_init(struct recv_priv *precvpriv,
33                               struct adapter *padapter)
34 {
35         return _SUCCESS;
36 }
37
38 /* alloc os related resource in struct recv_frame */
39 int rtw_os_recv_resource_alloc(struct adapter *padapter,
40                                struct recv_frame *precvframe)
41 {
42         precvframe->pkt_newalloc = NULL;
43         precvframe->pkt = NULL;
44         return _SUCCESS;
45 }
46
47 /* free os related resource in struct recv_frame */
48 void rtw_os_recv_resource_free(struct recv_priv *precvpriv)
49 {
50 }
51
52 /* alloc os related resource in struct recv_buf */
53 int rtw_os_recvbuf_resource_alloc(struct adapter *padapter,
54                                   struct recv_buf *precvbuf)
55 {
56         int res = _SUCCESS;
57
58         precvbuf->irp_pending = false;
59         precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
60         if (precvbuf->purb == NULL)
61                 res = _FAIL;
62         precvbuf->pskb = NULL;
63         precvbuf->reuse = false;
64         precvbuf->pallocated_buf = NULL;
65         precvbuf->pbuf = NULL;
66         precvbuf->pdata = NULL;
67         precvbuf->phead = NULL;
68         precvbuf->ptail = NULL;
69         precvbuf->pend = NULL;
70         precvbuf->transfer_len = 0;
71         precvbuf->len = 0;
72         return res;
73 }
74
75 /* free os related resource in struct recv_buf */
76 int rtw_os_recvbuf_resource_free(struct adapter *padapter,
77                                  struct recv_buf *precvbuf)
78 {
79         usb_free_urb(precvbuf->purb);
80         return _SUCCESS;
81 }
82
83 void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup)
84 {
85         union iwreq_data wrqu;
86         struct iw_michaelmicfailure    ev;
87         struct mlme_priv *pmlmepriv  = &padapter->mlmepriv;
88         struct security_priv    *psecuritypriv = &padapter->securitypriv;
89         u32 cur_time = 0;
90
91         if (psecuritypriv->last_mic_err_time == 0) {
92                 psecuritypriv->last_mic_err_time = jiffies;
93         } else {
94                 cur_time = jiffies;
95
96                 if (cur_time - psecuritypriv->last_mic_err_time < 60*HZ) {
97                         psecuritypriv->btkip_countermeasure = true;
98                         psecuritypriv->last_mic_err_time = 0;
99                         psecuritypriv->btkip_countermeasure_time = cur_time;
100                 } else {
101                         psecuritypriv->last_mic_err_time = jiffies;
102                 }
103         }
104
105         _rtw_memset(&ev, 0x00, sizeof(ev));
106         if (bgroup)
107                 ev.flags |= IW_MICFAILURE_GROUP;
108         else
109                 ev.flags |= IW_MICFAILURE_PAIRWISE;
110
111         ev.src_addr.sa_family = ARPHRD_ETHER;
112         memcpy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
113         _rtw_memset(&wrqu, 0x00, sizeof(wrqu));
114         wrqu.data.length = sizeof(ev);
115         wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE,
116                             &wrqu, (char *)&ev);
117 }
118
119 void rtw_hostapd_mlme_rx(struct adapter *padapter,
120                          struct recv_frame *precv_frame)
121 {
122 }
123
124 int rtw_recv_indicatepkt(struct adapter *padapter,
125                          struct recv_frame *precv_frame)
126 {
127         struct recv_priv *precvpriv;
128         struct __queue *pfree_recv_queue;
129         struct sk_buff *skb;
130         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
131
132
133         precvpriv = &(padapter->recvpriv);
134         pfree_recv_queue = &(precvpriv->free_recv_queue);
135
136         skb = precv_frame->pkt;
137         if (skb == NULL) {
138                 RT_TRACE(_module_recv_osdep_c_, _drv_err_,
139                          ("rtw_recv_indicatepkt():skb == NULL something wrong!!!!\n"));
140                 goto _recv_indicatepkt_drop;
141         }
142
143         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
144                  ("rtw_recv_indicatepkt():skb != NULL !!!\n"));
145         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
146                  ("rtw_recv_indicatepkt():precv_frame->rx_head =%p  precv_frame->hdr.rx_data =%p\n",
147                  precv_frame->rx_head, precv_frame->rx_data));
148         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
149                  ("precv_frame->hdr.rx_tail =%p precv_frame->rx_end =%p precv_frame->hdr.len =%d\n",
150                  precv_frame->rx_tail, precv_frame->rx_end,
151                  precv_frame->len));
152
153         skb->data = precv_frame->rx_data;
154
155         skb_set_tail_pointer(skb, precv_frame->len);
156
157         skb->len = precv_frame->len;
158
159         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
160                  ("skb->head =%p skb->data =%p skb->tail =%p skb->end =%p skb->len =%d\n",
161                  skb->head, skb->data, skb_tail_pointer(skb),
162                  skb_end_pointer(skb), skb->len));
163
164         if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
165                 struct sk_buff *pskb2 = NULL;
166                 struct sta_info *psta = NULL;
167                 struct sta_priv *pstapriv = &padapter->stapriv;
168                 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
169                 int bmcast = IS_MCAST(pattrib->dst);
170
171                 if (memcmp(pattrib->dst, myid(&padapter->eeprompriv),
172                            ETH_ALEN)) {
173                         if (bmcast) {
174                                 psta = rtw_get_bcmc_stainfo(padapter);
175                                 pskb2 = skb_clone(skb, GFP_ATOMIC);
176                         } else {
177                                 psta = rtw_get_stainfo(pstapriv, pattrib->dst);
178                         }
179
180                         if (psta) {
181                                 struct net_device *pnetdev;
182
183                                 pnetdev = (struct net_device *)padapter->pnetdev;
184                                 skb->dev = pnetdev;
185                                 skb_set_queue_mapping(skb, rtw_recv_select_queue(skb));
186
187                                 rtw_xmit_entry(skb, pnetdev);
188
189                                 if (bmcast)
190                                         skb = pskb2;
191                                 else
192                                         goto _recv_indicatepkt_end;
193                         }
194                 }
195         }
196
197         rcu_read_lock();
198         rcu_dereference(padapter->pnetdev->rx_handler_data);
199         rcu_read_unlock();
200
201         skb->ip_summed = CHECKSUM_NONE;
202         skb->dev = padapter->pnetdev;
203         skb->protocol = eth_type_trans(skb, padapter->pnetdev);
204
205         netif_rx(skb);
206
207 _recv_indicatepkt_end:
208
209         /*  pointers to NULL before rtw_free_recvframe() */
210         precv_frame->pkt = NULL;
211
212         rtw_free_recvframe(precv_frame, pfree_recv_queue);
213
214         RT_TRACE(_module_recv_osdep_c_, _drv_info_,
215                  ("\n rtw_recv_indicatepkt :after netif_rx!!!!\n"));
216
217
218         return _SUCCESS;
219
220 _recv_indicatepkt_drop:
221
222          /* enqueue back to free_recv_queue */
223         rtw_free_recvframe(precv_frame, pfree_recv_queue);
224
225          return _FAIL;
226 }
227
228 void rtw_os_read_port(struct adapter *padapter, struct recv_buf *precvbuf)
229 {
230         struct recv_priv *precvpriv = &padapter->recvpriv;
231
232         precvbuf->ref_cnt--;
233         /* free skb in recv_buf */
234         dev_kfree_skb_any(precvbuf->pskb);
235         precvbuf->pskb = NULL;
236         precvbuf->reuse = false;
237         if (!precvbuf->irp_pending)
238                 rtw_read_port(padapter, precvpriv->ff_hwaddr, 0,
239                               (unsigned char *)precvbuf);
240 }
241
242 static void _rtw_reordering_ctrl_timeout_handler(void *func_context)
243 {
244         struct recv_reorder_ctrl *preorder_ctrl;
245
246         preorder_ctrl = (struct recv_reorder_ctrl *)func_context;
247         rtw_reordering_ctrl_timeout_handler(preorder_ctrl);
248 }
249
250 void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
251 {
252         struct adapter *padapter = preorder_ctrl->padapter;
253
254         _init_timer(&(preorder_ctrl->reordering_ctrl_timer), padapter->pnetdev, _rtw_reordering_ctrl_timeout_handler, preorder_ctrl);
255 }