• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
410 			rtw_napi_gro_receive(&padapter->napi, pskb);
411 			rx_ok = _TRUE;
412 #else
413 			if (rtw_napi_gro_receive(&padapter->napi, pskb) != GRO_DROP)
414 				rx_ok = _TRUE;
415 #endif
416 			goto next;
417 		}
418 #endif /* CONFIG_RTW_GRO */
419 
420 		if (rtw_netif_receive_skb(padapter->pnetdev, pskb) == NET_RX_SUCCESS)
421 			rx_ok = _TRUE;
422 
423 next:
424 		if (rx_ok == _TRUE) {
425 			work_done++;
426 			DBG_COUNTER(padapter->rx_logs.os_netif_ok);
427 		} else {
428 			DBG_COUNTER(padapter->rx_logs.os_netif_err);
429 		}
430 	}
431 
432 	return work_done;
433 }
434 
rtw_recv_napi_poll(struct napi_struct * napi,int budget)435 int rtw_recv_napi_poll(struct napi_struct *napi, int budget)
436 {
437 	_adapter *padapter = container_of(napi, _adapter, napi);
438 	int work_done = 0;
439 	struct recv_priv *precvpriv = &padapter->recvpriv;
440 
441 
442 	work_done = napi_recv(padapter, budget);
443 	if (work_done < budget) {
444 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_PCI_HCI)
445 		napi_complete_done(napi, work_done);
446 #else
447 		napi_complete(napi);
448 #endif
449 		if (!skb_queue_empty(&precvpriv->rx_napi_skb_queue))
450 			napi_schedule(napi);
451 	}
452 
453 	return work_done;
454 }
455 
456 #ifdef CONFIG_RTW_NAPI_DYNAMIC
dynamic_napi_th_chk(_adapter * adapter)457 void dynamic_napi_th_chk (_adapter *adapter)
458 {
459 
460 	if (adapter->registrypriv.en_napi) {
461 		struct dvobj_priv *dvobj;
462 		struct registry_priv *registry;
463 
464 		dvobj = adapter_to_dvobj(adapter);
465 		registry = &adapter->registrypriv;
466 		if (dvobj->traffic_stat.cur_rx_tp > registry->napi_threshold)
467 			dvobj->en_napi_dynamic = 1;
468 		else
469 			dvobj->en_napi_dynamic = 0;
470 	}
471 
472 }
473 #endif /* CONFIG_RTW_NAPI_DYNAMIC */
474 #endif /* CONFIG_RTW_NAPI */
475 
476 #ifdef CONFIG_RTL8822CS_WIFI_HDF
477 struct rtw_EapolData {
478     bool regFlag;  /* is already registered */
479     unsigned short count; /* eapol frame count in NetBuffQueue. */
480     unsigned short maxCount;
481     signed long long enqueueTime;                       /* record eapol frame time for dfx. */
482     void (*notify)(const char *name, void *context); /* notify eapol frame enqueue message */
483     void *context;
484     NetBufQueue eapolQueue;
485 };
486 
rtw_os_indicate_eapol(_adapter * padapter,_pkt * pkt)487 static int rtw_os_indicate_eapol(_adapter *padapter, _pkt *pkt)
488 {
489 	u32 offset = 0;
490 	char* name = ADPT_ARG(padapter);
491 	struct rtw_EapolData * eapol = (struct rtw_EapolData *)get_rtl_netdev()->specialProcPriv;
492 
493 	if(pkt ==NULL)
494 	{
495 		RTW_INFO("rtw_os_indicate_eapol: alloc eapol pkt packet fail \n");
496 		goto err_handle;
497 	}
498 
499 	NetBufQueueEnqueue(&(eapol->eapolQueue), pkt);
500 	HdfWifiEventEapolRecv(name, eapol->context);
501 	return 0;
502 
503 err_handle:
504 	rtw_skb_free(pkt);
505 	if(pkt != NULL)
506 		NetBufFree(pkt);
507 	return 1;
508 }
509 #endif
510 
rtw_os_recv_indicate_pkt(_adapter * padapter,_pkt * pkt,union recv_frame * rframe)511 void rtw_os_recv_indicate_pkt(_adapter *padapter, _pkt *pkt, union recv_frame *rframe)
512 {
513 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
514 	struct recv_priv *precvpriv = &(padapter->recvpriv);
515 	struct registry_priv	*pregistrypriv = &padapter->registrypriv;
516 #ifdef CONFIG_BR_EXT
517 	void *br_port = NULL;
518 #endif
519 	int ret;
520 
521 #ifdef CONFIG_RTL8822CS_WIFI_HDF
522     if (pkt && rframe->u.hdr.attrib.eth_type == 0x888e) {
523 		RTW_INFO("recv eapol packet\n");
524         _pkt *skb;
525         skb = rframe->u.hdr.pkt;
526         skb->data = rframe->u.hdr.rx_data;
527         skb_set_tail_pointer(skb, rframe->u.hdr.len);
528         skb->len = rframe->u.hdr.len;
529 		rtw_os_indicate_eapol(padapter,skb);
530 		return;
531     }
532 #endif
533 
534 	/* Indicat the packets to upper layer */
535 	if (pkt) {
536 		struct ethhdr *ehdr = (struct ethhdr *)pkt->data;
537 
538 		DBG_COUNTER(padapter->rx_logs.os_indicate);
539 
540 #ifdef CONFIG_BR_EXT
541 		if (!adapter_use_wds(padapter) && check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE) == _TRUE) {
542 			/* Insert NAT2.5 RX here! */
543 			#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
544 			br_port = padapter->pnetdev->br_port;
545 			#else
546 			rcu_read_lock();
547 			br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
548 			rcu_read_unlock();
549 			#endif
550 
551 			if (br_port) {
552 				int nat25_handle_frame(_adapter *priv, struct sk_buff *skb);
553 
554 				if (nat25_handle_frame(padapter, pkt) == -1) {
555 					/* priv->ext_stats.rx_data_drops++; */
556 					/* DEBUG_ERR("RX DROP: nat25_handle_frame fail!\n"); */
557 					/* return FAIL; */
558 
559 					#if 1
560 					/* bypass this frame to upper layer!! */
561 					#else
562 					rtw_skb_free(sub_skb);
563 					continue;
564 					#endif
565 				}
566 			}
567 		}
568 #endif /* CONFIG_BR_EXT */
569 
570 		/* After eth_type_trans process , pkt->data pointer will move from ethrnet header to ip header */
571 #ifndef CONFIG_RTL8822CS_WIFI_HDF
572 		pkt->protocol = eth_type_trans(pkt, padapter->pnetdev);
573 #endif
574 		pkt->dev = padapter->pnetdev;
575 		pkt->ip_summed = CHECKSUM_NONE; /* CONFIG_TCP_CSUM_OFFLOAD_RX */
576 
577 		if (padapter->recvpriv.ip_statistic.enabled)
578 			rtw_rx_dbg_monitor_ip_statistic(padapter, pkt);
579 
580 #ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
581 		if ((rframe->u.hdr.attrib.csum_valid == 1)
582 		    && (rframe->u.hdr.attrib.csum_err == 0))
583 			pkt->ip_summed = CHECKSUM_UNNECESSARY;
584 #endif /* CONFIG_TCP_CSUM_OFFLOAD_RX */
585 
586 #ifdef CONFIG_RTW_NAPI
587 #ifdef CONFIG_RTW_NAPI_DYNAMIC
588 		if (!skb_queue_empty(&precvpriv->rx_napi_skb_queue)
589 			&& !adapter_to_dvobj(padapter)->en_napi_dynamic
590 			)
591 			napi_recv(padapter, RTL_NAPI_WEIGHT);
592 #endif
593 
594 		if (pregistrypriv->en_napi
595 			#ifdef CONFIG_RTW_NAPI_DYNAMIC
596 			&& adapter_to_dvobj(padapter)->en_napi_dynamic
597 			#endif
598 		) {
599 			skb_queue_tail(&precvpriv->rx_napi_skb_queue, pkt);
600 			#ifndef CONFIG_RTW_NAPI_V2
601 			napi_schedule(&padapter->napi);
602 			#endif
603 			return;
604 		}
605 #endif /* CONFIG_RTW_NAPI */
606 
607 		ret = rtw_netif_rx(padapter->pnetdev, pkt);
608 		if (ret == NET_RX_SUCCESS)
609 			DBG_COUNTER(padapter->rx_logs.os_netif_ok);
610 		else
611 			DBG_COUNTER(padapter->rx_logs.os_netif_err);
612 	}
613 }
614 
rtw_handle_tkip_mic_err(_adapter * padapter,struct sta_info * sta,u8 bgroup)615 void rtw_handle_tkip_mic_err(_adapter *padapter, struct sta_info *sta, u8 bgroup)
616 {
617 #ifdef CONFIG_IOCTL_CFG80211
618 	enum nl80211_key_type key_type = 0;
619 #endif
620 	union iwreq_data wrqu;
621 	struct iw_michaelmicfailure    ev;
622 	struct security_priv	*psecuritypriv = &padapter->securitypriv;
623 	systime cur_time = 0;
624 
625 	if (psecuritypriv->last_mic_err_time == 0)
626 		psecuritypriv->last_mic_err_time = rtw_get_current_time();
627 	else {
628 		cur_time = rtw_get_current_time();
629 
630 		if (cur_time - psecuritypriv->last_mic_err_time < 60 * HZ) {
631 			psecuritypriv->btkip_countermeasure = _TRUE;
632 			psecuritypriv->last_mic_err_time = 0;
633 			psecuritypriv->btkip_countermeasure_time = cur_time;
634 		} else
635 			psecuritypriv->last_mic_err_time = rtw_get_current_time();
636 	}
637 
638 #ifdef CONFIG_IOCTL_CFG80211
639 	if (bgroup)
640 		key_type |= NL80211_KEYTYPE_GROUP;
641 	else
642 		key_type |= NL80211_KEYTYPE_PAIRWISE;
643 
644 	cfg80211_michael_mic_failure(padapter->pnetdev, sta->cmn.mac_addr, key_type, -1, NULL, GFP_ATOMIC);
645 #endif
646 
647 	_rtw_memset(&ev, 0x00, sizeof(ev));
648 	if (bgroup)
649 		ev.flags |= IW_MICFAILURE_GROUP;
650 	else
651 		ev.flags |= IW_MICFAILURE_PAIRWISE;
652 
653 	ev.src_addr.sa_family = ARPHRD_ETHER;
654 	_rtw_memcpy(ev.src_addr.sa_data, sta->cmn.mac_addr, ETH_ALEN);
655 
656 	_rtw_memset(&wrqu, 0x00, sizeof(wrqu));
657 	wrqu.data.length = sizeof(ev);
658 
659 #ifndef CONFIG_IOCTL_CFG80211
660 	wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu, (char *) &ev);
661 #endif
662 }
663 
664 #ifdef CONFIG_HOSTAPD_MLME
rtw_hostapd_mlme_rx(_adapter * padapter,union recv_frame * precv_frame)665 void rtw_hostapd_mlme_rx(_adapter *padapter, union recv_frame *precv_frame)
666 {
667 	_pkt *skb;
668 	struct hostapd_priv *phostapdpriv  = padapter->phostapdpriv;
669 	struct net_device *pmgnt_netdev = phostapdpriv->pmgnt_netdev;
670 
671 
672 	skb = precv_frame->u.hdr.pkt;
673 
674 	if (skb == NULL)
675 		return;
676 
677 	skb->data = precv_frame->u.hdr.rx_data;
678 	skb->tail = precv_frame->u.hdr.rx_tail;
679 	skb->len = precv_frame->u.hdr.len;
680 
681 	/* pskb_copy = rtw_skb_copy(skb);
682 	*	if(skb == NULL) goto _exit; */
683 
684 	skb->dev = pmgnt_netdev;
685 	skb->ip_summed = CHECKSUM_NONE;
686 	skb->pkt_type = PACKET_OTHERHOST;
687 	/* skb->protocol = __constant_htons(0x0019); ETH_P_80211_RAW */
688 	skb->protocol = __constant_htons(0x0003); /*ETH_P_80211_RAW*/
689 
690 	/* 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); */
691 
692 	/* skb->mac.raw = skb->data; */
693 	skb_reset_mac_header(skb);
694 
695 	/* skb_pull(skb, 24); */
696 	_rtw_memset(skb->cb, 0, sizeof(skb->cb));
697 
698 	rtw_netif_rx(pmgnt_netdev, skb);
699 
700 	precv_frame->u.hdr.pkt = NULL; /* set pointer to NULL before rtw_free_recvframe() if call rtw_netif_rx() */
701 }
702 #endif /* CONFIG_HOSTAPD_MLME */
703 
704 #ifdef CONFIG_WIFI_MONITOR
705 /*
706    precv_frame: impossible to be NULL
707    precv_frame: free by caller
708  */
rtw_recv_monitor(_adapter * padapter,union recv_frame * precv_frame)709 int rtw_recv_monitor(_adapter *padapter, union recv_frame *precv_frame)
710 {
711 	int ret = _FAIL;
712 	_pkt *skb;
713 
714 	skb = precv_frame->u.hdr.pkt;
715 	if (skb == NULL) {
716 		RTW_INFO("%s :skb==NULL something wrong!!!!\n", __func__);
717 		goto _recv_drop;
718 	}
719 
720 	skb->data = precv_frame->u.hdr.rx_data;
721 	skb_set_tail_pointer(skb, precv_frame->u.hdr.len);
722 	skb->len = precv_frame->u.hdr.len;
723 	skb->ip_summed = CHECKSUM_NONE;
724 	skb->pkt_type = PACKET_OTHERHOST;
725 	skb->protocol = htons(0x0019); /* ETH_P_80211_RAW */
726 
727 	/* send to kernel */
728 	rtw_netif_rx(padapter->pnetdev, skb);
729 
730 	/* pointers to NULL before rtw_free_recvframe() */
731 	precv_frame->u.hdr.pkt = NULL;
732 
733 	ret = _SUCCESS;
734 
735 _recv_drop:
736 	return ret;
737 }
738 #endif /* CONFIG_WIFI_MONITOR */
739 
rtw_rframe_set_os_pkt(union recv_frame * rframe)740 inline void rtw_rframe_set_os_pkt(union recv_frame *rframe)
741 {
742 	_pkt *skb = rframe->u.hdr.pkt;
743 
744 	skb->data = rframe->u.hdr.rx_data;
745 	skb_set_tail_pointer(skb, rframe->u.hdr.len);
746 	skb->len = rframe->u.hdr.len;
747 }
748 
rtw_recv_indicatepkt(_adapter * padapter,union recv_frame * precv_frame)749 int rtw_recv_indicatepkt(_adapter *padapter, union recv_frame *precv_frame)
750 {
751 	struct recv_priv *precvpriv;
752 	_queue	*pfree_recv_queue;
753 
754 	precvpriv = &(padapter->recvpriv);
755 	pfree_recv_queue = &(precvpriv->free_recv_queue);
756 
757 	if (precv_frame->u.hdr.pkt == NULL)
758 		goto _recv_indicatepkt_drop;
759 
760 	rtw_os_recv_indicate_pkt(padapter, precv_frame->u.hdr.pkt, precv_frame);
761 
762 	precv_frame->u.hdr.pkt = NULL;
763 	rtw_free_recvframe(precv_frame, pfree_recv_queue);
764 	return _SUCCESS;
765 
766 _recv_indicatepkt_drop:
767 	rtw_free_recvframe(precv_frame, pfree_recv_queue);
768 	DBG_COUNTER(padapter->rx_logs.os_indicate_err);
769 	return _FAIL;
770 }
771 
rtw_os_read_port(_adapter * padapter,struct recv_buf * precvbuf)772 void rtw_os_read_port(_adapter *padapter, struct recv_buf *precvbuf)
773 {
774 #ifdef CONFIG_USB_HCI
775 	struct recv_priv *precvpriv = &padapter->recvpriv;
776 
777 	precvbuf->ref_cnt--;
778 
779 	/* free skb in recv_buf */
780 	rtw_skb_free(precvbuf->pskb);
781 
782 	precvbuf->pskb = NULL;
783 
784 	if (precvbuf->irp_pending == _FALSE)
785 		rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);
786 
787 
788 #endif
789 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
790 	precvbuf->pskb = NULL;
791 #endif
792 
793 }
794 
795