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