1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2017 Realtek Corporation.
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 #define _RECV_OSDEP_C_
16
17 #include <drv_types.h>
18
rtw_os_recvframe_duplicate_skb(_adapter * padapter,union recv_frame * pcloneframe,_pkt * pskb)19 int rtw_os_recvframe_duplicate_skb(_adapter *padapter, union recv_frame *pcloneframe, _pkt *pskb)
20 {
21 int res = _SUCCESS;
22 _pkt *pkt_copy = NULL;
23
24 if (pskb == NULL) {
25 RTW_INFO("%s [WARN] skb == NULL, drop frag frame\n", __func__);
26 return _FAIL;
27 }
28 #if 1
29 pkt_copy = rtw_skb_copy(pskb);
30
31 if (pkt_copy == NULL) {
32 RTW_INFO("%s [WARN] rtw_skb_copy fail , drop frag frame\n", __func__);
33 return _FAIL;
34 }
35 #else
36 pkt_copy = rtw_skb_clone(pskb);
37
38 if (pkt_copy == NULL) {
39 RTW_INFO("%s [WARN] rtw_skb_clone fail , drop frag frame\n", __func__);
40 return _FAIL;
41 }
42 #endif
43 pkt_copy->dev = padapter->pnetdev;
44
45 pcloneframe->u.hdr.pkt = pkt_copy;
46 pcloneframe->u.hdr.rx_head = pkt_copy->head;
47 pcloneframe->u.hdr.rx_data = pkt_copy->data;
48 pcloneframe->u.hdr.rx_end = skb_end_pointer(pkt_copy);
49 pcloneframe->u.hdr.rx_tail = skb_tail_pointer(pkt_copy);
50 pcloneframe->u.hdr.len = pkt_copy->len;
51
52 return res;
53 }
54
rtw_os_alloc_recvframe(_adapter * padapter,union recv_frame * precvframe,u8 * pdata,_pkt * pskb)55 int rtw_os_alloc_recvframe(_adapter *padapter, union recv_frame *precvframe, u8 *pdata, _pkt *pskb)
56 {
57 int res = _SUCCESS;
58 u8 shift_sz = 0;
59 u32 skb_len, alloc_sz;
60 _pkt *pkt_copy = NULL;
61 struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
62
63
64 if (pdata == NULL) {
65 precvframe->u.hdr.pkt = NULL;
66 res = _FAIL;
67 return res;
68 }
69
70
71 /* Modified by Albert 20101213 */
72 /* For 8 bytes IP header alignment. */
73 shift_sz = pattrib->qos ? 6 : 0; /* Qos data, wireless lan header length is 26 */
74
75 skb_len = pattrib->pkt_len;
76
77 /* for first fragment packet, driver need allocate 1536+drvinfo_sz+RXDESC_SIZE to defrag packet. */
78 /* modify alloc_sz for recvive crc error packet by thomas 2011-06-02 */
79 if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) {
80 /* alloc_sz = 1664; */ /* 1664 is 128 alignment. */
81 alloc_sz = (skb_len <= 1650) ? 1664 : (skb_len + 14);
82 } else {
83 alloc_sz = skb_len;
84 /* 6 is for IP header 8 bytes alignment in QoS packet case. */
85 /* 8 is for skb->data 4 bytes alignment. */
86 alloc_sz += 14;
87 }
88
89 pkt_copy = rtw_skb_alloc(alloc_sz);
90
91 if (pkt_copy) {
92 pkt_copy->dev = padapter->pnetdev;
93 pkt_copy->len = skb_len;
94 precvframe->u.hdr.pkt = pkt_copy;
95 precvframe->u.hdr.rx_head = pkt_copy->head;
96 precvframe->u.hdr.rx_end = pkt_copy->data + alloc_sz;
97 skb_reserve(pkt_copy, 8 - ((SIZE_PTR)(pkt_copy->data) & 7)); /* force pkt_copy->data at 8-byte alignment address */
98 skb_reserve(pkt_copy, shift_sz);/* force ip_hdr at 8-byte alignment address according to shift_sz. */
99 _rtw_memcpy(pkt_copy->data, pdata, skb_len);
100 precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pkt_copy->data;
101 } else {
102 #if 0
103 {
104 rtw_free_recvframe(precvframe_if2, &precvpriv->free_recv_queue);
105 rtw_enqueue_recvbuf_to_head(precvbuf, &precvpriv->recv_buf_pending_queue);
106
107 /* The case of can't allocate skb is serious and may never be recovered,
108 once bDriverStopped is enable, this task should be stopped.*/
109 if (!rtw_is_drv_stopped(secondary_padapter))
110 #ifdef PLATFORM_LINUX
111 tasklet_schedule(&precvpriv->recv_tasklet);
112 #endif
113 return ret;
114 }
115
116 #endif
117
118 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
119 RTW_INFO("%s:can not allocate memory for skb copy\n", __func__);
120
121 precvframe->u.hdr.pkt = NULL;
122
123 /* rtw_free_recvframe(precvframe, pfree_recv_queue); */
124 /*exit_rtw_os_recv_resource_alloc;*/
125
126 res = _FAIL;
127 #else
128 if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) {
129 RTW_INFO("%s: alloc_skb fail , drop frag frame\n", __FUNCTION__);
130 /* rtw_free_recvframe(precvframe, pfree_recv_queue); */
131 res = _FAIL;
132 goto exit_rtw_os_recv_resource_alloc;
133 }
134
135 if (pskb == NULL) {
136 res = _FAIL;
137 goto exit_rtw_os_recv_resource_alloc;
138 }
139
140 precvframe->u.hdr.pkt = rtw_skb_clone(pskb);
141 if (precvframe->u.hdr.pkt) {
142 RTW_INFO("%s: rtw_skb_clone success, RX throughput may be low!\n", __FUNCTION__);
143 precvframe->u.hdr.pkt->dev = padapter->pnetdev;
144 precvframe->u.hdr.rx_head = precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pdata;
145 precvframe->u.hdr.rx_end = pdata + alloc_sz;
146 } else {
147 RTW_INFO("%s: rtw_skb_clone fail\n", __FUNCTION__);
148 /* rtw_free_recvframe(precvframe, pfree_recv_queue); */
149 /*exit_rtw_os_recv_resource_alloc;*/
150 res = _FAIL;
151 }
152 #endif
153 }
154
155 exit_rtw_os_recv_resource_alloc:
156
157 return res;
158
159 }
160
rtw_os_free_recvframe(union recv_frame * precvframe)161 void rtw_os_free_recvframe(union recv_frame *precvframe)
162 {
163 if (precvframe->u.hdr.pkt) {
164 rtw_os_pkt_free(precvframe->u.hdr.pkt);
165 precvframe->u.hdr.pkt = NULL;
166 }
167 }
168
169 /* init os related resource in struct recv_priv */
rtw_os_recv_resource_init(struct recv_priv * precvpriv,_adapter * padapter)170 int rtw_os_recv_resource_init(struct recv_priv *precvpriv, _adapter *padapter)
171 {
172 int res = _SUCCESS;
173
174
175 #ifdef CONFIG_RTW_NAPI
176 skb_queue_head_init(&precvpriv->rx_napi_skb_queue);
177 #endif /* CONFIG_RTW_NAPI */
178
179 return res;
180 }
181
182 /* alloc os related resource in union recv_frame */
rtw_os_recv_resource_alloc(_adapter * padapter,union recv_frame * precvframe)183 int rtw_os_recv_resource_alloc(_adapter *padapter, union recv_frame *precvframe)
184 {
185 int res = _SUCCESS;
186
187 precvframe->u.hdr.pkt = NULL;
188
189 return res;
190 }
191
192 /* free os related resource in union recv_frame */
rtw_os_recv_resource_free(struct recv_priv * precvpriv)193 void rtw_os_recv_resource_free(struct recv_priv *precvpriv)
194 {
195 sint i;
196 union recv_frame *precvframe;
197 precvframe = (union recv_frame *) precvpriv->precv_frame_buf;
198
199
200 #ifdef CONFIG_RTW_NAPI
201 if (skb_queue_len(&precvpriv->rx_napi_skb_queue))
202 RTW_WARN("rx_napi_skb_queue not empty\n");
203 rtw_skb_queue_purge(&precvpriv->rx_napi_skb_queue);
204 #endif /* CONFIG_RTW_NAPI */
205
206 for (i = 0; i < NR_RECVFRAME; i++) {
207 rtw_os_free_recvframe(precvframe);
208 precvframe++;
209 }
210 }
211
212 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
213 #if !defined(CONFIG_RTL8822B) && !defined(CONFIG_RTL8822C) && !defined(CONFIG_RTL8723F)
214 #ifdef CONFIG_SDIO_RX_COPY
sdio_init_recvbuf_with_skb(struct recv_priv * recvpriv,struct recv_buf * rbuf,u32 size)215 static int sdio_init_recvbuf_with_skb(struct recv_priv *recvpriv, struct recv_buf *rbuf, u32 size)
216 {
217 #ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
218 if (RBUF_IS_PREALLOC(rbuf)) {
219 rbuf->pskb = rtw_alloc_skb_premem(size);
220 if (!rbuf->pskb) {
221 RTW_WARN("%s: Fail to get pre-alloc skb! size=%d\n", __func__, size);
222 return _FAIL;
223 }
224 skb_set_tail_pointer(rbuf->pskb, 0); /* TODO: do this in RTKM */
225 } else
226 #else
227 {
228 SIZE_PTR tmpaddr = 0;
229 SIZE_PTR alignment = 0;
230
231 rbuf->pskb = rtw_skb_alloc(size + RECVBUFF_ALIGN_SZ);
232 if (!rbuf->pskb)
233 return _FAIL;
234
235 tmpaddr = (SIZE_PTR)rbuf->pskb->data;
236 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
237 skb_reserve(rbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
238 }
239 #endif
240
241 rbuf->pskb->dev = recvpriv->adapter->pnetdev;
242
243 /* init recvbuf */
244 rbuf->phead = rbuf->pskb->head;
245 rbuf->pdata = rbuf->pskb->data;
246 rbuf->ptail = skb_tail_pointer(rbuf->pskb);
247 rbuf->pend = skb_end_pointer(rbuf->pskb);
248 rbuf->len = 0;
249
250 return _SUCCESS;
251 }
252 #endif /* CONFIG_SDIO_RX_COPY */
253 #endif /* !defined(CONFIG_RTL8822B) && !defined(CONFIG_RTL8822C) && !defined(CONFIG_RTL8723F) */
254 #endif /* defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) */
255
256 /* alloc os related resource in struct recv_buf */
rtw_os_recvbuf_resource_alloc(_adapter * padapter,struct recv_buf * precvbuf,u32 size)257 int rtw_os_recvbuf_resource_alloc(_adapter *padapter, struct recv_buf *precvbuf, u32 size)
258 {
259 int res = _SUCCESS;
260
261 #ifdef CONFIG_USB_HCI
262 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
263 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
264 struct usb_device *pusbd = pdvobjpriv->pusbdev;
265 #endif
266
267 precvbuf->irp_pending = _FALSE;
268 precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
269 if (precvbuf->purb == NULL)
270 res = _FAIL;
271
272 precvbuf->pskb = NULL;
273
274 precvbuf->pallocated_buf = precvbuf->pbuf = NULL;
275
276 precvbuf->pdata = precvbuf->phead = precvbuf->ptail = precvbuf->pend = NULL;
277
278 precvbuf->transfer_len = 0;
279
280 precvbuf->len = 0;
281
282 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
283 precvbuf->pallocated_buf = rtw_usb_buffer_alloc(pusbd, (size_t)size, &precvbuf->dma_transfer_addr);
284 precvbuf->pbuf = precvbuf->pallocated_buf;
285 if (precvbuf->pallocated_buf == NULL)
286 return _FAIL;
287 #endif /* CONFIG_USE_USB_BUFFER_ALLOC_RX */
288
289 #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
290 #if !defined(CONFIG_RTL8822B) && !defined(CONFIG_RTL8822C) && !defined(CONFIG_RTL8723F)
291 #ifdef CONFIG_SDIO_RX_COPY
292 res = sdio_init_recvbuf_with_skb(&padapter->recvpriv, precvbuf, size);
293 #endif
294 #endif
295
296 #endif /* CONFIG_XXX_HCI */
297
298 return res;
299 }
300
301 /* free os related resource in struct recv_buf */
rtw_os_recvbuf_resource_free(_adapter * padapter,struct recv_buf * precvbuf)302 int rtw_os_recvbuf_resource_free(_adapter *padapter, struct recv_buf *precvbuf)
303 {
304 int ret = _SUCCESS;
305
306 #ifdef CONFIG_USB_HCI
307
308 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
309
310 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
311 struct usb_device *pusbd = pdvobjpriv->pusbdev;
312
313 rtw_usb_buffer_free(pusbd, (size_t)precvbuf->alloc_sz, precvbuf->pallocated_buf, precvbuf->dma_transfer_addr);
314 precvbuf->pallocated_buf = NULL;
315 precvbuf->dma_transfer_addr = 0;
316
317 #endif /* CONFIG_USE_USB_BUFFER_ALLOC_RX */
318
319 if (precvbuf->purb) {
320 /* usb_kill_urb(precvbuf->purb); */
321 usb_free_urb(precvbuf->purb);
322 }
323
324 #endif /* CONFIG_USB_HCI */
325
326
327 if (precvbuf->pskb) {
328 #ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
329 if (rtw_free_skb_premem(precvbuf->pskb) != 0)
330 #endif
331 rtw_skb_free(precvbuf->pskb);
332 }
333 return ret;
334
335 }
336
rtw_os_alloc_msdu_pkt(union recv_frame * prframe,const u8 * da,const u8 * sa,u8 * msdu,u16 msdu_len,enum rtw_rx_llc_hdl llc_hdl)337 _pkt *rtw_os_alloc_msdu_pkt(union recv_frame *prframe, const u8 *da, const u8 *sa
338 , u8 *msdu ,u16 msdu_len, enum rtw_rx_llc_hdl llc_hdl)
339 {
340 u8 *data_ptr;
341 _pkt *sub_skb;
342 struct rx_pkt_attrib *pattrib;
343
344 pattrib = &prframe->u.hdr.attrib;
345
346 #ifdef CONFIG_SKB_COPY
347 sub_skb = rtw_skb_alloc(msdu_len + 14);
348 if (sub_skb) {
349 skb_reserve(sub_skb, 14);
350 data_ptr = (u8 *)skb_put(sub_skb, msdu_len);
351 _rtw_memcpy(data_ptr, msdu, msdu_len);
352 } else
353 #endif /* CONFIG_SKB_COPY */
354 {
355 sub_skb = rtw_skb_clone(prframe->u.hdr.pkt);
356 if (sub_skb) {
357 sub_skb->data = msdu;
358 sub_skb->len = msdu_len;
359 skb_set_tail_pointer(sub_skb, msdu_len);
360 } else {
361 RTW_INFO("%s(): rtw_skb_clone() Fail!!!\n", __FUNCTION__);
362 return NULL;
363 }
364 }
365
366 if (llc_hdl) {
367 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
368 skb_pull(sub_skb, SNAP_SIZE);
369 _rtw_memcpy(skb_push(sub_skb, ETH_ALEN), sa, ETH_ALEN);
370 _rtw_memcpy(skb_push(sub_skb, ETH_ALEN), da, ETH_ALEN);
371 } else {
372 /* Leave Ethernet header part of hdr and full payload */
373 u16 len;
374
375 len = htons(sub_skb->len);
376 _rtw_memcpy(skb_push(sub_skb, 2), &len, 2);
377 _rtw_memcpy(skb_push(sub_skb, ETH_ALEN), sa, ETH_ALEN);
378 _rtw_memcpy(skb_push(sub_skb, ETH_ALEN), da, ETH_ALEN);
379 }
380
381 return sub_skb;
382 }
383
384 #ifdef CONFIG_RTW_NAPI
napi_recv(_adapter * padapter,int budget)385 static int napi_recv(_adapter *padapter, int budget)
386 {
387 _pkt *pskb;
388 struct recv_priv *precvpriv = &padapter->recvpriv;
389 int work_done = 0;
390 struct registry_priv *pregistrypriv = &padapter->registrypriv;
391 u8 rx_ok;
392
393
394 while ((work_done < budget) &&
395 (!skb_queue_empty(&precvpriv->rx_napi_skb_queue))) {
396 pskb = skb_dequeue(&precvpriv->rx_napi_skb_queue);
397 if (!pskb)
398 break;
399
400 rx_ok = _FALSE;
401
402 #ifdef CONFIG_RTW_GRO
403 /*
404 cloned SKB use dataref to avoid kernel release it.
405 But dataref changed in napi_gro_receive.
406 So, we should prevent cloned SKB go into napi_gro_receive.
407 */
408 if (pregistrypriv->en_gro && !skb_cloned(pskb)) {
409 if (rtw_napi_gro_receive(&padapter->napi, pskb) != GRO_DROP)
410 rx_ok = _TRUE;
411 goto next;
412 }
413 #endif /* CONFIG_RTW_GRO */
414
415 if (rtw_netif_receive_skb(padapter->pnetdev, pskb) == NET_RX_SUCCESS)
416 rx_ok = _TRUE;
417
418 next:
419 if (rx_ok == _TRUE) {
420 work_done++;
421 DBG_COUNTER(padapter->rx_logs.os_netif_ok);
422 } else {
423 DBG_COUNTER(padapter->rx_logs.os_netif_err);
424 }
425 }
426
427 return work_done;
428 }
429
rtw_recv_napi_poll(struct napi_struct * napi,int budget)430 int rtw_recv_napi_poll(struct napi_struct *napi, int budget)
431 {
432 _adapter *padapter = container_of(napi, _adapter, napi);
433 int work_done = 0;
434 struct recv_priv *precvpriv = &padapter->recvpriv;
435
436
437 work_done = napi_recv(padapter, budget);
438 if (work_done < budget) {
439 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_PCI_HCI)
440 napi_complete_done(napi, work_done);
441 #else
442 napi_complete(napi);
443 #endif
444 if (!skb_queue_empty(&precvpriv->rx_napi_skb_queue))
445 napi_schedule(napi);
446 }
447
448 return work_done;
449 }
450
451 #ifdef CONFIG_RTW_NAPI_DYNAMIC
dynamic_napi_th_chk(_adapter * adapter)452 void dynamic_napi_th_chk (_adapter *adapter)
453 {
454
455 if (adapter->registrypriv.en_napi) {
456 struct dvobj_priv *dvobj;
457 struct registry_priv *registry;
458
459 dvobj = adapter_to_dvobj(adapter);
460 registry = &adapter->registrypriv;
461 if (dvobj->traffic_stat.cur_rx_tp > registry->napi_threshold)
462 dvobj->en_napi_dynamic = 1;
463 else
464 dvobj->en_napi_dynamic = 0;
465 }
466
467 }
468 #endif /* CONFIG_RTW_NAPI_DYNAMIC */
469 #endif /* CONFIG_RTW_NAPI */
470
rtw_os_recv_indicate_pkt(_adapter * padapter,_pkt * pkt,union recv_frame * rframe)471 void rtw_os_recv_indicate_pkt(_adapter *padapter, _pkt *pkt, union recv_frame *rframe)
472 {
473 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
474 struct recv_priv *precvpriv = &(padapter->recvpriv);
475 struct registry_priv *pregistrypriv = &padapter->registrypriv;
476 #ifdef CONFIG_BR_EXT
477 void *br_port = NULL;
478 #endif
479 int ret;
480
481 /* Indicat the packets to upper layer */
482 if (pkt) {
483 struct ethhdr *ehdr = (struct ethhdr *)pkt->data;
484
485 DBG_COUNTER(padapter->rx_logs.os_indicate);
486
487 #ifdef CONFIG_BR_EXT
488 if (!adapter_use_wds(padapter) && check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE) == _TRUE) {
489 /* Insert NAT2.5 RX here! */
490 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
491 br_port = padapter->pnetdev->br_port;
492 #else
493 rcu_read_lock();
494 br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
495 rcu_read_unlock();
496 #endif
497
498 if (br_port) {
499 int nat25_handle_frame(_adapter *priv, struct sk_buff *skb);
500
501 if (nat25_handle_frame(padapter, pkt) == -1) {
502 /* priv->ext_stats.rx_data_drops++; */
503 /* DEBUG_ERR("RX DROP: nat25_handle_frame fail!\n"); */
504 /* return FAIL; */
505
506 #if 1
507 /* bypass this frame to upper layer!! */
508 #else
509 rtw_skb_free(sub_skb);
510 continue;
511 #endif
512 }
513 }
514 }
515 #endif /* CONFIG_BR_EXT */
516
517 /* After eth_type_trans process , pkt->data pointer will move from ethrnet header to ip header */
518 pkt->protocol = eth_type_trans(pkt, padapter->pnetdev);
519 pkt->dev = padapter->pnetdev;
520 pkt->ip_summed = CHECKSUM_NONE; /* CONFIG_TCP_CSUM_OFFLOAD_RX */
521
522 if (padapter->recvpriv.ip_statistic.enabled)
523 rtw_rx_dbg_monitor_ip_statistic(padapter, pkt);
524
525 #ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
526 if ((rframe->u.hdr.attrib.csum_valid == 1)
527 && (rframe->u.hdr.attrib.csum_err == 0))
528 pkt->ip_summed = CHECKSUM_UNNECESSARY;
529 #endif /* CONFIG_TCP_CSUM_OFFLOAD_RX */
530
531 #ifdef CONFIG_RTW_NAPI
532 #ifdef CONFIG_RTW_NAPI_DYNAMIC
533 if (!skb_queue_empty(&precvpriv->rx_napi_skb_queue)
534 && !adapter_to_dvobj(padapter)->en_napi_dynamic
535 )
536 napi_recv(padapter, RTL_NAPI_WEIGHT);
537 #endif
538
539 if (pregistrypriv->en_napi
540 #ifdef CONFIG_RTW_NAPI_DYNAMIC
541 && adapter_to_dvobj(padapter)->en_napi_dynamic
542 #endif
543 ) {
544 skb_queue_tail(&precvpriv->rx_napi_skb_queue, pkt);
545 #ifndef CONFIG_RTW_NAPI_V2
546 napi_schedule(&padapter->napi);
547 #endif
548 return;
549 }
550 #endif /* CONFIG_RTW_NAPI */
551
552 ret = rtw_netif_rx(padapter->pnetdev, pkt);
553 if (ret == NET_RX_SUCCESS)
554 DBG_COUNTER(padapter->rx_logs.os_netif_ok);
555 else
556 DBG_COUNTER(padapter->rx_logs.os_netif_err);
557 }
558 }
559
rtw_handle_tkip_mic_err(_adapter * padapter,struct sta_info * sta,u8 bgroup)560 void rtw_handle_tkip_mic_err(_adapter *padapter, struct sta_info *sta, u8 bgroup)
561 {
562 #ifdef CONFIG_IOCTL_CFG80211
563 enum nl80211_key_type key_type = 0;
564 #endif
565 union iwreq_data wrqu;
566 struct iw_michaelmicfailure ev;
567 struct security_priv *psecuritypriv = &padapter->securitypriv;
568 systime cur_time = 0;
569
570 if (psecuritypriv->last_mic_err_time == 0)
571 psecuritypriv->last_mic_err_time = rtw_get_current_time();
572 else {
573 cur_time = rtw_get_current_time();
574
575 if (cur_time - psecuritypriv->last_mic_err_time < 60 * HZ) {
576 psecuritypriv->btkip_countermeasure = _TRUE;
577 psecuritypriv->last_mic_err_time = 0;
578 psecuritypriv->btkip_countermeasure_time = cur_time;
579 } else
580 psecuritypriv->last_mic_err_time = rtw_get_current_time();
581 }
582
583 #ifdef CONFIG_IOCTL_CFG80211
584 if (bgroup)
585 key_type |= NL80211_KEYTYPE_GROUP;
586 else
587 key_type |= NL80211_KEYTYPE_PAIRWISE;
588
589 cfg80211_michael_mic_failure(padapter->pnetdev, sta->cmn.mac_addr, key_type, -1, NULL, GFP_ATOMIC);
590 #endif
591
592 _rtw_memset(&ev, 0x00, sizeof(ev));
593 if (bgroup)
594 ev.flags |= IW_MICFAILURE_GROUP;
595 else
596 ev.flags |= IW_MICFAILURE_PAIRWISE;
597
598 ev.src_addr.sa_family = ARPHRD_ETHER;
599 _rtw_memcpy(ev.src_addr.sa_data, sta->cmn.mac_addr, ETH_ALEN);
600
601 _rtw_memset(&wrqu, 0x00, sizeof(wrqu));
602 wrqu.data.length = sizeof(ev);
603
604 #ifndef CONFIG_IOCTL_CFG80211
605 wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu, (char *) &ev);
606 #endif
607 }
608
609 #ifdef CONFIG_HOSTAPD_MLME
rtw_hostapd_mlme_rx(_adapter * padapter,union recv_frame * precv_frame)610 void rtw_hostapd_mlme_rx(_adapter *padapter, union recv_frame *precv_frame)
611 {
612 _pkt *skb;
613 struct hostapd_priv *phostapdpriv = padapter->phostapdpriv;
614 struct net_device *pmgnt_netdev = phostapdpriv->pmgnt_netdev;
615
616
617 skb = precv_frame->u.hdr.pkt;
618
619 if (skb == NULL)
620 return;
621
622 skb->data = precv_frame->u.hdr.rx_data;
623 skb->tail = precv_frame->u.hdr.rx_tail;
624 skb->len = precv_frame->u.hdr.len;
625
626 /* pskb_copy = rtw_skb_copy(skb);
627 * if(skb == NULL) goto _exit; */
628
629 skb->dev = pmgnt_netdev;
630 skb->ip_summed = CHECKSUM_NONE;
631 skb->pkt_type = PACKET_OTHERHOST;
632 /* skb->protocol = __constant_htons(0x0019); ETH_P_80211_RAW */
633 skb->protocol = __constant_htons(0x0003); /*ETH_P_80211_RAW*/
634
635 /* RTW_INFO("(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); */
636
637 /* skb->mac.raw = skb->data; */
638 skb_reset_mac_header(skb);
639
640 /* skb_pull(skb, 24); */
641 _rtw_memset(skb->cb, 0, sizeof(skb->cb));
642
643 rtw_netif_rx(pmgnt_netdev, skb);
644
645 precv_frame->u.hdr.pkt = NULL; /* set pointer to NULL before rtw_free_recvframe() if call rtw_netif_rx() */
646 }
647 #endif /* CONFIG_HOSTAPD_MLME */
648
649 #ifdef CONFIG_WIFI_MONITOR
650 /*
651 precv_frame: impossible to be NULL
652 precv_frame: free by caller
653 */
rtw_recv_monitor(_adapter * padapter,union recv_frame * precv_frame)654 int rtw_recv_monitor(_adapter *padapter, union recv_frame *precv_frame)
655 {
656 int ret = _FAIL;
657 _pkt *skb;
658
659 skb = precv_frame->u.hdr.pkt;
660 if (skb == NULL) {
661 RTW_INFO("%s :skb==NULL something wrong!!!!\n", __func__);
662 goto _recv_drop;
663 }
664
665 skb->data = precv_frame->u.hdr.rx_data;
666 skb_set_tail_pointer(skb, precv_frame->u.hdr.len);
667 skb->len = precv_frame->u.hdr.len;
668 skb->ip_summed = CHECKSUM_NONE;
669 skb->pkt_type = PACKET_OTHERHOST;
670 skb->protocol = htons(0x0019); /* ETH_P_80211_RAW */
671
672 /* send to kernel */
673 rtw_netif_rx(padapter->pnetdev, skb);
674
675 /* pointers to NULL before rtw_free_recvframe() */
676 precv_frame->u.hdr.pkt = NULL;
677
678 ret = _SUCCESS;
679
680 _recv_drop:
681 return ret;
682 }
683 #endif /* CONFIG_WIFI_MONITOR */
684
rtw_rframe_set_os_pkt(union recv_frame * rframe)685 inline void rtw_rframe_set_os_pkt(union recv_frame *rframe)
686 {
687 _pkt *skb = rframe->u.hdr.pkt;
688
689 skb->data = rframe->u.hdr.rx_data;
690 skb_set_tail_pointer(skb, rframe->u.hdr.len);
691 skb->len = rframe->u.hdr.len;
692 }
693
rtw_recv_indicatepkt(_adapter * padapter,union recv_frame * precv_frame)694 int rtw_recv_indicatepkt(_adapter *padapter, union recv_frame *precv_frame)
695 {
696 struct recv_priv *precvpriv;
697 _queue *pfree_recv_queue;
698
699 precvpriv = &(padapter->recvpriv);
700 pfree_recv_queue = &(precvpriv->free_recv_queue);
701
702 if (precv_frame->u.hdr.pkt == NULL)
703 goto _recv_indicatepkt_drop;
704
705 rtw_os_recv_indicate_pkt(padapter, precv_frame->u.hdr.pkt, precv_frame);
706
707 precv_frame->u.hdr.pkt = NULL;
708 rtw_free_recvframe(precv_frame, pfree_recv_queue);
709 return _SUCCESS;
710
711 _recv_indicatepkt_drop:
712 rtw_free_recvframe(precv_frame, pfree_recv_queue);
713 DBG_COUNTER(padapter->rx_logs.os_indicate_err);
714 return _FAIL;
715 }
716
rtw_os_read_port(_adapter * padapter,struct recv_buf * precvbuf)717 void rtw_os_read_port(_adapter *padapter, struct recv_buf *precvbuf)
718 {
719 #ifdef CONFIG_USB_HCI
720 struct recv_priv *precvpriv = &padapter->recvpriv;
721
722 precvbuf->ref_cnt--;
723
724 /* free skb in recv_buf */
725 rtw_skb_free(precvbuf->pskb);
726
727 precvbuf->pskb = NULL;
728
729 if (precvbuf->irp_pending == _FALSE)
730 rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);
731
732
733 #endif
734 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
735 precvbuf->pskb = NULL;
736 #endif
737
738 }
739
740