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