]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/net/wireless/realtek/rtl8192cu/os_dep/linux/recv_linux.c
net: Fix rtl8192cu build errors on other platforms
[mirror_ubuntu-zesty-kernel.git] / drivers / net / wireless / realtek / rtl8192cu / os_dep / linux / 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 <drv_conf.h>
23 #include <osdep_service.h>
24 #include <drv_types.h>
25
26 #include <wifi.h>
27 #include <recv_osdep.h>
28
29 #include <osdep_intf.h>
30 #include <ethernet.h>
31
32 #ifdef CONFIG_USB_HCI
33 #include <usb_ops.h>
34 #endif
35
36 //init os related resource in struct recv_priv
37 int rtw_os_recv_resource_init(struct recv_priv *precvpriv, _adapter *padapter)
38 {
39 int res=_SUCCESS;
40
41 return res;
42 }
43
44 //alloc os related resource in union recv_frame
45 int rtw_os_recv_resource_alloc(_adapter *padapter, union recv_frame *precvframe)
46 {
47 int res=_SUCCESS;
48
49 precvframe->u.hdr.pkt_newalloc = precvframe->u.hdr.pkt = NULL;
50
51 return res;
52
53 }
54
55 //free os related resource in union recv_frame
56 void rtw_os_recv_resource_free(struct recv_priv *precvpriv)
57 {
58
59 }
60
61
62 //alloc os related resource in struct recv_buf
63 int rtw_os_recvbuf_resource_alloc(_adapter *padapter, struct recv_buf *precvbuf)
64 {
65 int res=_SUCCESS;
66
67 #ifdef CONFIG_USB_HCI
68 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
69 struct usb_device *pusbd = pdvobjpriv->pusbdev;
70
71 precvbuf->irp_pending = _FALSE;
72 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
73 if(precvbuf->purb == NULL){
74 res = _FAIL;
75 }
76
77 precvbuf->pskb = NULL;
78
79 precvbuf->reuse = _FALSE;
80
81 precvbuf->pallocated_buf = precvbuf->pbuf = NULL;
82
83 precvbuf->pdata = precvbuf->phead = precvbuf->ptail = precvbuf->pend = NULL;
84
85 precvbuf->transfer_len = 0;
86
87 precvbuf->len = 0;
88
89 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
90 precvbuf->pallocated_buf = rtw_usb_buffer_alloc(pusbd, (size_t)precvbuf->alloc_sz, &precvbuf->dma_transfer_addr);
91 precvbuf->pbuf = precvbuf->pallocated_buf;
92 if(precvbuf->pallocated_buf == NULL)
93 return _FAIL;
94 #endif //CONFIG_USE_USB_BUFFER_ALLOC_RX
95
96 #endif //CONFIG_USB_HCI
97
98 return res;
99 }
100
101 //free os related resource in struct recv_buf
102 int rtw_os_recvbuf_resource_free(_adapter *padapter, struct recv_buf *precvbuf)
103 {
104 int ret = _SUCCESS;
105
106 #ifdef CONFIG_USB_HCI
107
108 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
109
110 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
111 struct usb_device *pusbd = pdvobjpriv->pusbdev;
112
113 rtw_usb_buffer_free(pusbd, (size_t)precvbuf->alloc_sz, precvbuf->pallocated_buf, precvbuf->dma_transfer_addr);
114 precvbuf->pallocated_buf = NULL;
115 precvbuf->dma_transfer_addr = 0;
116
117 #endif //CONFIG_USE_USB_BUFFER_ALLOC_RX
118
119 if(precvbuf->purb)
120 {
121 //usb_kill_urb(precvbuf->purb);
122 usb_free_urb(precvbuf->purb);
123 }
124
125 #endif //CONFIG_USB_HCI
126
127
128 if(precvbuf->pskb)
129 rtw_skb_free(precvbuf->pskb);
130
131
132 return ret;
133
134 }
135
136 void rtw_handle_tkip_mic_err(_adapter *padapter,u8 bgroup)
137 {
138 #ifdef CONFIG_IOCTL_CFG80211
139 enum nl80211_key_type key_type = 0;
140 #endif
141 union iwreq_data wrqu;
142 struct iw_michaelmicfailure ev;
143 struct mlme_priv* pmlmepriv = &padapter->mlmepriv;
144 struct security_priv *psecuritypriv = &padapter->securitypriv;
145 u32 cur_time = 0;
146
147 if( psecuritypriv->last_mic_err_time == 0 )
148 {
149 psecuritypriv->last_mic_err_time = rtw_get_current_time();
150 }
151 else
152 {
153 cur_time = rtw_get_current_time();
154
155 if( cur_time - psecuritypriv->last_mic_err_time < 60*HZ )
156 {
157 psecuritypriv->btkip_countermeasure = _TRUE;
158 psecuritypriv->last_mic_err_time = 0;
159 psecuritypriv->btkip_countermeasure_time = cur_time;
160 }
161 else
162 {
163 psecuritypriv->last_mic_err_time = rtw_get_current_time();
164 }
165 }
166
167 #ifdef CONFIG_IOCTL_CFG80211
168 if ( bgroup )
169 {
170 key_type |= NL80211_KEYTYPE_GROUP;
171 }
172 else
173 {
174 key_type |= NL80211_KEYTYPE_PAIRWISE;
175 }
176
177 cfg80211_michael_mic_failure(padapter->pnetdev, (u8 *)&pmlmepriv->assoc_bssid[ 0 ], key_type, -1,
178 NULL, GFP_ATOMIC);
179 #endif
180
181 _rtw_memset( &ev, 0x00, sizeof( ev ) );
182 if ( bgroup )
183 {
184 ev.flags |= IW_MICFAILURE_GROUP;
185 }
186 else
187 {
188 ev.flags |= IW_MICFAILURE_PAIRWISE;
189 }
190
191 ev.src_addr.sa_family = ARPHRD_ETHER;
192 _rtw_memcpy( ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[ 0 ], ETH_ALEN );
193
194 _rtw_memset( &wrqu, 0x00, sizeof( wrqu ) );
195 wrqu.data.length = sizeof( ev );
196
197 wireless_send_event( padapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu, (char*) &ev );
198 }
199
200 void rtw_hostapd_mlme_rx(_adapter *padapter, union recv_frame *precv_frame)
201 {
202 #ifdef CONFIG_HOSTAPD_MLME
203 _pkt *skb;
204 struct hostapd_priv *phostapdpriv = padapter->phostapdpriv;
205 struct net_device *pmgnt_netdev = phostapdpriv->pmgnt_netdev;
206
207 RT_TRACE(_module_recv_osdep_c_, _drv_info_, ("+rtw_hostapd_mlme_rx\n"));
208
209 skb = precv_frame->u.hdr.pkt;
210
211 if (skb == NULL)
212 return;
213
214 skb->data = precv_frame->u.hdr.rx_data;
215 skb->tail = precv_frame->u.hdr.rx_tail;
216 skb->len = precv_frame->u.hdr.len;
217
218 //pskb_copy = rtw_skb_copy(skb);
219 // if(skb == NULL) goto _exit;
220
221 skb->dev = pmgnt_netdev;
222 skb->ip_summed = CHECKSUM_NONE;
223 skb->pkt_type = PACKET_OTHERHOST;
224 //skb->protocol = __constant_htons(0x0019); /*ETH_P_80211_RAW*/
225 skb->protocol = __constant_htons(0x0003); /*ETH_P_80211_RAW*/
226
227 //DBG_871X("(1)data=0x%x, head=0x%x, tail=0x%x, mac_header=0x%x, len=%d\n", skb->data, skb->head, skb->tail, skb->mac_header, skb->len);
228
229 //skb->mac.raw = skb->data;
230 skb_reset_mac_header(skb);
231
232 //skb_pull(skb, 24);
233 _rtw_memset(skb->cb, 0, sizeof(skb->cb));
234
235 rtw_netif_rx(pmgnt_netdev, skb);
236
237 precv_frame->u.hdr.pkt = NULL; // set pointer to NULL before rtw_free_recvframe() if call rtw_netif_rx()
238 #endif
239 }
240
241 int rtw_recv_indicatepkt(_adapter *padapter, union recv_frame *precv_frame)
242 {
243 struct recv_priv *precvpriv;
244 _queue *pfree_recv_queue;
245 _pkt *skb;
246 struct mlme_priv*pmlmepriv = &padapter->mlmepriv;
247 #ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
248 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
249 #endif
250
251 #ifdef CONFIG_BR_EXT
252 void *br_port = NULL;
253 #endif
254
255 _func_enter_;
256
257 precvpriv = &(padapter->recvpriv);
258 pfree_recv_queue = &(precvpriv->free_recv_queue);
259
260 #ifdef CONFIG_DRVEXT_MODULE
261 if (drvext_rx_handler(padapter, precv_frame->u.hdr.rx_data, precv_frame->u.hdr.len) == _SUCCESS)
262 {
263 goto _recv_indicatepkt_drop;
264 }
265 #endif
266
267 skb = precv_frame->u.hdr.pkt;
268 if(skb == NULL)
269 {
270 RT_TRACE(_module_recv_osdep_c_,_drv_err_,("rtw_recv_indicatepkt():skb==NULL something wrong!!!!\n"));
271 goto _recv_indicatepkt_drop;
272 }
273
274 RT_TRACE(_module_recv_osdep_c_,_drv_info_,("rtw_recv_indicatepkt():skb != NULL !!!\n"));
275 RT_TRACE(_module_recv_osdep_c_,_drv_info_,("rtw_recv_indicatepkt():precv_frame->u.hdr.rx_head=%p precv_frame->hdr.rx_data=%p\n", precv_frame->u.hdr.rx_head, precv_frame->u.hdr.rx_data));
276 RT_TRACE(_module_recv_osdep_c_,_drv_info_,("precv_frame->hdr.rx_tail=%p precv_frame->u.hdr.rx_end=%p precv_frame->hdr.len=%d \n", precv_frame->u.hdr.rx_tail, precv_frame->u.hdr.rx_end, precv_frame->u.hdr.len));
277
278 skb->data = precv_frame->u.hdr.rx_data;
279
280 skb_set_tail_pointer(skb, precv_frame->u.hdr.len);
281
282 skb->len = precv_frame->u.hdr.len;
283
284 RT_TRACE(_module_recv_osdep_c_,_drv_info_,("\n skb->head=%p skb->data=%p skb->tail=%p skb->end=%p skb->len=%d\n", skb->head, skb->data, skb->tail, skb->end, skb->len));
285
286 if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
287 {
288 _pkt *pskb2=NULL;
289 struct sta_info *psta = NULL;
290 struct sta_priv *pstapriv = &padapter->stapriv;
291 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
292 int bmcast = IS_MCAST(pattrib->dst);
293
294 //DBG_871X("bmcast=%d\n", bmcast);
295
296 if(_rtw_memcmp(pattrib->dst, myid(&padapter->eeprompriv), ETH_ALEN)==_FALSE)
297 {
298 //DBG_871X("not ap psta=%p, addr=%pM\n", psta, pattrib->dst);
299
300 if(bmcast)
301 {
302 psta = rtw_get_bcmc_stainfo(padapter);
303 pskb2 = rtw_skb_clone(skb);
304 } else {
305 psta = rtw_get_stainfo(pstapriv, pattrib->dst);
306 }
307
308 if(psta)
309 {
310 struct net_device *pnetdev= (struct net_device*)padapter->pnetdev;
311
312 //DBG_871X("directly forwarding to the rtw_xmit_entry\n");
313
314 //skb->ip_summed = CHECKSUM_NONE;
315 skb->dev = pnetdev;
316 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
317 skb_set_queue_mapping(skb, rtw_recv_select_queue(skb));
318 #endif //LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35)
319
320 _rtw_xmit_entry(skb, pnetdev);
321
322 if(bmcast)
323 skb = pskb2;
324 else
325 goto _recv_indicatepkt_end;
326 }
327
328
329 }
330 else// to APself
331 {
332 //DBG_871X("to APSelf\n");
333 }
334 }
335
336
337 #ifdef CONFIG_BR_EXT
338
339 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
340 br_port = padapter->pnetdev->br_port;
341 #else // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
342 rcu_read_lock();
343 br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
344 rcu_read_unlock();
345 #endif // (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
346
347 if( br_port && (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) == _TRUE) )
348 {
349 int nat25_handle_frame(_adapter *priv, struct sk_buff *skb);
350 if (nat25_handle_frame(padapter, skb) == -1) {
351 //priv->ext_stats.rx_data_drops++;
352 //DEBUG_ERR("RX DROP: nat25_handle_frame fail!\n");
353 //return FAIL;
354 #if 1
355 // bypass this frame to upper layer!!
356 #else
357 goto _recv_indicatepkt_drop;
358 #endif
359 }
360 }
361
362 #endif // CONFIG_BR_EXT
363
364
365 #ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
366 if ( (pattrib->tcpchk_valid == 1) && (pattrib->tcp_chkrpt == 1) ) {
367 skb->ip_summed = CHECKSUM_UNNECESSARY;
368 //DBG_871X("CHECKSUM_UNNECESSARY \n");
369 } else {
370 skb->ip_summed = CHECKSUM_NONE;
371 //DBG_871X("CHECKSUM_NONE(%d, %d) \n", pattrib->tcpchk_valid, pattrib->tcp_chkrpt);
372 }
373 #else /* !CONFIG_TCP_CSUM_OFFLOAD_RX */
374
375 skb->ip_summed = CHECKSUM_NONE;
376
377 #endif
378
379 skb->dev = padapter->pnetdev;
380 skb->protocol = eth_type_trans(skb, padapter->pnetdev);
381
382 rtw_netif_rx(padapter->pnetdev, skb);
383
384 _recv_indicatepkt_end:
385
386 precv_frame->u.hdr.pkt = NULL; // pointers to NULL before rtw_free_recvframe()
387
388 rtw_free_recvframe(precv_frame, pfree_recv_queue);
389
390 RT_TRACE(_module_recv_osdep_c_,_drv_info_,("\n rtw_recv_indicatepkt :after rtw_netif_rx!!!!\n"));
391
392 _func_exit_;
393
394 return _SUCCESS;
395
396 _recv_indicatepkt_drop:
397
398 //enqueue back to free_recv_queue
399 if(precv_frame)
400 rtw_free_recvframe(precv_frame, pfree_recv_queue);
401
402 return _FAIL;
403
404 _func_exit_;
405
406 }
407
408 void rtw_os_read_port(_adapter *padapter, struct recv_buf *precvbuf)
409 {
410 struct recv_priv *precvpriv = &padapter->recvpriv;
411
412 #ifdef CONFIG_USB_HCI
413
414 precvbuf->ref_cnt--;
415
416 //free skb in recv_buf
417 rtw_skb_free(precvbuf->pskb);
418
419 precvbuf->pskb = NULL;
420 precvbuf->reuse = _FALSE;
421
422 if(precvbuf->irp_pending == _FALSE)
423 {
424 rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);
425 }
426
427
428 #endif
429 #ifdef CONFIG_SDIO_HCI
430 precvbuf->pskb = NULL;
431 #endif
432
433 }
434 void _rtw_reordering_ctrl_timeout_handler (void *FunctionContext);
435 void _rtw_reordering_ctrl_timeout_handler (void *FunctionContext)
436 {
437 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)FunctionContext;
438 rtw_reordering_ctrl_timeout_handler(preorder_ctrl);
439 }
440
441 void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
442 {
443 _adapter *padapter = preorder_ctrl->padapter;
444
445 _init_timer(&(preorder_ctrl->reordering_ctrl_timer), padapter->pnetdev, _rtw_reordering_ctrl_timeout_handler, preorder_ctrl);
446
447 }