xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/os_dep/linux/recv_linux.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
342 			rtw_napi_gro_receive(&padapter->napi, pskb);
343 #else
344 			if (rtw_napi_gro_receive(&padapter->napi, pskb) != GRO_DROP)
345 #endif
346 				rx_ok = _TRUE;
347 			goto next;
348 		}
349 #endif /* CONFIG_RTW_GRO */
350 
351 		if (rtw_netif_receive_skb(padapter->pnetdev, pskb) == NET_RX_SUCCESS)
352 			rx_ok = _TRUE;
353 
354 next:
355 		if (rx_ok == _TRUE) {
356 			work_done++;
357 			DBG_COUNTER(padapter->rx_logs.os_netif_ok);
358 		} else {
359 			DBG_COUNTER(padapter->rx_logs.os_netif_err);
360 		}
361 	}
362 
363 	return work_done;
364 }
365 
rtw_recv_napi_poll(struct napi_struct * napi,int budget)366 int rtw_recv_napi_poll(struct napi_struct *napi, int budget)
367 {
368 	_adapter *padapter = container_of(napi, _adapter, napi);
369 	int work_done = 0;
370 	struct recv_priv *precvpriv = &adapter_to_dvobj(padapter)->recvpriv;
371 
372 
373 	work_done = napi_recv(padapter, budget);
374 	if (work_done < budget) {
375 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_PCI_HCI)
376 		napi_complete_done(napi, work_done);
377 #else
378 		napi_complete(napi);
379 #endif
380 		if (!skb_queue_empty(&precvpriv->rx_napi_skb_queue))
381 			napi_schedule(napi);
382 	}
383 
384 	return work_done;
385 }
386 
387 #ifdef CONFIG_RTW_NAPI_DYNAMIC
dynamic_napi_th_chk(_adapter * adapter)388 void dynamic_napi_th_chk (_adapter *adapter)
389 {
390 
391 	if (adapter->registrypriv.en_napi) {
392 		struct dvobj_priv *dvobj;
393 		struct registry_priv *registry;
394 
395 		dvobj = adapter_to_dvobj(adapter);
396 		registry = &adapter->registrypriv;
397 		if (dvobj->traffic_stat.cur_rx_tp > registry->napi_threshold)
398 			dvobj->en_napi_dynamic = 1;
399 		else
400 			dvobj->en_napi_dynamic = 0;
401 	}
402 
403 }
404 #endif /* CONFIG_RTW_NAPI_DYNAMIC */
405 #endif /* CONFIG_RTW_NAPI */
406 
rtw_os_recv_indicate_pkt(_adapter * padapter,struct sk_buff * pkt,union recv_frame * rframe)407 void rtw_os_recv_indicate_pkt(_adapter *padapter, struct sk_buff *pkt,
408 						union recv_frame *rframe)
409 {
410 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
411 	struct recv_priv *precvpriv = &adapter_to_dvobj(padapter)->recvpriv;
412 	struct registry_priv	*pregistrypriv = &padapter->registrypriv;
413 #ifdef CONFIG_BR_EXT
414 	void *br_port = NULL;
415 #endif
416 	int ret;
417 
418 	/* Indicat the packets to upper layer */
419 	if (pkt) {
420 		struct ethhdr *ehdr = (struct ethhdr *)pkt->data;
421 
422 		DBG_COUNTER(padapter->rx_logs.os_indicate);
423 #ifdef CONFIG_BR_EXT
424 		if (!adapter_use_wds(padapter) &&
425 		    (MLME_IS_STA(padapter) || MLME_IS_ADHOC(padapter))) {
426 			/* Insert NAT2.5 RX here! */
427 			#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
428 			br_port = padapter->pnetdev->br_port;
429 			#else
430 			rcu_read_lock();
431 			br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
432 			rcu_read_unlock();
433 			#endif
434 
435 			if (br_port) {
436 				int nat25_handle_frame(_adapter *priv, struct sk_buff *skb);
437 
438 				if (nat25_handle_frame(padapter, pkt) == -1) {
439 					/* priv->ext_stats.rx_data_drops++; */
440 					/* DEBUG_ERR("RX DROP: nat25_handle_frame fail!\n"); */
441 					/* return FAIL; */
442 
443 					#if 1
444 					/* bypass this frame to upper layer!! */
445 					#else
446 					rtw_skb_free(sub_skb);
447 					continue;
448 					#endif
449 				}
450 			}
451 		}
452 #endif /* CONFIG_BR_EXT */
453 
454 		/* After eth_type_trans process , pkt->data pointer will move from ethrnet header to ip header */
455 		pkt->protocol = eth_type_trans(pkt, padapter->pnetdev);
456 		pkt->dev = padapter->pnetdev;
457 		pkt->ip_summed = CHECKSUM_NONE; /* CONFIG_TCP_CSUM_OFFLOAD_RX */
458 #ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
459 		if ((rframe->u.hdr.attrib.csum_valid == 1)
460 		    && (rframe->u.hdr.attrib.csum_err == 0))
461 			pkt->ip_summed = CHECKSUM_UNNECESSARY;
462 #endif /* CONFIG_TCP_CSUM_OFFLOAD_RX */
463 
464 #ifdef CONFIG_RTW_NAPI
465 #ifdef CONFIG_RTW_NAPI_DYNAMIC
466 		if (!skb_queue_empty(&precvpriv->rx_napi_skb_queue)
467 			&& !adapter_to_dvobj(padapter)->en_napi_dynamic
468 			)
469 			napi_recv(padapter, RTL_NAPI_WEIGHT);
470 #endif
471 
472 		if (pregistrypriv->en_napi
473 			#ifdef CONFIG_RTW_NAPI_DYNAMIC
474 			&& adapter_to_dvobj(padapter)->en_napi_dynamic
475 			#endif
476 		) {
477 			skb_queue_tail(&precvpriv->rx_napi_skb_queue, pkt);
478 			#ifndef CONFIG_RTW_NAPI_V2
479 			napi_schedule(&padapter->napi);
480 			#endif
481 			return;
482 		}
483 #endif /* CONFIG_RTW_NAPI */
484 
485 		ret = rtw_netif_rx(padapter->pnetdev, pkt);
486 		if (ret == NET_RX_SUCCESS)
487 			DBG_COUNTER(padapter->rx_logs.os_netif_ok);
488 		else
489 			DBG_COUNTER(padapter->rx_logs.os_netif_err);
490 	}
491 }
492 
rtw_handle_tkip_mic_err(_adapter * padapter,struct sta_info * sta,u8 bgroup)493 void rtw_handle_tkip_mic_err(_adapter *padapter, struct sta_info *sta, u8 bgroup)
494 {
495 #ifdef CONFIG_IOCTL_CFG80211
496 	enum nl80211_key_type key_type = 0;
497 #endif
498 	union iwreq_data wrqu;
499 	struct iw_michaelmicfailure    ev;
500 	struct security_priv	*psecuritypriv = &padapter->securitypriv;
501 	systime cur_time = 0;
502 
503 	if (psecuritypriv->last_mic_err_time == 0)
504 		psecuritypriv->last_mic_err_time = rtw_get_current_time();
505 	else {
506 		cur_time = rtw_get_current_time();
507 
508 		if (cur_time - psecuritypriv->last_mic_err_time < 60 * HZ) {
509 			psecuritypriv->btkip_countermeasure = _TRUE;
510 			psecuritypriv->last_mic_err_time = 0;
511 			psecuritypriv->btkip_countermeasure_time = cur_time;
512 		} else
513 			psecuritypriv->last_mic_err_time = rtw_get_current_time();
514 	}
515 
516 #ifdef CONFIG_IOCTL_CFG80211
517 	if (bgroup)
518 		key_type |= NL80211_KEYTYPE_GROUP;
519 	else
520 		key_type |= NL80211_KEYTYPE_PAIRWISE;
521 
522 	cfg80211_michael_mic_failure(padapter->pnetdev, sta->phl_sta->mac_addr, key_type, -1, NULL, GFP_ATOMIC);
523 #endif
524 
525 	_rtw_memset(&ev, 0x00, sizeof(ev));
526 	if (bgroup)
527 		ev.flags |= IW_MICFAILURE_GROUP;
528 	else
529 		ev.flags |= IW_MICFAILURE_PAIRWISE;
530 
531 	ev.src_addr.sa_family = ARPHRD_ETHER;
532 	_rtw_memcpy(ev.src_addr.sa_data, sta->phl_sta->mac_addr, ETH_ALEN);
533 
534 	_rtw_memset(&wrqu, 0x00, sizeof(wrqu));
535 	wrqu.data.length = sizeof(ev);
536 
537 #ifndef CONFIG_IOCTL_CFG80211
538 	wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu, (char *) &ev);
539 #endif
540 }
541 
542 #ifdef CONFIG_HOSTAPD_MLME
rtw_hostapd_mlme_rx(_adapter * padapter,union recv_frame * precv_frame)543 void rtw_hostapd_mlme_rx(_adapter *padapter, union recv_frame *precv_frame)
544 {
545 	struct sk_buff *skb;
546 	struct hostapd_priv *phostapdpriv  = padapter->phostapdpriv;
547 	struct net_device *pmgnt_netdev = phostapdpriv->pmgnt_netdev;
548 
549 
550 	skb = precv_frame->u.hdr.pkt;
551 
552 	if (skb == NULL)
553 		return;
554 
555 	skb->data = precv_frame->u.hdr.rx_data;
556 	skb->tail = precv_frame->u.hdr.rx_tail;
557 	skb->len = precv_frame->u.hdr.len;
558 
559 	/* pskb_copy = rtw_skb_copy(skb);
560 	*	if(skb == NULL) goto _exit; */
561 
562 	skb->dev = pmgnt_netdev;
563 	skb->ip_summed = CHECKSUM_NONE;
564 	skb->pkt_type = PACKET_OTHERHOST;
565 	/* skb->protocol = __constant_htons(0x0019); ETH_P_80211_RAW */
566 	skb->protocol = __constant_htons(0x0003); /*ETH_P_80211_RAW*/
567 
568 	/* 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); */
569 
570 	/* skb->mac.raw = skb->data; */
571 	skb_reset_mac_header(skb);
572 
573 	/* skb_pull(skb, 24); */
574 	_rtw_memset(skb->cb, 0, sizeof(skb->cb));
575 
576 	rtw_netif_rx(pmgnt_netdev, skb);
577 
578 	precv_frame->u.hdr.pkt = NULL; /* set pointer to NULL before rtw_free_recvframe() if call rtw_netif_rx() */
579 }
580 #endif /* CONFIG_HOSTAPD_MLME */
581 
582 #ifdef CONFIG_WIFI_MONITOR
583 /*
584    precv_frame: impossible to be NULL
585    precv_frame: free by caller
586  */
rtw_recv_monitor(_adapter * padapter,union recv_frame * precv_frame)587 int rtw_recv_monitor(_adapter *padapter, union recv_frame *precv_frame)
588 {
589 	int ret = _FAIL;
590 	struct sk_buff *skb;
591 
592 	skb = precv_frame->u.hdr.pkt;
593 	if (skb == NULL) {
594 		RTW_INFO("%s :skb==NULL something wrong!!!!\n", __func__);
595 		goto _recv_drop;
596 	}
597 
598 	skb->data = precv_frame->u.hdr.rx_data;
599 	skb_set_tail_pointer(skb, precv_frame->u.hdr.len);
600 	skb->len = precv_frame->u.hdr.len;
601 	skb->ip_summed = CHECKSUM_NONE;
602 	skb->pkt_type = PACKET_OTHERHOST;
603 	skb->protocol = htons(0x0019); /* ETH_P_80211_RAW */
604 
605 	/* send to kernel */
606 	rtw_netif_rx(padapter->pnetdev, skb);
607 
608 	/* pointers to NULL before rtw_free_recvframe() */
609 	precv_frame->u.hdr.pkt = NULL;
610 
611 	ret = _SUCCESS;
612 
613 _recv_drop:
614 	return ret;
615 }
616 #endif /* CONFIG_WIFI_MONITOR */
617 
rtw_rframe_set_os_pkt(union recv_frame * rframe)618 inline void rtw_rframe_set_os_pkt(union recv_frame *rframe)
619 {
620 	struct sk_buff *skb = rframe->u.hdr.pkt;
621 
622 	skb->data = rframe->u.hdr.rx_data;
623 	skb_set_tail_pointer(skb, rframe->u.hdr.len);
624 	skb->len = rframe->u.hdr.len;
625 }
626 
rtw_recv_indicatepkt(_adapter * padapter,union recv_frame * precv_frame)627 int rtw_recv_indicatepkt(_adapter *padapter, union recv_frame *precv_frame)
628 {
629 	if (precv_frame->u.hdr.pkt == NULL)
630 		goto _recv_indicatepkt_drop;
631 
632 	rtw_os_recv_indicate_pkt(padapter, precv_frame->u.hdr.pkt, precv_frame);
633 
634 	precv_frame->u.hdr.pkt = NULL;
635 	rtw_free_recvframe(precv_frame);
636 	return _SUCCESS;
637 
638 _recv_indicatepkt_drop:
639 	rtw_free_recvframe(precv_frame);
640 	DBG_COUNTER(padapter->rx_logs.os_indicate_err);
641 	return _FAIL;
642 }
643 
644